1+ define ( [
2+ 'jquery' ,
3+ 'CustomGento_Cookiebot/js/video-blocker-widget' ,
4+ 'CustomGento_Cookiebot/js/video-platform-validator'
5+ ] , function ( $ , createVideoBlocker , isSupportedVideoPlatform ) {
6+ 'use strict' ;
7+
8+ return function ( originalWidget ) {
9+ function getValidDimension ( value , fallback ) {
10+ if ( ! value || parseFloat ( value ) === 0 ) {
11+ return fallback ;
12+ }
13+ return value ;
14+ }
15+
16+ return function ( config , element ) {
17+ const videoElementContainer = $ ( element ) ;
18+ const videoElement = videoElementContainer [ 0 ] ;
19+ const videoElementStyles = window . getComputedStyle ( element ) ;
20+ const height = getValidDimension ( videoElementStyles . minHeight , '300px' ) ;
21+ const width = getValidDimension ( videoElementStyles . width , '400px' ) ;
22+
23+ if ( videoElementContainer . data ( 'background-type' ) !== 'video' ) {
24+ originalWidget ( config , element ) ;
25+ return ;
26+ }
27+
28+ const blockVideoConsentConfig = window . cookiebotConfig && window . cookiebotConfig . blockVideosUntilConsent ;
29+ const videoSrc = videoElement . getAttribute ( 'data-video-src' ) ;
30+ const cookieblockSrc = videoElement . getAttribute ( 'data-cookieblock-src' ) ;
31+ const src = videoSrc || cookieblockSrc ;
32+ let previousStatus = '' ;
33+ let blockerElement = null ;
34+
35+ if ( ! blockVideoConsentConfig || ! isSupportedVideoPlatform ( src ) ) {
36+ originalWidget ( config , element ) ;
37+ return ;
38+ }
39+
40+ addEventListener ( 'CookiebotOnLoad' , videoBackgroundBlocker ) ;
41+
42+ function videoBackgroundBlocker ( ) {
43+ if ( previousStatus === 'blocked' && ( ! window . Cookiebot ?. consent ?. marketing ) ) {
44+ return ;
45+ }
46+
47+ if ( ! window . Cookiebot ?. consent ?. marketing ) {
48+ if ( videoSrc ) {
49+ videoElement . setAttribute ( 'data-cookieblock-src' , videoSrc ) ;
50+ videoElement . removeAttribute ( 'data-video-src' ) ;
51+ }
52+ videoElement . style . display = 'none' ;
53+ blockerElement = createVideoBlocker ( videoElement ) ;
54+ const blockerElementContent = blockerElement . querySelector ( 'div' ) ;
55+ blockerElementContent . style . height = height ;
56+ blockerElementContent . style . width = width ;
57+ previousStatus = 'blocked' ;
58+ return ;
59+ }
60+
61+ if ( ! videoElement . getAttribute ( 'data-video-src' ) && cookieblockSrc ) {
62+ videoElement . setAttribute ( 'data-video-src' , cookieblockSrc ) ;
63+ videoElement . removeAttribute ( 'data-cookieblock-src' ) ;
64+ }
65+ videoElement . style . display = 'block' ;
66+
67+ if ( blockerElement ) {
68+ blockerElement . remove ( ) ;
69+ blockerElement = null ;
70+ }
71+
72+ originalWidget ( config , element ) ;
73+ previousStatus = 'unblocked' ;
74+ }
75+
76+ videoBackgroundBlocker ( ) ;
77+ } ;
78+ } ;
79+ } ) ;
0 commit comments