|
|
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) {
| |
| 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);
| |
| });
| |