X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Fjs%2Ftiny_mce%2Fthemes%2Fadvanced%2Feditor_template_src.js;fp=program%2Fjs%2Ftiny_mce%2Fthemes%2Fadvanced%2Feditor_template_src.js;h=279ca359ce3d9f6246367d3df302ccbc94b1b12e;hb=4212156c5c79d2f58342feb0d3ed1893f177bcab;hp=21eb259a205a9da0d3c46f24deb13b0b309b8ff9;hpb=e8a0682b96f5b7f297e58d101735ba20a0cc3a89;p=roundcube.git diff --git a/program/js/tiny_mce/themes/advanced/editor_template_src.js b/program/js/tiny_mce/themes/advanced/editor_template_src.js index 21eb259..279ca35 100644 --- a/program/js/tiny_mce/themes/advanced/editor_template_src.js +++ b/program/js/tiny_mce/themes/advanced/editor_template_src.js @@ -1,8 +1,11 @@ /** - * $Id: editor_template_src.js 1045 2009-03-04 20:03:18Z 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(tinymce) { @@ -97,11 +100,8 @@ 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)) @@ -121,7 +121,8 @@ // Init editor ed.onInit.add(function() { - ed.onNodeChange.add(t._nodeChanged, t); + if (!ed.settings.readonly) + 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")); @@ -194,36 +195,93 @@ }, _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; - } else - ed.execCommand('mceSetCSSClass', 0, v); + 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 (matches[0] == name) + ed.formatter.remove(name); + else + 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++); - c.onPostRender.add(function(ed, n) { - if (!c.NativeListBox) { + ed.formatter.register(name, { + inline : 'span', + classes : val, + selector : '*' + }); + + ctrl.add(t.editor.translate(key), name); + } + }); + } + }); + + // 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 +291,26 @@ }); } - 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) { + ed.execCommand('FontName', false, v); + + // Fake selection, execCommand will fire a nodeChange and update the selection + c.select(function(sv) { + return v == sv; + }); + + 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 +324,21 @@ 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) + 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; + }); + + return false; // No auto select }}); if (c) { @@ -473,7 +549,7 @@ }, resizeTo : function(w, h) { - var ed = this.editor, s = ed.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr'), dh; + 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 +557,18 @@ 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) + DOM.setStyle(ifr, 'width', e.clientWidth); + } }, destroy : function() { @@ -700,99 +782,53 @@ 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); - - // Resize placeholder - if (s.theme_advanced_resize_horizontal) - p.style.width = w + 'px'; + var mouseMoveHandler1, mouseMoveHandler2, + mouseUpHandler1, mouseUpHandler2, + startX, startY, startWidth, startHeight, width, height, ifrElm; - p.style.height = h + 'px'; + function resizeOnMove(e) { + width = startWidth + (e.screenX - startX); + height = startHeight + (e.screenY - startY); - return Event.cancel(e); - }); - - 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'; - - c.style.height = Math.max(10, r.h + r.dy) + 'px'; - ifr.style.height = Math.max(10, ifr.clientHeight + r.dy) + '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); + // Store away the size if (s.theme_advanced_resizing_use_cookie) { Cookie.setHash("TinyMCE_" + ed.id + "_size", { - cw : r.w + r.dx, - ch : r.h + r.dy + cw : width, + ch : height }); } - }); + }; + + e.preventDefault(); + + // 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 +837,34 @@ n = tb = null; }, - _nodeChanged : function(ed, cm, n, co) { - var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn; - - if (s.readonly) - return; + _nodeChanged : function(ed, cm, n, co, ob) { + var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn, 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()); 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); @@ -831,82 +879,78 @@ 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'); - } } - p = DOM.getParent(n, 'IMG'); + p = getParent('IMG'); if (c = cm.get('image')) c.setActive(!!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 (!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(); + } + + return false; + }); - 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; - }); - } - } else { - if (c = cm.get('fontselect')) - c.select(ed.queryCommandValue('FontName')); - - if (c = cm.get('fontsizeselect')) { - v = ed.queryCommandValue('FontSize'); - c.select(function(iv) { - return iv.fontSize == v; - }); - } + if (v['class'] && v['class'] === cl) + return true; + }); } 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'}); DOM.setHTML(p, ''); - ed.dom.getParent(n, function(n) { + getParent(function(n) { var na = n.nodeName.toLowerCase(), u, pi, ti = ''; + /*if (n.getAttribute('_mce_bogus')) + return; +*/ // Ignore non element and hidden elements if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved'))) return; @@ -950,9 +994,6 @@ break; case 'font': - if (s.convert_fonts_to_spans) - na = 'span'; - if (v = DOM.getAttrib(n, 'face')) ti += 'font: ' + v + ' '; @@ -975,9 +1016,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')