@@ -8,12 +8,12 @@ import "jarallaxVideo";
8
8
import $ from "jquery" ;
9
9
import $t from "mage/translate" ;
10
10
import events from "Magento_PageBuilder/js/events" ;
11
+ import mageUtils from "mageUtils" ;
11
12
import _ from "underscore" ;
12
13
import "vimeoWrapper" ;
13
- import ContentTypeConfigInterface from "../../content-type-config.types" ;
14
14
import HideShowOption from "../../content-type-menu/hide-show-option" ;
15
15
import { OptionsInterface } from "../../content-type-menu/option.types" ;
16
- import ContentTypeInterface from "../../content-type.types " ;
16
+ import { DataObject } from "../../data-store " ;
17
17
import Uploader from "../../uploader" ;
18
18
import delayUntil from "../../utils/delay-until" ;
19
19
import {
@@ -27,8 +27,7 @@ import {
27
27
import nestingLinkDialog from "../../utils/nesting-link-dialog" ;
28
28
import WysiwygFactory from "../../wysiwyg/factory" ;
29
29
import WysiwygInterface from "../../wysiwyg/wysiwyg-interface" ;
30
- import { ContentTypeMountEventParamsInterface , ContentTypeReadyEventParamsInterface } from "../content-type-events.types" ;
31
- import ObservableUpdater from "../observable-updater" ;
30
+ import { ContentTypeReadyEventParamsInterface } from "../content-type-events.types" ;
32
31
import BasePreview from "../preview" ;
33
32
34
33
/**
@@ -67,6 +66,18 @@ export default class Preview extends BasePreview {
67
66
*/
68
67
private handledDoubleClick : boolean = false ;
69
68
69
+ /**
70
+ * Properties that cause rebuilding video background
71
+ */
72
+ private videoUpdateProperties = [
73
+ "background_type" ,
74
+ "video_fallback_image" ,
75
+ "video_lazy_load" ,
76
+ "video_loop" ,
77
+ "video_play_only_visible" ,
78
+ "video_source" ,
79
+ ] ;
80
+
70
81
/**
71
82
* Debounce and defer the init of Jarallax
72
83
*
@@ -110,26 +121,6 @@ export default class Preview extends BasePreview {
110
121
111
122
} , 50 ) ;
112
123
113
- /**
114
- * @param {ContentTypeInterface } contentType
115
- * @param {ContentTypeConfigInterface } config
116
- * @param {ObservableUpdater } observableUpdater
117
- */
118
- constructor (
119
- contentType : ContentTypeInterface ,
120
- config : ContentTypeConfigInterface ,
121
- observableUpdater : ObservableUpdater ,
122
- ) {
123
- super ( contentType , config , observableUpdater ) ;
124
-
125
- this . contentType . dataStore . subscribe ( this . buildJarallax ) ;
126
- events . on ( "banner:mountAfter" , ( args : ContentTypeReadyEventParamsInterface ) => {
127
- if ( args . id === this . contentType . id ) {
128
- this . buildJarallax ( ) ;
129
- }
130
- } ) ;
131
- }
132
-
133
124
/**
134
125
* Return an array of options
135
126
*
@@ -459,7 +450,11 @@ export default class Preview extends BasePreview {
459
450
*/
460
451
protected bindEvents ( ) {
461
452
super . bindEvents ( ) ;
462
-
453
+ events . on ( "banner:mountAfter" , ( args : ContentTypeReadyEventParamsInterface ) => {
454
+ if ( args . id === this . contentType . id ) {
455
+ this . buildJarallax ( ) ;
456
+ }
457
+ } ) ;
463
458
events . on ( `${ this . config . name } :${ this . contentType . id } :updateAfter` , ( ) => {
464
459
const dataStore = this . contentType . dataStore . getState ( ) ;
465
460
const imageObject = ( dataStore [ this . config . additional_data . uploaderConfig . dataScope ] as object [ ] ) [ 0 ] || { } ;
@@ -470,6 +465,14 @@ export default class Preview extends BasePreview {
470
465
events . trigger ( `image:${ this . contentType . id } :assignAfter` , imageObject ) ;
471
466
nestingLinkDialog ( this . contentType . dataStore , this . wysiwyg , "message" , "link_url" ) ;
472
467
} ) ;
468
+ this . contentType . dataStore . subscribe ( function ( data : DataObject ) {
469
+ if ( this . isVideoShouldBeUpdated ( data ) ) {
470
+ this . buildJarallax ( ) ;
471
+ }
472
+ } . bind ( this ) ) ;
473
+ events . on ( `image:${ this . contentType . id } :uploadAfter` , ( ) => {
474
+ this . contentType . dataStore . set ( "background_type" , "image" ) ;
475
+ } ) ;
473
476
}
474
477
475
478
/**
@@ -487,4 +490,25 @@ export default class Preview extends BasePreview {
487
490
488
491
$ ( this . textarea ) . height ( scrollHeight ) ;
489
492
}
493
+
494
+ /**
495
+ * Adjust textarea's height based on scrollHeight
496
+ *
497
+ * @return boolean
498
+ */
499
+ private isVideoShouldBeUpdated ( state : DataObject ) : boolean {
500
+ const previousState = this . contentType . dataStore . previousState ;
501
+ const diff = mageUtils . compare ( previousState , state ) . changes ;
502
+
503
+ if ( diff . length > 0 ) {
504
+ return _ . some ( diff , ( element ) => {
505
+ if ( element . name === "video_fallback_image" ) {
506
+ return ( ! _ . isEmpty ( previousState . video_fallback_image ) && previousState . video_fallback_image ) !==
507
+ ( ! _ . isEmpty ( state . video_fallback_image ) && state . video_fallback_image ) ;
508
+ }
509
+
510
+ return this . videoUpdateProperties . indexOf ( element . name ) !== - 1 ;
511
+ } ) ;
512
+ }
513
+ }
490
514
}
0 commit comments