Utente:Jalo/monobook.js/test: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 13:
/** VARIABILI GLOBALI **/
arrayArgument = new Array (" ");
var httpsext = '';
Riga 617 ⟶ 603:
return "<"+text+">";
}
// Functions auxFicus and Ficus
Riga 1 621 ⟶ 1 170:
if (tornareIndietro == true)
WEUpdateFrame();
}
Riga 2 474 ⟶ 1 869:
document.body.appendChild(div);
div.getElementsByTagName('input')[0].focus();
}
//Funzioni per fare le query al DB con api.php
var wpajax = {
http: function(bundle) {
// mandatory: bundle.url
// optional: bundle.async
// optional: bundle.method
// optional: bundle.headers
// optional: bundle.data
// optional: bundle.onSuccess (xmlhttprequest, bundle)
// optional: bundle.onFailure (xmlhttprequest, bundle)
// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch(e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlhttp = false
}
}
}
if (xmlhttp) {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4)
wpajax.httpComplete(xmlhttp,bundle);
};
xmlhttp.open(bundle.method ? bundle.method : "GET",bundle.url,bundle.async == false ? false : true);
if (bundle.headers) {
for (var field in bundle.headers)
xmlhttp.setRequestHeader(field,bundle.headers[field]);
}
xmlhttp.send(bundle.data ? bundle.data : null);
}
return xmlhttp;
},
httpComplete: function(xmlhttp,bundle) {
if (xmlhttp.status == 200 || xmlhttp.status == 302) {
if (bundle.onSuccess)
bundle.onSuccess(xmlhttp,bundle);
} else if (bundle.onFailure) {
bundle.onFailure(xmlhttp,bundle);
} else {
// A activer en debug mode ?
// alert(xmlhttp.statusText);
}
}
};
// Parser
if (document.implementation.createDocument) {
var gml_xmlparser = new DOMParser();
}
function gml_XMLParse(string) {
if (document.implementation.createDocument) {
return gml_xmlparser.parseFromString(string, "text/xml");
} else if (window.ActiveXObject) {
var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
gml_xmldoc.async = "false";
ret = gml_xmldoc.loadXML(string);
if (!ret)
return null;
return gml_xmldoc.documentElement;
}
return null;
}
// HTMLize
String.prototype.htmlize = function() {
var chars = new Array('&','<','>','"');
var entities = new Array('amp','lt','gt','quot');
var regex = new RegExp();
var string = this;
for (var i=0; i<chars.length; i++) {
regex.compile(chars[i], "g");
string = string.replace(regex, '&' + entities[i] + ';');
}
return string;
}
//Questa variabile contiene il nome del browser utilizzato. Molto utile per evitare problemi
// di incompatibilita' tra la varie funzioni Javascript
// Si autovalorizza. Le sottovariabili da usare sono "BrowserDetect.browser", "BrowserDetect.version"
// e "BrowserDetect.OS"
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{ // for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};
BrowserDetect.init();
/**** Inizializzazione ****/
//Alias di document.getElementById
$ = function(id){
return document.getElementById(id);
};
//Ritorna true se la variabile toLoad contiene l'opzione str
mustLoad = (function(){
mustLoadCache = {};
var A = toLoad ? toLoad.split(' ') : [];
for(var i = 0; i < A.length; i++)
if (A[i])
mustLoadCache[A[i]] = true;
return function(str){
return mustLoadCache[str] === true;
};
})();
/** Codice di compatibilità con WikEd **/
//Copia dal frame di wikEd (http://en.wikipedia.org/wiki/User:Cacycle/wikEd.js) alla wpTextbox1 textarea
function WEUpdateTextarea(){
if (typeof(wikEdUseWikEd) != 'undefined')
if (wikEdUseWikEd == true)
WikEdUpdateTextarea();
}
//Copia la wpTextbox1 textarea nel frame del wikEd
function WEUpdateFrame(){
if (typeof(wikEdUseWikEd) != 'undefined')
if (wikEdUseWikEd == true)
WikEdUpdateFrame();
}
/**** Carica le funzioni personalizzate ****/
//Codice adattato da Prototype 1.6.0, http://www.prototypejs.org/
//Distribuito con licenza MIT-style
(function() {
/* Support for the DOMContentLoaded event is based on work by Dan Webb,
Matthias Miller, Dean Edwards and John Resig. */
var timer, fired = false;
function fireContentLoadedEvent() {
if (fired) return;
if (timer) window.clearInterval(timer);
contentLoaded();
fired = true;
}
if (document.addEventListener) {
if (navigator.userAgent.indexOf('AppleWebKit/') > -1) {
timer = window.setInterval(function() {
if (/loaded|complete/.test(document.readyState))
fireContentLoadedEvent();
}, 0);
window.addEventListener('load', fireContentLoadedEvent, false);
} else {
document.addEventListener("DOMContentLoaded",
fireContentLoadedEvent, false);
}
} else {
document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
$("__onDOMContentLoaded").onreadystatechange = function() {
if (this.readyState == "complete") {
this.onreadystatechange = null;
fireContentLoadedEvent();
}
};
}
})();
function contentLoaded(){
saveHistoryToCookie(); //memorizza le pagine visitate in un cookie
changeLinks();
addNavBarLinks();
addToolBoxLinks();
if(wgNamespaceNumber != -1){ //non nelle pagine speciali
if (mustLoad("ns0")) addEditSection0();
if (mustLoad("led")) lastEdit();
if (mustLoad("purg")) addPurge();
if (mustLoad("tabs")) add_tabs();
}
if (mustLoad("chat")) addChat();
if (mustLoad("since")) addSince();
if (mustLoad("allp")) setup_allpages_button();
ta['pt-logout'] = ['x', 'Logout (esci)']; //cambia l'accesskey per "logout"
akeytt();
}
//Modifica la sezione 0 della pagina
function addEditSection0(){
if(!$('ca-history'))
return;
var newLink = wgServer + wgScript + '?title=' + wgPageName + '&action=edit§ion=0';
addPortletLink('p-cactions', newLink, '0', 'ca-edit-0', 'Modifica la sezione 0');
}
/** AutoComplete: Based on http://www.webreference.com/programming/javascript/gr/column5/ **/
function AutoComplete(db, oText, /* optional */ nMaxSize){
this.oText = oText;
this.nMaxSize = nMaxSize || 20;
var oDiv = document.createElement('div');
oDiv.style.border = '2px solid green';
oDiv.style.position = 'absolute';
oDiv.style.visibility = 'hidden';
oDiv.style.backgroundColor = 'white';
this.oDiv = oDiv;
oText.parentNode.insertBefore(oDiv, oText.nextSibling);
this.db = db.sort();
oText.AutoComplete = this;
oText.onkeyup = AutoComplete.prototype.onTextChange;
oText.onblur = AutoComplete.prototype.onTextBlur;
};
AutoComplete.prototype.onTextBlur = function(){ this.AutoComplete.onblur(); };
AutoComplete.prototype.onblur = function(){ this.oDiv.style.visibility = "hidden"; };
AutoComplete.prototype.onTextChange = function(){ this.AutoComplete.onchange(); };
AutoComplete.prototype.onDivMouseDown = function(){ this.AutoComplete.oText.value = this.innerHTML; };
AutoComplete.prototype.onDivMouseOver = function(){ this.style.backgroundColor = 'lime'; };
AutoComplete.prototype.onDivMouseOut = function(){ this.style.backgroundColor = 'white'; };
AutoComplete.prototype.onchange = function(){
var txt = this.oText.value;
var aStr = [];
for(var i = 0; i < this.db.length; i++)
if(this.db[i].toLowerCase().indexOf(txt.toLowerCase()) == 0)
aStr.push(this.db[i]);
var nCount = aStr.length;
if ((this.nMaxSize == -1) || ((nCount < this.nMaxSize) && (nCount > 0))){
while (this.oDiv.hasChildNodes())
this.oDiv.removeChild(this.oDiv.firstChild);
var i, n = aStr.length;
for (i = 0; i < n; i++){
var d = document.createElement('div');
this.oDiv.appendChild(d);
d.appendChild(document.createTextNode(aStr[i]));
d.onmousedown = AutoComplete.prototype.onDivMouseDown;
d.onmouseover = AutoComplete.prototype.onDivMouseOver;
d.onmouseout = AutoComplete.prototype.onDivMouseOut;
d.AutoComplete = this;
}
this.oDiv.style.left = this.oText.offsetLeft+'px'; //NON-STANDARD! offsetLeft
this.oDiv.style.top = (this.oText.offsetTop+this.oText.clientHeight)+'px'; //NON-STANDARD! offsetTop e clientHeight
this.oDiv.style.visibility = "visible";
}
else {
this.oDiv.innerHTML = "";
this.oDiv.style.visibility = "hidden";
}
};
/** AutoComplete END **/
// Recupera il valore di un cookie
function GetCookie(name)
{
var cookie = ' ' + document.cookie;
var search = ' ' + name + '=';
var setStr = '';
var offset = 0;
var end = 0;
offset = cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = cookie.indexOf(';', offset)
if (end == -1)
end = cookie.length;
setStr = cookie.substring(offset, end);
setStr = setStr.replace(/\\+/g, ' ');
setStr = decodeURIComponent(setStr);
}
return(setStr);
}
// Setta il valore di un cookie
function SetCookie(name, value, expires, path, ___domain, secure)
{
var cookie = name + '=' + encodeURIComponent(value);
if (expires != null)
cookie += '; expires=' + expires
if (path != null)
cookie += '; path=' + path;
if (___domain != null)
cookie += '; ___domain=' + ___domain;
if (secure != null)
cookie += '; secure';
document.cookie = cookie;
}
/** WikiHistory **/
function getHistoryFromCookie(){
var c = GetCookie("wikiHistory");
var hist = c ? c.split('#') : [];
for(var i = 0; i < hist.length; i++)
hist[i] = decodeURIComponent(hist[i]);
return hist;
}
function saveHistoryToCookie(){
if(wgNamespaceNumber < 0) return;
var c = GetCookie("wikiHistory"), i;
var h = c ? c.split('#') : [];
var current = encodeURIComponent(wgPageName.replace(/_/g, ' ')), found = -1;
for(i = 0; i < h.length; i++)
if(h[i] == current){
found = i; break;
}
if(found == -1)
h.push(current);
else
h[found] = null;
var newh = [];
for(i = Math.max(0, h.length - 100); i < h.length; i++)
if(h[i] != null)
newh.push(h[i]);
var expire = new Date(); // scadenza del cookie
expire.setTime(expire.getTime() + (60 * 60 * 1000)); //scadenza di un'ora
SetCookie('wikiHistory', newh.join('#'), expire.toGMTString(), '/');
}
/** WikiHistory END **/
// Popola i combo box "argomento" nei popup della toollbat
function populateArrayArgument(Template, id)
{
var categoria = ""; // categoria da cui partire a cercare gli argomenti (es: "Categoria:Da controllare")
var skip = ""; // prefisso della sottocategoria che va scartato (es: "Categoria:Da tradurre - arte" diventa "arte")
switch(Template){
case "Categorizzare":
categoria = "Categoria:Categoria da definire";
skip = "Categoria:Categoria da definire -";
break;
case "Da unire":
categoria = "Categoria:Da unire per argomento";
skip = "Categoria:Da unire -";
break;
case "Incorso":
categoria = "Categoria:Eventi in corso";
skip = "Categoria:Eventi in corso -";
break;
case "Controlcopy":
categoria = "Categoria:Da controllare per copyright per argomento";
skip = "Categoria:Da controllare per copyright -";
break;
case "T":
categoria = "Categoria:Da tradurre per argomento";
skip = "Categoria:Da tradurre -";
break;
case "NN":
categoria = "Categoria:Voci con fonti non contestualizzate per argomento";
skip = "Categoria:Voci con fonti non contestualizzate -";
break;
case "P":
categoria = "Categoria:Segnalazioni NPOV per argomento";
skip = "Categoria:Segnalazioni NPOV";
break;
case "O":
categoria = "Categoria:Pagine orfane per argomento";
skip = "Categoria:Pagine orfane -";
break;
case "F":
categoria = "Categoria:Voci mancanti di fonti per argomento";
skip = "Categoria:Voci mancanti di fonti -";
break;
case "E":
categoria = "Categoria:Da verificare per enciclopedicità per argomento";
skip = "Categoria:Da verificare per enciclopedicità -";
break;
case "C":
categoria = "Categoria:Controllare per argomento";
skip = "Categoria:Controllare -";
break;
case "A":
categoria = "Categoria:Aiutare per argomento";
skip = "Categoria:Aiutare -";
break;
case "S":
case "S sezione":
categoria = "Categoria:Stub";
skip = "Categoria:Stub -";
break;
case "S tutti":
categoria = "Categoria:Stub per monobook";
skip = "Categoria:Stub";
break;
case "W":
categoria = "Categoria:Wikificare per argomento";
skip = "Categoria:Wikificare -";
break;
case "cancellazionens0":
categoria = "Categoria:Pagine in cancellazione per argomento";
skip = "Categoria:Pagine in cancellazione -";
break;
case "Immagine orfana":
categoria = "Categoria:Immagini orfane per argomento";
skip = "Categoria:Immagini orfane -";
break;
default:
return;
break;
}
wpajax.http({url: wgServer + wgScriptPath + '/api.php?action=query&list=categorymembers&cmtitle='+categoria+'&cmlimit=500&cmnamespace=14&format=xml', onSuccess: parseSubCategories, prefix: skip, id: id });
}
function sortAlpha(a,b)
{
return a.toUpperCase() > b.toUpperCase();
}
function parseSubCategories(xmlreq, data)
{
var api = xmlreq.responseXML;
if (api.firstChild.nodeName == "error") return;
members = api.getElementsByTagName('cm');
var prefix = data.prefix;
var id = data.id;
arrayArgument = new Array(" ");
for (i = 0; i< members.length; i++)
{
toCheck = members[i].getAttribute('title');
if (toCheck.indexOf(prefix) == 0)
{
toInsert = members[i].getAttribute('title').substr(prefix.length + 1);
// elenco categorie da non mostrare
if ((toInsert[0] != "-" && toInsert[1] != "-") &&
(toInsert.indexOf("argomento sconosciuto") == -1) &&
(toInsert.indexOf("non datate") == -1) &&
(toInsert.indexOf("per monobook") == -1) &&
(toInsert.indexOf("da classificare") == -1) &&
(toInsert.indexOf("per verificabilità") == -1) &&
(toInsert.indexOf("sezione") != 0) &&
(toInsert.indexOf("gennaio") != 0) &&
(toInsert.indexOf("febbraio") != 0) &&
(toInsert.indexOf("marzo") != 0) &&
(toInsert.indexOf("aprile") != 0) &&
(toInsert.indexOf("maggio") != 0) &&
(toInsert.indexOf("giugno") != 0) &&
(toInsert.indexOf("luglio") != 0) &&
(toInsert.indexOf("agosto") != 0) &&
(toInsert.indexOf("settembre") != 0) &&
(toInsert.indexOf("ottobre") != 0) &&
(toInsert.indexOf("novembre") != 0) &&
(toInsert.indexOf("dicembre") != 0) &&
(toInsert.indexOf("Gennaio") != 0) &&
(toInsert.indexOf("Febbraio") != 0) &&
(toInsert.indexOf("Marzo") != 0) &&
(toInsert.indexOf("Aprile") != 0) &&
(toInsert.indexOf("Maggio") != 0) &&
(toInsert.indexOf("Giugno") != 0) &&
(toInsert.indexOf("Luglio") != 0) &&
(toInsert.indexOf("Agosto") != 0) &&
(toInsert.indexOf("Settembre") != 0) &&
(toInsert.indexOf("Ottobre") != 0) &&
(toInsert.indexOf("Novembre") != 0) &&
(toInsert.indexOf("Dicembre") != 0))
arrayArgument.push(members[i].getAttribute('title').substr(prefix.length + 1));
}
}
arrayArgument.sort(sortAlpha);
var sel = document.getElementById(id);
// Cancello il vecchio contenuto della tendina
sel.length = 0;
// Carica le nuove opzioni
for (var j = 0, opt; j < arrayArgument.length; j++){
opt = new Option(arrayArgument[j],' ');
opt.value = arrayArgument[j];
sel.options[sel.options.length] = opt;
}
}
Riga 2 904 ⟶ 2 890:
// Setta la posizione del cursore
setCurPos(curPos,curPos+selDim);
}
Riga 2 944 ⟶ 2 901:
function creaTendina()
{
var tendina2 = document.createElement('select');
tendina2.name = 'popupSelect';
Riga 3 053 ⟶ 2 973:
tendina.options[tendina.options.length] = option;
}
}
Riga 4 292 ⟶ 4 201:
<option>WikiAfrica</option>\
<option>Wikilex</option>\
</select>\
</div>';
Riga 5 688 ⟶ 5 597:
$j(this).data( 'Ficus', function() {
var argomento = $j( '#wikieditor-toolbar-argomento' ).val();
aggiungiTesto("{{
})
},
Riga 7 730 ⟶ 7 639:
}
caricaTendinaPersonale();
|