Skip to content

Commit aef9c8f

Browse files
committed
PB-95: Video background for Row
1 parent 4410ddd commit aef9c8f

File tree

3 files changed

+46
-79
lines changed
  • app/code/Magento/PageBuilder/view/base/web/js
  • dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/frontend/web/js/content-type/row/appearance/default

3 files changed

+46
-79
lines changed

app/code/Magento/PageBuilder/view/base/web/js/content-type/row/appearance/default/widget.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,38 @@
44
*/
55
define([
66
'jquery',
7-
'jarallax',
8-
'jarallaxVideo',
9-
'vimeoWrapper'
10-
], function ($) {
7+
'Magento_PageBuilder/js/widget/video-background',
8+
'jarallax'
9+
], function ($, videoBackground) {
1110
'use strict';
1211

1312
return function (config, element) {
1413
var $element = $(element),
15-
parallaxSpeed = null,
16-
jarallaxConfig = null;
14+
parallaxSpeed = null;
1715

1816
if ($element.data('appearance') === 'contained') {
1917
$element = $(element).find('[data-element="inner"]');
2018
}
2119

22-
if ($element.data('enableParallax') !== 1 && $element.data('background-type') !== 'video') {
20+
if ($element.data('background-type') === 'video') {
21+
videoBackground(config, $element[0]);
22+
return;
23+
}
24+
25+
if ($element.data('enableParallax') !== 1) {
2326
return;
2427
}
2528

2629
$element.addClass('jarallax');
2730
$element.attr('data-jarallax', '');
28-
parallaxSpeed = parallaxSpeed || parseFloat($element.data('parallaxSpeed'));
2931

30-
if ($element.data('background-type') === 'video') {
31-
parallaxSpeed = $element.data('enableParallax') !== 1 ? 1 : parallaxSpeed;
32-
33-
jarallaxConfig = {
34-
imgSrc: $element.data('videoFallbackSrc'),
35-
speed: !isNaN(parallaxSpeed) ? parallaxSpeed : 0.5,
36-
videoLoop: $element.data('videoLoop'),
37-
videoPlayOnlyVisible: $element.data('videoPlayOnlyVisible'),
38-
disableVideo: false
39-
};
40-
}
32+
parallaxSpeed = parseFloat($element.data('parallaxSpeed'));
4133

42-
jarallaxConfig = jarallaxConfig || {
34+
window.jarallax($element[0], {
4335
imgPosition: $element[0].style.backgroundPosition || '50% 50%',
4436
imgRepeat: $element[0].style.backgroundRepeat || 'no-repeat',
4537
imgSize: $element[0].style.backgroundSize || 'cover',
4638
speed: !isNaN(parallaxSpeed) ? parallaxSpeed : 0.5
47-
};
48-
49-
window.jarallax($element[0], jarallaxConfig);
39+
});
5040
};
5141
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'jarallax',
8+
'jarallaxVideo',
9+
'vimeoWrapper'
10+
], function ($) {
11+
'use strict';
12+
13+
return function (config, element) {
14+
var $element = $(element),
15+
parallaxSpeed = $element.data('enableParallax') !== 1 ? 1 : parseFloat($element.data('parallaxSpeed'));
16+
17+
if ($element.data('background-type') !== 'video') {
18+
return;
19+
}
20+
21+
$element.addClass('jarallax');
22+
$element.attr('data-jarallax', '');
23+
24+
window.jarallax($element[0], {
25+
imgSrc: $element.data('videoFallbackSrc'),
26+
speed: !isNaN(parallaxSpeed) ? parallaxSpeed : 0.5,
27+
videoLoop: $element.data('videoLoop'),
28+
videoPlayOnlyVisible: $element.data('videoPlayOnlyVisible'),
29+
videoLazyLoading: $element.data('videoLazyLoad'),
30+
disableVideo: false
31+
});
32+
};
33+
});

dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/frontend/web/js/content-type/row/appearance/default/widget.test.js

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -53,61 +53,5 @@ define([
5353
speed: 1
5454
});
5555
});
56-
57-
it('Should call jarallax if video background and enableParallax === 1', function () {
58-
var el = document.createElement('div');
59-
60-
spyOn(window, 'jarallax');
61-
62-
el.setAttribute('data-enable-parallax', '1');
63-
el.setAttribute('data-background-type', 'video');
64-
65-
rowWidgetInitializer(undefined, el);
66-
67-
expect(window.jarallax).toHaveBeenCalled();
68-
});
69-
70-
it('Should call jarallax if video background and parallax not enabled with speed = 1', function () {
71-
var el = document.createElement('div');
72-
73-
spyOn(window, 'jarallax');
74-
75-
el.setAttribute('data-enable-parallax', '0');
76-
el.setAttribute('data-background-type', 'video');
77-
78-
rowWidgetInitializer(undefined, el);
79-
80-
expect(window.jarallax).toHaveBeenCalledWith(el, {
81-
speed: 1,
82-
imgSrc: undefined,
83-
videoLoop: undefined,
84-
videoPlayOnlyVisible: undefined,
85-
disableVideo: false
86-
});
87-
});
88-
89-
it('Should call jarallax on element based on its data if video background', function () {
90-
var el = document.createElement('div');
91-
92-
spyOn(window, 'jarallax');
93-
94-
el.setAttribute('data-enable-parallax', '1');
95-
el.setAttribute('data-background-type', 'video');
96-
el.setAttribute('data-enable-parallax', '1');
97-
el.setAttribute('data-video-fallback-src', '/image/test.jpg');
98-
el.setAttribute('data-video-loop', 'true');
99-
el.setAttribute('data-video-play-only-visible', 'false');
100-
el.setAttribute('data-parallax-speed', '0.3');
101-
102-
rowWidgetInitializer(undefined, el);
103-
104-
expect(window.jarallax).toHaveBeenCalledWith(el, {
105-
speed: 0.3,
106-
imgSrc: '/image/test.jpg',
107-
videoLoop: true,
108-
videoPlayOnlyVisible: false,
109-
disableVideo: false
110-
});
111-
});
11256
});
11357
});

0 commit comments

Comments
 (0)