Diferència entre revisions de la pàgina «MediaWiki:Common.js/infocarrer.js»
De Català a Cort
| Línia 2: | Línia 2: | ||
$(function () { | $(function () { | ||
h = "Nom del carrer: <input type=\"text\" id=\"q\"></input><button id=\"cerca\">Cerca</button>"; | h = "Nom del carrer: <input type=\"text\" id=\"q\"></input><button id=\"cerca\">Cerca</button>"; | ||
| + | h += "<button id=\"mostraAjuda\">Mostra ajuda</button>"; | ||
h += "<div id=\"errorcarrers\">Cerca massa general</div>"; | h += "<div id=\"errorcarrers\">Cerca massa general</div>"; | ||
jQuery("#infocarrer").html(h); | jQuery("#infocarrer").html(h); | ||
jQuery("#cerca").click(function() { cercaCarrer(jQuery("#q").val()); }); | jQuery("#cerca").click(function() { cercaCarrer(jQuery("#q").val()); }); | ||
jQuery("#q").on('keypress', function(e) { if(e.keyCode == 13) jQuery("#cerca").click(); }); | jQuery("#q").on('keypress', function(e) { if(e.keyCode == 13) jQuery("#cerca").click(); }); | ||
| + | jQuery("#mostraAjuda").click(function() { mostraAjuda(); }); | ||
}()); | }()); | ||
| Línia 31: | Línia 33: | ||
} | } | ||
}); | }); | ||
| + | } | ||
| + | |||
| + | function mostraAjuda() | ||
| + | { | ||
| + | jQuery("#ajuda").toggle(); | ||
| + | jQuery("#mostraAjuda").html(((jQuery("#ajuda").css("display") == "none") : "Mostra" : "Amaga") + " ajuda"); | ||
} | } | ||
Revisió del 09:50, 15 maig 2017
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
h = "Nom del carrer: <input type=\"text\" id=\"q\"></input><button id=\"cerca\">Cerca</button>";
h += "<button id=\"mostraAjuda\">Mostra ajuda</button>";
h += "<div id=\"errorcarrers\">Cerca massa general</div>";
jQuery("#infocarrer").html(h);
jQuery("#cerca").click(function() { cercaCarrer(jQuery("#q").val()); });
jQuery("#q").on('keypress', function(e) { if(e.keyCode == 13) jQuery("#cerca").click(); });
jQuery("#mostraAjuda").click(function() { mostraAjuda(); });
}());
function cercaCarrer(que)
{
que = que.trim().toLowerCase();
if (que == "")
return;
jQuery.getJSON("carrers/?q=" + que, function(resposta) {
console.log(resposta);
if (resposta.OK) {
jQuery("#errorcarrers").hide();
jQuery(".filacarrer").remove();
for(i=0; i<resposta.quants; ++i) {
carrer = resposta.trobats[i];
codi = carrer.codi ? carrer.codi : "";
fila = '<tr class="filacarrer"><td>' + carrer.nom + '</td><td>' + carrer.antic + '</td><td style="text-align:center">' + codi + '</td></tr>';
jQuery("#carrerstrobats").append(fila);
}
jQuery("#carrerstrobats").show();
}
else {
jQuery("#carrerstrobats").hide();
jQuery("#errorcarrers").text(resposta.error).show();
}
});
}
function mostraAjuda()
{
jQuery("#ajuda").toggle();
jQuery("#mostraAjuda").html(((jQuery("#ajuda").css("display") == "none") : "Mostra" : "Amaga") + " ajuda");
}