X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftiny_mce%2Ftiny_mce_src.js;h=64feb6663762f61f030fb01d3f7abf8f816900ac;hb=a8ce0eff2e9c97d6c0c878451f83a3759ec0d07f;hp=8c665b09535c46d2bdac3012c7b881f0948b6e2c;hpb=2797e21fbf023037fc706d85ab314e609a0d3a07;p=citadel.git diff --git a/webcit/tiny_mce/tiny_mce_src.js b/webcit/tiny_mce/tiny_mce_src.js index 8c665b095..64feb6663 100644 --- a/webcit/tiny_mce/tiny_mce_src.js +++ b/webcit/tiny_mce/tiny_mce_src.js @@ -5,9 +5,9 @@ var tinymce = { majorVersion : '3', - minorVersion : '4.5', + minorVersion : '4.9', - releaseDate : '2011-09-06', + releaseDate : '2012-02-23', _init : function() { var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; @@ -535,7 +535,7 @@ tinymce.create('tinymce.util.Dispatcher', { // And this is also more efficient for (i = 0; i 0 ? a : [c.scope]); if (s === false) break; @@ -578,7 +578,7 @@ tinymce.create('tinymce.util.Dispatcher', { // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri) u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something - u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u); + u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u); each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) { var s = u[i]; @@ -901,8 +901,11 @@ tinymce.create('tinymce.util.Dispatcher', { v = '{'; - for (i in o) - v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : ''; + for (i in o) { + if (o.hasOwnProperty(i)) { + v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : ''; + } + } return v + '}'; } @@ -923,6 +926,7 @@ tinymce.create('tinymce.util.Dispatcher', { }; })(); + tinymce.create('static tinymce.util.XHR', { send : function(o) { var x, t, w = window, c = 0; @@ -1038,11 +1042,17 @@ tinymce.create('static tinymce.util.XHR', { }()); (function(tinymce){ tinymce.VK = { - DELETE:46, - BACKSPACE:8 - + DELETE: 46, + BACKSPACE: 8, + ENTER: 13, + TAB: 9, + SPACEBAR: 32, + UP: 38, + DOWN: 40, + modifierPressed: function (e) { + return e.shiftKey || e.ctrlKey || e.altKey; + } } - })(tinymce); (function(tinymce) { @@ -1055,7 +1065,7 @@ tinymce.create('static tinymce.util.XHR', { var rng, blockElm, node, clonedSpan, isDelete; isDelete = e.keyCode == DELETE; - if (isDelete || e.keyCode == BACKSPACE) { + if ((isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) { e.preventDefault(); rng = selection.getRng(); @@ -1070,22 +1080,22 @@ tinymce.create('static tinymce.util.XHR', { if (blockElm) { node = blockElm.firstChild; + // Ignore empty text nodes + while (node && node.nodeType == 3 && node.nodeValue.length == 0) + node = node.nextSibling; + if (node && node.nodeName === 'SPAN') { clonedSpan = node.cloneNode(false); } } - // Do the backspace/delete actiopn + // Do the backspace/delete action ed.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null); // Find all odd apple-style-spans blockElm = dom.getParent(rng.startContainer, dom.isBlock); tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) { - var rng = dom.createRng(); - - // Set range selection before the span we are about to remove - rng.setStartBefore(span); - rng.setEndBefore(span); + var bm = selection.getBookmark(); if (clonedSpan) { dom.replace(clonedSpan.cloneNode(false), span, true); @@ -1094,45 +1104,184 @@ tinymce.create('static tinymce.util.XHR', { } // Restore the selection - selection.setRng(rng); + selection.moveToBookmark(bm); }); } }); }; function emptyEditorWhenDeleting(ed) { - ed.onKeyUp.add(function(ed, e) { - var keyCode = e.keyCode; + function serializeRng(rng) { + var body = ed.dom.create("body"); + var contents = rng.cloneContents(); + body.appendChild(contents); + return ed.selection.serializer.serialize(body, {format: 'html'}); + } + + function allContentsSelected(rng) { + var selection = serializeRng(rng); + + var allRng = ed.dom.createRng(); + allRng.selectNode(ed.getBody()); + + var allSelection = serializeRng(allRng); + return selection === allSelection; + } + + ed.onKeyDown.addToTop(function(ed, e) { + var keyCode = e.keyCode; if (keyCode == DELETE || keyCode == BACKSPACE) { - if (ed.dom.isEmpty(ed.getBody())) { + var rng = ed.selection.getRng(true); + if (!rng.collapsed && allContentsSelected(rng)) { ed.setContent('', {format : 'raw'}); ed.nodeChanged(); - return; + e.preventDefault(); } } }); + + }; + + function inputMethodFocus(ed) { + ed.dom.bind(ed.getDoc(), 'focusin', function() { + ed.selection.setRng(ed.selection.getRng()); + }); }; + + function removeHrOnBackspace(ed) { + ed.onKeyDown.add(function(ed, e) { + if (e.keyCode === BACKSPACE) { + if (ed.selection.isCollapsed() && ed.selection.getRng(true).startOffset === 0) { + var node = ed.selection.getNode(); + var previousSibling = node.previousSibling; + if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") { + ed.dom.remove(previousSibling); + tinymce.dom.Event.cancel(e); + } + } + } + }) + } + + function focusBody(ed) { + // Fix for a focus bug in FF 3.x where the body element + // wouldn't get proper focus if the user clicked on the HTML element + if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4 + ed.onMouseDown.add(function(ed, e) { + if (e.target.nodeName === "HTML") { + var body = ed.getBody(); + + // Blur the body it's focused but not correctly focused + body.blur(); + + // Refocus the body after a little while + setTimeout(function() { + body.focus(); + }, 0); + } + }); + } + }; + + function selectControlElements(ed) { + ed.onClick.add(function(ed, e) { + e = e.target; + + // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250 + // WebKit can't even do simple things like selecting an image + // Needs tobe the setBaseAndExtend or it will fail to select floated images + if (/^(IMG|HR)$/.test(e.nodeName)) + ed.selection.getSel().setBaseAndExtent(e, 0, e, 1); + + if (e.nodeName == 'A' && ed.dom.hasClass(e, 'mceItemAnchor')) + ed.selection.select(e); + + ed.nodeChanged(); + }); + }; + + function removeStylesOnPTagsInheritedFromHeadingTag(ed) { + ed.onKeyDown.add(function(ed, event) { + function checkInHeadingTag(ed) { + var currentNode = ed.selection.getNode(); + var headingTags = 'h1,h2,h3,h4,h5,h6'; + return ed.dom.is(currentNode, headingTags) || ed.dom.getParent(currentNode, headingTags) !== null; + } + + if (event.keyCode === VK.ENTER && !VK.modifierPressed(event) && checkInHeadingTag(ed)) { + setTimeout(function() { + var currentNode = ed.selection.getNode(); + if (ed.dom.is(currentNode, 'p')) { + ed.dom.setAttrib(currentNode, 'style', null); + // While tiny's content is correct after this method call, the content shown is not representative of it and needs to be 'repainted' + ed.execCommand('mceCleanup'); + } + }, 0); + } + }); + } + function selectionChangeNodeChanged(ed) { + var lastRng, selectionTimer; + + ed.dom.bind(ed.getDoc(), 'selectionchange', function() { + if (selectionTimer) { + clearTimeout(selectionTimer); + selectionTimer = 0; + } + + selectionTimer = window.setTimeout(function() { + var rng = ed.selection.getRng(); + + // Compare the ranges to see if it was a real change or not + if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) { + ed.nodeChanged(); + lastRng = rng; + } + }, 50); + }); + } + + function ensureBodyHasRoleApplication(ed) { + document.body.setAttribute("role", "application"); + } tinymce.create('tinymce.util.Quirks', { Quirks: function(ed) { - // Load WebKit specific fixed + // WebKit if (tinymce.isWebKit) { cleanupStylesWhenDeleting(ed); emptyEditorWhenDeleting(ed); + inputMethodFocus(ed); + selectControlElements(ed); + + // iOS + if (tinymce.isIDevice) { + selectionChangeNodeChanged(ed); + } } - // Load IE specific fixes + // IE if (tinymce.isIE) { + removeHrOnBackspace(ed); emptyEditorWhenDeleting(ed); + ensureBodyHasRoleApplication(ed); + removeStylesOnPTagsInheritedFromHeadingTag(ed) + } + + // Gecko + if (tinymce.isGecko) { + removeHrOnBackspace(ed); + focusBody(ed); } } }); })(tinymce); + (function(tinymce) { var namedEntities, baseEntities, reverseEntities, - attrsCharsRegExp = /[&<>\"\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, - textCharsRegExp = /[<>&\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, + attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, + textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, rawCharsRegExp = /[<>&\"\']/g, entityRegExp = /&(#x|#)?([\w]+);/g, asciiMap = { @@ -2118,7 +2267,7 @@ tinymce.html.Styles = function(settings, schema) { '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI '(?:\\/([^>]+)>)|' + // End element - '(?:([^\\s\\/<>]+)\\s*((?:[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*)>)' + // Start element + '(?:([^\\s\\/<>]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/)>)' + // Start element ')', 'g'); attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g; @@ -2648,6 +2797,10 @@ tinymce.html.Styles = function(settings, schema) { } } + // Keep comments + if (node.type === 8) + return false; + // Keep non whitespace text nodes if ((node.type === 3 && !whiteSpaceRegExp.test(node.value))) return false; @@ -3823,52 +3976,59 @@ tinymce.html.Writer = function(settings) { return this.run(e, function(e) { var s = t.settings; + var originalValue = e.getAttribute(n); + if (v !== null) { + switch (n) { + case "style": + if (!is(v, 'string')) { + each(v, function(v, n) { + t.setStyle(e, n, v); + }); - switch (n) { - case "style": - if (!is(v, 'string')) { - each(v, function(v, n) { - t.setStyle(e, n, v); - }); - - return; - } + return; + } - // No mce_style for elements with these since they might get resized by the user - if (s.keep_values) { - if (v && !t._isRes(v)) - e.setAttribute('data-mce-style', v, 2); - else - e.removeAttribute('data-mce-style', 2); - } + // No mce_style for elements with these since they might get resized by the user + if (s.keep_values) { + if (v && !t._isRes(v)) + e.setAttribute('data-mce-style', v, 2); + else + e.removeAttribute('data-mce-style', 2); + } - e.style.cssText = v; - break; + e.style.cssText = v; + break; - case "class": - e.className = v || ''; // Fix IE null bug - break; + case "class": + e.className = v || ''; // Fix IE null bug + break; - case "src": - case "href": - if (s.keep_values) { - if (s.url_converter) - v = s.url_converter.call(s.url_converter_scope || t, v, n, e); + case "src": + case "href": + if (s.keep_values) { + if (s.url_converter) + v = s.url_converter.call(s.url_converter_scope || t, v, n, e); - t.setAttrib(e, 'data-mce-' + n, v, 2); - } + t.setAttrib(e, 'data-mce-' + n, v, 2); + } - break; + break; - case "shape": - e.setAttribute('data-mce-style', v); - break; + case "shape": + e.setAttribute('data-mce-style', v); + break; + } } - if (is(v) && v !== null && v.length !== 0) e.setAttribute(n, '' + v, 2); else e.removeAttribute(n, 2); + + // fire onChangeAttrib event for attributes that have changed + if (tinyMCE.activeEditor && originalValue != v) { + var ed = tinyMCE.activeEditor; + ed.onSetAttrib.dispatch(ed, e, n, v); + } }); }, @@ -4512,6 +4672,10 @@ tinymce.html.Writer = function(settings) { } } + // Keep comment nodes + if (type == 8) + return false; + // Keep non whitespace text nodes if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue))) return false; @@ -4574,6 +4738,12 @@ tinymce.html.Writer = function(settings) { function trim(node) { var i, children = node.childNodes, type = node.nodeType; + function surroundedBySpans(node) { + var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN'; + var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN'; + return previousIsSpan && nextIsSpan; + } + if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark') return; @@ -4584,7 +4754,10 @@ tinymce.html.Writer = function(settings) { // Keep non whitespace text nodes if (type == 3 && node.nodeValue.length > 0) { // If parent element isn't a block or there isn't any useful contents for example "

" - if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0) + // Also keep text nodes with only spaces if surrounded by spans. + // eg. "

a b

" should keep space between a and b + var trimmedLength = tinymce.trim(node.nodeValue).length; + if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength == 0 && surroundedBySpans(node)) return; } else if (type == 1) { // If the only child is a bookmark then move it up @@ -4621,9 +4794,9 @@ tinymce.html.Writer = function(settings) { // Insert middle chunk if (re) - pa.replaceChild(re, e); - else - pa.insertBefore(e, pe); + pa.replaceChild(re, e); + else + pa.insertBefore(e, pe); // Insert after chunk pa.insertBefore(trim(aft), pe); @@ -5640,7 +5813,7 @@ tinymce.html.Writer = function(settings) { parent = node.parentNode; root = dom.getRoot().parentNode; - while (parent != root) { + while (parent != root && parent.nodeType !== 9) { children = parent.children; i = children.length; @@ -7123,6 +7296,12 @@ window.tinymce.dom.Sizzle = Sizzle; return; } + // When loaded asynchronously, the DOM Content may already be loaded + if (doc.readyState === 'complete') { + t._pageInit(win); + return; + } + // Use IE method if (doc.attachEvent) { doc.attachEvent("onreadystatechange", function() { @@ -7923,7 +8102,8 @@ window.tinymce.dom.Sizzle = Sizzle; } s.addRange(r); - t.selectedRange = s.getRangeAt(0); + // adding range isn't always successful so we need to check range count otherwise an exception can occur + t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null; } } else { // Is W3C Range @@ -8019,7 +8199,8 @@ window.tinymce.dom.Sizzle = Sizzle; if (sb && eb && sb != eb) { n = sb; - while ((n = n.nextSibling) && n != eb) { + var walker = new tinymce.dom.TreeWalker(sb, dom.getRoot()); + while ((n = walker.next()) && n != eb) { if (dom.isBlock(n)) bl.push(n); } @@ -8034,6 +8215,11 @@ window.tinymce.dom.Sizzle = Sizzle; normalize : function() { var self = this, rng, normalized; + // TODO: + // Retain selection direction. + // Lean left/right on Gecko for inline elements. + // Run this on mouse up/key up when the user manually moves the selection + // Normalize only on non IE browsers for now if (tinymce.isIE) return; @@ -8068,18 +8254,24 @@ window.tinymce.dom.Sizzle = Sizzle; if (node.nodeType === 3) { offset = start ? 0 : node.nodeValue.length - 1; container = node; + normalized = true; break; } - // Found a BR element that we can place the caret before - if (node.nodeName === 'BR') { + // Found a BR/IMG element that we can place the caret before + if (/^(BR|IMG)$/.test(node.nodeName)) { offset = dom.nodeIndex(node); container = node.parentNode; + + // Put caret after image when moving the end point + if (node.nodeName == "IMG" && !start) { + offset++; + } + + normalized = true; break; } } while (node = (start ? walker.next() : walker.prev())); - - normalized = true; } } } @@ -8094,7 +8286,7 @@ window.tinymce.dom.Sizzle = Sizzle; // Normalize the end points normalizeEndPoint(true); - if (rng.collapsed) + if (!rng.collapsed) normalizeEndPoint(); // Set the selection if it was normalized @@ -8206,12 +8398,11 @@ window.tinymce.dom.Sizzle = Sizzle; if (!settings.apply_source_formatting) settings.indent = false; - settings.remove_trailing_brs = true; - // Default DOM and Schema if they are undefined dom = dom || tinymce.DOM; schema = schema || new tinymce.html.Schema(settings); settings.entity_encoding = settings.entity_encoding || 'named'; + settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true; onPreProcess = new tinymce.util.Dispatcher(self); @@ -8275,8 +8466,8 @@ window.tinymce.dom.Sizzle = Sizzle; function trim(value) { return value.replace(/()/g, '\n') .replace(/^[\r\n]*|[\r\n]*$/g, '') - .replace(/^\s*(\/\/\s*|\]\]>|-->|\]\]-->)\s*$/g, ''); + .replace(/^\s*(()?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, ''); }; while (i--) { @@ -8425,7 +8616,7 @@ window.tinymce.dom.Sizzle = Sizzle; // Replace all BOM characters for now until we can find a better solution if (!args.cleanup) - args.content = args.content.replace(/\uFEFF/g, ''); + args.content = args.content.replace(/\uFEFF|\u200B/g, ''); // Post process if (!args.no_events) @@ -8719,6 +8910,24 @@ tinymce.dom.TreeWalker = function(start_node, root_node) { return; } + function exclude(nodes) { + var node; + + // First node is excluded + node = nodes[0]; + if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) { + nodes.splice(0, 1); + } + + // Last node is excluded + node = nodes[nodes.length - 1]; + if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) { + nodes.splice(nodes.length - 1, 1); + } + + return nodes; + }; + function collectSiblings(node, name, end_node) { var siblings = []; @@ -8748,7 +8957,7 @@ tinymce.dom.TreeWalker = function(start_node, root_node) { if (!next) siblings.reverse(); - callback(siblings); + callback(exclude(siblings)); } } }; @@ -8761,28 +8970,28 @@ tinymce.dom.TreeWalker = function(start_node, root_node) { if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)]; - // Find common ancestor and end points - ancestor = dom.findCommonAncestor(startContainer, endContainer); - // Same container if (startContainer == endContainer) - return callback([startContainer]); + return callback(exclude([startContainer])); + // Find common ancestor and end points + ancestor = dom.findCommonAncestor(startContainer, endContainer); + // Process left side for (node = startContainer; node; node = node.parentNode) { - if (node == endContainer) + if (node === endContainer) return walkBoundary(startContainer, ancestor, true); - if (node == ancestor) + if (node === ancestor) break; } // Process right side for (node = endContainer; node; node = node.parentNode) { - if (node == startContainer) + if (node === startContainer) return walkBoundary(endContainer, ancestor); - if (node == ancestor) + if (node === ancestor) break; } @@ -8801,48 +9010,46 @@ tinymce.dom.TreeWalker = function(start_node, root_node) { ); if (siblings.length) - callback(siblings); + callback(exclude(siblings)); // Walk right leaf walkBoundary(endContainer, endPoint); }; - /* this.split = function(rng) { + this.split = function(rng) { var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset; function splitText(node, offset) { - if (offset == node.nodeValue.length) - node.appendData(INVISIBLE_CHAR); - - node = node.splitText(offset); - - if (node.nodeValue === INVISIBLE_CHAR) - node.nodeValue = ''; - - return node; + return node.splitText(offset); }; // Handle single text node - if (startContainer == endContainer) { - if (startContainer.nodeType == 3) { - if (startOffset != 0) - startContainer = endContainer = splitText(startContainer, startOffset); - - if (endOffset - startOffset != startContainer.nodeValue.length) - splitText(startContainer, endOffset - startOffset); + if (startContainer == endContainer && startContainer.nodeType == 3) { + if (startOffset > 0 && startOffset < startContainer.nodeValue.length) { + endContainer = splitText(startContainer, startOffset); + startContainer = endContainer.previousSibling; + + if (endOffset > startOffset) { + endOffset = endOffset - startOffset; + startContainer = endContainer = splitText(endContainer, endOffset).previousSibling; + endOffset = endContainer.nodeValue.length; + startOffset = 0; + } else { + endOffset = 0; + } } } else { // Split startContainer text node if needed - if (startContainer.nodeType == 3 && startOffset != 0) { + if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) { startContainer = splitText(startContainer, startOffset); startOffset = 0; } // Split endContainer text node if needed - if (endContainer.nodeType == 3 && endOffset != endContainer.nodeValue.length) { + if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) { endContainer = splitText(endContainer, endOffset).previousSibling; endOffset = endContainer.nodeValue.length; } @@ -8855,7 +9062,7 @@ tinymce.dom.TreeWalker = function(start_node, root_node) { endOffset : endOffset }; }; -*/ + }; tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) { @@ -9025,6 +9232,7 @@ tinymce.dom.TreeWalker = function(start_node, root_node) { } }); })(tinymce); + (function(tinymce) { // Shorten class names var DOM = tinymce.DOM, is = tinymce.is; @@ -9560,7 +9768,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { // Internal functions _setupKeyboardNav : function(){ var contextMenu, menuItems, t=this; - contextMenu = DOM.select('#menu_' + t.id)[0]; + contextMenu = DOM.get('menu_' + t.id); menuItems = DOM.select('a[role=option]', 'menu_' + t.id); menuItems.splice(0,0,contextMenu); t.keyboardNav = new tinymce.ui.KeyboardNavigation({ @@ -9667,10 +9875,27 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { }, postRender : function() { - var t = this, s = t.settings; - + var t = this, s = t.settings, imgBookmark; + + // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so + // need to keep the selection in case the selection is lost + if (tinymce.isIE && t.editor) { + tinymce.dom.Event.add(t.id, 'mousedown', function(e) { + var nodeName = t.editor.selection.getNode().nodeName; + imgBookmark = nodeName === 'IMG' ? t.editor.selection.getBookmark() : null; + }); + } tinymce.dom.Event.add(t.id, 'click', function(e) { - if (!t.isDisabled()) + if (!t.isDisabled()) { + // restore the selection in case the selection is lost in IE + if (tinymce.isIE && t.editor && imgBookmark !== null) { + t.editor.selection.moveToBookmark(imgBookmark); + } + return s.onclick.call(s.scope, e); + } + }); + tinymce.dom.Event.add(t.id, 'keyup', function(e) { + if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR) return s.onclick.call(s.scope, e); }); } @@ -9706,7 +9931,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { return t.selectByIndex(-1); // Is string or number make function selector - if (va && va.call) + if (va && typeof(va)=="function") f = va; else { f = function(v) { @@ -9731,20 +9956,23 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { }, selectByIndex : function(idx) { - var t = this, e, o; + var t = this, e, o, label; if (idx != t.selectedIndex) { e = DOM.get(t.id + '_text'); + label = DOM.get(t.id + '_voiceDesc'); o = t.items[idx]; if (o) { t.selectedValue = o.value; t.selectedIndex = idx; DOM.setHTML(e, DOM.encode(o.title)); + DOM.setHTML(label, t.settings.title + " - " + o.title); DOM.removeClass(e, 'mceTitle'); DOM.setAttrib(t.id, 'aria-valuenow', o.title); } else { DOM.setHTML(e, DOM.encode(t.settings.title)); + DOM.setHTML(label, DOM.encode(t.settings.title)); DOM.addClass(e, 'mceTitle'); t.selectedValue = t.selectedIndex = null; DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title); @@ -9773,7 +10001,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { renderHTML : function() { var h = '', t = this, s = t.settings, cp = t.classPrefix; - h = ''; + h = ''; h += ''; h += ''; @@ -9869,6 +10097,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { if (o.value === undefined) { m.add({ title : o.title, + role : "option", 'class' : 'mceMenuItemTitle', onclick : function() { if (t.settings.onselect('') !== false) @@ -9877,6 +10106,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { }); } else { o.id = DOM.uniqueId(); + o.role= "option"; o.onclick = function() { if (t.settings.onselect(o.value) !== false) t.select(o.value); // Must be runned after @@ -9952,6 +10182,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { } }); })(tinymce); + (function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; @@ -9977,7 +10208,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { return t.selectByIndex(-1); // Is string or number make function selector - if (va && va.call) + if (va && typeof(va)=="function") f = va; else { f = function(v) { @@ -10210,8 +10441,8 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { h += ''; h += ''; - h = DOM.createHTML('table', {id : t.id, role: 'presentation', tabindex: '0', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h); - return DOM.createHTML('span', {role: 'button', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h); + h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h); + return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h); }, postRender : function() { @@ -10371,15 +10602,21 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { } n = DOM.add(tr, 'td'); - n = DOM.add(n, 'a', { - role : 'option', + var settings = { href : 'javascript:;', style : { backgroundColor : '#' + c }, 'title': t.editor.getLang('colors.' + c, c), 'data-mce-color' : '#' + c - }); + }; + + // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE. + if (!tinymce.isIE ) { + settings['role']= 'option'; + } + + n = DOM.add(n, 'a', settings); if (t.editor.forcedHighContrastMode) { n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' }); @@ -10485,7 +10722,8 @@ tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', { }, focus : function() { - this.keyNav.focus(); + var t = this; + dom.get(t.id).focus(); }, postRender : function() { @@ -10503,6 +10741,10 @@ tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', { root: t.id, items: items, onCancel: function() { + //Move focus if webkit so that navigation back will read the item. + if (tinymce.isWebKit) { + dom.get(t.editor.id+"_ifr").focus(); + } t.editor.focus(); }, excludeFromTabOrder: !t.settings.tab_focus_toolbar @@ -11010,7 +11252,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is, ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, - inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode; + inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode, VK = tinymce.VK; tinymce.create('tinymce.Editor', { Editor : function(id, s) { @@ -11034,6 +11276,8 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { 'onPostRender', + 'onLoad', + 'onInit', 'onRemove', @@ -11096,7 +11340,9 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { 'onVisualAid', - 'onSetProgressState' + 'onSetProgressState', + + 'onSetAttrib' ], function(e) { t[e] = new Dispatcher(t); }); @@ -11130,6 +11376,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { visual_table_class : 'mceItemTable', visual : 1, font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', + font_size_legacy_values : 'xx-small,small,medium,large,x-large,xx-large,300%', // See: http://www.w3.org/TR/CSS2/fonts.html#propdef-font-size apply_source_formatting : 1, directionality : 'ltr', forced_root_block : 'p', @@ -11430,6 +11677,13 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { t.iframeHTML += ''; + // Load the CSS by injecting them into the HTML this will reduce "flicker" + for (i = 0; i < t.contentCSS.length; i++) { + t.iframeHTML += ''; + } + + t.contentCSS = []; + bi = s.body_id || 'tinymce'; if (bi.indexOf('=') != -1) { bi = t.getParam('body_id', '', 'hash'); @@ -11442,12 +11696,12 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { bc = bc[t.id] || ''; } - t.iframeHTML += '
'; + t.iframeHTML += '
'; // Domain relaxing enabled, then set document domain if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) { // We need to write the contents here in IE since multiple writes messes up refresh button and back button - u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()'; + u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()'; } // Create iframe @@ -11481,24 +11735,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Setup iframe body if (!isIE || !tinymce.relaxedDomain) { - // Fix for a focus bug in FF 3.x where the body element - // wouldn't get proper focus if the user clicked on the HTML element - if (isGecko && !Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4 - t.onMouseDown.add(function(ed, e) { - if (e.target.nodeName === "HTML") { - var body = t.getBody(); - - // Blur the body it's focused but not correctly focused - body.blur(); - - // Refocus the body after a little while - setTimeout(function() { - body.focus(); - }, 0); - } - }); - } - d.open(); d.write(t.iframeHTML); d.close(); @@ -11574,10 +11810,12 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Keep scripts from executing t.parser.addNodeFilter('script', function(nodes, name) { - var i = nodes.length; + var i = nodes.length, node; - while (i--) - nodes[i].attr('type', 'mce-text/javascript'); + while (i--) { + node = nodes[i]; + node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript')); + } }); t.parser.addNodeFilter('#cdata', function(nodes, name) { @@ -11926,7 +12164,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { } t._refreshContentEditable(); - selection.normalize(); // Is not content editable if (!ce) @@ -12126,9 +12363,9 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus)) t.focus(); - o = {}; - t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o); - if (o.terminate) + a = extend({}, a); + t.onBeforeExecCommand.dispatch(t, cmd, ui, val, a); + if (a.terminate) return false; // Command callback @@ -12685,21 +12922,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { t.onMouseDown.add(setOpts); } - t.onClick.add(function(ed, e) { - e = e.target; - - // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250 - // WebKit can't even do simple things like selecting an image - // Needs tobe the setBaseAndExtend or it will fail to select floated images - if (tinymce.isWebKit && e.nodeName == 'IMG') - t.selection.getSel().setBaseAndExtent(e, 0, e, 1); - - if (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor')) - t.selection.select(e); - - t.nodeChanged(); - }); - // Add node change handlers t.onMouseUp.add(t.nodeChanged); //t.onClick.add(t.nodeChanged); @@ -12713,30 +12935,32 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Add block quote deletion handler t.onKeyDown.add(function(ed, e) { - // Was the BACKSPACE key pressed? - if (e.keyCode != 8) + if (e.keyCode != VK.BACKSPACE) + return; + + var rng = ed.selection.getRng(); + if (!rng.collapsed) return; - var n = ed.selection.getRng().startContainer; - var offset = ed.selection.getRng().startOffset; + var n = rng.startContainer; + var offset = rng.startOffset; while (n && n.nodeType && n.nodeType != 1 && n.parentNode) n = n.parentNode; - + // Is the cursor at the beginning of a blockquote? if (n && n.parentNode && n.parentNode.tagName === 'BLOCKQUOTE' && n.parentNode.firstChild == n && offset == 0) { // Remove the blockquote ed.formatter.toggle('blockquote', null, n.parentNode); // Move the caret to the beginning of n - var rng = ed.selection.getRng(); rng.setStart(n, 0); rng.setEnd(n, 0); ed.selection.setRng(rng); ed.selection.collapse(false); } }); - + // Add reset handler @@ -12873,7 +13097,8 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { t.undoManager.add(); }; - dom.bind(t.getDoc(), 'focusout', function(e) { + var focusLostFunc = tinymce.isGecko ? 'blur' : 'focusout'; + dom.bind(t.getDoc(), focusLostFunc, function(e){ if (!t.removed && t.undoManager.typing) addUndo(); }); @@ -12933,21 +13158,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { }); } - // Fire a nodeChanged when the selection is changed on WebKit this fixes selection issues on iOS5 - // It only fires the nodeChange event every 50ms since it would other wise update the UI when you type and it hogs the CPU - if (tinymce.isWebKit) { - dom.bind(t.getDoc(), 'selectionchange', function() { - if (t.selectionTimer) { - clearTimeout(t.selectionTimer); - t.selectionTimer = 0; - } - - t.selectionTimer = window.setTimeout(function() { - t.nodeChanged(); - }, 50); - }); - } - // Bug fix for FireFox keeping styles from end of selection instead of start. if (tinymce.isGecko) { function getAttributeApplyFunction() { @@ -12957,11 +13167,11 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { var target = t.selection.getStart(); if (target !== t.getBody()) { - t.dom.removeAllAttribs(target); + t.dom.setAttrib(target, "style", null); - each(template, function(attr) { - target.setAttributeNode(attr.cloneNode(true)); - }); + each(template, function(attr) { + target.setAttributeNode(attr.cloneNode(true)); + }); } }; } @@ -13273,6 +13483,8 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { var parser, serializer, parentNode, rootNode, fragment, args, marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement; + //selection.normalize(); + // Setup parser and serializer parser = editor.parser; serializer = new tinymce.html.Serializer({}, editor.schema); @@ -13499,7 +13711,14 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { addCommands({ // Override justify commands 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { - return isFormatMatch('align' + command.substring(7)); + var name = 'align' + command.substring(7); + // Use Formatter.matchNode instead of Formatter.match so that we don't match on parent node. This fixes bug where for both left + // and right align buttons can be active. This could occur when selected nodes have align right and the parent has align left. + var nodes = selection.isCollapsed() ? [selection.getNode()] : selection.getSelectedBlocks(); + var matches = tinymce.map(nodes, function(node) { + return !!formatter.matchNode(node, name); + }); + return tinymce.inArray(matches, TRUE) !== -1; }, 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) { @@ -14456,7 +14675,12 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { id = t.prefix + id; - if (ed.settings.use_native_selects) + + function useNativeListForAccessibility(ed) { + return ed.settings.use_accessible_selects && !tinymce.isGecko + } + + if (ed.settings.use_native_selects || useNativeListForAccessibility(ed)) c = new tinymce.ui.NativeListBox(id, s); else { cls = cc || t._cls.listbox || tinymce.ui.ListBox; @@ -14805,8 +15029,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { MCE_ATTR_RE = /^(src|href|style)$/, FALSE = false, TRUE = true, - undefined, - pendingFormats = {apply : [], remove : []}; + undefined; function isArray(obj) { return obj instanceof Array; @@ -14817,7 +15040,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { }; function isCaretNode(node) { - return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline'); + return node.nodeType === 1 && node.id === '_mce_caret'; }; // Public functions @@ -14892,30 +15115,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { function apply(name, vars, node) { var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed(); - function moveStart(rng) { - var container = rng.startContainer, - offset = rng.startOffset, - walker, node; - - // Move startContainer/startOffset in to a suitable node - if (container.nodeType == 1 || container.nodeValue === "") { - container = container.nodeType == 1 ? container.childNodes[offset] : container; - - // Might fail if the offset is behind the last element in it's container - if (container) { - walker = new TreeWalker(container, container.parentNode); - for (node = walker.current(); node; node = walker.next()) { - if (node.nodeType == 3 && !isWhiteSpaceNode(node)) { - rng.setStart(node, 0); - break; - } - } - } - } - - return rng; - }; - function setElementFormat(elm, fmt) { fmt = fmt || format; @@ -15022,7 +15221,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { } }; - function applyRngStyle(rng, bookmark) { + function applyRngStyle(rng, bookmark, node_specific) { var newWrappers = [], wrapName, wrapElm; // Setup wrapper element @@ -15086,7 +15285,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Is it valid to wrap this item if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) && - !(node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279)) { + !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node)) { // Start wrapping if (!currentWrapElm) { // Wrap the node @@ -15241,12 +15440,14 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { if (format) { if (node) { - rng = dom.createRng(); - - rng.setStartBefore(node); - rng.setEndAfter(node); - - applyRngStyle(expandRng(rng, formatList)); + if (node.nodeType) { + rng = dom.createRng(); + rng.setStartBefore(node); + rng.setEndAfter(node); + applyRngStyle(expandRng(rng, formatList), null, true); + } else { + applyRngStyle(node, null, true); + } } else { if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) { // Obtain selection node before selection is unselected by applyRngStyle() @@ -15264,7 +15465,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { } selection.moveToBookmark(bookmark); - selection.setRng(moveStart(selection.getRng(TRUE))); + moveStart(selection.getRng(TRUE)); ed.nodeChanged(); } else performCaretAction('apply', name, vars); @@ -15274,44 +15475,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { function remove(name, vars, node) { var formatList = get(name), format = formatList[0], bookmark, i, rng; - function moveStart(rng) { - var container = rng.startContainer, - offset = rng.startOffset, - walker, node, nodes, tmpNode; - - // Convert text node into index if possible - if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) { - container = container.parentNode; - offset = nodeIndex(container) + 1; - } - - // Move startContainer/startOffset in to a suitable node - if (container.nodeType == 1) { - nodes = container.childNodes; - container = nodes[Math.min(offset, nodes.length - 1)]; - walker = new TreeWalker(container); - - // If offset is at end of the parent node walk to the next one - if (offset > nodes.length - 1) - walker.next(); - - for (node = walker.current(); node; node = walker.next()) { - if (node.nodeType == 3 && !isWhiteSpaceNode(node)) { - // IE has a "neat" feature where it moves the start node into the closest element - // we can avoid this by inserting an element before it and then remove it after we set the selection - tmpNode = dom.create('a', null, INVISIBLE_CHAR); - node.parentNode.insertBefore(tmpNode, node); - - // Set selection and remove tmpNode - rng.setStart(node, 0); - selection.setRng(rng); - dom.remove(tmpNode); - - return; - } - } - } - }; // Merges the styles for each node function process(node) { @@ -15460,10 +15623,15 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Handle node if (node) { - rng = dom.createRng(); - rng.setStartBefore(node); - rng.setEndAfter(node); - removeRngStyle(rng); + if (node.nodeType) { + rng = dom.createRng(); + rng.setStartBefore(node); + rng.setEndAfter(node); + removeRngStyle(rng); + } else { + removeRngStyle(node); + } + return; } @@ -15473,13 +15641,18 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { selection.moveToBookmark(bookmark); // Check if start element still has formatting then we are at: "text|text" and need to move the start into the next text node - if (match(name, vars, selection.getStart())) { + if (format.inline && match(name, vars, selection.getStart())) { moveStart(selection.getRng(true)); } ed.nodeChanged(); } else performCaretAction('remove', name, vars); + + // When you remove formatting from a table cell in WebKit (cell, not the contents of a cell) there is a rendering issue with column width + if (tinymce.isWebKit) { + ed.execCommand('mceCleanup'); + } }; function toggle(name, vars, node) { @@ -15554,7 +15727,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { }; function match(name, vars, node) { - var startNode, i; + var startNode; function matchParents(node) { // Find first node with similar format settings @@ -15570,21 +15743,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { if (node) return matchParents(node); - // Check pending formats - if (selection.isCollapsed()) { - for (i = pendingFormats.apply.length - 1; i >= 0; i--) { - if (pendingFormats.apply[i].name == name) - return true; - } - - for (i = pendingFormats.remove.length - 1; i >= 0; i--) { - if (pendingFormats.remove[i].name == name) - return false; - } - - return matchParents(selection.getNode()); - } - // Check selected node node = selection.getNode(); if (matchParents(node)) @@ -15603,33 +15761,6 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { function matchAll(names, vars) { var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name; - // If the selection is collapsed then check pending formats - if (selection.isCollapsed()) { - for (ni = 0; ni < names.length; ni++) { - // If the name is to be removed, then stop it from being added - for (i = pendingFormats.remove.length - 1; i >= 0; i--) { - name = names[ni]; - - if (pendingFormats.remove[i].name == name) { - checkedMap[name] = true; - break; - } - } - } - - // If the format is to be applied - for (i = pendingFormats.apply.length - 1; i >= 0; i--) { - for (ni = 0; ni < names.length; ni++) { - name = names[ni]; - - if (!checkedMap[name] && pendingFormats.apply[i].name == name) { - checkedMap[name] = true; - matchedFormatNames.push(name); - } - } - } - } - // Check start of selection for formats startElement = selection.getStart(); dom.getParent(startElement, function(node) { @@ -15738,7 +15869,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { }; function isWhiteSpaceNode(node) { - return node && node.nodeType === 3 && /^([\s\r\n]+|)$/.test(node.nodeValue); + return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue); }; function wrap(node, name, attrs) { @@ -15754,31 +15885,42 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { var startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, - endOffset = rng.endOffset, sibling, lastIdx, leaf; + endOffset = rng.endOffset, sibling, lastIdx, leaf, endPoint; // This function walks up the tree if there is no siblings before/after the node - function findParentContainer(container, child_name, sibling_name, root) { - var parent, child; - - root = root || dom.getRoot(); + function findParentContainer(start) { + var container, parent, child, sibling, siblingName; - for (;;) { - // Check if we can move up are we at root level or body level - parent = container.parentNode; + container = parent = start ? startContainer : endContainer; + siblingName = start ? 'previousSibling' : 'nextSibling'; + root = dom.getRoot(); - // Stop expanding on block elements or root depending on format - if (parent == root || (!format[0].block_expand && isBlock(parent))) + // If it's a text node and the offset is inside the text + if (container.nodeType == 3 && !isWhiteSpaceNode(container)) { + if (start ? startOffset > 0 : endOffset < container.nodeValue.length) { return container; + } + } - for (sibling = parent[child_name]; sibling && sibling != container; sibling = sibling[sibling_name]) { - if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) - return container; + for (;;) { + // Stop expanding on block elements + if (!format[0].block_expand && isBlock(parent)) + return parent; + + // Walk left/right + for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) { + if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling)) { + return parent; + } + } - if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling)) - return container; + // Check if we can move up are we at root level or body level + if (parent.parentNode == root) { + container = parent; + break; } - container = container.parentNode; + parent = parent.parentNode; } return container; @@ -15816,23 +15958,103 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { } // Exclude bookmark nodes if possible - if (isBookmarkNode(startContainer.parentNode)) - startContainer = startContainer.parentNode; - - if (isBookmarkNode(startContainer)) + if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) { + startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode; startContainer = startContainer.nextSibling || startContainer; - if (isBookmarkNode(endContainer.parentNode)) { - endOffset = dom.nodeIndex(endContainer); - endContainer = endContainer.parentNode; + if (startContainer.nodeType == 3) + startOffset = 0; } - if (isBookmarkNode(endContainer) && endContainer.previousSibling) { - endContainer = endContainer.previousSibling; - endOffset = endContainer.length; + if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) { + endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode; + endContainer = endContainer.previousSibling || endContainer; + + if (endContainer.nodeType == 3) + endOffset = endContainer.length; } if (format[0].inline) { + if (rng.collapsed) { + function findWordEndPoint(container, offset, start) { + var walker, node, pos, lastTextNode; + + function findSpace(node, offset) { + var pos, pos2, str = node.nodeValue; + + if (typeof(offset) == "undefined") { + offset = start ? str.length : 0; + } + + if (start) { + pos = str.lastIndexOf(' ', offset); + pos2 = str.lastIndexOf('\u00a0', offset); + pos = pos > pos2 ? pos : pos2; + + // Include the space on remove to avoid tag soup + if (pos !== -1 && !remove) { + pos++; + } + } else { + pos = str.indexOf(' ', offset); + pos2 = str.indexOf('\u00a0', offset); + pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2; + } + + return pos; + }; + + if (container.nodeType === 3) { + pos = findSpace(container, offset); + + if (pos !== -1) { + return {container : container, offset : pos}; + } + + lastTextNode = container; + } + + // Walk the nodes inside the block + walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody()); + while (node = walker[start ? 'prev' : 'next']()) { + if (node.nodeType === 3) { + lastTextNode = node; + pos = findSpace(node); + + if (pos !== -1) { + return {container : node, offset : pos}; + } + } else if (isBlock(node)) { + break; + } + } + + if (lastTextNode) { + if (start) { + offset = 0; + } else { + offset = lastTextNode.length; + } + + return {container: lastTextNode, offset: offset}; + } + } + + // Expand left to closest word boundery + endPoint = findWordEndPoint(startContainer, startOffset, true); + if (endPoint) { + startContainer = endPoint.container; + startOffset = endPoint.offset; + } + + // Expand right to closest word boundery + endPoint = findWordEndPoint(endContainer, endOffset); + if (endPoint) { + endContainer = endPoint.container; + endOffset = endPoint.offset; + } + } + // Avoid applying formatting to a trailing space. leaf = findLeaf(endContainer, endOffset); if (leaf.node) { @@ -15846,19 +16068,25 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { endContainer = leaf.node; endContainer.splitText(leaf.offset - 1); } else if (leaf.node.previousSibling) { - endContainer = leaf.node.previousSibling; + // TODO: Figure out why this is in here + //endContainer = leaf.node.previousSibling; } } } } - + // Move start/end point up the tree if the leaves are sharp and if we are in different containers // Example * becomes !: !

*texttext*

! // This will reduce the number of wrapper elements that needs to be created // Move start point up the tree if (format[0].inline || format[0].block_expand) { - startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling'); - endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling'); + if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) { + startContainer = findParentContainer(true); + } + + if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) { + endContainer = findParentContainer(); + } } // Expand start/end container to matching selector @@ -15932,10 +16160,10 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Non block element then try to expand up the leaf if (format[0].block) { if (!isBlock(startContainer)) - startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling'); + startContainer = findParentContainer(true); if (!isBlock(endContainer)) - endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling'); + endContainer = findParentContainer(); } } @@ -16228,7 +16456,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { }; function getContainer(rng, start) { - var container, offset, lastIdx; + var container, offset, lastIdx, walker; container = rng[start ? 'startContainer' : 'endContainer']; offset = rng[start ? 'startOffset' : 'endOffset']; @@ -16242,142 +16470,318 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { container = container.childNodes[offset > lastIdx ? lastIdx : offset]; } + // If start text node is excluded then walk to the next node + if (container.nodeType === 3 && start && offset >= container.nodeValue.length) { + container = new TreeWalker(container, ed.getBody()).next() || container; + } + + // If end text node is excluded then walk to the previous node + if (container.nodeType === 3 && !start && offset == 0) { + container = new TreeWalker(container, ed.getBody()).prev() || container; + } + return container; }; function performCaretAction(type, name, vars) { - var i, currentPendingFormats = pendingFormats[type], - otherPendingFormats = pendingFormats[type == 'apply' ? 'remove' : 'apply']; + var invisibleChar, caretContainerId = '_mce_caret', debug = ed.settings.caret_debug; + + // Setup invisible character use zero width space on Gecko since it doesn't change the heigt of the container + invisibleChar = tinymce.isGecko ? '\u200B' : INVISIBLE_CHAR; + + // Creates a caret container bogus element + function createCaretContainer(fill) { + var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''}); + + if (fill) { + caretContainer.appendChild(ed.getDoc().createTextNode(invisibleChar)); + } + + return caretContainer; + }; + + function isCaretContainerEmpty(node, nodes) { + while (node) { + if ((node.nodeType === 3 && node.nodeValue !== invisibleChar) || node.childNodes.length > 1) { + return false; + } - function hasPending() { - return pendingFormats.apply.length || pendingFormats.remove.length; + // Collect nodes + if (nodes && node.nodeType === 1) { + nodes.push(node); + } + + node = node.firstChild; + } + + return true; }; + + // Returns any parent caret container element + function getParentCaretContainer(node) { + while (node) { + if (node.id === caretContainerId) { + return node; + } - function resetPending() { - pendingFormats.apply = []; - pendingFormats.remove = []; + node = node.parentNode; + } }; - function perform(caret_node) { - // Apply pending formats - each(pendingFormats.apply.reverse(), function(item) { - apply(item.name, item.vars, caret_node); + // Finds the first text node in the specified node + function findFirstTextNode(node) { + var walker; - // Colored nodes should be underlined so that the color of the underline matches the text color. - if (item.name === 'forecolor' && item.vars.value) - processUnderlineAndColor(caret_node.parentNode); - }); + if (node) { + walker = new TreeWalker(node, node); - // Remove pending formats - each(pendingFormats.remove.reverse(), function(item) { - remove(item.name, item.vars, caret_node); - }); + for (node = walker.current(); node; node = walker.next()) { + if (node.nodeType === 3) { + return node; + } + } + } + }; + + // Removes the caret container for the specified node or all on the current document + function removeCaretContainer(node, move_caret) { + var child, rng; + + if (!node) { + node = getParentCaretContainer(selection.getStart()); + + if (!node) { + while (node = dom.get(caretContainerId)) { + removeCaretContainer(node, false); + } + } + } else { + rng = selection.getRng(true); + + if (isCaretContainerEmpty(node)) { + if (move_caret !== false) { + rng.setStartBefore(node); + rng.setEndBefore(node); + } + + dom.remove(node); + } else { + child = findFirstTextNode(node); + + if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) { + child = child.deleteData(0, 1); + } + + dom.remove(node, 1); + } + + selection.setRng(rng); + } + }; + + // Applies formatting to the caret postion + function applyCaretFormat() { + var rng, caretContainer, textNode, offset, bookmark, container, text; + + rng = selection.getRng(true); + offset = rng.startOffset; + container = rng.startContainer; + text = container.nodeValue; - dom.remove(caret_node, 1); - resetPending(); + caretContainer = getParentCaretContainer(selection.getStart()); + if (caretContainer) { + textNode = findFirstTextNode(caretContainer); + } + + // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character + if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) { + // Get bookmark of caret position + bookmark = selection.getBookmark(); + + // Collapse bookmark range (WebKit) + rng.collapse(true); + + // Expand the range to the closest word and split it at those points + rng = expandRng(rng, get(name)); + rng = rangeUtils.split(rng); + + // Apply the format to the range + apply(name, vars, rng); + + // Move selection back to caret position + selection.moveToBookmark(bookmark); + } else { + if (!caretContainer || textNode.nodeValue !== invisibleChar) { + caretContainer = createCaretContainer(true); + textNode = caretContainer.firstChild; + + rng.insertNode(caretContainer); + offset = 1; + + apply(name, vars, caretContainer); + } else { + apply(name, vars, caretContainer); + } + + // Move selection to text node + selection.setCursorLocation(textNode, offset); + } }; - // Check if it already exists then ignore it - for (i = currentPendingFormats.length - 1; i >= 0; i--) { - if (currentPendingFormats[i].name == name) + function removeCaretFormat() { + var rng = selection.getRng(true), container, offset, bookmark, + hasContentAfter, node, formatNode, parents = [], i, caretContainer; + + container = rng.startContainer; + offset = rng.startOffset; + node = container; + + if (container.nodeType == 3) { + if (offset != container.nodeValue.length || container.nodeValue === invisibleChar) { + hasContentAfter = true; + } + + node = node.parentNode; + } + + while (node) { + if (matchNode(node, name, vars)) { + formatNode = node; + break; + } + + if (node.nextSibling) { + hasContentAfter = true; + } + + parents.push(node); + node = node.parentNode; + } + + // Node doesn't have the specified format + if (!formatNode) { return; - } + } - currentPendingFormats.push({name : name, vars : vars}); + // Is there contents after the caret then remove the format on the element + if (hasContentAfter) { + // Get bookmark of caret position + bookmark = selection.getBookmark(); - // Check if it's in the other type, then remove it - for (i = otherPendingFormats.length - 1; i >= 0; i--) { - if (otherPendingFormats[i].name == name) - otherPendingFormats.splice(i, 1); - } + // Collapse bookmark range (WebKit) + rng.collapse(true); - // Pending apply or remove formats - if (hasPending()) { - ed.getDoc().execCommand('FontName', false, 'mceinline'); - pendingFormats.lastRng = selection.getRng(); + // Expand the range to the closest word and split it at those points + rng = expandRng(rng, get(name), true); + rng = rangeUtils.split(rng); - // IE will convert the current word - each(dom.select('font,span'), function(node) { - var bookmark; + // Remove the format from the range + remove(name, vars, rng); - if (isCaretNode(node)) { - bookmark = selection.getBookmark(); - perform(node); - selection.moveToBookmark(bookmark); - ed.nodeChanged(); + // Move selection back to caret position + selection.moveToBookmark(bookmark); + } else { + caretContainer = createCaretContainer(); + + node = caretContainer; + for (i = parents.length - 1; i >= 0; i--) { + node.appendChild(parents[i].cloneNode(false)); + node = node.firstChild; + } + + // Insert invisible character into inner most format element + node.appendChild(dom.doc.createTextNode(invisibleChar)); + node = node.firstChild; + + // Insert caret container after the formated node + dom.insertAfter(caretContainer, formatNode); + + // Move selection to text node + selection.setCursorLocation(node, 1); + } + }; + + // Only bind the caret events once + if (!self._hasCaretEvents) { + // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements + ed.onBeforeGetContent.addToTop(function() { + var nodes = [], i; + + if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) { + // Mark children + i = nodes.length; + while (i--) { + dom.setAttrib(nodes[i], 'data-mce-bogus', '1'); + } } }); - // Only register listeners once if we need to - if (!pendingFormats.isListening && hasPending()) { - pendingFormats.isListening = true; - function performPendingFormat(node, textNode) { - var rng = dom.createRng(); - perform(node); + // Remove caret container on mouse up and on key up + tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) { + ed[name].addToTop(function() { + removeCaretContainer(); + }); + }); - rng.setStart(textNode, textNode.nodeValue.length); - rng.setEnd(textNode, textNode.nodeValue.length); - selection.setRng(rng); - ed.nodeChanged(); + // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys + ed.onKeyDown.addToTop(function(ed, e) { + var keyCode = e.keyCode; + + if (keyCode == 8 || keyCode == 37 || keyCode == 39) { + removeCaretContainer(getParentCaretContainer(selection.getStart())); } - var enterKeyPressed = false; + }); - each('onKeyDown,onKeyUp,onKeyPress,onMouseUp'.split(','), function(event) { - ed[event].addToTop(function(ed, e) { - if (e.keyCode==13 && !e.shiftKey) { - enterKeyPressed = true; - return; - } - // Do we have pending formats and is the selection moved has moved - if (hasPending() && !tinymce.dom.RangeUtils.compareRanges(pendingFormats.lastRng, selection.getRng())) { - var foundCaret = false; - each(dom.select('font,span'), function(node) { - var textNode, rng; - - // Look for marker - if (isCaretNode(node)) { - foundCaret = true; - textNode = node.firstChild; - - // Find the first text node within node - while (textNode && textNode.nodeType != 3) - textNode = textNode.firstChild; - - if (textNode) - performPendingFormat(node, textNode); - else - dom.remove(node); - } - }); - - // no caret - so we are - if (enterKeyPressed && !foundCaret) { - var node = selection.getNode(); - var textNode = node; - - // Find the first text node within node - while (textNode && textNode.nodeType != 3) - textNode = textNode.firstChild; - if (textNode) { - node=textNode.parentNode; - while (!isBlock(node)){ - node=node.parentNode; - } - performPendingFormat(node, textNode); - } - } + self._hasCaretEvents = true; + } - // Always unbind and clear pending styles on keyup - if (e.type == 'keyup' || e.type == 'mouseup') { - resetPending(); - enterKeyPressed=false; - } - } - }); - }); + // Do apply or remove caret format + if (type == "apply") { + applyCaretFormat(); + } else { + removeCaretFormat(); + } + }; + + function moveStart(rng) { + var container = rng.startContainer, + offset = rng.startOffset, + walker, node, nodes, tmpNode; + + // Convert text node into index if possible + if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) { + container = container.parentNode; + offset = nodeIndex(container) + 1; + } + + // Move startContainer/startOffset in to a suitable node + if (container.nodeType == 1) { + nodes = container.childNodes; + container = nodes[Math.min(offset, nodes.length - 1)]; + walker = new TreeWalker(container); + + // If offset is at end of the parent node walk to the next one + if (offset > nodes.length - 1) + walker.next(); + + for (node = walker.current(); node; node = walker.next()) { + if (node.nodeType == 3 && !isWhiteSpaceNode(node)) { + // IE has a "neat" feature where it moves the start node into the closest element + // we can avoid this by inserting an element before it and then remove it after we set the selection + tmpNode = dom.create('a', null, INVISIBLE_CHAR); + node.parentNode.insertBefore(tmpNode, node); + + // Set selection and remove tmpNode + rng.setStart(node, 0); + selection.setRng(rng); + dom.remove(tmpNode); + + return; + } } } }; + }; })(tinymce); @@ -16385,7 +16789,7 @@ tinymce.onAddEditor.add(function(tinymce, ed) { var filters, fontSizes, dom, settings = ed.settings; if (settings.inline_styles) { - fontSizes = tinymce.explode(settings.font_size_style_values); + fontSizes = tinymce.explode(settings.font_size_legacy_values); function replaceWithSpan(node, styles) { tinymce.each(styles, function(value, name) {