Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keyboard navigation for Adobe Stock image previews #25611

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 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();
$(document).on('keydown', this.handleKeyDown.bind(this));

return this;
},

/**
* Init observable variables
* @return {Object}
Expand All @@ -54,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 @@ -66,7 +84,12 @@ define([
* @param {Object} record
*/
prev: function (record) {
var recordToShow = this.getRecord(record._rowIndex - 1);
var recordToShow;

if (record._rowIndex === 0) {
return;
}
recordToShow = this.getRecord(record._rowIndex - 1);

recordToShow.rowNumber = record.firstInRow ? record.rowNumber - 1 : record.rowNumber;
this.show(recordToShow);
Expand Down Expand Up @@ -174,6 +197,23 @@ define([
block: 'center',
inline: 'nearest'
});
},

/**
* Handle keyboard navigation for image preview
*
* @param {Object} e
*/
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());
}
}
}
});
});