MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 1: | Linha 1: | ||
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */ | /* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */ | ||
function filterFunction(that, event) { | function filterFunction(that, event) { | ||
var container, input, filter, li, input_val; | |||
container = $(that).closest(".searchable"); | container = $(that).closest(".searchable"); | ||
input_val = container.find("input").val().toUpperCase(); | input_val = container.find("input").val().toUpperCase(); | ||
| Linha 20: | Linha 20: | ||
setTimeout(function () { | setTimeout(function () { | ||
container.find("ul li:visible").first().addClass("selected"); | container.find("ul li:visible").first().addClass("selected"); | ||
}, 100) | }, 100); | ||
} | } | ||
} | } | ||
| Linha 26: | Linha 26: | ||
function keyControl(e, container) { | function keyControl(e, container) { | ||
if (e.key == "ArrowDown") { | if (e.key == "ArrowDown") { | ||
if (container.find("ul li").hasClass("selected")) { | if (container.find("ul li").hasClass("selected")) { | ||
if (container.find("ul li:visible").index(container.find("ul li.selected")) + 1 < container.find("ul li:visible").length) { | if (container.find("ul li:visible").index(container.find("ul li.selected")) + 1 < container.find("ul li:visible").length) { | ||
container.find("ul li.selected").removeClass("selected").nextAll().not('[style*="display: none"]').first().addClass("selected"); | container.find("ul li.selected").removeClass("selected").nextAll().not('[style*="display: none"]').first().addClass("selected"); | ||
} | } | ||
} else { | } else { | ||
container.find("ul li:first-child").addClass("selected"); | container.find("ul li:first-child").addClass("selected"); | ||
| Linha 43: | Linha 41: | ||
} else if (e.key == "Enter") { | } else if (e.key == "Enter") { | ||
container.find("input").val(container.find("ul li.selected").text()).blur(); | container.find("input").val(container.find("ul li.selected").text()).blur(); | ||
onSelect(container.find("ul li.selected").text()) | onSelect(container.find("ul li.selected").text()); | ||
} | } | ||
| Linha 52: | Linha 50: | ||
function onSelect(val) { | function onSelect(val) { | ||
alert(val) | alert(val); | ||
} | } | ||
| Linha 61: | Linha 59: | ||
$(".searchable input").blur(function () { | $(".searchable input").blur(function () { | ||
var that = this; | |||
setTimeout(function () { | setTimeout(function () { | ||
$(that).closest(".searchable").find("ul").hide(); | $(that).closest(".searchable").find("ul").hide(); | ||
}, 300); | }, 300); | ||
}); | }); | ||
Edição das 23h12min de 1 de maio de 2023
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
function filterFunction(that, event) {
var container, input, filter, li, input_val;
container = $(that).closest(".searchable");
input_val = container.find("input").val().toUpperCase();
if (["ArrowDown", "ArrowUp", "Enter"].indexOf(event.key) != -1) {
keyControl(event, container);
} else {
li = container.find("ul li");
li.each(function (i, obj) {
if ($(this).text().toUpperCase().indexOf(input_val) > -1) {
$(this).show();
} else {
$(this).hide();
}
});
container.find("ul li").removeClass("selected");
setTimeout(function () {
container.find("ul li:visible").first().addClass("selected");
}, 100);
}
}
function keyControl(e, container) {
if (e.key == "ArrowDown") {
if (container.find("ul li").hasClass("selected")) {
if (container.find("ul li:visible").index(container.find("ul li.selected")) + 1 < container.find("ul li:visible").length) {
container.find("ul li.selected").removeClass("selected").nextAll().not('[style*="display: none"]').first().addClass("selected");
}
} else {
container.find("ul li:first-child").addClass("selected");
}
} else if (e.key == "ArrowUp") {
if (container.find("ul li:visible").index(container.find("ul li.selected")) > 0) {
container.find("ul li.selected").removeClass("selected").prevAll().not('[style*="display: none"]').first().addClass("selected");
}
} else if (e.key == "Enter") {
container.find("input").val(container.find("ul li.selected").text()).blur();
onSelect(container.find("ul li.selected").text());
}
container.find("ul li.selected")[0].scrollIntoView({
behavior: "smooth",
});
}
function onSelect(val) {
alert(val);
}
$(".searchable input").focus(function () {
$(this).closest(".searchable").find("ul").show();
$(this).closest(".searchable").find("ul li").show();
});
$(".searchable input").blur(function () {
var that = this;
setTimeout(function () {
$(that).closest(".searchable").find("ul").hide();
}, 300);
});