Handle default preview state after loading

This commit is contained in:
Pavel Djundik 2018-10-01 17:08:46 +03:00
parent 42717e3dec
commit 759e69ed07

View file

@ -138,12 +138,12 @@ export default {
}, },
watch: { watch: {
"link.type"() { "link.type"() {
this.updateShownState();
this.onPreviewUpdate(); this.onPreviewUpdate();
}, },
}, },
created() { created() {
const shouldOpenByDefault = this.link.type === "link" ? this.$root.settings.links : this.$root.settings.media; this.updateShownState();
this.link.shown = this.link.shown && shouldOpenByDefault;
}, },
mounted() { mounted() {
this.$root.$on("resize", this.handleResize); this.$root.$on("resize", this.handleResize);
@ -204,6 +204,28 @@ export default {
this.showMoreButton = this.$refs.content.offsetWidth >= this.$refs.container.offsetWidth; this.showMoreButton = this.$refs.content.offsetWidth >= this.$refs.container.offsetWidth;
}); });
}, },
updateShownState() {
let defaultState = true;
switch (this.link.type) {
case "error":
defaultState = this.link.error === "image-too-big" ? this.$root.settings.media : this.$root.settings.links;
break;
case "loading":
defaultState = false;
break;
case "link":
defaultState = this.$root.settings.links;
break;
default:
defaultState = this.$root.settings.media;
}
this.link.shown = this.link.shown && defaultState;
},
}, },
}; };
</script> </script>