MediaWiki:Gadget-corrections.js

Da Wikisource

Ocio: Daspò ver salvà, podaria esare neçesario snetare ła cache dal propio navegadore web par vedare i canbiamenti.

  • Firefox / Safari: tegner strucà el boton de łe letare grande Shift e schiciare sora Ricarga, o se nò struca Ctrl-F5 o Ctrl-R (⌘-R so Mac)
  • Google Chrome: strucare Ctrl-Shift-R (⌘-Shift-R so on Mac)
  • Internet Explorer / Edge: tegner strucà el boton Ctrl e schiciare so Ajorna, o sinò Ctrl-F5
  • Opera: Va in tel Menu → Inpostasion (Opera → Prefarense so on Mac) e pò in Privacy & sicuresa → Sneta dati del navegadore → Imajini e file in te ła cache.
/* taken from //wikisource.org/wiki/MediaWiki:Corrections.js
 * Author: ThomasV
 */

/**************
 * corrections 
 **************/


$(document).ready(function() {

	/* tradussion dei messagi javascript  */
	ws_messages = { 
		'optlist':'Opzion',
		'corr_list':"Coression fate a sta pagina",
		'corr_link':"Coression",
		'corr_one':"Un eror de stanpa </a> el xe stà coreto.",
		'corr_many':" erori de stanpa</a> i xe stà coreti."
	};
	ws_msg = function (name) {
		var m = ws_messages[name];
		if(m) return m; else return name;
	};
	
	get_optlist = function () {
		var optlist = document.getElementById("optlist"), cl;
		if(!optlist) {
			var displayOptions = document.createElement("div");
			if (mw.config.get('skin')==='vector') {
				displayOptions.className = "vector-menu vector-menu-portal portal collapsed";
				cl="vector-menu-content";
			} else {
				displayOptions.className = "portlet";
				cl="pBody";
			}
			displayOptions.innerHTML = '<h3 class="vector-menu-heading">' + ws_msg('optlist') + '<\/h3><div class="'+cl+'"><ul id="optlist"></ul><\/div>';
			var ptb = document.getElementById("p-tb");
			ptb.parentNode.insertBefore(displayOptions,ptb);
			displayOptions.setAttribute("id","p-displayOptions");
			displayOptions.id="p-displayOptions"; /* */
			optlist = document.getElementById("optlist");
		}
		return optlist;
	};
	
	close_corr_summary = function() {
		var summary = document.getElementById("corr_summary");
		if(!summary) return;
		summary.innerHTML = "";
		summary.parentNode.removeChild(summary);
	
		//cavo la sotolineadura
		$("span.coquille").css("border-bottom", "");
	};
	
	highlightCorr = function(index) {
		$("span.coquille")[index].style.backgroundColor = "yellow";
	};
	dehighlightCorr = function (index) {
		$("span.coquille")[index].style.backgroundColor = "";
	};
	
	
	scroll_to_correction = function(k) {
		var selectedPosX = 0;
		var selectedPosY = 0;
		var j=0;
		var spanlist = $('span.coquille');
		for(var i=0; i < spanlist.length; i++) {
			var item = spanlist[i];
				j = j+1; 
				if (j==k) {
					element=item;
					while(element !== null) {
						selectedPosX += element.offsetLeft;
						selectedPosY += element.offsetTop;
						element = element.offsetParent;
					}
					window.scrollTo(selectedPosX,selectedPosY);
			}
		}
	};
	
	pr_popup = function() {
		var corr_container = document.getElementById("corr_summary");
		if(corr_container) { close_corr_summary(); return; }
	
		//sotolineo de rosso
		$("span.coquille").css("border-bottom", "1px solid red");
	
		corr_container = document.createElement("div");
		corr_container.setAttribute("id","corr_summary");
		corr_container.className="uls-menu";
	
		var content= document.getElementById("text");
		var spanlist = document.getElementsByTagName("span");
		if (!content) for(var i=0; i< spanlist.length; i++) { if( spanlist[i].className=="text") content=item; }
		if (content) {
			corr_container.style.cssText="position:relative;";
			corr_container.innerHTML = '<div style="display:block;position:absolute;right:-0.5em;width:0em;"><div style="position:fixed;min-width:16em;max-width:35em;max-height:35em;background:#ffffff;z-index:1;border:1px solid;padding:5px">'+corr_list+'</div></div>';
			content.insertBefore(corr_container,content.firstChild);
		} else {
			corr_container.style.cssText="display:block;position:fixed;min-width:16em;max-width:35em;max-height:35em;scroll:auto;right:0.5em;background:#ffffff;z-index:1;border:1px solid;padding:5px";
			corr_container.innerHTML = corr_list;
			content = document.getElementById("bodyContent");
			content.insertBefore(corr_container,content.firstChild);
		}
	};
	
	
	var str = '<div class="row"><span class="icon-close" onclick="close_corr_summary()"></span></div>'
		+'<h4>'+ ws_messages.corr_list + ":</h4><ul>"; 
	var j=0;
	var spanlist = $('span.coquille');
	for (var i=0; i < spanlist.length; i++) {
		var item = spanlist.get(i);
		j=j+1;
		w1=w2='';
		if (item.previousSibling && item.previousSibling.data) { 
			context1=item.previousSibling.data.split(' ');
			if(context1.length>1) w1 = context1[context1.length - 2].replace(/[\s]*/g, '') + ' ' + context1[context1.length - 1].replace(/[\s]*/g, '');
		}
		if (item.nextSibling && item.nextSibling.data) { 
			context2=item.nextSibling.data.split(' ');
			if(context2.length>1) w2 = context2[0].replace(/[\s]*/g, '') + ' ' + context2[1].replace(/[\s]*/g, ''); 
		}

		//hidden "m" char is to avoid rtl languages firefox bug
		var newline = '<li>'+'<a style=\"color:#000000;\" href=\"javascript:scroll_to_correction('+j+');\" onMouseOver=\"highlightCorr('+(j-1)+')\" onMouseOut=\"dehighlightCorr('+(j-1)+')\"> « '
		+ w1 + '<span style=\"color:#ff0000;\">#pre#</span>'
		+ w2 + ' » → « '
		+ w1 + '<span style=\"color:#00A000;\">#post#</span>'
		+ w2 + ' »</a> #eco#</li>'; 

		//recupera link a errata corrige originale (se presente)
		var innerText = item.innerHTML;
		var eco = "";
		if (innerText.indexOf('<span class="eco">') != -1) {
			eco = "(" + innerText.substring(innerText.indexOf('<span class="eco">')) + ")";
			innerText = innerText.substring(0, innerText.indexOf('<span class="eco">'));
		}
		newline = newline.replace("#eco#", eco);

		if (mw.config.get('wgCanonicalNamespace') == 'Page') {
			newline = newline.replace("#pre#", innerText);
			newline = newline.replace("#post#",item.title);
		}
		else {
			newline = newline.replace("#pre#",item.title);
			newline = newline.replace("#post#", innerText);
		}
		str = str + newline; 
	}
	str=str+'</ul>';
	corr_list = str;

	if (j > 0) {
		get_optlist();
		mw.util.addPortletLink('p-displayOptions', 'javascript:pr_popup();', ws_messages.corr_link +" ("+j+")", 'option-corrections', '' );
		cs = document.getElementById("corr-info");
		if (cs) {
			if (j==1)
				cs.innerHTML = ' <a href="javascript:pr_popup();">' + ws_messages.corr_one;
			else
				cs.innerHTML = ' <a href="javascript:pr_popup();">' + j + ws_messages.corr_many; 
		}

		//espandi de default le opzioni
		$("#p-displayOptions > div.body").show();
	}
});
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wikisource.org/w/index.php?title=MediaWiki:Gadget-corrections.js&oldid=72416"