Skip to content

Commit

Permalink
support tinymce to 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lpreterite committed Jan 17, 2020
1 parent 4550c06 commit c9c4402
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import TinymceSetting from './setting'
import VueTinymce from './vue-tinymce.vue'
export { TinymceSetting, VueTinymce }
export { VueTinymce }
class VuePlugin{
constructor(){
const { prefix } = { prefix: "" }
Expand Down
23 changes: 0 additions & 23 deletions src/setting.js

This file was deleted.

25 changes: 17 additions & 8 deletions src/vue-tinymce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ const CHANGED = 2;
export default {
name: "VueTinymce",
model: {
prop: "content",
event: "change"
},
props: {
value: {
content: {
type: String,
default: ''
},
Expand Down Expand Up @@ -41,11 +45,11 @@ export default {
}
},
watch: {
value(val){
content(val){
// console.log('value change', val, this.status);
if(this.status === CHANGED) return this.status = INPUT;
if(!this.editor || !this.editor.initialized) return; // fix editor plugin is loading and set content will throw error.
this.editor.setContent(val);
this.setContent(this.editor, val);
}
},
created(){
Expand All @@ -60,17 +64,17 @@ export default {
this.setup(editor);
// console.log('setup');
editor.on('init', ()=>{
// console.log('init', this.value);
editor.setContent(this.value);
// console.log('init', this.content);
this.setContent(editor, this.content)
//fix execCommand not change ,more see issues#2
editor.on('input change undo redo execCommand KeyUp', ()=>{
if(this.status === INPUT || this.status === INIT) return this.status = CHANGED;
this.$emit('input', editor.getContent());
this.$emit('change', editor.getContent());
// console.log('editor change', editor.getContent());
});
//fix have chang not to emit input,more see issues #4
//fix have chang not to emit change,more see issues #4
editor.on('NodeChange', ()=>{
this.$emit('input', editor.getContent());
this.$emit('change', editor.getContent());
});
});
}
Expand All @@ -88,6 +92,11 @@ export default {
},
beforeDestroy: function(){
this.editor.remove();
},
methods: {
setContent(editor, val){
return editor.setContent(val)
}
}
}
</script>

0 comments on commit c9c4402

Please sign in to comment.