2 * editor_template_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
11 (function(tinymce) {
\r
12 var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;
\r
14 // Tell it to load theme specific language pack(s)
\r
15 tinymce.ThemeManager.requireLangPack('advanced');
\r
17 tinymce.create('tinymce.themes.AdvancedTheme', {
\r
18 sizes : [8, 10, 12, 14, 18, 24, 36],
\r
20 // Control name lookup, format: title, command
\r
22 bold : ['bold_desc', 'Bold'],
\r
23 italic : ['italic_desc', 'Italic'],
\r
24 underline : ['underline_desc', 'Underline'],
\r
25 strikethrough : ['striketrough_desc', 'Strikethrough'],
\r
26 justifyleft : ['justifyleft_desc', 'JustifyLeft'],
\r
27 justifycenter : ['justifycenter_desc', 'JustifyCenter'],
\r
28 justifyright : ['justifyright_desc', 'JustifyRight'],
\r
29 justifyfull : ['justifyfull_desc', 'JustifyFull'],
\r
30 bullist : ['bullist_desc', 'InsertUnorderedList'],
\r
31 numlist : ['numlist_desc', 'InsertOrderedList'],
\r
32 outdent : ['outdent_desc', 'Outdent'],
\r
33 indent : ['indent_desc', 'Indent'],
\r
34 cut : ['cut_desc', 'Cut'],
\r
35 copy : ['copy_desc', 'Copy'],
\r
36 paste : ['paste_desc', 'Paste'],
\r
37 undo : ['undo_desc', 'Undo'],
\r
38 redo : ['redo_desc', 'Redo'],
\r
39 link : ['link_desc', 'mceLink'],
\r
40 unlink : ['unlink_desc', 'unlink'],
\r
41 image : ['image_desc', 'mceImage'],
\r
42 cleanup : ['cleanup_desc', 'mceCleanup'],
\r
43 help : ['help_desc', 'mceHelp'],
\r
44 code : ['code_desc', 'mceCodeEditor'],
\r
45 hr : ['hr_desc', 'InsertHorizontalRule'],
\r
46 removeformat : ['removeformat_desc', 'RemoveFormat'],
\r
47 sub : ['sub_desc', 'subscript'],
\r
48 sup : ['sup_desc', 'superscript'],
\r
49 forecolor : ['forecolor_desc', 'ForeColor'],
\r
50 forecolorpicker : ['forecolor_desc', 'mceForeColor'],
\r
51 backcolor : ['backcolor_desc', 'HiliteColor'],
\r
52 backcolorpicker : ['backcolor_desc', 'mceBackColor'],
\r
53 charmap : ['charmap_desc', 'mceCharMap'],
\r
54 visualaid : ['visualaid_desc', 'mceToggleVisualAid'],
\r
55 anchor : ['anchor_desc', 'mceInsertAnchor'],
\r
56 newdocument : ['newdocument_desc', 'mceNewDocument'],
\r
57 blockquote : ['blockquote_desc', 'mceBlockQuote']
\r
60 stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
\r
62 init : function(ed, url) {
\r
63 var t = this, s, v, o;
\r
67 t.onResolveName = new tinymce.util.Dispatcher(this);
\r
69 ed.forcedHighContrastMode = ed.settings.detect_highcontrast && t._isHighContrast();
\r
70 ed.settings.skin = ed.forcedHighContrastMode ? 'highcontrast' : ed.settings.skin;
\r
73 t.settings = s = extend({
\r
74 theme_advanced_path : true,
\r
75 theme_advanced_toolbar_location : 'bottom',
\r
76 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
\r
77 theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
\r
78 theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",
\r
79 theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
\r
80 theme_advanced_toolbar_align : "center",
\r
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",
\r
82 theme_advanced_more_colors : 1,
\r
83 theme_advanced_row_height : 23,
\r
84 theme_advanced_resize_horizontal : 1,
\r
85 theme_advanced_resizing_use_cookie : 1,
\r
86 theme_advanced_font_sizes : "1,2,3,4,5,6,7",
\r
87 theme_advanced_font_selector : "span",
\r
88 theme_advanced_show_current_color: 0,
\r
89 readonly : ed.settings.readonly
\r
92 // Setup default font_size_style_values
\r
93 if (!s.font_size_style_values)
\r
94 s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt";
\r
96 if (tinymce.is(s.theme_advanced_font_sizes, 'string')) {
\r
97 s.font_size_style_values = tinymce.explode(s.font_size_style_values);
\r
98 s.font_size_classes = tinymce.explode(s.font_size_classes || '');
\r
100 // Parse string value
\r
102 ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes;
\r
103 each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) {
\r
106 if (k == v && v >= 1 && v <= 7) {
\r
107 k = v + ' (' + t.sizes[v - 1] + 'pt)';
\r
108 cl = s.font_size_classes[v - 1];
\r
109 v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt');
\r
112 if (/^\s*\./.test(v))
\r
113 cl = v.replace(/\./g, '');
\r
115 o[k] = cl ? {'class' : cl} : {fontSize : v};
\r
118 s.theme_advanced_font_sizes = o;
\r
121 if ((v = s.theme_advanced_path_location) && v != 'none')
\r
122 s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
\r
124 if (s.theme_advanced_statusbar_location == 'none')
\r
125 s.theme_advanced_statusbar_location = 0;
\r
127 if (ed.settings.content_css !== false)
\r
128 ed.contentCSS.push(ed.baseURI.toAbsolute(url + "/skins/" + ed.settings.skin + "/content.css"));
\r
131 ed.onInit.add(function() {
\r
132 if (!ed.settings.readonly) {
\r
133 ed.onNodeChange.add(t._nodeChanged, t);
\r
134 ed.onKeyUp.add(t._updateUndoStatus, t);
\r
135 ed.onMouseUp.add(t._updateUndoStatus, t);
\r
136 ed.dom.bind(ed.dom.getRoot(), 'dragend', function() {
\r
137 t._updateUndoStatus(ed);
\r
142 ed.onSetProgressState.add(function(ed, b, ti) {
\r
143 var co, id = ed.id, tb;
\r
146 t.progressTimer = setTimeout(function() {
\r
147 co = ed.getContainer();
\r
148 co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild);
\r
149 tb = DOM.get(ed.id + '_tbl');
\r
151 DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}});
\r
152 DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}});
\r
155 DOM.remove(id + '_blocker');
\r
156 DOM.remove(id + '_progress');
\r
157 clearTimeout(t.progressTimer);
\r
161 DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css");
\r
163 if (s.skin_variant)
\r
164 DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css");
\r
167 _isHighContrast : function() {
\r
168 var actualColor, div = DOM.add(DOM.getRoot(), 'div', {'style': 'background-color: rgb(171,239,86);'});
\r
170 actualColor = (DOM.getStyle(div, 'background-color', true) + '').toLowerCase().replace(/ /g, '');
\r
173 return actualColor != 'rgb(171,239,86)' && actualColor != '#abef56';
\r
176 createControl : function(n, cf) {
\r
179 if (c = cf.createControl(n))
\r
183 case "styleselect":
\r
184 return this._createStyleSelect();
\r
186 case "formatselect":
\r
187 return this._createBlockFormats();
\r
190 return this._createFontSelect();
\r
192 case "fontsizeselect":
\r
193 return this._createFontSizeSelect();
\r
196 return this._createForeColorMenu();
\r
199 return this._createBackColorMenu();
\r
202 if ((cd = this.controls[n]))
\r
203 return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]});
\r
206 execCommand : function(cmd, ui, val) {
\r
207 var f = this['_' + cmd];
\r
210 f.call(this, ui, val);
\r
217 _importClasses : function(e) {
\r
218 var ed = this.editor, ctrl = ed.controlManager.get('styleselect');
\r
220 if (ctrl.getLength() == 0) {
\r
221 each(ed.dom.getClasses(), function(o, idx) {
\r
222 var name = 'style_' + idx;
\r
224 ed.formatter.register(name, {
\r
226 attributes : {'class' : o['class']},
\r
230 ctrl.add(o['class'], name);
\r
235 _createStyleSelect : function(n) {
\r
236 var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl;
\r
238 // Setup style select box
\r
239 ctrl = ctrlMan.createListBox('styleselect', {
\r
240 title : 'advanced.style_select',
\r
241 onselect : function(name) {
\r
242 var matches, formatNames = [];
\r
244 each(ctrl.items, function(item) {
\r
245 formatNames.push(item.value);
\r
249 ed.undoManager.add();
\r
251 // Toggle off the current format
\r
252 matches = ed.formatter.matchAll(formatNames);
\r
253 if (!name || matches[0] == name) {
\r
255 ed.formatter.remove(matches[0]);
\r
257 ed.formatter.apply(name);
\r
259 ed.undoManager.add();
\r
262 return false; // No auto select
\r
266 // Handle specified format
\r
267 ed.onInit.add(function() {
\r
268 var counter = 0, formats = ed.getParam('style_formats');
\r
271 each(formats, function(fmt) {
\r
272 var name, keys = 0;
\r
274 each(fmt, function() {keys++;});
\r
277 name = fmt.name = fmt.name || 'style_' + (counter++);
\r
278 ed.formatter.register(name, fmt);
\r
279 ctrl.add(fmt.title, name);
\r
281 ctrl.add(fmt.title);
\r
284 each(ed.getParam('theme_advanced_styles', '', 'hash'), function(val, key) {
\r
288 name = 'style_' + (counter++);
\r
290 ed.formatter.register(name, {
\r
296 ctrl.add(t.editor.translate(key), name);
\r
302 // Auto import classes if the ctrl box is empty
\r
303 if (ctrl.getLength() == 0) {
\r
304 ctrl.onPostRender.add(function(ed, n) {
\r
305 if (!ctrl.NativeListBox) {
\r
306 Event.add(n.id + '_text', 'focus', t._importClasses, t);
\r
307 Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
\r
308 Event.add(n.id + '_open', 'focus', t._importClasses, t);
\r
309 Event.add(n.id + '_open', 'mousedown', t._importClasses, t);
\r
311 Event.add(n.id, 'focus', t._importClasses, t);
\r
318 _createFontSelect : function() {
\r
319 var c, t = this, ed = t.editor;
\r
321 c = ed.controlManager.createListBox('fontselect', {
\r
322 title : 'advanced.fontdefault',
\r
323 onselect : function(v) {
\r
324 var cur = c.items[c.selectedIndex];
\r
327 ed.execCommand('FontName', false, cur.value);
\r
331 ed.execCommand('FontName', false, v);
\r
333 // Fake selection, execCommand will fire a nodeChange and update the selection
\r
334 c.select(function(sv) {
\r
338 if (cur && cur.value == v) {
\r
342 return false; // No auto select
\r
347 each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
\r
348 c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
\r
355 _createFontSizeSelect : function() {
\r
356 var t = this, ed = t.editor, c, i = 0, cl = [];
\r
358 c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) {
\r
359 var cur = c.items[c.selectedIndex];
\r
364 if (cur['class']) {
\r
365 ed.formatter.toggle('fontsize_class', {value : cur['class']});
\r
366 ed.undoManager.add();
\r
369 ed.execCommand('FontSize', false, cur.fontSize);
\r
377 ed.undoManager.add();
\r
378 ed.formatter.toggle('fontsize_class', {value : v['class']});
\r
379 ed.undoManager.add();
\r
382 ed.execCommand('FontSize', false, v.fontSize);
\r
384 // Fake selection, execCommand will fire a nodeChange and update the selection
\r
385 c.select(function(sv) {
\r
389 if (cur && (cur.value.fontSize == v.fontSize || cur.value['class'] == v['class'])) {
\r
393 return false; // No auto select
\r
397 each(t.settings.theme_advanced_font_sizes, function(v, k) {
\r
398 var fz = v.fontSize;
\r
400 if (fz >= 1 && fz <= 7)
\r
401 fz = t.sizes[parseInt(fz) - 1] + 'pt';
\r
403 c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))});
\r
410 _createBlockFormats : function() {
\r
412 p : 'advanced.paragraph',
\r
413 address : 'advanced.address',
\r
414 pre : 'advanced.pre',
\r
415 h1 : 'advanced.h1',
\r
416 h2 : 'advanced.h2',
\r
417 h3 : 'advanced.h3',
\r
418 h4 : 'advanced.h4',
\r
419 h5 : 'advanced.h5',
\r
420 h6 : 'advanced.h6',
\r
421 div : 'advanced.div',
\r
422 blockquote : 'advanced.blockquote',
\r
423 code : 'advanced.code',
\r
424 dt : 'advanced.dt',
\r
425 dd : 'advanced.dd',
\r
426 samp : 'advanced.samp'
\r
429 c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', onselect : function(v) {
\r
430 t.editor.execCommand('FormatBlock', false, v);
\r
435 each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {
\r
436 c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});
\r
443 _createForeColorMenu : function() {
\r
444 var c, t = this, s = t.settings, o = {}, v;
\r
446 if (s.theme_advanced_more_colors) {
\r
447 o.more_colors_func = function() {
\r
448 t._mceColorPicker(0, {
\r
450 func : function(co) {
\r
457 if (v = s.theme_advanced_text_colors)
\r
460 if (s.theme_advanced_default_foreground_color)
\r
461 o.default_color = s.theme_advanced_default_foreground_color;
\r
463 o.title = 'advanced.forecolor_desc';
\r
464 o.cmd = 'ForeColor';
\r
467 c = t.editor.controlManager.createColorSplitButton('forecolor', o);
\r
472 _createBackColorMenu : function() {
\r
473 var c, t = this, s = t.settings, o = {}, v;
\r
475 if (s.theme_advanced_more_colors) {
\r
476 o.more_colors_func = function() {
\r
477 t._mceColorPicker(0, {
\r
479 func : function(co) {
\r
486 if (v = s.theme_advanced_background_colors)
\r
489 if (s.theme_advanced_default_background_color)
\r
490 o.default_color = s.theme_advanced_default_background_color;
\r
492 o.title = 'advanced.backcolor_desc';
\r
493 o.cmd = 'HiliteColor';
\r
496 c = t.editor.controlManager.createColorSplitButton('backcolor', o);
\r
501 renderUI : function(o) {
\r
502 var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl;
\r
505 ed.settings.aria_label = s.aria_label + ed.getLang('advanced.help_shortcut');
\r
508 // TODO: ACC Should have an aria-describedby attribute which is user-configurable to describe what this field is actually for.
\r
509 // Maybe actually inherit it from the original textara?
\r
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) : '')});
\r
511 DOM.add(n, 'span', {'class': 'mceVoiceLabel', 'style': 'display:none;', id: ed.id + '_voice'}, s.aria_label);
\r
514 n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'});
\r
516 n = sc = DOM.add(n, 'table', {role : "presentation", id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0});
\r
517 n = tb = DOM.add(n, 'tbody');
\r
519 switch ((s.theme_advanced_layout_manager || '').toLowerCase()) {
\r
521 ic = t._rowLayout(s, tb, o);
\r
524 case "customlayout":
\r
525 ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p);
\r
529 ic = t._simpleLayout(s, tb, o, p);
\r
534 // Add classes to first and last TRs
\r
536 DOM.addClass(nl[0], 'mceFirst');
\r
537 DOM.addClass(nl[nl.length - 1], 'mceLast');
\r
539 // Add classes to first and last TDs
\r
540 each(DOM.select('tr', tb), function(n) {
\r
541 DOM.addClass(n.firstChild, 'mceFirst');
\r
542 DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast');
\r
545 if (DOM.get(s.theme_advanced_toolbar_container))
\r
546 DOM.get(s.theme_advanced_toolbar_container).appendChild(p);
\r
548 DOM.insertAfter(p, n);
\r
550 Event.add(ed.id + '_path_row', 'click', function(e) {
\r
553 if (e.nodeName == 'A') {
\r
554 t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1'));
\r
556 return Event.cancel(e);
\r
560 if (DOM.get(ed.id + '_path_row')) {
\r
561 Event.add(ed.id + '_tbl', 'mouseover', function(e) {
\r
566 if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) {
\r
567 re = DOM.get(ed.id + '_path_row');
\r
568 t.lastPath = re.innerHTML;
\r
569 DOM.setHTML(re, e.parentNode.title);
\r
573 Event.add(ed.id + '_tbl', 'mouseout', function(e) {
\r
575 DOM.setHTML(ed.id + '_path_row', t.lastPath);
\r
582 if (!ed.getParam('accessibility_focus'))
\r
583 Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();});
\r
585 if (s.theme_advanced_toolbar_location == 'external')
\r
588 t.deltaHeight = o.deltaHeight;
\r
589 o.targetNode = null;
\r
591 ed.onKeyDown.add(function(ed, evt) {
\r
592 var DOM_VK_F10 = 121, DOM_VK_F11 = 122;
\r
595 if (evt.keyCode === DOM_VK_F10) {
\r
596 t.toolbarGroup.focus();
\r
597 return Event.cancel(evt);
\r
598 } else if (evt.keyCode === DOM_VK_F11) {
\r
599 DOM.get(ed.id + '_path_row').focus();
\r
600 return Event.cancel(evt);
\r
605 // alt+0 is the UK recommended shortcut for accessing the list of access controls.
\r
606 ed.addShortcut('alt+0', '', 'mceShortcuts', t);
\r
609 iframeContainer : ic,
\r
610 editorContainer : ed.id + '_parent',
\r
611 sizeContainer : sc,
\r
612 deltaHeight : o.deltaHeight
\r
616 getInfo : function() {
\r
618 longname : 'Advanced theme',
\r
619 author : 'Moxiecode Systems AB',
\r
620 authorurl : 'http://tinymce.moxiecode.com',
\r
621 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
625 resizeBy : function(dw, dh) {
\r
626 var e = DOM.get(this.editor.id + '_ifr');
\r
628 this.resizeTo(e.clientWidth + dw, e.clientHeight + dh);
\r
631 resizeTo : function(w, h, store) {
\r
632 var ed = this.editor, s = this.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr');
\r
634 // Boundery fix box
\r
635 w = Math.max(s.theme_advanced_resizing_min_width || 100, w);
\r
636 h = Math.max(s.theme_advanced_resizing_min_height || 100, h);
\r
637 w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w);
\r
638 h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h);
\r
640 // Resize iframe and container
\r
641 DOM.setStyle(e, 'height', '');
\r
642 DOM.setStyle(ifr, 'height', h);
\r
644 if (s.theme_advanced_resize_horizontal) {
\r
645 DOM.setStyle(e, 'width', '');
\r
646 DOM.setStyle(ifr, 'width', w);
\r
648 // Make sure that the size is never smaller than the over all ui
\r
649 if (w < e.clientWidth) {
\r
651 DOM.setStyle(ifr, 'width', e.clientWidth);
\r
655 // Store away the size
\r
656 if (store && s.theme_advanced_resizing_use_cookie) {
\r
657 Cookie.setHash("TinyMCE_" + ed.id + "_size", {
\r
664 destroy : function() {
\r
665 var id = this.editor.id;
\r
667 Event.clear(id + '_resize');
\r
668 Event.clear(id + '_path_row');
\r
669 Event.clear(id + '_external_close');
\r
672 // Internal functions
\r
674 _simpleLayout : function(s, tb, o, p) {
\r
675 var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;
\r
678 n = DOM.add(tb, 'tr');
\r
679 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
\r
683 // Create toolbar container at top
\r
685 t._addToolbars(tb, o);
\r
687 // Create external toolbar
\r
688 if (lo == 'external') {
\r
689 n = c = DOM.create('div', {style : 'position:relative'});
\r
690 n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'});
\r
691 DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'});
\r
692 n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0});
\r
693 etb = DOM.add(n, 'tbody');
\r
695 if (p.firstChild.className == 'mceOldBoxModel')
\r
696 p.firstChild.appendChild(c);
\r
698 p.insertBefore(c, p.firstChild);
\r
700 t._addToolbars(etb, o);
\r
702 ed.onMouseUp.add(function() {
\r
703 var e = DOM.get(ed.id + '_external');
\r
706 DOM.hide(lastExtID);
\r
708 var f = Event.add(ed.id + '_external_close', 'click', function() {
\r
709 DOM.hide(ed.id + '_external');
\r
710 Event.remove(ed.id + '_external_close', 'click', f);
\r
714 DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1);
\r
716 // Fixes IE rendering bug
\r
719 e.style.filter = '';
\r
721 lastExtID = ed.id + '_external';
\r
728 t._addStatusBar(tb, o);
\r
730 // Create iframe container
\r
731 if (!s.theme_advanced_toolbar_container) {
\r
732 n = DOM.add(tb, 'tr');
\r
733 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
\r
736 // Create toolbar container at bottom
\r
737 if (lo == 'bottom')
\r
738 t._addToolbars(tb, o);
\r
740 if (sl == 'bottom')
\r
741 t._addStatusBar(tb, o);
\r
746 _rowLayout : function(s, tb, o) {
\r
747 var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
\r
749 dc = s.theme_advanced_containers_default_class || '';
\r
750 da = s.theme_advanced_containers_default_align || 'center';
\r
752 each(explode(s.theme_advanced_containers || ''), function(c, i) {
\r
753 var v = s['theme_advanced_container_' + c] || '';
\r
755 switch (c.toLowerCase()) {
\r
757 n = DOM.add(tb, 'tr');
\r
758 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
\r
761 case 'mceelementpath':
\r
762 t._addStatusBar(tb, o);
\r
766 a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();
\r
767 a = 'mce' + t._ufirst(a);
\r
769 n = DOM.add(DOM.add(tb, 'tr'), 'td', {
\r
770 'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
\r
773 to = cf.createToolbar("toolbar" + i);
\r
774 t._addControls(v, to);
\r
775 DOM.setHTML(n, to.renderHTML());
\r
776 o.deltaHeight -= s.theme_advanced_row_height;
\r
783 _addControls : function(v, tb) {
\r
784 var t = this, s = t.settings, di, cf = t.editor.controlManager;
\r
786 if (s.theme_advanced_disable && !t._disabled) {
\r
789 each(explode(s.theme_advanced_disable), function(v) {
\r
797 each(explode(v), function(n) {
\r
803 // Compatiblity with 2.x
\r
804 if (n == 'tablecontrols') {
\r
805 each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) {
\r
806 n = t.createControl(n, cf);
\r
815 c = t.createControl(n, cf);
\r
822 _addToolbars : function(c, o) {
\r
823 var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a, toolbarGroup;
\r
825 toolbarGroup = cf.createToolbarGroup('toolbargroup', {
\r
826 'name': ed.getLang('advanced.toolbar'),
\r
827 'tab_focus_toolbar':ed.getParam('theme_advanced_tab_focus_toolbar')
\r
830 t.toolbarGroup = toolbarGroup;
\r
832 a = s.theme_advanced_toolbar_align.toLowerCase();
\r
833 a = 'mce' + t._ufirst(a);
\r
835 n = DOM.add(DOM.add(c, 'tr', {role: 'presentation'}), 'td', {'class' : 'mceToolbar ' + a, "role":"presentation"});
\r
837 // Create toolbar and add the controls
\r
838 for (i=1; (v = s['theme_advanced_buttons' + i]); i++) {
\r
839 tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i});
\r
841 if (s['theme_advanced_buttons' + i + '_add'])
\r
842 v += ',' + s['theme_advanced_buttons' + i + '_add'];
\r
844 if (s['theme_advanced_buttons' + i + '_add_before'])
\r
845 v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v;
\r
847 t._addControls(v, tb);
\r
848 toolbarGroup.add(tb);
\r
850 o.deltaHeight -= s.theme_advanced_row_height;
\r
852 h.push(toolbarGroup.renderHTML());
\r
853 h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
\r
854 DOM.setHTML(n, h.join(''));
\r
857 _addStatusBar : function(tb, o) {
\r
858 var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td;
\r
860 n = DOM.add(tb, 'tr');
\r
861 n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'});
\r
862 n = DOM.add(n, 'div', {id : ed.id + '_path_row', 'role': 'group', 'aria-labelledby': ed.id + '_path_voice'});
\r
863 if (s.theme_advanced_path) {
\r
864 DOM.add(n, 'span', {id: ed.id + '_path_voice'}, ed.translate('advanced.path'));
\r
865 DOM.add(n, 'span', {}, ': ');
\r
867 DOM.add(n, 'span', {}, ' ');
\r
871 if (s.theme_advanced_resizing) {
\r
872 DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize'});
\r
874 if (s.theme_advanced_resizing_use_cookie) {
\r
875 ed.onPostRender.add(function() {
\r
876 var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl');
\r
881 t.resizeTo(o.cw, o.ch);
\r
885 ed.onPostRender.add(function() {
\r
886 Event.add(ed.id + '_resize', 'click', function(e) {
\r
887 e.preventDefault();
\r
890 Event.add(ed.id + '_resize', 'mousedown', function(e) {
\r
891 var mouseMoveHandler1, mouseMoveHandler2,
\r
892 mouseUpHandler1, mouseUpHandler2,
\r
893 startX, startY, startWidth, startHeight, width, height, ifrElm;
\r
895 function resizeOnMove(e) {
\r
896 e.preventDefault();
\r
898 width = startWidth + (e.screenX - startX);
\r
899 height = startHeight + (e.screenY - startY);
\r
901 t.resizeTo(width, height);
\r
904 function endResize(e) {
\r
906 Event.remove(DOM.doc, 'mousemove', mouseMoveHandler1);
\r
907 Event.remove(ed.getDoc(), 'mousemove', mouseMoveHandler2);
\r
908 Event.remove(DOM.doc, 'mouseup', mouseUpHandler1);
\r
909 Event.remove(ed.getDoc(), 'mouseup', mouseUpHandler2);
\r
911 width = startWidth + (e.screenX - startX);
\r
912 height = startHeight + (e.screenY - startY);
\r
913 t.resizeTo(width, height, true);
\r
916 e.preventDefault();
\r
918 // Get the current rect size
\r
919 startX = e.screenX;
\r
920 startY = e.screenY;
\r
921 ifrElm = DOM.get(t.editor.id + '_ifr');
\r
922 startWidth = width = ifrElm.clientWidth;
\r
923 startHeight = height = ifrElm.clientHeight;
\r
925 // Register envent handlers
\r
926 mouseMoveHandler1 = Event.add(DOM.doc, 'mousemove', resizeOnMove);
\r
927 mouseMoveHandler2 = Event.add(ed.getDoc(), 'mousemove', resizeOnMove);
\r
928 mouseUpHandler1 = Event.add(DOM.doc, 'mouseup', endResize);
\r
929 mouseUpHandler2 = Event.add(ed.getDoc(), 'mouseup', endResize);
\r
934 o.deltaHeight -= 21;
\r
938 _updateUndoStatus : function(ed) {
\r
939 var cm = ed.controlManager;
\r
941 cm.setDisabled('undo', !ed.undoManager.hasUndo() && !ed.typing);
\r
942 cm.setDisabled('redo', !ed.undoManager.hasRedo());
\r
945 _nodeChanged : function(ed, cm, n, co, ob) {
\r
946 var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn, fc, bc, formatNames, matches;
\r
948 tinymce.each(t.stateControls, function(c) {
\r
949 cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
\r
952 function getParent(name) {
\r
953 var i, parents = ob.parents, func = name;
\r
955 if (typeof(name) == 'string') {
\r
956 func = function(node) {
\r
957 return node.nodeName == name;
\r
961 for (i = 0; i < parents.length; i++) {
\r
962 if (func(parents[i]))
\r
967 cm.setActive('visualaid', ed.hasVisual);
\r
968 t._updateUndoStatus(ed);
\r
969 cm.setDisabled('outdent', !ed.queryCommandState('Outdent'));
\r
971 p = getParent('A');
\r
972 if (c = cm.get('link')) {
\r
973 if (!p || !p.name) {
\r
974 c.setDisabled(!p && co);
\r
979 if (c = cm.get('unlink')) {
\r
980 c.setDisabled(!p && co);
\r
981 c.setActive(!!p && !p.name);
\r
984 if (c = cm.get('anchor')) {
\r
985 c.setActive(!co && !!p && p.name);
\r
988 p = getParent('IMG');
\r
989 if (c = cm.get('image'))
\r
990 c.setActive(!co && !!p && n.className.indexOf('mceItem') == -1);
\r
992 if (c = cm.get('styleselect')) {
\r
993 t._importClasses();
\r
996 each(c.items, function(item) {
\r
997 formatNames.push(item.value);
\r
1000 matches = ed.formatter.matchAll(formatNames);
\r
1001 c.select(matches[0]);
\r
1004 if (c = cm.get('formatselect')) {
\r
1005 p = getParent(DOM.isBlock);
\r
1008 c.select(p.nodeName.toLowerCase());
\r
1011 // Find out current fontSize, fontFamily and fontClass
\r
1012 getParent(function(n) {
\r
1013 if (n.nodeName === 'SPAN') {
\r
1014 if (!cl && n.className)
\r
1018 if (ed.dom.is(n, s.theme_advanced_font_selector)) {
\r
1019 if (!fz && n.style.fontSize)
\r
1020 fz = n.style.fontSize;
\r
1022 if (!fn && n.style.fontFamily)
\r
1023 fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase();
\r
1025 if (!fc && n.style.color)
\r
1026 fc = n.style.color;
\r
1028 if (!bc && n.style.backgroundColor)
\r
1029 bc = n.style.backgroundColor;
\r
1035 if (c = cm.get('fontselect')) {
\r
1036 c.select(function(v) {
\r
1037 return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn;
\r
1041 // Select font size
\r
1042 if (c = cm.get('fontsizeselect')) {
\r
1043 // Use computed style
\r
1044 if (s.theme_advanced_runtime_fontsize && !fz && !cl)
\r
1045 fz = ed.dom.getStyle(n, 'fontSize', true);
\r
1047 c.select(function(v) {
\r
1048 if (v.fontSize && v.fontSize === fz)
\r
1051 if (v['class'] && v['class'] === cl)
\r
1056 if (s.theme_advanced_show_current_color) {
\r
1057 function updateColor(controlId, color) {
\r
1058 if (c = cm.get(controlId)) {
\r
1060 color = c.settings.default_color;
\r
1061 if (color !== c.value) {
\r
1062 c.displayColor(color);
\r
1066 updateColor('forecolor', fc);
\r
1067 updateColor('backcolor', bc);
\r
1070 if (s.theme_advanced_show_current_color) {
\r
1071 function updateColor(controlId, color) {
\r
1072 if (c = cm.get(controlId)) {
\r
1074 color = c.settings.default_color;
\r
1075 if (color !== c.value) {
\r
1076 c.displayColor(color);
\r
1081 updateColor('forecolor', fc);
\r
1082 updateColor('backcolor', bc);
\r
1085 if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
\r
1086 p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
\r
1088 if (t.statusKeyboardNavigation) {
\r
1089 t.statusKeyboardNavigation.destroy();
\r
1090 t.statusKeyboardNavigation = null;
\r
1093 DOM.setHTML(p, '');
\r
1095 getParent(function(n) {
\r
1096 var na = n.nodeName.toLowerCase(), u, pi, ti = '';
\r
1098 if (n.getAttribute('data-mce-bogus'))
\r
1101 // Ignore non element and hidden elements
\r
1102 if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))
\r
1106 if (tinymce.isIE && n.scopeName !== 'HTML')
\r
1107 na = n.scopeName + ':' + na;
\r
1109 // Remove internal prefix
\r
1110 na = na.replace(/mce\:/g, '');
\r
1112 // Handle node name
\r
1123 if (v = DOM.getAttrib(n, 'src'))
\r
1124 ti += 'src: ' + v + ' ';
\r
1129 if (v = DOM.getAttrib(n, 'name')) {
\r
1130 ti += 'name: ' + v + ' ';
\r
1134 if (v = DOM.getAttrib(n, 'href'))
\r
1135 ti += 'href: ' + v + ' ';
\r
1140 if (v = DOM.getAttrib(n, 'face'))
\r
1141 ti += 'font: ' + v + ' ';
\r
1143 if (v = DOM.getAttrib(n, 'size'))
\r
1144 ti += 'size: ' + v + ' ';
\r
1146 if (v = DOM.getAttrib(n, 'color'))
\r
1147 ti += 'color: ' + v + ' ';
\r
1152 if (v = DOM.getAttrib(n, 'style'))
\r
1153 ti += 'style: ' + v + ' ';
\r
1158 if (v = DOM.getAttrib(n, 'id'))
\r
1159 ti += 'id: ' + v + ' ';
\r
1161 if (v = n.className) {
\r
1162 v = v.replace(/\b\s*(webkit|mce|Apple-)\w+\s*\b/g, '')
\r
1165 ti += 'class: ' + v + ' ';
\r
1167 if (DOM.isBlock(n) || na == 'img' || na == 'span')
\r
1172 na = na.replace(/(html:)/g, '');
\r
1173 na = {name : na, node : n, title : ti};
\r
1174 t.onResolveName.dispatch(t, na);
\r
1178 //u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
\r
1179 pi = DOM.create('a', {'href' : "javascript:;", role: 'button', onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
\r
1181 if (p.hasChildNodes()) {
\r
1182 p.insertBefore(DOM.create('span', {'aria-hidden': 'true'}, '\u00a0\u00bb '), p.firstChild);
\r
1183 p.insertBefore(pi, p.firstChild);
\r
1185 p.appendChild(pi);
\r
1188 if (DOM.select('a', p).length > 0) {
\r
1189 t.statusKeyboardNavigation = new tinymce.ui.KeyboardNavigation({
\r
1190 root: ed.id + "_path_row",
\r
1191 items: DOM.select('a', p),
\r
1192 excludeFromTabOrder: true,
\r
1193 onCancel: function() {
\r
1201 // Commands gets called by execCommand
\r
1203 _sel : function(v) {
\r
1204 this.editor.execCommand('mceSelectNodeDepth', false, v);
\r
1207 _mceInsertAnchor : function(ui, v) {
\r
1208 var ed = this.editor;
\r
1210 ed.windowManager.open({
\r
1211 url : this.url + '/anchor.htm',
\r
1212 width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)),
\r
1213 height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)),
\r
1216 theme_url : this.url
\r
1220 _mceCharMap : function() {
\r
1221 var ed = this.editor;
\r
1223 ed.windowManager.open({
\r
1224 url : this.url + '/charmap.htm',
\r
1225 width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)),
\r
1226 height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)),
\r
1229 theme_url : this.url
\r
1233 _mceHelp : function() {
\r
1234 var ed = this.editor;
\r
1236 ed.windowManager.open({
\r
1237 url : this.url + '/about.htm',
\r
1242 theme_url : this.url
\r
1246 _mceShortcuts : function() {
\r
1247 var ed = this.editor;
\r
1248 ed.windowManager.open({
\r
1249 url: this.url + '/shortcuts.htm',
\r
1254 theme_url: this.url
\r
1258 _mceColorPicker : function(u, v) {
\r
1259 var ed = this.editor;
\r
1263 ed.windowManager.open({
\r
1264 url : this.url + '/color_picker.htm',
\r
1265 width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)),
\r
1266 height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)),
\r
1267 close_previous : false,
\r
1270 input_color : v.color,
\r
1272 theme_url : this.url
\r
1276 _mceCodeEditor : function(ui, val) {
\r
1277 var ed = this.editor;
\r
1279 ed.windowManager.open({
\r
1280 url : this.url + '/source_editor.htm',
\r
1281 width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)),
\r
1282 height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)),
\r
1285 maximizable : true
\r
1287 theme_url : this.url
\r
1291 _mceImage : function(ui, val) {
\r
1292 var ed = this.editor;
\r
1294 // Internal image object like a flash placeholder
\r
1295 if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
\r
1298 ed.windowManager.open({
\r
1299 url : this.url + '/image.htm',
\r
1300 width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
\r
1301 height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
\r
1304 theme_url : this.url
\r
1308 _mceLink : function(ui, val) {
\r
1309 var ed = this.editor;
\r
1311 ed.windowManager.open({
\r
1312 url : this.url + '/link.htm',
\r
1313 width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)),
\r
1314 height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)),
\r
1317 theme_url : this.url
\r
1321 _mceNewDocument : function() {
\r
1322 var ed = this.editor;
\r
1324 ed.windowManager.confirm('advanced.newdocument', function(s) {
\r
1326 ed.execCommand('mceSetContent', false, '');
\r
1330 _mceForeColor : function() {
\r
1333 this._mceColorPicker(0, {
\r
1335 func : function(co) {
\r
1337 t.editor.execCommand('ForeColor', false, co);
\r
1342 _mceBackColor : function() {
\r
1345 this._mceColorPicker(0, {
\r
1347 func : function(co) {
\r
1349 t.editor.execCommand('HiliteColor', false, co);
\r
1354 _ufirst : function(s) {
\r
1355 return s.substring(0, 1).toUpperCase() + s.substring(1);
\r
1359 tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme);
\r