Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 2: Line 2:


// Sort categories alphabetically by the first character after the colon
// Sort categories alphabetically by the first character after the colon
<style>
$(function() {
/* Category sorting */
    var $categories = $('.mw-normal-catlinks ul li');
.mw-normal-catlinks ul {
    $categories.sort(function(a, b) {
    columns: 2; /* Adjust the number of columns as needed */
        var textA = $(a).text().toUpperCase();
    -webkit-columns: 2;
        var textB = $(b).text().toUpperCase();
    -moz-columns: 2;
        var charA = textA.match(/:(.)/)[1];
}
        var charB = textB.match(/:(.)/)[1];
 
        return (charA < charB) ? -1 : (charA > charB) ? 1 : 0;
.mw-normal-catlinks ul li {
    });
    display: inline-block;
    $('.mw-normal-catlinks ul').empty().append($categories);
    width: 100%;
});
    box-sizing: border-box;
}
</style>

Revision as of 20:43, 17 March 2024

/* Any JavaScript here will be loaded for all users on every page load. */

// Sort categories alphabetically by the first character after the colon
$(function() {
    var $categories = $('.mw-normal-catlinks ul li');
    $categories.sort(function(a, b) {
        var textA = $(a).text().toUpperCase();
        var textB = $(b).text().toUpperCase();
        var charA = textA.match(/:(.)/)[1];
        var charB = textB.match(/:(.)/)[1];
        return (charA < charB) ? -1 : (charA > charB) ? 1 : 0;
    });
    $('.mw-normal-catlinks ul').empty().append($categories);
});