Skip to content

Commit 020abbf

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-93271: [Backport for 2.1.x] Product Video feature not GDPR compliant
1 parent 484cfcf commit 020abbf

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ define([
8787
this._height = this.element.data('height');
8888
this._autoplay = !!this.element.data('autoplay');
8989
this._playing = this._autoplay || false;
90+
this.useYoutubeNocookie = this.element.data('youtubenocookie') || false;
9091

9192
this._responsive = this.element.data('responsive') !== false;
9293

@@ -164,6 +165,12 @@ define([
164165
* @private
165166
*/
166167
'youtubeapiready': function () {
168+
var host = 'https://www.youtube.com';
169+
170+
if (self.useYoutubeNocookie) {
171+
host = 'https://www.youtube-nocookie.com';
172+
}
173+
167174
if (self._player !== undefined) {
168175
return;
169176
}
@@ -178,6 +185,7 @@ define([
178185
width: self._width,
179186
videoId: self._code,
180187
playerVars: self._params,
188+
host: host,
181189
events: {
182190

183191
/**
@@ -470,7 +478,8 @@ define([
470478
description: tmp.snippet.description,
471479
thumbnail: tmp.snippet.thumbnails.high.url,
472480
videoId: videoInfo.id,
473-
videoProvider: videoInfo.type
481+
videoProvider: videoInfo.type,
482+
useYoutubeNocookie: videoInfo.useYoutubeNocookie
474483
};
475484
this._videoInformation = respData;
476485
this.element.trigger(this._UPDATE_VIDEO_INFORMATION_TRIGGER, respData);
@@ -601,7 +610,8 @@ define([
601610
var id,
602611
type,
603612
ampersandPosition,
604-
vimeoRegex;
613+
vimeoRegex,
614+
useYoutubeNocookie = false;
605615

606616
if (typeof href !== 'string') {
607617
return href;
@@ -621,9 +631,13 @@ define([
621631
id = id.substring(0, ampersandPosition);
622632
}
623633

624-
} else if (href.host.match(/youtube\.com|youtu\.be/)) {
634+
} else if (href.host.match(/youtube\.com|youtu\.be|youtube-nocookie.com/)) {
625635
id = href.pathname.replace(/^\/(embed\/|v\/)?/, '').replace(/\/.*/, '');
626636
type = 'youtube';
637+
638+
if (href.host.match(/youtube-nocookie.com/)) {
639+
useYoutubeNocookie = true;
640+
}
627641
} else if (href.host.match(/vimeo\.com/)) {
628642
type = 'vimeo';
629643
vimeoRegex = new RegExp(['https?:\\/\\/(?:www\\.|player\\.)?vimeo.com\\/(?:channels\\/(?:\\w+\\/)',
@@ -641,7 +655,7 @@ define([
641655
}
642656

643657
return id ? {
644-
id: id, type: type, s: href.search.replace(/^\?/, '')
658+
id: id, type: type, s: href.search.replace(/^\?/, ''), useYoutubeNocookie: useYoutubeNocookie
645659
} : false;
646660
}
647661
});

app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ define([
2121
container: '.video-player-container',
2222
videoClass: 'product-video',
2323
reset: false,
24+
useYoutubeNocookie: false,
2425
metaData: {
2526
DOM: {
2627
title: '.video-information.title span',
@@ -90,13 +91,17 @@ define([
9091
uploaderLink;
9192

9293
this.reset();
93-
this.element.find(this.options.container).append('<div class="' +
94-
this.options.videoClass +
95-
'" data-type="' +
96-
this.options.videoProvider +
97-
'" data-code="' +
98-
this.options.videoId +
99-
'" data-width="100%" data-height="100%"></div>');
94+
this.element.find(this.options.container).append(
95+
'<div class="' +
96+
this.options.videoClass +
97+
'" data-type="' +
98+
this.options.videoProvider +
99+
'" data-code="' +
100+
this.options.videoId +
101+
'" data-youtubenocookie="' +
102+
this.options.useYoutubeNocookie +
103+
'" data-width="100%" data-height="100%"></div>'
104+
);
100105
this.element.find(this.options.metaData.DOM.wrapper).show();
101106
this.element.find(this.options.metaData.DOM.title).text(this.options.metaData.data.title);
102107
this.element.find(this.options.metaData.DOM.uploaded).text(this.options.metaData.data.uploaded);
@@ -335,6 +340,7 @@ define([
335340
.createVideoPlayer({
336341
videoId: data.videoId,
337342
videoProvider: data.videoProvider,
343+
useYoutubeNocookie: data.useYoutubeNocookie,
338344
reset: false,
339345
metaData: {
340346
DOM: {

app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ define([
3434
var id,
3535
type,
3636
ampersandPosition,
37-
vimeoRegex;
37+
vimeoRegex,
38+
useYoutubeNocookie = false;
3839

3940
/**
4041
* Get youtube ID
@@ -68,9 +69,13 @@ define([
6869
id = _getYoutubeId(id);
6970
type = 'youtube';
7071
}
71-
} else if (href.host.match(/youtube\.com|youtu\.be/)) {
72+
} else if (href.host.match(/youtube\.com|youtu\.be|youtube-nocookie.com/)) {
7273
id = href.pathname.replace(/^\/(embed\/|v\/)?/, '').replace(/\/.*/, '');
7374
type = 'youtube';
75+
76+
if (href.host.match(/youtube-nocookie.com/)) {
77+
useYoutubeNocookie = true;
78+
}
7479
} else if (href.host.match(/vimeo\.com/)) {
7580
type = 'vimeo';
7681
vimeoRegex = new RegExp(['https?:\\/\\/(?:www\\.|player\\.)?vimeo.com\\/(?:channels\\/(?:\\w+\\/)',
@@ -85,7 +90,7 @@ define([
8590
}
8691

8792
return id ? {
88-
id: id, type: type, s: href.search.replace(/^\?/, '')
93+
id: id, type: type, s: href.search.replace(/^\?/, ''), useYoutubeNocookie: useYoutubeNocookie
8994
} : false;
9095
}
9196

@@ -283,6 +288,7 @@ define([
283288
tmpVideoData.id = dataUrl.id;
284289
tmpVideoData.provider = dataUrl.type;
285290
tmpVideoData.videoUrl = tmpInputData.videoUrl;
291+
tmpVideoData.useYoutubeNocookie = dataUrl.useYoutubeNocookie;
286292
}
287293

288294
videoData.push(tmpVideoData);
@@ -631,6 +637,8 @@ define([
631637
videoData.provider +
632638
'" data-code="' +
633639
videoData.id +
640+
'" data-youtubenocookie="' +
641+
videoData.useYoutubeNocookie +
634642
'" data-width="100%" data-height="100%"></div>'
635643
);
636644
},

app/code/Magento/ProductVideo/view/frontend/web/js/load-player.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ define(['jquery', 'jquery/ui'], function ($) {
8888
this._playing = this._autoplay || false;
8989
this._loop = this.element.data('loop');
9090
this._rel = this.element.data('related');
91+
this.useYoutubeNocookie = this.element.data('youtubenocookie') || false;
9192

9293
this._responsive = this.element.data('responsive') !== false;
9394

@@ -164,6 +165,12 @@ define(['jquery', 'jquery/ui'], function ($) {
164165
* Handle event
165166
*/
166167
'youtubeapiready': function () {
168+
var host = 'https://www.youtube.com';
169+
170+
if (self.useYoutubeNocookie) {
171+
host = 'https://www.youtube-nocookie.com';
172+
}
173+
167174
if (self._player !== undefined) {
168175
return;
169176
}
@@ -182,6 +189,7 @@ define(['jquery', 'jquery/ui'], function ($) {
182189
width: self._width,
183190
videoId: self._code,
184191
playerVars: self._params,
192+
host: host,
185193
events: {
186194

187195
/**

lib/web/fotorama/fotorama.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ fotoramaVersion = '4.6.4';
831831
}
832832
type = 'youtube';
833833
}
834-
} else if (href.host.match(/youtube\.com|youtu\.be/)) {
834+
} else if (href.host.match(/youtube\.com|youtu\.be|youtube-nocookie.com/)) {
835835
id = href.pathname.replace(/^\/(embed\/|v\/)?/, '').replace(/\/.*/, '');
836836
type = 'youtube';
837837
} else if (href.host.match(/vimeo\.com/)) {

0 commit comments

Comments
 (0)