MediaWiki: Common.js : Différence entre versions
De ECU
Ligne 359 : | Ligne 359 : | ||
}); | }); | ||
+ | |||
+ | |||
+ | function ddm() { | ||
+ | |||
+ | // Variables, change these in case you need to set other class names (mmhide_ for | ||
+ | // contribute users for example) | ||
+ | var parentClass = 'isParent'; //gets applied when the LI has a nested UL | ||
+ | var activeParentClass = 'isActive'; //gets applied when the nested UL is visible | ||
+ | var preventHoverClass = 'nohover'; //denotes a navigation that should not get any hover effects | ||
+ | var indicateJSClass = 'dhtml'; //gets applied to the main navigation when Javascript is available | ||
+ | var toHideClass = 'hiddenChild'; //gets applied to hide the nested UL | ||
+ | var toShowClass = 'shownChild'; //gets applied to show the nested UL | ||
+ | var currentClass = 'current'; //denotes the current active sub element and prevents collapsing | ||
+ | var d = document.getElementById('nav'); //denotes the navigation element | ||
+ | |||
+ | // if DOM is not available stop right here. | ||
+ | if (!document.getElementById && !document.createTextNode) { | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // if the navigation element is available, apply the class denoting DHTML capabilities | ||
+ | if (d) { | ||
+ | d.className += d.className == '' ? indicateJSClass : ' ' + indicateJSClass; | ||
+ | var lis, i, firstUL, j, apply; | ||
+ | |||
+ | // loop through all LIs and check which ones have a nested UL | ||
+ | lis = d.getElementsByTagName('li'); | ||
+ | for (i = 0; i < lis.length; i++) { | ||
+ | firstUL = lis[i].getElementsByTagName('ul')[0]; | ||
+ | // if there is a nested UL, deactivate the first nested link and apply the class to show | ||
+ | // there is a nested list | ||
+ | if (firstUL) { | ||
+ | lis[i].childNodes[0].onclick = function() { | ||
+ | return false; | ||
+ | }; | ||
+ | lis[i].className += lis[i].className == '' ? parentClass : ' ' + parentClass; | ||
+ | // check if there is a "current" element | ||
+ | apply = true; | ||
+ | if (new RegExp('\\b' + currentClass + '\\b').test(lis[i].className)) { | ||
+ | apply = false; | ||
+ | } | ||
+ | if (apply) { | ||
+ | for (j = 0; j < firstUL.getElementsByTagName('li').length; j++) { | ||
+ | if (new RegExp('\\b' + currentClass + '\\b').test(firstUL.getElementsByTagName('li')[j].className)) { | ||
+ | apply = false; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | // if there is no current element, apply the class to hide the nested list | ||
+ | if (apply) { | ||
+ | firstUL.className += firstUL.className == '' ? toHideClass : ' ' + toHideClass; | ||
+ | // check if there is a class to prevent hover effects and only apply the function | ||
+ | // onclick if that is the case, otherwise apply it onclick and onhover | ||
+ | if (new RegExp('\\b' + preventHoverClass + '\\b').test(d.className)) { | ||
+ | lis[i].onclick = function() { | ||
+ | doddm(this); | ||
+ | }; | ||
+ | } else { | ||
+ | lis[i].onclick = function() { | ||
+ | doddm(this); | ||
+ | }; | ||
+ | lis[i].onmouseover = function() { | ||
+ | doddm(this); | ||
+ | }; | ||
+ | lis[i].onmouseout = function() { | ||
+ | doddm(null); | ||
+ | }; | ||
+ | } | ||
+ | // if there is a current element, define the list as being kept open and apply the | ||
+ | // classes to show the nested list and define the parent LI as an active one | ||
+ | } else { | ||
+ | lis[i].keepopen = 1; | ||
+ | firstUL.className += firstUL.className == '' ? toShowClass : ' ' + toShowClass; | ||
+ | lis[i].className = lis[i].className.replace(parentClass, activeParentClass); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | // function to show and hide the nested lists and add the classes to the parent LIs | ||
+ | function doddm(o) { | ||
+ | var childUL, isobj, swap; | ||
+ | |||
+ | // loop through all LIs of the navigation | ||
+ | lis = d.getElementsByTagName('li'); | ||
+ | for (i = 0; i < lis.length; i++) { | ||
+ | isobj = lis[i] == o; | ||
+ | // function to exchange class names in an object | ||
+ | swap = function(tmpobj, tmporg, tmprep) { | ||
+ | tmpobj.className = tmpobj.className.replace(tmporg, tmprep); | ||
+ | }; | ||
+ | // if the current LI does not have an indicator to be kept visible | ||
+ | if (!lis[i].keepopen) { | ||
+ | childUL = lis[i].getElementsByTagName('ul')[0]; | ||
+ | // check if there is a nested UL and if the current LI is not the one clicked on | ||
+ | // and exchange the classes accordingly (ie. hide all other nested lists and | ||
+ | // make the LIs parent rather than active. | ||
+ | if (childUL) { | ||
+ | if (new RegExp('\\b' + preventHoverClass + '\\b').test(d.className)) { | ||
+ | if (new RegExp('\\b' + activeParentClass + '\\b').test(lis[i].className)) { | ||
+ | swap(childUL, isobj ? toShowClass : toHideClass, isobj ? toHideClass : toShowClass); | ||
+ | swap(lis[i], isobj ? activeParentClass : parentClass, isobj ? parentClass : activeParentClass); | ||
+ | } else { | ||
+ | |||
+ | swap(childUL, isobj ? toHideClass : toShowClass, isobj ? toShowClass : toHideClass); | ||
+ | swap(lis[i], isobj ? parentClass : activeParentClass, isobj ? activeParentClass : parentClass); | ||
+ | } | ||
+ | } else { | ||
+ | swap(childUL, isobj ? toHideClass : toShowClass, isobj ? toShowClass : toHideClass); | ||
+ | swap(lis[i], isobj ? parentClass : activeParentClass, isobj ? activeParentClass : parentClass); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | window.onload = function() { | ||
+ | ddm(); | ||
+ | // add other functions to be called onload below | ||
+ | }; |
Version du 12 juin 2019 à 13:32
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ $(function () { var myElement = document.getElementById('print'); myElement.innerHTML = '<button id="buttonprint" onclick = window.print()>Imprimer</button>'; }); $(function () { var myElement = document.getElementById('popupr'); myElement.innerHTML = '<button id="button1" onclick = document.getElementById("popup1").style.top="200px"> 1</button>'; }); $(function () { var myElement = document.getElementById('btnClose'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup1").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr2'); myElement.innerHTML = '<button id="button2" onclick = document.getElementById("popup2").style.top="178px"> 2</button>'; }); $(function () { var myElement = document.getElementById('btnClose2'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup2").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr3'); myElement.innerHTML = '<button id="button3" onclick = document.getElementById("popup3").style.top="130px"> 3</button>'; }); $(function () { var myElement = document.getElementById('btnClose3'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup3").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr4'); myElement.innerHTML = '<button id="button4" onclick = document.getElementById("popup4").style.top="200px"> 4</button>'; }); $(function () { var myElement = document.getElementById('btnClose4'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup4").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr5'); myElement.innerHTML = '<button id="button5" onclick = document.getElementById("popup5").style.top="340px"> 5</button>'; }); $(function () { var myElement = document.getElementById('btnClose5'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup5").style.top="-300px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr6'); myElement.innerHTML = '<button id="button6" onclick = document.getElementById("popup6").style.top="380px"> 6</button>'; }); $(function () { var myElement = document.getElementById('btnClose6'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup6").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr61'); myElement.innerHTML = '<button id="button61" onclick = document.getElementById("popup61").style.top="265px"> 61</button>'; }); $(function () { var myElement = document.getElementById('btnClose61'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup61").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr7'); myElement.innerHTML = '<button id="button7" onclick = document.getElementById("popup7").style.top="200px"> 7</button>'; }); $(function () { var myElement = document.getElementById('btnClose7'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup7").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr71'); myElement.innerHTML = '<button id="button71" onclick = document.getElementById("popup71").style.top="200px"> 71</button>'; }); $(function () { var myElement = document.getElementById('btnClose71'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup71").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr8'); myElement.innerHTML = '<button id="button8" onclick = document.getElementById("popup8").style.top="250px"> 8</button>'; }); $(function () { var myElement = document.getElementById('btnClose8'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup8").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr9'); myElement.innerHTML = '<button id="button9" onclick = document.getElementById("popup9").style.top="330px"> 9</button>'; }); $(function () { var myElement = document.getElementById('btnClose9'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup9").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr10'); myElement.innerHTML = '<button id="button10" onclick = document.getElementById("popup10").style.top="300px"> X</button>'; }); $(function () { var myElement = document.getElementById('btnClose10'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup10").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr11'); myElement.innerHTML = '<button id="button11" onclick = document.getElementById("popup11").style.top="150px"> 11</button>'; }); $(function () { var myElement = document.getElementById('btnClose11'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup11").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr12'); myElement.innerHTML = '<button id="button12" onclick = document.getElementById("popup12").style.top="180px"> 12</button>'; }); $(function () { var myElement = document.getElementById('btnClose12'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup12").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr13'); myElement.innerHTML = '<button id="button13" onclick = document.getElementById("popup13").style.top="270px"> 13</button>'; }); $(function () { var myElement = document.getElementById('btnClose13'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup13").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr14'); myElement.innerHTML = '<button id="button14" onclick = document.getElementById("popup14").style.top="150px"> 14</button>'; }); $(function () { var myElement = document.getElementById('btnClose14'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup14").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr15'); myElement.innerHTML = '<button id="button15" onclick = document.getElementById("popup15").style.top="300px"> 15</button>'; }); $(function () { var myElement = document.getElementById('btnClose15'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup15").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr16'); myElement.innerHTML = '<button id="button16" onclick = document.getElementById("popup16").style.top="305px"> 16</button>'; }); $(function () { var myElement = document.getElementById('btnClose16'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup16").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr161'); myElement.innerHTML = '<button id="button161" onclick = document.getElementById("popup161").style.top="205px"> 161</button>'; }); $(function () { var myElement = document.getElementById('btnClose161'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup161").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr17'); myElement.innerHTML = '<button id="button17" onclick = document.getElementById("popup17").style.top="180px"> 17</button>'; }); $(function () { var myElement = document.getElementById('btnClose17'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup17").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr18'); myElement.innerHTML = '<button id="button18" onclick = document.getElementById("popup18").style.top="200px"> 18</button>'; }); $(function () { var myElement = document.getElementById('btnClose18'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup18").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr19'); myElement.innerHTML = '<button id="button19" onclick = document.getElementById("popup19").style.top="340px"> 19</button>'; }); $(function () { var myElement = document.getElementById('btnClose19'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup19").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr20'); myElement.innerHTML = '<button id="button20" onclick = document.getElementById("popup20").style.top="330px"> 20</button>'; }); $(function () { var myElement = document.getElementById('btnClose20'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup20").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr21'); myElement.innerHTML = '<button id="button21" onclick = document.getElementById("popup21").style.top="305px"> 21</button>'; }); $(function () { var myElement = document.getElementById('btnClose21'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup21").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr22'); myElement.innerHTML = '<button id="button22" onclick = document.getElementById("popup22").style.top="200px"> 22</button>'; }); $(function () { var myElement = document.getElementById('btnClose22'); myElement.innerHTML = '<button id="btnClose" onclick=document.getElementById("popup22").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr23'); myElement.innerHTML = '<button id="button23" onclick = document.getElementById("popup23").style.top="200px"> INFORMATION</button>'; }); $(function () { var myElement = document.getElementById('btnClose23'); myElement.innerHTML = '<button id="btnClose1" onclick=document.getElementById("popup23").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr24'); myElement.innerHTML = '<button id="button24" onclick = document.getElementById("popup24").style.top="50px"> CONSULTATION</button>'; }); $(function () { var myElement = document.getElementById('btnClose24'); myElement.innerHTML = '<button id="btnClose1" onclick=document.getElementById("popup24").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr25'); myElement.innerHTML = '<button id="button25" onclick = document.getElementById("popup25").style.top="100px"> CONCERTATION</button>'; }); $(function () { var myElement = document.getElementById('btnClose25'); myElement.innerHTML = '<button id="btnClose1" onclick=document.getElementById("popup25").style.top="-1000px">× </button>'; }); $(function () { var myElement = document.getElementById('popupr26'); myElement.innerHTML = '<button id="button26" onclick = document.getElementById("popup26").style.top="150px"> CO-PRODUCTION</button>'; }); $(function () { var myElement = document.getElementById('btnClose26'); myElement.innerHTML = '<button id="btnClose1" onclick=document.getElementById("popup26").style.top="-1000px">× </button>'; }); function ddm() { // Variables, change these in case you need to set other class names (mmhide_ for // contribute users for example) var parentClass = 'isParent'; //gets applied when the LI has a nested UL var activeParentClass = 'isActive'; //gets applied when the nested UL is visible var preventHoverClass = 'nohover'; //denotes a navigation that should not get any hover effects var indicateJSClass = 'dhtml'; //gets applied to the main navigation when Javascript is available var toHideClass = 'hiddenChild'; //gets applied to hide the nested UL var toShowClass = 'shownChild'; //gets applied to show the nested UL var currentClass = 'current'; //denotes the current active sub element and prevents collapsing var d = document.getElementById('nav'); //denotes the navigation element // if DOM is not available stop right here. if (!document.getElementById && !document.createTextNode) { return; } // if the navigation element is available, apply the class denoting DHTML capabilities if (d) { d.className += d.className == '' ? indicateJSClass : ' ' + indicateJSClass; var lis, i, firstUL, j, apply; // loop through all LIs and check which ones have a nested UL lis = d.getElementsByTagName('li'); for (i = 0; i < lis.length; i++) { firstUL = lis[i].getElementsByTagName('ul')[0]; // if there is a nested UL, deactivate the first nested link and apply the class to show // there is a nested list if (firstUL) { lis[i].childNodes[0].onclick = function() { return false; }; lis[i].className += lis[i].className == '' ? parentClass : ' ' + parentClass; // check if there is a "current" element apply = true; if (new RegExp('\\b' + currentClass + '\\b').test(lis[i].className)) { apply = false; } if (apply) { for (j = 0; j < firstUL.getElementsByTagName('li').length; j++) { if (new RegExp('\\b' + currentClass + '\\b').test(firstUL.getElementsByTagName('li')[j].className)) { apply = false; break; } } } // if there is no current element, apply the class to hide the nested list if (apply) { firstUL.className += firstUL.className == '' ? toHideClass : ' ' + toHideClass; // check if there is a class to prevent hover effects and only apply the function // onclick if that is the case, otherwise apply it onclick and onhover if (new RegExp('\\b' + preventHoverClass + '\\b').test(d.className)) { lis[i].onclick = function() { doddm(this); }; } else { lis[i].onclick = function() { doddm(this); }; lis[i].onmouseover = function() { doddm(this); }; lis[i].onmouseout = function() { doddm(null); }; } // if there is a current element, define the list as being kept open and apply the // classes to show the nested list and define the parent LI as an active one } else { lis[i].keepopen = 1; firstUL.className += firstUL.className == '' ? toShowClass : ' ' + toShowClass; lis[i].className = lis[i].className.replace(parentClass, activeParentClass); } } } } // function to show and hide the nested lists and add the classes to the parent LIs function doddm(o) { var childUL, isobj, swap; // loop through all LIs of the navigation lis = d.getElementsByTagName('li'); for (i = 0; i < lis.length; i++) { isobj = lis[i] == o; // function to exchange class names in an object swap = function(tmpobj, tmporg, tmprep) { tmpobj.className = tmpobj.className.replace(tmporg, tmprep); }; // if the current LI does not have an indicator to be kept visible if (!lis[i].keepopen) { childUL = lis[i].getElementsByTagName('ul')[0]; // check if there is a nested UL and if the current LI is not the one clicked on // and exchange the classes accordingly (ie. hide all other nested lists and // make the LIs parent rather than active. if (childUL) { if (new RegExp('\\b' + preventHoverClass + '\\b').test(d.className)) { if (new RegExp('\\b' + activeParentClass + '\\b').test(lis[i].className)) { swap(childUL, isobj ? toShowClass : toHideClass, isobj ? toHideClass : toShowClass); swap(lis[i], isobj ? activeParentClass : parentClass, isobj ? parentClass : activeParentClass); } else { swap(childUL, isobj ? toHideClass : toShowClass, isobj ? toShowClass : toHideClass); swap(lis[i], isobj ? parentClass : activeParentClass, isobj ? activeParentClass : parentClass); } } else { swap(childUL, isobj ? toHideClass : toShowClass, isobj ? toShowClass : toHideClass); swap(lis[i], isobj ? parentClass : activeParentClass, isobj ? activeParentClass : parentClass); } } } } } } window.onload = function() { ddm(); // add other functions to be called onload below };