Diferència entre revisions de la pàgina «MediaWiki:Common.js/infocarrer.js»
De Català a Cort
| Línia 1: | Línia 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
$(function () { | $(function () { | ||
| + | if (jQuery("#infocarrer").length == 0) | ||
| + | return; | ||
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 += "<button id=\"mostraAjuda\">Mostra ajuda</button>"; | ||
Revisió del 10:34, 18 maig 2017
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
if (jQuery("#infocarrer").length == 0)
return;
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");
}