MediaWiki:Common.js: Difference between revisions

From Phidgets Support
No edit summary
No edit summary
 
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
/**
/**
  * Redirect User:Name/skin.js and skin.css to the current skin's pages
  * Redirect User:Name/skin.js and skin.css to the current skin's pages
  * (unless the 'skin' page really exists)
  * (unless the 'skin' page really exists).
  * @source: http://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
*
  * @rev: 2
* Dependencies: mediawiki.util
*
  * @source https://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
  * @revision 2016-04-13
  */
  */
 
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
if ( mw.config.get( 'wgArticleId' ) == 0 && mw.config.get( 'wgNamespaceNumber' ) == 2 ) {
mw.loader.using( 'mediawiki.util', function () {
        var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
        // Make sure there was a part before and after the slash
// Make sure there was a part before and after the slash
        // And that the latter is 'skin.js' or 'skin.css'
// And that the latter is 'skin.js' or 'skin.css'
        if ( titleParts.length == 2 ) {
if ( titleParts.length === 2 ) {
                var userSkinPage = titleParts.shift() + '/' + mw.config.get( 'skin' );
var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );
                if ( titleParts.slice(-1) == 'skin.js' ) {
if ( titleParts[1] === 'skin.js' ) {
                        window.location.href = mw.util.wikiGetlink( userSkinPage + '.js' );
window.location.href = mw.util.getUrl( userSkinPage + '.js' );
                } else if ( titleParts.slice(-1) == 'skin.css' ) {
} else if ( titleParts[1] === 'skin.css' ) {
                        window.location.href = mw.util.wikiGetlink( userSkinPage + '.css' );
window.location.href = mw.util.getUrl( userSkinPage + '.css' );
                }
}
        }
}
} );
}
}
   
   
// Book specific
// Book specific
var wgBookName = ( mw.config.get( 'wgPageName' ).split( '/', 1)[0] || '' ).split( ':', 2 ).join( ':' );
var wgBookName = ( mw.config.get( 'wgPageName' ).split( '/', 1)[0] || '' ).split( ':', 2 ).join( ':' );
importStylesheet('MediaWiki:Common.css/' + wgBookName);
mw.loader.load( '/docs/index.php?title=MediaWiki:Common.css/'+wgBookName+'&action=raw&ctype=text/css', 'text/css' );
   
   
// Imported scripts
// Imported scripts
importScript('MediaWiki:Common.js/Relics.js');
mw.loader.load( '/docs/index.php?title=MediaWiki:Common.js/CollapseElements.js&action=raw&ctype=text/javascript');
importScript('MediaWiki:Common.js/ExtraTools.js');
importScript('MediaWiki:Common.js/CollapseElements.js');
importScript('MediaWiki:Common.js/NavigationTabs.js');
importScript('MediaWiki:Common.js/Displaytitle.js');
importScript('MediaWiki:Common.js/RandomBook.js');
importScript('MediaWiki:Common.js/Perbook.js');
importScript('MediaWiki:Common.js/tabs.js');
importScript('MediaWiki:Common.js/top.js');
importScript('MediaWiki:Common.js/review.js');
importScript('MediaWiki:Common.js/Categories.js');
importScript('MediaWiki:Common.js/use.js');
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Watchlist' ) {
importScript('MediaWiki:Common.js/WatchlistNotice.js');
} else if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit', 'upload'] ) != -1 ) {
importScript('MediaWiki:Common.js/Special_characters.js');
importScript('MediaWiki:Common.js/Toolbox.js');
}
// Load sysop-specific JavaScript/CSS from [[MediaWiki:Common.js/Sysop.js]] and [[MediaWiki:Common.css/Sysop.css]]
if ( $.inArray( 'sysop', wgUserGroups) > -1 ) {
importStylesheet('MediaWiki:Common.css/Sysop.css');
if ( !window.disableSysopJS ) {
  $(function(){
  importScript('MediaWiki:Common.js/Sysop.js');
  });
}
}


// User guide sections
$('.ugcHeader').click(function () {
var hed = $(this)[0];
var con = $(this).next('.ugcContent')[0];
if ($(this).children('span.ugcHeaderIcon').hasClass("down"))
$(this).children('span.ugcHeaderIcon').removeClass("down");
else
$(this).children('span.ugcHeaderIcon').addClass("down");
$(this).parent().find('.ugcContent').each(function (i, item) {
if ($(item)[0] != con)
$(item).slideUp();
});


// Custom script for Mobile Navigation
$(this).parent().find('.ugcHeader').each(function (i, item) {
var menuCtn = $('#ph-dropDownMenu');
if ($(item)[0] != hed)
var searchCtn = $('#ph-dropDownSearch');
$(item).children('span.ugcHeaderIcon').removeClass("down");
var menuBtn = $('#mb-menu');
});
var searchBtn = $('#mb-search');
var tables = $('table');
var admintoolbox = $('#p-admin-toolbox');


searchBtn.click(function() {
$(this).next('.ugcContent').slideToggle();
  if(menuCtn.css('display') !== 'none') {
return false;
    menuCtn.css('display','none');
    if(menuBtn.hasClass('mb-menu-close'))
      menuBtn.removeClass('mb-menu-close')
  }
  if(searchCtn.css('display') === 'none') {
    searchCtn.fadeIn(200);
    return;
  } else {
    searchCtn.fadeOut(200);
    return;
  }
});
});


menuBtn.click(function() {
///////////////////////////////////////////// Sticky TOC
   if(searchCtn.css('display') !== 'none') {
function scrollTOC() {
     searchCtn.css('display','none');
   var el = document.getElementById('toc');
  var scr = $(this).scrollTop();
 
  if ((window.innerWidth >= 1400) && (el != null)) {
     if (scr > 0 && scr < 200){
      el.style.top = 200-scr + "px";
    }
    else if (scr >= 200){
      el.style.top = "0px";
    }
    else
    {
      el.style.top = "220px";
    }
   }
   }
  if(menuCtn.css('display') === 'none') {
    menuCtn.fadeIn(200);
    $(this).addClass('mb-menu-close');
    return;
  } else {
    menuCtn.fadeOut(200);
    $(this).removeClass('mb-menu-close');
    return;
  }
});
if($('#p-views').css('display') === 'block' && $('#p-cactions').css('display') === 'block') {
  $('.ph-search-group').addClass('hasAdminGroup');
    $('.ph-admin-group').addClass('group-visible');
}
}


tables.each(function() {
$(window).scroll(scrollTOC); // move the TOC whenever page scrolls
  $(this).addClass('table').attr('border','0');
$( document ).ready(scrollTOC); // move the TOC on refresh
  $(this).wrap("<div class='table-responsive'></div>");
});
 
admintoolbox.each(function() {
  var toolbox = $(this);
  toolbox.removeClass('portal').addClass('vectorMenu');
  var menuCtn = toolbox.find('div.body');
  menuCtn.removeClass('body').addClass('menu');
});
 
 
$('.ph-tools-group').addClass('group-visible');
 
// Scroll to top button
$(window).scroll(function () {
  var toTopBtn = $('.ph-to-top');
 
  if ($(this).scrollTop() > 400) {
    toTopBtn.stop(true, true).fadeIn();
  } else {
    toTopBtn.stop(true, true).fadeOut();
  }
});
 
$('.to-top').click(function () {
  $("html, body").animate({ scrollTop: 0 }, 600);
  return false;
});

Latest revision as of 17:01, 8 August 2023

/**
 * Redirect User:Name/skin.js and skin.css to the current skin's pages
 * (unless the 'skin' page really exists).
 *
 * Dependencies: mediawiki.util
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Redirect_skin.js
 * @revision 2016-04-13
 */
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
	mw.loader.using( 'mediawiki.util', function () {
		var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
		// Make sure there was a part before and after the slash
		// And that the latter is 'skin.js' or 'skin.css'
		if ( titleParts.length === 2 ) {
			var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );
			if ( titleParts[1] === 'skin.js' ) {
				window.location.href = mw.util.getUrl( userSkinPage + '.js' );
			} else if ( titleParts[1] === 'skin.css' ) {
				window.location.href = mw.util.getUrl( userSkinPage + '.css' );
			}
		}
	} );
}
 
// Book specific
var wgBookName = ( mw.config.get( 'wgPageName' ).split( '/', 1)[0] || '' ).split( ':', 2 ).join( ':' );
mw.loader.load( '/docs/index.php?title=MediaWiki:Common.css/'+wgBookName+'&action=raw&ctype=text/css', 'text/css' );
 
// Imported scripts
mw.loader.load( '/docs/index.php?title=MediaWiki:Common.js/CollapseElements.js&action=raw&ctype=text/javascript');

// User guide sections
$('.ugcHeader').click(function () {
	var hed = $(this)[0];
	var con = $(this).next('.ugcContent')[0];
	if ($(this).children('span.ugcHeaderIcon').hasClass("down"))
		$(this).children('span.ugcHeaderIcon').removeClass("down");
	else
		$(this).children('span.ugcHeaderIcon').addClass("down");
	
	$(this).parent().find('.ugcContent').each(function (i, item) {
		if ($(item)[0] != con)
			$(item).slideUp();
	});

	$(this).parent().find('.ugcHeader').each(function (i, item) {
		if ($(item)[0] != hed)
			$(item).children('span.ugcHeaderIcon').removeClass("down");
	});

	$(this).next('.ugcContent').slideToggle();
	return false;
});

///////////////////////////////////////////// Sticky TOC
function scrollTOC() {
  var el = document.getElementById('toc');
  var scr = $(this).scrollTop();
  
  if ((window.innerWidth >= 1400) && (el != null)) {
    if (scr > 0 && scr < 200){ 
      el.style.top = 200-scr + "px";
    }
    else if (scr >= 200){ 
      el.style.top = "0px";
    }
    else
    {
      el.style.top = "220px";
    }
  }
}

$(window).scroll(scrollTOC); // move the TOC whenever page scrolls
$( document ).ready(scrollTOC); // move the TOC on refresh