Skip to content

Commit 3f96e01

Browse files
committed
Improve code, DEV-1618
1 parent 15e9a2d commit 3f96e01

File tree

3 files changed

+30
-40
lines changed

3 files changed

+30
-40
lines changed

view/frontend/web/js/slide-widget-mixin.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
define([
22
'jquery',
33
'underscore',
4+
'CustomGento_Cookiebot/js/video-blocker-widget',
5+
'CustomGento_Cookiebot/js/video-platform-validator',
46
'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) {
7+
'Magento_PageBuilder/js/widget/video-background'
8+
], function ($, _, createVideoBlocker, isSupportedVideoPlatform, showOnHover, videoBackground) {
89
'use strict';
910

1011
return function (originalWidget) {
11-
function isSupportedVideoPlatform(url) {
12-
if (!url) {
13-
return false;
14-
}
15-
16-
// Regex patterns for supported video platforms
17-
const youtubePattern = /^https?:\/\/(www\.)?(youtube\.com|youtu\.be)\//i;
18-
const youtubeNocookiePattern = /^https?:\/\/(www\.)?youtube-nocookie\.com\//i;
19-
const vimeoPattern = /^https?:\/\/(www\.)?(vimeo\.com|player\.vimeo\.com)\//i;
20-
21-
return youtubePattern.test(url) ||
22-
youtubeNocookiePattern.test(url) ||
23-
vimeoPattern.test(url);
24-
}
25-
2612
return function (config, element) {
2713
const videoElement = element[0].querySelector('[data-background-type=video]');
2814

view/frontend/web/js/video-background-mixin.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
define([
22
'jquery',
3-
'CustomGento_Cookiebot/js/video-blocker-widget'
4-
], function ($, createVideoBlocker) {
3+
'CustomGento_Cookiebot/js/video-blocker-widget',
4+
'CustomGento_Cookiebot/js/video-platform-validator'
5+
], function ($, createVideoBlocker, isSupportedVideoPlatform) {
56
'use strict';
67

78
return function (originalWidget) {
8-
function isSupportedVideoPlatform(url) {
9-
if (!url) {
10-
return false;
11-
}
12-
13-
var youtubePattern = /^https?:\/\/(www\.)?(youtube\.com|youtu\.be)\//i;
14-
var youtubeNocookiePattern = /^https?:\/\/(www\.)?youtube-nocookie\.com\//i;
15-
var vimeoPattern = /^https?:\/\/(www\.)?(vimeo\.com|player\.vimeo\.com)\//i;
16-
17-
return youtubePattern.test(url) ||
18-
youtubeNocookiePattern.test(url) ||
19-
vimeoPattern.test(url);
20-
}
21-
229
function getValidDimension(value, fallback) {
2310
if (!value || parseFloat(value) === 0) {
2411
return fallback;
@@ -38,12 +25,12 @@ define([
3825
return;
3926
}
4027

41-
var blockVideoConsentConfig = window.cookiebotConfig && window.cookiebotConfig.blockVideosUntilConsent;
42-
var videoSrc = videoElement.getAttribute('data-video-src');
43-
var cookieblockSrc = videoElement.getAttribute('data-cookieblock-src');
44-
var src = videoSrc || cookieblockSrc;
45-
var previousStatus = '';
46-
var blockerElement = null;
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;
4734

4835
if (!blockVideoConsentConfig || !isSupportedVideoPlatform(src)) {
4936
originalWidget(config, element);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
define([], function () {
2+
'use strict';
3+
4+
return function isSupportedVideoPlatform(url) {
5+
if (!url) {
6+
return false;
7+
}
8+
9+
const youtubePattern = /^https?:\/\/(www\.)?(youtube\.com|youtu\.be)\//i;
10+
const youtubeNocookiePattern = /^https?:\/\/(www\.)?youtube-nocookie\.com\//i;
11+
const vimeoPattern = /^https?:\/\/(www\.)?(vimeo\.com|player\.vimeo\.com)\//i;
12+
13+
return youtubePattern.test(url) ||
14+
youtubeNocookiePattern.test(url) ||
15+
vimeoPattern.test(url);
16+
};
17+
});

0 commit comments

Comments
 (0)