Mudanças entre as edições de "Widget:Conquistas"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
Linha 1 207: Linha 1 207:


             var validTabs = {};
             var validTabs = {};
            var panelByTab = {};
            var tabByName = {};
             panels.forEach(function (p) {
             panels.forEach(function (p) {
                 var name = p.getAttribute("data-tab-content");
                 var name = p.getAttribute("data-tab-content");
                 if (name) validTabs[name] = p.querySelector(".gla-list");
                 if (name) {
                    validTabs[name] = p.querySelector(".gla-list");
                    panelByTab[name] = p;
                }
            });
            tabs.forEach(function (t) {
                var name = t.getAttribute("data-tab");
                if (name) tabByName[name] = t;
             });
             });


Linha 1 223: Linha 1 232:
                 if (src.parentNode) src.parentNode.removeChild(src);
                 if (src.parentNode) src.parentNode.removeChild(src);
             });
             });
            // Cache por aba pra evitar querySelectorAll em toda busca/filtro.
            var cardsByTab = {};
            var hiddenCountByTab = {};
            function buildTabCaches() {
                cardsByTab = {};
                hiddenCountByTab = {};
                Object.keys(validTabs).forEach(function (tabName) {
                    var list = validTabs[tabName];
                    if (!list) {
                        cardsByTab[tabName] = [];
                        hiddenCountByTab[tabName] = 0;
                        return;
                    }
                    var cards = [];
                    var hiddenCount = 0;
                    for (var i = 0; i < list.children.length; i++) {
                        var el = list.children[i];
                        if (!(el.classList && el.classList.contains("gla-item"))) continue;
                        cards.push(el);
                        if (el.getAttribute("data-hidden") === "true") hiddenCount++;
                    }
                    cardsByTab[tabName] = cards;
                    hiddenCountByTab[tabName] = hiddenCount;
                });
            }
            buildTabCaches();


             // Estado global
             // Estado global
Linha 1 235: Linha 1 272:


             function countHiddenInTab(tabName) {
             function countHiddenInTab(tabName) {
                 var panel = root.querySelector('.gla-conquistas-panel[data-tab-content="' + tabName + '"]');
                 return hiddenCountByTab[tabName] || 0;
                if (!panel) return 0;
                var n = 0;
                panel.querySelectorAll(".gla-item").forEach(function (card) {
                    if (card.getAttribute("data-hidden") === "true") n++;
                });
                return n;
             }
             }


Linha 1 300: Linha 1 331:


             function applyVisibility() {
             function applyVisibility() {
                 var panel = root.querySelector('.gla-conquistas-panel[data-tab-content="' + currentTab + '"]');
                 var cards = cardsByTab[currentTab] || [];
                 if (!panel) return;
                 if (!cards.length) return;


                 // Token-based search: divide a query em palavras e exige que
                 // Token-based search: divide a query em palavras e exige que
Linha 1 310: Linha 1 341:
                 var tokens = normalize(currentSearch).split(/\s+/).filter(Boolean);
                 var tokens = normalize(currentSearch).split(/\s+/).filter(Boolean);


                 panel.querySelectorAll(".gla-item").forEach(function (card) {
                 cards.forEach(function (card) {
                     var matchSearch = true;
                     var matchSearch = true;
                     if (tokens.length > 0) {
                     if (tokens.length > 0) {
Linha 1 358: Linha 1 389:
             // em wikitext), por isso aceitamos click + Enter/Space pra
             // em wikitext), por isso aceitamos click + Enter/Space pra
             // preservar semântica de botão acessível.
             // preservar semântica de botão acessível.
            var openSpoilerCard = null;
            var openSpoilerToggle = null;
            function closeOpenSpoiler() {
                if (openSpoilerCard) {
                    openSpoilerCard.classList.remove("is-open");
                    openSpoilerCard = null;
                }
                if (openSpoilerToggle) {
                    openSpoilerToggle.setAttribute("aria-expanded", "false");
                    openSpoilerToggle = null;
                }
            }
             function toggleSpoiler(toggle) {
             function toggleSpoiler(toggle) {
                 var card = toggle.closest(".gla-item.has-spoiler");
                 var card = toggle.closest(".gla-item.has-spoiler");
                 if (!card) return;
                 if (!card) return;
                 var isOpen = card.classList.contains("is-open");
                 var isOpen = (openSpoilerCard === card);
                 root.querySelectorAll(".gla-item.is-open").forEach(function (c) {
                 closeOpenSpoiler();
                    c.classList.remove("is-open");
                });
                root.querySelectorAll(".gla-item-spoiler-toggle").forEach(function (btn) {
                    btn.setAttribute("aria-expanded", "false");
                });
                 if (!isOpen) {
                 if (!isOpen) {
                     card.classList.add("is-open");
                     card.classList.add("is-open");
                     toggle.setAttribute("aria-expanded", "true");
                     toggle.setAttribute("aria-expanded", "true");
                    openSpoilerCard = card;
                    openSpoilerToggle = toggle;
                 }
                 }
             }
             }
Linha 1 461: Linha 1 503:
                 currentTab = nome;
                 currentTab = nome;
                 currentFilter = "all";
                 currentFilter = "all";
                closeOpenSpoiler();


                 tabs.forEach(function (t) { t.classList.remove("is-active"); });
                 tabs.forEach(function (t) { t.classList.remove("is-active"); });
                 panels.forEach(function (p) { p.classList.remove("is-active"); });
                 panels.forEach(function (p) { p.classList.remove("is-active"); });


                 var tab = root.querySelector('.gla-conquistas-tab[data-tab="' + nome + '"]');
                 var tab = tabByName[nome];
                 var panel = root.querySelector('.gla-conquistas-panel[data-tab-content="' + nome + '"]');
                 var panel = panelByTab[nome];
                 if (tab) tab.classList.add("is-active");
                 if (tab) tab.classList.add("is-active");
                 if (panel) panel.classList.add("is-active");
                 if (panel) panel.classList.add("is-active");
Linha 1 507: Linha 1 550:
             // recortem o popover nem os tooltips dos itens dentro dele.
             // recortem o popover nem os tooltips dos itens dentro dele.
             var portal = null;
             var portal = null;
            var activeChip = null;
            var activePopover = null;


             function ensurePortal() {
             function ensurePortal() {
Linha 1 588: Linha 1 633:
                         chip.setAttribute("aria-expanded", "true");
                         chip.setAttribute("aria-expanded", "true");
                         chip.__glaPopover = popover;
                         chip.__glaPopover = popover;
                        activeChip = chip;
                        activePopover = popover;
                     }
                     }
                 });
                 });
Linha 1 595: Linha 1 642:


             function closeAll() {
             function closeAll() {
                if (activePopover) {
                    activePopover.hidden = true;
                    activePopover.style.pointerEvents = "none";
                    activePopover = null;
                }
                if (activeChip) {
                    activeChip.setAttribute("aria-expanded", "false");
                    activeChip = null;
                    return;
                }
                // fallback defensivo (estado legado inesperado)
                 document.querySelectorAll(".reward-overflow-popover").forEach(function (p) {
                 document.querySelectorAll(".reward-overflow-popover").forEach(function (p) {
                     p.hidden = true;
                     p.hidden = true;
                     p.style.pointerEvents = "none";
                     p.style.pointerEvents = "none";
                 });
                 });
                 document.querySelectorAll(".reward-more-chip").forEach(function (c) {
                 document.querySelectorAll(".reward-more-chip[aria-expanded=\"true\"]").forEach(function (c) {
                     c.setAttribute("aria-expanded", "false");
                     c.setAttribute("aria-expanded", "false");
                 });
                 });
Linha 1 606: Linha 1 664:
             // Reposiciona qualquer popover aberto em scroll/resize.
             // Reposiciona qualquer popover aberto em scroll/resize.
             function repositionOpen() {
             function repositionOpen() {
                 document.querySelectorAll(".reward-more-chip[aria-expanded=\"true\"]").forEach(function (chip) {
                 if (activeChip && activePopover && !activePopover.hidden) {
                    var pop = chip.__glaPopover;
                    positionPopover(activePopover, activeChip);
                    if (pop && !pop.hidden) positionPopover(pop, chip);
                 }
                 });
             }
             }
             window.addEventListener("resize", repositionOpen);
             window.addEventListener("resize", repositionOpen);
Linha 1 634: Linha 1 691:
             }
             }


            document.addEventListener("click", function (e) {
                if (e.target.closest(".reward-overflow-popover, .reward-more-chip")) return;
                closeAll();
            });
            document.addEventListener("keydown", function (e) {
                if (e.key === "Escape") closeAll();
            });
         })();
         })();
     </script>
     </script>
</includeonly>
</includeonly>

Edição das 04h07min de 21 de maio de 2026