Use Mousetrap for image viewer shortcuts
This commit is contained in:
parent
77714accca
commit
2c0fc67ab9
@ -5,6 +5,7 @@ const options = require("./options");
|
|||||||
const socket = require("./socket");
|
const socket = require("./socket");
|
||||||
const templates = require("../views");
|
const templates = require("../views");
|
||||||
const input = $("#input");
|
const input = $("#input");
|
||||||
|
const Mousetrap = require("mousetrap");
|
||||||
|
|
||||||
module.exports = renderPreview;
|
module.exports = renderPreview;
|
||||||
|
|
||||||
@ -111,21 +112,12 @@ imageViewer.on("click", function(event, data = {}) {
|
|||||||
closeImageViewer(data);
|
closeImageViewer(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).keydown(function(e) {
|
Mousetrap.bind("esc", () => closeImageViewer());
|
||||||
switch (e.keyCode ? e.keyCode : e.which) {
|
|
||||||
case 27: // Escape
|
Mousetrap.bind(["left", "right"], (e, key) => {
|
||||||
closeImageViewer();
|
|
||||||
break;
|
|
||||||
case 37: // Left arrow
|
|
||||||
if (imageViewer.hasClass("opened")) {
|
if (imageViewer.hasClass("opened")) {
|
||||||
imageViewer.find(".previous-image-btn").click();
|
const direction = key === "left" ? "previous" : "next";
|
||||||
}
|
imageViewer.find(`.${direction}-image-btn`).click();
|
||||||
break;
|
|
||||||
case 39: // Right arrow
|
|
||||||
if (imageViewer.hasClass("opened")) {
|
|
||||||
imageViewer.find(".next-image-btn").click();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user