FANDOM


m (new i18n system, added custom selector for appending, firing a hook when loaded)
m (Added additional double-load check)
Line 15: Line 15:
 
i18no.loadMessages('ToggleSideBar').done(function(i18n) {
 
i18no.loadMessages('ToggleSideBar').done(function(i18n) {
 
i18n.useUserLang();
 
i18n.useUserLang();
  +
if($('#WikiaRail').length === 0 || $('#ToggleSideBarButton').length > 0) {
  +
return;
  +
}
 
$(window.ToggleSideBarSelector || '#WikiHeader .buttons').append(mw.html.element('button', {
 
$(window.ToggleSideBarSelector || '#WikiHeader .buttons').append(mw.html.element('button', {
 
class: 'wikia-menu-button secondary',
 
class: 'wikia-menu-button secondary',

Revision as of 20:02, February 21, 2017

/**
 * Name:        ToggleSideBar
 * Author:      KockaAdmiralac <1405223@gmail.com>
 * Description: Adds a button for toggling the side bar
 */
(function() {
    if($('#WikiaRail').length === 0 || $('#ToggleSideBarButton').length > 0) {
        return;
    }
    if(typeof window.dev === 'undefined' || typeof window.dev.i18n === 'undefined') {
        // Importing I18n-js library
        importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });
    }
    mw.hook('dev.i18n').add(function(i18no) {
        i18no.loadMessages('ToggleSideBar').done(function(i18n) {
            i18n.useUserLang();
            if($('#WikiaRail').length === 0 || $('#ToggleSideBarButton').length > 0) {
                return;
            }
            $(window.ToggleSideBarSelector || '#WikiHeader .buttons').append(mw.html.element('button', {
                class: 'wikia-menu-button secondary',
                id: 'ToggleSideBarButton'
            }, i18n.msg('toggle').escape()));
            $('#ToggleSideBarButton').click(function() {
                if($('#WikiaRail').css('display') === 'block') {
                    $('#WikiaRail').fadeToggle('slow', null, function() {
                        $('#WikiaMainContent').animate({ width: '100%' }, 'slow');
                    });
                } else {
                    $('#WikiaMainContent').animate({ width: ($('#WikiaPage').width() - 320) + 'px' }, 'slow', null, function() {
                        $('#WikiaRail').fadeToggle();
                    });
                }
            });
            mw.hook('ToggleSideBar.loaded').fire();
        });
    });
})();
Community content is available under CC-BY-SA unless otherwise noted.