FANDOM


//
/*jshint jquery:true, browser:true, es5:true, devel:true, camelcase:true, curly:false, undef:true, unused:true, bitwise:true, eqeqeq:true, forin:true, immed:true, latedef:true, newcap:true, noarg:true, unused:true, regexp:true, strict:true, trailing:true, maxcomplexity:10 */
/*global mediaWiki:true*/
 
(function (mw, $) {
    'use strict';
 
    if (mw.config.get('wgNamespaceNumber') !== 14 || 
        mw.config.get('skin') !== 'oasis' ||
        $.inArray('Sort option categories', mw.config.get('wgCategories')) === -1
    ) return;
 
    var pages = $('#mw-pages');
    if (!pages.length || $('.sortkey').length) return;
 
    function Title (title, continued, cssClass) {
        this.cssClass = cssClass;
        this.text = title;
        this.continued = continued;
    }
 
    Title.prototype.toString = function () {
        var text = this.text, id = '';
        if (this.continued) {
            text += ' cont.';
        } else {
            id = ' id="' + this.cssClass + ':' + text + '"';
        }
        return '<h3' + id + '>' + text + '</h3>';
    };
 
    function Link (title, href) {
        this.title = title;
        this.href = href;
    }
 
    Link.prototype.toString = function () {
        return '<a href="' + this.href + '" title="' + this.title + '">' + this.title + '</a>';
    };
 
    function List (title, continued, cssClass) {
        this.title = new Title(title, continued, cssClass);
        this.links = [];
    }
 
    List.prototype.addLink = function (title, href) {
        this.links.push(new Link(title, href));
    };
 
    List.prototype.toString = function () {
        if (!this.links.length) return '';
        return this.title + '<ul><li>' + this.links.join('</li><li>') + '</li></ul>';
    };
 
    function Column (cssClass) {
        this.cssClass = cssClass;
        this.count = 0;
        this.data = [];
    }
 
    Column.prototype.addList = function (title, continued) {
        this.count++;
        this.current = new List(title, continued, this.cssClass);
        this.data.push(this.current);
    };
 
    Column.prototype.addLink = function (title, href) {
        this.count++;
        this.current.addLink(title, href);
    };
 
    Column.prototype.toString = function () {
        return '<td style="width: 33%; vertical-align: text-top;">' + this.data.join('') + '</td>';
    };
 
    function Table (perColumn, cssClass) {
        this.cssClass = cssClass;
        this.cols = [];
        this.current = false;
        this.first = false;
        this.perColumn = perColumn;
    }
 
    Table.prototype.addLink = function (title, href, first) {
        if (!this.current || this.current.count === this.perColumn) {
            this.current = new Column(this.cssClass);
            this.cols.push(this.current);
        }
        if (first !== this.first || this.current.count === 0) {
            this.current.addList(first, first === this.first && this.current.count === 0);
            this.first = first;
        }
        this.current.addLink(title, href);
    };
 
    Table.prototype.toString = function () {
        return '<table class="' + this.cssClass + '" style="width: 100%"><tbody><tr>' + this.cols.join('') + '</tr></tbody></table>';
    };
 
    Table.getAlphabet = function (titles) {
        var alphabet = [];
        for (var i = 0; i < titles.length; i++) {
            if ($.inArray(titles[i][0].toUpperCase(), alphabet) === -1) {
                alphabet.push(titles[i][0].toUpperCase());
            }
        }
        return alphabet;
    };
 
    Table.create = function (titles) {
        var title, table,
            alphabet = Table.getAlphabet(titles);
        table = new Table(
            //Math.floor((alphabet.length + titles.length) / 3) + 1,
            Math.max(1, Math.floor((alphabet.length * 1.25 + titles.length) / 3)),
            'alpha'
        );
        if (titles.length > 200) {
            createSideNav(alphabet, 'alpha');
        }
        while (titles.length) {
            title = titles.shift();
            table.addLink(title, '/wiki/' + encodeURIComponent(title), title[0].toUpperCase());
        }
        return table.toString();
    };
 
    Table.rebuild = function (titles) {
        var title, table,
            alphabet = [], total = 0;
        if (!alphabet.length) {
            $.each(titles, function (first, list) {
                alphabet.push(first);
                total += list.length;
            });
        }
        createSideNav(alphabet, 'sortkey');
        table = new Table(Math.max(1, Math.floor((alphabet.length * 1.25 + total) / 3)), 'sortkey');
        $.each(titles, function (first, list) {
            while (list.length) {
                title = list.shift();
                table.addLink(title, '/wiki/' + encodeURIComponent(title), first);
            }
        });
        while (titles.length) {
            title = titles.shift();
            table.addLink(title, '/wiki/' + encodeURIComponent(title), title[0].toUpperCase());
        }
        return table.toString();
    };
 
    function createSideNav (alphabet, cssClass) {
        var color = $('.WikiaPage').css('border-left-color'),
            links = [];
        for (var i = 0; i < alphabet.length; i++) {
            links.push('<a href="#' + cssClass + ':' + alphabet[i] + '">' + alphabet[i] + '</a>');
        }
 
        $('head').append('<style type="text/css">.letters{width: 10px; padding: 5px; minHeight: 50px; left: 0; top: 0; border-top-left-radius: 4px; border-bottom-left-radius: 4px; border-top: 1px solid ' + color + '; border-left: 1px solid ' + color + '; border-bottom: 1px solid ' + color + '; border-right: none; position: fixed; background: ' + window.sassParams['color-body'] + '; z-index: 2; line-height: 140%; white-space: pre; text-align: center}</style>');
 
        var letters = $('<div class="letters"> </div>')
        .appendTo(document.body)
        .addClass(cssClass)
        .html(links.join("\n"));
 
        var $win = $(window),
            pageWidth = $('#WikiaPage').width(),
            lettersHeight = letters.height(),
            setPosition = function () {
                letters
                .css({
                    top: Math.floor(($win.height() - lettersHeight) / 2) + 'px',
                    left: Math.floor(($win.width() + $win.scrollLeft() - pageWidth) / 2) - 20 + 'px'
                });
            };
 
        setPosition();
        $win.resize(setPosition);
    }
 
    function getCatMembers (cat, cmcontinue) {
        var defer = $.Deferred(),
            url = '/api.php?format=json&action=query&list=categorymembers&cmprop=title|sortkeyprefix&cmtype=page&cmlimit=500';
        url += '&cmtitle=Category:' + cat;
        if (cmcontinue) {
            url += '&cmcontinue=' + cmcontinue;
        }
        $.getJSON(url)
        .done(function (data) {
            if (data.query && data.query.categorymembers && $.isArray(data.query.categorymembers)) {
                var lists = {
                        sortkey: {},
                        alpha: []
                    },
                    m, key,
                    members = data.query.categorymembers;
                for (var i = 0; i < members.length; i++) {
                    m = members[i];
                    key = (m.sortkeyprefix || m.title)[0].toUpperCase();
                    lists.sortkey[key] = lists.sortkey[key] || [];
                    lists.sortkey[key].push(m.title);
                    lists.alpha.push(m.title);
                }
                if (data['query-continue'] && data['query-continue'].categorymembers && data['query-continue'].categorymembers.cmcontinue) {
                    cmcontinue = data['query-continue'].categorymembers.cmcontinue;
                    getCatMembers(cat, cmcontinue)
                    .done(function (nextList) {
                        $.each(lists.sortkey, function (i, v) {
                            if (!nextList.sortkey[i]) return;
                            lists.sortkey[i] = v.concat(nextList.sortkey[i]);
                            delete nextList.sortkey[i];
                        });
                        lists.sortkey = $.extend(lists.sortkey, nextList.sortkey);
                        lists.alpha = lists.alpha.concat(nextList.alpha);
                        defer.resolve(lists);
                    });
                } else {
                    defer.resolve(lists);
                }
            }
        });
        return defer.promise();
    }
 
    function getCat (cat) {
        var defer = $.Deferred();
        getCatMembers(cat || mw.config.get('wgTitle'))
        .done(function (lists) {
            lists.alpha.sort();
            defer.resolve(lists);
        });
        return defer.promise();
    }
 
    function addRadioButtons (createAlphaSort) {
        var $p = pages.find('p').first();
        $p.html($p.html() +
            ' Sort by: '+
            '<input type="radio" name="sort" value="sortkey" checked="checked"> '+
            '<label>Last Name</label> ' +
            '<input type="radio" name="sort" value="alpha"> '+
            '<label>First Name</label> '
        );
 
        pages.find('input[name="sort"]')
        .click(function () {
            $('.alpha').add('.sortkey').css('display', 'none');
            $('.' + $(this).val()).css('display', 'block');
        })
        .eq(1).one('click', createAlphaSort);
    }
 
    var table = pages.find('table').first().addClass('sortkey');
 
    if (pages.children('a').length) { // category is oversized
        var h2 = pages.children('h2').clone(),
            m = pages.children('p').text().match(/(\d+)\D+$/m),
            total = m[1] || 'NaN';
        pages.empty()
        .append(h2)
        .append(
            '<p>This category contains ' + total + ' pages.</p>' +
            '<div id="cat-placeholder" class="wikiaThrobber" style="width: 100%; height: 100px; position: relative;"> </div>'
        );
        getCat()
        .done(function (lists) {
            $('#cat-placeholder').remove();
            table = $(Table.rebuild(lists.sortkey))
            .appendTo(pages);
            addRadioButtons(function () {
               table.after(Table.create(lists.alpha));
            });
        });
    } else {
        addRadioButtons(function () {
            var titles = [];
            table.find('a').each(function () {
                titles.push($(this).text());
            });
            table.after(Table.create(titles.sort()));
        });
    }
}(mediaWiki, jQuery));
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.