4
4
*/
5
5
define ( [
6
6
'jquery' ,
7
- 'Magento_Ui/js/grid/columns/column'
8
- ] , function ( $ , Column ) {
7
+ 'Magento_Ui/js/grid/columns/column' ,
8
+ 'Magento_Ui/js/lib/key-codes'
9
+ ] , function ( $ , Column , keyCodes ) {
9
10
'use strict' ;
10
11
11
12
return Column . extend ( {
@@ -38,6 +39,18 @@ define([
38
39
}
39
40
} ,
40
41
42
+ /**
43
+ * Initialize image preview component
44
+ *
45
+ * @returns {Object }
46
+ */
47
+ initialize : function ( ) {
48
+ this . _super ( ) ;
49
+ $ ( document ) . on ( 'keydown' , this . handleKeyDown . bind ( this ) ) ;
50
+
51
+ return this ;
52
+ } ,
53
+
41
54
/**
42
55
* Init observable variables
43
56
* @return {Object }
@@ -60,8 +73,13 @@ define([
60
73
* @param {Object } record
61
74
*/
62
75
next : function ( record ) {
63
- var recordToShow = this . getRecord ( record . _rowIndex + 1 ) ;
76
+ var recordToShow ;
77
+
78
+ if ( record . _rowIndex + 1 === this . masonry ( ) . rows ( ) . length ) {
79
+ return ;
80
+ }
64
81
82
+ recordToShow = this . getRecord ( record . _rowIndex + 1 ) ;
65
83
recordToShow . rowNumber = record . lastInRow ? record . rowNumber + 1 : record . rowNumber ;
66
84
this . show ( recordToShow ) ;
67
85
} ,
@@ -72,7 +90,12 @@ define([
72
90
* @param {Object } record
73
91
*/
74
92
prev : function ( record ) {
75
- var recordToShow = this . getRecord ( record . _rowIndex - 1 ) ;
93
+ var recordToShow ;
94
+
95
+ if ( record . _rowIndex === 0 ) {
96
+ return ;
97
+ }
98
+ recordToShow = this . getRecord ( record . _rowIndex - 1 ) ;
76
99
77
100
recordToShow . rowNumber = record . firstInRow ? record . rowNumber - 1 : record . rowNumber ;
78
101
this . show ( recordToShow ) ;
@@ -206,6 +229,23 @@ define([
206
229
block : 'center' ,
207
230
inline : 'nearest'
208
231
} ) ;
232
+ } ,
233
+
234
+ /**
235
+ * Handle keyboard navigation for image preview
236
+ *
237
+ * @param {Object } e
238
+ */
239
+ handleKeyDown : function ( e ) {
240
+ var key = keyCodes [ e . keyCode ] ;
241
+
242
+ if ( this . visibleRecord ( ) !== null ) {
243
+ if ( key === 'pageLeftKey' ) {
244
+ this . prev ( this . displayedRecord ( ) ) ;
245
+ } else if ( key === 'pageRightKey' ) {
246
+ this . next ( this . displayedRecord ( ) ) ;
247
+ }
248
+ }
209
249
}
210
250
} ) ;
211
251
} ) ;
0 commit comments