User:Mike Dillon/Scripts/tabs.js

This is an old revision of this page, as edited by Mike Dillon (talk | contribs) at 22:53, 6 May 2007 (use i18n.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Requires: [[User:Mike Dillon/Scripts/i18n.js]]

/* <pre><nowiki> */

/* Messages */
wfMsg("en", "purgeTabLabel", "Purge");
wfMsg("en", "purgeTabTitle", "Purge this page from the server cache");

wfMsg("en", "lastDiffTabLabel", "Last");
wfMsg("en", "lastDiffTabTitle", "Show differences between this version and the previous revision");

// Duplicate link tab from the top to the bottom of the content area
addOnloadHook(function () {
    // Clone the original tabs and change the id to "mytabs"
    var tabs = document.getElementById('p-cactions').cloneNode(true);
    tabs.id = 'mytabs';

    // Find individual tabs with ids and prefix the ids with "mytabs-"
    var listitems = tabs.getElementsByTagName('LI');
    for (var i=0; i < listitems.length; i++) {
        if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id;
    }

    // Add the cloned tabs at the end of the "column-content" div
    document.getElementById('column-content').appendChild(tabs);
});

// Add a new list item to the page tabs
function addTab(url, name, id, title, key) {
    // Add tab to the top tabs
    addPortletLink('p-cactions', url, name, id, title, key);

    // Add tab to the bottom if the tabs have been cloned
    addPortletLink('mytabs', url, name, 'mytabs-' + id, title, key);
}

// Add a 'purge' and 'last' links to the tabs
addOnloadHook(function () {
    var x = document.getElementById('ca-history');
    if(!x) return;

    if(x.children) x = x.children[0].href;
    else x = x.childNodes[0].href;

    addTab(x.replace(/action=history/, "action=purge"),
        wfMsg("purgeTabLabel"), 'ca-purge', wfMsg("purgeTabTitle"));
    addTab(x.replace(/action=history/, "diff=prev&oldid=" + wgArticleId),
        wfMsg("lastDiffTabLabel"), 'ca-last', wfMsg("lastDiffTabTitle"));
});

/* </nowiki></pre> */