2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+ /* eslint-disable no-undef */
5
6
define ( [
6
7
'jquery' ,
7
8
'Magento_Ui/js/grid/columns/column' ,
@@ -32,7 +33,8 @@ define([
32
33
listens : {
33
34
'${ $.provider }:params.filters' : 'hide' ,
34
35
'${ $.provider }:params.search' : 'hide' ,
35
- '${ $.provider }:params.paging' : 'hide'
36
+ '${ $.provider }:params.paging' : 'hide' ,
37
+ '${ $.provider }:data.items' : 'updateDisplayedRecord'
36
38
} ,
37
39
exports : {
38
40
height : '${ $.parentName }.thumbnail_url:previewHeight'
@@ -48,6 +50,25 @@ define([
48
50
this . _super ( ) ;
49
51
$ ( document ) . on ( 'keydown' , this . handleKeyDown . bind ( this ) ) ;
50
52
53
+ this . lastOpenedImage . subscribe ( function ( newValue ) {
54
+
55
+ if ( newValue === false && _ . isNull ( this . visibleRecord ( ) ) ) {
56
+ return ;
57
+ }
58
+
59
+ if ( newValue === this . visibleRecord ( ) ) {
60
+ return ;
61
+ }
62
+
63
+ if ( newValue === false ) {
64
+ this . hide ( ) ;
65
+
66
+ return ;
67
+ }
68
+
69
+ this . show ( this . masonry ( ) . rows ( ) [ newValue ] ) ;
70
+ } . bind ( this ) ) ;
71
+
51
72
return this ;
52
73
} ,
53
74
@@ -128,8 +149,6 @@ define([
128
149
* @param {Object } record
129
150
*/
130
151
show : function ( record ) {
131
- var img ;
132
-
133
152
if ( record . _rowIndex === this . visibleRecord ( ) ) {
134
153
this . hide ( ) ;
135
154
@@ -141,9 +160,21 @@ define([
141
160
this . _selectRow ( record . rowNumber || null ) ;
142
161
this . visibleRecord ( record . _rowIndex ) ;
143
162
144
- img = $ ( this . previewImageSelector + ' img' ) ;
163
+ this . lastOpenedImage ( record . _rowIndex ) ;
164
+ this . updateImageData ( ) ;
165
+ } ,
145
166
146
- if ( img . get ( 0 ) . complete ) {
167
+ /**
168
+ * Update image data when image preview is opened
169
+ */
170
+ updateImageData : function ( ) {
171
+ var img = $ ( this . previewImageSelector + ' img' ) ;
172
+
173
+ if ( ! img . get ( 0 ) ) {
174
+ setTimeout ( function ( ) {
175
+ this . updateImageData ( ) ;
176
+ } . bind ( this ) , 100 ) ;
177
+ } else if ( img . get ( 0 ) . complete ) {
147
178
this . updateHeight ( ) ;
148
179
this . scrollToPreview ( ) ;
149
180
} else {
@@ -152,8 +183,17 @@ define([
152
183
this . scrollToPreview ( ) ;
153
184
} . bind ( this ) ) ;
154
185
}
186
+ } ,
155
187
156
- this . lastOpenedImage ( record . _rowIndex ) ;
188
+ /**
189
+ * Update preview displayed record data from the new items data if the preview is expanded
190
+ *
191
+ * @param {Array } items
192
+ */
193
+ updateDisplayedRecord : function ( items ) {
194
+ if ( ! _ . isNull ( this . visibleRecord ( ) ) ) {
195
+ this . displayedRecord ( items [ this . visibleRecord ( ) ] ) ;
196
+ }
157
197
} ,
158
198
159
199
/**
0 commit comments