User:Mike Dillon/Scripts/tabs.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

// Requires: [[User:Mike Dillon/Scripts/addlilink.js]]

/* <pre><nowiki> */

// 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"),
        'purge', 'ca-purge', 'Purge the internal cache for this page', 'g');
    addTab(x.replace(/action=history/, "diff=cur&oldid=prev"),
        'last', 'ca-last', 'Show most recent diff');
});

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