X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftiny_mce%2Fthemes%2Fadvanced%2Feditor_template_src.js;h=bee26e161025b55d7efa965e4dcf449c300f26f9;hb=b05f4eef4014db3885787ef15107cba93c932ac9;hp=b3cef0199bd93e9357f6e2edab30d923c8f4dde9;hpb=7ce246db4a173b9c738e8e160f8d0030d4e82d78;p=citadel.git diff --git a/webcit/tiny_mce/themes/advanced/editor_template_src.js b/webcit/tiny_mce/themes/advanced/editor_template_src.js index b3cef0199..bee26e161 100644 --- a/webcit/tiny_mce/themes/advanced/editor_template_src.js +++ b/webcit/tiny_mce/themes/advanced/editor_template_src.js @@ -1,11 +1,14 @@ /** - * $Id: editor_template_src.js 960 2008-11-12 18:30:32Z spocke $ + * editor_template_src.js * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. + * + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ -(function() { +(function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode; // Tell it to load theme specific language pack(s) @@ -63,6 +66,9 @@ t.url = url; t.onResolveName = new tinymce.util.Dispatcher(this); + ed.forcedHighContrastMode = ed.settings.detect_highcontrast && t._isHighContrast(); + ed.settings.skin = ed.forcedHighContrastMode ? 'highcontrast' : ed.settings.skin; + // Default settings t.settings = s = extend({ theme_advanced_path : true, @@ -78,6 +84,8 @@ theme_advanced_resize_horizontal : 1, theme_advanced_resizing_use_cookie : 1, theme_advanced_font_sizes : "1,2,3,4,5,6,7", + theme_advanced_font_selector : "span", + theme_advanced_show_current_color: 0, readonly : ed.settings.readonly }, ed.settings); @@ -97,14 +105,11 @@ if (k == v && v >= 1 && v <= 7) { k = v + ' (' + t.sizes[v - 1] + 'pt)'; - - if (ed.settings.convert_fonts_to_spans) { - cl = s.font_size_classes[v - 1]; - v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt'); - } + cl = s.font_size_classes[v - 1]; + v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt'); } - if (/\s*\./.test(v)) + if (/^\s*\./.test(v)) cl = v.replace(/\./g, ''); o[k] = cl ? {'class' : cl} : {fontSize : v}; @@ -119,12 +124,19 @@ if (s.theme_advanced_statusbar_location == 'none') s.theme_advanced_statusbar_location = 0; + if (ed.settings.content_css !== false) + ed.contentCSS.push(ed.baseURI.toAbsolute(url + "/skins/" + ed.settings.skin + "/content.css")); + // Init editor ed.onInit.add(function() { - ed.onNodeChange.add(t._nodeChanged, t); - - if (ed.settings.content_css !== false) - ed.dom.loadCSS(ed.baseURI.toAbsolute("themes/advanced/skins/" + ed.settings.skin + "/content.css")); + if (!ed.settings.readonly) { + ed.onNodeChange.add(t._nodeChanged, t); + ed.onKeyUp.add(t._updateUndoStatus, t); + ed.onMouseUp.add(t._updateUndoStatus, t); + ed.dom.bind(ed.dom.getRoot(), 'dragend', function() { + t._updateUndoStatus(ed); + }); + } }); ed.onSetProgressState.add(function(ed, b, ti) { @@ -152,6 +164,15 @@ DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css"); }, + _isHighContrast : function() { + var actualColor, div = DOM.add(DOM.getRoot(), 'div', {'style': 'background-color: rgb(171,239,86);'}); + + actualColor = (DOM.getStyle(div, 'background-color', true) + '').toLowerCase().replace(/ /g, ''); + DOM.remove(div); + + return actualColor != 'rgb(171,239,86)' && actualColor != '#abef56'; + }, + createControl : function(n, cf) { var cd, c; @@ -194,36 +215,94 @@ }, _importClasses : function(e) { - var ed = this.editor, c = ed.controlManager.get('styleselect'); + var ed = this.editor, ctrl = ed.controlManager.get('styleselect'); + + if (ctrl.getLength() == 0) { + each(ed.dom.getClasses(), function(o, idx) { + var name = 'style_' + idx; + + ed.formatter.register(name, { + inline : 'span', + attributes : {'class' : o['class']}, + selector : '*' + }); - if (c.getLength() == 0) { - each(ed.dom.getClasses(), function(o) { - c.add(o['class'], o['class']); + ctrl.add(o['class'], name); }); } }, _createStyleSelect : function(n) { - var t = this, ed = t.editor, cf = ed.controlManager, c = cf.createListBox('styleselect', { + var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl; + + // Setup style select box + ctrl = ctrlMan.createListBox('styleselect', { title : 'advanced.style_select', - onselect : function(v) { - if (c.selectedValue === v) { - ed.execCommand('mceSetStyleInfo', 0, {command : 'removeformat'}); - c.select(); - return false; + onselect : function(name) { + var matches, formatNames = []; + + each(ctrl.items, function(item) { + formatNames.push(item.value); + }); + + ed.focus(); + ed.undoManager.add(); + + // Toggle off the current format + matches = ed.formatter.matchAll(formatNames); + if (!name || matches[0] == name) { + if (matches[0]) + ed.formatter.remove(matches[0]); } else - ed.execCommand('mceSetCSSClass', 0, v); + ed.formatter.apply(name); + + ed.undoManager.add(); + ed.nodeChanged(); + + return false; // No auto select } }); - if (c) { - each(ed.getParam('theme_advanced_styles', '', 'hash'), function(v, k) { - if (v) - c.add(t.editor.translate(k), v); - }); + // Handle specified format + ed.onInit.add(function() { + var counter = 0, formats = ed.getParam('style_formats'); + + if (formats) { + each(formats, function(fmt) { + var name, keys = 0; + + each(fmt, function() {keys++;}); + + if (keys > 1) { + name = fmt.name = fmt.name || 'style_' + (counter++); + ed.formatter.register(name, fmt); + ctrl.add(fmt.title, name); + } else + ctrl.add(fmt.title); + }); + } else { + each(ed.getParam('theme_advanced_styles', '', 'hash'), function(val, key) { + var name; + + if (val) { + name = 'style_' + (counter++); + + ed.formatter.register(name, { + inline : 'span', + classes : val, + selector : '*' + }); + + ctrl.add(t.editor.translate(key), name); + } + }); + } + }); - c.onPostRender.add(function(ed, n) { - if (!c.NativeListBox) { + // Auto import classes if the ctrl box is empty + if (ctrl.getLength() == 0) { + ctrl.onPostRender.add(function(ed, n) { + if (!ctrl.NativeListBox) { Event.add(n.id + '_text', 'focus', t._importClasses, t); Event.add(n.id + '_text', 'mousedown', t._importClasses, t); Event.add(n.id + '_open', 'focus', t._importClasses, t); @@ -233,13 +312,37 @@ }); } - return c; + return ctrl; }, _createFontSelect : function() { var c, t = this, ed = t.editor; - c = ed.controlManager.createListBox('fontselect', {title : 'advanced.fontdefault', cmd : 'FontName'}); + c = ed.controlManager.createListBox('fontselect', { + title : 'advanced.fontdefault', + onselect : function(v) { + var cur = c.items[c.selectedIndex]; + + if (!v && cur) { + ed.execCommand('FontName', false, cur.value); + return; + } + + ed.execCommand('FontName', false, v); + + // Fake selection, execCommand will fire a nodeChange and update the selection + c.select(function(sv) { + return v == sv; + }); + + if (cur && cur.value == v) { + c.select(null); + } + + return false; // No auto select + } + }); + if (c) { each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) { c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''}); @@ -253,16 +356,41 @@ var t = this, ed = t.editor, c, i = 0, cl = []; c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) { - if (v.fontSize) + var cur = c.items[c.selectedIndex]; + + if (!v && cur) { + cur = cur.value; + + if (cur['class']) { + ed.formatter.toggle('fontsize_class', {value : cur['class']}); + ed.undoManager.add(); + ed.nodeChanged(); + } else { + ed.execCommand('FontSize', false, cur.fontSize); + } + + return; + } + + if (v['class']) { + ed.focus(); + ed.undoManager.add(); + ed.formatter.toggle('fontsize_class', {value : v['class']}); + ed.undoManager.add(); + ed.nodeChanged(); + } else ed.execCommand('FontSize', false, v.fontSize); - else { - each(t.settings.theme_advanced_font_sizes, function(v, k) { - if (v['class']) - cl.push(v['class']); - }); - ed.editorCommands._applyInlineStyle('span', {'class' : v['class']}, {check_classes : cl}); + // Fake selection, execCommand will fire a nodeChange and update the selection + c.select(function(sv) { + return v == sv; + }); + + if (cur && (cur.value.fontSize == v.fontSize || cur.value['class'] == v['class'])) { + c.select(null); } + + return false; // No auto select }}); if (c) { @@ -298,7 +426,11 @@ samp : 'advanced.samp' }, t = this; - c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'}); + c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', onselect : function(v) { + t.editor.execCommand('FormatBlock', false, v); + return false; + }}); + if (c) { each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) { c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v}); @@ -369,12 +501,19 @@ renderUI : function(o) { var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl; - 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) : '')}); + if (ed.settings) { + ed.settings.aria_label = s.aria_label + ed.getLang('advanced.help_shortcut'); + } + + // TODO: ACC Should have an aria-describedby attribute which is user-configurable to describe what this field is actually for. + // Maybe actually inherit it from the original textara? + 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) : '')}); + DOM.add(n, 'span', {'class': 'mceVoiceLabel', 'style': 'display:none;', id: ed.id + '_voice'}, s.aria_label); if (!DOM.boxModel) n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'}); - n = sc = DOM.add(n, 'table', {id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0}); + n = sc = DOM.add(n, 'table', {role : "presentation", id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0}); n = tb = DOM.add(n, 'tbody'); switch ((s.theme_advanced_layout_manager || '').toLowerCase()) { @@ -393,7 +532,7 @@ n = o.targetNode; // Add classes to first and last TRs - nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8 + nl = sc.rows; DOM.addClass(nl[0], 'mceFirst'); DOM.addClass(nl[nl.length - 1], 'mceLast'); @@ -440,7 +579,7 @@ } */ - if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus')) + if (!ed.getParam('accessibility_focus')) Event.add(DOM.add(p, 'a', {href : '#'}, ''), 'focus', function() {tinyMCE.get(ed.id).focus();}); if (s.theme_advanced_toolbar_location == 'external') @@ -449,6 +588,24 @@ t.deltaHeight = o.deltaHeight; o.targetNode = null; + ed.onKeyDown.add(function(ed, evt) { + var DOM_VK_F10 = 121, DOM_VK_F11 = 122; + + if (evt.altKey) { + if (evt.keyCode === DOM_VK_F10) { + window.focus(); + t.toolbarGroup.focus(); + return Event.cancel(evt); + } else if (evt.keyCode === DOM_VK_F11) { + DOM.get(ed.id + '_path_row').focus(); + return Event.cancel(evt); + } + } + }); + + // alt+0 is the UK recommended shortcut for accessing the list of access controls. + ed.addShortcut('alt+0', '', 'mceShortcuts', t); + return { iframeContainer : ic, editorContainer : ed.id + '_parent', @@ -467,13 +624,13 @@ }, resizeBy : function(dw, dh) { - var e = DOM.get(this.editor.id + '_tbl'); + var e = DOM.get(this.editor.id + '_ifr'); this.resizeTo(e.clientWidth + dw, e.clientHeight + dh); }, - resizeTo : function(w, h) { - var ed = this.editor, s = ed.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr'), dh; + resizeTo : function(w, h, store) { + var ed = this.editor, s = this.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr'); // Boundery fix box w = Math.max(s.theme_advanced_resizing_min_width || 100, w); @@ -481,12 +638,28 @@ w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w); h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h); - // Calc difference between iframe and container - dh = e.clientHeight - ifr.clientHeight; - // Resize iframe and container - DOM.setStyle(ifr, 'height', h - dh); - DOM.setStyles(e, {width : w, height : h}); + DOM.setStyle(e, 'height', ''); + DOM.setStyle(ifr, 'height', h); + + if (s.theme_advanced_resize_horizontal) { + DOM.setStyle(e, 'width', ''); + DOM.setStyle(ifr, 'width', w); + + // Make sure that the size is never smaller than the over all ui + if (w < e.clientWidth) { + w = e.clientWidth; + DOM.setStyle(ifr, 'width', e.clientWidth); + } + } + + // Store away the size + if (store && s.theme_advanced_resizing_use_cookie) { + Cookie.setHash("TinyMCE_" + ed.id + "_size", { + cw : w, + ch : h + }); + } }, destroy : function() { @@ -580,7 +753,7 @@ each(explode(s.theme_advanced_containers || ''), function(c, i) { var v = s['theme_advanced_container_' + c] || ''; - switch (v.toLowerCase()) { + switch (c.toLowerCase()) { case 'mceeditor': n = DOM.add(tb, 'tr'); n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'}); @@ -648,17 +821,19 @@ }, _addToolbars : function(c, o) { - var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a; + var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a, toolbarGroup; - a = s.theme_advanced_toolbar_align.toLowerCase(); - a = 'mce' + t._ufirst(a); + toolbarGroup = cf.createToolbarGroup('toolbargroup', { + 'name': ed.getLang('advanced.toolbar'), + 'tab_focus_toolbar':ed.getParam('theme_advanced_tab_focus_toolbar') + }); - n = DOM.add(DOM.add(c, 'tr'), 'td', {'class' : 'mceToolbar ' + a}); + t.toolbarGroup = toolbarGroup; - if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus')) - h.push(DOM.createHTML('a', {href : '#', onfocus : 'tinyMCE.get(\'' + ed.id + '\').focus();'}, '')); + a = s.theme_advanced_toolbar_align.toLowerCase(); + a = 'mce' + t._ufirst(a); - h.push(DOM.createHTML('a', {href : '#', accesskey : 'q', title : ed.getLang("advanced.toolbar_focus")}, '')); + n = DOM.add(DOM.add(c, 'tr', {role: 'presentation'}), 'td', {'class' : 'mceToolbar ' + a, "role":"presentation"}); // Create toolbar and add the controls for (i=1; (v = s['theme_advanced_buttons' + i]); i++) { @@ -671,13 +846,11 @@ v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v; t._addControls(v, tb); - - //n.appendChild(n = tb.render()); - h.push(tb.renderHTML()); + toolbarGroup.add(tb); o.deltaHeight -= s.theme_advanced_row_height; } - + h.push(toolbarGroup.renderHTML()); h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '')); DOM.setHTML(n, h.join('')); }, @@ -686,12 +859,18 @@ var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td; n = DOM.add(tb, 'tr'); - n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'}); - n = DOM.add(n, 'div', {id : ed.id + '_path_row'}, s.theme_advanced_path ? ed.translate('advanced.path') + ': ' : ' '); - DOM.add(n, 'a', {href : '#', accesskey : 'x'}); + n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'}); + n = DOM.add(n, 'div', {id : ed.id + '_path_row', 'role': 'group', 'aria-labelledby': ed.id + '_path_voice'}); + if (s.theme_advanced_path) { + DOM.add(n, 'span', {id: ed.id + '_path_voice'}, ed.translate('advanced.path')); + DOM.add(n, 'span', {}, ': '); + } else { + DOM.add(n, 'span', {}, ' '); + } + - if (s.theme_advanced_resizing && !tinymce.isOldWebKit) { - DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize'}); + if (s.theme_advanced_resizing) { + DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize', tabIndex:"-1"}); if (s.theme_advanced_resizing_use_cookie) { ed.onPostRender.add(function() { @@ -700,99 +879,55 @@ if (!o) return; - if (s.theme_advanced_resize_horizontal) - c.style.width = Math.max(10, o.cw) + 'px'; - - c.style.height = Math.max(10, o.ch) + 'px'; - DOM.get(ed.id + '_ifr').style.height = Math.max(10, parseInt(o.ch) + t.deltaHeight) + 'px'; + t.resizeTo(o.cw, o.ch); }); } ed.onPostRender.add(function() { - Event.add(ed.id + '_resize', 'mousedown', function(e) { - var c, p, w, h, n, pa; - - // Measure container - c = DOM.get(ed.id + '_tbl'); - w = c.clientWidth; - h = c.clientHeight; - - miw = s.theme_advanced_resizing_min_width || 100; - mih = s.theme_advanced_resizing_min_height || 100; - maw = s.theme_advanced_resizing_max_width || 0xFFFF; - mah = s.theme_advanced_resizing_max_height || 0xFFFF; - - // Setup placeholder - p = DOM.add(DOM.get(ed.id + '_parent'), 'div', {'class' : 'mcePlaceHolder'}); - DOM.setStyles(p, {width : w, height : h}); - - // Replace with placeholder - DOM.hide(c); - DOM.show(p); - - // Create internal resize obj - r = { - x : e.screenX, - y : e.screenY, - w : w, - h : h, - dx : null, - dy : null - }; - - // Start listening - mf = Event.add(DOM.doc, 'mousemove', function(e) { - var w, h; - - // Calc delta values - r.dx = e.screenX - r.x; - r.dy = e.screenY - r.y; - - // Boundery fix box - w = Math.max(miw, r.w + r.dx); - h = Math.max(mih, r.h + r.dy); - w = Math.min(maw, w); - h = Math.min(mah, h); + Event.add(ed.id + '_resize', 'click', function(e) { + e.preventDefault(); + }); - // Resize placeholder - if (s.theme_advanced_resize_horizontal) - p.style.width = w + 'px'; + Event.add(ed.id + '_resize', 'mousedown', function(e) { + var mouseMoveHandler1, mouseMoveHandler2, + mouseUpHandler1, mouseUpHandler2, + startX, startY, startWidth, startHeight, width, height, ifrElm; - p.style.height = h + 'px'; + function resizeOnMove(e) { + e.preventDefault(); - return Event.cancel(e); - }); + width = startWidth + (e.screenX - startX); + height = startHeight + (e.screenY - startY); - me = Event.add(DOM.doc, 'mouseup', function(e) { - var ifr; + t.resizeTo(width, height); + }; + function endResize(e) { // Stop listening - Event.remove(DOM.doc, 'mousemove', mf); - Event.remove(DOM.doc, 'mouseup', me); - - c.style.display = ''; - DOM.remove(p); - - if (r.dx === null) - return; - - ifr = DOM.get(ed.id + '_ifr'); - - if (s.theme_advanced_resize_horizontal) - c.style.width = Math.max(10, r.w + r.dx) + 'px'; + Event.remove(DOM.doc, 'mousemove', mouseMoveHandler1); + Event.remove(ed.getDoc(), 'mousemove', mouseMoveHandler2); + Event.remove(DOM.doc, 'mouseup', mouseUpHandler1); + Event.remove(ed.getDoc(), 'mouseup', mouseUpHandler2); + + width = startWidth + (e.screenX - startX); + height = startHeight + (e.screenY - startY); + t.resizeTo(width, height, true); + }; - c.style.height = Math.max(10, r.h + r.dy) + 'px'; - ifr.style.height = Math.max(10, ifr.clientHeight + r.dy) + 'px'; + e.preventDefault(); - if (s.theme_advanced_resizing_use_cookie) { - Cookie.setHash("TinyMCE_" + ed.id + "_size", { - cw : r.w + r.dx, - ch : r.h + r.dy - }); - } - }); + // Get the current rect size + startX = e.screenX; + startY = e.screenY; + ifrElm = DOM.get(t.editor.id + '_ifr'); + startWidth = width = ifrElm.clientWidth; + startHeight = height = ifrElm.clientHeight; - return Event.cancel(e); + // Register envent handlers + mouseMoveHandler1 = Event.add(DOM.doc, 'mousemove', resizeOnMove); + mouseMoveHandler2 = Event.add(ed.getDoc(), 'mousemove', resizeOnMove); + mouseUpHandler1 = Event.add(DOM.doc, 'mouseup', endResize); + mouseUpHandler2 = Event.add(ed.getDoc(), 'mouseup', endResize); }); }); } @@ -801,22 +936,40 @@ n = tb = null; }, - _nodeChanged : function(ed, cm, n, co) { - var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn; + _updateUndoStatus : function(ed) { + var cm = ed.controlManager, um = ed.undoManager; - if (s.readonly) - return; + cm.setDisabled('undo', !um.hasUndo() && !um.typing); + cm.setDisabled('redo', !um.hasRedo()); + }, + + _nodeChanged : function(ed, cm, n, co, ob) { + var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn, fc, bc, formatNames, matches; tinymce.each(t.stateControls, function(c) { cm.setActive(c, ed.queryCommandState(t.controls[c][1])); }); + function getParent(name) { + var i, parents = ob.parents, func = name; + + if (typeof(name) == 'string') { + func = function(node) { + return node.nodeName == name; + }; + } + + for (i = 0; i < parents.length; i++) { + if (func(parents[i])) + return parents[i]; + } + }; + cm.setActive('visualaid', ed.hasVisual); - cm.setDisabled('undo', !ed.undoManager.hasUndo() && !ed.typing); - cm.setDisabled('redo', !ed.undoManager.hasRedo()); + t._updateUndoStatus(ed); cm.setDisabled('outdent', !ed.queryCommandState('Outdent')); - p = DOM.getParent(n, 'A'); + p = getParent('A'); if (c = cm.get('link')) { if (!p || !p.name) { c.setDisabled(!p && co); @@ -830,91 +983,123 @@ } if (c = cm.get('anchor')) { - c.setActive(!!p && p.name); - - if (tinymce.isWebKit) { - p = DOM.getParent(n, 'IMG'); - c.setActive(!!p && DOM.getAttrib(p, 'mce_name') == 'a'); - } + c.setActive(!co && !!p && p.name); } - p = DOM.getParent(n, 'IMG'); + p = getParent('IMG'); if (c = cm.get('image')) - c.setActive(!!p && n.className.indexOf('mceItem') == -1); + c.setActive(!co && !!p && n.className.indexOf('mceItem') == -1); if (c = cm.get('styleselect')) { - if (n.className) { - t._importClasses(); - c.select(n.className); - } else - c.select(); + t._importClasses(); + + formatNames = []; + each(c.items, function(item) { + formatNames.push(item.value); + }); + + matches = ed.formatter.matchAll(formatNames); + c.select(matches[0]); } if (c = cm.get('formatselect')) { - p = DOM.getParent(n, DOM.isBlock); + p = getParent(DOM.isBlock); if (p) c.select(p.nodeName.toLowerCase()); } - if (ed.settings.convert_fonts_to_spans) { - ed.dom.getParent(n, function(n) { - if (n.nodeName === 'SPAN') { - if (!cl && n.className) - cl = n.className; + // Find out current fontSize, fontFamily and fontClass + getParent(function(n) { + if (n.nodeName === 'SPAN') { + if (!cl && n.className) + cl = n.className; + } - if (!fz && n.style.fontSize) - fz = n.style.fontSize; + if (ed.dom.is(n, s.theme_advanced_font_selector)) { + if (!fz && n.style.fontSize) + fz = n.style.fontSize; - if (!fn && n.style.fontFamily) - fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase(); - } + if (!fn && n.style.fontFamily) + fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase(); + + if (!fc && n.style.color) + fc = n.style.color; - return false; + if (!bc && n.style.backgroundColor) + bc = n.style.backgroundColor; + } + + return false; + }); + + if (c = cm.get('fontselect')) { + c.select(function(v) { + return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn; }); + } - if (c = cm.get('fontselect')) { - c.select(function(v) { - return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn; - }); - } + // Select font size + if (c = cm.get('fontsizeselect')) { + // Use computed style + if (s.theme_advanced_runtime_fontsize && !fz && !cl) + fz = ed.dom.getStyle(n, 'fontSize', true); - if (c = cm.get('fontsizeselect')) { - c.select(function(v) { - if (v.fontSize && v.fontSize === fz) - return true; + c.select(function(v) { + if (v.fontSize && v.fontSize === fz) + return true; - if (v['class'] && v['class'] === cl) - return true; - }); + if (v['class'] && v['class'] === cl) + return true; + }); + } + + if (s.theme_advanced_show_current_color) { + function updateColor(controlId, color) { + if (c = cm.get(controlId)) { + if (!color) + color = c.settings.default_color; + if (color !== c.value) { + c.displayColor(color); + } + } } - } else { - if (c = cm.get('fontselect')) - c.select(ed.queryCommandValue('FontName')); + updateColor('forecolor', fc); + updateColor('backcolor', bc); + } - if (c = cm.get('fontsizeselect')) { - v = ed.queryCommandValue('FontSize'); - c.select(function(iv) { - return iv.fontSize == v; - }); - } + if (s.theme_advanced_show_current_color) { + function updateColor(controlId, color) { + if (c = cm.get(controlId)) { + if (!color) + color = c.settings.default_color; + if (color !== c.value) { + c.displayColor(color); + } + } + }; + + updateColor('forecolor', fc); + updateColor('backcolor', bc); } if (s.theme_advanced_path && s.theme_advanced_statusbar_location) { p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'}); + + if (t.statusKeyboardNavigation) { + t.statusKeyboardNavigation.destroy(); + t.statusKeyboardNavigation = null; + } + DOM.setHTML(p, ''); - ed.dom.getParent(n, function(n) { + getParent(function(n) { var na = n.nodeName.toLowerCase(), u, pi, ti = ''; - // Ignore non element and hidden elements - if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved'))) + // Ignore non element and bogus/hidden elements + if (n.nodeType != 1 || na === 'br' || n.getAttribute('data-mce-bogus') || DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')) return; - // Fake name - if (v = DOM.getAttrib(n, 'mce_name')) - na = v; - // Handle prefix if (tinymce.isIE && n.scopeName !== 'HTML') na = n.scopeName + ':' + na; @@ -950,9 +1135,6 @@ break; case 'font': - if (s.convert_fonts_to_spans) - na = 'span'; - if (v = DOM.getAttrib(n, 'face')) ti += 'font: ' + v + ' '; @@ -975,9 +1157,9 @@ ti += 'id: ' + v + ' '; if (v = n.className) { - v = v.replace(/(webkit-[\w\-]+|Apple-[\w\-]+|mceItem\w+|mceVisualAid)/g, ''); + v = v.replace(/\b\s*(webkit|mce|Apple-)\w+\s*\b/g, '') - if (v && v.indexOf('mceItem') == -1) { + if (v) { ti += 'class: ' + v + ' '; if (DOM.isBlock(n) || na == 'img' || na == 'span') @@ -992,14 +1174,25 @@ na = na.name; //u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');"; - pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na); + pi = DOM.create('a', {'href' : "javascript:;", role: 'button', onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na); if (p.hasChildNodes()) { - p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild); + p.insertBefore(DOM.create('span', {'aria-hidden': 'true'}, '\u00a0\u00bb '), p.firstChild); p.insertBefore(pi, p.firstChild); } else p.appendChild(pi); }, ed.getBody()); + + if (DOM.select('a', p).length > 0) { + t.statusKeyboardNavigation = new tinymce.ui.KeyboardNavigation({ + root: ed.id + "_path_row", + items: DOM.select('a', p), + excludeFromTabOrder: true, + onCancel: function() { + ed.focus(); + } + }, DOM); + } } }, @@ -1013,7 +1206,7 @@ var ed = this.editor; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/anchor.htm', + url : this.url + '/anchor.htm', width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)), height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)), inline : true @@ -1026,7 +1219,7 @@ var ed = this.editor; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/charmap.htm', + url : this.url + '/charmap.htm', width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)), height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)), inline : true @@ -1039,7 +1232,7 @@ var ed = this.editor; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/about.htm', + url : this.url + '/about.htm', width : 480, height : 380, inline : true @@ -1048,13 +1241,25 @@ }); }, + _mceShortcuts : function() { + var ed = this.editor; + ed.windowManager.open({ + url: this.url + '/shortcuts.htm', + width: 480, + height: 380, + inline: true + }, { + theme_url: this.url + }); + }, + _mceColorPicker : function(u, v) { var ed = this.editor; v = v || {}; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/color_picker.htm', + url : this.url + '/color_picker.htm', width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)), height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)), close_previous : false, @@ -1070,7 +1275,7 @@ var ed = this.editor; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/source_editor.htm', + url : this.url + '/source_editor.htm', width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)), height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)), inline : true, @@ -1089,7 +1294,7 @@ return; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/image.htm', + url : this.url + '/image.htm', width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)), height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)), inline : true @@ -1102,7 +1307,7 @@ var ed = this.editor; ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/link.htm', + url : this.url + '/link.htm', width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)), height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)), inline : true @@ -1150,4 +1355,4 @@ }); tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme); -}()); \ No newline at end of file +}(tinymce));