Files
Last update 2 months 4 days
by
Arnaud-Apu-Fanovard
ProductImagesModal.js.téléchargementfunction openProductImagesModal(e,t,n){PreviousElement=document.activeElement||document.body,$(".productImagesModal").modal("show");var s=$(".modalLoadingImg").html();$(".productImagesModalContent").html(s),$(".modalLoadingImg").show(),imageModalOpenedEvent(t),$.ajax({type:"GET",url:e,dataType:"html",cache:!0}).done(function(e){$(".productImagesModalContent").html(e),$(".modalLoadingImg").hide(),setInitialStatus(t),setThumbnails(),setBootstrapGrid(),stopMagic360(),stopMagicZoom(),startMagic360(),startMagicZoom(),setPdpLink(n),setGaEventViewProductButton(t.getAttribute("data-gavalue"))}).fail(function(){$(".productImagesModalContent").html(""),$(".modalLoadingImg").hide()})}function setPdpLink(e){e!=null?document.getElementById("linkToPdp").setAttribute("href",e):($(".linktopdp").css({display:"none"}),$(".productImagesModalLabel").css({"border-bottom":"none"}));var o='button, [href], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])',i=$(".productImagesModal"),s=i.find(o),t=s[0],n=s[s.length-1];$("#linkToPdp").on("keydown",function(e){var s=9;e.keyCode===s&&(e.shiftKey?document.activeElement===t&&(n.focus(),e.preventDefault()):document.activeElement===n&&(t.focus(),e.preventDefault()))}),$("#btnImagesModalCloseX").on("keydown",function(e){var s=9;e.keyCode===s&&(e.shiftKey?document.activeElement===t&&(n.focus(),e.preventDefault()):document.activeElement===n&&(t.focus(),e.preventDefault()))})}function setGaEventViewProductButton(e){if(e!=null&&$("#linkToPdp").length>0){var t=e.replace("Refine Product Click","Product Gallery Modal Refine Product Click");document.getElementById("linkToPdp").setAttribute("onclick",t)}}function setInitialStatus(e){var t=$(".productImagesModalContent .imageSlidesWrapper"),n=t.find(".carousel-inner .item").length;n===1&&t.find(".carousel-control").remove(),e.classList.contains("defaultSpinThumbnail")?($(".productImagesModalContent .spinThumbnail").addClass("active"),t.find(".carousel-inner .item[data-index=0]").addClass("active")):($(".productImagesModalContent .navThumbnail:first").addClass("active"),t.find(".carousel-inner .item[data-index=1]").addClass("active"))}function setBootstrapGrid(){var t=$(".productImagesModalContent .imageSlidesWrapper"),e=$(".productImagesModalContent .thumbnailsWrapper"),n=e.find(".navThumbnail").length,s=$(".productImagesModalContent .spinContainer");n<5?(t.addClass("col-xs-12 col-sm-12 col-md-10 col-lg-10"),e.addClass("col-xs-12 col-sm-12 col-md-2 col-lg-2")):(t.addClass("col-xs-12 col-sm-12 col-md-9 col-lg-9"),e.addClass("col-xs-12 col-sm-12 col-md-3 col-lg-3")),s.length?(e.find(".spinContainer").addClass("col-sm-3 col-md-12 col-lg-12"),e.find(".navThumbnailsContainer").addClass("col-sm-9 col-md-12 col-lg-12")):e.find(".navThumbnailsContainer").addClass("col-sm-12 col-md-12 col-lg-12")}function setThumbnails(){var o,t=$(window).width(),s=$(".productImagesModalContent .navThumbnails"),e=$(".productImagesModalContent .navThumbnails .navThumbnail"),n=$(".productImagesModalContent .spinContainer");t<600?(n.addClass("col-xs-4"),e.addClass("col-xs-4")):(n.removeClass("col-xs-4"),e.removeClass("col-xs-4")),t>=600&&t<768?(n.addClass("col-xs-3"),e.addClass("col-xs-3")):(n.removeClass("col-xs-3"),e.removeClass("col-xs-3")),t>=768&&t<992?(n.addClass("col-sm-3"),e.addClass("col-sm-3")):(n.removeClass("col-sm-3"),e.removeClass("col-sm-3")),t>=992?(o=e.length,o>4&&s.css({display:"flex","flex-wrap":"wrap","flex-direction":"row"}),e.css("margin-right","13px")):(s.removeAttr("style"),e.css("margin-right","0"))}function setBadgeAndTextBreakpoint(){var e=$(window).width();e<771?$(".visibleOnDekstopResize").css({display:"none"}):$(".visibleOnDekstopResize").removeAttr("style")}function startMagic360(){var t,n,s,e=$("#spin360Viewer");e.addClass("Magic360"),updateHintTexts(),t=5,e.on("mousedown",function(e){n=e.pageX,s=e.pageY}),e.on("mouseup",function(e){var o=Math.abs(e.pageX-n),i=Math.abs(e.pageY-s);(o>t||i>t)&&ga("send","event","Product Gallery Modal Interaction","360 Drag","Drag")});function i(e){var t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.top<=(window.innerHeight||document.documentElement.clientHeight)}function o(){for(var n,t=document.querySelectorAll?document.querySelectorAll("img.lazy-image"):document.getElementsByClassName("lazy-image"),e=t.length-1;e>=0;e--)n=t[e].getAttribute("data-src"),n&&!t[e].getAttribute("src")&&i(t[e])&&(t[e].setAttribute("src",n),t[e].setAttribute("data-src",""))}window.addEventListener?window.addEventListener("scroll",o,!1):window.attachEvent("onscroll",o),Magic360.start()}function startMagicZoom(){var e=$(".productImagesModalContent").find('[id^="zoomViewer_"]');e.addClass("MagicZoom"),e.each(function(){var e=$(this).attr("id");MagicZoom.start(e),$(this).on("focus",function(){$(this).on("keydown",function(t){switch(t.keyCode){case 13:MagicZoom.expand(e),t.preventDefault();break;case 187:MagicZoom.zoomIn(e),t.preventDefault();break;case 189:MagicZoom.zoomOut(e),t.preventDefault();break}})})})}function stopMagic360(){Magic360.stop();var e=$("#spin360Viewer");$(".productImagesModalContent").off("keydown"),e.removeClass("Magic360")}function stopMagicZoom(){var e=$(".productImagesModalContent").find('[id^="zoomViewer_"]');e.each(function(){var e=$(this).attr("id");MagicZoom.stop(e)}),e.removeClass("MagicZoom")}function updateHintTexts(){var e=$(window).width(),t=$("input:hidden[name=spinHintText]").val(),n=$("input:hidden[name=mobileSpinHintText]").val();e<992?Magic360Lang={"mobile-hint-text":n}:Magic360Lang={"mobile-hint-text":t}}$(window).on("resize",function(){setThumbnails(),setBadgeAndTextBreakpoint()});function thumbnailNavigation(e){$(".spinContainer").find(".spinThumbnail").removeClass("active"),$(".spinContainer").find(".spinThumbnailLink[data-index='"+e.getAttribute("data-index")+"']").parent().addClass("active"),$(".navThumbnails").find(".navThumbnail").removeClass("active"),$(".navThumbnails").find(".thumbnailLink[data-index='"+e.getAttribute("data-index")+"']").parent().addClass("active"),$(".carousel-inner").find(".item").removeClass("active"),$(".carousel-inner").find(".item[data-index='"+e.getAttribute("data-index")+"']").addClass("active"),thumbnailClickedEvent(e)}function bindProductImagesModal(){$(".productImagesModal").on("shown.bs.modal",function(){$(".productImagesModalContent").trigger("focus")}),$(".productImagesModal").on("hidden.bs.modal",function(){$(".productImagesModalContent").html(""),$(".modalLoadingImg").hide(),PreviousElement&&PreviousElement.focus()}),$(".productImagesModal").on("click",function(e){e.target===e.currentTarget&&(ga("send","event","Product Gallery Modal Interaction","Close","Outside Modal"),PreviousElement&&PreviousElement.focus())}),$(".productImagesModal").on("slide.bs.carousel",function(e){var n=$(e.relatedTarget),t=parseInt(n.attr("data-index"));$(".spin").length&&($(".spin").find(".spinThumbnail").removeClass("active"),$(".spin").find(".spinThumbnailLink[data-index='"+t+"']").parent().addClass("active")),$(".navThumbnails").find(".navThumbnail").removeClass("active"),$(".navThumbnails").find(".thumbnailLink[data-index='"+t+"']").parent().addClass("active")})}function imageModalOpenedEvent(e){var t,n,o,s="";e.classList.contains("img-link")?s="Big Image":e.classList.contains("defaultSpinThumbnail")?s="360 Image":e.classList.contains("plusMoreImagesText")&&(s="Plus Images Link"),t="",n=0,$("a#imglink").length&&(t+="Big Image|",n+=1),$("a.defaultSpinThumbnail.thumbControls").length&&(t+="360 Image|",n+=1),$("a#plusMoreImagesText").length&&(t+="Plus Images Link|",o=$("a#plusMoreImagesText").text(),n+=parseInt(o.substr(o.indexOf("+"),o.indexOf("images")).trim())),t=t.substr(0,t.length-1),ga("send","event","Product Gallery Modal Open",s,t,n)}function thumbnailClickedEvent(e){var t,n="Static";e.classList.contains("spinThumbnailLink")&&(n="360"),t=parseInt(e.getAttribute("data-index")),$("a.spinThumbnailLink").length&&(t+=1),ga("send","event","Product Gallery Modal Thumbnail Click",n,t.toString(),t)}function onMagic360Ready(){var s=this,o='button, [href], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])',i=$(".productImagesModal"),e=i.find(o),t=e[0],n=e[e.length-1];$(".productImagesModalContent").on("keydown",function(e){switch(Magic360.pause("spin360Viewer"),e.keyCode){case 37:Magic360.spin("spin360Viewer",1),e.preventDefault();break;case 38:Magic360.jump("spin360Viewer",-1),e.preventDefault();break;case 39:Magic360.spin("spin360Viewer",-1),e.preventDefault();break;case 40:Magic360.jump("spin360Viewer",1),e.preventDefault();break;case 187:Magic360.magnifyOn("spin360Viewer"),e.preventDefault();break;case 189:Magic360.magnifyOff("spin360Viewer"),e.preventDefault();break;case 9:e.shiftKey?document.activeElement===t&&(n.focus(),e.preventDefault()):document.activeElement===n&&(t.focus(),e.preventDefault());break}}),$(".productImagesModalContent").on("focus",function(){$(s).trigger("keydown")})}$(document).ready(function(){bindProductImagesModal(),Magic360Options={onready:onMagic360Ready}})