FANDOM


(Made this snippet public)
 
m (new i18n system, added custom selector for appending, firing a hook when loaded)
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
* Description: Adds a button for toggling the side bar
 
* Description: Adds a button for toggling the side bar
 
*/
 
*/
$(function() {
+
(function() {
if($("#WikiaRail").length === 0) {
+
if($('#WikiaRail').length === 0 || $('#ToggleSideBarButton').length > 0) {
 
return;
 
return;
 
}
 
}
$("#WikiHeader .buttons").append(mw.html.element("button", {
+
if(typeof window.dev === 'undefined' || typeof window.dev.i18n === 'undefined') {
class: "wikia-menu-button secondary",
+
// Importing I18n-js library
id: "ToggleSideBarButton"
+
importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });
}, "Toggle side bar"));
+
}
$("#ToggleSideBarButton").click(function() {
+
mw.hook('dev.i18n').add(function(i18no) {
if($("#WikiaRail").css("display") === "block") {
+
i18no.loadMessages('ToggleSideBar').done(function(i18n) {
$("#WikiaRail").fadeToggle("slow", null, function() {
+
i18n.useUserLang();
$("#WikiaMainContent").animate({width: "100%"}, "slow");
+
$(window.ToggleSideBarSelector || '#WikiHeader .buttons').append(mw.html.element('button', {
});
+
class: 'wikia-menu-button secondary',
} else {
+
id: 'ToggleSideBarButton'
$("#WikiaMainContent").animate({width: ($("#WikiaPage").width() - 320) + "px"}, "slow", null, function() {
+
}, i18n.msg('toggle').escape()));
$("#WikiaRail").fadeToggle();
+
$('#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();
  +
});
 
});
 
});
});
+
})();

Revision as of 19:45, February 18, 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();
            $(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.