Diferència entre revisions de la pàgina «MediaWiki:Common.js/infocarrer.js»
De Català a Cort
| Línia 4: | Línia 4: | ||
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("#cerca").keyup(function(e) { if(e.keyCode == 13) { cercaCarrer(jQuery("#q").val()); } }); | ||
}()); | }()); | ||
function cercaCarrer(que) | function cercaCarrer(que) | ||
{ | { | ||
| + | que = que.trim(); | ||
if (que == "") | if (que == "") | ||
return; | return; | ||
Revisió del 10:48, 12 abr 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 += "<div id=\"errorcarrers\">Cerca massa general</div>";
jQuery("#infocarrer").html(h);
jQuery("#cerca").click(function() { cercaCarrer(jQuery("#q").val()); });
jQuery("#cerca").keyup(function(e) { if(e.keyCode == 13) { cercaCarrer(jQuery("#q").val()); } });
}());
function cercaCarrer(que)
{
que = que.trim();
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("S'han trobat massa carrers (" + resposta.quants + "). Refinau la cerca").show();
}
});
}