Skip to content

Commit

Permalink
Refactored action click
Browse files Browse the repository at this point in the history
  • Loading branch information
drpayyne committed Nov 26, 2019
1 parent 0e30366 commit 1298766
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 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 @@ -40,7 +40,7 @@ define([
*/
initialize: function () {
this._super();
this.setNavigationListener();
$(document).on('keydown', this.handleKeyDown.bind(this));

return this;
},
Expand All @@ -67,8 +67,13 @@ define([
* @param {Object} record
*/
next: function (record) {
var recordToShow = this.getRecord(record._rowIndex + 1);
var recordToShow;

if (record._rowIndex + 1 === this.masonry().rows().length) {
return;
}

recordToShow = this.getRecord(record._rowIndex + 1);
recordToShow.rowNumber = record.lastInRow ? record.rowNumber + 1 : record.rowNumber;
this.show(recordToShow);
},
Expand All @@ -79,6 +84,9 @@ define([
* @param {Object} record
*/
prev: function (record) {
if (record._rowIndex === 0) {
return;
}
var recordToShow = this.getRecord(record._rowIndex - 1);

recordToShow.rowNumber = record.firstInRow ? record.rowNumber - 1 : record.rowNumber;
Expand Down Expand Up @@ -190,33 +198,20 @@ define([
},

/**
* Set image preview keyboard navigation listener
* Handle keyboard navigation for image preview
*
* @param {Object} e
*/
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');
handleKeyDown: function (e) {
var key = keyCodes[e.keyCode];

if (this.visibleRecord() !== null) {
if (key === 'pageLeftKey') {
this.prev(this.displayedRecord());
} else if (key === 'pageRightKey') {
this.next(this.displayedRecord());
}

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 1298766

Please sign in to comment.