-
Notifications
You must be signed in to change notification settings - Fork 11
/
vue-redactor.js
84 lines (77 loc) · 2.03 KB
/
vue-redactor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Redactor Vue Component
Version 1.2
Updated: June 9, 2021
http://imperavi.com/redactor/
Copyright 2021, Imperavi Ltd.
License: MIT
*/
Vue.component('Redactor', {
template: '<textarea ref="redactor" :name="name" :placeholder="placeholder" :value="value" />',
redactor: false,
props: {
value: {
default: '',
type: String
},
placeholder: {
type: String,
default: null
},
name: {
type: String,
default: null
},
config: {
default: {},
type: Object
}
},
watch: {
value(newValue, oldValue){
if (this.redactor.editor.isFocus() || this.redactor.editor.isSourceMode()) {
return;
}
this.redactor.source.setCode(newValue);
}
},
mounted() {
this.init()
},
beforeDestroy() {
this.destroy()
},
methods: {
init () {
var me = this;
var callbacks = {
changed: function(html) {
me.handleInput(html);
return html
}
};
// extend config
if (typeof this.config.callbacks === 'undefined') {
Vue.set(this.config, 'callbacks', callbacks);
}
else {
this.config.callbacks.changed = callbacks.changed;
}
// call Redactor
var app = Redactor(this.$refs.redactor, this.config);
// set instance
this.redactor = app;
this.$parent.redactor = app;
},
destroy () {
// Call destroy on redactor to cleanup event handlers
Redactor(this.$refs.redactor, 'destroy');
// unset instance for garbage collection
this.redactor = null;
this.$parent.redactor = null;
},
handleInput (val) {
this.$emit('input', val);
}
}
});