dc-accelerators-content-rendering-service
Version:
Amplience DC Frontend modules, using HTML Service
1 lines • 3.57 kB
JavaScript
;!function(e){function t(e){this.initBackgroundColor(e)}function i(i){var n=[].slice.call(i.querySelectorAll(".amp-dc-promo-block")),a=2,o=window.innerWidth;if(n.length<2)n[0].classList.add("dc-fade-in");else{n.forEach(function(e){n[a-1].classList.remove("dc-fade-in")}),n[a-1].classList.add("dc-fade-in");setInterval(function(){o=window.innerWidth;var e=[].slice.call(i.querySelectorAll(".dc-fade-in"));if(!(768<o)){var t=(a===n.length?a=1:a+=1,a-1);0<e.length&&e.forEach(function(e){e.classList.remove("dc-fade-in")}),n[t].classList.add("dc-fade-in")}},5e3)}}function n(e){var t={infinite:"true"===e.getAttribute("data-infinite"),navigation:"true"===e.getAttribute("data-navigation"),autoplay:"true"===e.getAttribute("data-autoplay")},i=(window.lory?window.lory:"function"==typeof require?require("lory.js").lory:null)(e,t);t.infinite||this.disableNavButtons(e,i),t.navigation&&this.navigationDots(e,i,t),this.enableSwipeGesturesOnVideo(e)}function a(e,t){[].slice.call(document.querySelectorAll(e)).forEach(function(e){e.component||(e.component=new t(e))})}function o(){a(".amp-dc-banner",t),a(".amp-dc-promo-banner",i),a(".amp-dc-slider",n)}t.prototype.initBackgroundColor=function(e){var t=e.querySelector(".amp-dc-banner-info"),i=t.getAttribute("data-color")||"fff",n=Number(t.getAttribute("data-opacity")||"1");if(0===i.indexOf("#")&&(i=i.slice(1)),3===i.length){var a=i.split("");i=a[0]+a[0],i+=a[1]+a[1],i+=a[2]+a[2]}var o=parseInt(i.slice(0,2),16),r=parseInt(i.slice(2,4),16),s=parseInt(i.slice(4,6),16);t.style.backgroundColor="rgba("+o+", "+r+", "+s+", "+n+")"},n.prototype.disableNavButtons=function(e,i){var n=Array.prototype.slice.call(e.querySelectorAll(".js_dc_slide"),0),a=e.querySelector(".js_prev"),o=e.querySelector(".js_next"),r="ctrl-disabled",t=function(e){var t=i.returnIndex();0===t?(a.classList.add(r),o.classList.remove(r)):t===n.length-1?(a.classList.remove(r),o.classList.add(r)):(a.classList.remove(r),o.classList.remove(r))};0===i.returnIndex()&&a.classList.add(r),e.addEventListener("after.lory.slide",t),e.addEventListener("on.lory.resize",t)},n.prototype.navigationDots=function(e,i,n){var a=Array.prototype.slice.call(e.querySelectorAll(".js_dc_slider_dot"),0);a.forEach(function(e,t){0===t&&e.classList.add("active"),e.addEventListener("click",function(e){i.slideTo(t)})}),e.addEventListener("after.lory.slide",function(e){a.forEach(function(e,t){e.classList.remove("active")}),console.log(n);var t=n.infinite?e.detail.currentSlide-1:e.detail.currentSlide;a[t].classList.add("active")}),e.addEventListener("on.lory.resize",function(){a.forEach(function(e,t){0===t?e.classList.add("active"):e.classList.remove("active")})})},n.prototype.enableSwipeGesturesOnVideo=function(e){if(navigator.userAgent.match(/Android/i)){var t=e.querySelectorAll(".amp-dc-slider .amp-dc-video");(t=Array.prototype.slice.call(t,0)).forEach(function(e,t){var i=document.createElement("div");i.style.width=e.clientWidth+"px",i.style.height=e.clientHeight-30+"px",i.style.marginBottom=30-e.clientHeight+"px",i.className="inactive-video",e.parentNode.parentNode.insertBefore(i,e.parentNode),i.addEventListener("click",function(){i.classList.add("no-overlay"),e.play()}),e.addEventListener("pause",function(){i.classList.remove("no-overlay")}),window.addEventListener("resize",function(){i.style.width=e.clientWidth+"px",i.style.height=e.clientHeight-30+"px",i.style.marginBottom=30-e.clientHeight+"px"})})}},e.Utils=e.Utils||{},e.Utils.attachComponents=o,document.addEventListener("DOMContentLoaded",function(){o()})}(window.AmpCa=window.AmpCa||{});