refactor: editor codeblock -> Vue component

This commit is contained in:
NGPixel
2017-05-28 14:34:50 -04:00
parent ebe288a5b2
commit f577a8134e
14 changed files with 295 additions and 303 deletions

View File

@@ -1,7 +1,5 @@
'use strict'
/* global FuseBox */
import filesize from 'filesize.js'
import $ from 'jquery'
@@ -18,7 +16,18 @@ export default {
data() {
return {}
},
computed: {
insertContent() {
return this.$store.state.editor.insertContent
}
},
methods: {
insert(content) {
if (mde.codemirror.doc.somethingSelected()) {
mde.codemirror.execCommand('singleSelection')
}
mde.codemirror.doc.replaceSelection(this.insertContent)
},
save() {
let self = this
this.$http.put(window.location.href, {
@@ -177,13 +186,9 @@ export default {
{
name: 'code-block',
action: (editor) => {
// if (!mdeModalOpenState) {
// if (mde.codemirror.doc.somethingSelected()) {
// vueCodeBlock.initContent = mde.codemirror.doc.getSelection()
// }
// vueCodeBlock.open()
// }
self.$store.dispatch('editorCodeblock/open', {
initialContent: (mde.codemirror.doc.somethingSelected()) ? mde.codemirror.doc.getSelection() : ''
})
},
className: 'icon-code',
title: 'Code Block'
@@ -212,8 +217,6 @@ export default {
})
// Save
this.$root.$on('editor-save', this.save)
$(window).bind('keydown', (ev) => {
if (ev.ctrlKey || ev.metaKey) {
switch (String.fromCharCode(ev.which).toLowerCase()) {
@@ -225,6 +228,10 @@ export default {
}
})
// Listeners
this.$root.$on('editor/save', this.save)
this.$root.$on('editor/insert', this.insert)
this.$store.dispatch('pageLoader/complete')
})
}