/
editor.js
105 lines (91 loc) · 2.36 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
/**
* Ckeditor normalization object.
*
* @author Michael Slusarz <slusarz@horde.org>
* @copyright 2014 Horde LLC
* @license GPL-2 (http://www.horde.org/licenses/gpl)
*/
var IMP_Editor = Class.create({
// config,
// dready,
// editor,
// id,
// iready
// wait,
initialize: function(id, config)
{
this.config = Object.clone(config);
this.id = id;
this.start();
this.editor.on('instanceReady', function(evt) {
this.iready = true;
document.fire('IMP_Editor:ready', evt.editor);
}.bind(this));
this.editor.on('dataReady', function(evt) {
if (!this.dready) {
document.fire('IMP_Editor:dataReady', evt.editor);
this.dready = true;
}
}.bind(this));
this.editor.on('instanceDestroyed', function(evt) {
this.dready = this.iready = this.editor = false;
document.fire('IMP_Editor:destroy', evt.editor);
}.bind(this));
},
start: function()
{
if (!this.editor) {
this.config.height = Math.max($(this.id).getHeight(), 200) - 75;
this.editor = CKEDITOR.replace(this.id, this.config);
}
},
destroy: function()
{
if (this.editor) {
this.editor.destroy(true);
}
},
busy: function()
{
return this.wait || !this.iready || !this.dready;
},
getData: function()
{
return this.editor.getData();
},
setData: function(data)
{
if (this.busy()) {
this.setData.bind(this, data).delay(0.1);
} else {
this.wait = true;
this.editor.setData(data, function() {
this.wait = false;
}.bind(this));
}
},
resize: function(width, height)
{
if (this.busy()) {
this.resize.bind(this, width, height).delay(0.1);
} else {
this.editor.resize(width, height);
}
},
focus: function()
{
if (this.busy()) {
this.focus.bind(this).delay(0.1);
} else {
this.editor.focus();
}
},
updateElement: function()
{
if (this.busy()) {
this.updateElement.bind(this).delay(0.1);
} else {
this.editor.updateElement();
}
}
});