MediaWiki:Common.js: Difference between revisions

From Phidgets Support
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 58: Line 58:
   var el = document.getElementById('toc');
   var el = document.getElementById('toc');
   var scr = $(this).scrollTop();
   var scr = $(this).scrollTop();
   if (window.innerWidth >= 1400) {
 
   if ((window.innerWidth >= 1400) && (el != null)) {
     if (scr > 0 && scr < 200){  
     if (scr > 0 && scr < 200){  
       el.style.top = 200-scr + "px";
       el.style.top = 200-scr + "px";

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