Utilisateur:Dr Brains/Help.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.var Help = new Object();
Help.Variables = new Object();
/* ========================================================================================================================= */
Help.Variables.Params = new Object();
Help.Variables.Params.Page = "Utilisateur:Dr_Brains/Help";
Help.Variables.Params.TalkPage = "Discussion utilisateur:Dr_Brains/Help";
Help.Variables.Params.SearchTemplate = mw.config.get('wgScript') + "?search={searchTerms}";
Help.Variables.Options = new Object();
Help.Variables.Texts = new Object();
Help.Variables.Texts.ButtonAlt = "Aide";
/* ========================================================================================================================= */
Help.Functions = new Object();
Help.Functions.AjaxDoRequest = function(bundle){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) Help.Functions.AjaxReadRequest(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)
try {
xmlhttp.setRequestHeader(field,bundle.headers[field]);
} catch(err) { }
}
xmlhttp.send(bundle.data ? bundle.data : null);
return xmlhttp;
};
Help.Functions.AjaxReadRequest = 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);
}};
Help.Functions.Init = function(){
Help.Functions.AjaxDoRequest({url:mw.config.get('wgServer') + mw.config.get('wgScript') + "?title="+encodeURIComponent(Help.Variables.Params.Page)+"&action=render",
onSuccess:Help.Functions.InitPanel
});
};
Help.Functions.InitPanel = function(Req, data){
if(Help.Variables.running==true) return;
Help.Variables.running=true;
var Div = document.createElement('div');
Div.innerHTML = Req.responseText;
document.body.appendChild(Div);
var HelpButton = document.getElementById("HelpButton");
if(!HelpButton) return;
var Links = HelpButton.getElementsByTagName('a');
for(var a=0,l=Links.length;a<l;a++){
var Link = Links[a];
Link.href = "javascript:;"
Link.onclick = function (){ Help.Functions.GetPanel(); return false; };
}
var LinkList = document.getElementById("HelpLinksList");
if(!LinkList) return;
Help.Functions.TransformLinks(LinkList);
var HelpScreenContent = document.getElementById("HelpScreenContent");
Help.Functions.TransformLinks(HelpScreenContent);
Help.Functions.InitButtons();
Help.Functions.GetPanel();
var anchorNode = document.getElementById("ResizeButton");
Help.Functions.setVerticalResizeZone(anchorNode, new Array(HelpScreenContent, LinkList), Div);
/*
var Opened = Help.Functions.getCookie("HelpScreen");
alert(Opened);
if(Opened=="1"){
Help.Functions.GetPanel();
}
*/
};
Help.Functions.InitHelpScreen = function(){
document.getElementById("HelpContainer").style.display = "none";
document.getElementById("DefaultScreen").style.display = "";
var HelpScreenContaint = document.getElementById("HelpScreenContent");
if(HelpScreenContaint){
HelpScreenContaint.style.backgroundColor = "#002000";
HelpScreenContaint.style.color = "black";
}
}
Help.Functions.InitThisButton = function (ID, HREF, ONCLICK){
var Button = document.getElementById(ID);
if(Button){
var ButtonLink = Button.getElementsByTagName('a')[0];
if(ButtonLink){
ButtonLink.href= (HREF ? HREF : "javascript:;");
if(ONCLICK) ButtonLink.onclick = ONCLICK
}
}
}
Help.Functions.InitButtons = function (){
// Boutons
Help.Functions.InitThisButton("HomeButton", false, function(){ Help.Functions.InitHelpScreen(); Help.Functions.getMenu(this, true); });
Help.Functions.InitThisButton("InfoButton", false, function(){ Help.Functions.getPageInfo(this); });
Help.Functions.InitThisButton("ResizeButton");
}
Help.Functions.getMenu = function(TheNode, reboot){
var TheButton = TheNode.parentNode;
var TheUL = TheButton.getElementsByTagName('ul')[0];
var TheButtonDiv = document.getElementById("HelpPageButtons");
if(!TheButtonDiv) return;
var AllUls = TheButtonDiv.getElementsByTagName('ul');
if(reboot) Help.Functions.InitHelpScreen();
for(var b=0,m=AllUls.length;b<m;b++){
if(AllUls[b]==TheUL && !AllUls[b].classList.contains("ButtonOpened")){
document.getElementById("HelpContainer").style.display = "";
document.getElementById("DefaultScreen").style.display = "none";
document.getElementById("HelpContainer").innerHTML = "<ul>" + AllUls[b].innerHTML + "</ul>";
AllUls[b].classList.add("ButtonOpened");
var HelpScreenContaint = document.getElementById("HelpScreenContent");
if(HelpScreenContaint) HelpScreenContaint.style.backgroundColor = "#A0E0C0";
}else{
AllUls[b].classList.remove("ButtonOpened");
}
}
}
Help.Functions.GetPanel = function(){
var Panel = document.getElementById("HelpPanel");
var HelpButton = document.getElementById("HelpButton");
var CUT = getElementsByClassName(HelpButton, "span", "Bouton_Default")[0];
var OFF = getElementsByClassName(HelpButton, "span", "Bouton_Off")[0];
var ON = getElementsByClassName(HelpButton, "span", "Bouton_On")[0];
if(!Panel ||!HelpButton ||!ON || !OFF ||!CUT) return;
if(Panel.style.display =="none"){
Panel.style.display = "";
ON.style.display = "";
OFF.style.display = "none";
CUT.style.display = "none";
Help.Functions.setCookie("HelpScreen", "1");
}else{
Panel.style.display = "none";
ON.style.display = "none";
OFF.style.display = "";
CUT.style.display = "none";
Help.Functions.setCookie("HelpScreen", "0");
}
};
Help.Functions.TransformLinks = function(TheNode){
if(!TheNode) return;
var AllLinks = TheNode.getElementsByTagName('a');
for(var a=0,l=AllLinks.length;a<l;a++){
var Link = AllLinks[a];
if(Link.classList.contains("external")){
Link.target = "_blank";
continue;
}
if(Link.classList.contains("image") || Link.classList.contains("mw-file-description")){
Link.href = "javascript:;";
continue;
}
if(Link.parentNode.classList.contains("editsection")){
Link.parentNode.style.display = "none";
continue;
}
if(Link.href.indexOf("javascript:")!=-1){
continue;
}
Link.onclick = function(){ Help.Functions.loadPageFromLink(this); return false; };
}
};
Help.Functions.getPageInfo = function(Link){
Help.Functions.getMenu(Link, false);
var OtherSpaceNumber = (( mw.config.get('wgNamespaceNumber') % 2 == 0) ? (mw.config.get('wgNamespaceNumber')+1) : (mw.config.get('wgNamespaceNumber')-1) );
var OtherSpaceName = ( (OtherSpaceNumber!=0 && OtherSpaceNumber!="0") ? mw.config.get('wgFormattedNamespaces')[OtherSpaceNumber]+":" : "");
var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?format=xml&action=query&prop=info"
+ "&inprop=protection|talkid|watched|subjectid|url|readable|preload|displaytitle"
+ "&titles="
+ encodeURIComponent(mw.config.get('wgPageName')) + ( (mw.config.get('wgNamespaceNumber')!=-1) ? "|"+ encodeURIComponent(OtherSpaceName + mw.config.get('wgTitle')) : "");
Help.Functions.AjaxDoRequest({url:URL,onSuccess:Help.Functions.receivePageInfo});
}
Help.Functions.receivePageInfo = function(Req, data){
var ObjetXML = Req.responseXML;
var Pages = ObjetXML.getElementsByTagName('page');
var ThesesPages = new Array();
for(var a=0,l=Pages.length;a<l;a++){
var Page = Pages[a];
var PageName = Page.getAttribute('title');
ThesesPages[PageName] = new Array();
lenj = Page.attributes.length;
for (j=0; j<lenj; j++) {
var AttributeName = Page.attributes[j].name;
var AttributeValue = Page.attributes[j].value;
ThesesPages[PageName][AttributeName] = AttributeValue;
}
}
Help.Functions.displayPageInfo(ThesesPages);
}
Help.Functions.displayPageInfo = function(data){
var HelpContainer = document.getElementById("HelpContainer");
while(HelpContainer.firstChild){HelpContainer.removeChild(HelpContainer.firstChild); }
var PagesNumber = data.length;
var Table = document.createElement('table');
Table.setAttribute("style", "background:none;width:100%");
var TR = document.createElement('tr');
for(var Page in data){
var Thispage = data[Page];
var TD = document.createElement('td');
TD.setAttribute("valign" , "top");
TD.setAttribute("style", "width:" + parseInt(100/PagesNumber) +"%");
var P = document.createElement('p');
P.innerHTML = "<b><big>"+Page+"</big></b>";
TD.appendChild(P);
var UL = document.createElement('ul');
for(var info in Thispage){
var LI = document.createElement('li');
LI.innerHTML = info + " = " + Thispage[info];
UL.appendChild(LI);
}
TD.appendChild(UL);
TR.appendChild(TD);
}
Table.appendChild(TR);
HelpContainer.appendChild(Table);
Help.Functions.TransformLinks(HelpContainer);
document.getElementById("DefaultScreen").style.display = "none";
HelpContainer.style.display = "";
Help.Functions.TransformLinks(HelpContainer);
var HelpScreenContent = document.getElementById("HelpScreenContent");
if(HelpScreenContent) HelpScreenContent.style.backgroundColor = "#A0E0C0";
}
Help.Functions.getElementWithId = function( elementId , elementTagName , elementParentNode ){
if(!elementParentNode) elementParentNode = document.body;
if (elementParentNode.getElementById) return elementParentNode.getElementById(elementId);
var TheElement = false;
var Elements = elementParentNode.getElementsByTagName(elementTagName);
var elementcount = 0;
while(elementcount<Elements.length){
var Id = Elements[elementcount].getAttribute('id');
if(Id){
if(Id==elementId){
TheElement = Elements[elementcount];
break;
}
}
elementcount++
}
if (! TheElement) return null;
return TheElement;
}
Help.Functions.extractPage = function(html){
var TempDiv = document.createElement('div');
TempDiv.style.display = "none";
document.body.insertBefore(TempDiv, document.body.firstChild);
var Content = Help.Functions.getElementWithId("bodyContent", "div", TempDiv);
if(!Content) Content = Help.Functions.getElementWithId("mw_contentholder", "div", TempDiv);
if(!Content) Content = Help.Functions.getElementWithId("article", "div", TempDiv);
if(Content) html = Content.innerHTML;
TempDiv.parentNode.removeChild(TempDiv);
return html;
}
Help.Functions.loadPage = function(URL){
Help.Functions.AjaxDoRequest({url:URL,onSuccess:function(Req, data){
var URL = data.url;
var HelpContainer = document.getElementById("HelpContainer");
while(HelpContainer.firstChild){HelpContainer.removeChild(HelpContainer.firstChild); }
HelpContainer.innerHTML = Help.Functions.extractPage(Req.responseText);
Help.Functions.TransformLinks(HelpContainer);
document.getElementById("DefaultScreen").style.display = "none";
HelpContainer.style.display = "";
var HelpScreenContent = document.getElementById("HelpScreenContent");
if(HelpScreenContent){
HelpScreenContent.style.backgroundColor = "#B0FF60";
HelpScreenContent.scrollTop = 0;
}
}});
}
Help.Functions.loadPageFromLink = function(Link){
if(!Link) return;
var URL = Link.href + "?action=render";
Help.Functions.loadPage(URL);
}
// Mise à jour du cookie
Help.Functions.setCookie = function(cookieName, cookieValue, expires) {
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; EXPIRES=' + expires.toGMTString() : '') + "; PATH=/" ;
}
// Interrogation du cookie
Help.Functions.getCookie = function(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));
}
}
if(cookieValue) return decodeURIComponent(cookieValue);
}
// Détermination de la hauteur de l'écran
Help.Functions.getScreenHeight = function(){
var ScreenHeight = 0;
if( typeof( window.innerHeight ) == 'number' ) {
ScreenHeight = parseInt(window.innerHeight);
}else if( document.documentElement && document.documentElement.clientHeight ){
ScreenHeight = parseInt(document.documentElement.clientHeight);
}else if( document.body && document.body.clientHeight ){
ScreenHeight = parseInt(document.body.clientHeight);
}
return ScreenHeight;
}
// Détermination du positionnement de la souris
Help.Functions.getMousePosition = function(e){
if(!e) { e = window.event; }
//ie
if(document.all){
curX = event.clientX;
curY = event.clientY;
}
//netscape 4
if(document.layers){
curX = e.pageX;
curY = e.pageY;
}
//mozilla
if(document.getElementById){
curX = e.clientX;
curY = e.clientY;
}
return {"X": curX, "Y": curY};
}
// Mise en place d'une zone de redimensionnement vertical
Help.Variables.Params.IsResizing = false;
Help.Variables.Params.NodeInitialHeight = new Array();
Help.Functions.setVerticalResizeZone = function(anchorNode, ToResizeNodes, containerNode){
if((!anchorNode)||(!ToResizeNodes)) return;
anchorNode.onmousedown = function(e){
if(!e) { e = window.event; }
var MaxHeight = Help.Functions.getScreenHeight();
PositionSouris_Y = Help.Functions.getMousePosition(e)["Y"];
for(var a=0;a<ToResizeNodes.length;a++){
var Node = ToResizeNodes[a];
Help.Variables.Params.NodeInitialHeight[a] = parseInt( (MaxHeight-PositionSouris_Y) - Node.offsetHeight );
}
Help.Variables.Params.IsResizing = true;
}
document.getElementsByTagName('body')[0].onmousemove = function(e) {
if(!e) { e = window.event; }
if(!Help.Variables.Params.IsResizing) return;
var MaxHeight = Help.Functions.getScreenHeight();
var HeightLimit = false;
var NewPositionSouris_Y = Help.Functions.getMousePosition(event)["Y"];
var NewHeight = new Array();
for(var a=0;a<ToResizeNodes.length;a++){
var Node = ToResizeNodes[a];
NewHeight[a] = parseInt((MaxHeight-NewPositionSouris_Y)-Help.Variables.Params.NodeInitialHeight[a]);
if(NewHeight[a]>MaxHeight) HeightLimit = true;
if(NewHeight[a]<0) HeightLimit = true;
}
if(HeightLimit) return;
for(var a=0;a<ToResizeNodes.length;a++){
var Node = ToResizeNodes[a];
if(Node.tagName && (Node.tagName.toLowerCase()=="iframe" || Node.tagName.toLowerCase()=="img")){
Node.height = NewHeight[a];
}else{
Node.style.height = NewHeight[a] + 'px';
}
}
}
document.getElementsByTagName('body')[0].onmouseup = function() {
Help.Variables.Params.IsResizing = false;
}
anchorNode.className = "NResize";
}
/* ========================================================================================================================= */
if(mw.config.get('wgPageName')!="Utilisateur:Dr_Brains/Help"){
importStylesheet('Utilisateur:Dr Brains/Help.css');
addOnloadHook(Help.Functions.Init);
}