Actions

MediaWiki

Difference between revisions of "Common.js"

From Sonic Retro

(New page: Any JavaScript here will be loaded for all users on every page load.: var autoCollapse = 2; var collapseCaption = "hide"; var expandCaption = "show"; function collapseTable( tab...)
 
 
(11 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 = {
var autoCollapse = 2;
+
animationsEnabled: $.support.opacity,
var collapseCaption = "hide";
+
getTab:function(poot, index) {
var expandCaption = "show";
+
return $(poot.children('.poot-tabs').children('ul').children('li')[parseInt(index)]);
+
},
function collapseTable( tableIndex )
+
changeTab:function(poot, index, duration, force) {
{
+
if(index == parseInt(poot.attr('pootSelected')) && !force && duration) return;
    var Button = document.getElementById( "collapseButton" + tableIndex );
+
if(!pootTabsHere.animationsEnabled) {
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
+
duration = 0;
+
}
    if ( !Table || !Button ) {
+
poot.attr('pootSelected', index.toString());
        return false;
+
var babies = poot.children('.poot-tabs-content').children();
    }
+
babies.each(function() {
+
$(this).fadeOut(duration, function(){
    var Rows = Table.rows;
+
$(this).removeClass('poot-tabs-selected');
+
});
    if ( Button.firstChild.data == collapseCaption ) {
+
});
        for ( var i = 1; i < Rows.length; i++ ) {
+
$(babies[index]).each(function() {
            Rows[i].style.display = "none";
+
$(this).fadeIn(duration, function(){
        }
+
$(this).addClass('poot-tabs-selected');
        Button.firstChild.data = expandCaption;
+
});
    } else {
+
});
        for ( var i = 1; i < Rows.length; i++ ) {
+
var cowtabs = poot.children('.poot-tabs').children('ul').children('li');
            Rows[i].style.display = Rows[0].style.display;
+
cowtabs.removeClass('poot-tabs-selected');
        }
+
$(cowtabs[index]).addClass('poot-tabs-selected');
        Button.firstChild.data = collapseCaption;
+
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());
function createCollapseButtons()
+
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);
    var tableIndex = 0;
+
if(poot.attr('vertical')) {
    var NavigationBoxes = new Object();
+
poot.children('.poot-tabs').css('height', bestHeight);
    var Tables = document.getElementsByTagName( "table" );
+
}
+
},
    for ( var i = 0; i < Tables.length; i++ ) {
+
toggleCollapse:function(poot) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
+
var pootLinkText = poot.children('.poot-tabs-showhide').text().split(';');
+
var duration = pootTabsHere.animationsEnabled ? parseInt(poot.attr('pootslideduration')) : 0;
            /* only add button and increment count if there is a header row to work with */
+
if(poot.attr('pootcollapse') != 'true') {
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
+
poot.attr('pootcollapse', 'true');
            if (!HeaderRow) continue;
+
poot.find('.poot-tabs-hidelink a').text(pootLinkText[0]);
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
+
poot.children('.poot-tabs, .poot-tabs-content').slideUp(duration);
            if (!Header) continue;
+
}
+
else {
            NavigationBoxes[ tableIndex ] = Tables[i];
+
poot.attr('pootcollapse', '');
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
+
poot.find('.poot-tabs-hidelink a').text(pootLinkText[1]);
+
poot.children('.poot-tabs, .poot-tabs-content').slideDown(duration);
            var Button    = document.createElement( "span" );
+
}
            var ButtonLink = document.createElement( "a" );
+
},
            var ButtonText = document.createTextNode( collapseCaption );
+
delayHeight:function(poot, selected) {
+
setTimeout(function() {
            Button.style.styleFloat = "right";
+
poot.attr('pootselected', selected.toString());
            Button.style.cssFloat = "right";
+
pootTabsHere.changeTab(poot, selected, 0, true);
            Button.style.fontWeight = "normal";
+
if(poot.hasClass('poot-tabs-collapsed')) {
            Button.style.textAlign = "right";
+
pootTabsHere.toggleCollapse(poot);
            Button.style.width = "6em";
+
}
+
}, 100);
            ButtonLink.style.color = Header.style.color;
+
},
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
+
poot:function() {
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
+
var dis = $(this);
            ButtonLink.appendChild( ButtonText );
+
var ind = 0;
+
dis.attr('originalTitle', dis.find('.poot-tabs-titletext').html());
            Button.appendChild( document.createTextNode( "[" ) );
+
var selected = /poot-tabs-selected-(\d+)/i.exec(dis.attr('class'));
            Button.appendChild( ButtonLink );
+
if(selected) {
            Button.appendChild( document.createTextNode( "]" ) );
+
pootTabsHere.delayHeight(dis, parseInt(selected[1])-1);
+
}
            Header.insertBefore( Button, Header.childNodes[0] );
+
else {
            tableIndex++;
+
pootTabsHere.delayHeight(dis, 0);
        }
+
}
    }
+
var duration = dis.hasClass('poot-tabs-noanimations') ? 0 : 200;
+
dis.attr('pootslideduration', dis.hasClass('poot-tabs-noanimations') ? '0' : '75');
    for ( var i = 0; i < tableIndex; i++ ) {
+
dis.children('.poot-tabs').children('ul').children('li').each(function(){
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
+
var thisInd = ind;
            collapseTable( i );
+
$(this).click(function(){
        }
+
pootTabsHere.changeTab(dis, thisInd, duration, false);
    }
+
$(this).blur();
}
+
$(this).find('*').blur();
+
return false;
addOnloadHook( createCollapseButtons );
+
});
 +
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

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