-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditor.js
114 lines (97 loc) · 3.83 KB
/
Editor.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
define([
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/string",
"dijit/_Widget",
"dijit/_TemplatedMixin",
"dijit/form/_FormValueWidget",
"dojo/text!./templates/Editor.html",
"ckeditor/ckeditor"
],
function(declare, lang, string, _Widget,
_TemplatedMixin, _FormValueWidget, templateEditor){
return declare("dojo-ckeditor.Editor",
[ _Widget, _TemplatedMixin, _FormValueWidget], {
cols: 80,
rows: 10,
settings: {},
defaultLang: 'en',
templateString: templateEditor,
postCreate: function () {
try {
CKEDITOR.replace(this.domNode, lang.mixin({
language: dojoConfig && dojoConfig.locale || this.defaultLang,
id: this.id
}, this.settings));
this.editor = CKEDITOR.instances[this.id];
this.editor.on('instanceReady', lang.hitch(this, function (){
// Will be deleted soon
this.emit('ready', this);
this.emit('dojo-ckeditor-ready', this);
}));
this.editor.on('change', lang.hitch(this, function (){
this._handleOnChange(this.get('value'));
}));
this.editor.on('blur', lang.hitch(this, function (){
this._onBlur();
}));
this.editor.on('focus', lang.hitch(this, function (){
this._onFocus();
}));
// Copy value from srcNodeRef, unless user specified a value explicitly (or there is no srcNodeRef)
// TODO: parser will handle this in 2.0
if(!this.value && this.srcNodeRef){
this.set('value', this.srcNodeRef.value);
}
} catch (e) {
console.error(this.declaredClass, arguments, e);
throw e;
}
},
focus: function () {
try {
this.inherited(arguments);
this.editor.focus();
} catch (e) {
console.error(this.declaredClass, arguments, e);
throw e;
}
},
_setValueAttr: function (value) {
try {
if (this.__lock) {
this.defer(function (){
this.set('value', value);
}, 10);
return;
}
this.__lock = true;
var inherited = lang.hitch(this, 'inherited', arguments);
this.editor.setData(value || '', lang.hitch(this, function (){
this.__lock = false;
inherited();
}));
} catch (e) {
console.error(this.declaredClass+" "+arguments.callee.nom, arguments, e);
throw e;
}
},
destroy: function () {
try {
this.editor && this.editor.destroy();
this.inherited(arguments);
} catch (e) {
console.error(this.declaredClass, arguments, e);
throw e;
}
},
_getValueAttr: function () {
try {
return string.trim(this.editor.getData());
} catch (e) {
console.error(this.declaredClass+" "+arguments.callee.nom, arguments, e);
throw e;
}
}
});
});