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