/*** * SUMMARY * * 1 - Lazy loading * 3 - Banner tracking * 4 - Cookie consent * 5 - Wishlist * 6 - ATC links ***/ /*------------- * Lazy loading --------------*/ document.addEventListener("DOMContentLoaded", function() { var lazyloadImages; if ("IntersectionObserver" in window) { lazyloadImages = document.querySelectorAll(".lazy"); var imageObserver = new IntersectionObserver(function(entries, observer) { entries.forEach(function(entry) { if (entry.isIntersecting) { var image = entry.target; image.classList.remove("lazy"); imageObserver.unobserve(image); } }); }); lazyloadImages.forEach(function(image) { imageObserver.observe(image); }); } else { var lazyloadThrottleTimeout; lazyloadImages = document.querySelectorAll(".lazy"); function lazyload () { if(lazyloadThrottleTimeout) { clearTimeout(lazyloadThrottleTimeout); } lazyloadThrottleTimeout = setTimeout(function() { var scrollTop = window.pageYOffset; lazyloadImages.forEach(function(img) { if(img.offsetTop < (window.innerHeight + scrollTop)) { img.src = img.dataset.src; img.classList.remove('lazy'); } }); if(lazyloadImages.length == 0) { document.removeEventListener("scroll", lazyload); window.removeEventListener("resize", lazyload); window.removeEventListener("orientationChange", lazyload); } }, 20); } document.addEventListener("scroll", lazyload); window.addEventListener("resize", lazyload); window.addEventListener("orientationChange", lazyload); } }) /*----------------- * Banners tracking ------------------*/ var _adresseTracking = "ajax_banner.php" //l'adresse à interroger function trackBanner(bid,evt){ var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur _xmlHttp=getXMLHTTP(); if(_xmlHttp){ //appel à l'url distante _xmlHttp.open("GET",_adresseTracking+"?banner_id="+bid+"&event="+evt,true); _xmlHttp.onreadystatechange=function() { if(_xmlHttp.readyState==4&&_xmlHttp.responseXML) { } }; // envoi de la requete _xmlHttp.send(null) } } // retourne un objet xmlHttpRequest. // méthode compatible entre tous les navigateurs (IE/Firefox/Opera) function getXMLHTTP(){ var xhr=null; if(window.XMLHttpRequest) // Firefox et autres xhr = new XMLHttpRequest(); else if(window.ActiveXObject){ // Internet Explorer try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e1) { xhr = null; } } } else { // XMLHttpRequest non supporté par le navigateur alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); } return xhr; } /*--------------- * Cookie consent ----------------*/ function acceptCookies() { expires = new Date(1738290888000); document.cookie = "consentCookie=1; expires=" + expires + "; path=/;"; $('#alertCookie').slideToggle(300); dataLayer.push({'consentCookie': 1}); } function refuseCookies() { expires = new Date(1738290888000); document.cookie = "consentCookie=0; expires=" + expires + "; path=/;"; $('#alertCookie').slideToggle(300); } /*--------------- * Wishlist ----------------*/ $(document).ready(function() { $(".wishlist").each(function(index, element) { element.className = "wishlist out"; element.setAttribute("title", "+"); }); $.get( "ajax_wishlist.php", {action: "GET"}, function (data) { result = JSON.parse(data, (key, value) => { element = document.getElementById("wish-" + key.toString()); if (element) { if (value == 'true') { element.className = "wishlist in"; element.setAttribute("title", "-"); } } }); }); $(".wishlist").click(function(event) { $.get( "ajax_wishlist.php", {action: "GET", id: (event.target.id).substring(5)}, function (data) { result = JSON.parse(data, (key, value) => { console.log(key + ':' + value); element = document.getElementById("wish-" + key.toString()); if (element) { if (value == 'true') { $.get( "ajax_wishlist.php", {action: "DELETE", id: (event.target.id).substring(5)} ); element.className = "wishlist out"; element.setAttribute("title", "+"); } else { $.get( "ajax_wishlist.php", {action: "PUT", id: (event.target.id).substring(5)} ); element.className = "wishlist in"; element.setAttribute("title", "-"); } } }); }); }); }) /*--------- * ATC links ----------*/ document.addEventListener("DOMContentLoaded", function(event) { var classname = document.getElementsByClassName("atc"); for (var i = 0; i < classname.length; i++) { //click gauche classname[i].addEventListener('click', myFunction, false); //click droit classname[i].addEventListener('contextmenu', myRightFunction, false); //pointer classname[i].style.cssText = "cursor: pointer"; } }); //fonction du click gauche var myFunction = function(event) { var attribute = this.getAttribute("data-atc"); if(event.ctrlKey) { var newWindow = window.open(decodeURIComponent(window.atob(attribute)), '_blank'); newWindow.focus(); } else { document.location.href = decodeURIComponent(window.atob(attribute)); } }; //fonction du click droit var myRightFunction = function(event) { var attribute = this.getAttribute("data-atc"); if(event.ctrlKey) { var newWindow = window.open(decodeURIComponent(window.atob(attribute)), '_blank'); newWindow.focus(); } else { window.open(decodeURIComponent(window.atob(attribute)),'_blank'); } }