Bind events in image viewer only once
This commit is contained in:
parent
ef473b0f53
commit
64aa510abf
@ -76,34 +76,32 @@ 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);
|
||||
if (!oldLink) {
|
||||
this.$root.$on("escapekey", this.closeViewer);
|
||||
this.$root.$on("resize", this.correctPosition);
|
||||
Mousetrap.bind("left", this.previous);
|
||||
Mousetrap.bind("right", this.next);
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.$root.$on("escapekey", this.closeViewer);
|
||||
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() {
|
||||
if (this.link === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.$root.$off("resize", this.correctPosition);
|
||||
this.channel = null;
|
||||
this.previousImage = null;
|
||||
this.nextImage = null;
|
||||
|
Loading…
Reference in New Issue
Block a user