Difference between revisions of "Common.js"
From Sonic Retro
Scarred Sun (talk | contribs) m (Reverted edits by Scarred Sun (talk) to last revision by Shobiz) |
Scarred Sun (talk | contribs) |
||
Line 35: | Line 35: | ||
} | } | ||
+ | // PootTabs by User:WindPower over at Portal Wiki | ||
+ | // It puts 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') + ' — ' + 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 | ||
/* Test if an element has a certain class ************************************** | /* Test if an element has a certain class ************************************** | ||
* | * |
Revision as of 17:29, 8 July 2015
/* Any JavaScript here will be loaded for all users on every page load. */
/** Import module *************************************************************
*
* Description: Includes a raw wiki page as javascript or CSS,
* used for including user made modules.
* Maintainers: [[User:AzaToth]]
*/
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
function importScript( page ) {
if( importedScripts[page] ) {
return;
}
importedScripts[page] = true;
var url = wgScriptPath
+ '/index.php?title='
+ encodeURIComponent( page.replace( / /g, '_' ) )
+ '&action=raw&ctype=text/javascript';
var scriptElem = document.createElement( 'script' );
scriptElem.setAttribute( 'src' , url );
scriptElem.setAttribute( 'type' , 'text/javascript' );
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}
function importStylesheet( page ) {
var sheet = '@import "'
+ wgScriptPath
+ '/index.php?title='
+ encodeURIComponent( page.replace( / /g, '_' ) )
+ '&action=raw&ctype=text/css";'
var styleElem = document.createElement( 'style' );
styleElem.setAttribute( 'type' , 'text/css' );
styleElem.appendChild( document.createTextNode( sheet ) );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
// PootTabs by User:WindPower over at Portal Wiki
// It puts 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') + ' — ' + 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
/* Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/** Internet Explorer bug fix **************************************************
*
* Description: Fixes IE horizontal scrollbar bug
* Maintainers: [[User:Tom-]]?
*/
if (navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat")
{
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll()
{
if (!oldWidth || docEl.clientWidth > oldWidth)
doFixIEScroll();
else
setTimeout(doFixIEScroll, 1);
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
}
var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
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 );
addOnloadHook(function() {
var pages = { 'Flying Fortress/Death Egg cliché': true, 'Gens/GS': true };
if (pages[wgTitle]) {
document.getElementsByClassName('subpages').item(0).style.display = 'none';
}
});