Handle keyboard shortcuts for modal popup
This commit is contained in:
parent
360a80b795
commit
c77ba5c611
|
@ -13,6 +13,9 @@ var app = new Vue({
|
||||||
currentItem: false,
|
currentItem: false,
|
||||||
showModal: false
|
showModal: false
|
||||||
},
|
},
|
||||||
|
created: function () {
|
||||||
|
window.addEventListener('keyup', this.handleKeyup);
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
detailPopup: function (itm, event) {
|
detailPopup: function (itm, event) {
|
||||||
// `this` inside methods points to the Vue instance
|
// `this` inside methods points to the Vue instance
|
||||||
|
@ -44,6 +47,27 @@ var app = new Vue({
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
this.items.splice(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue