1
1
define ( [
2
- 'mage/utils/wrapper ' ,
2
+ 'jquery ' ,
3
3
'underscore'
4
- ] , function ( wrapper , _ ) {
4
+ ] , function ( $ , _ ) {
5
5
'use strict' ;
6
6
7
7
return function ( swatchRenderer ) {
8
8
9
- return wrapper . wrap ( swatchRenderer , function ( create , config , element ) {
9
+ $ . widget ( 'mage.SwatchRenderer' , swatchRenderer , {
10
+
11
+ _init : function ( ) {
12
+ if ( _ . isUndefined ( this . options ) || _ . isEmpty ( this . options ) )
13
+ return this . _super ( ) ;
10
14
11
- if ( _ . isUndefined ( config . jsonConfig ) )
12
- return create ( config , element ) ;
15
+ if ( _ . isUndefined ( this . options . jsonConfig ) || _ . isEmpty ( this . options . jsonConfig ) )
16
+ return this . _super ( ) ;
13
17
14
- if ( _ . isUndefined ( config . jsonConfig . images ) )
15
- return create ( config , element ) ;
18
+ if ( _ . isUndefined ( this . options . jsonConfig . images ) || _ . isEmpty ( this . options . jsonConfig . images ) )
19
+ return this . _super ( ) ;
16
20
17
- let wdpr = window . devicePixelRatio ;
21
+ let wdpr = window . devicePixelRatio ;
18
22
19
- _ . each ( config . jsonConfig . images , function ( images ) {
20
- _ . each ( images , function ( imageObject ) {
21
- if ( _ . isUndefined ( imageObject . fastly_srcset ) )
22
- return ;
23
+ _ . each ( this . options . jsonConfig . images , function ( images ) {
24
+ _ . each ( images , function ( imageObject ) {
25
+ if ( _ . isUndefined ( imageObject . fastly_srcset ) )
26
+ return ;
23
27
24
- if ( ! _ . has ( imageObject . fastly_srcset , wdpr ) )
25
- return ;
28
+ if ( ! _ . has ( imageObject . fastly_srcset , wdpr ) )
29
+ return ;
26
30
27
- imageObject . img = imageObject . fastly_srcset [ wdpr ] ;
31
+ imageObject . img = imageObject . fastly_srcset [ wdpr ] ;
32
+ } ) ;
28
33
} ) ;
29
- } ) ;
30
34
31
- create ( config , element ) ;
35
+ return this . _super ( ) ;
36
+ }
32
37
} ) ;
38
+
39
+ return $ . mage . SwatchRenderer ;
33
40
} ;
34
- } ) ;
41
+ } ) ;
0 commit comments