Actions

MediaWiki

Difference between revisions of "Common.js"

From Sonic Retro

 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
var retro_menu_objs = [];
+
// PootTabs - it poots tabs on pages.
jQuery(window).unbind('resize').resize(function(){
+
var pootTabsHere = {
for (var i = 0; i < retro_menu_objs.length; i++)
+
animationsEnabled: $.support.opacity,
if (typeof(retro_menu_objs[i]) == "object")
+
getTab:function(poot, index) {
if (typeof(retro_menu_objs[i].resize) == "function")
+
return $(poot.children('.poot-tabs').children('ul').children('li')[parseInt(index)]);
retro_menu_objs[i].resize();
+
},
 +
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() {
var retro_menu_obj = function(e, limit, outerlimit) {
+
$(this).fadeIn(duration, function(){
var that = this;
+
$(this).addClass('poot-tabs-selected');
this.e = e;
 
this.original_width = e.children('div').outerWidth();
 
this.limit = limit;
 
this.outerlimit = outerlimit;
 
this.resize = function() {
 
if (this.original_width == 0) return;
 
if (jQuery(window).width() >= this.original_width + this.limit) {
 
this.e.children('div').children('a').each(function(){
 
jQuery(this).show();
 
});
 
this.e.children('div').children('div').children('a').hide();
 
this.e.children('div').children('div').children('ul').children('li').each(function(){
 
jQuery(this).hide();
 
});
 
} else {
 
var els = [];
 
this.e.children('div').children('a').each(function(){
 
els.push(jQuery(this));
 
jQuery(this).show();
 
});
 
this.e.children('div').children('div').children('a').show();
 
var num = 0, current;
 
while (els.length > 0) {
 
current = els.pop();
 
current.hide();
 
num++;
 
if (jQuery(window).width() >= this.e.children('div').outerWidth() + this.outerlimit) els = [];
 
}
 
if (num > 0) {
 
this.e.children('div').children('div').children('ul').children('li').each(function(){
 
els.push(jQuery(this));
 
});
 
while (els.length > 0) {
 
current = els.pop();
 
if (num > 0) current.show(); else current.hide();
 
num--;
 
}
 
}
 
}
 
};
 
this.dropdown_out = -1;
 
this.dropdown_interval = null;
 
this.dropdown_interval_func = function(){
 
if (that.dropdown_out < 0) return;
 
else if (that.dropdown_out == 0) {
 
that.e.children('div').children('div').children('ul').hide();
 
that.e.children('div').children('div').children('a').removeAttr('style');
 
}
 
that.dropdown_out--;
 
};
 
if (this.e.children('div').children('div').length > 0) this.e.children('div').children('div').remove();
 
var link_html = this.e.children('div').html().split('</a>'); link_html.pop();
 
for (var i = 0; i < link_html.length; i++) {
 
link_html[i] = "<li>" + link_html[i] + "</a></li>";
 
if (link_html[i].indexOf('class="current"') != -1) {
 
link_html[i] = link_html[i].replace('class="current"','').replace('<li>','<li class="current">');
 
}
 
}
 
this.e.children('div').append('<div><a href="#">&#9660;</a><ul style="display:none">' + link_html.join("") + '</ul></div>');
 
this.e.children('div').children('div').children('a').unbind('click').click(function(e){
 
e.preventDefault();
 
jQuery(this).next().toggle();
 
if (jQuery(this).next().is(':visible')) {
 
jQuery(this).attr('style','color:rgba(255,255,255,1)');
 
} else {
 
jQuery(this).removeAttr('style');
 
}
 
this.dropdown_out = -1;
 
clearInterval(that.dropdown_interval);
 
that.dropdown_interval = null;
 
 
});
 
});
this.e.children('div').children('div').children('ul').unbind('mouseenter').unbind('mouseleave').hover(function(){
+
});
that.dropdown_out = -1;
+
var cowtabs = poot.children('.poot-tabs').children('ul').children('li');
clearInterval(that.dropdown_interval);
+
cowtabs.removeClass('poot-tabs-selected');
that.dropdown_interval = null;
+
$(cowtabs[index]).addClass('poot-tabs-selected');
},function(){
+
pootTabsHere.updatePoot(poot, $(babies[index]).height());
that.dropdown_out = 10;
+
},
clearInterval(that.dropdown_interval);
+
updatePoot:function(poot, babysize) {
that.dropdown_interval = setInterval(function(){ that.dropdown_interval_func(); },100);
+
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';
this.resize();
+
poot.children('.poot-tabs-content').css('height', bestHeight);
};
+
if(poot.attr('vertical')) {
 
+
poot.children('.poot-tabs').css('height', bestHeight);
addOnloadHook(createToggleLinks);
+
}
 
+
},
function createToggleLinks() {
+
toggleCollapse:function(poot) {
 
+
var pootLinkText = poot.children('.poot-tabs-showhide').text().split(';');
var stateArray = new Array();
+
var duration = pootTabsHere.animationsEnabled ? parseInt(poot.attr('pootslideduration')) : 0;
var allObjects = document.getElementsByTagName('span');
+
if(poot.attr('pootcollapse') != 'true') {
var rCollapsingObject = new RegExp("^co;(.+?);(.+?);(.+?);(.+?)(;(.+?))?$");
+
poot.attr('pootcollapse', 'true');
+
poot.find('.poot-tabs-hidelink a').text(pootLinkText[0]);
for ( var i = 0; i < allObjects.length; i++ ) {
+
poot.children('.poot-tabs, .poot-tabs-content').slideUp(duration);
+
}
if ( rCollapsingObject.test(allObjects[i].className) ) {
+
else {
+
poot.attr('pootcollapse', '');
var collapsingInformation = rCollapsingObject.exec(allObjects[i].className);
+
poot.find('.poot-tabs-hidelink a').text(pootLinkText[1]);
+
poot.children('.poot-tabs, .poot-tabs-content').slideDown(duration);
var collapseText = collapsingInformation[1];
+
}
var expandText = collapsingInformation[2];
+
},
var initialState = collapsingInformation[3];
+
delayHeight:function(poot, selected) {
var targetClass = collapsingInformation[4];
+
setTimeout(function() {
var linkColor = collapsingInformation[6];
+
poot.attr('pootselected', selected.toString());
+
pootTabsHere.changeTab(poot, selected, 0, true);
var toggleLink = document.createElement("a");
+
if(poot.hasClass('poot-tabs-collapsed')) {
+
pootTabsHere.toggleCollapse(poot);
if ( initialState == "0" ) {
 
 
toggleLink.appendChild(document.createTextNode(expandText));
 
stateArray[targetClass] = "none";
 
 
}
 
}
+
}, 100);
else {
+
},
+
poot:function() {
toggleLink.appendChild(document.createTextNode(collapseText));
+
var dis = $(this);
stateArray[targetClass] = "inline";
+
var ind = 0;
}
+
dis.attr('originalTitle', dis.find('.poot-tabs-titletext').html());
+
var selected = /poot-tabs-selected-(\d+)/i.exec(dis.attr('class'));
toggleLink.setAttribute("href", "javascript:toggleCollapse('" + targetClass + "','" + collapseText + "','" + expandText + "')");
+
if(selected) {
+
pootTabsHere.delayHeight(dis, parseInt(selected[1])-1);
if ( linkColor != undefined && linkColor != "undefined" && linkColor != "" )
 
toggleLink.style.color = linkColor;
 
 
allObjects[i].innerHTML = "";
 
allObjects[i].appendChild(toggleLink);
 
 
}
 
}
+
else {
else if ( allObjects[i].className == "morphMaster" ) {
+
pootTabsHere.delayHeight(dis, 0);
 
var spanID = allObjects[i].getAttribute("id");
 
var targetID = spanID.substr(0, spanID.length - 6);
 
var counter = 1;
 
 
// Create forward and backward paging if the paging elements exist
 
if ( returnObjById(targetID + "LinkNext") && returnObjById(targetID + "LinkPrev") && returnObjById(targetID + "Content1") ) {
 
 
// Create the forward link
 
var nextLink = document.createElement("a");
 
nextLink.appendChild(document.createTextNode(returnObjById(targetID + "LinkNext").innerHTML));
 
nextLink.setAttribute("href", "javascript:morphForward('" + targetID + "')");
 
 
returnObjById(targetID + "LinkNext").innerHTML = "";
 
returnObjById(targetID + "LinkNext").appendChild(nextLink, 0);
 
 
// Create the backward link
 
var prevLink = document.createElement("a");
 
prevLink.appendChild(document.createTextNode(returnObjById(targetID + "LinkPrev").innerHTML));
 
prevLink.setAttribute("href", "javascript:morphBackward('" + targetID + "')");
 
 
returnObjById(targetID + "LinkPrev").innerHTML = "";
 
returnObjById(targetID + "LinkPrev").appendChild(prevLink, 0);
 
 
// Initialize content panes
 
while ( returnObjById(targetID + "Content" + counter) ) {
 
 
 
counter++;
 
}
 
}
 
 
 
counter = 1;
 
 
// Whether or not there is paging, generate normal links
 
while ( returnObjById(targetID + "Link" + counter) && returnObjById(targetID + "Content" + counter) ) {
 
 
var morphLink = document.createElement("a");
 
morphLink.appendChild(document.createTextNode(returnObjById(targetID + "Link" + counter).innerHTML));
 
morphLink.setAttribute("href", "javascript:performMorph('" + targetID + "','" + counter + "')");
 
 
returnObjById(targetID + "Link" + counter).innerHTML = "";
 
returnObjById(targetID + "Link" + counter).appendChild(morphLink, 0);
 
 
// Initialize content panes
 
 
counter++;
 
}
 
 
allObjects[i].innerHTML = "1";
 
allObjects[i].style.display = "none";
 
 
}
 
}
}
+
var duration = dis.hasClass('poot-tabs-noanimations') ? 0 : 200;
+
dis.attr('pootslideduration', dis.hasClass('poot-tabs-noanimations') ? '0' : '75');
// Set state of appropriate objects
+
dis.children('.poot-tabs').children('ul').children('li').each(function(){
allObjects = document.getElementsByTagName('*');
+
var thisInd = ind;
+
$(this).click(function(){
for ( var i = 0; i < allObjects.length; i++ ) {
+
pootTabsHere.changeTab(dis, thisInd, duration, false);
+
$(this).blur();
if ( stateArray[allObjects[i].className] )
+
$(this).find('*').blur();
allObjects[i].style.display = stateArray[allObjects[i].className];
+
return false;
}
+
});
}
+
ind++;
 
+
});
/* Function that toggles collapsing objects.
+
var isVertical = dis.hasClass('poot-tabs-vertical');
* Added 7/13/2008 by WhiteMystery (misterioblanco@gmail.com) */
+
dis.attr('pootvertical', isVertical ? 'true' : '');
 
+
if(isVertical) {
function toggleCollapse(targetClass, collapseText, expandText) {
+
var teenie = dis.children('.poot-tabs').width().toString() + 'px';
 
+
dis.children('.poot-tabs-content').css('margin-left', teenie);
var allObjects = document.getElementsByTagName('*');
 
var rCollapsingObject = new RegExp("^co;(.+?);(.+?);(.+?);" + targetClass + "(;(.+?))?$");
 
 
var linkType;
 
 
for ( var i = 0; i < allObjects.length; i++ ) {
 
 
if ( allObjects[i].className == targetClass ) {
 
 
if ( allObjects[i].style.display == "none" ) {
 
 
allObjects[i].style.display = "inline";
 
linkType = "Collapse";
 
}
 
 
else {
 
 
allObjects[i].style.display = "none";
 
linkType = "Expand";
 
}
 
}
 
}
 
 
allObjects = document.getElementsByTagName('span');
 
 
for ( var i = 0; i < allObjects.length; i++ ) {
 
 
if ( rCollapsingObject.test(allObjects[i].className) ) {
 
 
var collapsingInformation = rCollapsingObject.exec(allObjects[i].className);
 
 
var collapseText = collapsingInformation[1];
 
var expandText = collapsingInformation[2];
 
var linkColor = collapsingInformation[5];
 
 
var toggleLink = document.createElement("a");
 
 
if ( linkType == "Expand" )
 
 
toggleLink.appendChild(document.createTextNode(expandText));
 
 
else if ( linkType == "Collapse" )
 
 
toggleLink.appendChild(document.createTextNode(collapseText));
 
 
toggleLink.setAttribute("href", "javascript:toggleCollapse('" + targetClass + "','" + collapseText + "','" + expandText + "')");
 
 
if ( linkColor != undefined && linkColor != "undefined" && linkColor != "" )
 
toggleLink.style.color = linkColor;
 
 
allObjects[i].innerHTML = "";
 
allObjects[i].appendChild(toggleLink);
 
 
}
 
}
 +
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);
/* Functions that perform the morph operations.
+
// End of PootTabs
* Added 8/13/2008 by WhiteMystery ([email protected]) */
 
 
 
function performMorph(targetID, targetNumber) {
 
 
 
var counter = 1;
 
 
while ( returnObjById(targetID + "Content" + counter) ) {
 
 
if ( counter == targetNumber )
 
returnObjById(targetID + "Content" + counter).style.display = "block";
 
else
 
returnObjById(targetID + "Content" + counter).style.display = "none";
 
 
counter++;
 
}
 
 
returnObjById(targetID + "Master").innerHTML = targetNumber;
 
}
 
 
 
function morphForward(targetID) {
 
 
 
var nextPane = parseInt(returnObjById(targetID + "Master").innerHTML) + 1;
 
 
if ( returnObjById(targetID + "Content" + nextPane) )
 
performMorph(targetID, nextPane);
 
 
else
 
performMorph(targetID, "1");
 
}
 
 
 
function morphBackward(targetID) {
 
 
 
var prevPane = parseInt(returnObjById(targetID + "Master").innerHTML) - 1;
 
 
if ( prevPane > 0 )
 
performMorph(targetID, prevPane);
 
 
else {
 
 
var maxIndex = 1;
 
 
while ( returnObjById(targetID + "Content" + maxIndex) )
 
maxIndex++;
 
 
performMorph(targetID, maxIndex - 1);
 
}
 
}
 
 
 
/* Function that returns an object by ID for various browsers
 
* Taken from http://www.netlobo.com/javascript_get_element_id.html */
 
 
 
function returnObjById( id ) {
 
 
    if (document.getElementById)
 
        var returnVar = document.getElementById(id);
 
       
 
    else if (document.all)
 
        var returnVar = document.all[id];
 
       
 
    else if (document.layers)  
 
        var returnVar = document.layers[id];
 
       
 
    return returnVar;  
 
}
 
 
 
/*</pre>*/
 

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