MediaWiki:Common.js

From Wiki Valley - MediaWiki hosting and consulting

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
/*JoonBot*/
!function () {
  if (window.JOONBOT_WIDGET_ID) {
    console.warn("Joonbot snippet included twice");
  } else {
    window.JOONBOT_WIDGET_ID = "232e40d0-4477-4b27-8801-5254b2bd001c";
    var n, o;
    o = document.createElement("script");
    o.src = "https://js.joonbot.com/init.js", o.defer = !0, o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous";
    n = document.getElementsByTagName("script")[0], n.parentNode.insertBefore(o, n);
  }
}();

/* Ajout des validations des chammps avec le champs Tel*/
var usernameOk = false;
var emailOk = false;
var phoneOk = false;
var WikinameOk = false;
var descOk = false;
var descLengthOk = false;
var ToSOk = false;
if(document.getElementById('BoutonEnvoi')){
	var BoutonEnvoi = document.getElementById('BoutonEnvoi');
	BoutonEnvoi.onclick = function(){
		var Username = document.getElementById('wpUsername').value;
		var phoneValue = document.getElementById('wpPhone').value;
		var DescriptionValue = document.getElementById('wpBio').value;
		var Email = document.getElementById('wpEmail').value;
		var Wikiname = document.getElementById('wpRealName').value;
		var ToSBox = document.getElementById('wpToS');
		var regexPhone=/^([+]{0,1}[0-9]{1,}[.\- ]*)*[0-9]{2,}$/;
		var regexEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+\.(?:[a-zA-Z0-9-]+)+$/;
		var regexWikiname = /^[a-zA-Z0-9]{5,40}$/ ;
		var regexUsername = /[a-zA-Z0-9\s]{2,19}\s?$/ ;
		var regexForbiddenUsername = /[;{}\[\]\\/'<>()|$?%:#*~`+_§@€?.,]/;
		var regexForbidden = /[;{}\[\]\\/'<>()|$?%:#*~`+_§]/;
		if (regexForbiddenUsername.test(Username)||Username.length>40||Username.length<3){
				document.getElementById('wpUsername').style.borderColor = "red";
				document.getElementById('ErrorUsername').style.display = "inline";
			}else{
				document.getElementById('wpUsername').style.borderColor = "";
				usernameOk = true;
				document.getElementById('ErrorUsername').style.display = "none";
			}
		if(!regexWikiname.test(Wikiname)||regexForbidden.test(Wikiname)||(Wikiname.length)>20){
				document.getElementById('ErrorRealName').style.display = "inline";
				document.getElementById('wpRealName').style.borderColor = "red";
			}else{
				WikinameOk = true;
				document.getElementById('ErrorRealName').style.display = "none";
				document.getElementById('wpRealName').style.borderColor = "";
			}
		if(phoneValue != ''){	
			if(regexPhone.test(phoneValue) && phoneValue.length>=4){
					document.getElementById('wpPhone').style.borderColor = "";
					phoneOk = true;
					document.getElementById('ErrorPhone').style.display = "none";
				}else{
					document.getElementById('wpPhone').style.borderColor = "red";
					document.getElementById('ErrorPhone').style.display = "inline";
				}
		}else{
			phoneOk = true;
		}
		if(regexForbidden.test(DescriptionValue)||(DescriptionValue.length)<20||(DescriptionValue.length)>1000){
				document.getElementById('wpBio').style.borderColor = "red";
				descOk = false;
				document.getElementById('ErrorBio').style.display = "inline";
			}else{
				document.getElementById('wpBio').style.borderColor = "";
				descOk = true;
				document.getElementById('ErrorBio').style.display = "none";
			}
		if(!regexEmail.test(Email)){
				document.getElementById('wpEmail').style.borderColor = "red";
				document.getElementById('ErrorEmail').style.display = "inline";
			}else{
				emailOk = true;
				document.getElementById('wpEmail').style.borderColor = "";
				document.getElementById('ErrorEmail').style.display = "none";
			}
		if(!ToSBox.checked){
			document.getElementById('ErrorToS').style.display = "inline";
		}else{
				ToSOk = true;
				document.getElementById('ErrorToS').style.display = "none";
		}
		if(usernameOk&&emailOk&&WikinameOk&&phoneOk&&descOk&&ToSOk)
		{
			return true;
		}else{
			return false;
		}
	}
}



//var inputs = document.getElementsByTagName(‘input’);
/* Validation du formulaire de dde de Wiki 
var Usernamefield = document.getElementById('wpUsername') ;
var regexUsername = /^[a-zA-Z][a-zA-Z0-9\s]{2,19}\s?$/ ;

if ( Usernamefield) {
  Usernamefield.onblur = function(){
    var Username = document.getElementById('wpUsername').value;
    
    //console.log(Username);
    if ( regexUsername.test(Username) === false )
    {
      Usernamefield.className = "is-invalid";
      document.getElementById('wpUsername').style.borderColor = "red";
      document.getElementById('wpRealName').disabled=true;
      document.getElementById('wpEmail').disabled=true;
      document.getElementById('wpBio').disabled=true;
      document.getElementById('wpNotes').disabled=true;
      document.getElementById('wpToS').disabled=true;
      document.getElementById('ErrorUsername').style.visibility = "visible";
      //alert ('Pour le nom d\'utilisateur, indiquez uniquement entre 3 et 20 chiffres ou lettres en commençant par une lettre !') ;
      document.getElementById('BoutonEnvoi').disabled = true;
      
      
    }
    else{
      document.getElementById('wpUsername').style.borderColor = "";
      document.getElementById('wpRealName').disabled=false;
      document.getElementById('wpEmail').disabled=false;
      document.getElementById('wpBio').disabled=false;
      document.getElementById('wpNotes').disabled=false;
      document.getElementById('wpToS').disabled=false;
      document.getElementById('ErrorUsername').style.visibility = "hidden";
      document.getElementById('BoutonEnvoi').disabled = false;
    }
    
  };
}

var Wikinamefield = document.getElementById('wpRealName') ;
var regexWikiname = /^[a-zA-Z][a-zA-Z0-9]{2,19}\s?$/ ;
if ( Wikinamefield) {
  Wikinamefield.onblur = function(){
    var Wikiname = document.getElementById('wpRealName').value ;
    //console.log(Username);
    if ( regexWikiname.test(Wikiname) === false )
    {
      Wikinamefield.className = "is-invalid";
      document.getElementById('wpRealName').style.borderColor = "red";
      document.getElementById('wpBio').disabled=true;
      document.getElementById('wpNotes').disabled=true;
      document.getElementById('wpToS').disabled=true;
      //alert ('Pour le nom du wiki, indiquez uniquement entre 3 et 20 chiffres ou des lettres sans accent ni espace en commençant par une lettre !') ;
      document.getElementById('ErrorRealName').style.visibility = "visible";
      document.getElementById('BoutonEnvoi').disabled = true;
    }
    else{
      document.getElementById('wpRealName').style.borderColor = "";
      document.getElementById('wpBio').disabled=false;
      document.getElementById('wpNotes').disabled=false;
      document.getElementById('wpToS').disabled=false;
      //document.getElementById('wpRealName').after("");
      document.getElementById('ErrorRealName').style.visibility = "hidden";
      document.getElementById('BoutonEnvoi').disabled = false;
    }
  };
}
var Emailfield = document.getElementById('wpEmail') ;
var regexEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
//var regexEmail = /^[a-zA-Z][a-zA-Z0-9]{2,19}\s?$/ ;
if(Emailfield){
  Emailfield.onblur = function(){
    var Email = document.getElementById('wpEmail').value ;
    if ( regexEmail.test(Email) === false )
    {
      Emailfield.className = "is-invalid";
      document.getElementById('wpEmail').style.borderColor = "red";
      document.getElementById('wpRealName').disabled=true;
      document.getElementById('wpBio').disabled=true;
      document.getElementById('wpNotes').disabled=true;
      document.getElementById('wpToS').disabled=true;
      document.getElementById('ErrorEmail').style.visibility = "visible";
      document.getElementById('BoutonEnvoi').disabled = true;
    }
    else{
      document.getElementById('wpEmail').style.borderColor = "";
      document.getElementById('wpRealName').disabled=false;
      document.getElementById('wpBio').disabled=false;
      document.getElementById('wpNotes').disabled=false;
      document.getElementById('wpToS').disabled=false;
      document.getElementById('ErrorEmail').style.visibility = "hidden";
      document.getElementById('BoutonEnvoi').disabled = false;
    }
  };
}
var DescriptionField = document.getElementById('wpBio') ;
var regexBio = /^[a-zA-Z][a-zA-Z0-9]{2,19}\s?$/;
//var regexEmail = /^[a-zA-Z][a-zA-Z0-9]{2,19}\s?$/ ;
if(DescriptionField){
  DescriptionField.onblur = function(){
    var DescriptionValue = document.getElementById('wpBio').value;
    
    var Description = DescriptionValue ? DescriptionValue.match(/\S+/g).length : 0; 
    if (Description < 5)
    {
      DescriptionField.className = "is-invalid";
      document.getElementById('wpBio').style.border = "red";
      //document.getElementById('wpNotes').disabled=true;
      //document.getElementById('wpToS').disabled=true;
      document.getElementById('ErrorBio').style.visibility = "visible";
      document.getElementById('BoutonEnvoi').disabled = true;
    }
    else{
      document.getElementById('wpBio').style.border = "";
      //document.getElementById('wpNotes').disabled=false;
      //document.getElementById('wpToS').disabled=false;
      document.getElementById('ErrorBio').style.visibility = "hidden";
      document.getElementById('BoutonEnvoi').disabled = false;
    }
  };
}
*/

/* AJOUT MATHIS */

//GRID SWITCHES

const yOffset = -90;
function scroll(id, yOffset) {
  window.scrollTo({top: id.getBoundingClientRect().top + window.pageYOffset + yOffset, behavior: 'smooth'});
}


//ACCUEIL

const ext = document.getElementById("btn-ext");
if(ext){
  const ext = document.getElementById("btn-ext");
  const fct = document.getElementById("btn-fct");
  const gridFct = document.getElementsByClassName("fct-grid-fct")[0];
  const gridExt = document.getElementsByClassName("fct-grid-ext")[0];
  gridExt.style.display = "none";

  ext.onclick = function() {
    gridFct.style.display = "none";
    gridExt.style.display = "grid";
    scroll(ext, yOffset);
    fct.classList.remove("fct-active");
    ext.classList.add("fct-active");
  };

  fct.onclick = function() {
    gridExt.style.display = "none";
    gridFct.style.display = "grid";
    scroll(fct, yOffset);
    ext.classList.remove("fct-active");
    fct.classList.add("fct-active");
  };
};


//SERVICES

const wiki = document.getElementById("btn-autour");
if(wiki){
  const wiki = document.getElementById("btn-autour");
  const serv = document.getElementById("btn-serv");
  const publics = document.getElementById("btn-publics");
  const gridWiki  = document.getElementsByClassName("prest-grid-autour")[0];
  const gridServ = document.getElementsByClassName("prest-grid-serv")[0];
  const gridPublics = document.getElementsByClassName("prest-grid-publics")[0];

  wiki.onclick = function() {
    gridServ.style.display = "none";
    gridPublics.style.display = "none";
    gridWiki.style.display = "grid";
    scroll(wiki, yOffset);
    serv.classList.remove("fct-active");
    publics.classList.remove("fct-active");
    wiki.classList.add("fct-active");
  };

  serv.onclick = function() {
    gridWiki.style.display = "none";
    gridPublics.style.display = "none";
    gridServ.style.display = "grid";
    scroll(serv, yOffset);
    wiki.classList.remove("fct-active");
    publics.classList.remove("fct-active");
    serv.classList.add("fct-active");
  };

  publics.onclick = function() {
    gridWiki.style.display = "none";
    gridServ.style.display = "none";
    gridPublics.style.display = "grid";
    scroll(publics, yOffset);
    wiki.classList.remove("fct-active");
    serv.classList.remove("fct-active");
    publics.classList.add("fct-active");
  };
};


//Jquery problem, id/class not DOM element
/*
var ext = $("#btn-ext")[0];
var fct = $("#btn-fct")[0];
var gridFct = $(".fct-grid-fct")[0];
var gridExt = $(".fct-grid-ext")[0];

ext.click(function() {
  gridFct.css("display", "none");
  gridExt.css("display", "grid");
  scroll(ext, yOffset);
  fct.removeClass("fct-active");
  ext.addClass("fct-active");
});

fct.click(function() {
  gridExt.css("display", "none");
  gridFct.css("display", "grid");
  scroll(fct, yOffset);
  ext.removeClass("fct-active");
  fct.addClass("fct-active");
});
*/