From c77ba5c611643477eaeefdc8524d87f48ddfdae3 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Fri, 20 Jan 2017 15:45:12 +0100 Subject: [PATCH] Handle keyboard shortcuts for modal popup --- socialdragon/assets/js/app.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/socialdragon/assets/js/app.js b/socialdragon/assets/js/app.js index 4a94c4e..59e472f 100644 --- a/socialdragon/assets/js/app.js +++ b/socialdragon/assets/js/app.js @@ -13,6 +13,9 @@ var app = new Vue({ currentItem: false, showModal: false }, + created: function () { + window.addEventListener('keyup', this.handleKeyup); + }, methods: { detailPopup: function (itm, event) { // `this` inside methods points to the Vue instance @@ -44,6 +47,27 @@ var app = new Vue({ if (index > -1) { this.items.splice(index, 1); } + }, + handleKeyup: function (event) { + if (this.showModal) { + enter = 13; + backspace = 8; + remove = 46; + esc = 27; + if (event.keyCode === enter) { + if (this.mode === 1) { + return; + } + this.approveItem(this.currentItem.ID); + } else if (event.keyCode === backspace || event.keyCode === remove) { + if (this.mode === 2) { + return; + } + this.rejectItem(this.currentItem.ID); + } else if (event.keyCode === esc) { + this.showModal = false; + } + } } } })