diff options
author | Fatih Acet <acetfatih@gmail.com> | 2017-08-18 23:53:58 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2017-08-18 23:53:58 +0300 |
commit | fb6421550aa26fd92116e1d5d63969bdd58f67e4 (patch) | |
tree | 076541fa93a27233715307065f99c23dbcfa24bf /app | |
parent | 7e82e45d874170fe894f4caf3fba83b75ca16986 (diff) | |
download | gitlab-ce-fb6421550aa26fd92116e1d5d63969bdd58f67e4.tar.gz |
Fix empty markdown render request.
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/vue_shared/components/markdown/field.vue | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/app/assets/javascripts/vue_shared/components/markdown/field.vue b/app/assets/javascripts/vue_shared/components/markdown/field.vue index 11eaeb89c4c..9e93feeda3b 100644 --- a/app/assets/javascripts/vue_shared/components/markdown/field.vue +++ b/app/assets/javascripts/vue_shared/components/markdown/field.vue @@ -47,36 +47,40 @@ toggleMarkdownPreview() { this.previewMarkdown = !this.previewMarkdown; + /* + Can't use `$refs` as the component is technically in the parent component + so we access the VNode & then get the element + */ + const text = this.$slots.textarea[0].elm.value; + if (!this.previewMarkdown) { this.markdownPreview = ''; } else { - this.markdownPreviewLoading = true; - this.$http.post( - this.markdownPreviewPath, - { - /* - Can't use `$refs` as the component is technically in the parent component - so we access the VNode & then get the element - */ - text: this.$slots.textarea[0].elm.value, - }, - ) - .then(resp => resp.json()) - .then((data) => { - this.markdownPreviewLoading = false; - this.markdownPreview = data.body || 'Nothing to preview.'; - - if (data.references) { - this.referencedCommands = data.references.commands; - this.referencedUsers = data.references.users; - } + if (text) { + this.markdownPreviewLoading = true; + this.$http.post(this.markdownPreviewPath, { text }) + .then(resp => resp.json()) + .then((data) => { + this.renderMarkdown(data); + }) + .catch(() => new Flash('Error loading markdown preview')); + } else { + this.renderMarkdown(); + } + } + }, + renderMarkdown(data = {}) { + this.markdownPreviewLoading = false; + this.markdownPreview = data.body || 'Nothing to preview.'; - this.$nextTick(() => { - $(this.$refs['markdown-preview']).renderGFM(); - }); - }) - .catch(() => new Flash('Error loading markdown preview')); + if (data.references) { + this.referencedCommands = data.references.commands; + this.referencedUsers = data.references.users; } + + this.$nextTick(() => { + $(this.$refs['markdown-preview']).renderGFM(); + }); }, }, mounted() { |