Commit 3fc05267 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Let field.vue handle the changing of preview

parent ce22977f
...@@ -45,8 +45,10 @@ ...@@ -45,8 +45,10 @@
}, },
}, },
methods: { methods: {
toggleMarkdownPreview() { toggleMarkdownPreview(isPreview) {
this.previewMarkdown = !this.previewMarkdown; if (isPreview === this.previewMarkdown) return;
this.previewMarkdown = isPreview;
/* /*
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
......
...@@ -20,16 +20,12 @@ ...@@ -20,16 +20,12 @@
return form && !form.find('.js-vue-markdown-field').length; return form && !form.find('.js-vue-markdown-field').length;
}, },
isActiveTarget(target) { toggleMarkdownPreview(e, isPreview, form) {
return target.closest('li').classList.contains('active');
},
toggleMarkdownPreview(e, form) {
if (e.target.blur) e.target.blur(); if (e.target.blur) e.target.blur();
if (this.isMarkdownForm(form) || this.isActiveTarget(e.target)) return; if (this.isMarkdownForm(form)) return;
this.$emit('toggle-markdown'); this.$emit('toggle-markdown', isPreview);
}, },
}, },
mounted() { mounted() {
...@@ -48,17 +44,19 @@ ...@@ -48,17 +44,19 @@
<ul class="nav-links clearfix"> <ul class="nav-links clearfix">
<li :class="{ active: !previewMarkdown }"> <li :class="{ active: !previewMarkdown }">
<a <a
class="js-write-link"
href="#md-write-holder" href="#md-write-holder"
tabindex="-1" tabindex="-1"
@click.prevent="toggleMarkdownPreview($event)"> @click.prevent="toggleMarkdownPreview($event, false)">
Write Write
</a> </a>
</li> </li>
<li :class="{ active: previewMarkdown }"> <li :class="{ active: previewMarkdown }">
<a <a
class="js-preview-link"
href="#md-preview-holder" href="#md-preview-holder"
tabindex="-1" tabindex="-1"
@click.prevent="toggleMarkdownPreview($event)"> @click.prevent="toggleMarkdownPreview($event, true)">
Preview Preview
</a> </a>
</li> </li>
......
...@@ -53,8 +53,8 @@ describe('Markdown field component', () => { ...@@ -53,8 +53,8 @@ describe('Markdown field component', () => {
}); });
})); }));
previewLink = vm.$el.querySelector('.nav-links li:nth-child(2) a'); previewLink = vm.$el.querySelector('.nav-links .js-preview-link');
writeLink = vm.$el.querySelector('.nav-links li:nth-child(1) a'); writeLink = vm.$el.querySelector('.nav-links js-write-link');
}); });
it('sets preview link as active', (done) => { it('sets preview link as active', (done) => {
......
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