Skip to content

Commit

Permalink
Resolved Adobe issue 691
Browse files Browse the repository at this point in the history
  • Loading branch information
drpayyne committed Nov 14, 2019
1 parent 3efbe15 commit 0e30366
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions app/code/Magento/Ui/view/base/web/js/grid/columns/image-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/
define([
'jquery',
'Magento_Ui/js/grid/columns/column'
], function ($, Column) {
'Magento_Ui/js/grid/columns/column',
'Magento_Ui/js/lib/key-codes'
], function ($, Column, keyCodes) {
'use strict';

return Column.extend({
Expand All @@ -32,6 +33,18 @@ define([
}
},

/**
* Initialize image preview component
*
* @returns {Object}
*/
initialize: function () {
this._super();
this.setNavigationListener();

return this;
},

/**
* Init observable variables
* @return {Object}
Expand Down Expand Up @@ -174,6 +187,36 @@ define([
block: 'center',
inline: 'nearest'
});
}
},

/**
* Set image preview keyboard navigation listener
*/
setNavigationListener: function () {
var imageIndex, endIndex, key,
startIndex = 0,
imageColumnSelector = '.masonry-image-column',
adobeModalSelector = '.adobe-stock-modal',
imageGridSelector = '.masonry-image-grid';

$(document).on('keydown', function(e) {
key = keyCodes[e.keyCode];
endIndex = $(imageGridSelector)[0].children.length - 1;

if($(this.previewImageSelector).length > 0) {
imageIndex = $(this.previewImageSelector)
.parents(imageColumnSelector)
.data('repeatIndex');
}

if($(adobeModalSelector).hasClass('_show')) {
if(key === 'pageLeftKey' && imageIndex !== startIndex) {
$(this.previewImageSelector + ' .action-previous').click();
} else if (key === 'pageRightKey' && imageIndex !== endIndex) {
$(this.previewImageSelector + ' .action-next').click();
}
}
});
},
});
});

0 comments on commit 0e30366

Please sign in to comment.