adding all weblabels from weblabels.fsf.org
[weblabels.fsf.org.git] / www.fsf.org / 20131028 / files / tinymce / tiny_mce_init.js
CommitLineData
5a920362 1var InitializedTinyMCEInstances = {}\r
2\r
3function TinyMCEConfig(id) {\r
4 this.id = id;\r
5 this.widget_config = eval('(' + document.getElementById (this.id).title + ')');\r
6 this.toolbars = [];\r
7\r
8 this.init = function() {\r
9\r
10 // Check if already initialized\r
11 if (typeof (InitializedTinyMCEInstances[this.id]) != 'undefined') {\r
12 return;\r
13 }\r
14 InitializedTinyMCEInstances[this.id] = 1;\r
15\r
16 this.initToolbars();\r
17 var format = document.getElementById(this.id + '_text_format');\r
18 if (format && format.tagName.toLowerCase() == 'input' && format.value.indexOf('html') == -1) {\r
19 return;\r
20 }\r
21\r
22 // Set textformat to html and hide selector\r
23 var node = tinymce.DOM.get(this.id);\r
24 node = tinymce.DOM.getParent(node, '.ArchetypesRichWidget,.richTextWidget');\r
25 if (node != null) {\r
26 node = tinymce.DOM.select('div.fieldTextFormat', node);\r
27 if (node.length > 0) {\r
28 tinymce.DOM.select('select', node[0])[0].value = 'text/html';\r
29 tinymce.DOM.setStyle(node[0], 'display', 'none');\r
30 }\r
31 }\r
32\r
33 for (var i = 0; i < this.widget_config.customplugins.length; i++) {\r
34 if (this.widget_config.customplugins[i].indexOf('|') != -1) {\r
35 e = this.widget_config.customplugins[i].split('|');\r
36 tinymce.PluginManager.load(e[0], this.getPortalUrl() + e[1]);\r
37 }\r
38 }\r
39 var init_dict = {\r
40 mode : "exact",\r
41 elements : this.id,\r
42 strict_loading_mode : true,\r
43 theme : "advanced",\r
44 language : this.getLanguage(),\r
45 skin : "plone",\r
46 inlinepopups_skin : "plonepopup",\r
47 plugins : this.getPlugins(),\r
48 // Find out if ieSpell requires gecko spellchecker...\r
49 gecko_spellcheck : this.geckoSpellcheckEnabled(),\r
50\r
51 atd_rpc_id : this.widget_config.atd_rpc_id,\r
52 atd_rpc_url : this.widget_config.atd_rpc_url,\r
53 atd_show_types : this.widget_config.atd_show_types,\r
54 atd_ignore_strings : this.widget_config.atd_ignore_strings,\r
55\r
56 labels : this.widget_config.labels,\r
57 theme_advanced_styles : this.getStyles(),\r
58 theme_advanced_buttons1 : this.getToolbar(0),\r
59 theme_advanced_buttons2 : this.getToolbar(1),\r
60 theme_advanced_buttons3 : this.getToolbar(2),\r
61 theme_advanced_buttons4 : this.getToolbar(3),\r
62 theme_advanced_toolbar_location : this.getToolbarLocation(),\r
63 theme_advanced_toolbar_align : "left",\r
64 theme_advanced_path_location : this.getPathLocation(),\r
65 theme_advanced_path : false,\r
66 theme_advanced_resizing : this.getResizing(),\r
67 theme_advanced_resizing_use_cookie : this.getResizingUseCookie(),\r
68 theme_advanced_resize_horizontal : this.getResizeHorizontal(),\r
69 theme_advanced_source_editor_width : this.getEditorWidth(),\r
70 theme_advanced_source_editor_height : this.getEditorHeight(),\r
71\r
72 table_styles : this.getTableStyles(),\r
73 table_firstline_th : true,\r
74 directionality : this.getDirectionality(),\r
75 entity_encoding : this.getEntityEncoding(),\r
76 content_css : this.getContentCSS(),\r
77 body_class : "documentContent",\r
78 body_id : "content",\r
79 document_base_url : this.getBase(),\r
80 document_url : this.getDocumentUrl(),\r
81 portal_url : this.getPortalUrl(),\r
82 navigation_root_url : this.getNavigationRootUrl(),\r
83 livesearch : this.getLivesearch(),\r
84 valid_elements : this.getValidElements(),\r
85 valid_inline_styles : this.getValidInlineStyles(),\r
86 link_using_uids : this.getLinkUsingUids(),\r
87 allow_captioned_images : this.getAllowCaptionedImages(),\r
88 rooted : this.getRooted(),\r
89 force_span_wrappers : true,\r
90 fix_list_elements : false\r
91 };\r
92\r
93 window.tinyMCE.init(init_dict);\r
94 };\r
95\r
96 this.getButtonWidth = function(b) {\r
97 switch (b) {\r
98 case 'style':\r
99 return 150;\r
100 case 'forecolor':\r
101 return 32;\r
102 case 'backcolor':\r
103 return 32;\r
104 case 'tablecontrols':\r
105 return 285;\r
106 }\r
107 return 23;\r
108 };\r
109\r
110 this.getTableStyles = function() {\r
111 return this.widget_config.table_styles.join (";");\r
112 };\r
113\r
114 this.getToolbar = function(i) {\r
115 return this.toolbars[i];\r
116 };\r
117\r
118 this.initToolbars = function() {\r
119 var t = [[],[],[],[]];\r
120 var cur_toolbar = 0;\r
121 var cur_x = 0;\r
122 var button_width;\r
123\r
124 for (var i = 0; i < this.widget_config.buttons.length; i++) {\r
125 button_width = this.getButtonWidth(this.widget_config.buttons[i]);\r
126 if (cur_x + button_width > this.widget_config.toolbar_width) {\r
127 cur_x = button_width;\r
128 cur_toolbar++;\r
129 } else {\r
130 cur_x += button_width;\r
131 }\r
132 if (cur_toolbar <= 3) {\r
133 t[cur_toolbar].push (this.widget_config.buttons[i]);\r
134 }\r
135 }\r
136\r
137 this.toolbars = [t[0].join(','), t[1].join(','), t[2].join(','), t[3].join(',')];\r
138 };\r
139\r
140 this.getStyles = function() {\r
141 var h = {'Text': [], 'Selection': [], 'Tables': [], 'Lists': [], 'Print': []};\r
142 var styletype = "";\r
143\r
144 // Push title\r
145 h['Text'].push('{ title: "Text", tag: "", className: "-", type: "Text" }');\r
146 h['Selection'].push('{ title: "Selection", tag: "", className: "-", type: "Selection" }');\r
147 h['Tables'].push('{ title: "Tables", tag: "table", className: "-", type: "Tables" }');\r
148 h['Lists'].push('{ title: "Lists", tag: "ul", className: "-", type: "Lists" }');\r
149 h['Lists'].push('{ title: "Lists", tag: "ol", className: "-", type: "Lists" }');\r
150 h['Lists'].push('{ title: "Lists", tag: "dl", className: "-", type: "Lists" }');\r
151 h['Print'].push('{ title: "Print", tag: "", className: "-", type: "Print" }');\r
152\r
153 // Add defaults\r
154 h['Text'].push('{ title: "' + this.widget_config.labels['label_paragraph'] + '", tag: "p", className: "", type: "Text" }');\r
155 h['Selection'].push('{ title: "' + this.widget_config.labels['label_styles'] + '", tag: "", className: "", type: "Selection" }');\r
156 h['Tables'].push('{ title: "'+this.widget_config.labels['label_plain_cell'] +'", tag: "td", className: "", type: "Tables" }');\r
157 h['Lists'].push('{ title: "'+this.widget_config.labels['label_lists'] +'", tag: "dl", className: "", type: "Lists" }');\r
158\r
159 for (var i = 0; i < this.widget_config.styles.length; i++) {\r
160 e = this.widget_config.styles[i].split('|');\r
161 if (e.length <= 2) {\r
162 e[2] = "";\r
163 }\r
164 switch (e[1].toLowerCase()) {\r
165 case 'del':\r
166 case 'ins':\r
167 case 'span':\r
168 styletype = "Selection";\r
169 break;\r
170 case 'tr':\r
171 case 'td':\r
172 case 'th':\r
173 case 'table':\r
174 styletype = "Tables";\r
175 break;\r
176 case 'ul':\r
177 case 'ol':\r
178 case 'li':\r
179 case 'dt':\r
180 case 'dd':\r
181 case 'dl':\r
182 styletype = "Lists";\r
183 break;\r
184 default:\r
185 styletype = "Text";\r
186 break;\r
187 }\r
188 if (e[2] == "pageBreak") {\r
189 styletype = "Print";\r
190 }\r
191 h[styletype].push('{ title: "' + e[0] + '", tag: "' + e[1] + '", className: "' + e[2] + '", type: "' + styletype + '" }');\r
192 }\r
193\r
194 // Add items to array\r
195 var a = [];\r
196 if (h['Text'].length > 1) {\r
197 for (var i = 0; i < h['Text'].length; i++) {\r
198 a.push(h['Text'][i]);\r
199 }\r
200 }\r
201 if (h['Selection'].length > 1) {\r
202 for (var i = 0; i < h['Selection'].length; i++) {\r
203 a.push(h['Selection'][i]);\r
204 }\r
205 }\r
206 if (h['Tables'].length > 1) {\r
207 for (var i = 0; i < h['Tables'].length; i++) {\r
208 a.push(h['Tables'][i]);\r
209 }\r
210 }\r
211 if (h['Lists'].length > 1) {\r
212 for (var i = 0; i < h['Lists'].length; i++) {\r
213 a.push(h['Lists'][i]);\r
214 }\r
215 }\r
216 if (h['Print'].length > 1) {\r
217 for (var i = 0; i < h['Print'].length; i++) {\r
218 a.push(h['Print'][i]);\r
219 }\r
220 }\r
221 return '[' + a.join(',') + ']';\r
222 };\r
223\r
224 this.getValidInlineStyles = function() {\r
225 return this.widget_config.valid_inline_styles.join (',');\r
226 };\r
227\r
228 this.getValidElements = function() {\r
229 a = [];\r
230\r
231 for (var valid_element in this.widget_config.valid_elements) {\r
232 var s = valid_element;\r
233 if (this.widget_config.valid_elements[valid_element].length > 0) {\r
234 s += '[' + this.widget_config.valid_elements[valid_element].join ('|') + ']';\r
235 }\r
236 a.push (s);\r
237 }\r
238 return a.join (',');\r
239 };\r
240\r
241 this.getDocumentUrl = function() {\r
242 return this.widget_config.document_url;\r
243 };\r
244\r
245 this.getBase = function() {\r
246 return this.widget_config.parent;\r
247 };\r
248\r
249 this.getToolbarLocation = function () {\r
250 return this.widget_config.toolbar_location;\r
251 };\r
252\r
253 this.getPathLocation = function () {\r
254 return this.widget_config.path_location;\r
255 };\r
256\r
257 this.getResizing = function () {\r
258 return this.widget_config.resizing;\r
259 };\r
260\r
261 this.getResizingUseCookie = function () {\r
262 return this.widget_config.resizing_use_cookie;\r
263 };\r
264\r
265 this.getResizeHorizontal = function () {\r
266 return this.widget_config.resize_horizontal;\r
267 };\r
268\r
269 this.getEditorWidth = function () {\r
270 return this.widget_config.editor_width;\r
271 };\r
272\r
273 this.getEditorHeight = function () {\r
274 return this.widget_config.editor_height;\r
275 };\r
276\r
277 this.getDirectionality = function () {\r
278 return this.widget_config.directionality;\r
279 };\r
280\r
281 this.getEntityEncoding = function () {\r
282 return this.widget_config.entity_encoding;\r
283 };\r
284\r
285 this.getContentCSS = function () {\r
286 return this.widget_config.content_css;\r
287 };\r
288\r
289 this.getLanguage = function () {\r
290 return this.widget_config.language;\r
291 };\r
292\r
293 this.getLinkUsingUids = function () {\r
294 return this.widget_config.link_using_uids;\r
295 };\r
296\r
297 this.getAllowCaptionedImages = function () {\r
298 return this.widget_config.allow_captioned_images;\r
299 };\r
300\r
301 this.getRooted = function () {\r
302 return this.widget_config.rooted;\r
303 };\r
304\r
305 this.getPortalUrl = function () {\r
306 return this.widget_config.portal_url;\r
307 };\r
308\r
309 this.getNavigationRootUrl = function () {\r
310 return this.widget_config.navigation_root_url;\r
311 };\r
312\r
313 this.getLivesearch = function () {\r
314 return this.widget_config.livesearch;\r
315 };\r
316\r
317 this.getSpellchecker = function () {\r
318 var sp = this.widget_config.libraries_spellchecker_choice;\r
319 if ((sp != '') && (sp != 'browser')) {\r
320 return sp\r
321 }\r
322 else {\r
323 return\r
324 }\r
325 };\r
326\r
327 this.geckoSpellcheckEnabled = function () {\r
328 if (this.widget_config.libraries_spellchecker_choice == 'browser')\r
329 return true\r
330 else\r
331 return false\r
332 };\r
333\r
334 this.getPlugins = function () {\r
335 var plugins = "safari,pagebreak,table,save,advhr,emotions,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,inlinepopups,plonestyle,tabfocus,definitionlist,ploneinlinestyles";\r
336\r
337 var sp = this.getSpellchecker()\r
338 if (sp)\r
339 plugins += ',' + sp;\r
340\r
341 for (var i = 0; i < this.widget_config.customplugins.length; i++) {\r
342 if (this.widget_config.customplugins[i].indexOf('|') == -1) {\r
343 plugins += ',' + this.widget_config.customplugins[i];\r
344 } else {\r
345 plugins += ',' + this.widget_config.customplugins[i].split('|')[0];\r
346 }\r
347 }\r
348 if (this.widget_config.contextmenu) {\r
349 plugins += ',contextmenu';\r
350 }\r
351 if (this.widget_config.autoresize) {\r
352 plugins += ',autoresize';\r
353 }\r
354 return plugins;\r
355 }\r
356}\r
357\r
358if (typeof(kukit) != "undefined") {\r
359 kukit.actionsGlobalRegistry.register("init-tinymce", function(oper) {\r
360 var config = new TinyMCEConfig(oper.node.id);\r
361 delete InitializedTinyMCEInstances[oper.node.id]\r
362 config.init();\r
363 });\r
364\r
365 kukit.actionsGlobalRegistry.register("save-tinymce", function(oper) {\r
366 if(tinymce.EditorManager != undefined && tinymce.EditorManager.activeEditor != null){\r
367 tinymce.EditorManager.activeEditor.save();\r
368 }\r
369 });\r
370}\r