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