MediaWiki:Gadget-sister-projects.js

From Path of Exile 2 Wiki
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes. The simplest method that will work for most users is to hold down the ⇧ Shift key and click the Reload toolbar button. For details and other methods, see Help:Clear your browser cache.

/* global mw */
/* jshint strict:true, jquery:true, esversion:5, bitwise:true, curly:true, eqeqeq:true, undef:true, latedef:true, trailingcomma:true */

( function () {
'use strict';

/* Fires when wiki content is added. */
mw.hook('wikipage.content').add( function ($wikipageContent) {

    var namespace = mw.config.get('wgNamespaceNumber');

    /*
     * Add menu tab
     */
    var addTab = function (project, interwiki, page) {
        var url = mw.util.getUrl(interwiki + ':' + page);
        var tooltip = 'View this page on ' + project;
        if ( namespace === 0 ) {
            // Article namespace
            tooltip = 'View this article on ' + project;
        }
        var link = mw.util.addPortletLink(
        'p-namespaces',
            url,
            project,
            'ca-sister-' + interwiki,
            tooltip
        );
        link.classList.add('sister-tab');
    }

    if ( namespace === -1 || namespace === 8 ) {
        // Add tabs on Special and MediaWiki pages
        var page = mw.config.get('wgPageName');
        addTab('Path of Exile Wiki', 'poewiki', page);
    } else {
        // Add tabs from Template:Sister
        var sisterData = document.getElementsByClassName('js-sister-data');
        if (sisterData.length) {
            for ( var i = 0; i < sisterData.length; i++ ) {
                var data = sisterData[i].children;
                for ( var j = 0; j < data.length; j++ ) {
                    addTab(
                        data[j].dataset.project,
                        data[j].dataset.interwiki,
                        data[j].dataset.page
                    );
                }
            }
        }
    }

} );

}() );