22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5+ /* eslint-disable no-undef */
56define ( [
67 'jquery' ,
78 'Magento_Ui/js/grid/columns/column' ,
@@ -32,7 +33,8 @@ define([
3233 listens : {
3334 '${ $.provider }:params.filters' : 'hide' ,
3435 '${ $.provider }:params.search' : 'hide' ,
35- '${ $.provider }:params.paging' : 'hide'
36+ '${ $.provider }:params.paging' : 'hide' ,
37+ '${ $.provider }:data.items' : 'updateDisplayedRecord'
3638 } ,
3739 exports : {
3840 height : '${ $.parentName }.thumbnail_url:previewHeight'
@@ -48,6 +50,25 @@ define([
4850 this . _super ( ) ;
4951 $ ( document ) . on ( 'keydown' , this . handleKeyDown . bind ( this ) ) ;
5052
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+
5172 return this ;
5273 } ,
5374
@@ -128,8 +149,6 @@ define([
128149 * @param {Object } record
129150 */
130151 show : function ( record ) {
131- var img ;
132-
133152 if ( record . _rowIndex === this . visibleRecord ( ) ) {
134153 this . hide ( ) ;
135154
@@ -141,9 +160,21 @@ define([
141160 this . _selectRow ( record . rowNumber || null ) ;
142161 this . visibleRecord ( record . _rowIndex ) ;
143162
144- img = $ ( this . previewImageSelector + ' img' ) ;
163+ this . lastOpenedImage ( record . _rowIndex ) ;
164+ this . updateImageData ( ) ;
165+ } ,
145166
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 ) {
147178 this . updateHeight ( ) ;
148179 this . scrollToPreview ( ) ;
149180 } else {
@@ -152,8 +183,17 @@ define([
152183 this . scrollToPreview ( ) ;
153184 } . bind ( this ) ) ;
154185 }
186+ } ,
155187
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+ }
157197 } ,
158198
159199 /**
0 commit comments