Mercurial > gui
comparison ckeditor.js @ 34:2d195bee1efa
CKeditor wrapper
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Thu, 21 Nov 2013 18:19:02 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
33:2e7f8f7d71d4 | 34:2d195bee1efa |
---|---|
1 function toolbar_set(toolbars) { | |
2 var toolbarsOut = []; | |
3 | |
4 for (; toolbars != null; toolbars = toolbars._2) { | |
5 var toolbar = toolbars._1; | |
6 | |
7 if (toolbar == null) | |
8 toolbarsOut.push('/'); | |
9 else if (toolbar.n == "Bar") { | |
10 var buttonsOut = [], r = toolbar.v; | |
11 var name = r._Nam; | |
12 | |
13 for (var buttons = r._Buttons; buttons != null; buttons = buttons._2) { | |
14 var button = buttons._1; | |
15 buttonsOut.push(button == "Separator" ? "-" : button); | |
16 } | |
17 | |
18 if (name == null) | |
19 toolbarsOut.push(buttonsOut); | |
20 else | |
21 toolbarsOut.push({name: name, items: buttonsOut}); | |
22 } else | |
23 throw ("Invalid Ckeditor toolbar " + toolbar); | |
24 } | |
25 | |
26 return toolbarsOut; | |
27 } | |
28 | |
29 function sizeOut(v) { | |
30 if (v == "DefaultSize") | |
31 return null; | |
32 else if (v.n == "Pixels") | |
33 return (ts(v.v)); | |
34 else if (v.n == "Percent") | |
35 return (ts(v.v) + "%"); | |
36 else | |
37 throw ("Invalid Ckeditor.size " + v); | |
38 } | |
39 | |
40 function uw_ckeditor_editor(r) { | |
41 var config = {}; | |
42 | |
43 var width = sizeOut(r._Width); | |
44 if (width != null) | |
45 config.width = width; | |
46 | |
47 var height = sizeOut(r._Height); | |
48 if (height != null) | |
49 config.height = height; | |
50 | |
51 var toolbarSet = r._ToolbarSet; | |
52 | |
53 if (toolbarSet != null) | |
54 config.toolbar = toolbar_set(toolbarSet.v); | |
55 | |
56 return {config: config, name: fresh()} | |
57 } | |
58 | |
59 function uw_ckeditor_replace(t, id) { | |
60 t.editor = CKEDITOR.replace(id, t.config); | |
61 } | |
62 | |
63 function uw_ckeditor_content(t) { | |
64 if (t.editor == undefined) | |
65 return ""; | |
66 else | |
67 return t.editor.getData(); | |
68 } |