« MediaWiki:Common.js » : différence entre les versions
Jump to navigation
Jump to search
Aucun résumé des modifications |
Aucun résumé des modifications |
||
(18 versions intermédiaires par 3 utilisateurs non affichées) | |||
Ligne 1 : | Ligne 1 : | ||
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ |
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ |
||
// |
// ============================================================ |
||
////////////////////////// |
//////////// FONCTION : .indexOf (Patch IE) ////////////// |
||
addOnloadHook( function(){ |
|||
if (!Array.indexOf) { |
|||
var wpSave = document.getElementById('wpSave'); |
|||
Array.prototype.indexOf = function(obj,idx) { |
|||
if(wpSave){ |
|||
var len = this.length; |
|||
wpSave.onclick = function(){ |
|||
if (len == 0) return -1; |
|||
document.getElementById('editform').style.display = "none"; |
|||
if (!idx) idx = 0; |
|||
while (idx < 0) idx = len + idx; |
|||
for (var i = 0; i < len; i++) |
|||
if (this[i] == obj) |
|||
return i; |
|||
return -1; |
|||
} |
|||
} |
|||
// ============================================================ |
|||
// ============================================================ |
|||
//////////// FONCTION : .HTMLize (évite des attaques XSS) ////////////// |
|||
if(!String.HTMLize){ |
|||
String.prototype.HTMLize = function() { |
|||
var chars = new Array('&','<','>','"'); |
|||
var entities = new Array('amp','lt','gt','quot'); |
|||
var string = this; |
|||
for (var i=0; i<chars.length; i++) { |
|||
var regex = new RegExp(chars[i], "g"); |
|||
string = string.replace(regex, '&' + entities[i] + ';'); |
|||
} |
} |
||
return string; |
|||
});/////////////////////////////// |
|||
} |
|||
// ============================================================================ |
|||
} |
|||
// ============================================================ |
|||
// =========================================================================== |
// ================================================================================================== |
||
//////////// FONCTIONS RELATIVES AUX COOKIES ////////////// |
|||
//////////////////////////////////////////////////// Patch extension WhosOnline (liens bleus -> rouges) |
|||
function setCookie (cookieName, cookieValue, expires, path) { |
|||
function WhosOnline_CheckNewPage(position){ |
|||
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; EXPIRES=' + expires.toGMTString() : '') + "; PATH=/" ; |
|||
var ListePresents = document.getElementById('WhosOnlineList'); |
|||
} |
|||
if(!ListePresents) return; |
|||
if(!position) position=0; |
|||
function getCookie(cookieName) { |
|||
var Lien = ListePresents.getElementsByTagName('a')[position]; |
|||
var cookieValue = null; |
|||
var |
var posName = document.cookie.indexOf(escape(cookieName) + '=' ); |
||
if (posName != -1) { |
|||
LienHref = LienHref.split(wgServer).join('').split('/wiki/').join(''); |
|||
var posValue = posName + (escape(cookieName) + '=' ).length; |
|||
Requete = sajax_init_object(); |
|||
var endPos = document.cookie.indexOf(';', posValue) ; |
|||
var url = wgServer+'/w/api.php?action=query&redirects&titles='+LienHref; |
|||
if (endPos != -1) { |
|||
cookieValue = unescape(document.cookie.substring(posValue, endPos)); |
|||
Requete.send(null); |
|||
} else { |
|||
cookieValue = unescape(document.cookie.substring(posValue)); |
|||
if((Requete.readyState == 4)&&(Requete.status == 200)){ |
|||
var Reponse = document.createElement('div'); |
|||
Reponse.innerHTML = Requete.responseText; |
|||
var Spans = Reponse.getElementsByTagName('span')[7].innerHTML; |
|||
if(Spans.indexOf('missing=""')!=-1){ |
|||
Lien.className = "new"; |
|||
} |
|||
WhosOnline_CheckNewPage((position+1)); |
|||
} |
} |
||
} |
} |
||
return decodeURIComponent(cookieValue); |
|||
} |
|||
// ============================================================ |
|||
// ============================================================ |
|||
//////////// FONCTIONS : MANIPULATION DE CLASSES ////////////// |
|||
function hasClass(node, className) { |
|||
if (node.className == className) { |
|||
return true; |
|||
} |
|||
var reg = new RegExp('(^| )'+ className +'($| )') |
|||
if (reg.test(node.className)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
function addClass(node, className) { |
|||
if (hasClass(node, className)) { |
|||
return false; |
|||
} |
|||
node.className += ' '+ className; |
|||
return true; |
|||
} |
|||
function removeClass(node, className) { |
|||
if (!hasClass(node, className)) { |
|||
return false; |
|||
} |
|||
node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className); |
|||
return true; |
|||
} |
|||
function eregReplace(search, replace, subject) { |
|||
return subject.replace(new RegExp(search,'g'), replace); |
|||
} |
|||
// ============================================================ |
|||
//////////// FONCTION : RECUPERE LE CONTENU TEXTUEL D'UN ELEMENT ////////////// |
|||
function getTextContent(oNode) { |
|||
if (typeof(oNode.textContent)!="undefined") {return oNode.textContent;} |
|||
switch (oNode.nodeType) { |
|||
case 3: // TEXT_NODE |
|||
case 4: // CDATA_SECTION_NODE |
|||
return oNode.nodeValue; |
|||
break; |
|||
case 7: // PROCESSING_INSTRUCTION_NODE |
|||
case 8: // COMMENT_NODE |
|||
if (getTextContent.caller!=getTextContent) { |
|||
return oNode.nodeValue; |
|||
} |
|||
break; |
|||
case 9: // DOCUMENT_NODE |
|||
case 10: // DOCUMENT_TYPE_NODE |
|||
case 12: // NOTATION_NODE |
|||
return null; |
|||
break; |
|||
} |
|||
var _textContent = ""; |
|||
oNode = oNode.firstChild; |
|||
while (oNode) { |
|||
_textContent += getTextContent(oNode); |
|||
oNode = oNode.nextSibling; |
|||
} |
|||
return _textContent; |
|||
} |
|||
// =============================================== |
|||
// =============================================== |
|||
//////////// FONCTION : INSERE UN ELEMENT APRES UN ELEMENT DE REFERENCE ////////////// |
|||
function insertAfter(element, reference) { |
|||
if(reference.nextSibling!=null){ |
|||
reference.parentNode.insertBefore(element, reference.nextSibling); |
|||
}else{ |
|||
reference.parentNode.appendChild(element); |
|||
} |
|||
} |
|||
// =============================================== |
|||
// =============================================== |
|||
//////////// FONCTION : DECODE LE HTML ISSU D'UNE REQUETE API ////////////// |
|||
function API_HTMLDecode(text){ |
|||
var EncodedCharacter = new Array(); |
|||
var DecodedCharacter = new Array(); |
|||
var CharacterCount = 0; |
|||
EncodedCharacter[CharacterCount] = "&"; |
|||
DecodedCharacter[CharacterCount] = "&"; |
|||
CharacterCount++; |
|||
EncodedCharacter[CharacterCount] = "'"; |
|||
DecodedCharacter[CharacterCount] = "'"; |
|||
CharacterCount++; |
|||
EncodedCharacter[CharacterCount] = """; |
|||
DecodedCharacter[CharacterCount] = '"'; |
|||
CharacterCount++; |
|||
for(var a=0;a<EncodedCharacter.length;a++){ |
|||
while(text.indexOf(EncodedCharacter[a])!=-1){ |
|||
text = text.split(EncodedCharacter[a]).join(DecodedCharacter[a]); |
|||
if(text.indexOf(EncodedCharacter[a])==-1) break; |
|||
} |
|||
} |
|||
return text; |
|||
} |
} |
||
addOnloadHook(WhosOnline_CheckNewPage); |
|||
// =============================================== |
// =============================================== |
Dernière version du 2 décembre 2023 à 14:36
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ // ============================================================ //////////// FONCTION : .indexOf (Patch IE) ////////////// if (!Array.indexOf) { Array.prototype.indexOf = function(obj,idx) { var len = this.length; if (len == 0) return -1; if (!idx) idx = 0; while (idx < 0) idx = len + idx; for (var i = 0; i < len; i++) if (this[i] == obj) return i; return -1; } } // ============================================================ // ============================================================ //////////// FONCTION : .HTMLize (évite des attaques XSS) ////////////// if(!String.HTMLize){ String.prototype.HTMLize = function() { var chars = new Array('&','<','>','"'); var entities = new Array('amp','lt','gt','quot'); var string = this; for (var i=0; i<chars.length; i++) { var regex = new RegExp(chars[i], "g"); string = string.replace(regex, '&' + entities[i] + ';'); } return string; } } // ============================================================ // ================================================================================================== //////////// FONCTIONS RELATIVES AUX COOKIES ////////////// function setCookie (cookieName, cookieValue, expires, path) { document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; EXPIRES=' + expires.toGMTString() : '') + "; PATH=/" ; } function getCookie(cookieName) { var cookieValue = null; var posName = document.cookie.indexOf(escape(cookieName) + '=' ); if (posName != -1) { var posValue = posName + (escape(cookieName) + '=' ).length; var endPos = document.cookie.indexOf(';', posValue) ; if (endPos != -1) { cookieValue = unescape(document.cookie.substring(posValue, endPos)); } else { cookieValue = unescape(document.cookie.substring(posValue)); } } return decodeURIComponent(cookieValue); } // ============================================================ // ============================================================ //////////// FONCTIONS : MANIPULATION DE CLASSES ////////////// function hasClass(node, className) { if (node.className == className) { return true; } var reg = new RegExp('(^| )'+ className +'($| )') if (reg.test(node.className)) { return true; } return false; } function addClass(node, className) { if (hasClass(node, className)) { return false; } node.className += ' '+ className; return true; } function removeClass(node, className) { if (!hasClass(node, className)) { return false; } node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className); return true; } function eregReplace(search, replace, subject) { return subject.replace(new RegExp(search,'g'), replace); } // ============================================================ //////////// FONCTION : RECUPERE LE CONTENU TEXTUEL D'UN ELEMENT ////////////// function getTextContent(oNode) { if (typeof(oNode.textContent)!="undefined") {return oNode.textContent;} switch (oNode.nodeType) { case 3: // TEXT_NODE case 4: // CDATA_SECTION_NODE return oNode.nodeValue; break; case 7: // PROCESSING_INSTRUCTION_NODE case 8: // COMMENT_NODE if (getTextContent.caller!=getTextContent) { return oNode.nodeValue; } break; case 9: // DOCUMENT_NODE case 10: // DOCUMENT_TYPE_NODE case 12: // NOTATION_NODE return null; break; } var _textContent = ""; oNode = oNode.firstChild; while (oNode) { _textContent += getTextContent(oNode); oNode = oNode.nextSibling; } return _textContent; } // =============================================== // =============================================== //////////// FONCTION : INSERE UN ELEMENT APRES UN ELEMENT DE REFERENCE ////////////// function insertAfter(element, reference) { if(reference.nextSibling!=null){ reference.parentNode.insertBefore(element, reference.nextSibling); }else{ reference.parentNode.appendChild(element); } } // =============================================== // =============================================== //////////// FONCTION : DECODE LE HTML ISSU D'UNE REQUETE API ////////////// function API_HTMLDecode(text){ var EncodedCharacter = new Array(); var DecodedCharacter = new Array(); var CharacterCount = 0; EncodedCharacter[CharacterCount] = "&"; DecodedCharacter[CharacterCount] = "&"; CharacterCount++; EncodedCharacter[CharacterCount] = "'"; DecodedCharacter[CharacterCount] = "'"; CharacterCount++; EncodedCharacter[CharacterCount] = """; DecodedCharacter[CharacterCount] = '"'; CharacterCount++; for(var a=0;a<EncodedCharacter.length;a++){ while(text.indexOf(EncodedCharacter[a])!=-1){ text = text.split(EncodedCharacter[a]).join(DecodedCharacter[a]); if(text.indexOf(EncodedCharacter[a])==-1) break; } } return text; } // ===============================================