Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
// Nuova versione; il testo da editare viene inserito in una textarea, gli spazi  
// e gli acapo sono resi non editabili mediante analisi dell'evento oninput della textarea (verifica della 
// regolarità dell'input: il numero dei caratteri spazio e acapo non deve essere modificato)

// TODO: da gestire il corretto ripristino della posizione del puntatore mediante memorizzazione del selectionStart, selectionEnd
// sulla textarea




// rimpiazzale parole modificate nel testo dsed
function preFix() {
	recover();
	r=/^( *\(word \d+ \d+ \d+ \d+ ".+"\))/gm;
	var preTesto=$("pre").text();
	var wordLines=preTesto.match(r);
	for (i=0;i<wordLines.length;i+=1) {
		var testoSpan=$("#page_text span").eq(i).text();
		wordLinesNew=wordLines[i].replace(/(.*").+(".+)/,"$1"+testoSpan+"$2");
		if (wordLinesNew!==wordLines[i]) preTesto=preTesto.replace(wordLines[i],wordLinesNew);
	}
	$("pre").text(preTesto);
}



function lista() {
	var testo=$("pre").text();
	var parola="";
	
	// analisi della struttura del file dsed
	// 1. Struttura canonica, tipo IA: words=True e lines=True
	// 2. Struttura da FineReader11, prima edizione: words=False e lines=True
	// 3. Struttura da FineReader11, edizioneXavier:words=True e lines=False
	// Altre strutture:words=False lines=False  NON GESTITA
	// non gestita nemmeno la struttura a dettaglio integrale char 
	
	var words=true;
	var lines=true;
	if (testo.indexOf("(word")===-1) words=false;
	if(testo.indexOf("(line")===-1) lines=false;
	
	// gestione struttura 1
	
	if (words && lines) {
		testo=testo.split("\n");
		var l=[];
		for (i=0;i<testo.length;i+=1) { 
			if (testo[i].indexOf("(line")!=-1) {
			l.push("\n");
				
			}
				
				
			if (testo[i].indexOf("(word")!=-1) {
				parola=find_stringa(testo[i],'"','")',0);
				
				l.push(parola);
				testo[i]=testo[i].replace('"'+parola+'"','"'+i+'"');
			}
		}
	}
	
	// gestione struttura 2 (words=false, lines=true)
	
	// g3stione struttura 3 (words=true, lines=false)
	var textarea=$('<textarea id="djvuEditor" cols="40" rows="25" name=djvuEditor>');
        textarea.val(l.join(" ")).attr("oninput","valida()");
        mw.testoDjvuEditor=textarea.val();
        $("#page_text").append(textarea);
        mw.spazi=ccount(textarea.val()," ");
        mw.acapi=ccount(textarea.val(),"\n");
   return false;	
}

function valida() { if (ccount($("#djvuEditor").val()," ")===mw.spazi && ccount($("#djvuEditor").val(),"\n")===mw.acapi) 
	mw.testoDjvuEditor=$("#djvuEditor").val();
	else {$("#djvuEditor").val(mw.testoDjvuEditor);
             alert("I caratteri spazio e acapo non possono essere modificati,\nla modifica è stata annullata"); }
	
}

function ccount(testo,car) {

	return (testo.length-testo.replace(new RegExp(car,"g"),"").length);
	
}
$(document).ready(function() {
if (wgPageName=="Utente:Alex_brollo/djvuEditor") {
   lista();
   }
});