Skip to content

Commit 2129bfd

Browse files
committed
PB-95: Video background for Row
1 parent ce3ed40 commit 2129bfd

File tree

7 files changed

+156
-12
lines changed

7 files changed

+156
-12
lines changed

app/code/Magento/PageBuilder/view/adminhtml/pagebuilder/content_type/row.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<attribute name="parallax_speed" source="data-parallax-speed"/>
5555
<attribute name="background_images" source="data-background-images"/>
5656
<attribute name="background_type" source="data-background-type"/>
57-
<attribute name="video_source" source="data-video-src"/>
57+
<attribute name="video_source" source="data-video-src" converter="Magento_PageBuilder/js/content-type/video/converter/attribute/data-src"/>
5858
<attribute name="video_loop" source="data-video-loop"/>
5959
<attribute name="video_play_only_visible" source="data-video-play-only-visible"/>
6060
<attribute name="video_lazy_load" source="data-video-lazy-load"/>
@@ -111,7 +111,7 @@
111111
<attribute name="parallax_speed" source="data-parallax-speed"/>
112112
<attribute name="background_images" source="data-background-images"/>
113113
<attribute name="background_type" source="data-background-type"/>
114-
<attribute name="video_source" source="data-video-src"/>
114+
<attribute name="video_source" source="data-video-src" converter="Magento_PageBuilder/js/content-type/video/converter/attribute/data-src"/>
115115
<attribute name="video_loop" source="data-video-loop"/>
116116
<attribute name="video_play_only_visible" source="data-video-play-only-visible"/>
117117
<attribute name="video_lazy_load" source="data-video-lazy-load"/>
@@ -169,7 +169,7 @@
169169
<attribute name="parallax_speed" source="data-parallax-speed"/>
170170
<attribute name="background_images" source="data-background-images"/>
171171
<attribute name="background_type" source="data-background-type"/>
172-
<attribute name="video_source" source="data-video-src"/>
172+
<attribute name="video_source" source="data-video-src" converter="Magento_PageBuilder/js/content-type/video/converter/attribute/data-src"/>
173173
<attribute name="video_loop" source="data-video-loop"/>
174174
<attribute name="video_play_only_visible" source="data-video-play-only-visible"/>
175175
<attribute name="video_lazy_load" source="data-video-lazy-load"/>

app/code/Magento/PageBuilder/view/adminhtml/ui_component/pagebuilder_base_form_with_background_video.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@
7676
<field name="video_source" sortOrder="90" formElement="input">
7777
<settings>
7878
<visible>false</visible>
79-
<!-- <validation>-->
80-
<!-- <rule name="validate-video-url" xsi:type="boolean">true</rule>-->
81-
<!-- </validation>-->
79+
<validation>
80+
<rule name="validate-video-source" xsi:type="boolean">true</rule>
81+
</validation>
8282
<dataType>text</dataType>
8383
<label translate="true">Video URL</label>
8484
<tooltip>
8585
<description translate="true">
8686
<![CDATA[
87-
<p>Supported video formats include:</p>
88-
<p>MP4...</p>
87+
<p>Supported video sources are:</p>
88+
<p>URL to YouTube or Vimeo video</p>
89+
<p>URL to .mp4, .ogv or .webm video file</p>
8990
]]>
9091
</description>
9192
</tooltip>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/row/preview.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/video/converter/attribute/data-src.js

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/validator-rules-mixin.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ define([
156156
$.mage.__('Please enter a valid video URL.')
157157
);
158158

159+
validator.addRule(
160+
'validate-video-source',
161+
function (href) {
162+
if (utils.isEmptyNoTrim(href)) {
163+
return true;
164+
}
165+
166+
href = (href || '').replace(/^\s+/, '').replace(/\s+$/, '');
167+
168+
return validateIsUrl(href) && (
169+
href.match(/youtube\.com|youtu\.be/)
170+
|| href.match(/vimeo\.com/)
171+
|| href.match(/\.(mp4|ogv|webm)(?!\w)/)
172+
);
173+
},
174+
$.mage.__('Please enter a valid video URL.')
175+
);
176+
159177
validator.addRule(
160178
'validate-css-class',
161179
function (value) {

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/row/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class Preview extends PreviewCollection {
7777

7878
if (this.element &&
7979
(this.contentType.dataStore.get("background_type") as string) === 'video' &&
80-
(this.contentType.dataStore.get("video_source") as any[]).length
80+
(this.element.dataset.videoSrc as string).length
8181
) {
8282
window.Vimeo = window.Vimeo || {"Player": Player};
8383
const parallaxSpeed = (this.contentType.dataStore.get("enable_parallax") as string) === "1"
@@ -89,7 +89,7 @@ export default class Preview extends PreviewCollection {
8989
jarallax(
9090
this.element,
9191
{
92-
videoSrc: this.contentType.dataStore.get("video_source") as string,
92+
videoSrc: this.element.dataset.videoSrc as string,
9393
videoLoop: (this.contentType.dataStore.get("video_loop") as string) === "true",
9494
speed: !isNaN(parallaxSpeed) ? parallaxSpeed : 0.5,
9595
videoPlayOnlyVisible: (this.contentType.dataStore.get("video_play_only_visible") as string) === "true",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
import ConverterInterface from "../../../../converter/converter-interface";
7+
import {DataObject} from "../../../../data-store";
8+
import {get} from "../../../../utils/object";
9+
10+
export default class Src implements ConverterInterface {
11+
/**
12+
* Convert value to internal format
13+
*
14+
* @param value string
15+
* @returns {string | object}
16+
*/
17+
public fromDom(value: string): string | object {
18+
const fileRegExp = new RegExp("^(webm:|mp4:|ogv:)");
19+
if (fileRegExp.test(value)) {
20+
return value.substr(fileRegExp.exec(value)[0].length)
21+
}
22+
23+
return value;
24+
}
25+
26+
/**
27+
* Convert value to knockout format
28+
*
29+
* @param name string
30+
* @param data Object
31+
* @returns {string}
32+
*/
33+
public toDom(name: string, data: DataObject): string {
34+
const value = get<string>(data, name);
35+
if (value === undefined) {
36+
return "";
37+
}
38+
39+
const youtubeRegExp = new RegExp("^(?:https?:\/\/|\/\/)?(?:www\\.|m\\.)?" +
40+
"(?:youtu\\.be\/|youtube\\.com\/(?:embed\/|v\/|watch\\?v=|watch\\?.+&v=))([\\w-]{11})(?![\\w-])");
41+
const vimeoRegExp = new RegExp("https?:\/\/(?:www\\.|player\\.)?vimeo.com\/(?:channels\/" +
42+
"(?:\\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\\d+)\/video\/|video\/|)(\\d+)(?:$|\/|\\?)");
43+
const fileRegExp = new RegExp("^(?:https:)?\\/\\/.*[\\\\\\/].+\\.(webm|mp4|ogv)(?!\w)");
44+
45+
if (youtubeRegExp.test(value)) {
46+
return "https://www.youtube.com/watch?v=" + youtubeRegExp.exec(value)[1];
47+
} else if (vimeoRegExp.test(value)) {
48+
return "https://vimeo.com/" + vimeoRegExp.exec(value)[3];
49+
} else if (fileRegExp.test(value)) {
50+
const result = fileRegExp.exec(value);
51+
return result[1] + ":" + value;
52+
}
53+
54+
return value;
55+
}
56+
}

0 commit comments

Comments
 (0)