Diferència entre revisions de la pàgina «MediaWiki:Common.js/infocarrer.js»
De Català a Cort
| Línia 38: | Línia 38: | ||
{ | { | ||
jQuery("#ajuda").toggle(); | jQuery("#ajuda").toggle(); | ||
| − | jQuery("#mostraAjuda").html(((jQuery("#ajuda").css("display") == "none") | + | jQuery("#mostraAjuda").html(((jQuery("#ajuda").css("display") == "none") ? "Mostra" : "Amaga") + " ajuda"); |
} | } | ||
Revisió del 09:53, 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");
}