User:Gaèlic/Common.js/Morph.js

/* Any JavaScript here will be loaded for all users on every page load. */ // Funzioni (2) per il cassetto // Parametri: // indexNavigationBar: Numero identificativo del cassetto function toggleNavigationBar(indexNavigationBar) { var navToggle = $('#NavToggle' + indexNavigationBar); var navFrame = $('#NavFrame' + indexNavigationBar); var navContent = $('>.NavPic, >.NavContent', navFrame);

if(!navFrame.length || !navToggle.length) { return false; }

// Se il cassetto è aperto if(navToggle.text == navigationBarHide) { if(!navFrame.hasClass('noSlide') && !noNavSlide) { navContent.fadeOut({duration: fadeDelay, queue: false}).slideUp(slideDelay); }		else { navContent.hide; }		navToggle.text(navigationBarShow); }	// Se il cassetto è chiuso else if(navToggle.text == navigationBarShow) { if(!navFrame.hasClass('noSlide') && !noNavSlide) { navContent.fadeIn({duration: fadeDelay, queue: false}).hide.slideDown(slideDelay); }		else { navContent.show; }		navToggle.text(navigationBarHide); }	return; }

function createNavigationBarToggleButton { var indexNavigationBar = 0; $('div.NavFrame').each(function {		indexNavigationBar++;		var index = indexNavigationBar;		var navToggle = $(' ');		navToggle.attr({ 'class': 'NavToggle morphLink', 'id': 'NavToggle' + index, 'onclick': 'toggleNavigationBar(\'' + index + '\');' });		navToggle.text(navigationBarHide);		$('>.NavHead', this).append(navToggle);		$(this).attr({ 'id': 'NavFrame' + index });	});	if(navigationBarShowDefault < indexNavigationBar) { for(var i = 1; i <= indexNavigationBar; i++) { toggleNavigationBar(i); }	}	return; }

// Funzioni (2) di toggleLink // Autore: WhiteMystery function toggleCollapse(objToToggle) { var linkText = ''; var targetObject = $('#' + objToToggle); if(!targetObject.length) { return; }	var collapseText = $('#' + objToToggle + 'CollapseText').html; var expandText = $('#' + objToToggle + 'ExpandText').html; var slide = !$('#' + objToToggle + 'Link').hasClass('noSlide') && !noMorphSFX; var fade = !$('#' + objToToggle + 'Link').hasClass('noFade') && !noMorphSFX; if(targetObject.is(':hidden')) { if(fade && slide) { targetObject.fadeIn({duration: slideDelay, queue: false}).hide.slideDown(fadeDelay); // I delay sono volutamente invertiti }		else if(!fade && slide) { targetObject.slideDown(slideDelay); }		else if(fade && !slide) { targetObject.fadeIn(fadeDelay); }		else { targetObject.show; }		linkText = collapseText; }	else { if(fade && slide) { targetObject.fadeOut({duration: fadeDelay, queue: false}).slideUp(slideDelay); }		else if(!fade && slide) { targetObject.slideUp(slideDelay); }		else if(fade && !slide) { targetObject.fadeOut(fadeDelay); }		else { targetObject.hide; }		linkText = expandText; }	$('#' + objToToggle + 'Link-').html(linkText); return; }

function createToggleLinks { $('.toggleLink').each(function {		var spanID = $(this).attr('id');		var targetID = spanID.replace(/Link$/, '');		var collapseText = $('#' + targetID + 'CollapseText').html;		var expandText = $('#' + targetID + 'ExpandText').html;		var initialState = $('#' + targetID + 'InitialState').text;		var toggleLink = $(' ');		$(this).append(toggleLink);		if(initialState == '0') {			$('#' + targetID).hide;			toggleLink.html(expandText);		}		else {			$('#' + targetID).show;			toggleLink.html(collapseText);		}		toggleLink.attr({ 'id': targetID + 'Link-', 'class': 'morphLink', 'onclick': 'toggleCollapse(\'' + targetID + '\');' });	});	return; }

// Funzioni (5) del morph 2.0 // Autore: MFH // Parametri: // targetID: ID dell'oggetto morphizzato // targetNumber: Numero dell'elemento che si vuole visualizzare function performMorph(targetID, targetNumber) { var master = $('#' + targetID + 'Master'); var maxNumber = master.attr('max'); for(var i = 1; i <= maxNumber; i++) { $('.' + targetID + 'Content' + i).hide; }	if(master.hasClass('noFade') || noMorphSFX) { $('.' + targetID + 'Content' + targetNumber).show; }	else { $('.' + targetID + 'Content' + targetNumber).fadeIn({duration: fadeDelay, queue: false}); }	if(master.hasClass('noLoop')) { if(targetNumber == 1) { $('.' + targetID + 'LinkNext').show; $('.' + targetID + 'LinkPrev').hide; }		else if(targetNumber == maxNumber) { $('.' + targetID + 'LinkNext').hide; $('.' + targetID + 'LinkPrev').show; }		else { $('.' + targetID + 'LinkNext').show; $('.' + targetID + 'LinkPrev').show; }	}	$('.' + targetID + 'Counter').text('(' + targetNumber + '/' + maxNumber + ')'); master.attr('pos', targetNumber); return; }

function morphForward(targetID) { var master = $('#' + targetID + 'Master'); var maxPane = parseInt(master.attr('max')); var nextPane = parseInt(master.attr('pos')) + 1; if(nextPane <= maxPane) { performMorph(targetID, nextPane); }	else { performMorph(targetID, '1'); }	return; }

function morphBackward(targetID) { var master = $('#' + targetID + 'Master'); var maxPane = parseInt(master.attr('max')); var prevPane = parseInt(master.attr('pos')) - 1; if(prevPane > 0) { performMorph(targetID, prevPane); }	else { performMorph(targetID, maxPane); }	return; }

function morphRandom(targetID) { var master = $('#' + targetID + 'Master'); var maxPane = parseInt(master.attr('max')); var randPane = Math.floor(Math.random * maxPane + 1); performMorph(targetID, randPane); return; }

function createMorphLinks { $('.morphMaster').each(function {		var spanID = $(this).attr('id');		var targetID = spanID.replace(/Master$/, );		var noLoop = $(this).hasClass('noLoop');		var startPane = parseInt($('#' + targetID + 'Start').text);		var counter = 1;		while($('.' + targetID + 'Content' + counter).length) { // Creazione link diretti			$('.' + targetID + 'Link' + counter).addClass('morphLink').attr('onclick', 'performMorph(\ + targetID + '\', \'' + counter + '\');');			$('.' + targetID + 'Content' + counter).hide; // Preparazione contenuti			counter++;		}		$('#' + targetID + 'Start').remove;		if(startPane >= 1 && startPane <= counter - 1) {			$('.' + targetID + 'Content' + startPane).show;		}		else {			$('.' + targetID + 'Content1').show;			startPane = 1		}		if($('.' + targetID + 'Counter').length) {			$('.' + targetID + 'Counter').text('(' + startPane + '/' + (counter - 1) + ')');		}		if($('.' + targetID + 'Content1').length) { // Creazione link di scorrimento var nextLink = $('.' + targetID + 'LinkNext'); nextLink.addClass('morphLink').attr('onclick', 'morphForward(\'' + targetID + '\');'); if(noLoop && startPane == counter - 1) { nextLink.hide; }			var prevLink = $('.' + targetID + 'LinkPrev'); prevLink.addClass('morphLink').attr('onclick', 'morphBackward(\'' + targetID + '\');'); if(noLoop && startPane == 1) { prevLink.hide; }		}		$('.' + targetID + 'LinkRandom').addClass('morphLink').attr('onclick', 'morphRandom(\'' + targetID + '\');'); // Creazione link random $(this).hide.attr({			'pos': startPane,			'max': counter - 1		}); });	return; }