-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathckeditorUrweb.js
76 lines (60 loc) · 2.02 KB
/
ckeditorUrweb.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
window.CKEDITOR_BASEPATH = 'https://cdn.ckeditor.com/4.13.1/';
CKEDITOR.stylesSet.add( 'upo_styles', [
{ name: 'Typewriter', element: 'tt' }
]);
// Stop aggravating behavior of pop-ups (like to set a hyperlink) within a modal.
$(document).on('focusin', function(e) {
e.stopImmediatePropagation();
});
function toolbar_set(toolbars) {
var toolbarsOut = [];
for (; toolbars != null; toolbars = toolbars._2) {
var toolbar = toolbars._1;
if (toolbar == null)
toolbarsOut.push('/');
else if (toolbar.n == "Bar") {
var buttonsOut = [], r = toolbar.v;
var name = r._Nam;
for (var buttons = r._Buttons; buttons != null; buttons = buttons._2) {
var button = buttons._1;
buttonsOut.push(button == "Separator" ? "-" : button);
}
if (name == null)
toolbarsOut.push(buttonsOut);
else
toolbarsOut.push({name: name, items: buttonsOut});
} else
throw ("Invalid Ckeditor toolbar " + toolbar);
}
return toolbarsOut;
}
function sizeOut(v) {
if (v == "DefaultSize")
return null;
else if (v.n == "Pixels")
return (ts(v.v));
else if (v.n == "Percent")
return (ts(v.v) + "%");
else
throw ("Invalid Ckeditor.size " + v);
}
function uw_ckeditor_replace(r) {
var config = {entities : false, stylesSet : 'upo_styles', baseFloatZIndex : 1E5};
var width = sizeOut(r._Width);
if (width != null)
config.width = width;
var height = sizeOut(r._Height);
if (height != null)
config.height = height;
var toolbarSet = r._ToolbarSet;
if (toolbarSet != null)
config.toolbar = toolbar_set(toolbarSet.v);
var ed = CKEDITOR.replace(r._Id, config);
var src = r._Source;
ed.setData(sg(src));
ed.on('change', function(e) { sv(src, ed.getSnapshot()); });
}
function uw_ckeditor_setContent(id, s) {
var ed = CKEDITOR.instances[id];
if (ed) ed.setData(s);
}