Bind events in image viewer only once

This commit is contained in:
Pavel Djundik 2020-03-10 15:36:58 +02:00
parent ef473b0f53
commit 64aa510abf
1 changed files with 12 additions and 14 deletions

View File

@ -76,26 +76,25 @@ export default {
},
},
watch: {
link() {
link(newLink, oldLink) {
// TODO: history.pushState
if (this.link === null) {
if (newLink === null) {
this.$root.$off("escapekey", this.closeViewer);
this.$root.$off("resize", this.correctPosition);
Mousetrap.unbind("left", this.previous);
Mousetrap.unbind("right", this.next);
return;
}
this.setPrevNextImages();
this.$root.$on("resize", this.correctPosition);
},
},
mounted() {
if (!oldLink) {
this.$root.$on("escapekey", this.closeViewer);
this.$root.$on("resize", this.correctPosition);
Mousetrap.bind("left", this.previous);
Mousetrap.bind("right", this.next);
}
},
destroyed() {
this.$root.$off("escapekey", this.closeViewer);
Mousetrap.unbind("left", this.previous);
Mousetrap.unbind("right", this.next);
},
methods: {
closeViewer() {
@ -103,7 +102,6 @@ export default {
return;
}
this.$root.$off("resize", this.correctPosition);
this.channel = null;
this.previousImage = null;
this.nextImage = null;