MediaWiki:Common.js : Différence entre versions
Ligne 45 : | Ligne 45 : | ||
/*test*/ | /*test*/ | ||
− | (function () { | + | (function(){ |
− | + | ||
− | + | var allInput = document.querySelectorAll("#input"); | |
+ | var resultat = document.getElementById("inputResult"); | ||
+ | |||
+ | allInput.forEach(function(e){ | ||
+ | |||
+ | e.insertAdjacentHTML('afterbegin','<input type="number"></input>'); | ||
+ | |||
+ | }); | ||
+ | |||
+ | resultat.insertAdjacentHTML('afterbegin','<input class="resultat" type="number"></input>'); | ||
+ | |||
})(); | })(); | ||
− | + | function calcul(Tab){ | |
− | + | ||
− | var | + | var resultat = document.getElementsByClassName('resultat'); |
− | + | var valueResult = 0; | |
− | + | ||
+ | Tab.forEach(function(e){ | ||
+ | if (e!="") { | ||
+ | valueResult += parseFloat(e); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | resultat[0].value = valueResult | ||
+ | } | ||
+ | |||
+ | (function(){ | ||
+ | |||
+ | var bouttonCalcul = document.getElementById("buttonCalcul"); | ||
+ | |||
+ | bouttonCalcul.addEventListener("click", function(){ | ||
+ | |||
+ | var tabValue = []; | ||
+ | var allRealInput = document.querySelectorAll("input"); | ||
+ | |||
+ | allRealInput.forEach(function(e){ | ||
+ | tabValue.push(e.value) | ||
+ | }); | ||
+ | |||
+ | calcul(tabValue); | ||
+ | |||
+ | }); | ||
})(); | })(); | ||
Version du 23 septembre 2021 à 15:15
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
/*Favicon*/
$('link[rel="shortcut icon"]').attr('href', 'https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico');
/*Tabber*/
function onTabClick(event) {
var tabberFrere = event.currentTarget.parentElement.nextElementSibling;
tabberActive = tabberFrere.parentElement.querySelectorAll(".tabber-active");
tabberActive.forEach(function(tab) {
tab.className = tab.className.replace('tabber-active', '');
});
event.currentTarget.className += ' tabber-active';
tabberFrere.children[parseInt(event.currentTarget.id)].className += ' tabber-active';
}
(function(){
var tabberContainer = document.querySelectorAll("#tabber-container");
tabberContainer.forEach(function(e){
var classButton = e.querySelectorAll(".button");
classButton.forEach(function(e) {
e.addEventListener('click', onTabClick, false);
});
});
})();
/*test*/
(function(){
var allInput = document.querySelectorAll("#input");
var resultat = document.getElementById("inputResult");
allInput.forEach(function(e){
e.insertAdjacentHTML('afterbegin','<input type="number"></input>');
});
resultat.insertAdjacentHTML('afterbegin','<input class="resultat" type="number"></input>');
})();
function calcul(Tab){
var resultat = document.getElementsByClassName('resultat');
var valueResult = 0;
Tab.forEach(function(e){
if (e!="") {
valueResult += parseFloat(e);
}
});
resultat[0].value = valueResult
}
(function(){
var bouttonCalcul = document.getElementById("buttonCalcul");
bouttonCalcul.addEventListener("click", function(){
var tabValue = [];
var allRealInput = document.querySelectorAll("input");
allRealInput.forEach(function(e){
tabValue.push(e.value)
});
calcul(tabValue);
});
})();
/* Pour les cookies */
(function () {
var req = new XMLHttpRequest();
req.addEventListener('load', function (ev) {
if (this.status >= 200 && this.status < 300) {
var data = JSON.parse(this.responseText);
if (data.hasOwnProperty('version')) {
var gdpr = document.createElement("script");
gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
document.head.appendChild(gdpr);
}
}
});
req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
req.send();
})();