FANDOM


m (It's not #WikiaPage's width that matters)
m (Better support for mobile devices)
Line 4: Line 4:
 
* Description: Adds a button for toggling the side bar
 
* Description: Adds a button for toggling the side bar
 
*/
 
*/
(function() {
+
require(['wikia.browserDetect'], function(detect) {
 
var $rail = $('#WikiaRail'),
 
var $rail = $('#WikiaRail'),
 
$wrapper = $('#WikiaMainContent');
 
$wrapper = $('#WikiaMainContent');
if(!$rail.exists() || window.ToggleSideBarLoaded) {
+
if (!$rail.exists() || window.ToggleSideBarLoaded) {
 
return;
 
return;
 
}
 
}
 
window.ToggleSideBarLoaded = true;
 
window.ToggleSideBarLoaded = true;
if(typeof window.dev === 'undefined' || typeof window.dev.i18n === 'undefined') {
+
if (!window.dev || !window.dev.i18n) {
 
// Importing I18n-js library
 
// Importing I18n-js library
importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });
+
importArticle({
  +
type: 'script',
  +
article: 'u:dev:MediaWiki:I18n-js/code.js'
  +
});
 
}
 
}
 
mw.hook('dev.i18n').add(function(i18no) {
 
mw.hook('dev.i18n').add(function(i18no) {
Line 22: Line 22:
 
id: 'toggle-side-bar-button',
 
id: 'toggle-side-bar-button',
 
text: i18n.msg('toggle').escape()
 
text: i18n.msg('toggle').escape()
})
+
}).appendTo(window.ToggleSideBarSelector || '.page-header__contribution-buttons')
.appendTo(window.ToggleSideBarSelector || '.page-header__contribution-buttons')
+
.click(function() {
.click(function() {
+
var mob = detect.isMobile();
if($rail.css('display') === 'block') {
+
if ($rail.css('display') === 'block') {
$rail.fadeToggle('slow', null, function() {
+
$rail.fadeToggle('slow', null, function() {
  +
if (!mob) {
 
$wrapper.animate({ width: '100%' }, 'slow');
 
$wrapper.animate({ width: '100%' }, 'slow');
});
+
}
} else {
+
});
$wrapper.animate({ width: ($('.WikiaPageContentWrapper').width() - 330) + 'px' }, 'slow', null, function() {
+
} else if (mob) {
  +
$rail.fadeToggle();
  +
} else {
  +
$wrapper.animate(
  +
{ width: ($('.WikiaPageContentWrapper').width() - 330) + 'px' },
  +
'slow',
  +
null,
  +
function() {
 
$rail.fadeToggle();
 
$rail.fadeToggle();
});
+
}
}
+
);
});
+
}
  +
});
 
mw.hook('ToggleSideBar.loaded').fire();
 
mw.hook('ToggleSideBar.loaded').fire();
 
});
 
});
 
});
 
});
})();
+
});

Revision as of 22:42, December 15, 2017

/**
 * Name:        ToggleSideBar
 * Author:      KockaAdmiralac <1405223@gmail.com>
 * Description: Adds a button for toggling the side bar
 */
require(['wikia.browserDetect'], function(detect) {
    var $rail = $('#WikiaRail'),
        $wrapper = $('#WikiaMainContent');
    if (!$rail.exists() || window.ToggleSideBarLoaded) {
        return;
    }
    window.ToggleSideBarLoaded = true;
    if (!window.dev || !window.dev.i18n) {
        // 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() {
                var mob = detect.isMobile();
                if ($rail.css('display') === 'block') {
                    $rail.fadeToggle('slow', null, function() {
                        if (!mob) {
                            $wrapper.animate({ width: '100%' }, 'slow');
                        }
                    });
                } else if (mob) {
                    $rail.fadeToggle();
                } else {
                    $wrapper.animate(
                        { width: ($('.WikiaPageContentWrapper').width() - 330) + 'px' },
                        'slow',
                        null,
                        function() {
                            $rail.fadeToggle();
                        }
                    );
                }
            });
            mw.hook('ToggleSideBar.loaded').fire();
        });
    });
});
Community content is available under CC-BY-SA unless otherwise noted.