Diferència entre revisions de la pàgina «MediaWiki:Common.js/infocarrer.js»
De Català a Cort
m |
|||
| (Hi ha 5 revisions intermèdies del mateix usuari que no es mostren) | |||
| 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 += "<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(); }); | ||
}()); | }()); | ||
function cercaCarrer(que) | function cercaCarrer(que) | ||
{ | { | ||
| − | que = que.trim(); | + | que = que.trim().toLowerCase(); |
if (que == "") | if (que == "") | ||
return; | return; | ||
| Línia 21: | Línia 25: | ||
carrer = resposta.trobats[i]; | carrer = resposta.trobats[i]; | ||
codi = carrer.codi ? carrer.codi : ""; | codi = carrer.codi ? carrer.codi : ""; | ||
| − | fila = '<tr class="filacarrer"><td>' + | + | nom = carrer.nom; |
| + | if (carrer.infoc) | ||
| + | nom += "<span class=\"infoc\">" + carrer.infoc + "</span>"; | ||
| + | fila = '<tr class="filacarrer"><td>' + nom + '</td><td>' + carrer.antic + '</td><td style="text-align:center">' + codi + '</td></tr>'; | ||
jQuery("#carrerstrobats").append(fila); | jQuery("#carrerstrobats").append(fila); | ||
} | } | ||
| Línia 31: | Línia 38: | ||
} | } | ||
}); | }); | ||
| + | } | ||
| + | |||
| + | function mostraAjuda() | ||
| + | { | ||
| + | jQuery("#ajuda").toggle(); | ||
| + | jQuery("#mostraAjuda").html(((jQuery("#ajuda").css("display") == "none") ? "Mostra" : "Amaga") + " ajuda"); | ||
} | } | ||
Revisió de 10:33, 19 set 2019
/* 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 : "";
nom = carrer.nom;
if (carrer.infoc)
nom += "<span class=\"infoc\">" + carrer.infoc + "</span>";
fila = '<tr class="filacarrer"><td>' + 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");
}