Przejdź do zawartości

MediaWiki:Common.js: Różnice pomiędzy wersjami

Z Arcarium Index
Nie podano opisu zmian
Nie podano opisu zmian
Linia 13: Linia 13:
                 const textA = a.textContent.trim().toLowerCase();
                 const textA = a.textContent.trim().toLowerCase();
                 const textB = b.textContent.trim().toLowerCase();
                 const textB = b.textContent.trim().toLowerCase();
                 return textA.localeCompare(textB);
                 return textA.localeCompare(textB, 'pl');
             });
             });


            // Re-append in sorted order
             items.forEach(function (item) {
             items.forEach(function (item) {
                 container.appendChild(item);
                 container.appendChild(item);
Linia 23: Linia 22:
     }
     }


     // Run on page load
    function runSort() {
     $(document).ready(function () {
        // small delay helps because Wikibase renders async
        sortAliases();
        setTimeout(sortAliases, 50);
    });
    }
 
     // initial load
     $(document).ready(runSort);
 
    // standard MW hook
    mw.hook('wikipage.content').add(runSort);


    // Run again after dynamic updates
     mw.hook('wikibase.entityPage.entityLoaded').add(runSort);
     mw.hook('wikipage.content').add(function () {
        sortAliases();
    });


});
});

Wersja z 10:14, 30 kwi 2026

/* Umieszczony tutaj kod JavaScript zostanie załadowany przez każdego użytkownika, podczas każdego ładowania strony. */
mw.loader.using(['mediawiki.util']).then(function () {

    function sortAliases() {
        const aliasContainers = document.querySelectorAll('.wikibase-aliasesview-list');

        aliasContainers.forEach(function (container) {
            const items = Array.from(container.querySelectorAll('.wikibase-aliasesview-list-item'));

            if (items.length <= 1) return;

            items.sort(function (a, b) {
                const textA = a.textContent.trim().toLowerCase();
                const textB = b.textContent.trim().toLowerCase();
                return textA.localeCompare(textB, 'pl');
            });

            items.forEach(function (item) {
                container.appendChild(item);
            });
        });
    }

    function runSort() {
        // small delay helps because Wikibase renders async
        setTimeout(sortAliases, 50);
    }

    // initial load
    $(document).ready(runSort);

    // standard MW hook
    mw.hook('wikipage.content').add(runSort);

    mw.hook('wikibase.entityPage.entityLoaded').add(runSort);

});