2 * editor_template_src.js
4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;
14 // Tell it to load theme specific language pack(s)
15 tinymce.ThemeManager.requireLangPack('advanced');
17 tinymce.create('tinymce.themes.AdvancedTheme', {
18 sizes : [8, 10, 12, 14, 18, 24, 36],
20 // Control name lookup, format: title, command
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']
60 stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
62 init : function(ed, url) {
63 var t = this, s, v, o;
67 t.onResolveName = new tinymce.util.Dispatcher(this);
69 ed.forcedHighContrastMode = ed.settings.detect_highcontrast && t._isHighContrast();
70 ed.settings.skin = ed.forcedHighContrastMode ? 'highcontrast' : ed.settings.skin;
73 t.settings = s = extend({
74 theme_advanced_path : true,
75 theme_advanced_toolbar_location : 'bottom',
76 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
77 theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
78 theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",
79 theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
80 theme_advanced_toolbar_align : "center",
81 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",
82 theme_advanced_more_colors : 1,
83 theme_advanced_row_height : 23,
84 theme_advanced_resize_horizontal : 1,
85 theme_advanced_resizing_use_cookie : 1,
86 theme_advanced_font_sizes : "1,2,3,4,5,6,7",
87 theme_advanced_font_selector : "span",
88 theme_advanced_show_current_color: 0,
89 readonly : ed.settings.readonly
92 // Setup default font_size_style_values
93 if (!s.font_size_style_values)
94 s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt";
96 if (tinymce.is(s.theme_advanced_font_sizes, 'string')) {
97 s.font_size_style_values = tinymce.explode(s.font_size_style_values);
98 s.font_size_classes = tinymce.explode(s.font_size_classes || '');
100 // Parse string value
102 ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes;
103 each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) {
106 if (k == v && v >= 1 && v <= 7) {
107 k = v + ' (' + t.sizes[v - 1] + 'pt)';
108 cl = s.font_size_classes[v - 1];
109 v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt');
112 if (/^\s*\./.test(v))
113 cl = v.replace(/\./g, '');
115 o[k] = cl ? {'class' : cl} : {fontSize : v};
118 s.theme_advanced_font_sizes = o;
121 if ((v = s.theme_advanced_path_location) && v != 'none')
122 s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
124 if (s.theme_advanced_statusbar_location == 'none')
125 s.theme_advanced_statusbar_location = 0;
127 if (ed.settings.content_css !== false)
128 ed.contentCSS.push(ed.baseURI.toAbsolute(url + "/skins/" + ed.settings.skin + "/content.css"));
131 ed.onInit.add(function() {
132 if (!ed.settings.readonly) {
133 ed.onNodeChange.add(t._nodeChanged, t);
134 ed.onKeyUp.add(t._updateUndoStatus, t);
135 ed.onMouseUp.add(t._updateUndoStatus, t);
136 ed.dom.bind(ed.dom.getRoot(), 'dragend', function() {
137 t._updateUndoStatus(ed);
142 ed.onSetProgressState.add(function(ed, b, ti) {
143 var co, id = ed.id, tb;
146 t.progressTimer = setTimeout(function() {
147 co = ed.getContainer();
148 co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild);
149 tb = DOM.get(ed.id + '_tbl');
151 DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}});
152 DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}});
155 DOM.remove(id + '_blocker');
156 DOM.remove(id + '_progress');
157 clearTimeout(t.progressTimer);
161 DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css");
164 DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css");
167 _isHighContrast : function() {
168 var actualColor, div = DOM.add(DOM.getRoot(), 'div', {'style': 'background-color: rgb(171,239,86);'});
170 actualColor = (DOM.getStyle(div, 'background-color', true) + '').toLowerCase().replace(/ /g, '');
173 return actualColor != 'rgb(171,239,86)' && actualColor != '#abef56';
176 createControl : function(n, cf) {
179 if (c = cf.createControl(n))
184 return this._createStyleSelect();
187 return this._createBlockFormats();
190 return this._createFontSelect();
192 case "fontsizeselect":
193 return this._createFontSizeSelect();
196 return this._createForeColorMenu();
199 return this._createBackColorMenu();
202 if ((cd = this.controls[n]))
203 return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]});
206 execCommand : function(cmd, ui, val) {
207 var f = this['_' + cmd];
210 f.call(this, ui, val);
217 _importClasses : function(e) {
218 var ed = this.editor, ctrl = ed.controlManager.get('styleselect');
220 if (ctrl.getLength() == 0) {
221 each(ed.dom.getClasses(), function(o, idx) {
222 var name = 'style_' + idx;
224 ed.formatter.register(name, {
226 attributes : {'class' : o['class']},
230 ctrl.add(o['class'], name);
235 _createStyleSelect : function(n) {
236 var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl;
238 // Setup style select box
239 ctrl = ctrlMan.createListBox('styleselect', {
240 title : 'advanced.style_select',
241 onselect : function(name) {
242 var matches, formatNames = [];
244 each(ctrl.items, function(item) {
245 formatNames.push(item.value);
249 ed.undoManager.add();
251 // Toggle off the current format
252 matches = ed.formatter.matchAll(formatNames);
253 if (!name || matches[0] == name) {
255 ed.formatter.remove(matches[0]);
257 ed.formatter.apply(name);
259 ed.undoManager.add();
262 return false; // No auto select
266 // Handle specified format
267 ed.onInit.add(function() {
268 var counter = 0, formats = ed.getParam('style_formats');
271 each(formats, function(fmt) {
274 each(fmt, function() {keys++;});
277 name = fmt.name = fmt.name || 'style_' + (counter++);
278 ed.formatter.register(name, fmt);
279 ctrl.add(fmt.title, name);
284 each(ed.getParam('theme_advanced_styles', '', 'hash'), function(val, key) {
288 name = 'style_' + (counter++);
290 ed.formatter.register(name, {
296 ctrl.add(t.editor.translate(key), name);
302 // Auto import classes if the ctrl box is empty
303 if (ctrl.getLength() == 0) {
304 ctrl.onPostRender.add(function(ed, n) {
305 if (!ctrl.NativeListBox) {
306 Event.add(n.id + '_text', 'focus', t._importClasses, t);
307 Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
308 Event.add(n.id + '_open', 'focus', t._importClasses, t);
309 Event.add(n.id + '_open', 'mousedown', t._importClasses, t);
311 Event.add(n.id, 'focus', t._importClasses, t);
318 _createFontSelect : function() {
319 var c, t = this, ed = t.editor;
321 c = ed.controlManager.createListBox('fontselect', {
322 title : 'advanced.fontdefault',
323 onselect : function(v) {
324 var cur = c.items[c.selectedIndex];
327 ed.execCommand('FontName', false, cur.value);
331 ed.execCommand('FontName', false, v);
333 // Fake selection, execCommand will fire a nodeChange and update the selection
334 c.select(function(sv) {
338 if (cur && cur.value == v) {
342 return false; // No auto select
347 each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
348 c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
355 _createFontSizeSelect : function() {
356 var t = this, ed = t.editor, c, i = 0, cl = [];
358 c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) {
359 var cur = c.items[c.selectedIndex];
365 ed.formatter.toggle('fontsize_class', {value : cur['class']});
366 ed.undoManager.add();
369 ed.execCommand('FontSize', false, cur.fontSize);
377 ed.undoManager.add();
378 ed.formatter.toggle('fontsize_class', {value : v['class']});
379 ed.undoManager.add();
382 ed.execCommand('FontSize', false, v.fontSize);
384 // Fake selection, execCommand will fire a nodeChange and update the selection
385 c.select(function(sv) {
389 if (cur && (cur.value.fontSize == v.fontSize || cur.value['class'] && cur.value['class'] == v['class'])) {
393 return false; // No auto select
397 each(t.settings.theme_advanced_font_sizes, function(v, k) {
400 if (fz >= 1 && fz <= 7)
401 fz = t.sizes[parseInt(fz) - 1] + 'pt';
403 c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))});
410 _createBlockFormats : function() {
412 p : 'advanced.paragraph',
413 address : 'advanced.address',
414 pre : 'advanced.pre',
421 div : 'advanced.div',
422 blockquote : 'advanced.blockquote',
423 code : 'advanced.code',
426 samp : 'advanced.samp'
429 c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', onselect : function(v) {
430 t.editor.execCommand('FormatBlock', false, v);
435 each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {
436 c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});
443 _createForeColorMenu : function() {
444 var c, t = this, s = t.settings, o = {}, v;
446 if (s.theme_advanced_more_colors) {
447 o.more_colors_func = function() {
448 t._mceColorPicker(0, {
450 func : function(co) {
457 if (v = s.theme_advanced_text_colors)
460 if (s.theme_advanced_default_foreground_color)
461 o.default_color = s.theme_advanced_default_foreground_color;
463 o.title = 'advanced.forecolor_desc';
467 c = t.editor.controlManager.createColorSplitButton('forecolor', o);
472 _createBackColorMenu : function() {
473 var c, t = this, s = t.settings, o = {}, v;
475 if (s.theme_advanced_more_colors) {
476 o.more_colors_func = function() {
477 t._mceColorPicker(0, {
479 func : function(co) {
486 if (v = s.theme_advanced_background_colors)
489 if (s.theme_advanced_default_background_color)
490 o.default_color = s.theme_advanced_default_background_color;
492 o.title = 'advanced.backcolor_desc';
493 o.cmd = 'HiliteColor';
496 c = t.editor.controlManager.createColorSplitButton('backcolor', o);
501 renderUI : function(o) {
502 var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl;
505 ed.settings.aria_label = s.aria_label + ed.getLang('advanced.help_shortcut');
508 // TODO: ACC Should have an aria-describedby attribute which is user-configurable to describe what this field is actually for.
509 // Maybe actually inherit it from the original textara?
510 n = p = DOM.create('span', {role : 'application', 'aria-labelledby' : ed.id + '_voice', id : ed.id + '_parent', 'class' : 'mceEditor ' + ed.settings.skin + 'Skin' + (s.skin_variant ? ' ' + ed.settings.skin + 'Skin' + t._ufirst(s.skin_variant) : '')});
511 DOM.add(n, 'span', {'class': 'mceVoiceLabel', 'style': 'display:none;', id: ed.id + '_voice'}, s.aria_label);
514 n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'});
516 n = sc = DOM.add(n, 'table', {role : "presentation", id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0});
517 n = tb = DOM.add(n, 'tbody');
519 switch ((s.theme_advanced_layout_manager || '').toLowerCase()) {
521 ic = t._rowLayout(s, tb, o);
525 ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p);
529 ic = t._simpleLayout(s, tb, o, p);
534 // Add classes to first and last TRs
536 DOM.addClass(nl[0], 'mceFirst');
537 DOM.addClass(nl[nl.length - 1], 'mceLast');
539 // Add classes to first and last TDs
540 each(DOM.select('tr', tb), function(n) {
541 DOM.addClass(n.firstChild, 'mceFirst');
542 DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast');
545 if (DOM.get(s.theme_advanced_toolbar_container))
546 DOM.get(s.theme_advanced_toolbar_container).appendChild(p);
548 DOM.insertAfter(p, n);
550 Event.add(ed.id + '_path_row', 'click', function(e) {
553 if (e.nodeName == 'A') {
554 t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1'));
556 return Event.cancel(e);
560 if (DOM.get(ed.id + '_path_row')) {
561 Event.add(ed.id + '_tbl', 'mouseover', function(e) {
566 if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) {
567 re = DOM.get(ed.id + '_path_row');
568 t.lastPath = re.innerHTML;
569 DOM.setHTML(re, e.parentNode.title);
573 Event.add(ed.id + '_tbl', 'mouseout', function(e) {
575 DOM.setHTML(ed.id + '_path_row', t.lastPath);
582 if (!ed.getParam('accessibility_focus'))
583 Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();});
585 if (s.theme_advanced_toolbar_location == 'external')
588 t.deltaHeight = o.deltaHeight;
591 ed.onKeyDown.add(function(ed, evt) {
592 var DOM_VK_F10 = 121, DOM_VK_F11 = 122;
595 if (evt.keyCode === DOM_VK_F10) {
596 // Make sure focus is given to toolbar in Safari.
597 // We can't do this in IE as it prevents giving focus to toolbar when editor is in a frame
598 if (tinymce.isWebKit) {
601 t.toolbarGroup.focus();
602 return Event.cancel(evt);
603 } else if (evt.keyCode === DOM_VK_F11) {
604 DOM.get(ed.id + '_path_row').focus();
605 return Event.cancel(evt);
610 // alt+0 is the UK recommended shortcut for accessing the list of access controls.
611 ed.addShortcut('alt+0', '', 'mceShortcuts', t);
614 iframeContainer : ic,
615 editorContainer : ed.id + '_parent',
617 deltaHeight : o.deltaHeight
621 getInfo : function() {
623 longname : 'Advanced theme',
624 author : 'Moxiecode Systems AB',
625 authorurl : 'http://tinymce.moxiecode.com',
626 version : tinymce.majorVersion + "." + tinymce.minorVersion
630 resizeBy : function(dw, dh) {
631 var e = DOM.get(this.editor.id + '_ifr');
633 this.resizeTo(e.clientWidth + dw, e.clientHeight + dh);
636 resizeTo : function(w, h, store) {
637 var ed = this.editor, s = this.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr');
640 w = Math.max(s.theme_advanced_resizing_min_width || 100, w);
641 h = Math.max(s.theme_advanced_resizing_min_height || 100, h);
642 w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w);
643 h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h);
645 // Resize iframe and container
646 DOM.setStyle(e, 'height', '');
647 DOM.setStyle(ifr, 'height', h);
649 if (s.theme_advanced_resize_horizontal) {
650 DOM.setStyle(e, 'width', '');
651 DOM.setStyle(ifr, 'width', w);
653 // Make sure that the size is never smaller than the over all ui
654 if (w < e.clientWidth) {
656 DOM.setStyle(ifr, 'width', e.clientWidth);
660 // Store away the size
661 if (store && s.theme_advanced_resizing_use_cookie) {
662 Cookie.setHash("TinyMCE_" + ed.id + "_size", {
669 destroy : function() {
670 var id = this.editor.id;
672 Event.clear(id + '_resize');
673 Event.clear(id + '_path_row');
674 Event.clear(id + '_external_close');
677 // Internal functions
679 _simpleLayout : function(s, tb, o, p) {
680 var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;
683 n = DOM.add(tb, 'tr');
684 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
688 // Create toolbar container at top
690 t._addToolbars(tb, o);
692 // Create external toolbar
693 if (lo == 'external') {
694 n = c = DOM.create('div', {style : 'position:relative'});
695 n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'});
696 DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'});
697 n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0});
698 etb = DOM.add(n, 'tbody');
700 if (p.firstChild.className == 'mceOldBoxModel')
701 p.firstChild.appendChild(c);
703 p.insertBefore(c, p.firstChild);
705 t._addToolbars(etb, o);
707 ed.onMouseUp.add(function() {
708 var e = DOM.get(ed.id + '_external');
713 var f = Event.add(ed.id + '_external_close', 'click', function() {
714 DOM.hide(ed.id + '_external');
715 Event.remove(ed.id + '_external_close', 'click', f);
719 DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1);
721 // Fixes IE rendering bug
726 lastExtID = ed.id + '_external';
733 t._addStatusBar(tb, o);
735 // Create iframe container
736 if (!s.theme_advanced_toolbar_container) {
737 n = DOM.add(tb, 'tr');
738 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
741 // Create toolbar container at bottom
743 t._addToolbars(tb, o);
746 t._addStatusBar(tb, o);
751 _rowLayout : function(s, tb, o) {
752 var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
754 dc = s.theme_advanced_containers_default_class || '';
755 da = s.theme_advanced_containers_default_align || 'center';
757 each(explode(s.theme_advanced_containers || ''), function(c, i) {
758 var v = s['theme_advanced_container_' + c] || '';
760 switch (c.toLowerCase()) {
762 n = DOM.add(tb, 'tr');
763 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
766 case 'mceelementpath':
767 t._addStatusBar(tb, o);
771 a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();
772 a = 'mce' + t._ufirst(a);
774 n = DOM.add(DOM.add(tb, 'tr'), 'td', {
775 'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
778 to = cf.createToolbar("toolbar" + i);
779 t._addControls(v, to);
780 DOM.setHTML(n, to.renderHTML());
781 o.deltaHeight -= s.theme_advanced_row_height;
788 _addControls : function(v, tb) {
789 var t = this, s = t.settings, di, cf = t.editor.controlManager;
791 if (s.theme_advanced_disable && !t._disabled) {
794 each(explode(s.theme_advanced_disable), function(v) {
802 each(explode(v), function(n) {
808 // Compatiblity with 2.x
809 if (n == 'tablecontrols') {
810 each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) {
811 n = t.createControl(n, cf);
820 c = t.createControl(n, cf);
827 _addToolbars : function(c, o) {
828 var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a, toolbarGroup;
830 toolbarGroup = cf.createToolbarGroup('toolbargroup', {
831 'name': ed.getLang('advanced.toolbar'),
832 'tab_focus_toolbar':ed.getParam('theme_advanced_tab_focus_toolbar')
835 t.toolbarGroup = toolbarGroup;
837 a = s.theme_advanced_toolbar_align.toLowerCase();
838 a = 'mce' + t._ufirst(a);
840 n = DOM.add(DOM.add(c, 'tr', {role: 'presentation'}), 'td', {'class' : 'mceToolbar ' + a, "role":"presentation"});
842 // Create toolbar and add the controls
843 for (i=1; (v = s['theme_advanced_buttons' + i]); i++) {
844 tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i});
846 if (s['theme_advanced_buttons' + i + '_add'])
847 v += ',' + s['theme_advanced_buttons' + i + '_add'];
849 if (s['theme_advanced_buttons' + i + '_add_before'])
850 v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v;
852 t._addControls(v, tb);
853 toolbarGroup.add(tb);
855 o.deltaHeight -= s.theme_advanced_row_height;
857 h.push(toolbarGroup.renderHTML());
858 h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
859 DOM.setHTML(n, h.join(''));
862 _addStatusBar : function(tb, o) {
863 var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td;
865 n = DOM.add(tb, 'tr');
866 n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'});
867 n = DOM.add(n, 'div', {id : ed.id + '_path_row', 'role': 'group', 'aria-labelledby': ed.id + '_path_voice'});
868 if (s.theme_advanced_path) {
869 DOM.add(n, 'span', {id: ed.id + '_path_voice'}, ed.translate('advanced.path'));
870 DOM.add(n, 'span', {}, ': ');
872 DOM.add(n, 'span', {}, ' ');
876 if (s.theme_advanced_resizing) {
877 DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize', tabIndex:"-1"});
879 if (s.theme_advanced_resizing_use_cookie) {
880 ed.onPostRender.add(function() {
881 var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl');
886 t.resizeTo(o.cw, o.ch);
890 ed.onPostRender.add(function() {
891 Event.add(ed.id + '_resize', 'click', function(e) {
895 Event.add(ed.id + '_resize', 'mousedown', function(e) {
896 var mouseMoveHandler1, mouseMoveHandler2,
897 mouseUpHandler1, mouseUpHandler2,
898 startX, startY, startWidth, startHeight, width, height, ifrElm;
900 function resizeOnMove(e) {
903 width = startWidth + (e.screenX - startX);
904 height = startHeight + (e.screenY - startY);
906 t.resizeTo(width, height);
909 function endResize(e) {
911 Event.remove(DOM.doc, 'mousemove', mouseMoveHandler1);
912 Event.remove(ed.getDoc(), 'mousemove', mouseMoveHandler2);
913 Event.remove(DOM.doc, 'mouseup', mouseUpHandler1);
914 Event.remove(ed.getDoc(), 'mouseup', mouseUpHandler2);
916 width = startWidth + (e.screenX - startX);
917 height = startHeight + (e.screenY - startY);
918 t.resizeTo(width, height, true);
923 // Get the current rect size
926 ifrElm = DOM.get(t.editor.id + '_ifr');
927 startWidth = width = ifrElm.clientWidth;
928 startHeight = height = ifrElm.clientHeight;
930 // Register envent handlers
931 mouseMoveHandler1 = Event.add(DOM.doc, 'mousemove', resizeOnMove);
932 mouseMoveHandler2 = Event.add(ed.getDoc(), 'mousemove', resizeOnMove);
933 mouseUpHandler1 = Event.add(DOM.doc, 'mouseup', endResize);
934 mouseUpHandler2 = Event.add(ed.getDoc(), 'mouseup', endResize);
943 _updateUndoStatus : function(ed) {
944 var cm = ed.controlManager, um = ed.undoManager;
946 cm.setDisabled('undo', !um.hasUndo() && !um.typing);
947 cm.setDisabled('redo', !um.hasRedo());
950 _nodeChanged : function(ed, cm, n, co, ob) {
951 var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn, fc, bc, formatNames, matches;
953 tinymce.each(t.stateControls, function(c) {
954 cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
957 function getParent(name) {
958 var i, parents = ob.parents, func = name;
960 if (typeof(name) == 'string') {
961 func = function(node) {
962 return node.nodeName == name;
966 for (i = 0; i < parents.length; i++) {
967 if (func(parents[i]))
972 cm.setActive('visualaid', ed.hasVisual);
973 t._updateUndoStatus(ed);
974 cm.setDisabled('outdent', !ed.queryCommandState('Outdent'));
977 if (c = cm.get('link')) {
979 c.setDisabled(!p && co);
984 if (c = cm.get('unlink')) {
985 c.setDisabled(!p && co);
986 c.setActive(!!p && !p.name);
989 if (c = cm.get('anchor')) {
990 c.setActive(!co && !!p && p.name);
993 p = getParent('IMG');
994 if (c = cm.get('image'))
995 c.setActive(!co && !!p && n.className.indexOf('mceItem') == -1);
997 if (c = cm.get('styleselect')) {
1001 each(c.items, function(item) {
1002 formatNames.push(item.value);
1005 matches = ed.formatter.matchAll(formatNames);
1006 c.select(matches[0]);
1009 if (c = cm.get('formatselect')) {
1010 p = getParent(DOM.isBlock);
1013 c.select(p.nodeName.toLowerCase());
1016 // Find out current fontSize, fontFamily and fontClass
1017 getParent(function(n) {
1018 if (n.nodeName === 'SPAN') {
1019 if (!cl && n.className)
1023 if (ed.dom.is(n, s.theme_advanced_font_selector)) {
1024 if (!fz && n.style.fontSize)
1025 fz = n.style.fontSize;
1027 if (!fn && n.style.fontFamily)
1028 fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase();
1030 if (!fc && n.style.color)
1033 if (!bc && n.style.backgroundColor)
1034 bc = n.style.backgroundColor;
1040 if (c = cm.get('fontselect')) {
1041 c.select(function(v) {
1042 return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn;
1047 if (c = cm.get('fontsizeselect')) {
1048 // Use computed style
1049 if (s.theme_advanced_runtime_fontsize && !fz && !cl)
1050 fz = ed.dom.getStyle(n, 'fontSize', true);
1052 c.select(function(v) {
1053 if (v.fontSize && v.fontSize === fz)
1056 if (v['class'] && v['class'] === cl)
1061 if (s.theme_advanced_show_current_color) {
1062 function updateColor(controlId, color) {
1063 if (c = cm.get(controlId)) {
1065 color = c.settings.default_color;
1066 if (color !== c.value) {
1067 c.displayColor(color);
1071 updateColor('forecolor', fc);
1072 updateColor('backcolor', bc);
1075 if (s.theme_advanced_show_current_color) {
1076 function updateColor(controlId, color) {
1077 if (c = cm.get(controlId)) {
1079 color = c.settings.default_color;
1080 if (color !== c.value) {
1081 c.displayColor(color);
1086 updateColor('forecolor', fc);
1087 updateColor('backcolor', bc);
1090 if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
1091 p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
1093 if (t.statusKeyboardNavigation) {
1094 t.statusKeyboardNavigation.destroy();
1095 t.statusKeyboardNavigation = null;
1100 getParent(function(n) {
1101 var na = n.nodeName.toLowerCase(), u, pi, ti = '';
1103 // Ignore non element and bogus/hidden elements
1104 if (n.nodeType != 1 || na === 'br' || n.getAttribute('data-mce-bogus') || DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved'))
1108 if (tinymce.isIE && n.scopeName !== 'HTML')
1109 na = n.scopeName + ':' + na;
1111 // Remove internal prefix
1112 na = na.replace(/mce\:/g, '');
1125 if (v = DOM.getAttrib(n, 'src'))
1126 ti += 'src: ' + v + ' ';
1131 if (v = DOM.getAttrib(n, 'name')) {
1132 ti += 'name: ' + v + ' ';
1136 if (v = DOM.getAttrib(n, 'href'))
1137 ti += 'href: ' + v + ' ';
1142 if (v = DOM.getAttrib(n, 'face'))
1143 ti += 'font: ' + v + ' ';
1145 if (v = DOM.getAttrib(n, 'size'))
1146 ti += 'size: ' + v + ' ';
1148 if (v = DOM.getAttrib(n, 'color'))
1149 ti += 'color: ' + v + ' ';
1154 if (v = DOM.getAttrib(n, 'style'))
1155 ti += 'style: ' + v + ' ';
1160 if (v = DOM.getAttrib(n, 'id'))
1161 ti += 'id: ' + v + ' ';
1163 if (v = n.className) {
1164 v = v.replace(/\b\s*(webkit|mce|Apple-)\w+\s*\b/g, '')
1167 ti += 'class: ' + v + ' ';
1169 if (DOM.isBlock(n) || na == 'img' || na == 'span')
1174 na = na.replace(/(html:)/g, '');
1175 na = {name : na, node : n, title : ti};
1176 t.onResolveName.dispatch(t, na);
1180 //u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
1181 pi = DOM.create('a', {'href' : "javascript:;", role: 'button', onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
1183 if (p.hasChildNodes()) {
1184 p.insertBefore(DOM.create('span', {'aria-hidden': 'true'}, '\u00a0\u00bb '), p.firstChild);
1185 p.insertBefore(pi, p.firstChild);
1190 if (DOM.select('a', p).length > 0) {
1191 t.statusKeyboardNavigation = new tinymce.ui.KeyboardNavigation({
1192 root: ed.id + "_path_row",
1193 items: DOM.select('a', p),
1194 excludeFromTabOrder: true,
1195 onCancel: function() {
1203 // Commands gets called by execCommand
1205 _sel : function(v) {
1206 this.editor.execCommand('mceSelectNodeDepth', false, v);
1209 _mceInsertAnchor : function(ui, v) {
1210 var ed = this.editor;
1212 ed.windowManager.open({
1213 url : this.url + '/anchor.htm',
1214 width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)),
1215 height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)),
1218 theme_url : this.url
1222 _mceCharMap : function() {
1223 var ed = this.editor;
1225 ed.windowManager.open({
1226 url : this.url + '/charmap.htm',
1227 width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)),
1228 height : 265 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)),
1231 theme_url : this.url
1235 _mceHelp : function() {
1236 var ed = this.editor;
1238 ed.windowManager.open({
1239 url : this.url + '/about.htm',
1244 theme_url : this.url
1248 _mceShortcuts : function() {
1249 var ed = this.editor;
1250 ed.windowManager.open({
1251 url: this.url + '/shortcuts.htm',
1260 _mceColorPicker : function(u, v) {
1261 var ed = this.editor;
1265 ed.windowManager.open({
1266 url : this.url + '/color_picker.htm',
1267 width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)),
1268 height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)),
1269 close_previous : false,
1272 input_color : v.color,
1274 theme_url : this.url
1278 _mceCodeEditor : function(ui, val) {
1279 var ed = this.editor;
1281 ed.windowManager.open({
1282 url : this.url + '/source_editor.htm',
1283 width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)),
1284 height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)),
1289 theme_url : this.url
1293 _mceImage : function(ui, val) {
1294 var ed = this.editor;
1296 // Internal image object like a flash placeholder
1297 if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
1300 ed.windowManager.open({
1301 url : this.url + '/image.htm',
1302 width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
1303 height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
1306 theme_url : this.url
1310 _mceLink : function(ui, val) {
1311 var ed = this.editor;
1313 ed.windowManager.open({
1314 url : this.url + '/link.htm',
1315 width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)),
1316 height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)),
1319 theme_url : this.url
1323 _mceNewDocument : function() {
1324 var ed = this.editor;
1326 ed.windowManager.confirm('advanced.newdocument', function(s) {
1328 ed.execCommand('mceSetContent', false, '');
1332 _mceForeColor : function() {
1335 this._mceColorPicker(0, {
1337 func : function(co) {
1339 t.editor.execCommand('ForeColor', false, co);
1344 _mceBackColor : function() {
1347 this._mceColorPicker(0, {
1349 func : function(co) {
1351 t.editor.execCommand('HiliteColor', false, co);
1356 _ufirst : function(s) {
1357 return s.substring(0, 1).toUpperCase() + s.substring(1);
1361 tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme);