Actions

MediaWiki

Difference between revisions of "Common.js"

From Sonic Retro

 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
+
// PootTabs - it poots tabs on pages.
 
+
var pootTabsHere = {
/** Import module *************************************************************
+
animationsEnabled: $.support.opacity,
  *
+
getTab:function(poot, index) {
  *  Description: Includes a raw wiki page as javascript or CSS,  
+
return $(poot.children('.poot-tabs').children('ul').children('li')[parseInt(index)]);
  *              used for including user made modules.
+
},
  *  Maintainers: [[User:AzaToth]]
+
changeTab:function(poot, index, duration, force) {
  */
+
if(index == parseInt(poot.attr('pootSelected')) && !force && duration) return;
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
+
if(!pootTabsHere.animationsEnabled) {
function importScript( page ) {
+
duration = 0;
    if( importedScripts[page] ) {
+
}
        return;
+
poot.attr('pootSelected', index.toString());
    }
+
var babies = poot.children('.poot-tabs-content').children();
    importedScripts[page] = true;
+
babies.each(function() {
    var url = wgScriptPath
+
$(this).fadeOut(duration, function(){
            + '/index.php?title='
+
$(this).removeClass('poot-tabs-selected');
            + encodeURIComponent( page.replace( / /g, '_' ) )
+
});
            + '&action=raw&ctype=text/javascript';
+
});
    var scriptElem = document.createElement( 'script' );
+
$(babies[index]).each(function() {
    scriptElem.setAttribute( 'src' , url );
+
$(this).fadeIn(duration, function(){
    scriptElem.setAttribute( 'type' , 'text/javascript' );
+
$(this).addClass('poot-tabs-selected');
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
+
});
}
+
});
+
var cowtabs = poot.children('.poot-tabs').children('ul').children('li');
function importStylesheet( page ) {
+
cowtabs.removeClass('poot-tabs-selected');
    var sheet = '@import "'
+
$(cowtabs[index]).addClass('poot-tabs-selected');
              + wgScriptPath
+
pootTabsHere.updatePoot(poot, $(babies[index]).height());
              + '/index.php?title='
+
},
              + encodeURIComponent( page.replace( / /g, '_' ) )
+
updatePoot:function(poot, babysize) {
              + '&action=raw&ctype=text/css";'
+
poot.find('.poot-tabs-titletext').html(poot.attr('originalTitle') + ' — ' + pootTabsHere.getTab(poot, poot.attr('pootSelected')).html());
    var styleElem = document.createElement( 'style' );
+
var bestHeight = Math.max(poot.children('.poot-tabs-content').height(), Math.max(poot.children('.poot-tabs').height(), babysize)).toString() + 'px';
    styleElem.setAttribute( 'type' , 'text/css' );
+
poot.children('.poot-tabs-content').css('height', bestHeight);
    styleElem.appendChild( document.createTextNode( sheet ) );
+
if(poot.attr('vertical')) {
    document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
+
poot.children('.poot-tabs').css('height', bestHeight);
}
+
}
+
},
/* Test if an element has a certain class **************************************
+
toggleCollapse:function(poot) {
  *
+
var pootLinkText = poot.children('.poot-tabs-showhide').text().split(';');
  * Description: Uses regular expressions and caching for better performance.
+
var duration = pootTabsHere.animationsEnabled ? parseInt(poot.attr('pootslideduration')) : 0;
  * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
+
if(poot.attr('pootcollapse') != 'true') {
  */
+
poot.attr('pootcollapse', 'true');
+
poot.find('.poot-tabs-hidelink a').text(pootLinkText[0]);
var hasClass = (function () {
+
poot.children('.poot-tabs, .poot-tabs-content').slideUp(duration);
    var reCache = {};
+
}
    return function (element, className) {
+
else {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
+
poot.attr('pootcollapse', '');
    };
+
poot.find('.poot-tabs-hidelink a').text(pootLinkText[1]);
})();
+
poot.children('.poot-tabs, .poot-tabs-content').slideDown(duration);
+
}
/** Internet Explorer bug fix **************************************************
+
},
  *
+
delayHeight:function(poot, selected) {
  *  Description: Fixes IE horizontal scrollbar bug
+
setTimeout(function() {
  *  Maintainers: [[User:Tom-]]?
+
poot.attr('pootselected', selected.toString());
  */
+
pootTabsHere.changeTab(poot, selected, 0, true);
+
if(poot.hasClass('poot-tabs-collapsed')) {
if (navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat")
+
pootTabsHere.toggleCollapse(poot);
{
+
}
  var oldWidth;
+
}, 100);
  var docEl = document.documentElement;
+
},
+
poot:function() {
  function fixIEScroll()
+
var dis = $(this);
  {
+
var ind = 0;
    if (!oldWidth || docEl.clientWidth > oldWidth)
+
dis.attr('originalTitle', dis.find('.poot-tabs-titletext').html());
      doFixIEScroll();
+
var selected = /poot-tabs-selected-(\d+)/i.exec(dis.attr('class'));
    else
+
if(selected) {
      setTimeout(doFixIEScroll, 1);
+
pootTabsHere.delayHeight(dis, parseInt(selected[1])-1);
+
}
    oldWidth = docEl.clientWidth;
+
else {
  }
+
pootTabsHere.delayHeight(dis, 0);
+
}
  function doFixIEScroll() {
+
var duration = dis.hasClass('poot-tabs-noanimations') ? 0 : 200;
    docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
+
dis.attr('pootslideduration', dis.hasClass('poot-tabs-noanimations') ? '0' : '75');
  }
+
dis.children('.poot-tabs').children('ul').children('li').each(function(){
+
var thisInd = ind;
  document.attachEvent("onreadystatechange", fixIEScroll);
+
$(this).click(function(){
  attachEvent("onresize", fixIEScroll);
+
pootTabsHere.changeTab(dis, thisInd, duration, false);
}
+
$(this).blur();
 
+
$(this).find('*').blur();
var autoCollapse = 2;
+
return false;
var collapseCaption = "hide";
+
});
var expandCaption = "show";
+
ind++;
+
});
function collapseTable( tableIndex )
+
var isVertical = dis.hasClass('poot-tabs-vertical');
{
+
dis.attr('pootvertical', isVertical ? 'true' : '');
    var Button = document.getElementById( "collapseButton" + tableIndex );
+
if(isVertical) {
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
+
var teenie = dis.children('.poot-tabs').width().toString() + 'px';
+
dis.children('.poot-tabs-content').css('margin-left', teenie);
    if ( !Table || !Button ) {
+
}
        return false;
+
dis.attr('pootcollapse', ''); // False
    }
+
dis.find('.poot-tabs-hidelink a').click(function(){
+
pootTabsHere.toggleCollapse(dis);
    var Rows = Table.rows;
+
return false;
+
});
    if ( Button.firstChild.data == collapseCaption ) {
+
},
        for ( var i = 1; i < Rows.length; i++ ) {
+
init:function() {
            Rows[i].style.display = "none";
+
$('.poot-tabs-container').each(pootTabsHere.poot);
        }
+
}
        Button.firstChild.data = expandCaption;
+
};
    } else {
+
$(pootTabsHere.init);
        for ( var i = 1; i < Rows.length; i++ ) {
+
// End of PootTabs
            Rows[i].style.display = Rows[0].style.display;
 
        }
 
        Button.firstChild.data = collapseCaption;
 
    }
 
}
 
 
function createCollapseButtons()
 
{
 
    var tableIndex = 0;
 
    var NavigationBoxes = new Object();
 
    var Tables = document.getElementsByTagName( "table" );
 
 
    for ( var i = 0; i < Tables.length; i++ ) {
 
        if ( hasClass( Tables[i], "collapsible" ) ) {
 
 
            /* only add button and increment count if there is a header row to work with */
 
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
 
            if (!HeaderRow) continue;
 
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
 
            if (!Header) continue;
 
 
            NavigationBoxes[ tableIndex ] = Tables[i];
 
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
 
 
            var Button    = document.createElement( "span" );
 
            var ButtonLink = document.createElement( "a" );
 
            var ButtonText = document.createTextNode( collapseCaption );
 
 
            Button.style.styleFloat = "right";
 
            Button.style.cssFloat = "right";
 
            Button.style.fontWeight = "normal";
 
            Button.style.textAlign = "right";
 
            Button.style.width = "6em";
 
 
            ButtonLink.style.color = Header.style.color;
 
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
 
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
 
            ButtonLink.appendChild( ButtonText );
 
 
            Button.appendChild( document.createTextNode( "[" ) );
 
            Button.appendChild( ButtonLink );
 
            Button.appendChild( document.createTextNode( "]" ) );
 
 
            Header.insertBefore( Button, Header.childNodes[0] );
 
            tableIndex++;
 
        }
 
    }
 
 
    for ( var i = 0;  i < tableIndex; i++ ) {
 
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
 
            collapseTable( i );
 
        }
 
    }
 
}
 
 
addOnloadHook( createCollapseButtons );
 

Latest revision as of 09:20, 21 May 2017

// PootTabs - it poots tabs on pages.
var pootTabsHere = {
	animationsEnabled: $.support.opacity,
	getTab:function(poot, index) {
		return $(poot.children('.poot-tabs').children('ul').children('li')[parseInt(index)]);
	},
	changeTab:function(poot, index, duration, force) {
		if(index == parseInt(poot.attr('pootSelected')) && !force && duration) return;
		if(!pootTabsHere.animationsEnabled) {
			duration = 0;
		}
		poot.attr('pootSelected', index.toString());
		var babies = poot.children('.poot-tabs-content').children();
		babies.each(function() {
			$(this).fadeOut(duration, function(){
				$(this).removeClass('poot-tabs-selected');
			});
		});
		$(babies[index]).each(function() {
			$(this).fadeIn(duration, function(){
				$(this).addClass('poot-tabs-selected');
			});
		});
		var cowtabs = poot.children('.poot-tabs').children('ul').children('li');
		cowtabs.removeClass('poot-tabs-selected');
		$(cowtabs[index]).addClass('poot-tabs-selected');
		pootTabsHere.updatePoot(poot, $(babies[index]).height());
	},
	updatePoot:function(poot, babysize) {
		poot.find('.poot-tabs-titletext').html(poot.attr('originalTitle') + ' &mdash; ' + pootTabsHere.getTab(poot, poot.attr('pootSelected')).html());
		var bestHeight = Math.max(poot.children('.poot-tabs-content').height(), Math.max(poot.children('.poot-tabs').height(), babysize)).toString() + 'px';
		poot.children('.poot-tabs-content').css('height', bestHeight);
		if(poot.attr('vertical')) {
			poot.children('.poot-tabs').css('height', bestHeight);
		}
	},
	toggleCollapse:function(poot) {
		var pootLinkText = poot.children('.poot-tabs-showhide').text().split(';');
		var duration = pootTabsHere.animationsEnabled ? parseInt(poot.attr('pootslideduration')) : 0;
		if(poot.attr('pootcollapse') != 'true') {
			poot.attr('pootcollapse', 'true');
			poot.find('.poot-tabs-hidelink a').text(pootLinkText[0]);
			poot.children('.poot-tabs, .poot-tabs-content').slideUp(duration);
		}
		else {
			poot.attr('pootcollapse', '');
			poot.find('.poot-tabs-hidelink a').text(pootLinkText[1]);
			poot.children('.poot-tabs, .poot-tabs-content').slideDown(duration);
		}
	},
	delayHeight:function(poot, selected) {
		setTimeout(function() {
			poot.attr('pootselected', selected.toString());
			pootTabsHere.changeTab(poot, selected, 0, true);
			if(poot.hasClass('poot-tabs-collapsed')) {
				pootTabsHere.toggleCollapse(poot);
			}
		}, 100);
	},
	poot:function() {
		var dis = $(this);
		var ind = 0;
		dis.attr('originalTitle', dis.find('.poot-tabs-titletext').html());
		var selected = /poot-tabs-selected-(\d+)/i.exec(dis.attr('class'));
		if(selected) {
			pootTabsHere.delayHeight(dis, parseInt(selected[1])-1);
		}
		else {
			pootTabsHere.delayHeight(dis, 0);
		}
		var duration = dis.hasClass('poot-tabs-noanimations') ? 0 : 200;
		dis.attr('pootslideduration', dis.hasClass('poot-tabs-noanimations') ? '0' : '75');
		dis.children('.poot-tabs').children('ul').children('li').each(function(){
			var thisInd = ind;
			$(this).click(function(){
				pootTabsHere.changeTab(dis, thisInd, duration, false);
				$(this).blur();
				$(this).find('*').blur();
				return false;
			});
			ind++;
		});
		var isVertical = dis.hasClass('poot-tabs-vertical');
		dis.attr('pootvertical', isVertical ? 'true' : '');
		if(isVertical) {
			var teenie = dis.children('.poot-tabs').width().toString() + 'px';
			dis.children('.poot-tabs-content').css('margin-left', teenie);
		}
		dis.attr('pootcollapse', ''); // False
		dis.find('.poot-tabs-hidelink a').click(function(){
			pootTabsHere.toggleCollapse(dis);
			return false;
		});
	},
	init:function() {
		$('.poot-tabs-container').each(pootTabsHere.poot);
	}
};
$(pootTabsHere.init);
// End of PootTabs