Utente:Sanjilops/monobook.js: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Contenuto aggiunto Contenuto cancellato
Nessun oggetto della modifica
mNessun oggetto della modifica
Riga 154: Riga 154:
}
}


var t, code = '', i, tmp;
var t, code = '', tmp;
const max_len = 4090;
const max_len = 4096;
t = o.responseXML.getElementsByTagName('text')[0].firstChild;
t = o.responseXML.getElementsByTagName('text')[0].firstChild;
if (t == null) return;
if (t.length > max_len) {
var I = t.length/max_len;
tmp = t.splitText(max_len);
alert(t.length);
for (i=0; i<I; i++) {
tmp = t.splitText(max_len * i);
code += t.data;
code += t.data;
code += tmp.data;
}
}
if (tmp.length) code += tmp.data;
else code += t.data;
var previewArea = document.getElementById("wikiPreview");
var previewArea = document.getElementById("wikiPreview");
previewArea.innerHTML += code;
previewArea.innerHTML += code;

Versione delle 03:36, 3 mag 2009

//disablehideEdit=1;
disablealertLoad=1;
disableaprilfish = 1;




function Main() {
  FastOpen();
  if (document.getElementById('alert-load')) alert("alert onload presenti");
  if (document.getElementById('alert-unload')) alert("alert onunload presenti");

 /* Funzioni dell'editor */
 if ((wgAction == "edit" || wgAction == "submit") && document.getElementById("toolbar")) {

  quickpreviewLoad();

if (mwCustomEditButtons) {
   mwCustomEditButtons[0] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
     "speedTip": "A capo",
     "tagOpen": "<br />\n",
     "tagClose": "",
     "sampleText": ""};

   mwCustomEditButtons[1] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/commons/0/05/Button_Anf%C3%BChrung.png",
     "speedTip": "Citazione",
     "tagOpen": "{" + "{Cit|",
     "tagClose": "}" + "}",
     "sampleText": "..."};

   mwCustomEditButtons[2] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/commons/0/0c/Button_P_template.png",
     "speedTip": "Template",
     "tagOpen": "{{",
     "tagClose": "}" + "}",
     "sampleText": "Template"};

   mwCustomEditButtons[3] = {
     "imageFile": "http://images.wikia.com/nonciclopedia/images/f/f9/Button_box.png",
     "speedTip": "Box",
     "tagOpen": '{|width="100%" align="center" style="background: #FFFFFF; color: #000000; border: 1px solid #000000; text-align: left; margin-bottom: 0px; margin-top: 0px; padding-right: 4px; padding-left: 4px;"\n|',
     "tagClose": "\n|}\n",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://images.wikia.com/nonciclopedia/images/0/0c/Button_Chuck.png",
     "speedTip": "tag generico",
     "tagOpen": "{{",
     "tagClose": "||firma=~~" + "~~{{VF|" + wgCurRevisionId + "}" + "}" + "}" + "}\n\n",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://images2.wikia.nocookie.net/nonciclopedia/images/a/a5/Button_Samara.png",
     "speedTip": "scadenza",
     "tagOpen": "{" + "{scadenza|{" + "{subst:7g}" + "}|note=",
     "tagClose": "|firma=~~" + "~~{{VF|" + wgCurRevisionId + "}" + "}" + "}" + "}\n\n",
     "sampleText": ""};
}

  if(wgCurRevisionId)
    mwEditButtons[9].tagOpen = '--~~' + '~~{{VF|' + wgCurRevisionId + '}' + '}';
   else
    mwEditButtons[9].tagOpen = '--~~' + '~~{{VF|}' + '}';

  }
}
addOnloadHook(Main);

function FastOpen() {
 var Box = document.getElementById("searchBody");
 if (!Box) return;
 var form = document.createElement("form");
  Box.appendChild(form);
 form.action = "/index.php";
 form.target = "_blank";
 var c = document.createElement("input");
 form.appendChild(c);
 c.type = "text";
 c.setAttribute('name', "title");
 c.size = "20";
 var menu = document.createElement("select");
 form.appendChild(menu);
 menu.setAttribute('name', "action");
 menu.options[menu.length] = new Option("Modifica", "edit", true);
 menu.options[menu.length] = new Option("Cronol", "history");
 menu.options[menu.length] = new Option("Elimina", "delete");
 var p = document.createElement("input");
 form.appendChild(p);
 p.type = "submit";
 p.value = "vai"; 
}




var quickpreview_firstLoad = true;


function quickpreview () {
	var previewArea = document.getElementById("wikiPreview");
	if (previewArea == null) return false;
	previewArea.innerHTML = '';
	if (quickpreview_firstLoad) {
		previewArea.style.display = 'block';
		var temp = document.getElementById("editintro");
		if (temp) temp.style.display = 'none';
		temp = document.getElementsByClassName("mw-newarticletext")[0];
		if (temp) temp.style.display = 'none';
		temp = document.getElementsByClassName("mw-warning-with-logexcerpt")[0];
		if (temp) temp.style.display = 'none';
		temp = document.getElementById("contentSub2");
		if (temp) temp.style.display = 'none';
		document.getElementById("firstHeading").innerHTML = wgPageName;
		quickpreview_firstLoad = false;
	 }

	var textbox = document.getElementById("wpTextbox1");	
	var t;
	var start = textbox.selectionStart, end = textbox.selectionEnd;
	if (start < end) t = textbox.value.slice(start, end);
	 else t = textbox.value;
	t = t.replace(/\n==/, "__TOC__\n\n==");
	t = t.replace(/\n/g, "%0A");
	t = t.replace(/&/g, "%26");
	document.getElementsByTagName('body')[0].style.cursor = 'progress';
	quickpreviewRequest(t);
	return;
 }


function quickpreviewRequest(text) {
	const max = 4080;
	const url = wgServer + "/api.php?action=parse&title=" + encodeURI(wgPageName) + "&format=xml&prop=text&text=__NOTOC__%0A";
	var r = text.slice(max);
	var httpRequest = new XMLHttpRequest();
	var id = setTimeout(function() { httpRequest.abort(); alert("Errore: timeout del server"); document.getElementsByTagName('body')[0].style.cursor = 'auto';}, 30000);
	httpRequest.onreadystatechange = function () { quickpreviewWrite(httpRequest, r, id); };
	httpRequest.open('GET', url + text.slice(0, max), true);
	httpRequest.send('');
	return;
 }

function quickpreviewWrite(o, text, id) {
	if (o.readyState != 4) return;
	clearTimeout(id);
	if (o.status != 200) {
		if (o.status && (o.status < 199 || o.status > 300))
			alert("Anteprima non riuscita. Risposta del server: " + o.status);
		return;
	 }
	if (o.responseXML == null)  {
		alert("Anteprima non riuscita (errore del parser?)");
		return;
	 }

	var t, code = '', tmp;
	const max_len = 4096;
	t = o.responseXML.getElementsByTagName('text')[0].firstChild;
	if (t.length > max_len) {
		tmp = t.splitText(max_len);
		code += t.data;
		code += tmp.data;
	 }
	 else code += t.data;
	var previewArea = document.getElementById("wikiPreview");
	previewArea.innerHTML += code;
	if (text) quickpreviewRequest(text);
	 else {
		document.getElementsByTagName('body')[0].style.cursor = 'auto';
	 }
	return;
}



function quickpreviewLoad() {
if (navigator.appName == 'Microsoft Internet Explorer') return;
var buttons = document.getElementsByClassName("editButtons")[0];
if (buttons == null) return;
var b = document.createElement('input');
b.type = 'button';
b.value = "Ant. rapida";
b.id = "quickpreview";
b.marginRight = "0.33em";
b.addEventListener('click', quickpreview, true);
buttons.insertBefore(b, document.getElementById("wpDiff"));
document.getElementById("wpPreview").value = "Anteprima";
buttons.getElementsByClassName("editHelp")[0].style.display = 'none';
return;
}