|
| 1 | +define([ |
| 2 | + 'jquery', |
| 3 | + 'underscore', |
| 4 | + 'Magento_PageBuilder/js/widget/show-on-hover', |
| 5 | + 'Magento_PageBuilder/js/widget/video-background', |
| 6 | + 'CustomGento_Cookiebot/js/video-blocker-widget' |
| 7 | +], function ($, _, showOnHover, videoBackground, createVideoBlocker) { |
| 8 | + 'use strict'; |
| 9 | + |
| 10 | + return function (originalWidget) { |
| 11 | + return function (config, element) { |
| 12 | + let videoElement = element[0].querySelector('[data-background-type=video]'); |
| 13 | + let PreviousStatus = ''; |
| 14 | + if (!videoElement) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + let viewportElement = document.createElement('div'); |
| 19 | + let $slider = videoElement.getAttribute('data-video-src') |
| 20 | + const blockVideoConsentConfig = window.cookiebotConfig && window.cookiebotConfig.blockVideosUntilConsent; |
| 21 | + |
| 22 | + addEventListener('CookiebotOnLoad', () => { |
| 23 | + sliderVideoBlocker(); |
| 24 | + } |
| 25 | + ) |
| 26 | + |
| 27 | + function sliderVideoBlocker(){ |
| 28 | + if (PreviousStatus === 'blocked' && !Cookiebot?.consent?.marketing) { |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + if (!Cookiebot?.consent?.marketing && blockVideoConsentConfig) { |
| 33 | + videoElement.setAttribute('data-cookieblock-src', videoElement.getAttribute('data-video-src')); |
| 34 | + videoElement.removeAttribute('data-video-src'); |
| 35 | + createVideoBlocker(videoElement); |
| 36 | + videoElement.style.display = 'none'; |
| 37 | + PreviousStatus = 'blocked'; |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + $slider = $(element).closest('[data-content-type=slider]'); |
| 42 | + viewportElement.classList.add('jarallax-viewport-element'); |
| 43 | + |
| 44 | + if (!videoElement) { |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + if (!videoElement.getAttribute('data-video-src')) { |
| 49 | + videoElement.setAttribute('data-video-src', videoElement.getAttribute('data-cookieblock-src')); |
| 50 | + videoElement.style.display = 'block'; |
| 51 | + videoElement.removeAttribute('data-cookieblock-src'); |
| 52 | + videoElement.closest('.custom-slide-uwt').querySelector('.cookieconsent-optout-marketing').remove(); |
| 53 | + } |
| 54 | + videoElement.setAttribute('data-element-in-viewport', '.jarallax-viewport-element'); |
| 55 | + videoElement.appendChild(viewportElement); |
| 56 | + videoBackground(config, videoElement); |
| 57 | + videoElement.style.display = 'block'; |
| 58 | + PreviousStatus = 'unblocked'; |
| 59 | + |
| 60 | + if ($slider.data('afterChangeIsSet')) { |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + $slider.on('afterChange init', function () { |
| 65 | + var videoSlides = $slider[0].querySelectorAll('.jarallax'); |
| 66 | + |
| 67 | + _.each(videoSlides, function (videoSlide) { |
| 68 | + videoSlide.jarallax && videoSlide.jarallax.onScroll(); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + $slider.data('afterChangeIsSet', true); |
| 73 | + |
| 74 | + } |
| 75 | + |
| 76 | + sliderVideoBlocker(); |
| 77 | + }; |
| 78 | + }; |
| 79 | +}); |
0 commit comments