alecpl
2010-06-24 2011bef155aacdfa8461a4d5c2cd3988d946d135
commit | author | age
d9344f 1 /**
69d05c 2  * editor_template_src.js
d9344f 3  *
69d05c 4  * Copyright 2009, Moxiecode Systems AB
A 5  * Released under LGPL License.
6  *
7  * License: http://tinymce.moxiecode.com/license
8  * Contributing: http://tinymce.moxiecode.com/contributing
d9344f 9  */
S 10
29da64 11 (function(tinymce) {
d9344f 12     var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;
S 13
14     // Tell it to load theme specific language pack(s)
15     tinymce.ThemeManager.requireLangPack('advanced');
16
17     tinymce.create('tinymce.themes.AdvancedTheme', {
29da64 18         sizes : [8, 10, 12, 14, 18, 24, 36],
A 19
d9344f 20         // Control name lookup, format: title, command
S 21         controls : {
22             bold : ['bold_desc', 'Bold'],
23             italic : ['italic_desc', 'Italic'],
24             underline : ['underline_desc', 'Underline'],
25             strikethrough : ['striketrough_desc', 'Strikethrough'],
26             justifyleft : ['justifyleft_desc', 'JustifyLeft'],
27             justifycenter : ['justifycenter_desc', 'JustifyCenter'],
28             justifyright : ['justifyright_desc', 'JustifyRight'],
29             justifyfull : ['justifyfull_desc', 'JustifyFull'],
30             bullist : ['bullist_desc', 'InsertUnorderedList'],
31             numlist : ['numlist_desc', 'InsertOrderedList'],
32             outdent : ['outdent_desc', 'Outdent'],
33             indent : ['indent_desc', 'Indent'],
34             cut : ['cut_desc', 'Cut'],
35             copy : ['copy_desc', 'Copy'],
36             paste : ['paste_desc', 'Paste'],
37             undo : ['undo_desc', 'Undo'],
38             redo : ['redo_desc', 'Redo'],
39             link : ['link_desc', 'mceLink'],
40             unlink : ['unlink_desc', 'unlink'],
41             image : ['image_desc', 'mceImage'],
42             cleanup : ['cleanup_desc', 'mceCleanup'],
43             help : ['help_desc', 'mceHelp'],
44             code : ['code_desc', 'mceCodeEditor'],
45             hr : ['hr_desc', 'InsertHorizontalRule'],
46             removeformat : ['removeformat_desc', 'RemoveFormat'],
47             sub : ['sub_desc', 'subscript'],
48             sup : ['sup_desc', 'superscript'],
49             forecolor : ['forecolor_desc', 'ForeColor'],
50             forecolorpicker : ['forecolor_desc', 'mceForeColor'],
51             backcolor : ['backcolor_desc', 'HiliteColor'],
52             backcolorpicker : ['backcolor_desc', 'mceBackColor'],
53             charmap : ['charmap_desc', 'mceCharMap'],
54             visualaid : ['visualaid_desc', 'mceToggleVisualAid'],
55             anchor : ['anchor_desc', 'mceInsertAnchor'],
56             newdocument : ['newdocument_desc', 'mceNewDocument'],
57             blockquote : ['blockquote_desc', 'mceBlockQuote']
58         },
59
60         stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
61
62         init : function(ed, url) {
29da64 63             var t = this, s, v, o;
d9344f 64     
S 65             t.editor = ed;
66             t.url = url;
67             t.onResolveName = new tinymce.util.Dispatcher(this);
68
69             // Default settings
70             t.settings = s = extend({
71                 theme_advanced_path : true,
72                 theme_advanced_toolbar_location : 'bottom',
73                 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
74                 theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
75                 theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",
76                 theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
77                 theme_advanced_toolbar_align : "center",
78                 theme_advanced_fonts : "Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats",
79                 theme_advanced_more_colors : 1,
80                 theme_advanced_row_height : 23,
81                 theme_advanced_resize_horizontal : 1,
29da64 82                 theme_advanced_resizing_use_cookie : 1,
A 83                 theme_advanced_font_sizes : "1,2,3,4,5,6,7",
84                 readonly : ed.settings.readonly
d9344f 85             }, ed.settings);
29da64 86
A 87             // Setup default font_size_style_values
88             if (!s.font_size_style_values)
89                 s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt";
90
91             if (tinymce.is(s.theme_advanced_font_sizes, 'string')) {
92                 s.font_size_style_values = tinymce.explode(s.font_size_style_values);
93                 s.font_size_classes = tinymce.explode(s.font_size_classes || '');
94
95                 // Parse string value
96                 o = {};
97                 ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes;
98                 each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) {
99                     var cl;
100
101                     if (k == v && v >= 1 && v <= 7) {
102                         k = v + ' (' + t.sizes[v - 1] + 'pt)';
69d05c 103                         cl = s.font_size_classes[v - 1];
A 104                         v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt');
29da64 105                     }
A 106
107                     if (/^\s*\./.test(v))
108                         cl = v.replace(/\./g, '');
109
110                     o[k] = cl ? {'class' : cl} : {fontSize : v};
111                 });
112
113                 s.theme_advanced_font_sizes = o;
114             }
d9344f 115
S 116             if ((v = s.theme_advanced_path_location) && v != 'none')
117                 s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
118
119             if (s.theme_advanced_statusbar_location == 'none')
120                 s.theme_advanced_statusbar_location = 0;
121
122             // Init editor
123             ed.onInit.add(function() {
69d05c 124                 if (!ed.settings.readonly)
A 125                     ed.onNodeChange.add(t._nodeChanged, t);
d9344f 126
S 127                 if (ed.settings.content_css !== false)
128                     ed.dom.loadCSS(ed.baseURI.toAbsolute("themes/advanced/skins/" + ed.settings.skin + "/content.css"));
129             });
130
131             ed.onSetProgressState.add(function(ed, b, ti) {
132                 var co, id = ed.id, tb;
133
134                 if (b) {
135                     t.progressTimer = setTimeout(function() {
136                         co = ed.getContainer();
137                         co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild);
138                         tb = DOM.get(ed.id + '_tbl');
139
140                         DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}});
141                         DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}});
142                     }, ti || 0);
143                 } else {
144                     DOM.remove(id + '_blocker');
145                     DOM.remove(id + '_progress');
146                     clearTimeout(t.progressTimer);
147                 }
148             });
149
29da64 150             DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css");
d9344f 151
S 152             if (s.skin_variant)
29da64 153                 DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css");
d9344f 154         },
S 155
156         createControl : function(n, cf) {
157             var cd, c;
158
159             if (c = cf.createControl(n))
160                 return c;
161
162             switch (n) {
163                 case "styleselect":
164                     return this._createStyleSelect();
165
166                 case "formatselect":
167                     return this._createBlockFormats();
168
169                 case "fontselect":
170                     return this._createFontSelect();
171
172                 case "fontsizeselect":
173                     return this._createFontSizeSelect();
174
175                 case "forecolor":
176                     return this._createForeColorMenu();
177
178                 case "backcolor":
179                     return this._createBackColorMenu();
180             }
181
182             if ((cd = this.controls[n]))
183                 return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]});
184         },
185
186         execCommand : function(cmd, ui, val) {
187             var f = this['_' + cmd];
188
189             if (f) {
190                 f.call(this, ui, val);
191                 return true;
192             }
193
194             return false;
195         },
196
18240a 197         _importClasses : function(e) {
69d05c 198             var ed = this.editor, ctrl = ed.controlManager.get('styleselect');
d9344f 199
69d05c 200             if (ctrl.getLength() == 0) {
A 201                 each(ed.dom.getClasses(), function(o, idx) {
202                     var name = 'style_' + idx;
203
204                     ed.formatter.register(name, {
205                         inline : 'span',
2011be 206                         attributes : {'class' : o['class']},
69d05c 207                         selector : '*'
A 208                     });
209
210                     ctrl.add(o['class'], name);
d9344f 211                 });
S 212             }
213         },
214
215         _createStyleSelect : function(n) {
69d05c 216             var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl;
A 217
218             // Setup style select box
219             ctrl = ctrlMan.createListBox('styleselect', {
d9344f 220                 title : 'advanced.style_select',
69d05c 221                 onselect : function(name) {
2011be 222                     var matches, formatNames = [];
A 223
224                     each(ctrl.items, function(item) {
225                         formatNames.push(item.value);
226                     });
227
228                     ed.focus();
229                     ed.undoManager.add();
230
231                     // Toggle off the current format
232                     matches = ed.formatter.matchAll(formatNames);
233                     if (matches[0] == name)
234                         ed.formatter.remove(name);
235                     else
236                         ed.formatter.apply(name);
237
238                     ed.undoManager.add();
239                     ed.nodeChanged();
69d05c 240
A 241                     return false; // No auto select
d9344f 242                 }
S 243             });
244
69d05c 245             // Handle specified format
A 246             ed.onInit.add(function() {
247                 var counter = 0, formats = ed.getParam('style_formats');
d9344f 248
69d05c 249                 if (formats) {
A 250                     each(formats, function(fmt) {
251                         var name, keys = 0;
252
253                         each(fmt, function() {keys++;});
254
255                         if (keys > 1) {
256                             name = fmt.name = fmt.name || 'style_' + (counter++);
257                             ed.formatter.register(name, fmt);
258                             ctrl.add(fmt.title, name);
259                         } else
260                             ctrl.add(fmt.title);
261                     });
262                 } else {
263                     each(ed.getParam('theme_advanced_styles', '', 'hash'), function(val, key) {
264                         var name;
265
266                         if (val) {
267                             name = 'style_' + (counter++);
268
269                             ed.formatter.register(name, {
270                                 inline : 'span',
2011be 271                                 classes : val,
A 272                                 selector : '*'
69d05c 273                             });
A 274
275                             ctrl.add(t.editor.translate(key), name);
276                         }
277                     });
278                 }
279             });
280
281             // Auto import classes if the ctrl box is empty
282             if (ctrl.getLength() == 0) {
283                 ctrl.onPostRender.add(function(ed, n) {
284                     if (!ctrl.NativeListBox) {
29da64 285                         Event.add(n.id + '_text', 'focus', t._importClasses, t);
A 286                         Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
287                         Event.add(n.id + '_open', 'focus', t._importClasses, t);
288                         Event.add(n.id + '_open', 'mousedown', t._importClasses, t);
289                     } else
290                         Event.add(n.id, 'focus', t._importClasses, t);
d9344f 291                 });
S 292             }
293
69d05c 294             return ctrl;
d9344f 295         },
S 296
297         _createFontSelect : function() {
298             var c, t = this, ed = t.editor;
299
69d05c 300             c = ed.controlManager.createListBox('fontselect', {
A 301                 title : 'advanced.fontdefault',
302                 onselect : function(v) {
303                     ed.execCommand('FontName', false, v);
2011be 304
A 305                     // Fake selection, execCommand will fire a nodeChange and update the selection
306                     c.select(function(sv) {
307                         return v == sv;
308                     });
309
69d05c 310                     return false; // No auto select
A 311                 }
312             });
313
d9344f 314             if (c) {
S 315                 each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
316                     c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
317                 });
318             }
319
320             return c;
321         },
322
323         _createFontSizeSelect : function() {
29da64 324             var t = this, ed = t.editor, c, i = 0, cl = [];
d9344f 325
29da64 326             c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) {
2011be 327                 if (v['class']) {
A 328                     ed.focus();
329                     ed.undoManager.add();
330                     ed.formatter.toggle('fontsize_class', {value : v['class']});
331                     ed.undoManager.add();
332                     ed.nodeChanged();
333                 } else
29da64 334                     ed.execCommand('FontSize', false, v.fontSize);
A 335
2011be 336                 // Fake selection, execCommand will fire a nodeChange and update the selection
A 337                 c.select(function(sv) {
338                     return v == sv;
339                 });
69d05c 340
A 341                 return false; // No auto select
29da64 342             }});
A 343
d9344f 344             if (c) {
29da64 345                 each(t.settings.theme_advanced_font_sizes, function(v, k) {
A 346                     var fz = v.fontSize;
347
348                     if (fz >= 1 && fz <= 7)
349                         fz = t.sizes[parseInt(fz) - 1] + 'pt';
350
351                     c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))});
d9344f 352                 });
S 353             }
354
355             return c;
356         },
357
358         _createBlockFormats : function() {
359             var c, fmts = {
360                 p : 'advanced.paragraph',
361                 address : 'advanced.address',
362                 pre : 'advanced.pre',
363                 h1 : 'advanced.h1',
364                 h2 : 'advanced.h2',
365                 h3 : 'advanced.h3',
366                 h4 : 'advanced.h4',
367                 h5 : 'advanced.h5',
368                 h6 : 'advanced.h6',
369                 div : 'advanced.div',
370                 blockquote : 'advanced.blockquote',
371                 code : 'advanced.code',
372                 dt : 'advanced.dt',
373                 dd : 'advanced.dd',
374                 samp : 'advanced.samp'
375             }, t = this;
376
377             c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'});
378             if (c) {
379                 each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {
380                     c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});
381                 });
382             }
383
384             return c;
385         },
386
387         _createForeColorMenu : function() {
388             var c, t = this, s = t.settings, o = {}, v;
389
390             if (s.theme_advanced_more_colors) {
391                 o.more_colors_func = function() {
392                     t._mceColorPicker(0, {
393                         color : c.value,
394                         func : function(co) {
395                             c.setColor(co);
396                         }
397                     });
398                 };
399             }
400
401             if (v = s.theme_advanced_text_colors)
402                 o.colors = v;
403
29da64 404             if (s.theme_advanced_default_foreground_color)
A 405                 o.default_color = s.theme_advanced_default_foreground_color;
406
d9344f 407             o.title = 'advanced.forecolor_desc';
S 408             o.cmd = 'ForeColor';
409             o.scope = this;
410
411             c = t.editor.controlManager.createColorSplitButton('forecolor', o);
412
413             return c;
414         },
415
416         _createBackColorMenu : function() {
417             var c, t = this, s = t.settings, o = {}, v;
418
419             if (s.theme_advanced_more_colors) {
420                 o.more_colors_func = function() {
421                     t._mceColorPicker(0, {
422                         color : c.value,
423                         func : function(co) {
424                             c.setColor(co);
425                         }
426                     });
427                 };
428             }
429
430             if (v = s.theme_advanced_background_colors)
431                 o.colors = v;
29da64 432
A 433             if (s.theme_advanced_default_background_color)
434                 o.default_color = s.theme_advanced_default_background_color;
d9344f 435
S 436             o.title = 'advanced.backcolor_desc';
437             o.cmd = 'HiliteColor';
438             o.scope = this;
439
440             c = t.editor.controlManager.createColorSplitButton('backcolor', o);
441
442             return c;
443         },
444
445         renderUI : function(o) {
446             var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl;
447
448             n = p = DOM.create('span', {id : ed.id + '_parent', 'class' : 'mceEditor ' + ed.settings.skin + 'Skin' + (s.skin_variant ? ' ' + ed.settings.skin + 'Skin' + t._ufirst(s.skin_variant) : '')});
449
450             if (!DOM.boxModel)
451                 n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'});
452
453             n = sc = DOM.add(n, 'table', {id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0});
454             n = tb = DOM.add(n, 'tbody');
455
456             switch ((s.theme_advanced_layout_manager || '').toLowerCase()) {
457                 case "rowlayout":
458                     ic = t._rowLayout(s, tb, o);
459                     break;
460
461                 case "customlayout":
462                     ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p);
463                     break;
464
465                 default:
466                     ic = t._simpleLayout(s, tb, o, p);
467             }
468
469             n = o.targetNode;
470
471             // Add classes to first and last TRs
472             nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8
473             DOM.addClass(nl[0], 'mceFirst');
474             DOM.addClass(nl[nl.length - 1], 'mceLast');
475
476             // Add classes to first and last TDs
477             each(DOM.select('tr', tb), function(n) {
478                 DOM.addClass(n.firstChild, 'mceFirst');
479                 DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast');
480             });
481
482             if (DOM.get(s.theme_advanced_toolbar_container))
483                 DOM.get(s.theme_advanced_toolbar_container).appendChild(p);
484             else
485                 DOM.insertAfter(p, n);
486
487             Event.add(ed.id + '_path_row', 'click', function(e) {
488                 e = e.target;
489
490                 if (e.nodeName == 'A') {
491                     t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1'));
492
493                     return Event.cancel(e);
494                 }
495             });
496 /*
497             if (DOM.get(ed.id + '_path_row')) {
498                 Event.add(ed.id + '_tbl', 'mouseover', function(e) {
499                     var re;
500     
501                     e = e.target;
502
503                     if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) {
504                         re = DOM.get(ed.id + '_path_row');
505                         t.lastPath = re.innerHTML;
506                         DOM.setHTML(re, e.parentNode.title);
507                     }
508                 });
509
510                 Event.add(ed.id + '_tbl', 'mouseout', function(e) {
511                     if (t.lastPath) {
512                         DOM.setHTML(ed.id + '_path_row', t.lastPath);
513                         t.lastPath = 0;
514                     }
515                 });
516             }
517 */
518
29da64 519             if (!ed.getParam('accessibility_focus'))
d9344f 520                 Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();});
S 521
522             if (s.theme_advanced_toolbar_location == 'external')
523                 o.deltaHeight = 0;
524
525             t.deltaHeight = o.deltaHeight;
526             o.targetNode = null;
527
528             return {
529                 iframeContainer : ic,
530                 editorContainer : ed.id + '_parent',
531                 sizeContainer : sc,
532                 deltaHeight : o.deltaHeight
533             };
534         },
535
536         getInfo : function() {
537             return {
538                 longname : 'Advanced theme',
539                 author : 'Moxiecode Systems AB',
540                 authorurl : 'http://tinymce.moxiecode.com',
541                 version : tinymce.majorVersion + "." + tinymce.minorVersion
542             }
543         },
544
545         resizeBy : function(dw, dh) {
546             var e = DOM.get(this.editor.id + '_tbl');
547
548             this.resizeTo(e.clientWidth + dw, e.clientHeight + dh);
549         },
550
551         resizeTo : function(w, h) {
799907 552             var ed = this.editor, s = this.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr');
d9344f 553
S 554             // Boundery fix box
555             w = Math.max(s.theme_advanced_resizing_min_width || 100, w);
556             h = Math.max(s.theme_advanced_resizing_min_height || 100, h);
557             w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w);
558             h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h);
559
560             // Resize iframe and container
799907 561             DOM.setStyle(e, 'height', '');
A 562             DOM.setStyle(ifr, 'height', h);
563
564             if (s.theme_advanced_resize_horizontal) {
565                 DOM.setStyle(e, 'width', '');
566                 DOM.setStyle(ifr, 'width', w);
567
568                 // Make sure that the size is never smaller than the over all ui
569                 if (w < e.clientWidth)
570                     DOM.setStyle(ifr, 'width', e.clientWidth);
571             }
d9344f 572         },
S 573
574         destroy : function() {
575             var id = this.editor.id;
576
577             Event.clear(id + '_resize');
578             Event.clear(id + '_path_row');
579             Event.clear(id + '_external_close');
580         },
581
582         // Internal functions
583
584         _simpleLayout : function(s, tb, o, p) {
585             var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;
29da64 586
A 587             if (s.readonly) {
588                 n = DOM.add(tb, 'tr');
589                 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
590                 return ic;
591             }
d9344f 592
S 593             // Create toolbar container at top
594             if (lo == 'top')
595                 t._addToolbars(tb, o);
596
597             // Create external toolbar
598             if (lo == 'external') {
599                 n = c = DOM.create('div', {style : 'position:relative'});
600                 n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'});
601                 DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'});
602                 n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0});
603                 etb = DOM.add(n, 'tbody');
604
605                 if (p.firstChild.className == 'mceOldBoxModel')
606                     p.firstChild.appendChild(c);
607                 else
608                     p.insertBefore(c, p.firstChild);
609
610                 t._addToolbars(etb, o);
611
612                 ed.onMouseUp.add(function() {
613                     var e = DOM.get(ed.id + '_external');
614                     DOM.show(e);
615
616                     DOM.hide(lastExtID);
617
618                     var f = Event.add(ed.id + '_external_close', 'click', function() {
619                         DOM.hide(ed.id + '_external');
620                         Event.remove(ed.id + '_external_close', 'click', f);
621                     });
622
623                     DOM.show(e);
624                     DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1);
625
626                     // Fixes IE rendering bug
627                     DOM.hide(e);
628                     DOM.show(e);
629                     e.style.filter = '';
630
631                     lastExtID = ed.id + '_external';
632
633                     e = null;
634                 });
635             }
636
637             if (sl == 'top')
638                 t._addStatusBar(tb, o);
639
640             // Create iframe container
641             if (!s.theme_advanced_toolbar_container) {
642                 n = DOM.add(tb, 'tr');
643                 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
644             }
645
646             // Create toolbar container at bottom
647             if (lo == 'bottom')
648                 t._addToolbars(tb, o);
649
650             if (sl == 'bottom')
651                 t._addStatusBar(tb, o);
652
653             return ic;
654         },
655
656         _rowLayout : function(s, tb, o) {
657             var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
658
659             dc = s.theme_advanced_containers_default_class || '';
660             da = s.theme_advanced_containers_default_align || 'center';
661
662             each(explode(s.theme_advanced_containers || ''), function(c, i) {
663                 var v = s['theme_advanced_container_' + c] || '';
664
18240a 665                 switch (v.toLowerCase()) {
d9344f 666                     case 'mceeditor':
S 667                         n = DOM.add(tb, 'tr');
668                         n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
669                         break;
670
671                     case 'mceelementpath':
672                         t._addStatusBar(tb, o);
673                         break;
674
675                     default:
18240a 676                         a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();
d9344f 677                         a = 'mce' + t._ufirst(a);
S 678
679                         n = DOM.add(DOM.add(tb, 'tr'), 'td', {
680                             'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
681                         });
682
683                         to = cf.createToolbar("toolbar" + i);
684                         t._addControls(v, to);
685                         DOM.setHTML(n, to.renderHTML());
686                         o.deltaHeight -= s.theme_advanced_row_height;
687                 }
688             });
689
690             return ic;
691         },
692
693         _addControls : function(v, tb) {
694             var t = this, s = t.settings, di, cf = t.editor.controlManager;
695
696             if (s.theme_advanced_disable && !t._disabled) {
697                 di = {};
698
699                 each(explode(s.theme_advanced_disable), function(v) {
700                     di[v] = 1;
701                 });
702
703                 t._disabled = di;
704             } else
705                 di = t._disabled;
706
707             each(explode(v), function(n) {
708                 var c;
709
710                 if (di && di[n])
711                     return;
712
713                 // Compatiblity with 2.x
714                 if (n == 'tablecontrols') {
715                     each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) {
716                         n = t.createControl(n, cf);
717
718                         if (n)
719                             tb.add(n);
720                     });
721
722                     return;
723                 }
724
725                 c = t.createControl(n, cf);
726
727                 if (c)
728                     tb.add(c);
729             });
730         },
731
732         _addToolbars : function(c, o) {
733             var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a;
734
735             a = s.theme_advanced_toolbar_align.toLowerCase();
736             a = 'mce' + t._ufirst(a);
737
738             n = DOM.add(DOM.add(c, 'tr'), 'td', {'class' : 'mceToolbar ' + a});
739
29da64 740             if (!ed.getParam('accessibility_focus'))
d9344f 741                 h.push(DOM.createHTML('a', {href : '#', onfocus : 'tinyMCE.get(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
S 742
743             h.push(DOM.createHTML('a', {href : '#', accesskey : 'q', title : ed.getLang("advanced.toolbar_focus")}, '<!-- IE -->'));
744
745             // Create toolbar and add the controls
746             for (i=1; (v = s['theme_advanced_buttons' + i]); i++) {
747                 tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i});
748
749                 if (s['theme_advanced_buttons' + i + '_add'])
750                     v += ',' + s['theme_advanced_buttons' + i + '_add'];
751
752                 if (s['theme_advanced_buttons' + i + '_add_before'])
753                     v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v;
754
755                 t._addControls(v, tb);
756
757                 //n.appendChild(n = tb.render());
758                 h.push(tb.renderHTML());
759
760                 o.deltaHeight -= s.theme_advanced_row_height;
761             }
762
763             h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
764             DOM.setHTML(n, h.join(''));
765         },
766
767         _addStatusBar : function(tb, o) {
768             var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td;
769
770             n = DOM.add(tb, 'tr');
771             n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'});
29da64 772             n = DOM.add(n, 'div', {id : ed.id + '_path_row'}, s.theme_advanced_path ? ed.translate('advanced.path') + ': ' : '&#160;');
d9344f 773             DOM.add(n, 'a', {href : '#', accesskey : 'x'});
S 774
29da64 775             if (s.theme_advanced_resizing) {
d9344f 776                 DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize'});
S 777
778                 if (s.theme_advanced_resizing_use_cookie) {
779                     ed.onPostRender.add(function() {
780                         var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl');
781
782                         if (!o)
783                             return;
784
69d05c 785                         t.resizeTo(o.cw, o.ch);
d9344f 786                     });
S 787                 }
788
789                 ed.onPostRender.add(function() {
790                     Event.add(ed.id + '_resize', 'mousedown', function(e) {
799907 791                         var mouseMoveHandler1, mouseMoveHandler2,
A 792                             mouseUpHandler1, mouseUpHandler2,
69d05c 793                             startX, startY, startWidth, startHeight, width, height, ifrElm;
d9344f 794
69d05c 795                         function resizeOnMove(e) {
A 796                             width = startWidth + (e.screenX - startX);
797                             height = startHeight + (e.screenY - startY);
d9344f 798
69d05c 799                             t.resizeTo(width, height);
799907 800                         };
A 801
802                         function endResize(e) {
803                             // Stop listening
804                             Event.remove(DOM.doc, 'mousemove', mouseMoveHandler1);
805                             Event.remove(ed.getDoc(), 'mousemove', mouseMoveHandler2);
806                             Event.remove(DOM.doc, 'mouseup', mouseUpHandler1);
807                             Event.remove(ed.getDoc(), 'mouseup', mouseUpHandler2);
808
809                             // Store away the size
810                             if (s.theme_advanced_resizing_use_cookie) {
811                                 Cookie.setHash("TinyMCE_" + ed.id + "_size", {
812                                     cw : width,
813                                     ch : height
814                                 });
815                             }
d9344f 816                         };
S 817
69d05c 818                         e.preventDefault();
d9344f 819
69d05c 820                         // Get the current rect size
A 821                         startX = e.screenX;
822                         startY = e.screenY;
823                         ifrElm = DOM.get(t.editor.id + '_ifr');
824                         startWidth = width = ifrElm.clientWidth;
825                         startHeight = height = ifrElm.clientHeight;
d9344f 826
69d05c 827                         // Register envent handlers
A 828                         mouseMoveHandler1 = Event.add(DOM.doc, 'mousemove', resizeOnMove);
829                         mouseMoveHandler2 = Event.add(ed.getDoc(), 'mousemove', resizeOnMove);
799907 830                         mouseUpHandler1 = Event.add(DOM.doc, 'mouseup', endResize);
A 831                         mouseUpHandler2 = Event.add(ed.getDoc(), 'mouseup', endResize);
d9344f 832                     });
S 833                 });
834             }
835
836             o.deltaHeight -= 21;
837             n = tb = null;
838         },
839
69d05c 840         _nodeChanged : function(ed, cm, n, co, ob) {
799907 841             var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn, formatNames, matches;
d9344f 842
S 843             tinymce.each(t.stateControls, function(c) {
844                 cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
845             });
69d05c 846
A 847             function getParent(name) {
848                 var i, parents = ob.parents, func = name;
849
850                 if (typeof(name) == 'string') {
851                     func = function(node) {
852                         return node.nodeName == name;
853                     };
854                 }
855
856                 for (i = 0; i < parents.length; i++) {
857                     if (func(parents[i]))
858                         return parents[i];
859                 }
860             };
d9344f 861
S 862             cm.setActive('visualaid', ed.hasVisual);
863             cm.setDisabled('undo', !ed.undoManager.hasUndo() && !ed.typing);
864             cm.setDisabled('redo', !ed.undoManager.hasRedo());
865             cm.setDisabled('outdent', !ed.queryCommandState('Outdent'));
866
69d05c 867             p = getParent('A');
d9344f 868             if (c = cm.get('link')) {
S 869                 if (!p || !p.name) {
870                     c.setDisabled(!p && co);
871                     c.setActive(!!p);
872                 }
873             }
874
875             if (c = cm.get('unlink')) {
876                 c.setDisabled(!p && co);
877                 c.setActive(!!p && !p.name);
878             }
879
880             if (c = cm.get('anchor')) {
881                 c.setActive(!!p && p.name);
882             }
883
69d05c 884             p = getParent('IMG');
d9344f 885             if (c = cm.get('image'))
S 886                 c.setActive(!!p && n.className.indexOf('mceItem') == -1);
887
888             if (c = cm.get('styleselect')) {
69d05c 889                 t._importClasses();
A 890
799907 891                 formatNames = [];
A 892                 each(c.items, function(item) {
893                     formatNames.push(item.value);
69d05c 894                 });
799907 895
A 896                 matches = ed.formatter.matchAll(formatNames);
897                 c.select(matches[0]);
d9344f 898             }
S 899
900             if (c = cm.get('formatselect')) {
69d05c 901                 p = getParent(DOM.isBlock);
d9344f 902
S 903                 if (p)
904                     c.select(p.nodeName.toLowerCase());
905             }
906
69d05c 907             // Find out current fontSize, fontFamily and fontClass
A 908             getParent(function(n) {
909                 if (n.nodeName === 'SPAN') {
910                     if (!cl && n.className)
911                         cl = n.className;
d9344f 912
69d05c 913                     if (!fz && n.style.fontSize)
A 914                         fz = n.style.fontSize;
29da64 915
69d05c 916                     if (!fn && n.style.fontFamily)
A 917                         fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase();
918                 }
29da64 919
69d05c 920                 return false;
A 921             });
922
923             if (c = cm.get('fontselect')) {
924                 c.select(function(v) {
925                     return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn;
29da64 926                 });
69d05c 927             }
29da64 928
69d05c 929             // Select font size
A 930             if (c = cm.get('fontsizeselect')) {
931                 // Use computed style
932                 if (s.theme_advanced_runtime_fontsize && !fz && !cl)
933                     fz = ed.dom.getStyle(n, 'fontSize', true);
29da64 934
69d05c 935                 c.select(function(v) {
A 936                     if (v.fontSize && v.fontSize === fz)
937                         return true;
29da64 938
69d05c 939                     if (v['class'] && v['class'] === cl)
A 940                         return true;
941                 });
29da64 942             }
d9344f 943
S 944             if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
945                 p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
946                 DOM.setHTML(p, '');
947
69d05c 948                 getParent(function(n) {
d9344f 949                     var na = n.nodeName.toLowerCase(), u, pi, ti = '';
S 950
69d05c 951                     /*if (n.getAttribute('_mce_bogus'))
A 952                         return;
953 */
d9344f 954                     // Ignore non element and hidden elements
29da64 955                     if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))
d9344f 956                         return;
S 957
958                     // Fake name
959                     if (v = DOM.getAttrib(n, 'mce_name'))
960                         na = v;
29da64 961
d9344f 962                     // Handle prefix
S 963                     if (tinymce.isIE && n.scopeName !== 'HTML')
964                         na = n.scopeName + ':' + na;
965
966                     // Remove internal prefix
967                     na = na.replace(/mce\:/g, '');
968
969                     // Handle node name
970                     switch (na) {
971                         case 'b':
972                             na = 'strong';
973                             break;
974
975                         case 'i':
976                             na = 'em';
977                             break;
978
979                         case 'img':
980                             if (v = DOM.getAttrib(n, 'src'))
981                                 ti += 'src: ' + v + ' ';
982
983                             break;
984
985                         case 'a':
986                             if (v = DOM.getAttrib(n, 'name')) {
987                                 ti += 'name: ' + v + ' ';
988                                 na += '#' + v;
989                             }
990
991                             if (v = DOM.getAttrib(n, 'href'))
992                                 ti += 'href: ' + v + ' ';
993
994                             break;
995
996                         case 'font':
997                             if (v = DOM.getAttrib(n, 'face'))
998                                 ti += 'font: ' + v + ' ';
999
1000                             if (v = DOM.getAttrib(n, 'size'))
1001                                 ti += 'size: ' + v + ' ';
1002
1003                             if (v = DOM.getAttrib(n, 'color'))
1004                                 ti += 'color: ' + v + ' ';
1005
1006                             break;
1007
1008                         case 'span':
1009                             if (v = DOM.getAttrib(n, 'style'))
1010                                 ti += 'style: ' + v + ' ';
1011
1012                             break;
1013                     }
1014
1015                     if (v = DOM.getAttrib(n, 'id'))
1016                         ti += 'id: ' + v + ' ';
1017
1018                     if (v = n.className) {
69d05c 1019                         v = v.replace(/\b\s*(webkit|mce|Apple-)\w+\s*\b/g, '')
d9344f 1020
69d05c 1021                         if (v) {
d9344f 1022                             ti += 'class: ' + v + ' ';
S 1023
1024                             if (DOM.isBlock(n) || na == 'img' || na == 'span')
1025                                 na += '.' + v;
1026                         }
1027                     }
1028
1029                     na = na.replace(/(html:)/g, '');
1030                     na = {name : na, node : n, title : ti};
1031                     t.onResolveName.dispatch(t, na);
1032                     ti = na.title;
1033                     na = na.name;
1034
1035                     //u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
1036                     pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
1037
1038                     if (p.hasChildNodes()) {
1039                         p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild);
1040                         p.insertBefore(pi, p.firstChild);
1041                     } else
1042                         p.appendChild(pi);
1043                 }, ed.getBody());
1044             }
1045         },
1046
1047         // Commands gets called by execCommand
1048
1049         _sel : function(v) {
1050             this.editor.execCommand('mceSelectNodeDepth', false, v);
1051         },
1052
1053         _mceInsertAnchor : function(ui, v) {
1054             var ed = this.editor;
1055
1056             ed.windowManager.open({
1057                 url : tinymce.baseURL + '/themes/advanced/anchor.htm',
1058                 width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)),
1059                 height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)),
1060                 inline : true
1061             }, {
1062                 theme_url : this.url
1063             });
1064         },
1065
1066         _mceCharMap : function() {
1067             var ed = this.editor;
1068
1069             ed.windowManager.open({
1070                 url : tinymce.baseURL + '/themes/advanced/charmap.htm',
1071                 width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)),
1072                 height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)),
1073                 inline : true
1074             }, {
1075                 theme_url : this.url
1076             });
1077         },
1078
1079         _mceHelp : function() {
1080             var ed = this.editor;
1081
1082             ed.windowManager.open({
1083                 url : tinymce.baseURL + '/themes/advanced/about.htm',
1084                 width : 480,
1085                 height : 380,
1086                 inline : true
1087             }, {
1088                 theme_url : this.url
1089             });
1090         },
1091
1092         _mceColorPicker : function(u, v) {
1093             var ed = this.editor;
1094
1095             v = v || {};
1096
1097             ed.windowManager.open({
1098                 url : tinymce.baseURL + '/themes/advanced/color_picker.htm',
1099                 width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)),
1100                 height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)),
1101                 close_previous : false,
1102                 inline : true
1103             }, {
1104                 input_color : v.color,
1105                 func : v.func,
1106                 theme_url : this.url
1107             });
1108         },
1109
1110         _mceCodeEditor : function(ui, val) {
1111             var ed = this.editor;
1112
1113             ed.windowManager.open({
1114                 url : tinymce.baseURL + '/themes/advanced/source_editor.htm',
1115                 width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)),
1116                 height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)),
1117                 inline : true,
1118                 resizable : true,
1119                 maximizable : true
1120             }, {
1121                 theme_url : this.url
1122             });
1123         },
1124
1125         _mceImage : function(ui, val) {
1126             var ed = this.editor;
1127
1128             // Internal image object like a flash placeholder
1129             if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
1130                 return;
1131
1132             ed.windowManager.open({
1133                 url : tinymce.baseURL + '/themes/advanced/image.htm',
1134                 width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
1135                 height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
1136                 inline : true
1137             }, {
1138                 theme_url : this.url
1139             });
1140         },
1141
1142         _mceLink : function(ui, val) {
1143             var ed = this.editor;
1144
1145             ed.windowManager.open({
1146                 url : tinymce.baseURL + '/themes/advanced/link.htm',
1147                 width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)),
1148                 height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)),
1149                 inline : true
1150             }, {
1151                 theme_url : this.url
1152             });
1153         },
1154
1155         _mceNewDocument : function() {
1156             var ed = this.editor;
1157
1158             ed.windowManager.confirm('advanced.newdocument', function(s) {
1159                 if (s)
1160                     ed.execCommand('mceSetContent', false, '');
1161             });
1162         },
1163
1164         _mceForeColor : function() {
1165             var t = this;
1166
1167             this._mceColorPicker(0, {
18240a 1168                 color: t.fgColor,
d9344f 1169                 func : function(co) {
18240a 1170                     t.fgColor = co;
d9344f 1171                     t.editor.execCommand('ForeColor', false, co);
S 1172                 }
1173             });
1174         },
1175
1176         _mceBackColor : function() {
1177             var t = this;
1178
1179             this._mceColorPicker(0, {
18240a 1180                 color: t.bgColor,
d9344f 1181                 func : function(co) {
18240a 1182                     t.bgColor = co;
d9344f 1183                     t.editor.execCommand('HiliteColor', false, co);
S 1184                 }
1185             });
1186         },
1187
1188         _ufirst : function(s) {
1189             return s.substring(0, 1).toUpperCase() + s.substring(1);
1190         }
1191     });
1192
1193     tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme);
29da64 1194 }(tinymce));