MediaWiki:Gadget-topIcons.js: Difference between revisions

From RuneRealm Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
if (namespace === -1 || namespace === 8) {
if (namespace === -1 || namespace === 8) {
var page = mw.config.get('wgPageName');
var page = mw.config.get('wgPageName');
addLink('Discord');
addLink('the RuneScape Wiki', 'rsw', page);
// addLink('Discord', 'discord', page);
addLink('the RuneScape Classic Wiki', 'classicrsw', page);
// addLink('the RuneScape Wiki', 'rsw', page);
addLink('the Meta Weird Gloop Wiki', 'meta', page);
// addLink('the RuneScape Classic Wiki', 'classicrsw', page);
// addLink('the Meta Weird Gloop Wiki', 'meta', page);
} else {
} else {
// make this work when "Show preview without reloading the page" is checked
// make this work when "Show preview without reloading the page" is checked
Line 33: Line 31:
});
});
}
}
//function addLink(page) {
// var url = 'https://www.runerealm.org/discord';
// var title = 'Join our Discord to talk about wiki content or becoming an editor.';


function addLink(wikiname, interwiki, page) {
// var link = mw.util.addPortletLink('p-namespaces', url, '',
var url = mw.util.getUrl(interwiki + ':' + page);
// // no text - use background-image instead
var title = wikiname + ' also has an article on ' + page + '.';
// 'gadget-external-discord',
// // button id
// title // title text shown on hover
// );


// wikipedia links aren't forwarded - see [[Special:Interwiki]]
// // for styling all links at once - addPortletLink only sets an id
if (interwiki === 'wikipedia') {
// //$(link).addClass('gadget-external-icon');
url = '//en.wikipedia.org/wiki/' + encodeURIComponent(page);
//}
}
function addLink(page) {
var url = mw.util.getUrl('discord:' + page);
var title = 'Discord also has an article on ' + page + '.';


// Special and MediaWiki namespaces
// Special and MediaWiki namespaces
if (namespace === -1 || namespace === 8) {
if (namespace === -1 || namespace === 8) {
url += window.location.search; // include url parameters
url += window.location.search; // include url parameters
title = 'Open this page on Discord.';
title = 'Open this page on ' + wikiname + '.';
}
}
var link = mw.util.addPortletLink('p-namespaces', url, '',
var link = mw.util.addPortletLink('p-namespaces', url, '',
// no text - use background-image instead
// no text - use background-image instead
'gadget-external-discord',
'gadget-external-' + interwiki,
// button id
// button id
title // title text shown on hover
title // title text shown on hover
Line 68: Line 56:
$(link).addClass('gadget-external-icon');
$(link).addClass('gadget-external-icon');
}
}
//function addLink(wikiname, interwiki, page) {
// var url = mw.util.getUrl(interwiki + ':' + page);
// var title = wikiname + ' also has an article on ' + page + '.';

// // wikipedia links aren't forwarded - see [[Special:Interwiki]]
// if (interwiki === 'wikipedia') {
// url = '//en.wikipedia.org/wiki/' + encodeURIComponent(page);
// }

// // Special and MediaWiki namespaces
// if (namespace === -1 || namespace === 8) {
// url += window.location.search; // include url parameters
// title = 'Open this page on ' + wikiname + '.';
// }
// var link = mw.util.addPortletLink('p-namespaces', url, '',
// // no text - use background-image instead
// 'gadget-external-' + interwiki,
// // button id
// title // title text shown on hover
// );

// // for styling all links at once - addPortletLink only sets an id
// $(link).addClass('gadget-external-icon');
//}
})(jQuery, mediaWiki);
})(jQuery, mediaWiki);

Latest revision as of 12:31, 20 October 2024

"use strict";

/**
 * Moves icons from [[Template:External]] to the top bar, next to "Article" and "Talk" tabs;
 * rewritten from scratch for modern MediaWiki
 */
(function ($, mw) {
  var namespace = mw.config.get('wgNamespaceNumber');

  // automatically show externals on Special and MediaWiki namespaces
  if (namespace === -1 || namespace === 8) {
    var page = mw.config.get('wgPageName');
    addLink('the RuneScape Wiki', 'rsw', page);
    addLink('the RuneScape Classic Wiki', 'classicrsw', page);
    addLink('the Meta Weird Gloop Wiki', 'meta', page);
  } else {
    // make this work when "Show preview without reloading the page" is checked
    mw.hook('wikipage.content').add(function ($content) {
      if (!$content.has('.rs-external-header-links').length) return;

      // clear existing externals first so previewing doesn't add an infinite amount
      $('.gadget-external-icon').remove();

      // convert whatever [[Template:External]] gives us
      $('.rs-header-icon').each(function (index, icon) {
        addLink(icon.dataset.wikiname, icon.dataset.interwiki, icon.dataset.page);
      });

      // clean up
      $('.rs-external-header-links').remove();
    });
  }

  function addLink(wikiname, interwiki, page) {
    var url = mw.util.getUrl(interwiki + ':' + page);
    var title = wikiname + ' also has an article on ' + page + '.';

    // wikipedia links aren't forwarded - see [[Special:Interwiki]]
    if (interwiki === 'wikipedia') {
      url = '//en.wikipedia.org/wiki/' + encodeURIComponent(page);
    }

    // Special and MediaWiki namespaces
    if (namespace === -1 || namespace === 8) {
      url += window.location.search; // include url parameters
      title = 'Open this page on ' + wikiname + '.';
    }
    var link = mw.util.addPortletLink('p-namespaces', url, '',
    // no text - use background-image instead
    'gadget-external-' + interwiki,
    // button id
    title // title text shown on hover
    );

    // for styling all links at once - addPortletLink only sets an id
    $(link).addClass('gadget-external-icon');
  }
})(jQuery, mediaWiki);