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