Cimitero:MediaWiki:Common.js/Varie.js: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Contenuto aggiunto Contenuto cancellato
(Creata pagina con '→‎Any JavaScript here will be loaded for all users on every page load.: // Inserisce il pulsante "purge" in cima alla pagina // Autore: MFH function createPurgeButton() { ...')
 
(Removing Terms of Use violation)
Riga 334: Riga 334:
$(this).text(IP);
$(this).text(IP);
}
}
});
return;
}

// Funzioni (2) per gestire gli alert
// Carica un alert su un link prima di caricare la nuova pagina, oppure su un link "fasullo", senza caricare nessuna nuova pagina
function alertLink() {
$('span.alert-link,span.alert-nolink').each(function() {
var link = $('a:first', this);
var text = $(this).attr('title');
link.click(function() {
alert(text);
});
if($(this).hasClass('alert-nolink')) {
link.attr('href', '#');
}
});
return;
}

// Carica uno o più alert al caricamento della pagina
function alertLoad() {
$('span.alert-load').each(function() {
alert($(this).text());
});
});
return;
return;

Versione delle 02:18, 23 feb 2018

/* Any JavaScript here will be loaded for all users on every page load. */
// Inserisce il pulsante "purge" in cima alla pagina
// Autore: MFH
function createPurgeButton() {
	var reportProblem = $('#ca-report-problem');
	if(reportProblem.length) { // Modifica il pulsante "report a problem", che è già invisibile
		var link = $('a', reportProblem).eq(0);
		link.text('Purge');
		link.attr('href', wgServer + wgScriptPath + '/index.php?title=' + wgPageName + '&action=purge');
		reportProblem.attr('id', 'ca-purge');
	}
	else {
		var menuList = $('#p-cactions ul').eq(0);
		var newLi = $('<li></li>');
		newLi.attr('id', 'ca-purge');
		newLi.html('<a href="' + wgServer + wgScriptPath + '/index.php?title=' + wgPageName + '&action=purge">Purge</a>');
		menuList.append(newLi);
	}
	return;
}

// Rende il link di modifica sezione identico a quello di wikipedia italiana
function moveEditSection() {
	$('span.editsection').each(function() {
		var editLink = $(this);
		editLink.addClass('editsection-it_wiki');
		editLink.siblings().eq(0).after(editLink);
	});
	return;
}

// Aggiunge link di modifica per la sezione 0
function sectionZeroEditLink() {
	if(!$('#bodyContent span.editsection').length || $('#no-sec0-edit').length) {
		return;
	}
	var link = $('<a></a>').attr({
		'rel': 'nofollow',
		'title': 'Modifica la sezione introduttiva',
		'href': wgServer + wgScriptPath + '/index.php?title=' + encodeURI(wgPageName) + '&action=edit&section=0&editintro=MediaWiki:Editintro'
	}).text('modifica');
	var span = $('<span></span>').attr('class', 'editsection');
	span.append('[', link, ']');
	$('#siteSub').prepend(span);
	return;
}

// Inserisce css personalizzati se viene usato il Template:Css
function addCSS() {
	var styleSheet = $('#add-css');
	if(!styleSheet.length) {
		return;
	}
	var linkElem = document.createElement('link');
	linkElem.type = 'text/css';
	linkElem.rel = 'stylesheet';
	linkElem.href = '/index.php?title=Nonciclopedia:Skin/' + styleSheet.text().replace(' ', '_') + '.css&action=raw&ctype=text/css&smaxage=120';
	linkElem.id = 'add-css-link';
	document.getElementsByTagName('head')[0].appendChild(linkElem);
	return;
}

// Cambio del titolo
function rewriteTitle() {
	if($('#TitleText').length) {
		var titleText = $('#TitleText');
		var h1 = $('#firstHeading');
		h1.html(titleText.html());
		if(titleText.text()) {
			document.title = titleText.text() + ' - Nonciclopedia';
		}
		else {
			document.title = 'Nonciclopedia';
		}
		if($('#TitleColor').length) {
			h1.css('color', $('#TitleColor').text());
		}
		if($('#TitleBorderBottom').length) {
			h1.css('border-bottom', $('#TitleBorderBottom').text());
		}
		if($('#TitleFontFamily').length) {
			h1.css('font-family', $('#TitleFontFamily').text());
		}
		$('#TitleText,#TitleColor,#TitleBorderBottom,#TitleFontFamily').remove();
	}
	return;
}

// Cambio del sottotitolo o sottotitolo random
function rewriteSubTitle() {
	h3 = $('#siteSub');
	if($('#SubTitleText').length) {
		h3.text($('#SubTitleText').text());
		$('#SubTitleText').remove();
	}
	else {
		var subTitles = new Array(
			'Da Nonciclopedia, l\'enciclopedia libera su cauzione',
			'Da Nonciclopedia, l\'enciclopedia libera con l\'indulto',
			'Da Nonciclopedia, l\'enciclopedia libera dagli inestetismi',
			'Dà Noncicloppedia, lenciclopedia l\'ibbera dal\'orttografia',
			'Da Nonciclopedia, l\'enciclopedia che libera la gola e calma la tosse',
			'Da Nonciclopedia, l\'enciclopedia libera... finché non ci beccano!',
			'Da Nonciclopedia, l\'enciclopedia in libertà vigilata',
			'Da Nonciclopedia, l\'enciclopedia libera da qualsivoglia contenuto',
			'Da Nonciclopedia, l\'enciclopedia libidinosa',
			'Da Nonciclopedia, l\'enciclopedia libertina',
			'Da Nonciclopedia, l\'enciclopedia liberatoria',
			'Da Nonciclopedia, l\'enciclopedia libera dal pudore. 8====D',
			'Da Nonciclopedia, l\'enciclopedia liberalizzata (ma solo in Olanda)',
			'Da Nonciclopedia, l\'enciclopedia liberamente ispirata all\'Osservatore Romano',
			'Da Nonciclopedia, l\'enciclopedia VM 18 e libera dai bambini'
		);
		var n = Math.round(Math.random() * (subTitles.length - 1));
		h3.text(subTitles[n]);
	}
	return;
}

/***************                 Effetti                ***************/
// Elenchi numerati
// Autore: Genuzzo
function numList() {
	$('.ncMaster').each(function() {
		var list = $('.ncContent li', this);
		var posStr = $('.ncPos', this).text().split(',');
		var posNum = new Array();
		for(var i = 0; i < posStr.length; i++) {
			var num = parseInt(posStr[i]);
			if(isNaN(num)) {
				continue;
			}
			else if(num > 0 && num <= list.length) {
				posNum.push(num - 1);
			}
			else if(num < 0 && num >= -list.length) {
				posNum.push(list.length + num)
			}
			else {
				continue;
			}
		}
		var separator = $('.ncSeparator', this).text();
		var hasSeparator = (separator != '');
		if(hasSeparator) {
			var newList = $('<div></div>');
		}
		else {
			var newList = $('<ul></ul>');
		}
		for(var i = 0; i < posNum.length; i++) {
			if(hasSeparator) {
				newList.append(list.eq(posNum[i]).html());
				if(i != posNum.length -1) {
					newList.append(separator);
				}
			}
			else {
				newList.append('<li>' + list.eq(posNum[i]).html() + '</li>');
			}
		}
		$(this).html('').append(newList);
	});
	return;
}

// Elenchi random
function randomList() {
	if($('.randomlist').length && $('.randomcontent').length && $('.randomtext').length) {
		var randList = $('.randomlist');
		var randContent = $('.randomcontent');
		var randText = $('.randomtext');
		for(var i = 0; i < randList.length; i++) {
			var max = parseInt(randList.eq(i).attr('title'));
			var list = $('li', randContent.eq(i));
			var text = randText.eq(i);
			var N = new Array();
			var dot = max == 1 ? '' : '• ';
			text.text('');
			for(var j = 0; j < max; j++) {
				do {
					n = Math.round(Math.random() * (list.length - 1));
						for (var k = 0; k < j && n != -1; k++) {
							if (N[k] == n) {
								n = -1;
							}
						}
				} while(n == -1)
				N[j] = n;
				var item = $('<div></div>');
				item.text(dot + list.eq(n).text());
				text.append(item);
			}
		}
	}
	return;
}

// Funzioni (2) di countdown
var timers = new Array();
// Parametri:
// i: Indice del contatore
function updateTimer(i) {
	var node = $('span.countdowntimer').eq(i);
	var now = new Date();
	var then = new Date();
	then.setTime(node.attr('eventdate'));
	var diff = Math.floor((then.getTime() - now.getTime()) / 1000);

	// catch bad date strings
	if(isNaN(diff)) {
		node.text('** ' + then.toString() + ' **');
		return;
	}
	diff = Math.abs(diff);
	var left = ' ';

	// calcuate the diff
	left = (diff % 60) + ' secondi ' + left;
	diff = Math.floor(diff / 60);
	if(diff > 0) {
		left = (diff % 60) + ' minuti e ' + left;
	}
	diff = Math.floor(diff / 60);
	if(diff > 0) {
		left = (diff % 24) + ' ore, ' + left;
	}
	diff = Math.floor(diff / 24);
	if(diff > 0) {
		left = diff + ' giorni, ' + left
	}
	node.text(left);

	// a setInterval() is more efficient, but calling setTimeout()
	// makes errors break the script rather than infinitely recurse
	timers[i] = setTimeout('updateTimer(' + i + ')',1000);
	return;
}

function checkTimers() {
	$('span.notimer').hide();
	$('span.countdowntimer').each(function(i) {
		var node = $(this);
		date = new Date(node.text())
		node.attr('eventdate', date.getTime()).text('0 giorni 0 ore 0 minuti 0 secondi').css('display', 'inline');
		updateTimer(i);
	});
	return;
}

// Funzioni (2) per il Template:Counter
// Autore: Genuzzo
function coolCounterUpdate(text) {
	text = text.split('&gt;')[1].split('\n')[0].replace(/\./g, '');
	if(!initializedCounter) {
		myCounter = new flipCounter('flip-counter', {value: text, inc: 0, pace: 0, auto: false});
		myCounter.add(1000);
		$('#coolcounterwait').remove();
		initializedCounter = true;
	}
	myCounter.setValue(text);
	return;
}

function initializeCoolCounter() {
	if($('#flip-counter').length > 0) {
		urll = '/api.php?action=parse&text={{NUMBEROFEDITS}}&format=xml';
        initializedCounter = false;
        setInterval(function() {
			$.ajax({
				url: wgServer + wgScriptPath + urll,
				dataType: 'text',
				success: function(data) {
					coolCounterUpdate(data);
				}
			});
		}, 5000);
	}
	return;
}

// Class che aggiunge "target= '_blank'" ai link
function targetBlank() {
	var tags = $('.target-blank a');
	if(!tags.length) {
		return;
	}
	tags.attr('target', '_blank');
	return;
}

// Funzione per inserire il nome utente in appositi elementi
// Autore: Sparkla
function usernameReplace() {
	var spanList = $('span.insertusername');
	if(!spanList.length) {
		return;
	}
	var defaultText = '<tuo nome>';
	if(wgUserName) {
		spanList.text(wgUserName);
		return;
	}
	else {
		spanList.text(defaultText);
	}
	var userPage = $('#pt-anonuserpage');
	if(userPage.length > 0) {
		var IP = $('a:first', userPage);
		if(!IP.length) {
			return;
		}
		spanList.each(function() {
			if($(this).text() == defaultText) {
				$(this).text(IP.text());
			}
		});
		return;
	}
	var IP = undefined;
	$.ajax({
		url: wgServer + wgScriptPath + '/api.php?action=query&meta=userinfo&format=xml',
		dataType: 'xml',
		async: false,
		success: function(data) {
			IP = $('userinfo', data).attr('name');
		}
	});
	if(!IP) {
		return;
	}
	spanList.each(function() {
		if($(this).text() == defaultText) {
			$(this).text(IP);
		}
	});
	return;
}


// Visualizza note come tooltip
// Autore: Sanjilops
function refTooltip() {
	$('sup.reference').each(function() {
		var span = $('<span></span>');
		var id = $(this).attr('id').replace(/^cite\_ref\-/, '');
		span.attr({
			'class': 'reference-tt',
			'id': 'cite-tt' + id
		});
		var ref = $('#cite_note-' + id.replace(/_(\d+)-\d+$/, '-$1') + ' span.reference-text').html();
		if(!ref) {
			return;
		}
		span.html(ref);
		if($(this).position().left < $('#bodyContent').width() / 2) {
			span.css('left', ($(this).width() - 1) + 'px');
		}
		else {
			span.css('right', ($(this).width() - 1) + 'px');
		}
		span.css('width', ref < 400 ? ref + 'px' : '400px');
		$(this).append(span);
	});
	return;
}