Use mousetrap for escape binds

This commit is contained in:
Pavel Djundik 2019-11-18 21:18:35 +02:00
parent 0cb8dc73bb
commit 9147772cb2
2 changed files with 14 additions and 10 deletions

View File

@ -38,11 +38,7 @@ export default {
};
},
mounted() {
document.addEventListener("keydown", (e) => {
if (e.code === "Escape") {
this.close();
}
});
Mousetrap.bind("esc", this.close);
const trap = Mousetrap(this.$refs.contextMenu);
@ -78,6 +74,9 @@ export default {
return false;
});
},
destroyed() {
Mousetrap.unbind("esc", this.close);
},
methods: {
open(event, items) {
this.items = items;

View File

@ -25,6 +25,8 @@
</template>
<script>
import Mousetrap from "mousetrap";
export default {
name: "ImageViewer",
data() {
@ -61,14 +63,17 @@ export default {
},
},
mounted() {
document.addEventListener("keydown", (e) => {
if (e.code === "Escape") {
this.closeViewer();
}
});
Mousetrap.bind("esc", this.closeViewer);
},
destroyed() {
Mousetrap.unbind("esc", this.closeViewer);
},
methods: {
closeViewer() {
if (this.link === null) {
return;
}
this.$root.$off("resize", this.correctPosition);
this.link = null;
},