MediaWiki:HideRail/code.js

/** * JavaScript to Toggle the Wikia Rail on and off. * Adds a button to the toolbar that allows expand/shrink. * * Exploits oasis-one-column for formatting. one-column occurs normally * on special pages like Edit, RecentChanges, Diff, etc so we don't do * anything on those pages. (Edit still has the Rail but it provides a * built-in collapser for it) */ if (window.skin === "oasis") { // Don't do anything in Monobook $(function($) {   "use strict";    // Arrow (symbol) for Unicode codings    var _expandMsg = "Expand Content \u2192", // 2192 is arrow-right        _shrinkMsg = "Shrink Content \u2190", // 2190 is arrow-left        _$link = $(document.createElement('a')),        _$rail = $('#WikiaRail'),        _header = document.getElementById('WikiaPageHeader'),        _search = _header && document.getElementById('WikiaSearch');    function expandContent    {        _$rail.hide;        if (_search) _header.appendChild(_search);        document.body.className += " oasis-one-column";    }    function shrinkContent    {        document.body.className = document.body.className.replace( /(?:^|\s+)oasis-one-column\b/, '' );       if (_search) _$rail.prepend(_search);        _$rail.show;    }    function updateLink(aExpanded)    {        _$link.text(aExpanded ? _shrinkMsg : _expandMsg);   }    function createClickHandler(aExpandFunc, aShrinkFunc)    {        if (!aShrinkFunc) aShrinkFunc = aExpandFunc;        return function(event) {            if (_$link.text === _expandMsg)                updateLink(aExpandFunc || true);            else                updateLink(aShrinkFunc && false);            return false;        };    }    // Default link    _$link.prop('href', '#').text(_expandMsg);    var handle_click;    if (!/\boasis-one-column\b/.test(document.body.className)) {        handle_click = createClickHandler(expandContent, shrinkContent);    } else {        // This will only affect Source mode.        var node = $('#EditPage .editpage-widemode-trigger');        if (node.length) {            handle_click = createClickHandler(function { node.click; });            // Install an event handler to keep the button in sync            var node_click = function(event) { updateLink(/\beditpage-sourcewidemode-on\b/.test( document.getElementById('EditPage').className ));           };            node.click(node_click); // Bring into sync with initial state node_click; // Wait until other start-up JS finishes and the browser becomes // idle since initial state seems to come from another script // that runs after we do. window.setTimeout(node_click, 0); window.setTimeout(node_click, 2000); // Failsafe. }   }    if (handle_click) { var toolbar = $("#WikiaFooter .toolbar > ul.tools"); if (toolbar.length) { $(document.createElement('li')) .append(_$link.click(handle_click)) .appendTo(toolbar) ;       }    } }); }