MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Make sidebar sections collapsible
*/
$(function(){
$root = $(':root');
$panel = $('#mw-panel');
$portals = $("#mw-panel .portal");
var s = function(){
$portals.each(function(index, el){
var $el = $(el);
var $id = $el.attr("id");
if(!$id){
return;
}
// for < 1366px
$el.removeClass('expanded');
// for >= 1366px
if(localStorage.getItem('sidebar_c_'+$id) === "y"){
$el.addClass('collapsed').find('.body').slideUp(0);
}
});
}
s();
$(window).on('resize', s);
$portals.on("click", "h3", function(event){
var $el = $(this).parent();
var $id = $el.attr("id");
if(!$id){
return;
}
event.stopPropagation();
var styles = getComputedStyle($root[0]);
//Note: jQuery's .css() can not handle inexistent custom property properly.
var sidebarWidth = parseInt(styles.getPropertyValue('--layout-sidebar-width')||styles.getPropertyValue('--main-layout-sidebar-width')) || 250;
if($panel.width() <= sidebarWidth){
$el.toggleClass('collapsed');
if($el.hasClass('collapsed')){ // more consistent between class and slide status.
localStorage.setItem('sidebar_c_'+$id, "y");
$el.find('.body').slideUp('fast');
}
else{
localStorage.setItem('sidebar_c_'+$id, "n");
$el.find('.body').slideDown('fast');
}
}
else{
$("#mw-panel .portal").not($el).removeClass('expanded');
$el.toggleClass('expanded');
}
});
});
// Scripts to use when viewing articles
$(function(){
if (mw.config.get('wgIsArticle') || window.location.href.indexOf('action=submit') > -1 || mw.config.get('wgNamespaceNumber') == -1) {
// Only if the page contains collapsible tables
if ( $('.collapsible, .expandable').length > 0 ) {
mw.loader.load( '/index.php?title=MediaWiki:CollapsibleTables.js&action=raw&ctype=text/javascript' );
}
}
});