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