Clean code
This commit is contained in:
parent
c45ef8ccf1
commit
df041b2214
120
core/core.js.php
120
core/core.js.php
@ -36,7 +36,7 @@ core.alert = function(text) {
|
||||
}(jQuery));
|
||||
// Validation de la lightbox avec le bouton entrée
|
||||
$(document).on("keyup", function(event) {
|
||||
if(event.keyCode === 13) {
|
||||
if (event.keyCode === 13) {
|
||||
lightbox.close();
|
||||
}
|
||||
});
|
||||
@ -75,7 +75,7 @@ core.confirm = function(text, yesCallback, noCallback) {
|
||||
.on("click", function() {
|
||||
lightbox.options('button', true);
|
||||
lightbox.close();
|
||||
if(typeof noCallback !== "undefined") {
|
||||
if (typeof noCallback !== "undefined") {
|
||||
noCallback();
|
||||
}
|
||||
}),
|
||||
@ -85,7 +85,7 @@ core.confirm = function(text, yesCallback, noCallback) {
|
||||
.on("click", function() {
|
||||
lightbox.options('button', true);
|
||||
lightbox.close();
|
||||
if(typeof yesCallback !== "undefined") {
|
||||
if (typeof yesCallback !== "undefined") {
|
||||
yesCallback();
|
||||
}
|
||||
})
|
||||
@ -95,18 +95,18 @@ core.confirm = function(text, yesCallback, noCallback) {
|
||||
// Callback lors d'un clic sur le fond et sur la croix de fermeture
|
||||
lightbox.options('button', false);
|
||||
$(document).on('lity:close', function(event, instance) {
|
||||
if(
|
||||
instance.options('button') === false
|
||||
&& typeof noCallback !== "undefined"
|
||||
if (
|
||||
instance.options('button') === false &&
|
||||
typeof noCallback !== "undefined"
|
||||
) {
|
||||
noCallback();
|
||||
}
|
||||
});
|
||||
// Validation de la lightbox avec le bouton entrée
|
||||
$(document).on("keyup", function(event) {
|
||||
if(event.keyCode === 13) {
|
||||
if (event.keyCode === 13) {
|
||||
lightbox.close();
|
||||
if(typeof yesCallback !== "undefined") {
|
||||
if (typeof yesCallback !== "undefined") {
|
||||
yesCallback();
|
||||
}
|
||||
}
|
||||
@ -128,7 +128,7 @@ core.end = function() {
|
||||
var inputsDOM = formDOM.find("input:not([data-no-dirty]), select:not([data-no-dirty]), textarea:not(.editorWysiwyg):not([data-no-dirty])");
|
||||
var inputSerialize = inputsDOM.serialize();
|
||||
$(window).on("beforeunload", function() {
|
||||
if(inputsDOM.serialize() !== inputSerialize) {
|
||||
if (inputsDOM.serialize() !== inputSerialize) {
|
||||
message = "<?php echo helper::translate('Les modifications que vous avez apportées ne seront peut-être pas enregistrées.');?>";
|
||||
return message;
|
||||
}
|
||||
@ -166,16 +166,15 @@ core.start = function() {
|
||||
*/
|
||||
var backToTopDOM = $("#backToTop");
|
||||
backToTopDOM.on("click", function() {
|
||||
$("body, html").animate({scrollTop: 0}, "400");
|
||||
$("body, html").animate({ scrollTop: 0 }, "400");
|
||||
});
|
||||
/**
|
||||
* Affiche / Cache le bouton pour remonter en haut
|
||||
*/
|
||||
$(window).on("scroll", function() {
|
||||
if($(this).scrollTop() > 200) {
|
||||
if ($(this).scrollTop() > 200) {
|
||||
backToTopDOM.fadeIn();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
backToTopDOM.fadeOut();
|
||||
}
|
||||
});
|
||||
@ -210,7 +209,7 @@ core.start = function() {
|
||||
/**
|
||||
* Traitement du formulaire cookies
|
||||
*/
|
||||
$("#cookieForm").submit(function(event){
|
||||
$("#cookieForm").submit(function(event) {
|
||||
|
||||
// Variables des cookies
|
||||
var getUrl = window.location;
|
||||
@ -247,27 +246,27 @@ core.start = function() {
|
||||
menuDOM.slideToggle();
|
||||
});
|
||||
$(window).on("resize", function() {
|
||||
if($(window).width() > 768) {
|
||||
if ($(window).width() > 768) {
|
||||
menuDOM.css("display", "");
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Sélection d'une langue du site
|
||||
*/
|
||||
|
||||
$("#barSelectLanguage").on("change", function() {
|
||||
var lang = $(this).val();
|
||||
console.log (lang);
|
||||
if(lang) {
|
||||
$(location).attr("href", lang);
|
||||
var langUrl = $(this).val();
|
||||
var langCookie = getCookie('ZWII_CONTENT');
|
||||
if (langUrl !== langCookie) {
|
||||
$(location).attr("href", langUrl);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
/**
|
||||
* Choix de page dans la barre de membre
|
||||
*/
|
||||
$("#barSelectPage").on("change", function() {
|
||||
var pageUrl = $(this).val();
|
||||
if(pageUrl) {
|
||||
if (pageUrl) {
|
||||
$(location).attr("href", pageUrl);
|
||||
}
|
||||
});
|
||||
@ -279,11 +278,10 @@ core.start = function() {
|
||||
$(".inputFileHidden").on("change", function() {
|
||||
var inputFileHiddenDOM = $(this);
|
||||
var fileName = inputFileHiddenDOM.val();
|
||||
if(fileName === "") {
|
||||
if (fileName === "") {
|
||||
fileName = "Choisissez un fichier";
|
||||
$(inputFileHiddenDOM).addClass("disabled");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$(inputFileHiddenDOM).removeClass("disabled");
|
||||
}
|
||||
inputFileHiddenDOM.parent().find(".inputFileLabel").text(fileName);
|
||||
@ -328,10 +326,9 @@ core.start = function() {
|
||||
$("[type=email]").on("change", function() {
|
||||
var _this = $(this);
|
||||
var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
|
||||
if(pattern.test(_this.val())) {
|
||||
if (pattern.test(_this.val())) {
|
||||
core.noticeRemove(_this.attr("id"));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message = "<?php echo helper::translate('Format incorrect');?>";
|
||||
core.noticeAdd(_this.attr("id"), message);
|
||||
}
|
||||
@ -354,7 +351,7 @@ core.start = function() {
|
||||
elementDOM.each(function() {
|
||||
var _this = $(this);
|
||||
var width = _this.parent().first().width();
|
||||
if (width > _this.data("maxwidth")){ width = _this.data("maxwidth");}
|
||||
if (width > _this.data("maxwidth")) { width = _this.data("maxwidth"); }
|
||||
_this
|
||||
.width(width)
|
||||
.height(width * _this.data("ratio"));
|
||||
@ -366,18 +363,20 @@ core.start = function() {
|
||||
*/
|
||||
$(window).on("resize", function() {
|
||||
var responsive = "<?php echo $this->getdata(['theme','header','imageContainer']);?>";
|
||||
if (responsive === "cover" || responsive === "contain" ) {
|
||||
if (responsive === "cover" || responsive === "contain") {
|
||||
var widthpx = "<?php echo $this->getdata(['theme','site','width']);?>";
|
||||
var width = widthpx.substr(0,widthpx.length-2);
|
||||
var width = widthpx.substr(0, widthpx.length - 2);
|
||||
var heightpx = "<?php echo $this->getdata(['theme','header','height']);?>";
|
||||
var height = heightpx.substr(0,heightpx.length-2);
|
||||
var height = heightpx.substr(0, heightpx.length - 2);
|
||||
var ratio = width / height;
|
||||
if ( ($(window).width() / ratio) <= height) {
|
||||
$("header").height( $(window).width() / ratio );
|
||||
if (($(window).width() / ratio) <= height) {
|
||||
$("header").height($(window).width() / ratio);
|
||||
}
|
||||
}
|
||||
}).trigger("resize");
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -385,7 +384,7 @@ core.start();
|
||||
|
||||
/**
|
||||
* Confirmation de suppression
|
||||
*/
|
||||
*/
|
||||
$("#pageDelete").on("click", function() {
|
||||
var _this = $(this);
|
||||
message = "<?php echo helper::translate('Confirmez-vous la suppression de cette page ?');?>";
|
||||
@ -414,25 +413,51 @@ core.relativeLuminanceW3C = function(rgba) {
|
||||
return .2126 * R + .7152 * G + .0722 * B;
|
||||
};
|
||||
|
||||
// Fonctions
|
||||
function setCookie(name, value, days) {
|
||||
var expires = "";
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/; samesite=lax";
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Define function to capitalize the first letter of a string
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
$(document).ready(function() {
|
||||
/**
|
||||
* Affiche le sous-menu quand il est sticky
|
||||
*/
|
||||
$("nav").mouseenter(function(){
|
||||
$("#navfixedlogout .navSub").css({ 'pointer-events' : 'auto' });
|
||||
$("#navfixedconnected .navSub").css({ 'pointer-events' : 'auto' });
|
||||
$("nav").mouseenter(function() {
|
||||
$("#navfixedlogout .navSub").css({ 'pointer-events': 'auto' });
|
||||
$("#navfixedconnected .navSub").css({ 'pointer-events': 'auto' });
|
||||
});
|
||||
$("nav").mouseleave(function(){
|
||||
$("#navfixedlogout .navSub").css({ 'pointer-events' : 'none' });
|
||||
$("#navfixedconnected .navSub").css({ 'pointer-events' : 'none' });
|
||||
$("nav").mouseleave(function() {
|
||||
$("#navfixedlogout .navSub").css({ 'pointer-events': 'none' });
|
||||
$("#navfixedconnected .navSub").css({ 'pointer-events': 'none' });
|
||||
});
|
||||
|
||||
/**
|
||||
* Chargement paresseux des images et des iframes
|
||||
*/
|
||||
$("img,picture,iframe").attr("loading","lazy");
|
||||
$("img,picture,iframe").attr("loading", "lazy");
|
||||
|
||||
/**
|
||||
* Effet accordéon
|
||||
@ -452,6 +477,7 @@ $(document).ready(function(){
|
||||
item.addClass('active')
|
||||
.find('.accordion-content').slideDown(speed);
|
||||
}
|
||||
|
||||
function close(item, speed) {
|
||||
accordion.find('.accordion-item').removeClass('active')
|
||||
.find('.accordion-content').slideUp(speed);
|
||||
@ -478,10 +504,9 @@ $(document).ready(function(){
|
||||
*/
|
||||
$("#toggle").click(function() {
|
||||
var changeIcon = $('#toggle').children("span");
|
||||
if ( $(changeIcon).hasClass('zwiico-menu') ) {
|
||||
if ($(changeIcon).hasClass('zwiico-menu')) {
|
||||
$(changeIcon).removeClass('zwiico-menu').addClass('zwiico-cancel');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$(changeIcon).addClass('zwiico-menu');
|
||||
};
|
||||
});
|
||||
@ -489,6 +514,7 @@ $(document).ready(function(){
|
||||
/**
|
||||
* Remove ID Facebook from URL
|
||||
*/
|
||||
if(/^\?fbclid=/.test(location.search))
|
||||
if (/^\?fbclid=/.test(location.search))
|
||||
location.replace(location.href.replace(/\?fbclid.+/, ""));
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user