Use mousetrap for escape binds
This commit is contained in:
parent
0cb8dc73bb
commit
9147772cb2
@ -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;
|
||||
|
@ -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;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user