Commit a153f006 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Separate preview and write tabs into seperate events

parent a1c39065
...@@ -45,10 +45,10 @@ ...@@ -45,10 +45,10 @@
}, },
}, },
methods: { methods: {
toggleMarkdownPreview(isPreview) { showPreviewTab() {
if (isPreview === this.previewMarkdown) return; if (this.previewMarkdown) return;
this.previewMarkdown = isPreview; this.previewMarkdown = true;
/* /*
Can't use `$refs` as the component is technically in the parent component Can't use `$refs` as the component is technically in the parent component
...@@ -56,20 +56,22 @@ ...@@ -56,20 +56,22 @@
*/ */
const text = this.$slots.textarea[0].elm.value; const text = this.$slots.textarea[0].elm.value;
if (!this.previewMarkdown) { if (text) {
this.markdownPreview = '';
} else if (text) {
this.markdownPreviewLoading = true; this.markdownPreviewLoading = true;
this.$http.post(this.markdownPreviewPath, { text }) this.$http.post(this.markdownPreviewPath, { text })
.then(resp => resp.json()) .then(resp => resp.json())
.then((data) => { .then(data => this.renderMarkdown(data))
this.renderMarkdown(data);
})
.catch(() => new Flash('Error loading markdown preview')); .catch(() => new Flash('Error loading markdown preview'));
} else { } else {
this.renderMarkdown(); this.renderMarkdown();
} }
}, },
showWriteTab() {
this.markdownPreview = '';
this.previewMarkdown = false;
},
renderMarkdown(data = {}) { renderMarkdown(data = {}) {
this.markdownPreviewLoading = false; this.markdownPreviewLoading = false;
this.markdownPreview = data.body || 'Nothing to preview.'; this.markdownPreview = data.body || 'Nothing to preview.';
...@@ -106,7 +108,8 @@ ...@@ -106,7 +108,8 @@
ref="gl-form"> ref="gl-form">
<markdown-header <markdown-header
:preview-markdown="previewMarkdown" :preview-markdown="previewMarkdown"
@toggle-markdown="toggleMarkdownPreview" /> @preview-markdown="showPreviewTab"
@write-markdown="showWriteTab" />
<div <div
class="md-write-holder" class="md-write-holder"
v-show="!previewMarkdown"> v-show="!previewMarkdown">
......
...@@ -20,28 +20,27 @@ ...@@ -20,28 +20,27 @@
return form && !form.find('.js-vue-markdown-field').length; return form && !form.find('.js-vue-markdown-field').length;
}, },
toggleMarkdownPreview(e, isPreview, form) { previewMarkdownTab(event, form) {
if (e.target.blur) e.target.blur(); if (event.target.blur) event.target.blur();
if (this.isMarkdownForm(form)) return; if (this.isMarkdownForm(form)) return;
this.$emit('toggle-markdown', isPreview); this.$emit('preview-markdown');
}, },
toggleMarkdownPreviewShow(event, form) { writeMarkdownTab(event, form) {
return this.toggleMarkdownPreview(event, true, form); if (event.target.blur) event.target.blur();
}, if (this.isMarkdownForm(form)) return;
toggleMarkdownPreviewHide(event, form) { this.$emit('write-markdown');
return this.toggleMarkdownPreview(event, false, form);
}, },
}, },
mounted() { mounted() {
$(document).on('markdown-preview:show.vue', this.toggleMarkdownPreviewShow); $(document).on('markdown-preview:show.vue', this.previewMarkdownTab);
$(document).on('markdown-preview:hide.vue', this.toggleMarkdownPreviewHide); $(document).on('markdown-preview:hide.vue', this.writeMarkdownTab);
}, },
beforeDestroy() { beforeDestroy() {
$(document).off('markdown-preview:show.vue', this.toggleMarkdownPreviewShow); $(document).off('markdown-preview:show.vue', this.previewMarkdownTab);
$(document).off('markdown-preview:hide.vue', this.toggleMarkdownPreviewHide); $(document).off('markdown-preview:hide.vue', this.writeMarkdownTab);
}, },
}; };
</script> </script>
...@@ -54,7 +53,7 @@ ...@@ -54,7 +53,7 @@
class="js-write-link" class="js-write-link"
href="#md-write-holder" href="#md-write-holder"
tabindex="-1" tabindex="-1"
@click.prevent="toggleMarkdownPreview($event, false)"> @click.prevent="writeMarkdownTab($event, form)">
Write Write
</a> </a>
</li> </li>
...@@ -63,7 +62,7 @@ ...@@ -63,7 +62,7 @@
class="js-preview-link" class="js-preview-link"
href="#md-preview-holder" href="#md-preview-holder"
tabindex="-1" tabindex="-1"
@click.prevent="toggleMarkdownPreview($event, true)"> @click.prevent="previewMarkdownTab($event, form)">
Preview Preview
</a> </a>
</li> </li>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment