FANDOM


m (Added additional double-load check)
m (Better double run protection, element caching, jQueryfying, change 320 to 330 because it was looking weird for me on 320)
(2 intermediate revisions by one user not shown)
Line 5: Line 5:
 
*/
 
*/
 
(function() {
 
(function() {
if($('#WikiaRail').length === 0 || $('#ToggleSideBarButton').length > 0) {
+
var $rail = $('#WikiaRail'),
  +
$wrapper = $('#WikiaMainContent');
  +
if(!$rail.exists() || window.ToggleSideBarLoaded) {
 
return;
 
return;
 
}
 
}
  +
window.ToggleSideBarLoaded = true;
 
if(typeof window.dev === 'undefined' || typeof window.dev.i18n === 'undefined') {
 
if(typeof window.dev === 'undefined' || typeof window.dev.i18n === 'undefined') {
 
// Importing I18n-js library
 
// Importing I18n-js library
Line 15: Line 16:
 
i18no.loadMessages('ToggleSideBar').done(function(i18n) {
 
i18no.loadMessages('ToggleSideBar').done(function(i18n) {
 
i18n.useUserLang();
 
i18n.useUserLang();
if($('#WikiaRail').length === 0 || $('#ToggleSideBarButton').length > 0) {
+
$('<a>', {
return;
+
'class': 'wds-button wds-is-squished wds-is-secondary',
}
+
id: 'toggle-side-bar-button',
$(window.ToggleSideBarSelector || '#WikiHeader .buttons').append(mw.html.element('button', {
+
text: i18n.msg('toggle').escape()
class: 'wikia-menu-button secondary',
+
})
id: 'ToggleSideBarButton'
+
.appendTo(window.ToggleSideBarSelector || '.page-header__contribution-buttons')
}, i18n.msg('toggle').escape()));
+
.click(function() {
$('#ToggleSideBarButton').click(function() {
+
if($rail.css('display') === 'block') {
if($('#WikiaRail').css('display') === 'block') {
+
$rail.fadeToggle('slow', null, function() {
$('#WikiaRail').fadeToggle('slow', null, function() {
+
$wrapper.animate({ width: '100%' }, 'slow');
$('#WikiaMainContent').animate({ width: '100%' }, 'slow');
+
});
});
+
} else {
} else {
+
$wrapper.animate({ width: ($('#WikiaPage').width() - 330) + 'px' }, 'slow', null, function() {
$('#WikiaMainContent').animate({ width: ($('#WikiaPage').width() - 320) + 'px' }, 'slow', null, function() {
+
$rail.fadeToggle();
$('#WikiaRail').fadeToggle();
+
});
});
+
}
}
+
});
});
 
 
mw.hook('ToggleSideBar.loaded').fire();
 
mw.hook('ToggleSideBar.loaded').fire();
 
});
 
});

Revision as of 18:52, July 13, 2017

/**
 * Name:        ToggleSideBar
 * Author:      KockaAdmiralac <1405223@gmail.com>
 * Description: Adds a button for toggling the side bar
 */
(function() {
    var $rail = $('#WikiaRail'),
        $wrapper = $('#WikiaMainContent');
    if(!$rail.exists() || window.ToggleSideBarLoaded) {
        return;
    }
    window.ToggleSideBarLoaded = true;
    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();
            $('<a>', {
                'class': 'wds-button wds-is-squished wds-is-secondary',
                id: 'toggle-side-bar-button',
                text: i18n.msg('toggle').escape()
            })
                .appendTo(window.ToggleSideBarSelector || '.page-header__contribution-buttons')
                .click(function() {
                    if($rail.css('display') === 'block') {
                        $rail.fadeToggle('slow', null, function() {
                            $wrapper.animate({ width: '100%' }, 'slow');
                        });
                    } else {
                        $wrapper.animate({ width: ($('#WikiaPage').width() - 330) + 'px' }, 'slow', null, function() {
                            $rail.fadeToggle();
                        });
                    }
                });
            mw.hook('ToggleSideBar.loaded').fire();
        });
    });
})();
Community content is available under CC-BY-SA unless otherwise noted.