11define ( [
2- 'jquery'
2+ 'jquery' ,
33] , function ( $ ) {
44 'use strict' ;
55
66 return function ( widget ) {
77 $ . widget ( 'mage.AddFotoramaVideoEvents' , widget , {
8-
98 _clickHandler : function ( e ) {
109 const blockVideoConsentConfig = window . cookiebotConfig && window . cookiebotConfig . blockVideosUntilConsent ;
1110
11+ if ( Cookiebot ?. consent ?. marketing ) {
12+ this . _super ( e ) ;
13+ return ;
14+ }
15+
1216 if ( ! Cookiebot ?. consent ?. marketing && blockVideoConsentConfig ) {
1317 const videoElement = event . target . querySelector ( '.product-video' ) ;
1418
15- if ( Cookiebot ?. consent ?. marketing ) {
16- return ;
17- }
18-
1919 const linkElement = document . createElement ( "a" ) ;
2020 const divElement = document . createElement ( "div" ) ;
2121 const paragraphElement = document . createElement ( "p" ) ;
22- const iframeHeight = videoElement . getBoundingClientRect ( ) . height || 300 ;
23- const iframeWidth = videoElement . getBoundingClientRect ( ) . width || 400 ;
22+ const iframeHeight = videoElement ? .getBoundingClientRect ( ) . height || 300 ;
23+ const iframeWidth = videoElement ? .getBoundingClientRect ( ) . width || 400 ;
2424
2525
2626 divElement . innerHTML = `
@@ -44,12 +44,33 @@ define([
4444 divElement . append ( paragraphElement ) ;
4545 paragraphElement . style . zIndex = "1000" ;
4646 paragraphElement . style . position = "relative" ;
47- videoElement . parentNode . insertBefore ( divElement , videoElement ) ;
47+ videoElement ? .parentNode . insertBefore ( divElement , videoElement ) ;
4848
4949 return ;
5050 }
5151 this . _super ( e ) ;
5252 } ,
53+
54+ _initialize : function ( ) {
55+ this . _super ( ) ;
56+ addEventListener ( "CookiebotOnAccept" , ( ) => {
57+ const videoIframes = document . querySelectorAll ( ".pagebuilder-video-container iframe" ) ;
58+
59+ videoIframes . forEach ( ( iframe ) => {
60+ if ( Cookiebot ?. consent ?. marketing ) {
61+ const cookiebotOutput = document ?. querySelector ( '.cookieconsent-optout-marketing' ) ;
62+ const videoElement = cookiebotOutput . closest ( '.video-unplayed[aria-hidden="false"]' ) ;
63+
64+ const event = new PointerEvent ( 'click' , {
65+ bubbles : true ,
66+ cancelable : true ,
67+ view : window
68+ } ) ;
69+ videoElement ?. dispatchEvent ( event ) ;
70+ }
71+ } ) ;
72+ } ) ;
73+ }
5374 } ) ;
5475
5576 return $ . mage . AddFotoramaVideoEvents ;
0 commit comments