commit 84f59ab451c2cfd38ab4955c609580fe1630524a parent 938ed9d04ec5a78249d7261169e8158189e55cdc Author: Dan Stillman <dstillman@zotero.org> Date: Sat, 9 Oct 2010 08:04:25 +0000 Run TinyMCE as content rather than chrome (and now without needing any modifications) Also upgraded to latest version Popup windows currently show location and status bars, which needs to be fixed Diffstat:
30 files changed, 5841 insertions(+), 5622 deletions(-)
diff --git a/chrome/skin/default/zotero/tinymce/integration-content.css b/chrome/content/zotero/tinymce/css/integration-content.css diff --git a/chrome/skin/default/zotero/tinymce/note-content.css b/chrome/content/zotero/tinymce/css/note-content.css diff --git a/chrome/content/zotero/tinymce/css/note-ui.css b/chrome/content/zotero/tinymce/css/note-ui.css @@ -0,0 +1,35 @@ +html, body { + height: 100%; + margin: 0; +} +#tinymce_parent { + display: block; + height: 100%; +} +#tinymce_tbl { + height: 100% !important; + width: 100% !important; +} + +table.mceLayout > tbody > tr.mceLast { + position: absolute; + display: block; + top: 54px; + bottom: 2px; + left: 1px; + right: 1px; +} + +td.mceIframeContainer { + display: block; + height: 100% !important; + width: 100% !important; +} +#tinymce_ifr { + height: 100% !important; + width: 100% !important; +} + +#tinymce_formatselect_text { + width: 65px; +} diff --git a/chrome/content/zotero/tinymce/note.html b/chrome/content/zotero/tinymce/note.html @@ -2,7 +2,7 @@ <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TinyMCE</title> -<link type="text/css" rel="stylesheet" href="chrome://zotero/skin/tinymce/note-ui.css"/> +<link type="text/css" rel="stylesheet" href="css/note-ui.css"/> <script type="text/javascript" src="tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ @@ -10,7 +10,7 @@ body_id : "zotero-tinymce-note", mode : "none", theme : "advanced", - content_css : "chrome://zotero/skin/tinymce/note-content.css", + content_css : "css/note-content.css", button_tile_map : true, language : "en", // TODO: localize entity_encoding : "raw", diff --git a/chrome/content/zotero/tinymce/plugins/contextmenu/editor_plugin.js b/chrome/content/zotero/tinymce/plugins/contextmenu/editor_plugin.js @@ -1,31 +1,74 @@ /** - * $Id: editor_plugin_src.js 848 2008-05-15 11:54:40Z spocke $ + * editor_plugin_src.js * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * Contains modifications by Zotero (commented) + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ (function() { var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM; + /** + * This plugin a context menu to TinyMCE editor instances. + * + * @class tinymce.plugins.ContextMenu + */ tinymce.create('tinymce.plugins.ContextMenu', { + /** + * Initializes the plugin, this will be executed after the plugin has been created. + * This call is done before the editor instance has finished it's initialization so use the onInit event + * of the editor instance to intercept that event. + * + * @method init + * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. + * @param {string} url Absolute URL to where the plugin is located. + */ init : function(ed) { - var t = this; + var t = this, lastRng; t.editor = ed; + + /** + * This event gets fired when the context menu is shown. + * + * @event onContextMenu + * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event. + * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed. + */ t.onContextMenu = new tinymce.util.Dispatcher(this); ed.onContextMenu.add(function(ed, e) { if (!e.ctrlKey) { + // Restore the last selection since it was removed + if (lastRng) + ed.selection.setRng(lastRng); + t._getMenu(ed).showMenu(e.clientX, e.clientY); - Event.add(ed.getDoc(), 'click', hide); + Event.add(ed.getDoc(), 'click', function(e) { + hide(ed, e); + }); Event.cancel(e); } }); - function hide() { + ed.onRemove.add(function() { + if (t._menu) + t._menu.removeAll(); + }); + + function hide(ed, e) { + lastRng = null; + + // Since the contextmenu event moves + // the selection we need to store it away + if (e && e.button == 2) { + lastRng = ed.selection.getRng(); + return; + } + if (t._menu) { t._menu.removeAll(); t._menu.destroy(); @@ -37,6 +80,13 @@ ed.onKeyDown.add(hide); }, + /** + * Returns information about the plugin as a name/value array. + * The current keys are longname, author, authorurl, infourl and version. + * + * @method getInfo + * @return {Object} Name/value array containing information about the plugin. + */ getInfo : function() { return { longname : 'Contextmenu', @@ -76,9 +126,8 @@ m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'}); } - // Disabled by Dan S./Zotero - //m.addSeparator(); - //m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); + m.addSeparator(); + m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); m.addSeparator(); am = m.addMenu({title : 'contextmenu.align'}); @@ -95,4 +144,4 @@ // Register plugin tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu); -})(); +})(); +\ No newline at end of file diff --git a/chrome/content/zotero/tinymce/plugins/paste/editor_plugin.js b/chrome/content/zotero/tinymce/plugins/paste/editor_plugin.js @@ -1,16 +1,46 @@ /** - * $Id: editor_plugin_src.js 1143 2009-05-27 10:05:31Z spocke $ + * editor_plugin_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() { - var each = tinymce.each; + var each = tinymce.each, + entities = null, + defs = { + paste_auto_cleanup_on_paste : true, + paste_block_drop : false, + paste_retain_style_properties : "none", + paste_strip_class_attributes : "mso", + paste_remove_spans : false, + paste_remove_styles : false, + paste_remove_styles_if_webkit : true, + paste_convert_middot_lists : true, + paste_convert_headers_to_strong : false, + paste_dialog_width : "450", + paste_dialog_height : "400", + paste_text_use_dialog : false, + paste_text_sticky : false, + paste_text_notifyalways : false, + paste_text_linebreaktype : "p", + paste_text_replacements : [ + [/\u2026/g, "..."], + [/[\x93\x94\u201c\u201d]/g, '"'], + [/[\x60\x91\x92\u2018\u2019]/g, "'"] + ] + }; + + function getParam(ed, name) { + return ed.getParam(name, defs[name]); + } tinymce.create('tinymce.plugins.PastePlugin', { init : function(ed, url) { - var t = this, cb; + var t = this; t.editor = ed; t.url = url; @@ -33,8 +63,12 @@ ed.execCallback('paste_postprocess', pl, o); }); + // Initialize plain text flag + ed.pasteAsPlainText = false; + // This function executes the process handlers and inserts the contents - function process(o) { + // force_rich overrides plain text mode set by user, important for pasting with execCommand + function process(o, force_rich) { var dom = ed.dom; // Execute pre process handlers @@ -49,29 +83,69 @@ // Serialize content o.content = ed.serializer.serialize(o.node, {getInner : 1}); - // Insert cleaned content. We need to handle insertion of contents containing block elements separately - if (/<(p|h[1-6]|ul|ol)/.test(o.content)) + // Plain text option active? + if ((!force_rich) && (ed.pasteAsPlainText)) { + t._insertPlainText(ed, dom, o.content); + + if (!getParam(ed, "paste_text_sticky")) { + ed.pasteAsPlainText = false; + ed.controlManager.setActive("pastetext", false); + } + } else if (/<(p|h[1-6]|ul|ol)/.test(o.content)) { + // Handle insertion of contents containing block elements separately t._insertBlockContent(ed, dom, o.content); - else + } else { t._insert(o.content); - }; + } + } // Add command for external usage ed.addCommand('mceInsertClipboardContent', function(u, o) { - process(o); + process(o, true); }); + if (!getParam(ed, "paste_text_use_dialog")) { + ed.addCommand('mcePasteText', function(u, v) { + var cookie = tinymce.util.Cookie; + + ed.pasteAsPlainText = !ed.pasteAsPlainText; + ed.controlManager.setActive('pastetext', ed.pasteAsPlainText); + + if ((ed.pasteAsPlainText) && (!cookie.get("tinymcePasteText"))) { + if (getParam(ed, "paste_text_sticky")) { + ed.windowManager.alert(ed.translate('paste.plaintext_mode_sticky')); + } else { + ed.windowManager.alert(ed.translate('paste.plaintext_mode_sticky')); + } + + if (!getParam(ed, "paste_text_notifyalways")) { + cookie.set("tinymcePasteText", "1", new Date(new Date().getFullYear() + 1, 12, 31)) + } + } + }); + } + + ed.addButton('pastetext', {title: 'paste.paste_text_desc', cmd: 'mcePasteText'}); + ed.addButton('selectall', {title: 'paste.selectall_desc', cmd: 'selectall'}); + // This function grabs the contents from the clipboard by adding a // hidden div and placing the caret inside it and after the browser paste // is done it grabs that contents and processes that function grabContent(e) { var n, or, rng, sel = ed.selection, dom = ed.dom, body = ed.getBody(), posY; + // Check if browser supports direct plaintext access + if (ed.pasteAsPlainText && (e.clipboardData || dom.doc.dataTransfer)) { + e.preventDefault(); + process({content : (e.clipboardData || dom.doc.dataTransfer).getData('Text')}, true); + return; + } + if (dom.get('_mcePaste')) return; // Create container to paste into - n = dom.add(body, 'div', {id : '_mcePaste'}, ' '); + n = dom.add(body, 'div', {id : '_mcePaste', 'class' : 'mcePaste'}, '\uFEFF<br _mce_bogus="1">'); // If contentEditable mode we need to find out the position of the closest element if (body != ed.getDoc().body) @@ -98,11 +172,28 @@ // Remove container dom.remove(n); + // Check if the contents was changed, if it wasn't then clipboard extraction failed probably due + // to IE security settings so we pass the junk though better than nothing right + if (n.innerHTML === '\uFEFF') { + ed.execCommand('mcePasteWord'); + e.preventDefault(); + return; + } + // Process contents process({content : n.innerHTML}); + // Block the real paste event return tinymce.dom.Event.cancel(e); } else { + function block(e) { + e.preventDefault(); + }; + + // Block mousedown and click to prevent selection change + dom.bind(ed.getDoc(), 'mousedown', block); + dom.bind(ed.getDoc(), 'keydown', block); + or = ed.selection.getRng(); // Move caret into hidden div @@ -114,32 +205,55 @@ // Wait a while and grab the pasted contents window.setTimeout(function() { - var n = dom.get('_mcePaste'), h; + var h = '', nl = dom.select('div.mcePaste'); + + // WebKit will split the div into multiple ones so this will loop through then all and join them to get the whole HTML string + each(nl, function(n) { + var child = n.firstChild; + + // WebKit inserts a DIV container with lots of odd styles + if (child && child.nodeName == 'DIV' && child.style.marginTop && child.style.backgroundColor) { + dom.remove(child, 1); + } + + // WebKit duplicates the divs so we need to remove them + each(dom.select('div.mcePaste', n), function(n) { + dom.remove(n, 1); + }); - // Webkit clones the _mcePaste div for some odd reason so this will ensure that we get the real new div not the old empty one - n.id = '_mceRemoved'; - dom.remove(n); - n = dom.get('_mcePaste') || n; + // Remove apply style spans + each(dom.select('span.Apple-style-span', n), function(n) { + dom.remove(n, 1); + }); - // Grab the HTML contents - // We need to look for a apple style wrapper on webkit it also adds a div wrapper if you copy/paste the body of the editor - // It's amazing how strange the contentEditable mode works in WebKit - h = (dom.select('> span.Apple-style-span div', n)[0] || dom.select('> span.Apple-style-span', n)[0] || n).innerHTML; + // Remove bogus br elements + each(dom.select('br[_mce_bogus]', n), function(n) { + dom.remove(n); + }); - // Remove hidden div and restore selection - dom.remove(n); + h += n.innerHTML; + }); + + // Remove the nodes + each(nl, function(n) { + dom.remove(n); + }); // Restore the old selection if (or) sel.setRng(or); process({content : h}); + + // Unblock events ones we got the contents + dom.unbind(ed.getDoc(), 'mousedown', block); + dom.unbind(ed.getDoc(), 'keydown', block); }, 0); } - }; + } // Check if we should use the new auto process method - if (ed.getParam('paste_auto_cleanup_on_paste', true)) { + if (getParam(ed, "paste_auto_cleanup_on_paste")) { // Is it's Opera or older FF use key handler if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) { ed.onKeyDown.add(function(ed, e) { @@ -155,7 +269,7 @@ } // Block all drag/drop events - if (ed.getParam('paste_block_drop')) { + if (getParam(ed, "paste_block_drop")) { ed.onInit.add(function() { ed.dom.bind(ed.getBody(), ['dragend', 'dragover', 'draggesture', 'dragdrop', 'drop', 'drag'], function(e) { e.preventDefault(); @@ -181,10 +295,15 @@ }, _preProcess : function(pl, o) { - var ed = this.editor, h = o.content, process, stripClass; - //console.log('Before preprocess:' + o.content); + var ed = this.editor, + h = o.content, + grep = tinymce.grep, + explode = tinymce.explode, + trim = tinymce.trim, + len, stripClass; + function process(items) { each(items, function(v) { // Remove or replace @@ -193,71 +312,205 @@ else h = h.replace(v[0], v[1]); }); - }; - - // Process away some basic content - process([ - /^\s*( )+/g, // nbsp entities at the start of contents - /( |<br[^>]*>)+\s*$/g // nbsp entities at the end of contents - ]); + } // Detect Word content and process it more aggressive - if (/(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/.test(h) || o.wordContent) { - o.wordContent = true; // Mark the pasted contents as word specific content + if (/class="?Mso|style="[^"]*\bmso-|w:WordDocument/i.test(h) || o.wordContent) { + o.wordContent = true; // Mark the pasted contents as word specific content //console.log('Word contents detected.'); - if (ed.getParam('paste_convert_middot_lists', true)) { + // Process away some basic content + process([ + /^\s*( )+/gi, // entities at the start of contents + /( |<br[^>]*>)+\s*$/gi // entities at the end of contents + ]); + + if (getParam(ed, "paste_convert_headers_to_strong")) { + h = h.replace(/<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>"); + } + + if (getParam(ed, "paste_convert_middot_lists")) { process([ - [/<!--\[if !supportLists\]-->/gi, '$&__MCE_ITEM__'], // Convert supportLists to a list item marker - [/(<span[^>]+:\s*symbol[^>]+>)/gi, '$1__MCE_ITEM__'], // Convert symbol spans to list items - [/(<span[^>]+mso-list:[^>]+>)/gi, '$1__MCE_ITEM__'] // Convert mso-list to item marker + [/<!--\[if !supportLists\]-->/gi, '$&__MCE_ITEM__'], // Convert supportLists to a list item marker + [/(<span[^>]+(?:mso-list:|:\s*symbol)[^>]+>)/gi, '$1__MCE_ITEM__'] // Convert mso-list and symbol spans to item markers ]); } process([ - /<!--[\s\S]+?-->/gi, // Word comments - /<\/?(img|font|meta|link|style|div|v:\w+)[^>]*>/gi, // Remove some tags including VML content - /<\\?\?xml[^>]*>/gi, // XML namespace declarations - /<\/?o:[^>]*>/gi, // MS namespaced elements <o:tag> - / (id|name|language|type|on\w+|v:\w+)=\"([^\"]*)\"/gi, // on.., class, style and language attributes with quotes - / (id|name|language|type|on\w+|v:\w+)=(\w+)/gi, // on.., class, style and language attributes without quotes (IE) - [/<(\/?)s>/gi, '<$1strike>'], // Convert <s> into <strike> for line-though - /<script[^>]+>[\s\S]*?<\/script>/gi, // All scripts elements for msoShowComment for example - [/ /g, '\u00a0'] // Replace nsbp entites to char since it's easier to handle + // Word comments like conditional comments etc + /<!--[\s\S]+?-->/gi, + + // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content, MS Office namespaced tags, and a few other tags + /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi, + + // Convert <s> into <strike> for line-though + [/<(\/?)s>/gi, "<$1strike>"], + + // Replace nsbp entites to char since it's easier to handle + [/ /gi, "\u00a0"] ]); + // Remove bad attributes, with or without quotes, ensuring that attribute text is really inside a tag. + // If JavaScript had a RegExp look-behind, we could have integrated this with the last process() array and got rid of the loop. But alas, it does not, so we cannot. + do { + len = h.length; + h = h.replace(/(<[a-z][^>]*\s)(?:id|name|language|type|on\w+|\w+:\w+)=(?:"[^"]*"|\w+)\s?/gi, "$1"); + } while (len != h.length); + // Remove all spans if no styles is to be retained - if (!ed.getParam('paste_retain_style_properties')) { - process([ - /<\/?(span)[^>]*>/gi - ]); - } - } + if (getParam(ed, "paste_retain_style_properties").replace(/^none$/i, "").length == 0) { + h = h.replace(/<\/?span[^>]*>/gi, ""); + } else { + // We're keeping styles, so at least clean them up. + // CSS Reference: http://msdn.microsoft.com/en-us/library/aa155477.aspx - // Allow for class names to be retained if desired; either all, or just the ones from Word - // Note that the paste_strip_class_attributes: 'none, verify_css_classes: true is also a good variation. - stripClass = ed.getParam('paste_strip_class_attributes', 'all'); - if (stripClass != 'none') { - if (stripClass == 'all') { - process([ - / class=\"([^\"]*)\"/gi, // class attributes with quotes - / class=(\w+)/gi // class attributes without quotes (IE) - ]); - } else { // Only strip the 'mso*' classes process([ - / class=\"(mso[^\"]*)\"/gi, // class attributes with quotes - / class=(mso\w+)/gi // class attributes without quotes (IE) + // Convert <span style="mso-spacerun:yes">___</span> to string of alternating breaking/non-breaking spaces of same length + [/<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi, + function(str, spaces) { + return (spaces.length > 0)? spaces.replace(/./, " ").slice(Math.floor(spaces.length/2)).split("").join("\u00a0") : ""; + } + ], + + // Examine all styles: delete junk, transform some, and keep the rest + [/(<[a-z][^>]*)\sstyle="([^"]*)"/gi, + function(str, tag, style) { + var n = [], + i = 0, + s = explode(trim(style).replace(/"/gi, "'"), ";"); + + // Examine each style definition within the tag's style attribute + each(s, function(v) { + var name, value, + parts = explode(v, ":"); + + function ensureUnits(v) { + return v + ((v !== "0") && (/\d$/.test(v)))? "px" : ""; + } + + if (parts.length == 2) { + name = parts[0].toLowerCase(); + value = parts[1].toLowerCase(); + + // Translate certain MS Office styles into their CSS equivalents + switch (name) { + case "mso-padding-alt": + case "mso-padding-top-alt": + case "mso-padding-right-alt": + case "mso-padding-bottom-alt": + case "mso-padding-left-alt": + case "mso-margin-alt": + case "mso-margin-top-alt": + case "mso-margin-right-alt": + case "mso-margin-bottom-alt": + case "mso-margin-left-alt": + case "mso-table-layout-alt": + case "mso-height": + case "mso-width": + case "mso-vertical-align-alt": + n[i++] = name.replace(/^mso-|-alt$/g, "") + ":" + ensureUnits(value); + return; + + case "horiz-align": + n[i++] = "text-align:" + value; + return; + + case "vert-align": + n[i++] = "vertical-align:" + value; + return; + + case "font-color": + case "mso-foreground": + n[i++] = "color:" + value; + return; + + case "mso-background": + case "mso-highlight": + n[i++] = "background:" + value; + return; + + case "mso-default-height": + n[i++] = "min-height:" + ensureUnits(value); + return; + + case "mso-default-width": + n[i++] = "min-width:" + ensureUnits(value); + return; + + case "mso-padding-between-alt": + n[i++] = "border-collapse:separate;border-spacing:" + ensureUnits(value); + return; + + case "text-line-through": + if ((value == "single") || (value == "double")) { + n[i++] = "text-decoration:line-through"; + } + return; + + case "mso-zero-height": + if (value == "yes") { + n[i++] = "display:none"; + } + return; + } + + // Eliminate all MS Office style definitions that have no CSS equivalent by examining the first characters in the name + if (/^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?!align|decor|indent|trans)|top-bar|version|vnd|word-break)/.test(name)) { + return; + } + + // If it reached this point, it must be a valid CSS style + n[i++] = name + ":" + parts[1]; // Lower-case name, but keep value case + } + }); + + // If style attribute contained any valid styles the re-write it; otherwise delete style attribute. + if (i > 0) { + return tag + ' style="' + n.join(';') + '"'; + } else { + return tag; + } + } + ] ]); } } - // Remove spans option - if (ed.getParam('paste_remove_spans')) { + // Replace headers with <strong> + if (getParam(ed, "paste_convert_headers_to_strong")) { process([ - /<\/?(span)[^>]*>/gi + [/<h[1-6][^>]*>/gi, "<p><strong>"], + [/<\/h[1-6][^>]*>/gi, "</strong></p>"] ]); } + // Class attribute options are: leave all as-is ("none"), remove all ("all"), or remove only those starting with mso ("mso"). + // Note:- paste_strip_class_attributes: "none", verify_css_classes: true is also a good variation. + stripClass = getParam(ed, "paste_strip_class_attributes"); + + if (stripClass !== "none") { + function removeClasses(match, g1) { + if (stripClass === "all") + return ''; + + var cls = grep(explode(g1.replace(/^(["'])(.*)\1$/, "$2"), " "), + function(v) { + return (/^(?!mso)/i.test(v)); + } + ); + + return cls.length ? ' class="' + cls.join(" ") + '"' : ''; + }; + + h = h.replace(/ class="([^"]+)"/gi, removeClasses); + h = h.replace(/ class=(\w+)/gi, removeClasses); + } + + // Remove spans option + if (getParam(ed, "paste_remove_spans")) { + h = h.replace(/<\/?span[^>]*>/gi, ""); + } + //console.log('After preprocess:' + h); o.content = h; @@ -276,56 +529,58 @@ dom.remove(a, 1); }); - if (t.editor.getParam('paste_convert_middot_lists', true)) + if (getParam(ed, "paste_convert_middot_lists")) { t._convertLists(pl, o); + } // Process styles - styleProps = ed.getParam('paste_retain_style_properties'); // retained properties + styleProps = getParam(ed, "paste_retain_style_properties"); // retained properties - // If string property then split it - if (tinymce.is(styleProps, 'string')) - styleProps = tinymce.explode(styleProps); + // Process only if a string was specified and not equal to "all" or "*" + if ((tinymce.is(styleProps, "string")) && (styleProps !== "all") && (styleProps !== "*")) { + styleProps = tinymce.explode(styleProps.replace(/^none$/i, "")); - // Retains some style properties - each(dom.select('*', o.node), function(el) { - var newStyle = {}, npc = 0, i, sp, sv; - - // Store a subset of the existing styles - if (styleProps) { - for (i = 0; i < styleProps.length; i++) { - sp = styleProps[i]; - sv = dom.getStyle(el, sp); - - if (sv) { - newStyle[sp] = sv; - npc++; + // Retains some style properties + each(dom.select('*', o.node), function(el) { + var newStyle = {}, npc = 0, i, sp, sv; + + // Store a subset of the existing styles + if (styleProps) { + for (i = 0; i < styleProps.length; i++) { + sp = styleProps[i]; + sv = dom.getStyle(el, sp); + + if (sv) { + newStyle[sp] = sv; + npc++; + } } } - } - // Remove all of the existing styles - dom.setAttrib(el, 'style', ''); + // Remove all of the existing styles + dom.setAttrib(el, 'style', ''); - if (styleProps && npc > 0) - dom.setStyles(el, newStyle); // Add back the stored subset of styles - else // Remove empty span tags that do not have class attributes - if (el.nodeName == 'SPAN' && !el.className) - dom.remove(el, true); - }); + if (styleProps && npc > 0) + dom.setStyles(el, newStyle); // Add back the stored subset of styles + else // Remove empty span tags that do not have class attributes + if (el.nodeName == 'SPAN' && !el.className) + dom.remove(el, true); + }); + } } // Remove all style information or only specifically on WebKit to avoid the style bug on that browser - if (ed.getParam("paste_remove_styles") || (ed.getParam("paste_remove_styles_if_webkit") && tinymce.isWebKit)) { + if (getParam(ed, "paste_remove_styles") || (getParam(ed, "paste_remove_styles_if_webkit") && tinymce.isWebKit)) { each(dom.select('*[style]', o.node), function(el) { el.removeAttribute('style'); - el.removeAttribute('mce_style'); + el.removeAttribute('_mce_style'); }); } else { if (tinymce.isWebKit) { // We need to compress the styles on WebKit since if you paste <img border="0" /> it will become <img border="0" style="... lots of junk ..." /> // Removing the mce_style that contains the real value will force the Serializer engine to compress the styles each(dom.select('*', o.node), function(el) { - el.removeAttribute('mce_style'); + el.removeAttribute('_mce_style'); }); } } @@ -417,7 +672,7 @@ * This logic can be improved so text nodes at the start/end remain in the start/end block elements */ _insertBlockContent : function(ed, dom, content) { - var parentBlock, marker, sel = ed.selection, last, elm, vp, y, elmHeight; + var parentBlock, marker, sel = ed.selection, last, elm, vp, y, elmHeight, markerId = 'mce_marker'; function select(n) { var r; @@ -431,14 +686,15 @@ sel.select(n, 1); sel.collapse(false); } - }; + } // Insert a marker for the caret position - this._insert('<span id="_marker"> </span>', 1); - marker = dom.get('_marker'); - parentBlock = dom.getParent(marker, 'p,h1,h2,h3,h4,h5,h6,ul,ol'); + this._insert('<span id="' + markerId + '"></span>', 1); + marker = dom.get(markerId); + parentBlock = dom.getParent(marker, 'p,h1,h2,h3,h4,h5,h6,ul,ol,th,td'); - if (parentBlock) { + // If it's a parent block but not a table cell + if (parentBlock && !/TD|TH/.test(parentBlock.nodeName)) { // Split parent block marker = dom.split(parentBlock, marker); @@ -455,7 +711,9 @@ sel.collapse(0); } - dom.remove('_marker'); // Remove marker if it's left + // Remove marker if it's left + while (elm = dom.get(markerId)) + dom.remove(elm); // Get element, position and height elm = sel.getStart(); @@ -472,10 +730,10 @@ * Inserts the specified contents at the caret position. */ _insert : function(h, skip_undo) { - var ed = this.editor; + var ed = this.editor, r = ed.selection.getRng(); - // First delete the contents seems to work better on WebKit - if (!ed.selection.isCollapsed()) + // First delete the contents seems to work better on WebKit when the selection spans multiple list items or multiple table cells. + if (!ed.selection.isCollapsed() && r.startContainer != r.endContainer) ed.getDoc().execCommand('Delete', false, null); // It's better to use the insertHTML method on Gecko since it will combine paragraphs correctly before inserting the contents @@ -483,30 +741,212 @@ }, /** + * Instead of the old plain text method which tried to re-create a paste operation, the + * new approach adds a plain text mode toggle switch that changes the behavior of paste. + * This function is passed the same input that the regular paste plugin produces. + * It performs additional scrubbing and produces (and inserts) the plain text. + * This approach leverages all of the great existing functionality in the paste + * plugin, and requires minimal changes to add the new functionality. + * Speednet - June 2009 + */ + _insertPlainText : function(ed, dom, h) { + var i, len, pos, rpos, node, breakElms, before, after, + w = ed.getWin(), + d = ed.getDoc(), + sel = ed.selection, + is = tinymce.is, + inArray = tinymce.inArray, + linebr = getParam(ed, "paste_text_linebreaktype"), + rl = getParam(ed, "paste_text_replacements"); + + function process(items) { + each(items, function(v) { + if (v.constructor == RegExp) + h = h.replace(v, ""); + else + h = h.replace(v[0], v[1]); + }); + }; + + if ((typeof(h) === "string") && (h.length > 0)) { + if (!entities) + entities = ("34,quot,38,amp,39,apos,60,lt,62,gt," + ed.serializer.settings.entities).split(","); + + // If HTML content with line-breaking tags, then remove all cr/lf chars because only tags will break a line + if (/<(?:p|br|h[1-6]|ul|ol|dl|table|t[rdh]|div|blockquote|fieldset|pre|address|center)[^>]*>/i.test(h)) { + process([ + /[\n\r]+/g + ]); + } else { + // Otherwise just get rid of carriage returns (only need linefeeds) + process([ + /\r+/g + ]); + } + + process([ + [/<\/(?:p|h[1-6]|ul|ol|dl|table|div|blockquote|fieldset|pre|address|center)>/gi, "\n\n"], // Block tags get a blank line after them + [/<br[^>]*>|<\/tr>/gi, "\n"], // Single linebreak for <br /> tags and table rows + [/<\/t[dh]>\s*<t[dh][^>]*>/gi, "\t"], // Table cells get tabs betweem them + /<[a-z!\/?][^>]*>/gi, // Delete all remaining tags + [/ /gi, " "], // Convert non-break spaces to regular spaces (remember, *plain text*) + [ + // HTML entity + /&(#\d+|[a-z0-9]{1,10});/gi, + + // Replace with actual character + function(e, s) { + if (s.charAt(0) === "#") { + return String.fromCharCode(s.slice(1)); + } + else { + return ((e = inArray(entities, s)) > 0)? String.fromCharCode(entities[e-1]) : " "; + } + } + ], + [/(?:(?!\n)\s)*(\n+)(?:(?!\n)\s)*/gi, "$1"], // Cool little RegExp deletes whitespace around linebreak chars. + [/\n{3,}/g, "\n\n"], // Max. 2 consecutive linebreaks + /^\s+|\s+$/g // Trim the front & back + ]); + + h = dom.encode(h); + + // Delete any highlighted text before pasting + if (!sel.isCollapsed()) { + d.execCommand("Delete", false, null); + } + + // Perform default or custom replacements + if (is(rl, "array") || (is(rl, "array"))) { + process(rl); + } + else if (is(rl, "string")) { + process(new RegExp(rl, "gi")); + } + + // Treat paragraphs as specified in the config + if (linebr == "none") { + process([ + [/\n+/g, " "] + ]); + } + else if (linebr == "br") { + process([ + [/\n/g, "<br />"] + ]); + } + else { + process([ + /^\s+|\s+$/g, + [/\n\n/g, "</p><p>"], + [/\n/g, "<br />"] + ]); + } + + // This next piece of code handles the situation where we're pasting more than one paragraph of plain + // text, and we are pasting the content into the middle of a block node in the editor. The block + // node gets split at the selection point into "Para A" and "Para B" (for the purposes of explaining). + // The first paragraph of the pasted text is appended to "Para A", and the last paragraph of the + // pasted text is prepended to "Para B". Any other paragraphs of pasted text are placed between + // "Para A" and "Para B". This code solves a host of problems with the original plain text plugin and + // now handles styles correctly. (Pasting plain text into a styled paragraph is supposed to make the + // plain text take the same style as the existing paragraph.) + if ((pos = h.indexOf("</p><p>")) != -1) { + rpos = h.lastIndexOf("</p><p>"); + node = sel.getNode(); + breakElms = []; // Get list of elements to break + + do { + if (node.nodeType == 1) { + // Don't break tables and break at body + if (node.nodeName == "TD" || node.nodeName == "BODY") { + break; + } + + breakElms[breakElms.length] = node; + } + } while (node = node.parentNode); + + // Are we in the middle of a block node? + if (breakElms.length > 0) { + before = h.substring(0, pos); + after = ""; + + for (i=0, len=breakElms.length; i<len; i++) { + before += "</" + breakElms[i].nodeName.toLowerCase() + ">"; + after += "<" + breakElms[breakElms.length-i-1].nodeName.toLowerCase() + ">"; + } + + if (pos == rpos) { + h = before + after + h.substring(pos+7); + } + else { + h = before + h.substring(pos+4, rpos+4) + after + h.substring(rpos+7); + } + } + } + + // Insert content at the caret, plus add a marker for repositioning the caret + ed.execCommand("mceInsertRawHTML", false, h + '<span id="_plain_text_marker"> </span>'); + + // Reposition the caret to the marker, which was placed immediately after the inserted content. + // Needs to be done asynchronously (in window.setTimeout) or else it doesn't work in all browsers. + // The second part of the code scrolls the content up if the caret is positioned off-screen. + // This is only necessary for WebKit browsers, but it doesn't hurt to use for all. + window.setTimeout(function() { + var marker = dom.get('_plain_text_marker'), + elm, vp, y, elmHeight; + + sel.select(marker, false); + d.execCommand("Delete", false, null); + marker = null; + + // Get element, position and height + elm = sel.getStart(); + vp = dom.getViewPort(w); + y = dom.getPos(elm).y; + elmHeight = elm.clientHeight; + + // Is element within viewport if not then scroll it into view + if ((y < vp.y) || (y + elmHeight > vp.y + vp.h)) { + d.body.scrollTop = y < vp.y ? y : y - vp.h + 25; + } + }, 0); + } + }, + + /** * This method will open the old style paste dialogs. Some users might want the old behavior but still use the new cleanup engine. */ _legacySupport : function() { var t = this, ed = t.editor; - // Register commands for backwards compatibility - each(['mcePasteText', 'mcePasteWord'], function(cmd) { - ed.addCommand(cmd, function() { + // Register command(s) for backwards compatibility + ed.addCommand("mcePasteWord", function() { + ed.windowManager.open({ + file: t.url + "/pasteword.htm", + width: parseInt(getParam(ed, "paste_dialog_width")), + height: parseInt(getParam(ed, "paste_dialog_height")), + inline: 1 + }); + }); + + if (getParam(ed, "paste_text_use_dialog")) { + ed.addCommand("mcePasteText", function() { ed.windowManager.open({ - file : t.url + (cmd == 'mcePasteText' ? '/pastetext.htm' : '/pasteword.htm'), - width : parseInt(ed.getParam("paste_dialog_width", "450")), - height : parseInt(ed.getParam("paste_dialog_height", "400")), + file : t.url + "/pastetext.htm", + width: parseInt(getParam(ed, "paste_dialog_width")), + height: parseInt(getParam(ed, "paste_dialog_height")), inline : 1 }); }); - }); + } - // Register buttons for backwards compatibility - ed.addButton('pastetext', {title : 'paste.paste_text_desc', cmd : 'mcePasteText'}); - ed.addButton('pasteword', {title : 'paste.paste_word_desc', cmd : 'mcePasteWord'}); - ed.addButton('selectall', {title : 'paste.selectall_desc', cmd : 'selectall'}); + // Register button for backwards compatibility + ed.addButton("pasteword", {title : "paste.paste_word_desc", cmd : "mcePasteWord"}); } }); // Register plugin - tinymce.PluginManager.add('paste', tinymce.plugins.PastePlugin); -})(); -\ No newline at end of file + tinymce.PluginManager.add("paste", tinymce.plugins.PastePlugin); +})(); diff --git a/chrome/content/zotero/tinymce/themes/advanced/about.htm b/chrome/content/zotero/tinymce/themes/advanced/about.htm @@ -1,4 +1,4 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{#advanced_dlg.about_title}</title> @@ -48,9 +48,7 @@ </div> <div class="mceActionPanel"> - <div style="float: right"> - <input type="button" id="cancel" name="cancel" value="{#close}" onclick="tinyMCEPopup.close();" /> - </div> + <input type="button" id="cancel" name="cancel" value="{#close}" onclick="tinyMCEPopup.close();" /> </div> </body> </html> diff --git a/chrome/content/zotero/tinymce/themes/advanced/anchor.htm b/chrome/content/zotero/tinymce/themes/advanced/anchor.htm @@ -4,7 +4,6 @@ <title>{#advanced_dlg.anchor_title}</title> <script type="text/javascript" src="../../tiny_mce_popup.js"></script> <script type="text/javascript" src="js/anchor.js"></script> - <base target="_self" /> </head> <body style="display: none"> <form onsubmit="AnchorDialog.update();return false;" action="#"> @@ -13,19 +12,14 @@ <td colspan="2" class="title">{#advanced_dlg.anchor_title}</td> </tr> <tr> - <td nowrap="nowrap">{#advanced_dlg.anchor_name}:</td> + <td class="nowrap">{#advanced_dlg.anchor_name}:</td> <td><input name="anchorName" type="text" class="mceFocus" id="anchorName" value="" style="width: 200px" /></td> </tr> </table> <div class="mceActionPanel"> - <div style="float: left"> - <input type="submit" id="insert" name="insert" value="{#update}" /> - </div> - - <div style="float: right"> - <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> - </div> + <input type="submit" id="insert" name="insert" value="{#update}" /> + <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> </div> </form> </body> diff --git a/chrome/content/zotero/tinymce/themes/advanced/charmap.htm b/chrome/content/zotero/tinymce/themes/advanced/charmap.htm @@ -1,11 +1,9 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{#advanced_dlg.charmap_title}</title> - <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <script type="text/javascript" src="../../tiny_mce_popup.js"></script> <script type="text/javascript" src="js/charmap.js"></script> - <base target="_self" /> </head> <body id="charmap" style="display:none"> <table align="center" border="0" cellspacing="0" cellpadding="2"> diff --git a/chrome/content/zotero/tinymce/themes/advanced/color_picker.htm b/chrome/content/zotero/tinymce/themes/advanced/color_picker.htm @@ -5,7 +5,6 @@ <script type="text/javascript" src="../../tiny_mce_popup.js"></script> <script type="text/javascript" src="../../utils/mctabs.js"></script> <script type="text/javascript" src="js/color_picker.js"></script> - <base target="_self" /> </head> <body id="colorpicker" style="display: none"> <form onsubmit="insertAction();return false" action="#"> @@ -22,7 +21,7 @@ <fieldset> <legend>{#advanced_dlg.colorpicker_picker_title}</legend> <div id="picker"> - <img id="colors" src="img/colorpicker.jpg" onclick="computeColor(event)" onmousedown="isMouseDown = true;return false;" onmouseup="isMouseDown = false;" onmousemove="if (isMouseDown && isMouseOver) computeColor(event); return false;" onmouseover="isMouseOver=true;" onmouseout="isMouseOver=false;" /> + <img id="colors" src="img/colorpicker.jpg" onclick="computeColor(event)" onmousedown="isMouseDown = true;return false;" onmouseup="isMouseDown = false;" onmousemove="if (isMouseDown && isMouseOver) computeColor(event); return false;" onmouseover="isMouseOver=true;" onmouseout="isMouseOver=false;" alt="" /> <div id="light"> <!-- Will be filled with divs --> @@ -61,9 +60,7 @@ </div> <div class="mceActionPanel"> - <div style="float: left"> - <input type="submit" id="insert" name="insert" value="{#apply}" /> - </div> + <input type="submit" id="insert" name="insert" value="{#apply}" /> <div id="preview"></div> diff --git a/chrome/content/zotero/tinymce/themes/advanced/editor_template.js b/chrome/content/zotero/tinymce/themes/advanced/editor_template.js @@ -1,1147 +1 @@ -/** - * $Id: editor_template_src.js 925 2008-09-11 11:25:26Z spocke $ - * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. - */ - -(function() { - 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) - tinymce.ThemeManager.requireLangPack('advanced'); - - tinymce.create('tinymce.themes.AdvancedTheme', { - sizes : [8, 10, 12, 14, 18, 24, 36], - - // Control name lookup, format: title, command - controls : { - bold : ['bold_desc', 'Bold'], - italic : ['italic_desc', 'Italic'], - underline : ['underline_desc', 'Underline'], - strikethrough : ['striketrough_desc', 'Strikethrough'], - justifyleft : ['justifyleft_desc', 'JustifyLeft'], - justifycenter : ['justifycenter_desc', 'JustifyCenter'], - justifyright : ['justifyright_desc', 'JustifyRight'], - justifyfull : ['justifyfull_desc', 'JustifyFull'], - bullist : ['bullist_desc', 'InsertUnorderedList'], - numlist : ['numlist_desc', 'InsertOrderedList'], - outdent : ['outdent_desc', 'Outdent'], - indent : ['indent_desc', 'Indent'], - cut : ['cut_desc', 'Cut'], - copy : ['copy_desc', 'Copy'], - paste : ['paste_desc', 'Paste'], - undo : ['undo_desc', 'Undo'], - redo : ['redo_desc', 'Redo'], - link : ['link_desc', 'mceLink'], - unlink : ['unlink_desc', 'unlink'], - image : ['image_desc', 'mceImage'], - cleanup : ['cleanup_desc', 'mceCleanup'], - help : ['help_desc', 'mceHelp'], - code : ['code_desc', 'mceCodeEditor'], - hr : ['hr_desc', 'InsertHorizontalRule'], - removeformat : ['removeformat_desc', 'RemoveFormat'], - sub : ['sub_desc', 'subscript'], - sup : ['sup_desc', 'superscript'], - forecolor : ['forecolor_desc', 'ForeColor'], - forecolorpicker : ['forecolor_desc', 'mceForeColor'], - backcolor : ['backcolor_desc', 'HiliteColor'], - backcolorpicker : ['backcolor_desc', 'mceBackColor'], - charmap : ['charmap_desc', 'mceCharMap'], - visualaid : ['visualaid_desc', 'mceToggleVisualAid'], - anchor : ['anchor_desc', 'mceInsertAnchor'], - newdocument : ['newdocument_desc', 'mceNewDocument'], - blockquote : ['blockquote_desc', 'mceBlockQuote'] - }, - - stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'], - - init : function(ed, url) { - var t = this, s, v, o; - - t.editor = ed; - t.url = url; - t.onResolveName = new tinymce.util.Dispatcher(this); - - // Default settings - t.settings = s = extend({ - theme_advanced_path : true, - theme_advanced_toolbar_location : 'bottom', - theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect", - theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code", - theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap", - theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6", - theme_advanced_toolbar_align : "center", - theme_advanced_fonts : "Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats", - theme_advanced_more_colors : 1, - theme_advanced_row_height : 23, - theme_advanced_resize_horizontal : 1, - theme_advanced_resizing_use_cookie : 1, - theme_advanced_font_sizes : "1,2,3,4,5,6,7", - readonly : ed.settings.readonly - }, ed.settings); - - // Setup default font_size_style_values - if (!s.font_size_style_values) - s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt"; - - if (tinymce.is(s.theme_advanced_font_sizes, 'string')) { - s.font_size_style_values = tinymce.explode(s.font_size_style_values); - s.font_size_classes = tinymce.explode(s.font_size_classes || ''); - - // Parse string value - o = {}; - ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes; - each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) { - var cl; - - 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'); - } - } - - if (/\s*\./.test(v)) - cl = v.replace(/\./g, ''); - - o[k] = cl ? {'class' : cl} : {fontSize : v}; - }); - - s.theme_advanced_font_sizes = o; - } - - if ((v = s.theme_advanced_path_location) && v != 'none') - s.theme_advanced_statusbar_location = s.theme_advanced_path_location; - - if (s.theme_advanced_statusbar_location == 'none') - s.theme_advanced_statusbar_location = 0; - - // 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")); - }); - - ed.onSetProgressState.add(function(ed, b, ti) { - var co, id = ed.id, tb; - - if (b) { - t.progressTimer = setTimeout(function() { - co = ed.getContainer(); - co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild); - tb = DOM.get(ed.id + '_tbl'); - - DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}}); - DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}}); - }, ti || 0); - } else { - DOM.remove(id + '_blocker'); - DOM.remove(id + '_progress'); - clearTimeout(t.progressTimer); - } - }); - - DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css"); - - if (s.skin_variant) - DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css"); - }, - - createControl : function(n, cf) { - var cd, c; - - if (c = cf.createControl(n)) - return c; - - switch (n) { - case "styleselect": - return this._createStyleSelect(); - - case "formatselect": - return this._createBlockFormats(); - - case "fontselect": - return this._createFontSelect(); - - case "fontsizeselect": - return this._createFontSizeSelect(); - - case "forecolor": - return this._createForeColorMenu(); - - case "backcolor": - return this._createBackColorMenu(); - } - - if ((cd = this.controls[n])) - return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]}); - }, - - execCommand : function(cmd, ui, val) { - var f = this['_' + cmd]; - - if (f) { - f.call(this, ui, val); - return true; - } - - return false; - }, - - _importClasses : function(e) { - var ed = this.editor, c = ed.controlManager.get('styleselect'); - - if (c.getLength() == 0) { - each(ed.dom.getClasses(), function(o) { - c.add(o['class'], o['class']); - }); - } - }, - - _createStyleSelect : function(n) { - var t = this, ed = t.editor, cf = ed.controlManager, c = cf.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); - } - }); - - if (c) { - each(ed.getParam('theme_advanced_styles', '', 'hash'), function(v, k) { - if (v) - c.add(t.editor.translate(k), v); - }); - - c.onPostRender.add(function(ed, n) { - if (!c.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); - Event.add(n.id + '_open', 'mousedown', t._importClasses, t); - } else - Event.add(n.id, 'focus', t._importClasses, t); - }); - } - - return c; - }, - - _createFontSelect : function() { - var c, t = this, ed = t.editor; - - c = ed.controlManager.createListBox('fontselect', {title : 'advanced.fontdefault', cmd : 'FontName'}); - 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 : ''}); - }); - } - - return c; - }, - - _createFontSizeSelect : function() { - 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) - 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}); - } - }}); - - if (c) { - each(t.settings.theme_advanced_font_sizes, function(v, k) { - var fz = v.fontSize; - - if (fz >= 1 && fz <= 7) - fz = t.sizes[parseInt(fz) - 1] + 'pt'; - - c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))}); - }); - } - - return c; - }, - - _createBlockFormats : function() { - var c, fmts = { - p : 'advanced.paragraph', - address : 'advanced.address', - pre : 'advanced.pre', - h1 : 'advanced.h1', - h2 : 'advanced.h2', - h3 : 'advanced.h3', - h4 : 'advanced.h4', - h5 : 'advanced.h5', - h6 : 'advanced.h6', - div : 'advanced.div', - blockquote : 'advanced.blockquote', - code : 'advanced.code', - dt : 'advanced.dt', - dd : 'advanced.dd', - samp : 'advanced.samp' - }, t = this; - - c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'}); - 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}); - }); - } - - return c; - }, - - _createForeColorMenu : function() { - var c, t = this, s = t.settings, o = {}, v; - - if (s.theme_advanced_more_colors) { - o.more_colors_func = function() { - t._mceColorPicker(0, { - color : c.value, - func : function(co) { - c.setColor(co); - } - }); - }; - } - - if (v = s.theme_advanced_text_colors) - o.colors = v; - - o.title = 'advanced.forecolor_desc'; - o.cmd = 'ForeColor'; - o.scope = this; - - c = t.editor.controlManager.createColorSplitButton('forecolor', o); - - return c; - }, - - _createBackColorMenu : function() { - var c, t = this, s = t.settings, o = {}, v; - - if (s.theme_advanced_more_colors) { - o.more_colors_func = function() { - t._mceColorPicker(0, { - color : c.value, - func : function(co) { - c.setColor(co); - } - }); - }; - } - - if (v = s.theme_advanced_background_colors) - o.colors = v; - - o.title = 'advanced.backcolor_desc'; - o.cmd = 'HiliteColor'; - o.scope = this; - - c = t.editor.controlManager.createColorSplitButton('backcolor', o); - - return c; - }, - - 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 (!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 = tb = DOM.add(n, 'tbody'); - - switch ((s.theme_advanced_layout_manager || '').toLowerCase()) { - case "rowlayout": - ic = t._rowLayout(s, tb, o); - break; - - case "customlayout": - ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p); - break; - - default: - ic = t._simpleLayout(s, tb, o, p); - } - - n = o.targetNode; - - // Add classes to first and last TRs - nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8 - DOM.addClass(nl[0], 'mceFirst'); - DOM.addClass(nl[nl.length - 1], 'mceLast'); - - // Add classes to first and last TDs - each(DOM.select('tr', tb), function(n) { - DOM.addClass(n.firstChild, 'mceFirst'); - DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast'); - }); - - if (DOM.get(s.theme_advanced_toolbar_container)) - DOM.get(s.theme_advanced_toolbar_container).appendChild(p); - else - DOM.insertAfter(p, n); - - Event.add(ed.id + '_path_row', 'click', function(e) { - e = e.target; - - if (e.nodeName == 'A') { - t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1')); - - return Event.cancel(e); - } - }); -/* - if (DOM.get(ed.id + '_path_row')) { - Event.add(ed.id + '_tbl', 'mouseover', function(e) { - var re; - - e = e.target; - - if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) { - re = DOM.get(ed.id + '_path_row'); - t.lastPath = re.innerHTML; - DOM.setHTML(re, e.parentNode.title); - } - }); - - Event.add(ed.id + '_tbl', 'mouseout', function(e) { - if (t.lastPath) { - DOM.setHTML(ed.id + '_path_row', t.lastPath); - t.lastPath = 0; - } - }); - } -*/ - - if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus')) - Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();}); - - if (s.theme_advanced_toolbar_location == 'external') - o.deltaHeight = 0; - - t.deltaHeight = o.deltaHeight; - o.targetNode = null; - - return { - iframeContainer : ic, - editorContainer : ed.id + '_parent', - sizeContainer : sc, - deltaHeight : o.deltaHeight - }; - }, - - getInfo : function() { - return { - longname : 'Advanced theme', - author : 'Moxiecode Systems AB', - authorurl : 'http://tinymce.moxiecode.com', - version : tinymce.majorVersion + "." + tinymce.minorVersion - } - }, - - resizeBy : function(dw, dh) { - var e = DOM.get(this.editor.id + '_tbl'); - - 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; - - // Boundery fix box - w = Math.max(s.theme_advanced_resizing_min_width || 100, w); - h = Math.max(s.theme_advanced_resizing_min_height || 100, h); - 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}); - }, - - destroy : function() { - var id = this.editor.id; - - Event.clear(id + '_resize'); - Event.clear(id + '_path_row'); - Event.clear(id + '_external_close'); - }, - - // Internal functions - - _simpleLayout : function(s, tb, o, p) { - var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c; - - if (s.readonly) { - n = DOM.add(tb, 'tr'); - n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'}); - return ic; - } - - // Create toolbar container at top - if (lo == 'top') - t._addToolbars(tb, o); - - // Create external toolbar - if (lo == 'external') { - n = c = DOM.create('div', {style : 'position:relative'}); - n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'}); - DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'}); - n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0}); - etb = DOM.add(n, 'tbody'); - - if (p.firstChild.className == 'mceOldBoxModel') - p.firstChild.appendChild(c); - else - p.insertBefore(c, p.firstChild); - - t._addToolbars(etb, o); - - ed.onMouseUp.add(function() { - var e = DOM.get(ed.id + '_external'); - DOM.show(e); - - DOM.hide(lastExtID); - - var f = Event.add(ed.id + '_external_close', 'click', function() { - DOM.hide(ed.id + '_external'); - Event.remove(ed.id + '_external_close', 'click', f); - }); - - DOM.show(e); - DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1); - - // Fixes IE rendering bug - DOM.hide(e); - DOM.show(e); - e.style.filter = ''; - - lastExtID = ed.id + '_external'; - - e = null; - }); - } - - if (sl == 'top') - t._addStatusBar(tb, o); - - // Create iframe container - if (!s.theme_advanced_toolbar_container) { - n = DOM.add(tb, 'tr'); - n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'}); - } - - // Create toolbar container at bottom - if (lo == 'bottom') - t._addToolbars(tb, o); - - if (sl == 'bottom') - t._addStatusBar(tb, o); - - return ic; - }, - - _rowLayout : function(s, tb, o) { - var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a; - - dc = s.theme_advanced_containers_default_class || ''; - da = s.theme_advanced_containers_default_align || 'center'; - - each(explode(s.theme_advanced_containers || ''), function(c, i) { - var v = s['theme_advanced_container_' + c] || ''; - - switch (v.toLowerCase()) { - case 'mceeditor': - n = DOM.add(tb, 'tr'); - n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'}); - break; - - case 'mceelementpath': - t._addStatusBar(tb, o); - break; - - default: - a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase(); - a = 'mce' + t._ufirst(a); - - n = DOM.add(DOM.add(tb, 'tr'), 'td', { - 'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da - }); - - to = cf.createToolbar("toolbar" + i); - t._addControls(v, to); - DOM.setHTML(n, to.renderHTML()); - o.deltaHeight -= s.theme_advanced_row_height; - } - }); - - return ic; - }, - - _addControls : function(v, tb) { - var t = this, s = t.settings, di, cf = t.editor.controlManager; - - if (s.theme_advanced_disable && !t._disabled) { - di = {}; - - each(explode(s.theme_advanced_disable), function(v) { - di[v] = 1; - }); - - t._disabled = di; - } else - di = t._disabled; - - each(explode(v), function(n) { - var c; - - if (di && di[n]) - return; - - // Compatiblity with 2.x - if (n == 'tablecontrols') { - each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) { - n = t.createControl(n, cf); - - if (n) - tb.add(n); - }); - - return; - } - - c = t.createControl(n, cf); - - if (c) - tb.add(c); - }); - }, - - _addToolbars : function(c, o) { - var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a; - - a = s.theme_advanced_toolbar_align.toLowerCase(); - a = 'mce' + t._ufirst(a); - - n = DOM.add(DOM.add(c, 'tr'), 'td', {'class' : 'mceToolbar ' + a}); - - if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus')) - h.push(DOM.createHTML('a', {href : '#', onfocus : 'tinyMCE.get(\'' + ed.id + '\').focus();'}, '<!-- IE -->')); - - h.push(DOM.createHTML('a', {href : '#', accesskey : 'q', title : ed.getLang("advanced.toolbar_focus")}, '<!-- IE -->')); - - // Create toolbar and add the controls - for (i=1; (v = s['theme_advanced_buttons' + i]); i++) { - tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i}); - - if (s['theme_advanced_buttons' + i + '_add']) - v += ',' + s['theme_advanced_buttons' + i + '_add']; - - if (s['theme_advanced_buttons' + i + '_add_before']) - v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v; - - t._addControls(v, tb); - - //n.appendChild(n = tb.render()); - h.push(tb.renderHTML()); - - o.deltaHeight -= s.theme_advanced_row_height; - } - - h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->')); - DOM.setHTML(n, h.join('')); - }, - - _addStatusBar : function(tb, o) { - 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'}); - - 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_use_cookie) { - ed.onPostRender.add(function() { - var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl'); - - 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'; - }); - } - - 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'; - - p.style.height = h + 'px'; - - return Event.cancel(e); - }); - - me = Event.add(DOM.doc, 'mouseup', function(e) { - var ifr; - - // 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'; - - if (s.theme_advanced_resizing_use_cookie) { - Cookie.setHash("TinyMCE_" + ed.id + "_size", { - cw : r.w + r.dx, - ch : r.h + r.dy - }); - } - }); - - return Event.cancel(e); - }); - }); - } - - o.deltaHeight -= 21; - 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; - - tinymce.each(t.stateControls, function(c) { - cm.setActive(c, ed.queryCommandState(t.controls[c][1])); - }); - - 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'); - if (c = cm.get('link')) { - if (!p || !p.name) { - c.setDisabled(!p && co); - c.setActive(!!p); - } - } - - if (c = cm.get('unlink')) { - c.setDisabled(!p && co); - c.setActive(!!p && !p.name); - } - - 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'); - 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(); - } - - if (c = cm.get('formatselect')) { - p = DOM.getParent(n, 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; - - if (!fz && n.style.fontSize) - fz = n.style.fontSize; - - if (!fn && n.style.fontFamily) - fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase(); - } - - return false; - }); - - if (c = cm.get('fontselect')) { - c.select(function(v) { - return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn; - }); - } - - if (c = cm.get('fontsizeselect')) { - 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 (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) { - 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'))) - return; - - // Fake name - if (v = DOM.getAttrib(n, 'mce_name')) - na = v; - - // Handle prefix - if (tinymce.isIE && n.scopeName !== 'HTML') - na = n.scopeName + ':' + na; - - // Remove internal prefix - na = na.replace(/mce\:/g, ''); - - // Handle node name - switch (na) { - case 'b': - na = 'strong'; - break; - - case 'i': - na = 'em'; - break; - - case 'img': - if (v = DOM.getAttrib(n, 'src')) - ti += 'src: ' + v + ' '; - - break; - - case 'a': - if (v = DOM.getAttrib(n, 'name')) { - ti += 'name: ' + v + ' '; - na += '#' + v; - } - - if (v = DOM.getAttrib(n, 'href')) - ti += 'href: ' + v + ' '; - - break; - - case 'font': - if (s.convert_fonts_to_spans) - na = 'span'; - - if (v = DOM.getAttrib(n, 'face')) - ti += 'font: ' + v + ' '; - - if (v = DOM.getAttrib(n, 'size')) - ti += 'size: ' + v + ' '; - - if (v = DOM.getAttrib(n, 'color')) - ti += 'color: ' + v + ' '; - - break; - - case 'span': - if (v = DOM.getAttrib(n, 'style')) - ti += 'style: ' + v + ' '; - - break; - } - - if (v = DOM.getAttrib(n, 'id')) - ti += 'id: ' + v + ' '; - - if (v = n.className) { - v = v.replace(/(webkit-[\w\-]+|Apple-[\w\-]+|mceItem\w+|mceVisualAid)/g, ''); - - if (v && v.indexOf('mceItem') == -1) { - ti += 'class: ' + v + ' '; - - if (DOM.isBlock(n) || na == 'img' || na == 'span') - na += '.' + v; - } - } - - na = na.replace(/(html:)/g, ''); - na = {name : na, node : n, title : ti}; - t.onResolveName.dispatch(t, na); - ti = na.title; - 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); - - if (p.hasChildNodes()) { - p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild); - p.insertBefore(pi, p.firstChild); - } else - p.appendChild(pi); - }, ed.getBody()); - } - }, - - // Commands gets called by execCommand - - _sel : function(v) { - this.editor.execCommand('mceSelectNodeDepth', false, v); - }, - - _mceInsertAnchor : function(ui, v) { - var ed = this.editor; - - ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/anchor.htm', - width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)), - height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)), - inline : true - }, { - theme_url : this.url - }); - }, - - _mceCharMap : function() { - var ed = this.editor; - - ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/charmap.htm', - width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)), - height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)), - inline : true - }, { - theme_url : this.url - }); - }, - - _mceHelp : function() { - var ed = this.editor; - - ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/about.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', - width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)), - height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)), - close_previous : false, - inline : true - }, { - input_color : v.color, - func : v.func, - theme_url : this.url - }); - }, - - _mceCodeEditor : function(ui, val) { - var ed = this.editor; - - ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/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, - resizable : true, - maximizable : true - }, { - theme_url : this.url - }); - }, - - _mceImage : function(ui, val) { - var ed = this.editor; - - // Internal image object like a flash placeholder - if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1) - return; - - ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/image.htm', - width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)), - height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)), - inline : true - }, { - theme_url : this.url - }); - }, - - _mceLink : function(ui, val) { - var ed = this.editor; - - ed.windowManager.open({ - url : tinymce.baseURL + '/themes/advanced/link.htm', - width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)), - height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)), - inline : true - }, { - theme_url : this.url - }); - }, - - _mceNewDocument : function() { - var ed = this.editor; - - ed.windowManager.confirm('advanced.newdocument', function(s) { - if (s) - ed.execCommand('mceSetContent', false, ''); - }); - }, - - _mceForeColor : function() { - var t = this; - - this._mceColorPicker(0, { - color: t.fgColor, - func : function(co) { - t.fgColor = co; - t.editor.execCommand('ForeColor', false, co); - } - }); - }, - - _mceBackColor : function() { - var t = this; - - this._mceColorPicker(0, { - color: t.bgColor, - func : function(co) { - t.bgColor = co; - t.editor.execCommand('HiliteColor', false, co); - } - }); - }, - - _ufirst : function(s) { - return s.substring(0, 1).toUpperCase() + s.substring(1); - } - }); - - tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme); -}()); -\ No newline at end of file +(function(e){var d=e.DOM,b=e.dom.Event,h=e.extend,f=e.each,a=e.util.Cookie,g,c=e.explode;e.ThemeManager.requireLangPack("advanced");e.create("tinymce.themes.AdvancedTheme",{sizes:[8,10,12,14,18,24,36],controls:{bold:["bold_desc","Bold"],italic:["italic_desc","Italic"],underline:["underline_desc","Underline"],strikethrough:["striketrough_desc","Strikethrough"],justifyleft:["justifyleft_desc","JustifyLeft"],justifycenter:["justifycenter_desc","JustifyCenter"],justifyright:["justifyright_desc","JustifyRight"],justifyfull:["justifyfull_desc","JustifyFull"],bullist:["bullist_desc","InsertUnorderedList"],numlist:["numlist_desc","InsertOrderedList"],outdent:["outdent_desc","Outdent"],indent:["indent_desc","Indent"],cut:["cut_desc","Cut"],copy:["copy_desc","Copy"],paste:["paste_desc","Paste"],undo:["undo_desc","Undo"],redo:["redo_desc","Redo"],link:["link_desc","mceLink"],unlink:["unlink_desc","unlink"],image:["image_desc","mceImage"],cleanup:["cleanup_desc","mceCleanup"],help:["help_desc","mceHelp"],code:["code_desc","mceCodeEditor"],hr:["hr_desc","InsertHorizontalRule"],removeformat:["removeformat_desc","RemoveFormat"],sub:["sub_desc","subscript"],sup:["sup_desc","superscript"],forecolor:["forecolor_desc","ForeColor"],forecolorpicker:["forecolor_desc","mceForeColor"],backcolor:["backcolor_desc","HiliteColor"],backcolorpicker:["backcolor_desc","mceBackColor"],charmap:["charmap_desc","mceCharMap"],visualaid:["visualaid_desc","mceToggleVisualAid"],anchor:["anchor_desc","mceInsertAnchor"],newdocument:["newdocument_desc","mceNewDocument"],blockquote:["blockquote_desc","mceBlockQuote"]},stateControls:["bold","italic","underline","strikethrough","bullist","numlist","justifyleft","justifycenter","justifyright","justifyfull","sub","sup","blockquote"],init:function(j,k){var l=this,m,i,n;l.editor=j;l.url=k;l.onResolveName=new e.util.Dispatcher(this);l.settings=m=h({theme_advanced_path:true,theme_advanced_toolbar_location:"bottom",theme_advanced_buttons1:"bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",theme_advanced_buttons2:"bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",theme_advanced_buttons3:"hr,removeformat,visualaid,|,sub,sup,|,charmap",theme_advanced_blockformats:"p,address,pre,h1,h2,h3,h4,h5,h6",theme_advanced_toolbar_align:"center",theme_advanced_fonts:"Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats",theme_advanced_more_colors:1,theme_advanced_row_height:23,theme_advanced_resize_horizontal:1,theme_advanced_resizing_use_cookie:1,theme_advanced_font_sizes:"1,2,3,4,5,6,7",readonly:j.settings.readonly},j.settings);if(!m.font_size_style_values){m.font_size_style_values="8pt,10pt,12pt,14pt,18pt,24pt,36pt"}if(e.is(m.theme_advanced_font_sizes,"string")){m.font_size_style_values=e.explode(m.font_size_style_values);m.font_size_classes=e.explode(m.font_size_classes||"");n={};j.settings.theme_advanced_font_sizes=m.theme_advanced_font_sizes;f(j.getParam("theme_advanced_font_sizes","","hash"),function(q,p){var o;if(p==q&&q>=1&&q<=7){p=q+" ("+l.sizes[q-1]+"pt)";o=m.font_size_classes[q-1];q=m.font_size_style_values[q-1]||(l.sizes[q-1]+"pt")}if(/^\s*\./.test(q)){o=q.replace(/\./g,"")}n[p]=o?{"class":o}:{fontSize:q}});m.theme_advanced_font_sizes=n}if((i=m.theme_advanced_path_location)&&i!="none"){m.theme_advanced_statusbar_location=m.theme_advanced_path_location}if(m.theme_advanced_statusbar_location=="none"){m.theme_advanced_statusbar_location=0}j.onInit.add(function(){if(!j.settings.readonly){j.onNodeChange.add(l._nodeChanged,l)}if(j.settings.content_css!==false){j.dom.loadCSS(j.baseURI.toAbsolute(k+"/skins/"+j.settings.skin+"/content.css"))}});j.onSetProgressState.add(function(q,o,r){var s,t=q.id,p;if(o){l.progressTimer=setTimeout(function(){s=q.getContainer();s=s.insertBefore(d.create("DIV",{style:"position:relative"}),s.firstChild);p=d.get(q.id+"_tbl");d.add(s,"div",{id:t+"_blocker","class":"mceBlocker",style:{width:p.clientWidth+2,height:p.clientHeight+2}});d.add(s,"div",{id:t+"_progress","class":"mceProgress",style:{left:p.clientWidth/2,top:p.clientHeight/2}})},r||0)}else{d.remove(t+"_blocker");d.remove(t+"_progress");clearTimeout(l.progressTimer)}});d.loadCSS(m.editor_css?j.documentBaseURI.toAbsolute(m.editor_css):k+"/skins/"+j.settings.skin+"/ui.css");if(m.skin_variant){d.loadCSS(k+"/skins/"+j.settings.skin+"/ui_"+m.skin_variant+".css")}},createControl:function(l,i){var j,k;if(k=i.createControl(l)){return k}switch(l){case"styleselect":return this._createStyleSelect();case"formatselect":return this._createBlockFormats();case"fontselect":return this._createFontSelect();case"fontsizeselect":return this._createFontSizeSelect();case"forecolor":return this._createForeColorMenu();case"backcolor":return this._createBackColorMenu()}if((j=this.controls[l])){return i.createButton(l,{title:"advanced."+j[0],cmd:j[1],ui:j[2],value:j[3]})}},execCommand:function(k,j,l){var i=this["_"+k];if(i){i.call(this,j,l);return true}return false},_importClasses:function(k){var i=this.editor,j=i.controlManager.get("styleselect");if(j.getLength()==0){f(i.dom.getClasses(),function(n,l){var m="style_"+l;i.formatter.register(m,{inline:"span",attributes:{"class":n["class"]},selector:"*"});j.add(n["class"],m)})}},_createStyleSelect:function(m){var k=this,i=k.editor,j=i.controlManager,l;l=j.createListBox("styleselect",{title:"advanced.style_select",onselect:function(o){var p,n=[];f(l.items,function(q){n.push(q.value)});i.focus();i.undoManager.add();p=i.formatter.matchAll(n);if(!o||p[0]==o){i.formatter.remove(p[0])}else{i.formatter.apply(o)}i.undoManager.add();i.nodeChanged();return false}});i.onInit.add(function(){var o=0,n=i.getParam("style_formats");if(n){f(n,function(p){var q,r=0;f(p,function(){r++});if(r>1){q=p.name=p.name||"style_"+(o++);i.formatter.register(q,p);l.add(p.title,q)}else{l.add(p.title)}})}else{f(i.getParam("theme_advanced_styles","","hash"),function(r,q){var p;if(r){p="style_"+(o++);i.formatter.register(p,{inline:"span",classes:r,selector:"*"});l.add(k.editor.translate(q),p)}})}});if(l.getLength()==0){l.onPostRender.add(function(o,p){if(!l.NativeListBox){b.add(p.id+"_text","focus",k._importClasses,k);b.add(p.id+"_text","mousedown",k._importClasses,k);b.add(p.id+"_open","focus",k._importClasses,k);b.add(p.id+"_open","mousedown",k._importClasses,k)}else{b.add(p.id,"focus",k._importClasses,k)}})}return l},_createFontSelect:function(){var k,j=this,i=j.editor;k=i.controlManager.createListBox("fontselect",{title:"advanced.fontdefault",onselect:function(l){var m=k.items[k.selectedIndex];if(!l&&m){i.execCommand("FontName",false,m.value);return}i.execCommand("FontName",false,l);k.select(function(n){return l==n});return false}});if(k){f(i.getParam("theme_advanced_fonts",j.settings.theme_advanced_fonts,"hash"),function(m,l){k.add(i.translate(l),m,{style:m.indexOf("dings")==-1?"font-family:"+m:""})})}return k},_createFontSizeSelect:function(){var m=this,k=m.editor,n,l=0,j=[];n=k.controlManager.createListBox("fontsizeselect",{title:"advanced.font_size",onselect:function(i){var o=n.items[n.selectedIndex];if(!i&&o){o=o.value;if(o["class"]){k.formatter.toggle("fontsize_class",{value:o["class"]});k.undoManager.add();k.nodeChanged()}else{k.execCommand("FontSize",false,o.fontSize)}return}if(i["class"]){k.focus();k.undoManager.add();k.formatter.toggle("fontsize_class",{value:i["class"]});k.undoManager.add();k.nodeChanged()}else{k.execCommand("FontSize",false,i.fontSize)}n.select(function(p){return i==p});return false}});if(n){f(m.settings.theme_advanced_font_sizes,function(o,i){var p=o.fontSize;if(p>=1&&p<=7){p=m.sizes[parseInt(p)-1]+"pt"}n.add(i,o,{style:"font-size:"+p,"class":"mceFontSize"+(l++)+(" "+(o["class"]||""))})})}return n},_createBlockFormats:function(){var k,i={p:"advanced.paragraph",address:"advanced.address",pre:"advanced.pre",h1:"advanced.h1",h2:"advanced.h2",h3:"advanced.h3",h4:"advanced.h4",h5:"advanced.h5",h6:"advanced.h6",div:"advanced.div",blockquote:"advanced.blockquote",code:"advanced.code",dt:"advanced.dt",dd:"advanced.dd",samp:"advanced.samp"},j=this;k=j.editor.controlManager.createListBox("formatselect",{title:"advanced.block",cmd:"FormatBlock"});if(k){f(j.editor.getParam("theme_advanced_blockformats",j.settings.theme_advanced_blockformats,"hash"),function(m,l){k.add(j.editor.translate(l!=m?l:i[m]),m,{"class":"mce_formatPreview mce_"+m})})}return k},_createForeColorMenu:function(){var m,j=this,k=j.settings,l={},i;if(k.theme_advanced_more_colors){l.more_colors_func=function(){j._mceColorPicker(0,{color:m.value,func:function(n){m.setColor(n)}})}}if(i=k.theme_advanced_text_colors){l.colors=i}if(k.theme_advanced_default_foreground_color){l.default_color=k.theme_advanced_default_foreground_color}l.title="advanced.forecolor_desc";l.cmd="ForeColor";l.scope=this;m=j.editor.controlManager.createColorSplitButton("forecolor",l);return m},_createBackColorMenu:function(){var m,j=this,k=j.settings,l={},i;if(k.theme_advanced_more_colors){l.more_colors_func=function(){j._mceColorPicker(0,{color:m.value,func:function(n){m.setColor(n)}})}}if(i=k.theme_advanced_background_colors){l.colors=i}if(k.theme_advanced_default_background_color){l.default_color=k.theme_advanced_default_background_color}l.title="advanced.backcolor_desc";l.cmd="HiliteColor";l.scope=this;m=j.editor.controlManager.createColorSplitButton("backcolor",l);return m},renderUI:function(k){var m,l,q,v=this,r=v.editor,w=v.settings,u,j,i;m=j=d.create("span",{id:r.id+"_parent","class":"mceEditor "+r.settings.skin+"Skin"+(w.skin_variant?" "+r.settings.skin+"Skin"+v._ufirst(w.skin_variant):"")});if(!d.boxModel){m=d.add(m,"div",{"class":"mceOldBoxModel"})}m=u=d.add(m,"table",{id:r.id+"_tbl","class":"mceLayout",cellSpacing:0,cellPadding:0});m=q=d.add(m,"tbody");switch((w.theme_advanced_layout_manager||"").toLowerCase()){case"rowlayout":l=v._rowLayout(w,q,k);break;case"customlayout":l=r.execCallback("theme_advanced_custom_layout",w,q,k,j);break;default:l=v._simpleLayout(w,q,k,j)}m=k.targetNode;i=d.stdMode?u.getElementsByTagName("tr"):u.rows;d.addClass(i[0],"mceFirst");d.addClass(i[i.length-1],"mceLast");f(d.select("tr",q),function(o){d.addClass(o.firstChild,"mceFirst");d.addClass(o.childNodes[o.childNodes.length-1],"mceLast")});if(d.get(w.theme_advanced_toolbar_container)){d.get(w.theme_advanced_toolbar_container).appendChild(j)}else{d.insertAfter(j,m)}b.add(r.id+"_path_row","click",function(n){n=n.target;if(n.nodeName=="A"){v._sel(n.className.replace(/^.*mcePath_([0-9]+).*$/,"$1"));return b.cancel(n)}});if(!r.getParam("accessibility_focus")){b.add(d.add(j,"a",{href:"#"},"<!-- IE -->"),"focus",function(){tinyMCE.get(r.id).focus()})}if(w.theme_advanced_toolbar_location=="external"){k.deltaHeight=0}v.deltaHeight=k.deltaHeight;k.targetNode=null;return{iframeContainer:l,editorContainer:r.id+"_parent",sizeContainer:u,deltaHeight:k.deltaHeight}},getInfo:function(){return{longname:"Advanced theme",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",version:e.majorVersion+"."+e.minorVersion}},resizeBy:function(i,j){var k=d.get(this.editor.id+"_tbl");this.resizeTo(k.clientWidth+i,k.clientHeight+j)},resizeTo:function(i,m,k){var j=this.editor,l=this.settings,n=d.get(j.id+"_tbl"),o=d.get(j.id+"_ifr");i=Math.max(l.theme_advanced_resizing_min_width||100,i);m=Math.max(l.theme_advanced_resizing_min_height||100,m);i=Math.min(l.theme_advanced_resizing_max_width||65535,i);m=Math.min(l.theme_advanced_resizing_max_height||65535,m);d.setStyle(n,"height","");d.setStyle(o,"height",m);if(l.theme_advanced_resize_horizontal){d.setStyle(n,"width","");d.setStyle(o,"width",i);if(i<n.clientWidth){i=n.clientWidth;d.setStyle(o,"width",n.clientWidth)}}if(k&&l.theme_advanced_resizing_use_cookie){a.setHash("TinyMCE_"+j.id+"_size",{cw:i,ch:m})}},destroy:function(){var i=this.editor.id;b.clear(i+"_resize");b.clear(i+"_path_row");b.clear(i+"_external_close")},_simpleLayout:function(y,r,k,i){var x=this,u=x.editor,v=y.theme_advanced_toolbar_location,m=y.theme_advanced_statusbar_location,l,j,q,w;if(y.readonly){l=d.add(r,"tr");l=j=d.add(l,"td",{"class":"mceIframeContainer"});return j}if(v=="top"){x._addToolbars(r,k)}if(v=="external"){l=w=d.create("div",{style:"position:relative"});l=d.add(l,"div",{id:u.id+"_external","class":"mceExternalToolbar"});d.add(l,"a",{id:u.id+"_external_close",href:"javascript:;","class":"mceExternalClose"});l=d.add(l,"table",{id:u.id+"_tblext",cellSpacing:0,cellPadding:0});q=d.add(l,"tbody");if(i.firstChild.className=="mceOldBoxModel"){i.firstChild.appendChild(w)}else{i.insertBefore(w,i.firstChild)}x._addToolbars(q,k);u.onMouseUp.add(function(){var o=d.get(u.id+"_external");d.show(o);d.hide(g);var n=b.add(u.id+"_external_close","click",function(){d.hide(u.id+"_external");b.remove(u.id+"_external_close","click",n)});d.show(o);d.setStyle(o,"top",0-d.getRect(u.id+"_tblext").h-1);d.hide(o);d.show(o);o.style.filter="";g=u.id+"_external";o=null})}if(m=="top"){x._addStatusBar(r,k)}if(!y.theme_advanced_toolbar_container){l=d.add(r,"tr");l=j=d.add(l,"td",{"class":"mceIframeContainer"})}if(v=="bottom"){x._addToolbars(r,k)}if(m=="bottom"){x._addStatusBar(r,k)}return j},_rowLayout:function(w,m,k){var v=this,p=v.editor,u,x,i=p.controlManager,l,j,r,q;u=w.theme_advanced_containers_default_class||"";x=w.theme_advanced_containers_default_align||"center";f(c(w.theme_advanced_containers||""),function(s,o){var n=w["theme_advanced_container_"+s]||"";switch(n.toLowerCase()){case"mceeditor":l=d.add(m,"tr");l=j=d.add(l,"td",{"class":"mceIframeContainer"});break;case"mceelementpath":v._addStatusBar(m,k);break;default:q=(w["theme_advanced_container_"+s+"_align"]||x).toLowerCase();q="mce"+v._ufirst(q);l=d.add(d.add(m,"tr"),"td",{"class":"mceToolbar "+(w["theme_advanced_container_"+s+"_class"]||u)+" "+q||x});r=i.createToolbar("toolbar"+o);v._addControls(n,r);d.setHTML(l,r.renderHTML());k.deltaHeight-=w.theme_advanced_row_height}});return j},_addControls:function(j,i){var k=this,l=k.settings,m,n=k.editor.controlManager;if(l.theme_advanced_disable&&!k._disabled){m={};f(c(l.theme_advanced_disable),function(o){m[o]=1});k._disabled=m}else{m=k._disabled}f(c(j),function(p){var o;if(m&&m[p]){return}if(p=="tablecontrols"){f(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"],function(q){q=k.createControl(q,n);if(q){i.add(q)}});return}o=k.createControl(p,n);if(o){i.add(o)}})},_addToolbars:function(w,k){var z=this,p,m,r=z.editor,A=z.settings,y,j=r.controlManager,u,l,q=[],x;x=A.theme_advanced_toolbar_align.toLowerCase();x="mce"+z._ufirst(x);l=d.add(d.add(w,"tr"),"td",{"class":"mceToolbar "+x});if(!r.getParam("accessibility_focus")){q.push(d.createHTML("a",{href:"#",onfocus:"tinyMCE.get('"+r.id+"').focus();"},"<!-- IE -->"))}q.push(d.createHTML("a",{href:"#",accesskey:"q",title:r.getLang("advanced.toolbar_focus")},"<!-- IE -->"));for(p=1;(y=A["theme_advanced_buttons"+p]);p++){m=j.createToolbar("toolbar"+p,{"class":"mceToolbarRow"+p});if(A["theme_advanced_buttons"+p+"_add"]){y+=","+A["theme_advanced_buttons"+p+"_add"]}if(A["theme_advanced_buttons"+p+"_add_before"]){y=A["theme_advanced_buttons"+p+"_add_before"]+","+y}z._addControls(y,m);q.push(m.renderHTML());k.deltaHeight-=A.theme_advanced_row_height}q.push(d.createHTML("a",{href:"#",accesskey:"z",title:r.getLang("advanced.toolbar_focus"),onfocus:"tinyMCE.getInstanceById('"+r.id+"').focus();"},"<!-- IE -->"));d.setHTML(l,q.join(""))},_addStatusBar:function(m,j){var k,v=this,p=v.editor,w=v.settings,i,q,u,l;k=d.add(m,"tr");k=l=d.add(k,"td",{"class":"mceStatusbar"});k=d.add(k,"div",{id:p.id+"_path_row"},w.theme_advanced_path?p.translate("advanced.path")+": ":" ");d.add(k,"a",{href:"#",accesskey:"x"});if(w.theme_advanced_resizing){d.add(l,"a",{id:p.id+"_resize",href:"javascript:;",onclick:"return false;","class":"mceResize"});if(w.theme_advanced_resizing_use_cookie){p.onPostRender.add(function(){var n=a.getHash("TinyMCE_"+p.id+"_size"),r=d.get(p.id+"_tbl");if(!n){return}v.resizeTo(n.cw,n.ch)})}p.onPostRender.add(function(){b.add(p.id+"_resize","click",function(n){n.preventDefault()});b.add(p.id+"_resize","mousedown",function(D){var t,r,s,o,C,z,A,F,n,E,x;function y(G){G.preventDefault();n=A+(G.screenX-C);E=F+(G.screenY-z);v.resizeTo(n,E)}function B(G){b.remove(d.doc,"mousemove",t);b.remove(p.getDoc(),"mousemove",r);b.remove(d.doc,"mouseup",s);b.remove(p.getDoc(),"mouseup",o);n=A+(G.screenX-C);E=F+(G.screenY-z);v.resizeTo(n,E,true)}D.preventDefault();C=D.screenX;z=D.screenY;x=d.get(v.editor.id+"_ifr");A=n=x.clientWidth;F=E=x.clientHeight;t=b.add(d.doc,"mousemove",y);r=b.add(p.getDoc(),"mousemove",y);s=b.add(d.doc,"mouseup",B);o=b.add(p.getDoc(),"mouseup",B)})})}j.deltaHeight-=21;k=m=null},_nodeChanged:function(r,z,l,x,j){var C=this,i,y=0,B,u,D=C.settings,A,k,w,m,q;e.each(C.stateControls,function(n){z.setActive(n,r.queryCommandState(C.controls[n][1]))});function o(p){var s,n=j.parents,t=p;if(typeof(p)=="string"){t=function(v){return v.nodeName==p}}for(s=0;s<n.length;s++){if(t(n[s])){return n[s]}}}z.setActive("visualaid",r.hasVisual);z.setDisabled("undo",!r.undoManager.hasUndo()&&!r.typing);z.setDisabled("redo",!r.undoManager.hasRedo());z.setDisabled("outdent",!r.queryCommandState("Outdent"));i=o("A");if(u=z.get("link")){if(!i||!i.name){u.setDisabled(!i&&x);u.setActive(!!i)}}if(u=z.get("unlink")){u.setDisabled(!i&&x);u.setActive(!!i&&!i.name)}if(u=z.get("anchor")){u.setActive(!!i&&i.name)}i=o("IMG");if(u=z.get("image")){u.setActive(!!i&&l.className.indexOf("mceItem")==-1)}if(u=z.get("styleselect")){C._importClasses();m=[];f(u.items,function(n){m.push(n.value)});q=r.formatter.matchAll(m);u.select(q[0])}if(u=z.get("formatselect")){i=o(d.isBlock);if(i){u.select(i.nodeName.toLowerCase())}}o(function(p){if(p.nodeName==="SPAN"){if(!A&&p.className){A=p.className}if(!k&&p.style.fontSize){k=p.style.fontSize}if(!w&&p.style.fontFamily){w=p.style.fontFamily.replace(/[\"\']+/g,"").replace(/^([^,]+).*/,"$1").toLowerCase()}}return false});if(u=z.get("fontselect")){u.select(function(n){return n.replace(/^([^,]+).*/,"$1").toLowerCase()==w})}if(u=z.get("fontsizeselect")){if(D.theme_advanced_runtime_fontsize&&!k&&!A){k=r.dom.getStyle(l,"fontSize",true)}u.select(function(n){if(n.fontSize&&n.fontSize===k){return true}if(n["class"]&&n["class"]===A){return true}})}if(D.theme_advanced_path&&D.theme_advanced_statusbar_location){i=d.get(r.id+"_path")||d.add(r.id+"_path_row","span",{id:r.id+"_path"});d.setHTML(i,"");o(function(E){var p=E.nodeName.toLowerCase(),s,v,t="";if(E.nodeType!=1||E.nodeName==="BR"||(d.hasClass(E,"mceItemHidden")||d.hasClass(E,"mceItemRemoved"))){return}if(B=d.getAttrib(E,"mce_name")){p=B}if(e.isIE&&E.scopeName!=="HTML"){p=E.scopeName+":"+p}p=p.replace(/mce\:/g,"");switch(p){case"b":p="strong";break;case"i":p="em";break;case"img":if(B=d.getAttrib(E,"src")){t+="src: "+B+" "}break;case"a":if(B=d.getAttrib(E,"name")){t+="name: "+B+" ";p+="#"+B}if(B=d.getAttrib(E,"href")){t+="href: "+B+" "}break;case"font":if(B=d.getAttrib(E,"face")){t+="font: "+B+" "}if(B=d.getAttrib(E,"size")){t+="size: "+B+" "}if(B=d.getAttrib(E,"color")){t+="color: "+B+" "}break;case"span":if(B=d.getAttrib(E,"style")){t+="style: "+B+" "}break}if(B=d.getAttrib(E,"id")){t+="id: "+B+" "}if(B=E.className){B=B.replace(/\b\s*(webkit|mce|Apple-)\w+\s*\b/g,"");if(B){t+="class: "+B+" ";if(d.isBlock(E)||p=="img"||p=="span"){p+="."+B}}}p=p.replace(/(html:)/g,"");p={name:p,node:E,title:t};C.onResolveName.dispatch(C,p);t=p.title;p=p.name;v=d.create("a",{href:"javascript:;",onmousedown:"return false;",title:t,"class":"mcePath_"+(y++)},p);if(i.hasChildNodes()){i.insertBefore(d.doc.createTextNode(" \u00bb "),i.firstChild);i.insertBefore(v,i.firstChild)}else{i.appendChild(v)}},r.getBody())}},_sel:function(i){this.editor.execCommand("mceSelectNodeDepth",false,i)},_mceInsertAnchor:function(k,j){var i=this.editor;i.windowManager.open({url:this.url+"/anchor.htm",width:320+parseInt(i.getLang("advanced.anchor_delta_width",0)),height:90+parseInt(i.getLang("advanced.anchor_delta_height",0)),inline:true},{theme_url:this.url})},_mceCharMap:function(){var i=this.editor;i.windowManager.open({url:this.url+"/charmap.htm",width:550+parseInt(i.getLang("advanced.charmap_delta_width",0)),height:250+parseInt(i.getLang("advanced.charmap_delta_height",0)),inline:true},{theme_url:this.url})},_mceHelp:function(){var i=this.editor;i.windowManager.open({url:this.url+"/about.htm",width:480,height:380,inline:true},{theme_url:this.url})},_mceColorPicker:function(k,j){var i=this.editor;j=j||{};i.windowManager.open({url:this.url+"/color_picker.htm",width:375+parseInt(i.getLang("advanced.colorpicker_delta_width",0)),height:250+parseInt(i.getLang("advanced.colorpicker_delta_height",0)),close_previous:false,inline:true},{input_color:j.color,func:j.func,theme_url:this.url})},_mceCodeEditor:function(j,k){var i=this.editor;i.windowManager.open({url:this.url+"/source_editor.htm",width:parseInt(i.getParam("theme_advanced_source_editor_width",720)),height:parseInt(i.getParam("theme_advanced_source_editor_height",580)),inline:true,resizable:true,maximizable:true},{theme_url:this.url})},_mceImage:function(j,k){var i=this.editor;if(i.dom.getAttrib(i.selection.getNode(),"class").indexOf("mceItem")!=-1){return}i.windowManager.open({url:this.url+"/image.htm",width:355+parseInt(i.getLang("advanced.image_delta_width",0)),height:275+parseInt(i.getLang("advanced.image_delta_height",0)),inline:true},{theme_url:this.url})},_mceLink:function(j,k){var i=this.editor;i.windowManager.open({url:this.url+"/link.htm",width:310+parseInt(i.getLang("advanced.link_delta_width",0)),height:200+parseInt(i.getLang("advanced.link_delta_height",0)),inline:true},{theme_url:this.url})},_mceNewDocument:function(){var i=this.editor;i.windowManager.confirm("advanced.newdocument",function(j){if(j){i.execCommand("mceSetContent",false,"")}})},_mceForeColor:function(){var i=this;this._mceColorPicker(0,{color:i.fgColor,func:function(j){i.fgColor=j;i.editor.execCommand("ForeColor",false,j)}})},_mceBackColor:function(){var i=this;this._mceColorPicker(0,{color:i.bgColor,func:function(j){i.bgColor=j;i.editor.execCommand("HiliteColor",false,j)}})},_ufirst:function(i){return i.substring(0,1).toUpperCase()+i.substring(1)}});e.ThemeManager.add("advanced",e.themes.AdvancedTheme)}(tinymce)); +\ No newline at end of file diff --git a/chrome/content/zotero/tinymce/themes/advanced/image.htm b/chrome/content/zotero/tinymce/themes/advanced/image.htm @@ -6,7 +6,6 @@ <script type="text/javascript" src="../../utils/mctabs.js"></script> <script type="text/javascript" src="../../utils/form_utils.js"></script> <script type="text/javascript" src="js/image.js"></script> - <base target="_self" /> </head> <body id="image" style="display: none"> <form onsubmit="ImageDialog.update();return false;" action="#"> @@ -20,7 +19,7 @@ <div id="general_panel" class="panel current"> <table border="0" cellpadding="4" cellspacing="0"> <tr> - <td nowrap="nowrap"><label for="src">{#advanced_dlg.image_src}</label></td> + <td class="nowrap"><label for="src">{#advanced_dlg.image_src}</label></td> <td><table border="0" cellspacing="0" cellpadding="0"> <tr> <td><input id="src" name="src" type="text" class="mceFocus" value="" style="width: 200px" onchange="ImageDialog.getImageData();" /></td> @@ -33,11 +32,11 @@ <td><select id="image_list" name="image_list" onchange="document.getElementById('src').value=this.options[this.selectedIndex].value;document.getElementById('alt').value=this.options[this.selectedIndex].text;"></select></td> </tr> <tr> - <td nowrap="nowrap"><label for="alt">{#advanced_dlg.image_alt}</label></td> + <td class="nowrap"><label for="alt">{#advanced_dlg.image_alt}</label></td> <td><input id="alt" name="alt" type="text" value="" style="width: 200px" /></td> </tr> <tr> - <td nowrap="nowrap"><label for="align">{#advanced_dlg.image_align}</label></td> + <td class="nowrap"><label for="align">{#advanced_dlg.image_align}</label></td> <td><select id="align" name="align" onchange="ImageDialog.updateStyle();"> <option value="">{#not_set}</option> <option value="baseline">{#advanced_dlg.image_align_baseline}</option> @@ -51,21 +50,21 @@ </select></td> </tr> <tr> - <td nowrap="nowrap"><label for="width">{#advanced_dlg.image_dimensions}</label></td> + <td class="nowrap"><label for="width">{#advanced_dlg.image_dimensions}</label></td> <td><input id="width" name="width" type="text" value="" size="3" maxlength="5" /> x <input id="height" name="height" type="text" value="" size="3" maxlength="5" /></td> </tr> <tr> - <td nowrap="nowrap"><label for="border">{#advanced_dlg.image_border}</label></td> + <td class="nowrap"><label for="border">{#advanced_dlg.image_border}</label></td> <td><input id="border" name="border" type="text" value="" size="3" maxlength="3" onchange="ImageDialog.updateStyle();" /></td> </tr> <tr> - <td nowrap="nowrap"><label for="vspace">{#advanced_dlg.image_vspace}</label></td> + <td class="nowrap"><label for="vspace">{#advanced_dlg.image_vspace}</label></td> <td><input id="vspace" name="vspace" type="text" value="" size="3" maxlength="3" onchange="ImageDialog.updateStyle();" /></td> </tr> <tr> - <td nowrap="nowrap"><label for="hspace">{#advanced_dlg.image_hspace}</label></td> + <td class="nowrap"><label for="hspace">{#advanced_dlg.image_hspace}</label></td> <td><input id="hspace" name="hspace" type="text" value="" size="3" maxlength="3" onchange="ImageDialog.updateStyle();" /></td> </tr> </table> @@ -73,13 +72,8 @@ </div> <div class="mceActionPanel"> - <div style="float: left"> - <input type="submit" id="insert" name="insert" value="{#insert}" /> - </div> - - <div style="float: right"> - <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> - </div> + <input type="submit" id="insert" name="insert" value="{#insert}" /> + <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> </div> </form> </body> diff --git a/chrome/content/zotero/tinymce/themes/advanced/img/icons.gif b/chrome/content/zotero/tinymce/themes/advanced/img/icons.gif Binary files differ. diff --git a/chrome/content/zotero/tinymce/themes/advanced/js/anchor.js b/chrome/content/zotero/tinymce/themes/advanced/js/anchor.js @@ -5,7 +5,7 @@ var AnchorDialog = { var action, elm, f = document.forms[0]; this.editor = ed; - elm = ed.dom.getParent(ed.selection.getNode(), 'A,IMG'); + elm = ed.dom.getParent(ed.selection.getNode(), 'A'); v = ed.dom.getAttrib(elm, 'name'); if (v) { @@ -17,18 +17,18 @@ var AnchorDialog = { }, update : function() { - var ed = this.editor; - + var ed = this.editor, elm, name = document.forms[0].anchorName.value; + tinyMCEPopup.restoreSelection(); if (this.action != 'update') ed.selection.collapse(1); - // Webkit acts weird if empty inline element is inserted so we need to use a image instead - if (tinymce.isWebKit) - ed.execCommand('mceInsertContent', 0, ed.dom.createHTML('img', {mce_name : 'a', name : document.forms[0].anchorName.value, 'class' : 'mceItemAnchor'})); + elm = ed.dom.getParent(ed.selection.getNode(), 'A'); + if (elm) + elm.name = name; else - ed.execCommand('mceInsertContent', 0, ed.dom.createHTML('a', {name : document.forms[0].anchorName.value, 'class' : 'mceItemAnchor'}, '')); + ed.execCommand('mceInsertContent', 0, ed.dom.createHTML('a', {name : name, 'class' : 'mceItemAnchor'}, '')); tinyMCEPopup.close(); } diff --git a/chrome/content/zotero/tinymce/themes/advanced/js/charmap.js b/chrome/content/zotero/tinymce/themes/advanced/js/charmap.js @@ -1,3 +1,13 @@ +/** + * charmap.js + * + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. + * + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing + */ + tinyMCEPopup.requireLangPack(); var charmap = [ diff --git a/chrome/content/zotero/tinymce/themes/advanced/js/image.js b/chrome/content/zotero/tinymce/themes/advanced/js/image.js @@ -151,8 +151,8 @@ var ImageDialog = { } // Merge - st = tinyMCEPopup.dom.parseStyle(dom.serializeStyle(st)); - this.styleVal = dom.serializeStyle(st); + st = tinyMCEPopup.dom.parseStyle(dom.serializeStyle(st), 'img'); + this.styleVal = dom.serializeStyle(st, 'img'); } }, diff --git a/chrome/content/zotero/tinymce/themes/advanced/js/link.js b/chrome/content/zotero/tinymce/themes/advanced/js/link.js @@ -53,6 +53,7 @@ var LinkDialog = { // Create new anchor elements if (e == null) { + ed.getDoc().execCommand("unlink", false, null); tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1}); tinymce.each(ed.dom.select("a"), function(n) { @@ -62,8 +63,8 @@ var LinkDialog = { ed.dom.setAttribs(e, { href : f.href.value, title : f.linktitle.value, - target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null, - 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null + target : f.target_list ? getSelectValue(f, "target_list") : null, + 'class' : f.class_list ? getSelectValue(f, "class_list") : null }); } }); @@ -71,8 +72,8 @@ var LinkDialog = { ed.dom.setAttribs(e, { href : f.href.value, title : f.linktitle.value, - target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null, - 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null + target : f.target_list ? getSelectValue(f, "target_list") : null, + 'class' : f.class_list ? getSelectValue(f, "class_list") : null }); } @@ -92,7 +93,7 @@ var LinkDialog = { if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email'))) n.value = 'mailto:' + n.value; - if (/^\s*www./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external'))) + if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external'))) n.value = 'http://' + n.value; }, diff --git a/chrome/content/zotero/tinymce/themes/advanced/js/source_editor.js b/chrome/content/zotero/tinymce/themes/advanced/js/source_editor.js @@ -2,7 +2,7 @@ tinyMCEPopup.requireLangPack(); tinyMCEPopup.onInit.add(onLoadInit); function saveContent() { - tinyMCEPopup.editor.setContent(document.getElementById('htmlSource').value); + tinyMCEPopup.editor.setContent(document.getElementById('htmlSource').value, {source_view : true}); tinyMCEPopup.close(); } @@ -13,7 +13,7 @@ function onLoadInit() { if (tinymce.isGecko) document.body.spellcheck = tinyMCEPopup.editor.getParam("gecko_spellcheck"); - document.getElementById('htmlSource').value = tinyMCEPopup.editor.getContent(); + document.getElementById('htmlSource').value = tinyMCEPopup.editor.getContent({source_view : true}); if (tinyMCEPopup.editor.getParam("theme_advanced_source_editor_wrap", true)) { setWrap('soft'); @@ -44,19 +44,13 @@ function toggleWordWrap(elm) { setWrap('off'); } -var wHeight=0, wWidth=0, owHeight=0, owWidth=0; - function resizeInputs() { - var el = document.getElementById('htmlSource'); + var vp = tinyMCEPopup.dom.getViewPort(window), el; - if (!tinymce.isIE) { - wHeight = self.innerHeight - 65; - wWidth = self.innerWidth - 16; - } else { - wHeight = document.body.clientHeight - 70; - wWidth = document.body.clientWidth - 16; - } + el = document.getElementById('htmlSource'); - el.style.height = Math.abs(wHeight) + 'px'; - el.style.width = Math.abs(wWidth) + 'px'; + if (el) { + el.style.width = (vp.w - 20) + 'px'; + el.style.height = (vp.h - 65) + 'px'; + } } diff --git a/chrome/content/zotero/tinymce/themes/advanced/link.htm b/chrome/content/zotero/tinymce/themes/advanced/link.htm @@ -7,7 +7,6 @@ <script type="text/javascript" src="../../utils/form_utils.js"></script> <script type="text/javascript" src="../../utils/validate.js"></script> <script type="text/javascript" src="js/link.js"></script> - <base target="_self" /> </head> <body id="link" style="display: none"> <form onsubmit="LinkDialog.update();return false;" action="#"> @@ -22,7 +21,7 @@ <table border="0" cellpadding="4" cellspacing="0"> <tr> - <td nowrap="nowrap"><label for="href">{#advanced_dlg.link_url}</label></td> + <td class="nowrap"><label for="href">{#advanced_dlg.link_url}</label></td> <td><table border="0" cellspacing="0" cellpadding="0"> <tr> <td><input id="href" name="href" type="text" class="mceFocus" value="" style="width: 200px" onchange="LinkDialog.checkPrefix(this);" /></td> @@ -39,7 +38,7 @@ <td><select id="target_list" name="target_list"></select></td> </tr> <tr> - <td nowrap="nowrap"><label for="linktitle">{#advanced_dlg.link_titlefield}</label></td> + <td class="nowrap"><label for="linktitle">{#advanced_dlg.link_titlefield}</label></td> <td><input id="linktitle" name="linktitle" type="text" value="" style="width: 200px" /></td> </tr> <tr> @@ -51,13 +50,8 @@ </div> <div class="mceActionPanel"> - <div style="float: left"> - <input type="submit" id="insert" name="insert" value="{#insert}" /> - </div> - - <div style="float: right"> - <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> - </div> + <input type="submit" id="insert" name="insert" value="{#insert}" /> + <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> </div> </form> </body> diff --git a/chrome/content/zotero/tinymce/themes/advanced/skins/default/content.css b/chrome/content/zotero/tinymce/themes/advanced/skins/default/content.css @@ -8,8 +8,9 @@ h4 {font-size: 1em} h5 {font-size: .83em} h6 {font-size: .75em} .mceItemTable, .mceItemTable td, .mceItemTable th, .mceItemTable caption, .mceItemVisualAid {border: 1px dashed #BBB;} -a.mceItemAnchor {width:12px; line-height:6px; overflow:hidden; padding-left:12px; background:url(img/items.gif) no-repeat bottom left;} -img.mceItemAnchor {width:12px; height:12px; background:url(img/items.gif) no-repeat;} +a.mceItemAnchor {display:inline-block; width:11px !important; height:11px !important; background:url(img/items.gif) no-repeat 0 0;} +span.mceItemNbsp {background: #DDD} +td.mceSelected, th.mceSelected {background-color:#3399ff !important} img {border:0;} table {cursor:default} table td, table th {cursor:text} @@ -17,7 +18,7 @@ ins {border-bottom:1px solid green; text-decoration: none; color:green} del {color:red; text-decoration:line-through} cite {border-bottom:1px dashed blue} acronym {border-bottom:1px dotted #CCC; cursor:help} -abbr, html\:abbr {border-bottom:1px dashed #CCC; cursor:help} +abbr {border-bottom:1px dashed #CCC; cursor:help} /* IE */ * html body { @@ -30,3 +31,6 @@ scrollbar-highlight-color:#F0F0EE; scrollbar-shadow-color:#F0F0EE; scrollbar-track-color:#F5F5F5; } + +img:-moz-broken {-moz-force-broken-image-icon:1; width:24px; height:24px} +font[face=mceinline] {font-family:inherit !important} diff --git a/chrome/content/zotero/tinymce/themes/advanced/skins/default/dialog.css b/chrome/content/zotero/tinymce/themes/advanced/skins/default/dialog.css @@ -19,6 +19,7 @@ td {font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;} textarea {resize:none;outline:none;} a:link, a:visited {color:black;} a:hover {color:#2B6FB6;} +.nowrap {white-space: nowrap} /* Forms */ fieldset {margin:0; padding:4px; border:1px solid #919B9C; font-family:Verdana, Arial; font-size:10px;} @@ -41,16 +42,18 @@ width:94px; height:26px; background:url(img/buttons.png) 0 -26px; cursor:pointer; padding-bottom:2px; +float:left; } -#insert {background:url(img/buttons.png) 0 -52px;} -#cancel {background:url(img/buttons.png) 0 0;} +#insert {background:url(img/buttons.png) 0 -52px} +#cancel {background:url(img/buttons.png) 0 0; float:right} /* Browse */ +a.pickcolor, a.browse {text-decoration:none} a.browse span {display:block; width:20px; height:18px; background:url(../../img/icons.gif) -860px 0; border:1px solid #FFF; margin-left:1px;} .mceOldBoxModel a.browse span {width:22px; height:20px;} a.browse:hover span {border:1px solid #0A246A; background-color:#B2BBD0;} -a.browse span.disabled {border:1px solid white; -moz-opacity:0.3; opacity:0.3; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);} +a.browse span.disabled {border:1px solid white; opacity:0.3; -ms-filter:'alpha(opacity=30)'; filter:alpha(opacity=30)} a.browse:hover span.disabled {border:1px solid white; background-color:transparent;} a.pickcolor span {display:block; width:20px; height:16px; background:url(../../img/icons.gif) -840px 0; margin-left:2px;} .mceOldBoxModel a.pickcolor span {width:21px; height:17px;} @@ -111,4 +114,4 @@ h3 {font-size:14px;} #colorpicker #namedcolors {width:150px;} #colorpicker #namedcolors a {display:block; float:left; width:10px; height:10px; margin:1px 1px 0 0; overflow:hidden;} #colorpicker #colornamecontainer {margin-top:5px;} -#colorpicker #picker_panel fieldset {margin:auto;width:325px;} -\ No newline at end of file +#colorpicker #picker_panel fieldset {margin:auto;width:325px;} diff --git a/chrome/content/zotero/tinymce/themes/advanced/skins/default/ui.css b/chrome/content/zotero/tinymce/themes/advanced/skins/default/ui.css @@ -4,7 +4,7 @@ .defaultSkin table td {vertical-align:middle} /* Containers */ -.defaultSkin table {background:#F0F0EE} +.defaultSkin table {direction:ltr; background:#F0F0EE} .defaultSkin iframe {display:block; background:#FFF} .defaultSkin .mceToolbar {height:26px} .defaultSkin .mceLeft {text-align:left} @@ -24,7 +24,7 @@ .defaultSkin .mceIframeContainer {border-top:1px solid #CCC; border-bottom:1px solid #CCC} .defaultSkin .mceStatusbar {font-family:'MS Sans Serif',sans-serif,Verdana,Arial; font-size:9pt; line-height:16px; overflow:visible; color:#000; display:block; height:20px} .defaultSkin .mceStatusbar div {float:left; margin:2px} -.defaultSkin .mceStatusbar a.mceResize {display:block; float:right; background:url(../../img/icons.gif) -800px 0; width:20px; height:20px; cursor:se-resize} +.defaultSkin .mceStatusbar a.mceResize {display:block; float:right; background:url(../../img/icons.gif) -800px 0; width:20px; height:20px; cursor:se-resize; outline:0} .defaultSkin .mceStatusbar a:hover {text-decoration:underline} .defaultSkin table.mceToolbar {margin-left:3px} .defaultSkin span.mceIcon, .defaultSkin img.mceIcon {display:block; width:20px; height:20px} @@ -37,7 +37,7 @@ .defaultSkin .mceButton {display:block; border:1px solid #F0F0EE; width:20px; height:20px; margin-right:1px} .defaultSkin a.mceButtonEnabled:hover {border:1px solid #0A246A; background-color:#B2BBD0} .defaultSkin a.mceButtonActive, .defaultSkin a.mceButtonSelected {border:1px solid #0A246A; background-color:#C2CBE0} -.defaultSkin .mceButtonDisabled .mceIcon {opacity:0.3; filter:alpha(opacity=30)} +.defaultSkin .mceButtonDisabled .mceIcon {opacity:0.3; -ms-filter:'alpha(opacity=30)'; filter:alpha(opacity=30)} .defaultSkin .mceButtonLabeled {width:auto} .defaultSkin .mceButtonLabeled span.mceIcon {float:left} .defaultSkin span.mceButtonLabel {display:block; font-size:10px; padding:4px 6px 0 22px; font-family:Tahoma,Verdana,Arial,Helvetica} @@ -47,12 +47,9 @@ .defaultSkin .mceSeparator {display:block; background:url(../../img/icons.gif) -180px 0; width:2px; height:20px; margin:2px 2px 0 4px} /* ListBox */ -.defaultSkin .mceListBox {direction:ltr} .defaultSkin .mceListBox, .defaultSkin .mceListBox a {display:block} -/* width changed to 65px by Dan S./Zotero */ -.defaultSkin .mceListBox .mceText {padding-left:4px; width:65px; text-align:left; border:1px solid #CCC; border-right:0; background:#FFF; font-family:Tahoma,Verdana,Arial,Helvetica; font-size:11px; height:20px; line-height:20px; overflow:hidden} -/* margin-right changed to 1px by Dan S./Zotero */ -.defaultSkin .mceListBox .mceOpen {width:9px; height:20px; background:url(../../img/icons.gif) -741px 0; margin-right:1px; border:1px solid #CCC;} +.defaultSkin .mceListBox .mceText {padding-left:4px; width:70px; text-align:left; border:1px solid #CCC; border-right:0; background:#FFF; font-family:Tahoma,Verdana,Arial,Helvetica; font-size:11px; height:20px; line-height:20px; overflow:hidden} +.defaultSkin .mceListBox .mceOpen {width:9px; height:20px; background:url(../../img/icons.gif) -741px 0; margin-right:2px; border:1px solid #CCC;} .defaultSkin table.mceListBoxEnabled:hover .mceText, .defaultSkin .mceListBoxHover .mceText, .defaultSkin .mceListBoxSelected .mceText {border:1px solid #A2ABC0; border-right:0; background:#FFF} .defaultSkin table.mceListBoxEnabled:hover .mceOpen, .defaultSkin .mceListBoxHover .mceOpen, .defaultSkin .mceListBoxSelected .mceOpen {background-color:#FFF; border:1px solid #A2ABC0} .defaultSkin .mceListBoxDisabled a.mceText {color:gray; background-color:transparent;} @@ -65,13 +62,12 @@ .defaultSkin .mceSplitButton {width:32px; height:20px; direction:ltr} .defaultSkin .mceSplitButton a, .defaultSkin .mceSplitButton span {height:20px; display:block} .defaultSkin .mceSplitButton a.mceAction {width:20px; border:1px solid #F0F0EE; border-right:0;} -.defaultSkin .mceSplitButton span.mceAction {width:20px; background:url(../../img/icons.gif) 20px 20px;} -.defaultSkin .mceSplitButton a.mceOpen {width:9px; border:1px solid #F0F0EE;} -.defaultSkin .mceSplitButton span.mceOpen {width:9px; background:url(../../img/icons.gif) -741px 0;} +.defaultSkin .mceSplitButton span.mceAction {width:20px; background-image:url(../../img/icons.gif);} +.defaultSkin .mceSplitButton a.mceOpen {width:9px; background:url(../../img/icons.gif) -741px 0; border:1px solid #F0F0EE;} +.defaultSkin .mceSplitButton span.mceOpen {display:none} .defaultSkin table.mceSplitButtonEnabled:hover a.mceAction, .defaultSkin .mceSplitButtonHover a.mceAction, .defaultSkin .mceSplitButtonSelected a.mceAction {border:1px solid #0A246A; border-right:0; background-color:#B2BBD0} -.defaultSkin table.mceSplitButtonEnabled:hover a.mceOpen, .defaultSkin .mceSplitButtonHover a.mceOpen, .defaultSkin .mceSplitButtonSelected a.mceOpen {border:1px solid #0A246A;} -.defaultSkin table.mceSplitButtonEnabled:hover span.mceOpen, .defaultSkin .mceSplitButtonHover span.mceOpen, .defaultSkin .mceSplitButtonSelected span.mceOpen {background-color:#B2BBD0} -.defaultSkin .mceSplitButtonDisabled .mceAction, .defaultSkin .mceSplitButtonDisabled span.mceOpen {opacity:0.3; filter:alpha(opacity=30)} +.defaultSkin table.mceSplitButtonEnabled:hover a.mceOpen, .defaultSkin .mceSplitButtonHover a.mceOpen, .defaultSkin .mceSplitButtonSelected a.mceOpen {background-color:#B2BBD0; border:1px solid #0A246A;} +.defaultSkin .mceSplitButtonDisabled .mceAction, .defaultSkin .mceSplitButtonDisabled a.mceOpen {opacity:0.3; -ms-filter:'alpha(opacity=30)'; filter:alpha(opacity=30)} .defaultSkin .mceSplitButtonActive a.mceAction {border:1px solid #0A246A; background-color:#C2CBE0} .defaultSkin .mceSplitButtonActive a.mceOpen {border-left:0;} @@ -109,9 +105,8 @@ .defaultSkin .mceMenuItemSub a {background:url(img/menu_arrow.gif) no-repeat top right;} /* Progress,Resize */ -.defaultSkin .mceBlocker {position:absolute; left:0; top:0; z-index:1000; opacity:0.5; filter:alpha(opacity=50); background:#FFF} +.defaultSkin .mceBlocker {position:absolute; left:0; top:0; z-index:1000; opacity:0.5; -ms-filter:'alpha(opacity=50)'; filter:alpha(opacity=50); background:#FFF} .defaultSkin .mceProgress {position:absolute; left:0; top:0; z-index:1001; background:url(img/progress.gif) no-repeat; width:32px; height:32px; margin:-16px 0 0 -16px} -.defaultSkin .mcePlaceHolder {border:1px dotted gray} /* Formats */ .defaultSkin .mce_formatPreview a {font-size:10px} @@ -214,4 +209,5 @@ .defaultSkin span.mce_del {background-position:-940px -20px} .defaultSkin span.mce_ins {background-position:-960px -20px} .defaultSkin span.mce_pagebreak {background-position:0 -40px} -.defaultSkin .mce_spellchecker span.mceAction {background-position:-540px -20px} +.defaultSkin span.mce_restoredraft {background-position:-20px -40px} +.defaultSkin span.mce_spellchecker {background-position:-540px -20px} diff --git a/chrome/content/zotero/tinymce/themes/advanced/source_editor.htm b/chrome/content/zotero/tinymce/themes/advanced/source_editor.htm @@ -1,10 +1,8 @@ <html xmlns="http://www.w3.org/1999/xhtml"> <head> - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>{#advanced_dlg.code_title}</title> <script type="text/javascript" src="../../tiny_mce_popup.js"></script> <script type="text/javascript" src="js/source_editor.js"></script> - <base target="_self" /> </head> <body onresize="resizeInputs();" style="display:none; overflow:hidden;"> <form name="source" onsubmit="saveContent();return false;" action="#"> @@ -19,13 +17,8 @@ <textarea name="htmlSource" id="htmlSource" rows="15" cols="100" style="width: 100%; height: 100%; font-family: 'Courier New',Courier,monospace; font-size: 12px;" dir="ltr" wrap="off" class="mceFocus"></textarea> <div class="mceActionPanel"> - <div style="float: left"> - <input type="submit" name="insert" value="{#update}" id="insert" /> - </div> - - <div style="float: right"> - <input type="button" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" id="cancel" /> - </div> + <input type="submit" name="insert" value="{#update}" id="insert" /> + <input type="button" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" id="cancel" /> </div> </form> </body> diff --git a/chrome/content/zotero/tinymce/tiny_mce.js b/chrome/content/zotero/tinymce/tiny_mce.js @@ -1,432 +1,468 @@ -/* - * Contains modifications by Zotero (commented) - */ -var tinymce = { - majorVersion : '3', - minorVersion : '2.5', - releaseDate : '2009-06-29', - - _init : function() { - var t = this, d = document, w = window, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; - - // Browser checks - t.isOpera = w.opera && opera.buildNumber; - t.isWebKit = /WebKit/.test(ua); - t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); - t.isIE6 = t.isIE && /MSIE [56]/.test(ua); - t.isGecko = !t.isWebKit && /Gecko/.test(ua); - t.isMac = ua.indexOf('Mac') != -1; - t.isAir = /adobeair/i.test(ua); - - // TinyMCE .NET webcontrol might be setting the values for TinyMCE - if (w.tinyMCEPreInit) { - t.suffix = tinyMCEPreInit.suffix; - t.baseURL = tinyMCEPreInit.base; - t.query = tinyMCEPreInit.query; - return; - } +(function(win) { + var whiteSpaceRe = /^\s*|\s*$/g, + undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1'; - // Get suffix and base - t.suffix = ''; + var tinymce = { + majorVersion : '3', - // If base element found, add that infront of baseURL - nl = d.getElementsByTagName('base'); - for (i=0; i<nl.length; i++) { - if (v = nl[i].href) { - // Host only value like http://site.com or http://site.com:8008 - if (/^https?:\/\/[^\/]+$/.test(v)) - v += '/'; + minorVersion : '3.9.2', - base = v ? v.match(/.*\//)[0] : ''; // Get only directory - } - } + releaseDate : '2010-09-29', - function getBase(n) { - if (n.src && /tiny_mce(|_gzip|_jquery|_prototype)(_dev|_src)?.js/.test(n.src)) { - if (/_(src|dev)\.js/g.test(n.src)) - t.suffix = '_src'; + _init : function() { + var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; - if ((p = n.src.indexOf('?')) != -1) - t.query = n.src.substring(p + 1); + t.isOpera = win.opera && opera.buildNumber; - t.baseURL = n.src.substring(0, n.src.lastIndexOf('/')); + t.isWebKit = /WebKit/.test(ua); - // If path to script is relative and a base href was found add that one infront - if (base && t.baseURL.indexOf('://') == -1) - t.baseURL = base + t.baseURL; + t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); - return t.baseURL; - } + t.isIE6 = t.isIE && /MSIE [56]/.test(ua); - return null; - }; + t.isGecko = !t.isWebKit && /Gecko/.test(ua); + + t.isMac = ua.indexOf('Mac') != -1; + + t.isAir = /adobeair/i.test(ua); + + t.isIDevice = /(iPad|iPhone)/.test(ua); - // Check document - nl = d.getElementsByTagName('script'); - for (i=0; i<nl.length; i++) { - if (getBase(nl[i])) + // TinyMCE .NET webcontrol might be setting the values for TinyMCE + if (win.tinyMCEPreInit) { + t.suffix = tinyMCEPreInit.suffix; + t.baseURL = tinyMCEPreInit.base; + t.query = tinyMCEPreInit.query; return; - } + } + + // Get suffix and base + t.suffix = ''; + + // If base element found, add that infront of baseURL + nl = d.getElementsByTagName('base'); + for (i=0; i<nl.length; i++) { + if (v = nl[i].href) { + // Host only value like http://site.com or http://site.com:8008 + if (/^https?:\/\/[^\/]+$/.test(v)) + v += '/'; + + base = v ? v.match(/.*\//)[0] : ''; // Get only directory + } + } + + function getBase(n) { + if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) { + if (/_(src|dev)\.js/g.test(n.src)) + t.suffix = '_src'; + + if ((p = n.src.indexOf('?')) != -1) + t.query = n.src.substring(p + 1); + + t.baseURL = n.src.substring(0, n.src.lastIndexOf('/')); + + // If path to script is relative and a base href was found add that one infront + // the src property will always be an absolute one on non IE browsers and IE 8 + // so this logic will basically only be executed on older IE versions + if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0) + t.baseURL = base + t.baseURL; - // Check head - n = d.getElementsByTagName('head')[0]; - if (n) { - nl = n.getElementsByTagName('script'); + return t.baseURL; + } + + return null; + }; + + // Check document + nl = d.getElementsByTagName('script'); for (i=0; i<nl.length; i++) { if (getBase(nl[i])) return; } - } - - return; - }, - is : function(o, t) { - var n = typeof(o); + // Check head + n = d.getElementsByTagName('head')[0]; + if (n) { + nl = n.getElementsByTagName('script'); + for (i=0; i<nl.length; i++) { + if (getBase(nl[i])) + return; + } + } - if (!t) - return n != 'undefined'; + return; + }, - if (t == 'array' && (o.hasOwnProperty && o instanceof Array)) - return true; + is : function(o, t) { + if (!t) + return o !== undefined; - return n == t; - }, + if (t == 'array' && (o.hasOwnProperty && o instanceof Array)) + return true; + return typeof(o) == t; + }, - each : function(o, cb, s) { - var n, l; + each : function(o, cb, s) { + var n, l; - if (!o) - return 0; + if (!o) + return 0; - s = s || o; + s = s || o; - if (typeof(o.length) != 'undefined') { - // Indexed arrays, needed for Safari - for (n=0, l = o.length; n<l; n++) { - if (cb.call(s, o[n], n, o) === false) - return 0; - } - } else { - // Hashtables - for (n in o) { - if (o.hasOwnProperty(n)) { + if (o.length !== undefined) { + // Indexed arrays, needed for Safari + for (n=0, l = o.length; n < l; n++) { if (cb.call(s, o[n], n, o) === false) return 0; } + } else { + // Hashtables + for (n in o) { + if (o.hasOwnProperty(n)) { + if (cb.call(s, o[n], n, o) === false) + return 0; + } + } } - } - return 1; - }, + return 1; + }, - map : function(a, f) { - var o = []; - tinymce.each(a, function(v) { - o.push(f(v)); - }); + map : function(a, f) { + var o = []; - return o; - }, + tinymce.each(a, function(v) { + o.push(f(v)); + }); - grep : function(a, f) { - var o = []; + return o; + }, - tinymce.each(a, function(v) { - if (!f || f(v)) - o.push(v); - }); + grep : function(a, f) { + var o = []; - return o; - }, + tinymce.each(a, function(v) { + if (!f || f(v)) + o.push(v); + }); - inArray : function(a, v) { - var i, l; + return o; + }, - if (a) { - for (i = 0, l = a.length; i < l; i++) { - if (a[i] === v) - return i; - } - } + inArray : function(a, v) { + var i, l; - return -1; - }, + if (a) { + for (i = 0, l = a.length; i < l; i++) { + if (a[i] === v) + return i; + } + } - extend : function(o, e) { - var i, a = arguments; + return -1; + }, - for (i=1; i<a.length; i++) { - e = a[i]; + extend : function(o, e) { + var i, l, a = arguments; - tinymce.each(e, function(v, n) { - if (typeof(v) !== 'undefined') - o[n] = v; - }); - } + for (i = 1, l = a.length; i < l; i++) { + e = a[i]; - return o; - }, + tinymce.each(e, function(v, n) { + if (v !== undefined) + o[n] = v; + }); + } + return o; + }, - trim : function(s) { - return (s ? '' + s : '').replace(/^\s*|\s*$/g, ''); - }, - create : function(s, p) { - var t = this, sp, ns, cn, scn, c, de = 0; + trim : function(s) { + return (s ? '' + s : '').replace(whiteSpaceRe, ''); + }, - // Parse : <prefix> <class>:<super class> - s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); - cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name + create : function(s, p) { + var t = this, sp, ns, cn, scn, c, de = 0; - // Create namespace for new class - ns = t.createNS(s[3].replace(/\.\w+$/, '')); + // Parse : <prefix> <class>:<super class> + s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); + cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name - // Class already exists - if (ns[cn]) - return; + // Create namespace for new class + ns = t.createNS(s[3].replace(/\.\w+$/, '')); - // Make pure static class - if (s[2] == 'static') { - ns[cn] = p; + // Class already exists + if (ns[cn]) + return; - if (this.onCreate) - this.onCreate(s[2], s[3], ns[cn]); + // Make pure static class + if (s[2] == 'static') { + ns[cn] = p; - return; - } + if (this.onCreate) + this.onCreate(s[2], s[3], ns[cn]); - // Create default constructor - if (!p[cn]) { - p[cn] = function() {}; - de = 1; - } + return; + } - // Add constructor and methods - ns[cn] = p[cn]; - t.extend(ns[cn].prototype, p); - - // Extend - if (s[5]) { - sp = t.resolve(s[5]).prototype; - scn = s[5].match(/\.(\w+)$/i)[1]; // Class name - - // Extend constructor - c = ns[cn]; - if (de) { - // Add passthrough constructor - ns[cn] = function() { - return sp[scn].apply(this, arguments); - }; - } else { - // Add inherit constructor - ns[cn] = function() { - this.parent = sp[scn]; - return c.apply(this, arguments); - }; + // Create default constructor + if (!p[cn]) { + p[cn] = function() {}; + de = 1; } - ns[cn].prototype[cn] = ns[cn]; - // Add super methods - t.each(sp, function(f, n) { - ns[cn].prototype[n] = sp[n]; - }); + // Add constructor and methods + ns[cn] = p[cn]; + t.extend(ns[cn].prototype, p); - // Add overridden methods - t.each(p, function(f, n) { - // Extend methods if needed - if (sp[n]) { - ns[cn].prototype[n] = function() { - this.parent = sp[n]; - return f.apply(this, arguments); + // Extend + if (s[5]) { + sp = t.resolve(s[5]).prototype; + scn = s[5].match(/\.(\w+)$/i)[1]; // Class name + + // Extend constructor + c = ns[cn]; + if (de) { + // Add passthrough constructor + ns[cn] = function() { + return sp[scn].apply(this, arguments); }; } else { - if (n != cn) - ns[cn].prototype[n] = f; + // Add inherit constructor + ns[cn] = function() { + this.parent = sp[scn]; + return c.apply(this, arguments); + }; } + ns[cn].prototype[cn] = ns[cn]; + + // Add super methods + t.each(sp, function(f, n) { + ns[cn].prototype[n] = sp[n]; + }); + + // Add overridden methods + t.each(p, function(f, n) { + // Extend methods if needed + if (sp[n]) { + ns[cn].prototype[n] = function() { + this.parent = sp[n]; + return f.apply(this, arguments); + }; + } else { + if (n != cn) + ns[cn].prototype[n] = f; + } + }); + } + + // Add static methods + t.each(p['static'], function(f, n) { + ns[cn][n] = f; }); - } - // Add static methods - t.each(p['static'], function(f, n) { - ns[cn][n] = f; - }); + if (this.onCreate) + this.onCreate(s[2], s[3], ns[cn].prototype); + }, - if (this.onCreate) - this.onCreate(s[2], s[3], ns[cn].prototype); - }, + walk : function(o, f, n, s) { + s = s || this; - walk : function(o, f, n, s) { - s = s || this; + if (o) { + if (n) + o = o[n]; - if (o) { - if (n) - o = o[n]; + tinymce.each(o, function(o, i) { + if (f.call(s, o, i, n) === false) + return false; - tinymce.each(o, function(o, i) { - if (f.call(s, o, i, n) === false) - return false; + tinymce.walk(o, f, n, s); + }); + } + }, - tinymce.walk(o, f, n, s); - }); - } - }, + createNS : function(n, o) { + var i, v; - createNS : function(n, o) { - var i, v; + o = o || win; - o = o || window; + n = n.split('.'); + for (i=0; i<n.length; i++) { + v = n[i]; - n = n.split('.'); - for (i=0; i<n.length; i++) { - v = n[i]; + if (!o[v]) + o[v] = {}; - if (!o[v]) - o[v] = {}; + o = o[v]; + } - o = o[v]; - } + return o; + }, - return o; - }, + resolve : function(n, o) { + var i, l; - resolve : function(n, o) { - var i, l; + o = o || win; - o = o || window; + n = n.split('.'); + for (i = 0, l = n.length; i < l; i++) { + o = o[n[i]]; - n = n.split('.'); - for (i=0, l = n.length; i<l; i++) { - o = o[n[i]]; + if (!o) + break; + } - if (!o) - break; - } + return o; + }, - return o; - }, + addUnload : function(f, s) { + var t = this; - addUnload : function(f, s) { - var t = this, w = window; + f = {func : f, scope : s || this}; - f = {func : f, scope : s || this}; + if (!t.unloads) { + function unload() { + var li = t.unloads, o, n; - if (!t.unloads) { - function unload() { - var li = t.unloads, o, n; + if (li) { + // Call unload handlers + for (n in li) { + o = li[n]; - if (li) { - // Call unload handlers - for (n in li) { - o = li[n]; + if (o && o.func) + o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy + } + + // Detach unload function + if (win.detachEvent) { + win.detachEvent('onbeforeunload', fakeUnload); + win.detachEvent('onunload', unload); + } else if (win.removeEventListener) + win.removeEventListener('unload', unload, false); - if (o && o.func) - o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy + // Destroy references + t.unloads = o = li = w = unload = 0; + + // Run garbarge collector on IE + if (win.CollectGarbage) + CollectGarbage(); } + }; - // Detach unload function - if (w.detachEvent) { - w.detachEvent('onbeforeunload', fakeUnload); - w.detachEvent('onunload', unload); - } else if (w.removeEventListener) - w.removeEventListener('unload', unload, false); + function fakeUnload() { + var d = document; - // Destroy references - t.unloads = o = li = w = unload = 0; + // Is there things still loading, then do some magic + if (d.readyState == 'interactive') { + function stop() { + // Prevent memory leak + d.detachEvent('onstop', stop); - // Run garbarge collector on IE - if (window.CollectGarbage) - window.CollectGarbage(); - } - }; + // Call unload handler + if (unload) + unload(); - function fakeUnload() { - var d = document; + d = 0; + }; - // Is there things still loading, then do some magic - if (d.readyState == 'interactive') { - function stop() { - // Prevent memory leak - d.detachEvent('onstop', stop); + // Fire unload when the currently loading page is stopped + if (d) + d.attachEvent('onstop', stop); + + // Remove onstop listener after a while to prevent the unload function + // to execute if the user presses cancel in an onbeforeunload + // confirm dialog and then presses the browser stop button + win.setTimeout(function() { + if (d) + d.detachEvent('onstop', stop); + }, 0); + } + }; - // Call unload handler - if (unload) - unload(); + // Attach unload handler + if (win.attachEvent) { + win.attachEvent('onunload', unload); + win.attachEvent('onbeforeunload', fakeUnload); + } else if (win.addEventListener) + win.addEventListener('unload', unload, false); - d = 0; - }; + // Setup initial unload handler array + t.unloads = [f]; + } else + t.unloads.push(f); - // Fire unload when the currently loading page is stopped - if (d) - d.attachEvent('onstop', stop); + return f; + }, - // Remove onstop listener after a while to prevent the unload function - // to execute if the user presses cancel in an onbeforeunload - // confirm dialog and then presses the browser stop button - window.setTimeout(function() { - if (d) - d.detachEvent('onstop', stop); - }, 0); + removeUnload : function(f) { + var u = this.unloads, r = null; + + tinymce.each(u, function(o, i) { + if (o && o.func == f) { + u.splice(i, 1); + r = f; + return false; } - }; + }); - // Attach unload handler - if (w.attachEvent) { - w.attachEvent('onunload', unload); - w.attachEvent('onbeforeunload', fakeUnload); - } else if (w.addEventListener) - w.addEventListener('unload', unload, false); + return r; + }, - // Setup initial unload handler array - t.unloads = [f]; - } else - t.unloads.push(f); + explode : function(s, d) { + return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s; + }, - return f; - }, + _addVer : function(u) { + var v; - removeUnload : function(f) { - var u = this.unloads, r = null; + if (!this.query) + return u; - tinymce.each(u, function(o, i) { - if (o && o.func == f) { - u.splice(i, 1); - r = f; - return false; - } - }); + v = (u.indexOf('?') == -1 ? '?' : '&') + this.query; - return r; - }, + if (u.indexOf('#') == -1) + return u + v; - explode : function(s, d) { - return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s; - }, + return u.replace('#', v + '#'); + }, - _addVer : function(u) { - var v; + // Fix function for IE 9 where regexps isn't working correctly + // Todo: remove me once MS fixes the bug + _replace : function(find, replace, str) { + // On IE9 we have to fake $x replacement + if (isRegExpBroken) { + return str.replace(find, function() { + var val = replace, args = arguments, i; - if (!this.query) - return u; + for (i = 0; i < args.length - 2; i++) { + if (args[i] === undefined) { + val = val.replace(new RegExp('\\$' + i, 'g'), ''); + } else { + val = val.replace(new RegExp('\\$' + i, 'g'), args[i]); + } + } - v = (u.indexOf('?') == -1 ? '?' : '&') + this.query; + return val; + }); + } - if (u.indexOf('#') == -1) - return u + v; + return str.replace(find, replace); + } - return u.replace('#', v + '#'); - } + }; - }; + // Initialize the API + tinymce._init(); + + // Expose tinymce namespace to the global namespace (window) + win.tinymce = win.tinyMCE = tinymce; +})(window); -// Required for GZip AJAX loading -window.tinymce = tinymce; -// Initialize the API -tinymce._init(); tinymce.create('tinymce.util.Dispatcher', { scope : null, listeners : null, @@ -479,6 +515,7 @@ tinymce.create('tinymce.util.Dispatcher', { } }); + (function() { var each = tinymce.each; @@ -493,7 +530,7 @@ tinymce.create('tinymce.util.Dispatcher', { s = t.settings = s || {}; // Strange app protocol or local anchor - if (/^(mailto|tel|news|javascript|about):/i.test(u) || /^\s*#/.test(u)) { + if (/^(mailto|tel|news|javascript|about|data):/i.test(u) || /^\s*#/.test(u)) { t.source = u; return; } @@ -508,23 +545,13 @@ 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 - - // Added by Dan S./Zotero - u = u.replace("jar:file", "jarfile"); - u = u.replace("zotero@chnm.gmu.edu", "zotero.chnm.gmu.edu"); - 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]; - if (s) { - // Zope 3 workaround, they use @@something + // Zope 3 workaround, they use @@something + if (s) s = s.replace(/\(mce_at\)/g, '@@'); - - // Added by Dan S./Zotero - s = s.replace("jarfile", "jar:file"); - s = s.replace("zotero.chnm.gmu.edu", "zotero@chnm.gmu.edu"); - } t[v] = s; }); @@ -591,7 +618,7 @@ tinymce.create('tinymce.util.Dispatcher', { toAbsolute : function(u, nh) { var u = new tinymce.util.URI(u, {base_uri : this}); - return u.getURI(this.host == u.host ? nh : 0); + return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0); }, toRelPath : function(base, path) { @@ -637,7 +664,7 @@ tinymce.create('tinymce.util.Dispatcher', { }, toAbsPath : function(base, path) { - var i, nb = 0, o = [], tr; + var i, nb = 0, o = [], tr, outPath; // Split paths tr = /\/$/.test(path) ? '/' : ''; @@ -677,9 +704,19 @@ tinymce.create('tinymce.util.Dispatcher', { // If /a/b/c or / if (i <= 0) - return '/' + o.reverse().join('/') + tr; + outPath = o.reverse().join('/'); + else + outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/'); + + // Add front / if it's needed + if (outPath.indexOf('/') !== 0) + outPath = '/' + outPath; - return '/' + base.slice(0, i).join('/') + '/' + o.reverse().join('/') + tr; + // Add traling / if it's needed + if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) + outPath += tr; + + return outPath; }, getURI : function(nh) { @@ -717,9 +754,9 @@ tinymce.create('tinymce.util.Dispatcher', { return t.source; } - - }); + }); })(); + (function() { var each = tinymce.each; @@ -788,9 +825,9 @@ tinymce.create('tinymce.util.Dispatcher', { this.set(n, '', d, p, d); } - - }); + }); })(); + tinymce.create('static tinymce.util.JSON', { serialize : function(o) { var i, v, s = tinymce.util.JSON.serialize, t; @@ -836,13 +873,14 @@ tinymce.create('static tinymce.util.JSON', { parse : function(s) { try { - throw ('evalremoved2'); + return eval('(' + s + ')'); } catch (ex) { // Ignore } } }); + tinymce.create('static tinymce.util.XHR', { send : function(o) { var x, t, w = window, c = 0; @@ -876,12 +914,13 @@ tinymce.create('static tinymce.util.XHR', { if (o.content_type) x.setRequestHeader('Content-Type', o.content_type); + x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + x.send(o.data); function ready() { if (!o.async || x.readyState == 4 || c++ > 10000) { - // Modified by Dan S./Zotero - if (o.success && c < 10000 && (x.status == 200 || x.status == 0)) + if (o.success && c < 10000 && x.status == 200) o.success.call(o.success_scope, '' + x.responseText, x, o); else if (o.error) o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o); @@ -898,9 +937,9 @@ tinymce.create('static tinymce.util.XHR', { // Wait for response, onReadyStateChange can not be used since it leaks memory in IE t = w.setTimeout(ready, 10); } - - } + } }); + (function() { var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR; @@ -952,12 +991,32 @@ tinymce.create('static tinymce.util.XHR', { return new tinymce.util.JSONRequest().send(o); } } - - }); -}());(function(tinymce) { + }); +}()); +(function(tinymce) { // Shorten names - var each = tinymce.each, is = tinymce.is; - var isWebKit = tinymce.isWebKit, isIE = tinymce.isIE; + var each = tinymce.each, + is = tinymce.is, + isWebKit = tinymce.isWebKit, + isIE = tinymce.isIE, + blockRe = /^(H[1-6R]|P|DIV|ADDRESS|PRE|FORM|T(ABLE|BODY|HEAD|FOOT|H|R|D)|LI|OL|UL|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|MENU|ISINDEX|SAMP)$/, + boolAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'), + mceAttribs = makeMap('src,href,style,coords,shape'), + encodedChars = {'&' : '&', '"' : '"', '<' : '<', '>' : '>'}, + encodeCharsRe = /[<>&\"]/g, + simpleSelectorRe = /^([a-z0-9],?)+$/i, + tagRegExp = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)(\s*\/?)>/g, + attrRegExp = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g; + + function makeMap(str) { + var map = {}, i; + + str = str.split(','); + for (i = str.length; i >= 0; i--) + map[str[i]] = 1; + + return map; + }; tinymce.create('tinymce.dom.DOMUtils', { doc : null, @@ -980,15 +1039,15 @@ tinymce.create('static tinymce.util.XHR', { }, DOMUtils : function(d, s) { - var t = this; + var t = this, globalStyle; t.doc = d; t.win = window; t.files = {}; t.cssFlicker = false; t.counter = 0; - t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat"; - t.stdMode = d.documentMode === 8; + t.stdMode = d.documentMode >= 8; + t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode; t.settings = s = tinymce.extend({ keep_values : false, @@ -1005,6 +1064,16 @@ tinymce.create('static tinymce.util.XHR', { } } + // Build styles list + if (s.valid_styles) { + t._styles = {}; + + // Convert styles into a rule list + each(s.valid_styles, function(value, key) { + t._styles[key] = tinymce.explode(value); + }); + } + tinymce.addUnload(t.destroy, t); }, @@ -1124,6 +1193,14 @@ tinymce.create('static tinymce.util.XHR', { return e; }, + getNext : function(node, selector) { + return this._findSib(node, selector, 'nextSibling'); + }, + + getPrev : function(node, selector) { + return this._findSib(node, selector, 'previousSibling'); + }, + select : function(pa, s) { var t = this; @@ -1131,8 +1208,30 @@ tinymce.create('static tinymce.util.XHR', { return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []); }, - is : function(n, patt) { - return tinymce.dom.Sizzle.matches(patt, n.nodeType ? [n] : n).length > 0; + is : function(n, selector) { + var i; + + // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance + if (n.length === undefined) { + // Simple all selector + if (selector === '*') + return n.nodeType == 1; + + // Simple selector just elements + if (simpleSelectorRe.test(selector)) { + selector = selector.toLowerCase().split(/,/); + n = n.nodeName.toLowerCase(); + + for (i = selector.length - 1; i >= 0; i--) { + if (selector[i] == n) + return true; + } + + return false; + } + } + + return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0; }, @@ -1170,44 +1269,33 @@ tinymce.create('static tinymce.util.XHR', { o += ' ' + k + '="' + t.encode(a[k]) + '"'; } - if (tinymce.is(h)) + // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime + if (typeof(h) != "undefined") return o + '>' + h + '</' + n + '>'; return o + ' />'; }, - remove : function(n, k) { - var t = this; - - return this.run(n, function(n) { - var p, g, i; + remove : function(node, keep_children) { + return this.run(node, function(node) { + var parent, child; - p = n.parentNode; + parent = node.parentNode; - if (!p) + if (!parent) return null; - if (k) { - for (i = n.childNodes.length - 1; i >= 0; i--) - t.insertAfter(n.childNodes[i], n); - - //each(n.childNodes, function(c) { - // p.insertBefore(c.cloneNode(true), n); - //}); - } - - // Fix IE psuedo leak - if (t.fixPsuedoLeaks) { - p = n.cloneNode(true); - k = 'IELeakGarbageBin'; - g = t.get(k) || t.add(t.doc.body, 'div', {id : k, style : 'display:none'}); - g.appendChild(n); - g.innerHTML = ''; - - return p; + if (keep_children) { + while (child = node.firstChild) { + // IE 8 will crash if you don't remove completely empty text nodes + if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue) + parent.insertBefore(child, node); + else + node.removeChild(child); + } } - return p.removeChild(n); + return parent.removeChild(node); }); }, @@ -1252,7 +1340,7 @@ tinymce.create('static tinymce.util.XHR', { // Force update of the style data if (t.settings.update_styles) - t.setAttrib(e, 'mce_style'); + t.setAttrib(e, '_mce_style'); }); }, @@ -1335,9 +1423,9 @@ tinymce.create('static tinymce.util.XHR', { // 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('mce_style', v, 2); + e.setAttribute('_mce_style', v, 2); else - e.removeAttribute('mce_style', 2); + e.removeAttribute('_mce_style', 2); } e.style.cssText = v; @@ -1353,13 +1441,13 @@ tinymce.create('static tinymce.util.XHR', { if (s.url_converter) v = s.url_converter.call(s.url_converter_scope || t, v, n, e); - t.setAttrib(e, 'mce_' + n, v, 2); + t.setAttrib(e, '_mce_' + n, v, 2); } break; case "shape": - e.setAttribute('mce_style', v); + e.setAttribute('_mce_style', v); break; } @@ -1393,7 +1481,7 @@ tinymce.create('static tinymce.util.XHR', { // Try the mce variant for these if (/^(src|href|style|coords|shape)$/.test(n)) { - v = e.getAttribute("mce_" + n); + v = e.getAttribute("_mce_" + n); if (v) return v; @@ -1407,14 +1495,26 @@ tinymce.create('static tinymce.util.XHR', { if (!v) v = e.getAttribute(n, 2); + // Check boolean attribs + if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) { + if (e[t.props[n]] === true && v === '') + return n; + + return v ? n : ''; + } + + // Inner input elements will override attributes on form elements + if (e.nodeName === "FORM" && e.getAttributeNode(n)) + return e.getAttributeNode(n).nodeValue; + if (n === 'style') { v = v || e.style.cssText; if (v) { - v = t.serializeStyle(t.parseStyle(v)); + v = t.serializeStyle(t.parseStyle(v), e.nodeName); if (t.settings.keep_values && !t._isRes(v)) - e.setAttribute('mce_style', v); + e.setAttribute('_mce_style', v); } } @@ -1482,7 +1582,7 @@ tinymce.create('static tinymce.util.XHR', { default: // IE has odd anonymous function for event attributes if (n.indexOf('on') === 0 && v) - v = ('' + v).replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1'); + v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v); } } @@ -1502,7 +1602,6 @@ tinymce.create('static tinymce.util.XHR', { e = t.boxModel ? d.documentElement : d.body; x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x; - n.top += t.win.self != t.win.top ? 2 : 0; // IE adds some strange extra cord if used in a frameset return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x}; } @@ -1624,15 +1723,23 @@ tinymce.create('static tinymce.util.XHR', { return o; }, - serializeStyle : function(o) { - var s = ''; + serializeStyle : function(o, name) { + var t = this, s = ''; - each(o, function(v, k) { + function add(v, k) { if (k && v) { - if (tinymce.isGecko && k.indexOf('-moz-') === 0) + // Remove browser specific styles like -moz- or -webkit- + if (k.indexOf('-') === 0) return; switch (k) { + case 'font-weight': + // Opera will output bold as 700 + if (v == 700) + v = 'bold'; + + break; + case 'color': case 'background-color': v = v.toLowerCase(); @@ -1641,7 +1748,19 @@ tinymce.create('static tinymce.util.XHR', { s += (s ? ' ' : '') + k + ': ' + v + ';'; } - }); + }; + + // Validate style output + if (name && t._styles) { + each(t._styles['*'], function(name) { + add(o[name], name); + }); + + each(t._styles[name.toLowerCase()], function(name) { + add(o[name], name); + }); + } else + each(o, add); return s; }, @@ -1666,7 +1785,7 @@ tinymce.create('static tinymce.util.XHR', { // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading // It's ugly but it seems to work fine. - if (isIE && d.documentMode) { + if (isIE && d.documentMode && d.recalc) { link.onload = function() { d.recalc(); link.onload = null; @@ -1704,9 +1823,18 @@ tinymce.create('static tinymce.util.XHR', { re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g"); v = e.className.replace(re, ' '); + v = tinymce.trim(v != ' ' ? v : ''); - return e.className = tinymce.trim(v != ' ' ? v : ''); - } + e.className = v; + + // Empty class attr + if (!v) { + e.removeAttribute('class'); + e.removeAttribute('className'); + } + + return v; + } return e.className; }); @@ -1749,6 +1877,10 @@ tinymce.create('static tinymce.util.XHR', { if (isIE) { function set() { + // Remove all child nodes + while (e.firstChild) + e.firstChild.removeNode(); + try { // IE will remove comments from the beginning // unless you padd the contents with something @@ -1758,10 +1890,6 @@ tinymce.create('static tinymce.util.XHR', { // IE sometimes produces an unknown runtime error on innerHTML if it's an block element within a block element for example a div inside a p // This seems to fix this problem - // Remove all child nodes - while (e.firstChild) - e.firstChild.removeNode(); - // Create new div with HTML contents and a BR infront to keep comments x = t.create('div'); x.innerHTML = '<br />' + h; @@ -1779,7 +1907,7 @@ tinymce.create('static tinymce.util.XHR', { // DOM tree if contents like this <p><ul><li>Item 1</li></ul></p> is inserted // It seems to be that IE doesn't like a root block element placed inside another root block element if (t.settings.fix_ie_paragraphs) - h = h.replace(/<p><\/p>|<p([^>]+)><\/p>|<p[^\/+]\/>/gi, '<p$1 mce_keep="true"> </p>'); + h = h.replace(/<p><\/p>|<p([^>]+)><\/p>|<p[^\/+]\/>/gi, '<p$1 _mce_keep="true"> </p>'); set(); @@ -1790,12 +1918,12 @@ tinymce.create('static tinymce.util.XHR', { n = nl[i]; if (!n.hasChildNodes()) { - if (!n.mce_keep) { + if (!n._mce_keep) { x = 1; // Is broken break; } - n.removeAttribute('mce_keep'); + n.removeAttribute('_mce_keep'); } } } @@ -1804,13 +1932,13 @@ tinymce.create('static tinymce.util.XHR', { if (x) { // So if we replace the p elements with divs and mark them and then replace them back to paragraphs // after we use innerHTML we can fix the DOM tree - h = h.replace(/<p ([^>]+)>|<p>/g, '<div $1 mce_tmp="1">'); - h = h.replace(/<\/p>/g, '</div>'); + h = h.replace(/<p ([^>]+)>|<p>/ig, '<div $1 _mce_tmp="1">'); + h = h.replace(/<\/p>/gi, '</div>'); // Set the new HTML with DIVs set(); - // Replace all DIV elements with he mce_tmp attibute back to paragraphs + // Replace all DIV elements with the _mce_tmp attibute back to paragraphs // This is needed since IE has a annoying bug see above for details // This is a slow process but it has to be done. :( if (t.settings.fix_ie_paragraphs) { @@ -1819,7 +1947,7 @@ tinymce.create('static tinymce.util.XHR', { n = nl[i]; // Is it a temp div - if (n.mce_tmp) { + if (n._mce_tmp) { // Create new paragraph p = t.doc.createElement('p'); @@ -1827,7 +1955,7 @@ tinymce.create('static tinymce.util.XHR', { n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) { var v; - if (b !== 'mce_tmp') { + if (b !== '_mce_tmp') { v = n.getAttribute(b); if (!v && b === 'class') @@ -1855,27 +1983,23 @@ tinymce.create('static tinymce.util.XHR', { }, processHTML : function(h) { - var t = this, s = t.settings; + var t = this, s = t.settings, codeBlocks = []; if (!s.process_html) return h; - // Convert strong and em to b and i in FF since it can't handle them - if (tinymce.isGecko) { - h = h.replace(/<(\/?)strong>|<strong( [^>]+)>/gi, '<$1b$2>'); - h = h.replace(/<(\/?)em>|<em( [^>]+)>/gi, '<$1i$2>'); - } else if (isIE) { + if (isIE) { h = h.replace(/'/g, '''); // IE can't handle apos h = h.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/gi, ''); // IE doesn't handle default values correct } - // Fix some issues - h = h.replace(/<a( )([^>]+)\/>|<a\/>/gi, '<a$1$2></a>'); // Force open + // Force tags open, and on IE9 replace $1$2 that got left behind due to bugs in their RegExp engine + h = tinymce._replace(/<a( )([^>]+)\/>|<a\/>/gi, '<a$1$2></a>', h); // Force open - // Store away src and href in mce_src and mce_href since browsers mess them up + // Store away src and href in _mce_src and mce_href since browsers mess them up if (s.keep_values) { // Wrap scripts and styles in comments for serialization purposes - if (/<script|noscript|style/.test(h)) { + if (/<script|noscript|style/i.test(h)) { function trim(s) { // Remove prefix and suffix code for element s = s.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n'); @@ -1887,34 +2011,37 @@ tinymce.create('static tinymce.util.XHR', { }; // Wrap the script contents in CDATA and keep them from executing - h = h.replace(/<script([^>]+|)>([\s\S]*?)<\/script>/g, function(v, attribs, text) { + h = h.replace(/<script([^>]+|)>([\s\S]*?)<\/script>/gi, function(v, attribs, text) { // Force type attribute if (!attribs) attribs = ' type="text/javascript"'; - // Prefix script type/language attribute values with mce- to prevent it from executing - attribs = attribs.replace(/(type|language)=\"?/, '$&mce-'); - attribs = attribs.replace(/src=\"([^\"]+)\"?/, function(a, url) { + // Convert the src attribute of the scripts + attribs = attribs.replace(/src=\"([^\"]+)\"?/i, function(a, url) { if (s.url_converter) url = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(url), 'src', 'script')); - return 'mce_src="' + url + '"'; + return '_mce_src="' + url + '"'; }); // Wrap text contents - if (tinymce.trim(text)) - text = '<!--\n' + trim(text) + '\n// -->'; + if (tinymce.trim(text)) { + codeBlocks.push(trim(text)); + text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n// -->'; + } return '<mce:script' + attribs + '>' + text + '</mce:script>'; }); // Wrap style elements - h = h.replace(/<style([^>]+|)>([\s\S]*?)<\/style>/g, function(v, attribs, text) { + h = h.replace(/<style([^>]+|)>([\s\S]*?)<\/style>/gi, function(v, attribs, text) { // Wrap text contents - if (text) - text = '<!--\n' + trim(text) + '\n-->'; + if (text) { + codeBlocks.push(trim(text)); + text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n-->'; + } - return '<mce:style' + attribs + '>' + text + '</mce:style><style ' + attribs + ' mce_bogus="1">' + text + '</style>'; + return '<mce:style' + attribs + '>' + text + '</mce:style><style ' + attribs + ' _mce_bogus="1">' + text + '</style>'; }); // Wrap noscript elements @@ -1923,45 +2050,52 @@ tinymce.create('static tinymce.util.XHR', { }); } - h = h.replace(/<!\[CDATA\[([\s\S]+)\]\]>/g, '<!--[CDATA[$1]]-->'); + h = tinymce._replace(/<!\[CDATA\[([\s\S]+)\]\]>/g, '<!--[CDATA[$1]]-->', h); - // Process all tags with src, href or style - h = h.replace(/<([\w:]+) [^>]*(src|href|style|shape|coords)[^>]*>/gi, function(a, n) { - function handle(m, b, c) { - var u = c; + // This function processes the attributes in the HTML string to force boolean + // attributes to the attr="attr" format and convert style, src and href to _mce_ versions + function processTags(html) { + return html.replace(tagRegExp, function(match, elm_name, attrs, end) { + return '<' + elm_name + attrs.replace(attrRegExp, function(match, name, value, val2, val3) { + var mceValue; - // Tag already got a mce_ version - if (a.indexOf('mce_' + b) != -1) - return m; + name = name.toLowerCase(); + value = value || val2 || val3 || ""; - if (b == 'style') { - // No mce_style for elements with these since they might get resized by the user - if (t._isRes(c)) - return m; + // Treat boolean attributes + if (boolAttrs[name]) { + // false or 0 is treated as a missing attribute + if (value === 'false' || value === '0') + return; - if (s.hex_colors) { - u = u.replace(/rgb\([^\)]+\)/g, function(v) { - return t.toHex(v); - }); + return name + '="' + name + '"'; } - if (s.url_converter) { - u = u.replace(/url\([\'\"]?([^\)\'\"]+)\)/g, function(x, c) { - return 'url(' + t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(c), b, n)) + ')'; - }); + // Is attribute one that needs special treatment + if (mceAttribs[name] && attrs.indexOf('_mce_' + name) == -1) { + mceValue = t.decode(value); + + // Convert URLs to relative/absolute ones + if (s.url_converter && (name == "src" || name == "href")) + mceValue = s.url_converter.call(s.url_converter_scope || t, mceValue, name, elm_name); + + // Process styles lowercases them and compresses them + if (name == 'style') + mceValue = t.serializeStyle(t.parseStyle(mceValue), name); + + return name + '="' + value + '"' + ' _mce_' + name + '="' + t.encode(mceValue) + '"'; } - } else if (b != 'coords' && b != 'shape') { - if (s.url_converter) - u = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(c), b, n)); - } - return ' ' + b + '="' + c + '" mce_' + b + '="' + u + '"'; - }; + return match; + }) + end + '>'; + }); + }; - a = a.replace(/ (src|href|style|coords|shape)=[\"]([^\"]+)[\"]/gi, handle); // W3C - a = a.replace(/ (src|href|style|coords|shape)=[\']([^\']+)[\']/gi, handle); // W3C + h = processTags(h); - return a.replace(/ (src|href|style|coords|shape)=([^\s\"\'>]+)/gi, handle); // IE + // Restore script blocks + h = h.replace(/MCE_SCRIPT:([0-9]+)/g, function(val, idx) { + return codeBlocks[idx]; }); } @@ -1988,25 +2122,41 @@ tinymce.create('static tinymce.util.XHR', { setOuterHTML : function(e, h, d) { var t = this; - return this.run(e, function(e) { + function setHTML(e, h, d) { var n, tp; + tp = d.createElement("body"); + tp.innerHTML = h; + + n = tp.lastChild; + while (n) { + t.insertAfter(n.cloneNode(true), e); + n = n.previousSibling; + } + + t.remove(e); + }; + + return this.run(e, function(e) { e = t.get(e); - d = d || e.ownerDocument || t.doc; - - if (isIE && e.nodeType == 1) - e.outerHTML = h; - else { - tp = d.createElement("body"); - tp.innerHTML = h; - - n = tp.lastChild; - while (n) { - t.insertAfter(n.cloneNode(true), e); - n = n.previousSibling; - } - t.remove(e); + // Only set HTML on elements + if (e.nodeType == 1) { + d = d || e.ownerDocument || t.doc; + + if (isIE) { + try { + // Try outerHTML for IE it sometimes produces an unknown runtime error + if (isIE && e.nodeType == 1) + e.outerHTML = h; + else + setHTML(e, h, d); + } catch (ex) { + // Fix for unknown runtime error + setHTML(e, h, d); + } + } else + setHTML(e, h, d); } }); }, @@ -2015,7 +2165,7 @@ tinymce.create('static tinymce.util.XHR', { var e, n, v; // Look for entities to decode - if (/&[^;]+;/.test(s)) { + if (/&[\w#]+;/.test(s)) { // Decode the entities using a div element not super efficient but less code e = this.doc.createElement("div"); e.innerHTML = s; @@ -2025,7 +2175,7 @@ tinymce.create('static tinymce.util.XHR', { if (n) { do { v += n.nodeValue; - } while (n.nextSibling); + } while (n = n.nextSibling); } return v || s; @@ -2034,43 +2184,27 @@ tinymce.create('static tinymce.util.XHR', { return s; }, - encode : function(s) { - return s ? ('' + s).replace(/[<>&\"]/g, function (c, b) { - switch (c) { - case '&': - return '&'; - - case '"': - return '"'; - - case '<': - return '<'; - - case '>': - return '>'; - } - - return c; - }) : s; + encode : function(str) { + return ('' + str).replace(encodeCharsRe, function(chr) { + return encodedChars[chr]; + }); }, - insertAfter : function(n, r) { - var t = this; - - r = t.get(r); + insertAfter : function(node, reference_node) { + reference_node = this.get(reference_node); - return this.run(n, function(n) { - var p, ns; + return this.run(node, function(node) { + var parent, nextSibling; - p = r.parentNode; - ns = r.nextSibling; + parent = reference_node.parentNode; + nextSibling = reference_node.nextSibling; - if (ns) - p.insertBefore(n, ns); + if (nextSibling) + parent.insertBefore(node, nextSibling); else - p.appendChild(n); + parent.appendChild(node); - return n; + return node; }); }, @@ -2080,7 +2214,7 @@ tinymce.create('static tinymce.util.XHR', { n = n.nodeName || n; - return /^(H[1-6]|HR|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TR|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP)$/.test(n); + return blockRe.test(n); }, replace : function(n, o, k) { @@ -2091,23 +2225,34 @@ tinymce.create('static tinymce.util.XHR', { return t.run(o, function(o) { if (k) { - each(o.childNodes, function(c) { - n.appendChild(c.cloneNode(true)); + each(tinymce.grep(o.childNodes), function(c) { + n.appendChild(c); }); } - // Fix IE psuedo leak for elements since replacing elements if fairly common - // Will break parentNode for some unknown reason - if (t.fixPsuedoLeaks && o.nodeType === 1) { - o.parentNode.insertBefore(n, o); - t.remove(o); - return n; - } - return o.parentNode.replaceChild(n, o); }); }, + rename : function(elm, name) { + var t = this, newElm; + + if (elm.nodeName != name.toUpperCase()) { + // Rename block element + newElm = t.create(name); + + // Copy attribs to new block + each(t.getAttribs(elm), function(attr_node) { + t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName)); + }); + + // Replace block + t.replace(newElm, elm, 1); + } + + return newElm || elm; + }, + findCommonAncestor : function(a, b) { var ps = a, pe; @@ -2174,7 +2319,7 @@ tinymce.create('static tinymce.util.XHR', { // Remove everything but class name ov = v; - v = v.replace(/.*\.([a-z0-9_\-]+).*/i, '$1'); + v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v); // Filter classes if (f && !(v = f(v, ov))) @@ -2251,9 +2396,13 @@ tinymce.create('static tinymce.util.XHR', { if (n.nodeName == 'OBJECT') return n.attributes; + // IE doesn't keep the selected attribute if you clone option elements + if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected')) + o.push({specified : 1, nodeName : 'selected'}); + // It's crazy that this is faster in IE but it's because it returns all attributes all the time - n.cloneNode(false).outerHTML.replace(/([a-z0-9\:\-_]+)=/gi, function(a, b) { - o.push({specified : 1, nodeName : b}); + n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) { + o.push({specified : 1, nodeName : a}); }); return o; @@ -2281,64 +2430,96 @@ tinymce.create('static tinymce.util.XHR', { return d.createRange ? d.createRange() : new tinymce.dom.Range(this); }, + nodeIndex : function(node, normalized) { + var idx = 0, lastNodeType, lastNode, nodeType; + + if (node) { + for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) { + nodeType = node.nodeType; + + // Normalize text nodes + if (normalized && nodeType == 3) { + if (nodeType == lastNodeType || !node.nodeValue.length) + continue; + } + + idx++; + lastNodeType = nodeType; + } + } + + return idx; + }, + split : function(pe, e, re) { var t = this, r = t.createRng(), bef, aft, pa; - // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sence - // but we don't want that in our code since it serves no purpose + // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense + // but we don't want that in our code since it serves no purpose for the end user // For example if this is chopped: // <p>text 1<span><b>CHOP</b></span>text 2</p> // would produce: // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p> // this function will then trim of empty edges and produce: // <p>text 1</p><b>CHOP</b><p>text 2</p> - function trimEdge(n, na) { - n = n[na]; + function trim(node) { + var i, children = node.childNodes; - if (n && n[na] && n[na].nodeType == 1 && isEmpty(n[na])) - t.remove(n[na]); - }; + if (node.nodeType == 1 && node.getAttribute('_mce_type') == 'bookmark') + return; + + for (i = children.length - 1; i >= 0; i--) + trim(children[i]); + + if (node.nodeType != 9) { + // Keep non whitespace text nodes + if (node.nodeType == 3 && node.nodeValue.length > 0) { + // If parent element isn't a block or there isn't any useful contents for example "<p> </p>" + if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0) + return; + } + + if (node.nodeType == 1) { + // If the only child is a bookmark then move it up + children = node.childNodes; + if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('_mce_type') == 'bookmark') + node.parentNode.insertBefore(children[0], node); + + // Keep non empty elements or img, hr etc + if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName)) + return; + } - function isEmpty(n) { - n = t.getOuterHTML(n); - n = n.replace(/<(img|hr|table)/gi, '-'); // Keep these convert them to - chars - n = n.replace(/<[^>]+>/g, ''); // Remove all tags + t.remove(node); + } - return n.replace(/[ \t\r\n]+| | /g, '') == ''; + return node; }; if (pe && e) { // Get before chunk - r.setStartBefore(pe); - r.setEndBefore(e); + r.setStart(pe.parentNode, t.nodeIndex(pe)); + r.setEnd(e.parentNode, t.nodeIndex(e)); bef = r.extractContents(); // Get after chunk r = t.createRng(); - r.setStartAfter(e); - r.setEndAfter(pe); + r.setStart(e.parentNode, t.nodeIndex(e) + 1); + r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1); aft = r.extractContents(); - // Insert chunks and remove parent + // Insert before chunk pa = pe.parentNode; + pa.insertBefore(trim(bef), pe); - // Remove right side edge of the before contents - trimEdge(bef, 'lastChild'); - - if (!isEmpty(bef)) - pa.insertBefore(bef, pe); - + // Insert middle chunk if (re) pa.replaceChild(re, e); else pa.insertBefore(e, pe); - // Remove left site edge of the after contents - trimEdge(aft, 'firstChild'); - - if (!isEmpty(aft)) - pa.insertBefore(aft, pe); - + // Insert after chunk + pa.insertBefore(trim(aft), pe); t.remove(pe); return re || e; @@ -2364,6 +2545,27 @@ tinymce.create('static tinymce.util.XHR', { }, + _findSib : function(node, selector, name) { + var t = this, f = selector; + + if (node) { + // If expression make a function of it using is + if (is(f, 'string')) { + f = function(node) { + return t.is(node, selector); + }; + } + + // Loop all siblings + for (node = node[name]; node; node = node[name]) { + if (f(node)) + return node; + } + } + + return null; + }, + _isRes : function(c) { // Is live resizble element return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c); @@ -2398,237 +2600,239 @@ tinymce.create('static tinymce.util.XHR', { return s; } */ + }); - }); - - // Setup page DOM tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0}); })(tinymce); -(function(ns) { - // Traverse constants - var EXTRACT = 0, CLONE = 1, DELETE = 2, extend = tinymce.extend; - - function indexOf(child, parent) { - var i, node; - - if (child.parentNode != parent) - return -1; - - for (node = parent.firstChild, i = 0; node != child; node = node.nextSibling) - i++; - - return i; - }; - - function nodeIndex(n) { - var i = 0; - - while (n.previousSibling) { - i++; - n = n.previousSibling; - } - - return i; - }; - - function getSelectedNode(container, offset) { - var child; - - if (container.nodeType == 3 /* TEXT_NODE */) - return container; - - if (offset < 0) - return container; - - child = container.firstChild; - while (child != null && offset > 0) { - --offset; - child = child.nextSibling; - } - - if (child != null) - return child; - - return container; - }; +(function(ns) { // Range constructor function Range(dom) { - var d = dom.doc; - - extend(this, { - dom : dom, - + var t = this, + doc = dom.doc, + EXTRACT = 0, + CLONE = 1, + DELETE = 2, + TRUE = true, + FALSE = false, + START_OFFSET = 'startOffset', + START_CONTAINER = 'startContainer', + END_CONTAINER = 'endContainer', + END_OFFSET = 'endOffset', + extend = tinymce.extend, + nodeIndex = dom.nodeIndex; + + extend(t, { // Inital states - startContainer : d, + startContainer : doc, startOffset : 0, - endContainer : d, + endContainer : doc, endOffset : 0, - collapsed : true, - commonAncestorContainer : d, + collapsed : TRUE, + commonAncestorContainer : doc, // Range constants START_TO_START : 0, START_TO_END : 1, END_TO_END : 2, - END_TO_START : 3 + END_TO_START : 3, + + // Public methods + setStart : setStart, + setEnd : setEnd, + setStartBefore : setStartBefore, + setStartAfter : setStartAfter, + setEndBefore : setEndBefore, + setEndAfter : setEndAfter, + collapse : collapse, + selectNode : selectNode, + selectNodeContents : selectNodeContents, + compareBoundaryPoints : compareBoundaryPoints, + deleteContents : deleteContents, + extractContents : extractContents, + cloneContents : cloneContents, + insertNode : insertNode, + surroundContents : surroundContents, + cloneRange : cloneRange }); - }; - - // Add range methods - extend(Range.prototype, { - setStart : function(n, o) { - this._setEndPoint(true, n, o); - }, - setEnd : function(n, o) { - this._setEndPoint(false, n, o); - }, + function setStart(n, o) { + _setEndPoint(TRUE, n, o); + }; - setStartBefore : function(n) { - this.setStart(n.parentNode, nodeIndex(n)); - }, + function setEnd(n, o) { + _setEndPoint(FALSE, n, o); + }; - setStartAfter : function(n) { - this.setStart(n.parentNode, nodeIndex(n) + 1); - }, + function setStartBefore(n) { + setStart(n.parentNode, nodeIndex(n)); + }; - setEndBefore : function(n) { - this.setEnd(n.parentNode, nodeIndex(n)); - }, + function setStartAfter(n) { + setStart(n.parentNode, nodeIndex(n) + 1); + }; - setEndAfter : function(n) { - this.setEnd(n.parentNode, nodeIndex(n) + 1); - }, + function setEndBefore(n) { + setEnd(n.parentNode, nodeIndex(n)); + }; - collapse : function(ts) { - var t = this; + function setEndAfter(n) { + setEnd(n.parentNode, nodeIndex(n) + 1); + }; + function collapse(ts) { if (ts) { - t.endContainer = t.startContainer; - t.endOffset = t.startOffset; + t[END_CONTAINER] = t[START_CONTAINER]; + t[END_OFFSET] = t[START_OFFSET]; } else { - t.startContainer = t.endContainer; - t.startOffset = t.endOffset; + t[START_CONTAINER] = t[END_CONTAINER]; + t[START_OFFSET] = t[END_OFFSET]; } - t.collapsed = true; - }, + t.collapsed = TRUE; + }; - selectNode : function(n) { - this.setStartBefore(n); - this.setEndAfter(n); - }, + function selectNode(n) { + setStartBefore(n); + setEndAfter(n); + }; - selectNodeContents : function(n) { - this.setStart(n, 0); - this.setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length); - }, + function selectNodeContents(n) { + setStart(n, 0); + setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length); + }; - compareBoundaryPoints : function(h, r) { - var t = this, sc = t.startContainer, so = t.startOffset, ec = t.endContainer, eo = t.endOffset; + function compareBoundaryPoints(h, r) { + var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET]; // Check START_TO_START if (h === 0) - return t._compareBoundaryPoints(sc, so, sc, so); + return _compareBoundaryPoints(sc, so, sc, so); // Check START_TO_END if (h === 1) - return t._compareBoundaryPoints(sc, so, ec, eo); + return _compareBoundaryPoints(sc, so, ec, eo); // Check END_TO_END if (h === 2) - return t._compareBoundaryPoints(ec, eo, ec, eo); + return _compareBoundaryPoints(ec, eo, ec, eo); // Check END_TO_START if (h === 3) - return t._compareBoundaryPoints(ec, eo, sc, so); - }, + return _compareBoundaryPoints(ec, eo, sc, so); + }; - deleteContents : function() { - this._traverse(DELETE); - }, + function deleteContents() { + _traverse(DELETE); + }; - extractContents : function() { - return this._traverse(EXTRACT); - }, + function extractContents() { + return _traverse(EXTRACT); + }; - cloneContents : function() { - return this._traverse(CLONE); - }, + function cloneContents() { + return _traverse(CLONE); + }; - insertNode : function(n) { - var t = this, nn, o; + function insertNode(n) { + var startContainer = this[START_CONTAINER], + startOffset = this[START_OFFSET], nn, o; // Node is TEXT_NODE or CDATA - if (n.nodeType === 3 || n.nodeType === 4) { - nn = t.startContainer.splitText(t.startOffset); - t.startContainer.parentNode.insertBefore(n, nn); + if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) { + if (!startOffset) { + // At the start of text + startContainer.parentNode.insertBefore(n, startContainer); + } else if (startOffset >= startContainer.nodeValue.length) { + // At the end of text + dom.insertAfter(n, startContainer); + } else { + // Middle, need to split + nn = startContainer.splitText(startOffset); + startContainer.parentNode.insertBefore(n, nn); + } } else { // Insert element node - if (t.startContainer.childNodes.length > 0) - o = t.startContainer.childNodes[t.startOffset]; + if (startContainer.childNodes.length > 0) + o = startContainer.childNodes[startOffset]; - t.startContainer.insertBefore(n, o); + if (o) + startContainer.insertBefore(n, o); + else + startContainer.appendChild(n); } - }, + }; - surroundContents : function(n) { - var t = this, f = t.extractContents(); + function surroundContents(n) { + var f = t.extractContents(); t.insertNode(n); n.appendChild(f); t.selectNode(n); - }, - - cloneRange : function() { - var t = this; + }; - return extend(new Range(t.dom), { - startContainer : t.startContainer, - startOffset : t.startOffset, - endContainer : t.endContainer, - endOffset : t.endOffset, + function cloneRange() { + return extend(new Range(dom), { + startContainer : t[START_CONTAINER], + startOffset : t[START_OFFSET], + endContainer : t[END_CONTAINER], + endOffset : t[END_OFFSET], collapsed : t.collapsed, commonAncestorContainer : t.commonAncestorContainer }); - }, + }; -/* - detach : function() { - // Not implemented - }, -*/ - // Internal methods + // Private methods - _isCollapsed : function() { - return (this.startContainer == this.endContainer && this.startOffset == this.endOffset); - }, + function _getSelectedNode(container, offset) { + var child; + + if (container.nodeType == 3 /* TEXT_NODE */) + return container; + + if (offset < 0) + return container; + + child = container.firstChild; + while (child && offset > 0) { + --offset; + child = child.nextSibling; + } + + if (child) + return child; + + return container; + }; + + function _isCollapsed() { + return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]); + }; - _compareBoundaryPoints : function (containerA, offsetA, containerB, offsetB) { + function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) { var c, offsetC, n, cmnRoot, childA, childB; - // In the first case the boundary-points have the same container. A is before B - // if its offset is less than the offset of B, A is equal to B if its offset is - // equal to the offset of B, and A is after B if its offset is greater than the + // In the first case the boundary-points have the same container. A is before B + // if its offset is less than the offset of B, A is equal to B if its offset is + // equal to the offset of B, and A is after B if its offset is greater than the // offset of B. if (containerA == containerB) { - if (offsetA == offsetB) { + if (offsetA == offsetB) return 0; // equal - } else if (offsetA < offsetB) { + + if (offsetA < offsetB) return -1; // before - } else { - return 1; // after - } + + return 1; // after } - // In the second case a child node C of the container of A is an ancestor - // container of B. In this case, A is before B if the offset of A is less than or + // In the second case a child node C of the container of A is an ancestor + // container of B. In this case, A is before B if the offset of A is less than or // equal to the index of the child node C and A is after B otherwise. c = containerB; - while (c && c.parentNode != containerA) { + while (c && c.parentNode != containerA) c = c.parentNode; - } + if (c) { offsetC = 0; n = containerA.firstChild; @@ -2638,15 +2842,14 @@ tinymce.create('static tinymce.util.XHR', { n = n.nextSibling; } - if (offsetA <= offsetC) { + if (offsetA <= offsetC) return -1; // before - } else { - return 1; // after - } + + return 1; // after } - // In the third case a child node C of the container of B is an ancestor container - // of A. In this case, A is before B if the index of the child node C is less than + // In the third case a child node C of the container of B is an ancestor container + // of A. In this case, A is before B if the index of the child node C is less than // the offset of B and A is after B otherwise. c = containerA; while (c && c.parentNode != containerB) { @@ -2662,124 +2865,113 @@ tinymce.create('static tinymce.util.XHR', { n = n.nextSibling; } - if (offsetC < offsetB) { + if (offsetC < offsetB) return -1; // before - } else { - return 1; // after - } + + return 1; // after } - // In the fourth case, none of three other cases hold: the containers of A and B - // are siblings or descendants of sibling nodes. In this case, A is before B if + // In the fourth case, none of three other cases hold: the containers of A and B + // are siblings or descendants of sibling nodes. In this case, A is before B if // the container of A is before the container of B in a pre-order traversal of the // Ranges' context tree and A is after B otherwise. - cmnRoot = this.dom.findCommonAncestor(containerA, containerB); + cmnRoot = dom.findCommonAncestor(containerA, containerB); childA = containerA; - while (childA && childA.parentNode != cmnRoot) { - childA = childA.parentNode; - } + while (childA && childA.parentNode != cmnRoot) + childA = childA.parentNode; - if (!childA) { + if (!childA) childA = cmnRoot; - } childB = containerB; - while (childB && childB.parentNode != cmnRoot) { + while (childB && childB.parentNode != cmnRoot) childB = childB.parentNode; - } - if (!childB) { + if (!childB) childB = cmnRoot; - } - if (childA == childB) { + if (childA == childB) return 0; // equal - } n = cmnRoot.firstChild; while (n) { - if (n == childA) { + if (n == childA) return -1; // before - } - if (n == childB) { + if (n == childB) return 1; // after - } n = n.nextSibling; } - }, + }; - _setEndPoint : function(st, n, o) { - var t = this, ec, sc; + function _setEndPoint(st, n, o) { + var ec, sc; if (st) { - t.startContainer = n; - t.startOffset = o; + t[START_CONTAINER] = n; + t[START_OFFSET] = o; } else { - t.endContainer = n; - t.endOffset = o; + t[END_CONTAINER] = n; + t[END_OFFSET] = o; } - // If one boundary-point of a Range is set to have a root container - // other than the current one for the Range, the Range is collapsed to + // If one boundary-point of a Range is set to have a root container + // other than the current one for the Range, the Range is collapsed to // the new position. This enforces the restriction that both boundary- // points of a Range must have the same root container. - ec = t.endContainer; + ec = t[END_CONTAINER]; while (ec.parentNode) ec = ec.parentNode; - sc = t.startContainer; + sc = t[START_CONTAINER]; while (sc.parentNode) sc = sc.parentNode; - if (sc != ec) { - t.collapse(st); - } else { - // The start position of a Range is guaranteed to never be after the - // end position. To enforce this restriction, if the start is set to - // be at a position after the end, the Range is collapsed to that + if (sc == ec) { + // The start position of a Range is guaranteed to never be after the + // end position. To enforce this restriction, if the start is set to + // be at a position after the end, the Range is collapsed to that // position. - if (t._compareBoundaryPoints(t.startContainer, t.startOffset, t.endContainer, t.endOffset) > 0) + if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0) t.collapse(st); - } - - t.collapsed = t._isCollapsed(); - t.commonAncestorContainer = t.dom.findCommonAncestor(t.startContainer, t.endContainer); - }, + } else + t.collapse(st); - // This code is heavily "inspired" by the Apache Xerces implementation. I hope they don't mind. :) + t.collapsed = _isCollapsed(); + t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]); + }; - _traverse : function(how) { - var t = this, c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep; + function _traverse(how) { + var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep; - if (t.startContainer == t.endContainer) - return t._traverseSameContainer(how); + if (t[START_CONTAINER] == t[END_CONTAINER]) + return _traverseSameContainer(how); - for (c = t.endContainer, p = c.parentNode; p != null; c = p, p = p.parentNode) { - if (p == t.startContainer) - return t._traverseCommonStartContainer(c, how); + for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) { + if (p == t[START_CONTAINER]) + return _traverseCommonStartContainer(c, how); ++endContainerDepth; } - for (c = t.startContainer, p = c.parentNode; p != null; c = p, p = p.parentNode) { - if (p == t.endContainer) - return t._traverseCommonEndContainer(c, how); + for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) { + if (p == t[END_CONTAINER]) + return _traverseCommonEndContainer(c, how); ++startContainerDepth; } depthDiff = startContainerDepth - endContainerDepth; - startNode = t.startContainer; + startNode = t[START_CONTAINER]; while (depthDiff > 0) { startNode = startNode.parentNode; depthDiff--; } - endNode = t.endContainer; + endNode = t[END_CONTAINER]; while (depthDiff < 0) { endNode = endNode.parentNode; depthDiff++; @@ -2791,47 +2983,47 @@ tinymce.create('static tinymce.util.XHR', { endNode = ep; } - return t._traverseCommonAncestors(startNode, endNode, how); - }, + return _traverseCommonAncestors(startNode, endNode, how); + }; - _traverseSameContainer : function(how) { - var t = this, frag, s, sub, n, cnt, sibling, xferNode; + function _traverseSameContainer(how) { + var frag, s, sub, n, cnt, sibling, xferNode; if (how != DELETE) - frag = t.dom.doc.createDocumentFragment(); + frag = doc.createDocumentFragment(); // If selection is empty, just return the fragment - if (t.startOffset == t.endOffset) + if (t[START_OFFSET] == t[END_OFFSET]) return frag; // Text node needs special case handling - if (t.startContainer.nodeType == 3 /* TEXT_NODE */) { + if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) { // get the substring - s = t.startContainer.nodeValue; - sub = s.substring(t.startOffset, t.endOffset); + s = t[START_CONTAINER].nodeValue; + sub = s.substring(t[START_OFFSET], t[END_OFFSET]); // set the original text node to its new value if (how != CLONE) { - t.startContainer.deleteData(t.startOffset, t.endOffset - t.startOffset); + t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]); // Nothing is partially selected, so collapse to start point - t.collapse(true); + t.collapse(TRUE); } if (how == DELETE) - return null; + return; - frag.appendChild(t.dom.doc.createTextNode(sub)); + frag.appendChild(doc.createTextNode(sub)); return frag; } // Copy nodes between the start/end offsets. - n = getSelectedNode(t.startContainer, t.startOffset); - cnt = t.endOffset - t.startOffset; + n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]); + cnt = t[END_OFFSET] - t[START_OFFSET]; while (cnt > 0) { sibling = n.nextSibling; - xferNode = t._traverseFullySelected(n, how); + xferNode = _traverseFullySelected(n, how); if (frag) frag.appendChild( xferNode ); @@ -2842,31 +3034,31 @@ tinymce.create('static tinymce.util.XHR', { // Nothing is partially selected, so collapse to start point if (how != CLONE) - t.collapse(true); + t.collapse(TRUE); return frag; - }, + }; - _traverseCommonStartContainer : function(endAncestor, how) { - var t = this, frag, n, endIdx, cnt, sibling, xferNode; + function _traverseCommonStartContainer(endAncestor, how) { + var frag, n, endIdx, cnt, sibling, xferNode; if (how != DELETE) - frag = t.dom.doc.createDocumentFragment(); + frag = doc.createDocumentFragment(); - n = t._traverseRightBoundary(endAncestor, how); + n = _traverseRightBoundary(endAncestor, how); if (frag) frag.appendChild(n); - endIdx = indexOf(endAncestor, t.startContainer); - cnt = endIdx - t.startOffset; + endIdx = nodeIndex(endAncestor); + cnt = endIdx - t[START_OFFSET]; if (cnt <= 0) { - // Collapse to just before the endAncestor, which + // Collapse to just before the endAncestor, which // is partially selected. if (how != CLONE) { t.setEndBefore(endAncestor); - t.collapse(false); + t.collapse(FALSE); } return frag; @@ -2875,7 +3067,7 @@ tinymce.create('static tinymce.util.XHR', { n = endAncestor.previousSibling; while (cnt > 0) { sibling = n.previousSibling; - xferNode = t._traverseFullySelected(n, how); + xferNode = _traverseFullySelected(n, how); if (frag) frag.insertBefore(xferNode, frag.firstChild); @@ -2884,34 +3076,34 @@ tinymce.create('static tinymce.util.XHR', { n = sibling; } - // Collapse to just before the endAncestor, which + // Collapse to just before the endAncestor, which // is partially selected. if (how != CLONE) { t.setEndBefore(endAncestor); - t.collapse(false); + t.collapse(FALSE); } return frag; - }, + }; - _traverseCommonEndContainer : function(startAncestor, how) { - var t = this, frag, startIdx, n, cnt, sibling, xferNode; + function _traverseCommonEndContainer(startAncestor, how) { + var frag, startIdx, n, cnt, sibling, xferNode; if (how != DELETE) - frag = t.dom.doc.createDocumentFragment(); + frag = doc.createDocumentFragment(); - n = t._traverseLeftBoundary(startAncestor, how); + n = _traverseLeftBoundary(startAncestor, how); if (frag) frag.appendChild(n); - startIdx = indexOf(startAncestor, t.endContainer); + startIdx = nodeIndex(startAncestor); ++startIdx; // Because we already traversed it.... - cnt = t.endOffset - startIdx; + cnt = t[END_OFFSET] - startIdx; n = startAncestor.nextSibling; while (cnt > 0) { sibling = n.nextSibling; - xferNode = t._traverseFullySelected(n, how); + xferNode = _traverseFullySelected(n, how); if (frag) frag.appendChild(xferNode); @@ -2922,25 +3114,25 @@ tinymce.create('static tinymce.util.XHR', { if (how != CLONE) { t.setStartAfter(startAncestor); - t.collapse(true); + t.collapse(TRUE); } return frag; - }, + }; - _traverseCommonAncestors : function(startAncestor, endAncestor, how) { - var t = this, n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling; + function _traverseCommonAncestors(startAncestor, endAncestor, how) { + var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling; if (how != DELETE) - frag = t.dom.doc.createDocumentFragment(); + frag = doc.createDocumentFragment(); - n = t._traverseLeftBoundary(startAncestor, how); + n = _traverseLeftBoundary(startAncestor, how); if (frag) frag.appendChild(n); commonParent = startAncestor.parentNode; - startOffset = indexOf(startAncestor, commonParent); - endOffset = indexOf(endAncestor, commonParent); + startOffset = nodeIndex(startAncestor); + endOffset = nodeIndex(endAncestor); ++startOffset; cnt = endOffset - startOffset; @@ -2948,7 +3140,7 @@ tinymce.create('static tinymce.util.XHR', { while (cnt > 0) { nextSibling = sibling.nextSibling; - n = t._traverseFullySelected(sibling, how); + n = _traverseFullySelected(sibling, how); if (frag) frag.appendChild(n); @@ -2957,38 +3149,37 @@ tinymce.create('static tinymce.util.XHR', { --cnt; } - n = t._traverseRightBoundary(endAncestor, how); + n = _traverseRightBoundary(endAncestor, how); if (frag) frag.appendChild(n); if (how != CLONE) { t.setStartAfter(startAncestor); - t.collapse(true); + t.collapse(TRUE); } return frag; - }, + }; - _traverseRightBoundary : function(root, how) { - var t = this, next = getSelectedNode(t.endContainer, t.endOffset - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent; - var isFullySelected = next != t.endContainer; + function _traverseRightBoundary(root, how) { + var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER]; if (next == root) - return t._traverseNode(next, isFullySelected, false, how); + return _traverseNode(next, isFullySelected, FALSE, how); parent = next.parentNode; - clonedParent = t._traverseNode(parent, false, false, how); + clonedParent = _traverseNode(parent, FALSE, FALSE, how); - while (parent != null) { - while (next != null) { + while (parent) { + while (next) { prevSibling = next.previousSibling; - clonedChild = t._traverseNode(next, isFullySelected, false, how); + clonedChild = _traverseNode(next, isFullySelected, FALSE, how); if (how != DELETE) clonedParent.insertBefore(clonedChild, clonedParent.firstChild); - isFullySelected = true; + isFullySelected = TRUE; next = prevSibling; } @@ -2998,37 +3189,33 @@ tinymce.create('static tinymce.util.XHR', { next = parent.previousSibling; parent = parent.parentNode; - clonedGrandParent = t._traverseNode(parent, false, false, how); + clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how); if (how != DELETE) clonedGrandParent.appendChild(clonedParent); clonedParent = clonedGrandParent; } + }; - // should never occur - return null; - }, - - _traverseLeftBoundary : function(root, how) { - var t = this, next = getSelectedNode(t.startContainer, t.startOffset); - var isFullySelected = next != t.startContainer, parent, clonedParent, nextSibling, clonedChild, clonedGrandParent; + function _traverseLeftBoundary(root, how) { + var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent; if (next == root) - return t._traverseNode(next, isFullySelected, true, how); + return _traverseNode(next, isFullySelected, TRUE, how); parent = next.parentNode; - clonedParent = t._traverseNode(parent, false, true, how); + clonedParent = _traverseNode(parent, FALSE, TRUE, how); - while (parent != null) { - while (next != null) { + while (parent) { + while (next) { nextSibling = next.nextSibling; - clonedChild = t._traverseNode(next, isFullySelected, true, how); + clonedChild = _traverseNode(next, isFullySelected, TRUE, how); if (how != DELETE) clonedParent.appendChild(clonedChild); - isFullySelected = true; + isFullySelected = TRUE; next = nextSibling; } @@ -3038,33 +3225,30 @@ tinymce.create('static tinymce.util.XHR', { next = parent.nextSibling; parent = parent.parentNode; - clonedGrandParent = t._traverseNode(parent, false, true, how); + clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how); if (how != DELETE) clonedGrandParent.appendChild(clonedParent); clonedParent = clonedGrandParent; } + }; - // should never occur - return null; - }, - - _traverseNode : function(n, isFullySelected, isLeft, how) { - var t = this, txtValue, newNodeValue, oldNodeValue, offset, newNode; + function _traverseNode(n, isFullySelected, isLeft, how) { + var txtValue, newNodeValue, oldNodeValue, offset, newNode; if (isFullySelected) - return t._traverseFullySelected(n, how); + return _traverseFullySelected(n, how); if (n.nodeType == 3 /* TEXT_NODE */) { txtValue = n.nodeValue; if (isLeft) { - offset = t.startOffset; + offset = t[START_OFFSET]; newNodeValue = txtValue.substring(offset); oldNodeValue = txtValue.substring(0, offset); } else { - offset = t.endOffset; + offset = t[END_OFFSET]; newNodeValue = txtValue.substring(0, offset); oldNodeValue = txtValue.substring(offset); } @@ -3073,286 +3257,245 @@ tinymce.create('static tinymce.util.XHR', { n.nodeValue = oldNodeValue; if (how == DELETE) - return null; + return; - newNode = n.cloneNode(false); + newNode = n.cloneNode(FALSE); newNode.nodeValue = newNodeValue; return newNode; } if (how == DELETE) - return null; - - return n.cloneNode(false); - }, + return; - _traverseFullySelected : function(n, how) { - var t = this; + return n.cloneNode(FALSE); + }; + function _traverseFullySelected(n, how) { if (how != DELETE) - return how == CLONE ? n.cloneNode(true) : n; + return how == CLONE ? n.cloneNode(TRUE) : n; n.parentNode.removeChild(n); - return null; - } - }); + }; + }; ns.Range = Range; })(tinymce.dom); + (function() { function Selection(selection) { - var t = this, invisibleChar = '\uFEFF', range, lastIERng; - - function compareRanges(rng1, rng2) { - if (rng1 && rng2) { - // Both are control ranges and the selected element matches - if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0)) - return 1; - - // Both are text ranges and the range matches - if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1)) - return 1; - } - - return 0; - }; + var t = this, invisibleChar = '\uFEFF', range, lastIERng, dom = selection.dom, TRUE = true, FALSE = false; + // Returns a W3C DOM compatible range object by using the IE Range API function getRange() { - var dom = selection.dom, ieRange = selection.getRng(), domRange = dom.createRng(), startPos, endPos, element, sc, ec, collapsed; + var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed; - function findIndex(element) { - var nl = element.parentNode.childNodes, i; - - for (i = nl.length - 1; i >= 0; i--) { - if (nl[i] == element) - return i; - } - - return -1; - }; - - function findEndPoint(start) { - var rng = ieRange.duplicate(), parent, i, nl, n, offset = 0, index = 0, pos, tmpRng; - - // Insert marker character - rng.collapse(start); - parent = rng.parentElement(); - rng.pasteHTML(invisibleChar); // Needs to be a pasteHTML instead of .text = since IE has a bug with nodeValue - - // Find marker character - nl = parent.childNodes; - for (i = 0; i < nl.length; i++) { - n = nl[i]; - - // Calculate node index excluding text node fragmentation - if (i > 0 && (n.nodeType !== 3 || nl[i - 1].nodeType !== 3)) - index++; - - // If text node then calculate offset - if (n.nodeType === 3) { - // Look for marker - pos = n.nodeValue.indexOf(invisibleChar); - if (pos !== -1) { - offset += pos; - break; - } - - offset += n.nodeValue.length; - } else - offset = 0; - } - - // Remove marker character - rng.moveStart('character', -1); - rng.text = ''; - - return {index : index, offset : offset, parent : parent}; - }; - - // If selection is outside the current document just return an empty range - element = ieRange.item ? ieRange.item(0) : ieRange.parentElement(); - if (element.ownerDocument != dom.doc) - return domRange; + // If selection is outside the current document just return an empty range + element = ieRange.item ? ieRange.item(0) : ieRange.parentElement(); + if (element.ownerDocument != dom.doc) + return domRange; // Handle control selection or text selection of a image if (ieRange.item || !element.hasChildNodes()) { - domRange.setStart(element.parentNode, findIndex(element)); + domRange.setStart(element.parentNode, dom.nodeIndex(element)); domRange.setEnd(domRange.startContainer, domRange.startOffset + 1); return domRange; } - // Check collapsed state collapsed = selection.isCollapsed(); - // Find start and end pos index and offset - startPos = findEndPoint(true); - endPos = findEndPoint(false); - - // Normalize the elements to avoid fragmented dom - startPos.parent.normalize(); - endPos.parent.normalize(); - - // Set start container and offset - sc = startPos.parent.childNodes[Math.min(startPos.index, startPos.parent.childNodes.length - 1)]; - - if (sc.nodeType != 3) - domRange.setStart(startPos.parent, startPos.index); - else - domRange.setStart(startPos.parent.childNodes[startPos.index], startPos.offset); - - // Set end container and offset - ec = endPos.parent.childNodes[Math.min(endPos.index, endPos.parent.childNodes.length - 1)]; - - if (ec.nodeType != 3) { - if (!collapsed) - endPos.index++; + function findEndPoint(start) { + var marker, container, offset, nodes, startIndex = 0, endIndex, index, parent, checkRng, position; - domRange.setEnd(endPos.parent, endPos.index); - } else - domRange.setEnd(endPos.parent.childNodes[endPos.index], endPos.offset); + // Setup temp range and collapse it + checkRng = ieRange.duplicate(); + checkRng.collapse(start); - // If not collapsed then make sure offsets are valid - if (!collapsed) { - sc = domRange.startContainer; - if (sc.nodeType == 1) - domRange.setStart(sc, Math.min(domRange.startOffset, sc.childNodes.length)); + // Create marker and insert it at the end of the endpoints parent + marker = dom.create('a'); + parent = checkRng.parentElement(); - ec = domRange.endContainer; - if (ec.nodeType == 1) - domRange.setEnd(ec, Math.min(domRange.endOffset, ec.childNodes.length)); - } + // If parent doesn't have any children then set the container to that parent and the index to 0 + if (!parent.hasChildNodes()) { + domRange[start ? 'setStart' : 'setEnd'](parent, 0); + return; + } - // Restore selection to new range - t.addRange(domRange); + parent.appendChild(marker); + checkRng.moveToElementText(marker); + position = ieRange.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', checkRng); + if (position > 0) { + // The position is after the end of the parent element. + // This is the case where IE puts the caret to the left edge of a table. + domRange[start ? 'setStartAfter' : 'setEndAfter'](parent); + dom.remove(marker); + return; + } - return domRange; - }; + // Setup node list and endIndex + nodes = tinymce.grep(parent.childNodes); + endIndex = nodes.length - 1; + // Perform a binary search for the position + while (startIndex <= endIndex) { + index = Math.floor((startIndex + endIndex) / 2); + + // Insert marker and check it's position relative to the selection + parent.insertBefore(marker, nodes[index]); + checkRng.moveToElementText(marker); + position = ieRange.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', checkRng); + if (position > 0) { + // Marker is to the right + startIndex = index + 1; + } else if (position < 0) { + // Marker is to the left + endIndex = index - 1; + } else { + // Maker is where we are + found = true; + break; + } + } - this.addRange = function(rng) { - var ieRng, body = selection.dom.doc.body, startPos, endPos, sc, so, ec, eo; + // Setup container + container = position > 0 || index == 0 ? marker.nextSibling : marker.previousSibling; - // Setup some shorter versions - sc = rng.startContainer; - so = rng.startOffset; - ec = rng.endContainer; - eo = rng.endOffset; - ieRng = body.createTextRange(); + // Handle element selection + if (container.nodeType == 1) { + dom.remove(marker); - // Find element - sc = sc.nodeType == 1 ? sc.childNodes[Math.min(so, sc.childNodes.length - 1)] : sc; - ec = ec.nodeType == 1 ? ec.childNodes[Math.min(so == eo ? eo : eo - 1, ec.childNodes.length - 1)] : ec; + // Find offset and container + offset = dom.nodeIndex(container); + container = container.parentNode; - // Single element selection - if (sc == ec && sc.nodeType == 1) { - // Make control selection for some elements - if (/^(IMG|TABLE)$/.test(sc.nodeName) && so != eo) { - ieRng = body.createControlRange(); - ieRng.addElement(sc); + // Move the offset if we are setting the end or the position is after an element + if (!start || index > 0) + offset++; } else { - ieRng = body.createTextRange(); - - // Padd empty elements with invisible character - if (!sc.hasChildNodes() && sc.canHaveHTML) - sc.innerHTML = invisibleChar; - - // Select element contents - ieRng.moveToElementText(sc); - - // If it's only containing a padding remove it so the caret remains - if (sc.innerHTML == invisibleChar) { - ieRng.collapse(true); - sc.removeChild(sc.firstChild); + // Calculate offset within text node + if (position > 0 || index == 0) { + checkRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', ieRange); + offset = checkRng.text.length; + } else { + checkRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', ieRange); + offset = container.nodeValue.length - checkRng.text.length; } - } - - if (so == eo) - ieRng.collapse(eo <= rng.endContainer.childNodes.length - 1); - ieRng.select(); + dom.remove(marker); + } - return; - } + domRange[start ? 'setStart' : 'setEnd'](container, offset); + }; - function getCharPos(container, offset) { - var nodeVal, rng, pos; + // Find start point + findEndPoint(true); - if (container.nodeType != 3) - return -1; + // Find end point if needed + if (!collapsed) + findEndPoint(); - nodeVal = container.nodeValue; - rng = body.createTextRange(); + return domRange; + }; - // Insert marker at offset position - container.nodeValue = nodeVal.substring(0, offset) + invisibleChar + nodeVal.substring(offset); + this.addRange = function(rng) { + var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body; - // Find char pos of marker and remove it - rng.moveToElementText(container.parentNode); - rng.findText(invisibleChar); - pos = Math.abs(rng.moveStart('character', -0xFFFFF)); - container.nodeValue = nodeVal; + function setEndPoint(start) { + var container, offset, marker, tmpRng, nodes; - return pos; - }; + marker = dom.create('a'); + container = start ? startContainer : endContainer; + offset = start ? startOffset : endOffset; + tmpRng = ieRng.duplicate(); - // Collapsed range - if (rng.collapsed) { - pos = getCharPos(sc, so); + if (container == doc) { + container = body; + offset = 0; + } - ieRng = body.createTextRange(); - ieRng.move('character', pos); - ieRng.select(); + if (container.nodeType == 3) { + container.parentNode.insertBefore(marker, container); + tmpRng.moveToElementText(marker); + tmpRng.moveStart('character', offset); + dom.remove(marker); + ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng); + } else { + nodes = container.childNodes; - return; - } else { - // If same text container - if (sc == ec && sc.nodeType == 3) { - startPos = getCharPos(sc, so); + if (nodes.length) { + if (offset >= nodes.length) { + dom.insertAfter(marker, nodes[nodes.length - 1]); + } else { + container.insertBefore(marker, nodes[offset]); + } - ieRng.move('character', startPos); - ieRng.moveEnd('character', eo - so); - ieRng.select(); + tmpRng.moveToElementText(marker); + } else { + // Empty node selection for example <div>|</div> + marker = doc.createTextNode(invisibleChar); + container.appendChild(marker); + tmpRng.moveToElementText(marker.parentNode); + tmpRng.collapse(TRUE); + } - return; + ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng); + dom.remove(marker); } + } - // Get caret positions - startPos = getCharPos(sc, so); - endPos = getCharPos(ec, eo); - ieRng = body.createTextRange(); - - // Move start of range to start character position or start element - if (startPos == -1) { - ieRng.moveToElementText(sc); - startPos = 0; - } else - ieRng.move('character', startPos); + // Destroy cached range + this.destroy(); - // Move end of range to end character position or end element - tmpRng = body.createTextRange(); + // Setup some shorter versions + startContainer = rng.startContainer; + startOffset = rng.startOffset; + endContainer = rng.endContainer; + endOffset = rng.endOffset; + ieRng = body.createTextRange(); - if (endPos == -1) - tmpRng.moveToElementText(ec); - else - tmpRng.move('character', endPos); + // If single element selection then try making a control selection out of it + if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) { + if (startOffset == endOffset - 1) { + try { + ctrlRng = body.createControlRange(); + ctrlRng.addElement(startContainer.childNodes[startOffset]); + ctrlRng.select(); + ctrlRng.scrollIntoView(); + return; + } catch (ex) { + // Ignore + } + } + } - ieRng.setEndPoint('EndToEnd', tmpRng); - ieRng.select(); + // Set start/end point of selection + setEndPoint(true); + setEndPoint(); - return; - } + // Select the new range and scroll it into view + ieRng.select(); + ieRng.scrollIntoView(); }; this.getRangeAt = function() { // Setup new range if the cache is empty - if (!range || !compareRanges(lastIERng, selection.getRng())) { + if (!range || !tinymce.dom.RangeUtils.compareRanges(lastIERng, selection.getRng())) { range = getRange(); // Store away text range for next call lastIERng = selection.getRng(); } + // IE will say that the range is equal then produce an invalid argument exception + // if you perform specific operations in a keyup event. For example Ctrl+Del. + // This hack will invalidate the range cache if the exception occurs + try { + range.startContainer.nextSibling; + } catch (ex) { + range = getRange(); + lastIERng = null; + } + // Return cached range return range; }; @@ -3367,6 +3510,7 @@ tinymce.create('static tinymce.util.XHR', { tinymce.dom.TridentSelection = Selection; })(); + /* * Sizzle CSS Selector Engine - v1.0 * Copyright 2009, The Dojo Foundation @@ -3375,14 +3519,26 @@ tinymce.create('static tinymce.util.XHR', { */ (function(){ -var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g, +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, done = 0, toString = Object.prototype.toString, - hasDuplicate = false; + hasDuplicate = false, + baseHasDuplicate = true; + +// Here we check if the JavaScript engine is using some sort of +// optimization where it does not always call our comparision +// function. If that is the case, discard the hasDuplicate value. +// Thus far that includes Google Chrome. +[0, 0].sort(function(){ + baseHasDuplicate = false; + return 0; +}); var Sizzle = function(selector, context, results, seed) { results = results || []; - var origContext = context = context || document; + context = context || document; + + var origContext = context; if ( context.nodeType !== 1 && context.nodeType !== 9 ) { return []; @@ -3392,19 +3548,25 @@ var Sizzle = function(selector, context, results, seed) { return results; } - var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context); + var parts = [], m, set, checkSet, extra, prune = true, contextXML = Sizzle.isXML(context), + soFar = selector, ret, cur, pop, i; // Reset the position of the chunker regexp (start from head) - chunker.lastIndex = 0; - - while ( (m = chunker.exec(selector)) !== null ) { - parts.push( m[1] ); + do { + chunker.exec(""); + m = chunker.exec(soFar); + + if ( m ) { + soFar = m[3]; - if ( m[2] ) { - extra = RegExp.rightContext; - break; + parts.push( m[1] ); + + if ( m[2] ) { + extra = m[3]; + break; + } } - } + } while ( m ); if ( parts.length > 1 && origPOS.exec( selector ) ) { if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { @@ -3417,9 +3579,10 @@ var Sizzle = function(selector, context, results, seed) { while ( parts.length ) { selector = parts.shift(); - if ( Expr.relative[ selector ] ) + if ( Expr.relative[ selector ] ) { selector += parts.shift(); - + } + set = posProcess( selector, set ); } } @@ -3428,12 +3591,12 @@ var Sizzle = function(selector, context, results, seed) { // (but not if it'll be faster if the inner selector is an ID) if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { - var ret = Sizzle.find( parts.shift(), context, contextXML ); + ret = Sizzle.find( parts.shift(), context, contextXML ); context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; } if ( context ) { - var ret = seed ? + ret = seed ? { expr: parts.pop(), set: makeArray(seed) } : Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set; @@ -3445,7 +3608,8 @@ var Sizzle = function(selector, context, results, seed) { } while ( parts.length ) { - var cur = parts.pop(), pop = cur; + cur = parts.pop(); + pop = cur; if ( !Expr.relative[ cur ] ) { cur = ""; @@ -3469,20 +3633,20 @@ var Sizzle = function(selector, context, results, seed) { } if ( !checkSet ) { - throw "Syntax error, unrecognized expression: " + (cur || selector); + Sizzle.error( cur || selector ); } if ( toString.call(checkSet) === "[object Array]" ) { if ( !prune ) { results.push.apply( results, checkSet ); } else if ( context && context.nodeType === 1 ) { - for ( var i = 0; checkSet[i] != null; i++ ) { - if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { + for ( i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) { results.push( set[i] ); } } } else { - for ( var i = 0; checkSet[i] != null; i++ ) { + for ( i = 0; checkSet[i] != null; i++ ) { if ( checkSet[i] && checkSet[i].nodeType === 1 ) { results.push( set[i] ); } @@ -3502,7 +3666,7 @@ var Sizzle = function(selector, context, results, seed) { Sizzle.uniqueSort = function(results){ if ( sortOrder ) { - hasDuplicate = false; + hasDuplicate = baseHasDuplicate; results.sort(sortOrder); if ( hasDuplicate ) { @@ -3513,6 +3677,8 @@ Sizzle.uniqueSort = function(results){ } } } + + return results; }; Sizzle.matches = function(expr, set){ @@ -3520,7 +3686,7 @@ Sizzle.matches = function(expr, set){ }; Sizzle.find = function(expr, context, isXML){ - var set, match; + var set; if ( !expr ) { return []; @@ -3529,8 +3695,9 @@ Sizzle.find = function(expr, context, isXML){ for ( var i = 0, l = Expr.order.length; i < l; i++ ) { var type = Expr.order[i], match; - if ( (match = Expr.match[ type ].exec( expr )) ) { - var left = RegExp.leftContext; + if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { + var left = match[1]; + match.splice(1,1); if ( left.substr( left.length - 1 ) !== "\\" ) { match[1] = (match[1] || "").replace(/\\/g, ""); @@ -3552,15 +3719,21 @@ Sizzle.find = function(expr, context, isXML){ Sizzle.filter = function(expr, set, inplace, not){ var old = expr, result = [], curLoop = set, match, anyFound, - isXMLFilter = set && set[0] && isXML(set[0]); + isXMLFilter = set && set[0] && Sizzle.isXML(set[0]); while ( expr && set.length ) { for ( var type in Expr.filter ) { - if ( (match = Expr.match[ type ].exec( expr )) != null ) { - var filter = Expr.filter[ type ], found, item; + if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { + var filter = Expr.filter[ type ], found, item, left = match[1]; anyFound = false; - if ( curLoop == result ) { + match.splice(1,1); + + if ( left.substr( left.length - 1 ) === "\\" ) { + continue; + } + + if ( curLoop === result ) { result = []; } @@ -3611,9 +3784,9 @@ Sizzle.filter = function(expr, set, inplace, not){ } // Improper expression - if ( expr == old ) { + if ( expr === old ) { if ( anyFound == null ) { - throw "Syntax error, unrecognized expression: " + expr; + Sizzle.error( expr ); } else { break; } @@ -3625,18 +3798,23 @@ Sizzle.filter = function(expr, set, inplace, not){ return curLoop; }; +Sizzle.error = function( msg ) { + throw "Syntax error, unrecognized expression: " + msg; +}; + var Expr = Sizzle.selectors = { order: [ "ID", "NAME", "TAG" ], match: { - ID: /#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/, - CLASS: /\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/, - NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/, - ATTR: /\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, - TAG: /^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/, - CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, - POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/, - PSEUDO: /:((?:[\w\u00c0-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/ + ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, + CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, + TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, + CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/, + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, + PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ }, + leftMatch: {}, attrMap: { "class": "className", "for": "htmlFor" @@ -3647,20 +3825,20 @@ var Expr = Sizzle.selectors = { } }, relative: { - "+": function(checkSet, part, isXML){ + "+": function(checkSet, part){ var isPartStr = typeof part === "string", isTag = isPartStr && !/\W/.test(part), isPartStrNotTag = isPartStr && !isTag; - if ( isTag && !isXML ) { - part = part.toUpperCase(); + if ( isTag ) { + part = part.toLowerCase(); } for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { if ( (elem = checkSet[i]) ) { while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} - checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ? + checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? elem || false : elem === part; } @@ -3670,22 +3848,23 @@ var Expr = Sizzle.selectors = { Sizzle.filter( part, checkSet, true ); } }, - ">": function(checkSet, part, isXML){ - var isPartStr = typeof part === "string"; + ">": function(checkSet, part){ + var isPartStr = typeof part === "string", + elem, i = 0, l = checkSet.length; if ( isPartStr && !/\W/.test(part) ) { - part = isXML ? part : part.toUpperCase(); + part = part.toLowerCase(); - for ( var i = 0, l = checkSet.length; i < l; i++ ) { - var elem = checkSet[i]; + for ( ; i < l; i++ ) { + elem = checkSet[i]; if ( elem ) { var parent = elem.parentNode; - checkSet[i] = parent.nodeName === part ? parent : false; + checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; } } } else { - for ( var i = 0, l = checkSet.length; i < l; i++ ) { - var elem = checkSet[i]; + for ( ; i < l; i++ ) { + elem = checkSet[i]; if ( elem ) { checkSet[i] = isPartStr ? elem.parentNode : @@ -3699,20 +3878,22 @@ var Expr = Sizzle.selectors = { } }, "": function(checkSet, part, isXML){ - var doneName = done++, checkFn = dirCheck; + var doneName = done++, checkFn = dirCheck, nodeCheck; - if ( !part.match(/\W/) ) { - var nodeCheck = part = isXML ? part : part.toUpperCase(); + if ( typeof part === "string" && !/\W/.test(part) ) { + part = part.toLowerCase(); + nodeCheck = part; checkFn = dirNodeCheck; } checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); }, "~": function(checkSet, part, isXML){ - var doneName = done++, checkFn = dirCheck; + var doneName = done++, checkFn = dirCheck, nodeCheck; - if ( typeof part === "string" && !part.match(/\W/) ) { - var nodeCheck = part = isXML ? part : part.toUpperCase(); + if ( typeof part === "string" && !/\W/.test(part) ) { + part = part.toLowerCase(); + nodeCheck = part; checkFn = dirNodeCheck; } @@ -3726,7 +3907,7 @@ var Expr = Sizzle.selectors = { return m ? [m] : []; } }, - NAME: function(match, context, isXML){ + NAME: function(match, context){ if ( typeof context.getElementsByName !== "undefined" ) { var ret = [], results = context.getElementsByName(match[1]); @@ -3753,9 +3934,10 @@ var Expr = Sizzle.selectors = { for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { if ( elem ) { - if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) { - if ( !inplace ) + if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) { + if ( !inplace ) { result.push( elem ); + } } else if ( inplace ) { curLoop[i] = false; } @@ -3768,14 +3950,13 @@ var Expr = Sizzle.selectors = { return match[1].replace(/\\/g, ""); }, TAG: function(match, curLoop){ - for ( var i = 0; curLoop[i] === false; i++ ){} - return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase(); + return match[1].toLowerCase(); }, CHILD: function(match){ - if ( match[1] == "nth" ) { + if ( match[1] === "nth" ) { // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( - match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" || + match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); // calculate the numbers (first)n+(last) including if they are negative @@ -3804,7 +3985,7 @@ var Expr = Sizzle.selectors = { PSEUDO: function(match, curLoop, inplace, result, not){ if ( match[1] === "not" ) { // If we're dealing with a complex expression, or a simple one - if ( match[3].match(chunker).length > 1 || /^\w/.test(match[3]) ) { + if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { match[3] = Sizzle(match[3], null, null, curLoop); } else { var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); @@ -3850,7 +4031,7 @@ var Expr = Sizzle.selectors = { return !!Sizzle( match[3], elem ).length; }, header: function(elem){ - return /h\d/i.test( elem.nodeName ); + return (/h\d/i).test( elem.nodeName ); }, text: function(elem){ return "text" === elem.type; @@ -3877,10 +4058,10 @@ var Expr = Sizzle.selectors = { return "reset" === elem.type; }, button: function(elem){ - return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON"; + return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; }, input: function(elem){ - return /input|select|textarea|button/i.test(elem.nodeName); + return (/input|select|textarea|button/i).test(elem.nodeName); } }, setFilters: { @@ -3903,10 +4084,10 @@ var Expr = Sizzle.selectors = { return i > match[3] - 0; }, nth: function(elem, i, match){ - return match[3] - 0 == i; + return match[3] - 0 === i; }, eq: function(elem, i, match){ - return match[3] - 0 == i; + return match[3] - 0 === i; } }, filter: { @@ -3916,17 +4097,19 @@ var Expr = Sizzle.selectors = { if ( filter ) { return filter( elem, i, match, array ); } else if ( name === "contains" ) { - return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0; + return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0; } else if ( name === "not" ) { var not = match[3]; - for ( var i = 0, l = not.length; i < l; i++ ) { - if ( not[i] === elem ) { + for ( var j = 0, l = not.length; j < l; j++ ) { + if ( not[j] === elem ) { return false; } } return true; + } else { + Sizzle.error( "Syntax error, unrecognized expression: " + name ); } }, CHILD: function(elem, match){ @@ -3934,20 +4117,26 @@ var Expr = Sizzle.selectors = { switch (type) { case 'only': case 'first': - while (node = node.previousSibling) { - if ( node.nodeType === 1 ) return false; + while ( (node = node.previousSibling) ) { + if ( node.nodeType === 1 ) { + return false; + } + } + if ( type === "first" ) { + return true; } - if ( type == 'first') return true; node = elem; case 'last': - while (node = node.nextSibling) { - if ( node.nodeType === 1 ) return false; + while ( (node = node.nextSibling) ) { + if ( node.nodeType === 1 ) { + return false; + } } return true; case 'nth': var first = match[2], last = match[3]; - if ( first == 1 && last == 0 ) { + if ( first === 1 && last === 0 ) { return true; } @@ -3965,10 +4154,10 @@ var Expr = Sizzle.selectors = { } var diff = elem.nodeIndex - last; - if ( first == 0 ) { - return diff == 0; + if ( first === 0 ) { + return diff === 0; } else { - return ( diff % first == 0 && diff / first >= 0 ); + return ( diff % first === 0 && diff / first >= 0 ); } } }, @@ -3976,7 +4165,7 @@ var Expr = Sizzle.selectors = { return elem.nodeType === 1 && elem.getAttribute("id") === match; }, TAG: function(elem, match){ - return (match === "*" && elem.nodeType === 1) || elem.nodeName === match; + return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match; }, CLASS: function(elem, match){ return (" " + (elem.className || elem.getAttribute("class")) + " ") @@ -4004,7 +4193,7 @@ var Expr = Sizzle.selectors = { !check ? value && result !== false : type === "!=" ? - value != check : + value !== check : type === "^=" ? value.indexOf(check) === 0 : type === "$=" ? @@ -4023,14 +4212,18 @@ var Expr = Sizzle.selectors = { } }; -var origPOS = Expr.match.POS; +var origPOS = Expr.match.POS, + fescape = function(all, num){ + return "\\" + (num - 0 + 1); + }; for ( var type in Expr.match ) { - Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); + Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); + Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); } var makeArray = function(array, results) { - array = Array.prototype.slice.call( array ); + array = Array.prototype.slice.call( array, 0 ); if ( results ) { results.push.apply( results, array ); @@ -4042,23 +4235,25 @@ var makeArray = function(array, results) { // Perform a simple check to determine if the browser is capable of // converting a NodeList to an array using builtin methods. +// Also verifies that the returned array holds DOM nodes +// (which is not the case in the Blackberry browser) try { - Array.prototype.slice.call( document.documentElement.childNodes ); + Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; // Provide a fallback method if it does not work } catch(e){ makeArray = function(array, results) { - var ret = results || []; + var ret = results || [], i = 0; if ( toString.call(array) === "[object Array]" ) { Array.prototype.push.apply( ret, array ); } else { if ( typeof array.length === "number" ) { - for ( var i = 0, l = array.length; i < l; i++ ) { + for ( var l = array.length; i < l; i++ ) { ret.push( array[i] ); } } else { - for ( var i = 0; array[i]; i++ ) { + for ( ; array[i]; i++ ) { ret.push( array[i] ); } } @@ -4072,6 +4267,13 @@ var sortOrder; if ( document.documentElement.compareDocumentPosition ) { sortOrder = function( a, b ) { + if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { + if ( a == b ) { + hasDuplicate = true; + } + return a.compareDocumentPosition ? -1 : 1; + } + var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; if ( ret === 0 ) { hasDuplicate = true; @@ -4080,6 +4282,13 @@ if ( document.documentElement.compareDocumentPosition ) { }; } else if ( "sourceIndex" in document.documentElement ) { sortOrder = function( a, b ) { + if ( !a.sourceIndex || !b.sourceIndex ) { + if ( a == b ) { + hasDuplicate = true; + } + return a.sourceIndex ? -1 : 1; + } + var ret = a.sourceIndex - b.sourceIndex; if ( ret === 0 ) { hasDuplicate = true; @@ -4088,6 +4297,13 @@ if ( document.documentElement.compareDocumentPosition ) { }; } else if ( document.createRange ) { sortOrder = function( a, b ) { + if ( !a.ownerDocument || !b.ownerDocument ) { + if ( a == b ) { + hasDuplicate = true; + } + return a.ownerDocument ? -1 : 1; + } + var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); aRange.setStart(a, 0); aRange.setEnd(a, 0); @@ -4101,12 +4317,32 @@ if ( document.documentElement.compareDocumentPosition ) { }; } +// Utility function for retreiving the text value of an array of DOM nodes +Sizzle.getText = function( elems ) { + var ret = "", elem; + + for ( var i = 0; elems[i]; i++ ) { + elem = elems[i]; + + // Get the text from text nodes and CDATA nodes + if ( elem.nodeType === 3 || elem.nodeType === 4 ) { + ret += elem.nodeValue; + + // Traverse everything else, except comment nodes + } else if ( elem.nodeType !== 8 ) { + ret += Sizzle.getText( elem.childNodes ); + } + } + + return ret; +}; + // Check to see if the browser returns elements by name when // querying by getElementById (and provide a workaround) (function(){ // We're going to inject a fake input element with a specified name var form = document.createElement("div"), - id = "script" + (new Date).getTime(); + id = "script" + (new Date()).getTime(); form.innerHTML = "<a name='" + id + "'/>"; // Inject it into the root element, check its status, and remove it quickly @@ -4115,7 +4351,7 @@ if ( document.documentElement.compareDocumentPosition ) { // The workaround has to do additional checks after a getElementById // Which slows things down for other browsers (hence the branching) - if ( !!document.getElementById( id ) ) { + if ( document.getElementById( id ) ) { Expr.find.ID = function(match, context, isXML){ if ( typeof context.getElementById !== "undefined" && !isXML ) { var m = context.getElementById(match[1]); @@ -4130,6 +4366,7 @@ if ( document.documentElement.compareDocumentPosition ) { } root.removeChild( form ); + root = form = null; // release memory in IE })(); (function(){ @@ -4170,68 +4407,75 @@ if ( document.documentElement.compareDocumentPosition ) { return elem.getAttribute("href", 2); }; } + + div = null; // release memory in IE })(); -if ( document.querySelectorAll ) (function(){ - var oldSizzle = Sizzle, div = document.createElement("div"); - div.innerHTML = "<p class='TEST'></p>"; +if ( document.querySelectorAll ) { + (function(){ + var oldSizzle = Sizzle, div = document.createElement("div"); + div.innerHTML = "<p class='TEST'></p>"; - // Safari can't handle uppercase or unicode characters when - // in quirks mode. - if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { - return; - } + // Safari can't handle uppercase or unicode characters when + // in quirks mode. + if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { + return; + } - Sizzle = function(query, context, extra, seed){ - context = context || document; + Sizzle = function(query, context, extra, seed){ + context = context || document; - // Only use querySelectorAll on non-XML documents - // (ID selectors don't work in non-HTML documents) - if ( !seed && context.nodeType === 9 && !isXML(context) ) { - try { - return makeArray( context.querySelectorAll(query), extra ); - } catch(e){} - } + // Only use querySelectorAll on non-XML documents + // (ID selectors don't work in non-HTML documents) + if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) { + try { + return makeArray( context.querySelectorAll(query), extra ); + } catch(e){} + } - return oldSizzle(query, context, extra, seed); - }; + return oldSizzle(query, context, extra, seed); + }; - for ( var prop in oldSizzle ) { - Sizzle[ prop ] = oldSizzle[ prop ]; - } -})(); + for ( var prop in oldSizzle ) { + Sizzle[ prop ] = oldSizzle[ prop ]; + } -if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){ + div = null; // release memory in IE + })(); +} + +(function(){ var div = document.createElement("div"); + div.innerHTML = "<div class='test e'></div><div class='test'></div>"; // Opera can't find a second classname (in 9.6) - if ( div.getElementsByClassName("e").length === 0 ) + // Also, make sure that getElementsByClassName actually exists + if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { return; + } // Safari caches class attributes, doesn't catch changes (in 3.2) div.lastChild.className = "e"; - if ( div.getElementsByClassName("e").length === 1 ) + if ( div.getElementsByClassName("e").length === 1 ) { return; - + } + Expr.order.splice(1, 0, "CLASS"); Expr.find.CLASS = function(match, context, isXML) { if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { return context.getElementsByClassName(match[1]); } }; + + div = null; // release memory in IE })(); function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { - var sibDir = dir == "previousSibling" && !isXML; for ( var i = 0, l = checkSet.length; i < l; i++ ) { var elem = checkSet[i]; if ( elem ) { - if ( sibDir && elem.nodeType === 1 ){ - elem.sizcache = doneName; - elem.sizset = i; - } elem = elem[dir]; var match = false; @@ -4246,7 +4490,7 @@ function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { elem.sizset = i; } - if ( elem.nodeName === cur ) { + if ( elem.nodeName.toLowerCase() === cur ) { match = elem; break; } @@ -4260,14 +4504,9 @@ function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { } function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { - var sibDir = dir == "previousSibling" && !isXML; for ( var i = 0, l = checkSet.length; i < l; i++ ) { var elem = checkSet[i]; if ( elem ) { - if ( sibDir && elem.nodeType === 1 ) { - elem.sizcache = doneName; - elem.sizset = i; - } elem = elem[dir]; var match = false; @@ -4302,15 +4541,17 @@ function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { } } -var contains = document.compareDocumentPosition ? function(a, b){ - return a.compareDocumentPosition(b) & 16; +Sizzle.contains = document.compareDocumentPosition ? function(a, b){ + return !!(a.compareDocumentPosition(b) & 16); } : function(a, b){ return a !== b && (a.contains ? a.contains(b) : true); }; -var isXML = function(elem){ - return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || - !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; +Sizzle.isXML = function(elem){ + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; + return documentElement ? documentElement.nodeName !== "HTML" : false; }; var posProcess = function(selector, context){ @@ -4339,6 +4580,7 @@ window.tinymce.dom.Sizzle = Sizzle; })(); + (function(tinymce) { // Shorten names var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event; @@ -4611,10 +4853,8 @@ window.tinymce.dom.Sizzle = Sizzle; this.cancelBubble = true; } } + }); - }); - - // Shorten name and setup global instance Event = tinymce.dom.Event = new tinymce.dom.EventUtils(); // Dispatch DOM content loaded event for IE and Safari @@ -4624,45 +4864,25 @@ window.tinymce.dom.Sizzle = Sizzle; Event.destroy(); }); })(tinymce); -(function(tinymce) { - var each = tinymce.each; - - tinymce.create('tinymce.dom.Element', { - Element : function(id, s) { - var t = this, dom, el; - - s = s || {}; - t.id = id; - t.dom = dom = s.dom || tinymce.DOM; - t.settings = s; - - // Only IE leaks DOM references, this is a lot faster - if (!tinymce.isIE) - el = t.dom.get(t.id); - each([ - 'getPos', - 'getRect', - 'getParent', - 'add', - 'setStyle', - 'getStyle', - 'setStyles', - 'setAttrib', - 'setAttribs', - 'getAttrib', - 'addClass', - 'removeClass', - 'hasClass', - 'getOuterHTML', - 'setOuterHTML', - 'remove', - 'show', - 'hide', - 'isHidden', - 'setHTML', - 'get' - ], function(k) { +(function(tinymce) { + tinymce.dom.Element = function(id, settings) { + var t = this, dom, el; + + t.settings = settings = settings || {}; + t.id = id; + t.dom = dom = settings.dom || tinymce.DOM; + + // Only IE leaks DOM references, this is a lot faster + if (!tinymce.isIE) + el = dom.get(t.id); + + tinymce.each( + ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' + + 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' + + 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' + + 'isHidden,setHTML,get').split(/,/) + , function(k) { t[k] = function() { var a = [id], i; @@ -4674,83 +4894,86 @@ window.tinymce.dom.Sizzle = Sizzle; return a; }; - }); - }, - - on : function(n, f, s) { - return tinymce.dom.Event.add(this.id, n, f, s); - }, + }); - getXY : function() { - return { - x : parseInt(this.getStyle('left')), - y : parseInt(this.getStyle('top')) - }; - }, + tinymce.extend(t, { + on : function(n, f, s) { + return tinymce.dom.Event.add(t.id, n, f, s); + }, - getSize : function() { - var n = this.dom.get(this.id); + getXY : function() { + return { + x : parseInt(t.getStyle('left')), + y : parseInt(t.getStyle('top')) + }; + }, - return { - w : parseInt(this.getStyle('width') || n.clientWidth), - h : parseInt(this.getStyle('height') || n.clientHeight) - }; - }, + getSize : function() { + var n = dom.get(t.id); - moveTo : function(x, y) { - this.setStyles({left : x, top : y}); - }, + return { + w : parseInt(t.getStyle('width') || n.clientWidth), + h : parseInt(t.getStyle('height') || n.clientHeight) + }; + }, - moveBy : function(x, y) { - var p = this.getXY(); + moveTo : function(x, y) { + t.setStyles({left : x, top : y}); + }, - this.moveTo(p.x + x, p.y + y); - }, + moveBy : function(x, y) { + var p = t.getXY(); - resizeTo : function(w, h) { - this.setStyles({width : w, height : h}); - }, + t.moveTo(p.x + x, p.y + y); + }, - resizeBy : function(w, h) { - var s = this.getSize(); + resizeTo : function(w, h) { + t.setStyles({width : w, height : h}); + }, - this.resizeTo(s.w + w, s.h + h); - }, + resizeBy : function(w, h) { + var s = t.getSize(); - update : function(k) { - var t = this, b, dom = t.dom; + t.resizeTo(s.w + w, s.h + h); + }, - if (tinymce.isIE6 && t.settings.blocker) { - k = k || ''; + update : function(k) { + var b; - // Ignore getters - if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0) - return; + if (tinymce.isIE6 && settings.blocker) { + k = k || ''; - // Remove blocker on remove - if (k == 'remove') { - dom.remove(t.blocker); - return; - } + // Ignore getters + if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0) + return; - if (!t.blocker) { - t.blocker = dom.uniqueId(); - b = dom.add(t.settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'}); - dom.setStyle(b, 'opacity', 0); - } else - b = dom.get(t.blocker); + // Remove blocker on remove + if (k == 'remove') { + dom.remove(t.blocker); + return; + } - dom.setStyle(b, 'left', t.getStyle('left', 1)); - dom.setStyle(b, 'top', t.getStyle('top', 1)); - dom.setStyle(b, 'width', t.getStyle('width', 1)); - dom.setStyle(b, 'height', t.getStyle('height', 1)); - dom.setStyle(b, 'display', t.getStyle('display', 1)); - dom.setStyle(b, 'zIndex', parseInt(t.getStyle('zIndex', 1) || 0) - 1); + if (!t.blocker) { + t.blocker = dom.uniqueId(); + b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'}); + dom.setStyle(b, 'opacity', 0); + } else + b = dom.get(t.blocker); + + dom.setStyles(b, { + left : t.getStyle('left', 1), + top : t.getStyle('top', 1), + width : t.getStyle('width', 1), + height : t.getStyle('height', 1), + display : t.getStyle('display', 1), + zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1 + }); + } } - } - }); + }; })(tinymce); + (function(tinymce) { function trimNl(s) { return s.replace(/[\n\r]+/g, ''); @@ -4781,6 +5004,9 @@ window.tinymce.dom.Sizzle = Sizzle; if (!t.win.getSelection) t.tridentSel = new tinymce.dom.TridentSelection(t); + if (tinymce.isIE && dom.boxModel) + this._fixIESelection(); + // Prevent leaks tinymce.addUnload(t.destroy, t); }, @@ -4838,23 +5064,38 @@ window.tinymce.dom.Sizzle = Sizzle; h += '<span id="__caret">_</span>'; // Delete and insert new node - r.deleteContents(); - r.insertNode(t.getRng().createContextualFragment(h)); + + if (r.startContainer == d && r.endContainer == d) { + // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents + d.body.innerHTML = h; + } else { + r.deleteContents(); + if (d.body.childNodes.length == 0) { + d.body.innerHTML = h; + } else { + // createContextualFragment doesn't exists in IE 9 DOMRanges + if (r.createContextualFragment) { + r.insertNode(r.createContextualFragment(h)); + } else { + // Fake createContextualFragment call in IE 9 + var frag = d.createDocumentFragment(), temp = d.createElement('div'); + + frag.appendChild(temp); + temp.outerHTML = h; + + r.insertNode(frag); + } + } + } // Move to caret marker c = t.dom.get('__caret'); - // Make sure we wrap it compleatly, Opera fails with a simple select call r = d.createRange(); r.setStartBefore(c); - r.setEndAfter(c); + r.setEndBefore(c); t.setRng(r); - // Delete the marker, and hopefully the caret gets placed in the right location - // Removed this since it seems to remove in FF and simply deleting it - // doesn't seem to affect the caret position in any browser - //d.execCommand('Delete', false, null); - // Remove the caret position t.dom.remove('__caret'); } else { @@ -4872,34 +5113,50 @@ window.tinymce.dom.Sizzle = Sizzle; }, getStart : function() { - var t = this, r = t.getRng(), e; - - if (isIE) { - if (r.item) - return r.item(0); - - r = r.duplicate(); - r.collapse(1); - e = r.parentElement(); + var rng = this.getRng(), startElement, parentElement, checkRng, node; + + if (rng.duplicate || rng.item) { + // Control selection, return first item + if (rng.item) + return rng.item(0); + + // Get start element + checkRng = rng.duplicate(); + checkRng.collapse(1); + startElement = checkRng.parentElement(); + + // Check if range parent is inside the start element, then return the inner parent element + // This will fix issues when a single element is selected, IE would otherwise return the wrong start element + parentElement = node = rng.parentElement(); + while (node = node.parentNode) { + if (node == startElement) { + startElement = parentElement; + break; + } + } - if (e && e.nodeName == 'BODY') - return e.firstChild; + // If start element is body element try to move to the first child if it exists + if (startElement && startElement.nodeName == 'BODY') + return startElement.firstChild || startElement; - return e; + return startElement; } else { - e = r.startContainer; + startElement = rng.startContainer; + + if (startElement.nodeType == 1 && startElement.hasChildNodes()) + startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)]; - if (e.nodeName == 'BODY') - return e.firstChild; + if (startElement && startElement.nodeType == 3) + return startElement.parentNode; - return t.dom.getParent(e, '*'); + return startElement; } }, getEnd : function() { - var t = this, r = t.getRng(), e; + var t = this, r = t.getRng(), e, eo; - if (isIE) { + if (r.duplicate || r.item) { if (r.item) return r.item(0); @@ -4908,331 +5165,302 @@ window.tinymce.dom.Sizzle = Sizzle; e = r.parentElement(); if (e && e.nodeName == 'BODY') - return e.lastChild; + return e.lastChild || e; return e; } else { e = r.endContainer; + eo = r.endOffset; - if (e.nodeName == 'BODY') - return e.lastChild; + if (e.nodeType == 1 && e.hasChildNodes()) + e = e.childNodes[eo > 0 ? eo - 1 : eo]; - return t.dom.getParent(e, '*'); + if (e && e.nodeType == 3) + return e.parentNode; + + return e; } }, - getBookmark : function(si) { - var t = this, r = t.getRng(), tr, sx, sy, vp = t.dom.getViewPort(t.win), e, sp, bp, le, c = -0xFFFFFF, s, ro = t.dom.getRoot(), wb = 0, wa = 0, nv; - sx = vp.x; - sy = vp.y; + getBookmark : function(type, normalized) { + var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles; - // Simple bookmark fast but not as persistent - if (si) - return {rng : r, scrollX : sx, scrollY : sy}; + function findIndex(name, element) { + var index = 0; - // Handle IE - if (isIE) { - // Control selection - if (r.item) { - e = r.item(0); + each(dom.select(name), function(node, i) { + if (node == element) + index = i; + }); - each(t.dom.select(e.nodeName), function(n, i) { - if (e == n) { - sp = i; - return false; - } - }); + return index; + }; - return { - tag : e.nodeName, - index : sp, - scrollX : sx, - scrollY : sy - }; - } + if (type == 2) { + function getLocation() { + var rng = t.getRng(true), root = dom.getRoot(), bookmark = {}; - // Text selection - tr = t.dom.doc.body.createTextRange(); - tr.moveToElementText(ro); - tr.collapse(true); - bp = Math.abs(tr.move('character', c)); + function getPoint(rng, start) { + var container = rng[start ? 'startContainer' : 'endContainer'], + offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0; - tr = r.duplicate(); - tr.collapse(true); - sp = Math.abs(tr.move('character', c)); + if (container.nodeType == 3) { + if (normalized) { + for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling) + offset += node.nodeValue.length; + } - tr = r.duplicate(); - tr.collapse(false); - le = Math.abs(tr.move('character', c)) - sp; + point.push(offset); + } else { + childNodes = container.childNodes; - return { - start : sp - bp, - length : le, - scrollX : sx, - scrollY : sy - }; - } + if (offset >= childNodes.length && childNodes.length) { + after = 1; + offset = Math.max(0, childNodes.length - 1); + } - // Handle W3C - e = t.getNode(); - s = t.getSel(); + point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after); + } - if (!s) - return null; + for (; container && container != root; container = container.parentNode) + point.push(t.dom.nodeIndex(container, normalized)); - // Image selection - if (e && e.nodeName == 'IMG') { - return { - scrollX : sx, - scrollY : sy - }; - } + return point; + }; - // Text selection + bookmark.start = getPoint(rng, true); - function getPos(r, sn, en) { - var w = t.dom.doc.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}; + if (!t.isCollapsed()) + bookmark.end = getPoint(rng); - while ((n = w.nextNode()) != null) { - if (n == sn) - d.start = p; + return bookmark; + }; - if (n == en) { - d.end = p; - return d; - } + return getLocation(); + } - p += trimNl(n.nodeValue || '').length; - } + // Handle simple range + if (type) + return {rng : t.getRng()}; - return null; - }; + rng = t.getRng(); + id = dom.uniqueId(); + collapsed = tinyMCE.activeEditor.selection.isCollapsed(); + styles = 'overflow:hidden;line-height:0px'; - // Caret or selection - if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) { - e = getPos(ro, s.anchorNode, s.focusNode); + // Explorer method + if (rng.duplicate || rng.item) { + // Text selection + if (!rng.item) { + rng2 = rng.duplicate(); - if (!e) - return {scrollX : sx, scrollY : sy}; + // Insert start marker + rng.collapse(); + rng.pasteHTML('<span _mce_type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>'); - // Count whitespace before - trimNl(s.anchorNode.nodeValue || '').replace(/^\s+/, function(a) {wb = a.length;}); + // Insert end marker + if (!collapsed) { + rng2.collapse(false); + rng2.pasteHTML('<span _mce_type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>'); + } + } else { + // Control selection + element = rng.item(0); + name = element.nodeName; - return { - start : Math.max(e.start + s.anchorOffset - wb, 0), - end : Math.max(e.end + s.focusOffset - wb, 0), - scrollX : sx, - scrollY : sy, - beg : s.anchorOffset - wb == 0 - }; + return {name : name, index : findIndex(name, element)}; + } } else { - e = getPos(ro, r.startContainer, r.endContainer); + element = t.getNode(); + name = element.nodeName; + if (name == 'IMG') + return {name : name, index : findIndex(name, element)}; - // Count whitespace before start and end container - //(r.startContainer.nodeValue || '').replace(/^\s+/, function(a) {wb = a.length;}); - //(r.endContainer.nodeValue || '').replace(/^\s+/, function(a) {wa = a.length;}); + // W3C method + rng2 = rng.cloneRange(); - if (!e) - return {scrollX : sx, scrollY : sy}; + // Insert end marker + if (!collapsed) { + rng2.collapse(false); + rng2.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_end', style : styles}, chr)); + } - return { - start : Math.max(e.start + r.startOffset - wb, 0), - end : Math.max(e.end + r.endOffset - wa, 0), - scrollX : sx, - scrollY : sy, - beg : r.startOffset - wb == 0 - }; + rng.collapse(true); + rng.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_start', style : styles}, chr)); } - }, - - moveToBookmark : function(b) { - var t = this, r = t.getRng(), s = t.getSel(), ro = t.dom.getRoot(), sd, nvl, nv; - function getPos(r, sp, ep) { - var w = t.dom.doc.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}, o, v, wa, wb; + t.moveToBookmark({id : id, keep : 1}); - while ((n = w.nextNode()) != null) { - wa = wb = 0; + return {id : id}; + }, - nv = n.nodeValue || ''; - //nv.replace(/^\s+[^\s]/, function(a) {wb = a.length - 1;}); - //nv.replace(/[^\s]\s+$/, function(a) {wa = a.length - 1;}); + moveToBookmark : function(bookmark) { + var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset; - nvl = trimNl(nv).length; - p += nvl; + // Clear selection cache + if (t.tridentSel) + t.tridentSel.destroy(); - if (p >= sp && !d.startNode) { - o = sp - (p - nvl); + if (bookmark) { + if (bookmark.start) { + rng = dom.createRng(); + root = dom.getRoot(); - // Fix for odd quirk in FF - if (b.beg && o >= nvl) - continue; + function setEndPoint(start) { + var point = bookmark[start ? 'start' : 'end'], i, node, offset, children; - d.startNode = n; - d.startOffset = o + wb; - } + if (point) { + // Find container node + for (node = root, i = point.length - 1; i >= 1; i--) { + children = node.childNodes; - if (p >= ep) { - d.endNode = n; - d.endOffset = ep - (p - nvl) + wb; - return d; - } - } + if (children.length) + node = children[point[i]]; + } - return null; - }; + // Set offset within container node + if (start) + rng.setStart(node, point[0]); + else + rng.setEnd(node, point[0]); + } + }; - if (!b) - return false; + setEndPoint(true); + setEndPoint(); - t.win.scrollTo(b.scrollX, b.scrollY); + t.setRng(rng); + } else if (bookmark.id) { + function restoreEndPoint(suffix) { + var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep; - // Handle explorer - if (isIE) { - // Handle simple - if (r = b.rng) { - try { - r.select(); - } catch (ex) { - // Ignore - } + if (marker) { + node = marker.parentNode; - return true; - } + if (suffix == 'start') { + if (!keep) { + idx = dom.nodeIndex(marker); + } else { + node = marker.firstChild; + idx = 1; + } - t.win.focus(); + startContainer = endContainer = node; + startOffset = endOffset = idx; + } else { + if (!keep) { + idx = dom.nodeIndex(marker); + } else { + node = marker.firstChild; + idx = 1; + } - // Handle control bookmark - if (b.tag) { - r = ro.createControlRange(); + endContainer = node; + endOffset = idx; + } - each(t.dom.select(b.tag), function(n, i) { - if (i == b.index) - r.addElement(n); - }); - } else { - // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs - try { - // Incorrect bookmark - if (b.start < 0) - return true; + if (!keep) { + prev = marker.previousSibling; + next = marker.nextSibling; - r = s.createRange(); - r.moveToElementText(ro); - r.collapse(true); - r.moveStart('character', b.start); - r.moveEnd('character', b.length); - } catch (ex2) { - return true; - } - } + // Remove all marker text nodes + each(tinymce.grep(marker.childNodes), function(node) { + if (node.nodeType == 3) + node.nodeValue = node.nodeValue.replace(/\uFEFF/g, ''); + }); - try { - r.select(); - } catch (ex) { - // Needed for some odd IE bug #1843306 - } + // Remove marker but keep children if for example contents where inserted into the marker + // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature + while (marker = dom.get(bookmark.id + '_' + suffix)) + dom.remove(marker, 1); + + // If siblings are text nodes then merge them unless it's Opera since it some how removes the node + // and we are sniffing since adding a lot of detection code for a browser with 3% of the market isn't worth the effort. Sorry, Opera but it's just a fact + if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) { + idx = prev.nodeValue.length; + prev.appendData(next.nodeValue); + dom.remove(next); + + if (suffix == 'start') { + startContainer = endContainer = prev; + startOffset = endOffset = idx; + } else { + endContainer = prev; + endOffset = idx; + } + } + } + } + }; - return true; - } + function addBogus(node) { + // Adds a bogus BR element for empty block elements + // on non IE browsers just to have a place to put the caret + if (!isIE && dom.isBlock(node) && !node.innerHTML) + node.innerHTML = '<br _mce_bogus="1" />'; - // Handle W3C - if (!s) - return false; + return node; + }; - // Handle simple - if (b.rng) { - s.removeAllRanges(); - s.addRange(b.rng); - } else { - if (is(b.start) && is(b.end)) { - try { - sd = getPos(ro, b.start, b.end); - - if (sd) { - r = t.dom.doc.createRange(); - r.setStart(sd.startNode, sd.startOffset); - r.setEnd(sd.endNode, sd.endOffset); - s.removeAllRanges(); - s.addRange(r); - } + // Restore start/end points + restoreEndPoint('start'); + restoreEndPoint('end'); - if (!tinymce.isOpera) - t.win.focus(); - } catch (ex) { - // Ignore + if (startContainer) { + rng = dom.createRng(); + rng.setStart(addBogus(startContainer), startOffset); + rng.setEnd(addBogus(endContainer), endOffset); + t.setRng(rng); } - } + } else if (bookmark.name) { + t.select(dom.select(bookmark.name)[bookmark.index]); + } else if (bookmark.rng) + t.setRng(bookmark.rng); } }, - select : function(n, c) { - var t = this, r = t.getRng(), s = t.getSel(), b, fn, ln, d = t.win.document; + select : function(node, content) { + var t = this, dom = t.dom, rng = dom.createRng(), idx; - function find(n, start) { - var walker, o; - - if (n) { - walker = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); + idx = dom.nodeIndex(node); + rng.setStart(node.parentNode, idx); + rng.setEnd(node.parentNode, idx + 1); - // Find first/last non empty text node - while (n = walker.nextNode()) { - o = n; + // Find first/last text node or BR element + if (content) { + function setPoint(node, start) { + var walker = new tinymce.dom.TreeWalker(node, node); - if (tinymce.trim(n.nodeValue).length != 0) { + do { + // Text node + if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) { if (start) - return n; + rng.setStart(node, 0); else - o = n; - } - } - } - - return o; - }; - - if (isIE) { - try { - b = d.body; - - if (/^(IMG|TABLE)$/.test(n.nodeName)) { - r = b.createControlRange(); - r.addElement(n); - } else { - r = b.createTextRange(); - r.moveToElementText(n); - } - - r.select(); - } catch (ex) { - // Throws illigal agrument in IE some times - } - } else { - if (c) { - fn = find(n, 1) || t.dom.select('br:first', n)[0]; - ln = find(n, 0) || t.dom.select('br:last', n)[0]; + rng.setEnd(node, node.nodeValue.length); - if (fn && ln) { - r = d.createRange(); + return; + } - if (fn.nodeName == 'BR') - r.setStartBefore(fn); - else - r.setStart(fn, 0); + // BR element + if (node.nodeName == 'BR') { + if (start) + rng.setStartBefore(node); + else + rng.setEndBefore(node); - if (ln.nodeName == 'BR') - r.setEndBefore(ln); - else - r.setEnd(ln, ln.nodeValue.length); - } else - r.selectNode(n); - } else - r.selectNode(n); + return; + } + } while (node = (start ? walker.next() : walker.prev())); + }; - t.setRng(r); + setPoint(node, 1); + setPoint(node); } - return n; + t.setRng(rng); + + return node; }, isCollapsed : function() { @@ -5241,7 +5469,10 @@ window.tinymce.dom.Sizzle = Sizzle; if (!r || r.item) return false; - return !s || r.boundingWidth == 0 || r.collapsed; + if (r.compareEndPoints) + return r.compareEndPoints('StartToEnd', r) === 0; + + return !s || r.collapsed; }, collapse : function(b) { @@ -5265,7 +5496,7 @@ window.tinymce.dom.Sizzle = Sizzle; }, getRng : function(w3c) { - var t = this, s, r; + var t = this, s, r, elm, doc = t.win.document; // Found tridentSel object then we need to use that one if (w3c && t.tridentSel) @@ -5273,29 +5504,49 @@ window.tinymce.dom.Sizzle = Sizzle; try { if (s = t.getSel()) - r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : t.win.document.createRange()); + r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange()); } catch (ex) { // IE throws unspecified error here if TinyMCE is placed in a frame/iframe } + // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet + if (tinymce.isIE && r.setStart && doc.selection.createRange().item) { + elm = doc.selection.createRange().item(0); + r = doc.createRange(); + r.setStartBefore(elm); + r.setEndAfter(elm); + } + // No range found then create an empty one // This can occur when the editor is placed in a hidden container element on Gecko // Or on IE when there was an exception if (!r) - r = isIE ? t.win.document.body.createTextRange() : t.win.document.createRange(); + r = doc.createRange ? doc.createRange() : doc.body.createTextRange(); + if (t.selectedRange && t.explicitRange) { + if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) { + // Safari, Opera and Chrome only ever select text which causes the range to change. + // This lets us use the originally set range if the selection hasn't been changed by the user. + r = t.explicitRange; + } else { + t.selectedRange = null; + t.explicitRange = null; + } + } return r; }, setRng : function(r) { var s, t = this; - + if (!t.tridentSel) { s = t.getSel(); if (s) { + t.explicitRange = r; s.removeAllRanges(); s.addRange(r); + t.selectedRange = s.getRangeAt(0); } } else { // Is W3C Range @@ -5322,33 +5573,36 @@ window.tinymce.dom.Sizzle = Sizzle; }, getNode : function() { - var t = this, r = t.getRng(), s = t.getSel(), e; + var t = this, rng = t.getRng(), sel = t.getSel(), elm; - if (!isIE) { + if (rng.setStart) { // Range maybe lost after the editor is made visible again - if (!r) + if (!rng) return t.dom.getRoot(); - e = r.commonAncestorContainer; + elm = rng.commonAncestorContainer; // Handle selection a image or other control like element such as anchors - if (!r.collapsed) { - // If the anchor node is a element instead of a text node then return this element - if (tinymce.isWebKit && s.anchorNode && s.anchorNode.nodeType == 1) - return s.anchorNode.childNodes[s.anchorOffset]; - - if (r.startContainer == r.endContainer) { - if (r.startOffset - r.endOffset < 2) { - if (r.startContainer.hasChildNodes()) - e = r.startContainer.childNodes[r.startOffset]; + if (!rng.collapsed) { + if (rng.startContainer == rng.endContainer) { + if (rng.startOffset - rng.endOffset < 2) { + if (rng.startContainer.hasChildNodes()) + elm = rng.startContainer.childNodes[rng.startOffset]; } } + + // If the anchor node is a element instead of a text node then return this element + if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1) + return sel.anchorNode.childNodes[sel.anchorOffset]; } - return t.dom.getParent(e, '*'); + if (elm && elm.nodeType == 3) + return elm.parentNode; + + return elm; } - return r.item ? r.item(0) : r.parentElement(); + return rng.item ? rng.item(0) : rng.parentElement(); }, getSelectedBlocks : function(st, en) { @@ -5386,10 +5640,82 @@ window.tinymce.dom.Sizzle = Sizzle; // Manual destroy then remove unload handler if (!s) tinymce.removeUnload(t.destroy); - } + }, - }); + // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode + _fixIESelection : function() { + var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng; + + // Make HTML element unselectable since we are going to handle selection by hand + doc.documentElement.unselectable = true; + + // Return range from point or null if it failed + function rngFromPoint(x, y) { + var rng = body.createTextRange(); + + try { + rng.moveToPoint(x, y); + } catch (ex) { + // IE sometimes throws and exception, so lets just ignore it + rng = null; + } + + return rng; + }; + + // Fires while the selection is changing + function selectionChange(e) { + var pointRng; + + // Check if the button is down or not + if (e.button) { + // Create range from mouse position + pointRng = rngFromPoint(e.x, e.y); + + if (pointRng) { + // Check if pointRange is before/after selection then change the endPoint + if (pointRng.compareEndPoints('StartToStart', startRng) > 0) + pointRng.setEndPoint('StartToStart', startRng); + else + pointRng.setEndPoint('EndToEnd', startRng); + + pointRng.select(); + } + } else + endSelection(); + } + + // Removes listeners + function endSelection() { + dom.unbind(doc, 'mouseup', endSelection); + dom.unbind(doc, 'mousemove', selectionChange); + started = 0; + }; + + // Detect when user selects outside BODY + dom.bind(doc, 'mousedown', function(e) { + if (e.target.nodeName === 'HTML') { + if (started) + endSelection(); + + started = 1; + + // Setup start position + startRng = rngFromPoint(e.x, e.y); + if (startRng) { + // Listen for selection change events + dom.bind(doc, 'mouseup', endSelection); + dom.bind(doc, 'mousemove', selectionChange); + + dom.win.focus(); + startRng.select(); + } + } + }); + } + }); })(tinymce); + (function(tinymce) { tinymce.create('tinymce.dom.XMLWriter', { node : null, @@ -5471,7 +5797,7 @@ window.tinymce.dom.Sizzle = Sizzle; var h; h = this.doc.xml || new XMLSerializer().serializeToString(this.doc); - h = h.replace(/<\?[^?]+\?>|<html>|<\/html>|<html\/>|<!DOCTYPE[^>]+>/g, ''); + h = h.replace(/<\?[^?]+\?>|<html[^>]*>|<\/html>|<html\/>|<!DOCTYPE[^>]+>/g, ''); h = h.replace(/ ?\/>/g, ' />'); if (this.valid) @@ -5479,10 +5805,12 @@ window.tinymce.dom.Sizzle = Sizzle; return h; } - - }); + }); })(tinymce); + (function(tinymce) { + var attrsCharsRegExp = /[&\"<>]/g, textCharsRegExp = /[<>&]/g, encodedChars = {'&' : '&', '"' : '"', '<' : '<', '>' : '>'}; + tinymce.create('tinymce.dom.StringWriter', { str : null, tags : null, @@ -5513,12 +5841,16 @@ window.tinymce.dom.Sizzle = Sizzle; this.inAttr = true; this.count++; this.elementCount = this.count; + this.attrs = {}; }, writeAttribute : function(n, v) { var t = this; - t.writeRaw(" " + t.encode(n) + '="' + t.encode(v) + '"'); + if (!t.attrs[n]) { + t.writeRaw(" " + t.encode(n, true) + '="' + t.encode(v, true) + '"'); + t.attrs[n] = v; + } }, writeEndElement : function() { @@ -5559,7 +5891,7 @@ window.tinymce.dom.Sizzle = Sizzle; writeComment : function(v) { this._writeAttributesEnd(); - this.writeRaw('<!-- ' + v + '-->'); + this.writeRaw('<!--' + v + '-->'); this.count++; }, @@ -5567,23 +5899,9 @@ window.tinymce.dom.Sizzle = Sizzle; this.str += v; }, - encode : function(s) { - return s.replace(/[<>&"]/g, function(v) { - switch (v) { - case '<': - return '<'; - - case '>': - return '>'; - - case '&': - return '&'; - - case '"': - return '"'; - } - - return v; + encode : function(s, attr) { + return s.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(v) { + return encodedChars[v]; }); }, @@ -5606,9 +5924,9 @@ window.tinymce.dom.Sizzle = Sizzle; return true; } - - }); + }); })(tinymce); + (function(tinymce) { // Shorten names var extend = tinymce.extend, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, isIE = tinymce.isIE, isGecko = tinymce.isGecko; @@ -5632,27 +5950,29 @@ window.tinymce.dom.Sizzle = Sizzle; t.writer = new tinymce.dom.StringWriter(); } + // IE9 broke the XML attributes order so it can't be used anymore + if (tinymce.isIE && document.documentMode > 8) { + t.writer = new tinymce.dom.StringWriter(); + } + // Default settings t.settings = s = extend({ dom : tinymce.DOM, valid_nodes : 0, node_filter : 0, attr_filter : 0, - invalid_attrs : /^(mce_|_moz_|sizset|sizcache)/, + invalid_attrs : /^(_mce_|_moz_|sizset|sizcache)/, closed : /^(br|hr|input|meta|img|link|param|area)$/, entity_encoding : 'named', entities : '160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro', - bool_attrs : /(checked|disabled|readonly|selected|nowrap)/, valid_elements : '*[*]', extended_valid_elements : 0, - valid_child_elements : 0, invalid_elements : 0, fix_table_elements : 1, fix_list_elements : true, fix_content_duplication : true, convert_fonts_to_spans : false, font_size_classes : 0, - font_size_style_values : 0, apply_source_formatting : 0, indent_mode : 'simple', indent_char : '\t', @@ -5663,6 +5983,11 @@ window.tinymce.dom.Sizzle = Sizzle; }, s); t.dom = s.dom; + t.schema = s.schema; + + // Use raw entities if no entities are defined + if (s.entity_encoding == 'named' && !s.entities) + s.entity_encoding = 'raw'; if (s.remove_redundant_brs) { t.onPostProcess.add(function(se, o) { @@ -5726,20 +6051,27 @@ window.tinymce.dom.Sizzle = Sizzle; if (s.fix_table_elements) { t.onPreProcess.add(function(se, o) { - each(t.dom.select('p table', o.node), function(n) { - // IE has a odd bug where tables inside paragraphs sometimes gets wrapped in a BODY and documentFragement element - // This hack seems to resolve that issue. This will normally not happed since your contents should be valid in the first place - if (isIE) - n.outerHTML = n.outerHTML; - - t.dom.split(t.dom.getParent(n, 'p'), n); - }); + // Since Opera will crash if you attach the node to a dynamic document we need to brrowser sniff a specific build + // so Opera users with an older version will have to live with less compaible output not much we can do here + if (!tinymce.isOpera || opera.buildNumber() >= 1767) { + each(t.dom.select('p table', o.node).reverse(), function(n) { + var parent = t.dom.getParent(n.parentNode, 'table,p'); + + if (parent.nodeName != 'TABLE') { + try { + t.dom.split(parent, n); + } catch (ex) { + // IE can sometimes fire an unknown runtime error so we just ignore it + } + } + }); + } }); } }, setEntities : function(s) { - var t = this, a, i, l = {}, re = '', v; + var t = this, a, i, l = {}, v; // No need to setup more than once if (t.entityLookup) @@ -5757,94 +6089,11 @@ window.tinymce.dom.Sizzle = Sizzle; l[String.fromCharCode(a[i])] = a[i + 1]; v = parseInt(a[i]).toString(16); - re += '\\u' + '0000'.substring(v.length) + v; } - if (!re) { - t.settings.entity_encoding = 'raw'; - return; - } - - t.entitiesRE = new RegExp('[' + re + ']', 'g'); t.entityLookup = l; }, - setValidChildRules : function(s) { - this.childRules = null; - this.addValidChildRules(s); - }, - - addValidChildRules : function(s) { - var t = this, inst, intr, bloc; - - if (!s) - return; - - inst = 'A|BR|SPAN|BDO|MAP|OBJECT|IMG|TT|I|B|BIG|SMALL|EM|STRONG|DFN|CODE|Q|SAMP|KBD|VAR|CITE|ABBR|ACRONYM|SUB|SUP|#text|#comment'; - intr = 'A|BR|SPAN|BDO|OBJECT|APPLET|IMG|MAP|IFRAME|TT|I|B|U|S|STRIKE|BIG|SMALL|FONT|BASEFONT|EM|STRONG|DFN|CODE|Q|SAMP|KBD|VAR|CITE|ABBR|ACRONYM|SUB|SUP|INPUT|SELECT|TEXTAREA|LABEL|BUTTON|#text|#comment'; - bloc = 'H[1-6]|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|FORM|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP'; - - each(s.split(','), function(s) { - var p = s.split(/\[|\]/), re; - - s = ''; - each(p[1].split('|'), function(v) { - if (s) - s += '|'; - - switch (v) { - case '%itrans': - v = intr; - break; - - case '%itrans_na': - v = intr.substring(2); - break; - - case '%istrict': - v = inst; - break; - - case '%istrict_na': - v = inst.substring(2); - break; - - case '%btrans': - v = bloc; - break; - - case '%bstrict': - v = bloc; - break; - } - - s += v; - }); - re = new RegExp('^(' + s.toLowerCase() + ')$', 'i'); - - each(p[0].split('/'), function(s) { - t.childRules = t.childRules || {}; - t.childRules[s] = re; - }); - }); - - // Build regex - s = ''; - each(t.childRules, function(v, k) { - if (s) - s += '|'; - - s += k; - }); - - t.parentElementsRE = new RegExp('^(' + s.toLowerCase() + ')$', 'i'); - - /*console.debug(t.parentElementsRE.toString()); - each(t.childRules, function(v) { - console.debug(v.toString()); - });*/ - }, - setRules : function(s) { var t = this; @@ -6049,18 +6298,56 @@ window.tinymce.dom.Sizzle = Sizzle; }, serialize : function(n, o) { - var h, t = this, doc; + var h, t = this, doc, oldDoc, impl, selected; t._setup(); o = o || {}; o.format = o.format || 'html'; - n = n.cloneNode(true); t.processObj = o; - // Nodes needs to be attached to something in WebKit due to a bug https://bugs.webkit.org/show_bug.cgi?id=25571 - if (tinymce.isWebKit) { - doc = n.ownerDocument.implementation.createHTMLDocument(""); - doc.body.appendChild(n); + // IE looses the selected attribute on option elements so we need to store it + // See: http://support.microsoft.com/kb/829907 + if (isIE) { + selected = []; + each(n.getElementsByTagName('option'), function(n) { + var v = t.dom.getAttrib(n, 'selected'); + + selected.push(v ? v : null); + }); + } + + n = n.cloneNode(true); + + // IE looses the selected attribute on option elements so we need to restore it + if (isIE) { + each(n.getElementsByTagName('option'), function(n, i) { + t.dom.setAttrib(n, 'selected', selected[i]); + }); + } + + // Nodes needs to be attached to something in WebKit/Opera + // Older builds of Opera crashes if you attach the node to an document created dynamically + // and since we can't feature detect a crash we need to sniff the acutal build number + // This fix will make DOM ranges and make Sizzle happy! + impl = n.ownerDocument.implementation; + if (impl.createHTMLDocument && (tinymce.isOpera && opera.buildNumber() >= 1767)) { + // Create an empty HTML document + doc = impl.createHTMLDocument(""); + + // Add the element or it's children if it's a body element to the new document + each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) { + doc.body.appendChild(doc.importNode(node, true)); + }); + + // Grab first child or body element for serialization + if (n.nodeName != 'BODY') + n = doc.body.firstChild; + else + n = doc.body; + + // set the new document in DOMUtils so createElement etc works + oldDoc = t.dom.doc; + t.dom.doc = doc; } t.key = '' + (parseInt(t.key) + 1); @@ -6073,11 +6360,16 @@ window.tinymce.dom.Sizzle = Sizzle; // Serialize HTML DOM into a string t.writer.reset(); + t._info = o; t._serializeNode(n, o.getInner); // Post process o.content = t.writer.getContent(); + // Restore the old document if it was changed + if (oldDoc) + t.dom.doc = oldDoc; + if (!o.no_events) t.onPostProcess.dispatch(t, o); @@ -6122,23 +6414,23 @@ window.tinymce.dom.Sizzle = Sizzle; // This process is only done when getting contents out from the editor. if (!o.set) { // We need to replace paragraph whitespace with an nbsp before indentation to keep the \u00a0 char - h = h.replace(/<p>\s+<\/p>|<p([^>]+)>\s+<\/p>/g, s.entity_encoding == 'numeric' ? '<p$1> </p>' : '<p$1> </p>'); + h = tinymce._replace(/<p>\s+<\/p>|<p([^>]+)>\s+<\/p>/g, s.entity_encoding == 'numeric' ? '<p$1> </p>' : '<p$1> </p>', h); if (s.remove_linebreaks) { h = h.replace(/\r?\n|\r/g, ' '); - h = h.replace(/(<[^>]+>)\s+/g, '$1 '); - h = h.replace(/\s+(<\/[^>]+>)/g, ' $1'); - h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object) ([^>]+)>\s+/g, '<$1 $2>'); // Trim block start - h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>\s+/g, '<$1>'); // Trim block start - h = h.replace(/\s+<\/(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>/g, '</$1>'); // Trim block end + h = tinymce._replace(/(<[^>]+>)\s+/g, '$1 ', h); + h = tinymce._replace(/\s+(<\/[^>]+>)/g, ' $1', h); + h = tinymce._replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object) ([^>]+)>\s+/g, '<$1 $2>', h); // Trim block start + h = tinymce._replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>\s+/g, '<$1>', h); // Trim block start + h = tinymce._replace(/\s+<\/(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>/g, '</$1>', h); // Trim block end } // Simple indentation if (s.apply_source_formatting && s.indent_mode == 'simple') { // Add line breaks before and after block elements - h = h.replace(/<(\/?)(ul|hr|table|meta|link|tbody|tr|object|body|head|html|map)(|[^>]+)>\s*/g, '\n<$1$2$3>\n'); - h = h.replace(/\s*<(p|h[1-6]|blockquote|div|title|style|pre|script|td|li|area)(|[^>]+)>/g, '\n<$1$2>'); - h = h.replace(/<\/(p|h[1-6]|blockquote|div|title|style|pre|script|td|li)>\s*/g, '</$1>\n'); + h = tinymce._replace(/<(\/?)(ul|hr|table|meta|link|tbody|tr|object|body|head|html|map)(|[^>]+)>\s*/g, '\n<$1$2$3>\n', h); + h = tinymce._replace(/\s*<(p|h[1-6]|blockquote|div|title|style|pre|script|td|li|area)(|[^>]+)>/g, '\n<$1$2>', h); + h = tinymce._replace(/<\/(p|h[1-6]|blockquote|div|title|style|pre|script|td|li)>\s*/g, '</$1>\n', h); h = h.replace(/\n\n/g, '\n'); } } @@ -6146,14 +6438,11 @@ window.tinymce.dom.Sizzle = Sizzle; h = t._unprotect(h, p); // Restore CDATA sections - h = h.replace(/<!--\[CDATA\[([\s\S]+)\]\]-->/g, '<![CDATA[$1]]>'); - - // Restore scripts - h = h.replace(/(type|language)=\"mce-/g, '$1="'); + h = tinymce._replace(/<!--\[CDATA\[([\s\S]+)\]\]-->/g, '<![CDATA[$1]]>', h); // Restore the \u00a0 character if raw mode is enabled if (s.entity_encoding == 'raw') - h = h.replace(/<p> <\/p>|<p([^>]+)> <\/p>/g, '<p$1>\u00a0</p>'); + h = tinymce._replace(/<p> <\/p>|<p([^>]+)> <\/p>/g, '<p$1>\u00a0</p>', h); // Restore noscript elements h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) { @@ -6164,23 +6453,34 @@ window.tinymce.dom.Sizzle = Sizzle; o.content = h; }, - _serializeNode : function(n, inn) { - var t = this, s = t.settings, w = t.writer, hc, el, cn, i, l, a, at, no, v, nn, ru, ar, iv, closed; + _serializeNode : function(n, inner) { + var t = this, s = t.settings, w = t.writer, hc, el, cn, i, l, a, at, no, v, nn, ru, ar, iv, closed, keep, type, scopeName; if (!s.node_filter || s.node_filter(n)) { switch (n.nodeType) { case 1: // Element - if (n.hasAttribute ? n.hasAttribute('mce_bogus') : n.getAttribute('mce_bogus')) + if (n.hasAttribute ? n.hasAttribute('_mce_bogus') : n.getAttribute('_mce_bogus')) return; - iv = false; + iv = keep = false; hc = n.hasChildNodes(); - nn = n.getAttribute('mce_name') || n.nodeName.toLowerCase(); + nn = n.getAttribute('_mce_name') || n.nodeName.toLowerCase(); + + // Get internal type + type = n.getAttribute('_mce_type'); + if (type) { + if (!t._info.cleanup) { + iv = true; + return; + } else + keep = 1; + } // Add correct prefix on IE if (isIE) { - if (n.scopeName !== 'HTML' && n.scopeName !== 'html') - nn = n.scopeName + ':' + nn; + scopeName = n.scopeName; + if (scopeName && scopeName !== 'HTML' && scopeName !== 'html') + nn = scopeName + ':' + nn; } // Remove mce prefix on IE needed for the abbr element @@ -6188,18 +6488,20 @@ window.tinymce.dom.Sizzle = Sizzle; nn = nn.substring(4); // Check if valid - if (!t.validElementsRE || !t.validElementsRE.test(nn) || (t.invalidElementsRE && t.invalidElementsRE.test(nn)) || inn) { - iv = true; - break; + if (!keep) { + if (!t.validElementsRE || !t.validElementsRE.test(nn) || (t.invalidElementsRE && t.invalidElementsRE.test(nn)) || inner) { + iv = true; + break; + } } if (isIE) { // Fix IE content duplication (DOM can have multiple copies of the same node) if (s.fix_content_duplication) { - if (n.mce_serialized == t.key) + if (n._mce_serialized == t.key) return; - n.mce_serialized = t.key; + n._mce_serialized = t.key; } // IE sometimes adds a / infront of the node name @@ -6212,18 +6514,23 @@ window.tinymce.dom.Sizzle = Sizzle; } // Check if valid child - if (t.childRules) { - if (t.parentElementsRE.test(t.elementName)) { - if (!t.childRules[t.elementName].test(nn)) { - iv = true; - break; - } + if (s.validate_children) { + if (t.elementName && !t.schema.isValid(t.elementName, nn)) { + iv = true; + break; } t.elementName = nn; } ru = t.findRule(nn); + + // No valid rule for this element could be found then skip it + if (!ru) { + iv = true; + break; + } + nn = ru.name || nn; closed = s.closed.test(nn); @@ -6283,6 +6590,10 @@ window.tinymce.dom.Sizzle = Sizzle; } } + // Keep type attribute + if (type && keep) + w.writeAttribute('_mce_type', type); + // Write text from script if (nn === 'script' && tinymce.trim(n.innerHTML)) { w.writeText('// '); // Padd it with a comment so it will parse on older browsers @@ -6295,7 +6606,7 @@ window.tinymce.dom.Sizzle = Sizzle; if (ru.padd) { // If it has only one bogus child, padd it anyway workaround for <td><br /></td> bug if (hc && (cn = n.firstChild) && cn.nodeType === 1 && n.childNodes.length === 1) { - if (cn.hasAttribute ? cn.hasAttribute('mce_bogus') : cn.getAttribute('mce_bogus')) + if (cn.hasAttribute ? cn.hasAttribute('_mce_bogus') : cn.getAttribute('_mce_bogus')) w.writeText('\u00a0'); } else if (!hc) w.writeText('\u00a0'); // No children then padd it @@ -6305,10 +6616,8 @@ window.tinymce.dom.Sizzle = Sizzle; case 3: // Text // Check if valid child - if (t.childRules && t.parentElementsRE.test(t.elementName)) { - if (!t.childRules[t.elementName].test(n.nodeName)) - return; - } + if (s.validate_children && t.elementName && !t.schema.isValid(t.elementName, '#text')) + return; return w.writeText(n.nodeValue); @@ -6401,7 +6710,7 @@ window.tinymce.dom.Sizzle = Sizzle; t.setEntities(s.entities); l = t.entityLookup; - h = h.replace(t.entitiesRE, function(a) { + h = h.replace(/[\u007E-\uFFFF]/g, function(a) { var v; if (v = l[a]) @@ -6431,7 +6740,6 @@ window.tinymce.dom.Sizzle = Sizzle; t.setRules(s.valid_elements); t.addRules(s.extended_valid_elements); - t.addValidChildRules(s.valid_child_elements); if (s.invalid_elements) t.invalidElementsRE = new RegExp('^(' + wildcardToRE(s.invalid_elements.replace(/,/g, '|').toLowerCase()) + ')$'); @@ -6454,16 +6762,6 @@ window.tinymce.dom.Sizzle = Sizzle; v = this.dom.getAttrib(n, na); - // Bool attr - if (this.settings.bool_attrs.test(na) && v) { - v = ('' + v).toLowerCase(); - - if (v === 'false' || v === '0') - return null; - - v = na; - } - switch (na) { case 'rowspan': case 'colspan': @@ -6506,273 +6804,573 @@ window.tinymce.dom.Sizzle = Sizzle; return v; } - - }); + }); })(tinymce); + (function(tinymce) { - var each = tinymce.each, Event = tinymce.dom.Event; + tinymce.dom.ScriptLoader = function(settings) { + var QUEUED = 0, + LOADING = 1, + LOADED = 2, + states = {}, + queue = [], + scriptLoadedCallbacks = {}, + queueLoadedCallbacks = [], + loading = 0, + undefined; + + function loadScript(url, callback) { + var t = this, dom = tinymce.DOM, elm, uri, loc, id; + + // Execute callback when script is loaded + function done() { + dom.remove(id); + + if (elm) + elm.onreadystatechange = elm.onload = elm = null; + + callback(); + }; - tinymce.create('tinymce.dom.ScriptLoader', { - ScriptLoader : function(s) { - this.settings = s || {}; - this.queue = []; - this.lookup = {}; - }, + id = dom.uniqueId(); - isDone : function(u) { - return this.lookup[u] ? this.lookup[u].state == 2 : 0; - }, + if (tinymce.isIE6) { + uri = new tinymce.util.URI(url); + loc = location; - markDone : function(u) { - this.lookup[u] = {state : 2, url : u}; - }, + // If script is from same domain and we + // use IE 6 then use XHR since it's more reliable + if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol) { + tinymce.util.XHR.send({ + url : tinymce._addVer(uri.getURI()), + success : function(content) { + // Create new temp script element + var script = dom.create('script', { + type : 'text/javascript' + }); - add : function(u, cb, s, pr) { - var t = this, lo = t.lookup, o; + // Evaluate script in global scope + script.text = content; + document.getElementsByTagName('head')[0].appendChild(script); + dom.remove(script); - if (o = lo[u]) { - // Is loaded fire callback - if (cb && o.state == 2) - cb.call(s || this); + done(); + } + }); - return o; + return; + } } - o = {state : 0, url : u, func : cb, scope : s || this}; + // Create new script element + elm = dom.create('script', { + id : id, + type : 'text/javascript', + src : tinymce._addVer(url) + }); - if (pr) - t.queue.unshift(o); - else - t.queue.push(o); + // Add onload listener for non IE browsers since IE9 + // fires onload event before the script is parsed and executed + if (!tinymce.isIE) + elm.onload = done; - lo[u] = o; + elm.onreadystatechange = function() { + var state = elm.readyState; - return o; - }, + // Loaded state is passed on IE 6 however there + // are known issues with this method but we can't use + // XHR in a cross domain loading + if (state == 'complete' || state == 'loaded') + done(); + }; - load : function(u, cb, s) { - var t = this, o; + // Most browsers support this feature so we report errors + // for those at least to help users track their missing plugins etc + // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option + /*elm.onerror = function() { + alert('Failed to load: ' + url); + };*/ - if (o = t.lookup[u]) { - // Is loaded fire callback - if (cb && o.state == 2) - cb.call(s || t); + // Add script to document + (document.getElementsByTagName('head')[0] || document.body).appendChild(elm); + }; - return o; + this.isDone = function(url) { + return states[url] == LOADED; + }; + + this.markDone = function(url) { + states[url] = LOADED; + }; + + this.add = this.load = function(url, callback, scope) { + var item, state = states[url]; + + // Add url to load queue + if (state == undefined) { + queue.push(url); + states[url] = QUEUED; } - function loadScript(u) { - if (Event.domLoaded || t.settings.strict_mode) { - tinymce.util.XHR.send({ - url : tinymce._addVer(u), - error : t.settings.error, - async : false, - success : function(co) { - throw('evalremoved3'); - } - }); - } else - document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>'); - }; + if (callback) { + // Store away callback for later execution + if (!scriptLoadedCallbacks[url]) + scriptLoadedCallbacks[url] = []; - if (!tinymce.is(u, 'string')) { - each(u, function(u) { - loadScript(u); + scriptLoadedCallbacks[url].push({ + func : callback, + scope : scope || this }); + } + }; - if (cb) - cb.call(s || t); - } else { - loadScript(u); + this.loadQueue = function(callback, scope) { + this.loadScripts(queue, callback, scope); + }; - if (cb) - cb.call(s || t); - } - }, + this.loadScripts = function(scripts, callback, scope) { + var loadScripts; - loadQueue : function(cb, s) { - var t = this; + function execScriptLoadedCallbacks(url) { + // Execute URL callback functions + tinymce.each(scriptLoadedCallbacks[url], function(callback) { + callback.func.call(callback.scope); + }); + + scriptLoadedCallbacks[url] = undefined; + }; - if (!t.queueLoading) { - t.queueLoading = 1; - t.queueCallbacks = []; + queueLoadedCallbacks.push({ + func : callback, + scope : scope || this + }); - t.loadScripts(t.queue, function() { - t.queueLoading = 0; + loadScripts = function() { + var loadingScripts = tinymce.grep(scripts); - if (cb) - cb.call(s || t); + // Current scripts has been handled + scripts.length = 0; - each(t.queueCallbacks, function(o) { - o.func.call(o.scope); - }); + // Load scripts that needs to be loaded + tinymce.each(loadingScripts, function(url) { + // Script is already loaded then execute script callbacks directly + if (states[url] == LOADED) { + execScriptLoadedCallbacks(url); + return; + } + + // Is script not loading then start loading it + if (states[url] != LOADING) { + states[url] = LOADING; + loading++; + + loadScript(url, function() { + states[url] = LOADED; + loading--; + + execScriptLoadedCallbacks(url); + + // Load more scripts if they where added by the recently loaded script + loadScripts(); + }); + } }); - } else if (cb) - t.queueCallbacks.push({func : cb, scope : s || t}); - }, - eval : function(co) { - var w = window; + // No scripts are currently loading then execute all pending queue loaded callbacks + if (!loading) { + tinymce.each(queueLoadedCallbacks, function(callback) { + callback.func.call(callback.scope); + }); - // Evaluate script - if (!w.execScript) { - try { - throw('evalremoved1'); - } catch (ex) { - throw('evalremoved2'); + queueLoadedCallbacks.length = 0; } - } else - w.execScript(co); // IE - }, + }; - loadScripts : function(sc, cb, s) { - var t = this, lo = t.lookup; + loadScripts(); + }; + }; - function done(o) { - o.state = 2; // Has been loaded + // Global script loader + tinymce.ScriptLoader = new tinymce.dom.ScriptLoader(); +})(tinymce); - // Run callback - if (o.func) - o.func.call(o.scope || t); - }; +tinymce.dom.TreeWalker = function(start_node, root_node) { + var node = start_node; - function allDone() { - var l; + function findSibling(node, start_name, sibling_name, shallow) { + var sibling, parent; - // Check if all files are loaded - l = sc.length; - each(sc, function(o) { - o = lo[o.url]; + if (node) { + // Walk into nodes if it has a start + if (!shallow && node[start_name]) + return node[start_name]; - if (o.state === 2) {// It has finished loading - done(o); - l--; - } else - load(o); - }); + // Return the sibling if it has one + if (node != root_node) { + sibling = node[sibling_name]; + if (sibling) + return sibling; - // They are all loaded - if (l === 0 && cb) { - cb.call(s || t); - cb = 0; + // Walk up the parents to look for siblings + for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) { + sibling = parent[sibling_name]; + if (sibling) + return sibling; } - }; + } + } + }; - function load(o) { - if (o.state > 0) - return; + this.current = function() { + return node; + }; + + this.next = function(shallow) { + return (node = findSibling(node, 'firstChild', 'nextSibling', shallow)); + }; + + this.prev = function(shallow) { + return (node = findSibling(node, 'lastChild', 'lastSibling', shallow)); + }; +}; + +(function() { + var transitional = {}; + + function unpack(lookup, data) { + var key; + + function replace(value) { + return value.replace(/[A-Z]+/g, function(key) { + return replace(lookup[key]); + }); + }; + + // Unpack lookup + for (key in lookup) { + if (lookup.hasOwnProperty(key)) + lookup[key] = replace(lookup[key]); + } + + // Unpack and parse data into object map + replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]/g, function(str, name, children) { + var i, map = {}; + + children = children.split(/\|/); + + for (i = children.length - 1; i >= 0; i--) + map[children[i]] = 1; - o.state = 1; // Is loading + transitional[name] = map; + }); + }; - tinymce.dom.ScriptLoader.loadScript(o.url, function() { - done(o); - allDone(); + // This is the XHTML 1.0 transitional elements with it's children packed to reduce it's size + // we will later include the attributes here and use it as a default for valid elements but it + // requires us to rewrite the serializer engine + unpack({ + Z : '#|H|K|N|O|P', + Y : '#|X|form|R|Q', + X : 'p|T|div|U|W|isindex|fieldset|table', + W : 'pre|hr|blockquote|address|center|noframes', + U : 'ul|ol|dl|menu|dir', + ZC : '#|p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q', + T : 'h1|h2|h3|h4|h5|h6', + ZB : '#|X|S|Q', + S : 'R|P', + ZA : '#|a|G|J|M|O|P', + R : '#|a|H|K|N|O', + Q : 'noscript|P', + P : 'ins|del|script', + O : 'input|select|textarea|label|button', + N : 'M|L', + M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym', + L : 'sub|sup', + K : 'J|I', + J : 'tt|i|b|u|s|strike', + I : 'big|small|font|basefont', + H : 'G|F', + G : 'br|span|bdo', + F : 'object|applet|img|map|iframe' + }, 'script[]' + + 'style[]' + + 'object[#|param|X|form|a|H|K|N|O|Q]' + + 'param[]' + + 'p[S]' + + 'a[Z]' + + 'br[]' + + 'span[S]' + + 'bdo[S]' + + 'applet[#|param|X|form|a|H|K|N|O|Q]' + + 'h1[S]' + + 'img[]' + + 'map[X|form|Q|area]' + + 'h2[S]' + + 'iframe[#|X|form|a|H|K|N|O|Q]' + + 'h3[S]' + + 'tt[S]' + + 'i[S]' + + 'b[S]' + + 'u[S]' + + 's[S]' + + 'strike[S]' + + 'big[S]' + + 'small[S]' + + 'font[S]' + + 'basefont[]' + + 'em[S]' + + 'strong[S]' + + 'dfn[S]' + + 'code[S]' + + 'q[S]' + + 'samp[S]' + + 'kbd[S]' + + 'var[S]' + + 'cite[S]' + + 'abbr[S]' + + 'acronym[S]' + + 'sub[S]' + + 'sup[S]' + + 'input[]' + + 'select[optgroup|option]' + + 'optgroup[option]' + + 'option[]' + + 'textarea[]' + + 'label[S]' + + 'button[#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' + + 'h4[S]' + + 'ins[#|X|form|a|H|K|N|O|Q]' + + 'h5[S]' + + 'del[#|X|form|a|H|K|N|O|Q]' + + 'h6[S]' + + 'div[#|X|form|a|H|K|N|O|Q]' + + 'ul[li]' + + 'li[#|X|form|a|H|K|N|O|Q]' + + 'ol[li]' + + 'dl[dt|dd]' + + 'dt[S]' + + 'dd[#|X|form|a|H|K|N|O|Q]' + + 'menu[li]' + + 'dir[li]' + + 'pre[ZA]' + + 'hr[]' + + 'blockquote[#|X|form|a|H|K|N|O|Q]' + + 'address[S|p]' + + 'center[#|X|form|a|H|K|N|O|Q]' + + 'noframes[#|X|form|a|H|K|N|O|Q]' + + 'isindex[]' + + 'fieldset[#|legend|X|form|a|H|K|N|O|Q]' + + 'legend[S]' + + 'table[caption|col|colgroup|thead|tfoot|tbody|tr]' + + 'caption[S]' + + 'col[]' + + 'colgroup[col]' + + 'thead[tr]' + + 'tr[th|td]' + + 'th[#|X|form|a|H|K|N|O|Q]' + + 'form[#|X|a|H|K|N|O|Q]' + + 'noscript[#|X|form|a|H|K|N|O|Q]' + + 'td[#|X|form|a|H|K|N|O|Q]' + + 'tfoot[tr]' + + 'tbody[tr]' + + 'area[]' + + 'base[]' + + 'body[#|X|form|a|H|K|N|O|Q]' + ); + + tinymce.dom.Schema = function() { + var t = this, elements = transitional; + + t.isValid = function(name, child_name) { + var element = elements[name]; + + return !!(element && (!child_name || element[child_name])); + }; + }; +})(); +(function(tinymce) { + tinymce.dom.RangeUtils = function(dom) { + var INVISIBLE_CHAR = '\uFEFF'; + + this.walk = function(rng, callback) { + var startContainer = rng.startContainer, + startOffset = rng.startOffset, + endContainer = rng.endContainer, + endOffset = rng.endOffset, + ancestor, startPoint, + endPoint, node, parent, siblings, nodes; + + // Handle table cell selection the table plugin enables + // you to fake select table cells and perform formatting actions on them + nodes = dom.select('td.mceSelected,th.mceSelected'); + if (nodes.length > 0) { + tinymce.each(nodes, function(node) { + callback([node]); }); - }; - each(sc, function(o) { - var u = o.url; + return; + } + + function collectSiblings(node, name, end_node) { + var siblings = []; - // Add to queue if needed - if (!lo[u]) { - lo[u] = o; - t.queue.push(o); - } else - o = lo[u]; + for (; node && node != end_node; node = node[name]) + siblings.push(node); - // Is already loading or has been loaded - if (o.state > 0) - return; + return siblings; + }; - if (!Event.domLoaded && !t.settings.strict_mode) { - var ix, ol = ''; + function findEndPoint(node, root) { + do { + if (node.parentNode == root) + return node; - // Add onload events - if (cb || o.func) { - o.state = 1; // Is loading + node = node.parentNode; + } while(node); + }; - ix = tinymce.dom.ScriptLoader._addOnLoad(function() { - done(o); - allDone(); - }); + function walkBoundary(start_node, end_node, next) { + var siblingName = next ? 'nextSibling' : 'previousSibling'; - if (tinymce.isIE) - ol = ' onreadystatechange="'; - else - ol = ' onload="'; + for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) { + parent = node.parentNode; + siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName); - ol += 'tinymce.dom.ScriptLoader._onLoad(this,\'' + u + '\',' + ix + ');"'; + if (siblings.length) { + if (!next) + siblings.reverse(); + + callback(siblings); } + } + }; - document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"' + ol + '></script>'); + // If index based start position then resolve it + if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) + startContainer = startContainer.childNodes[startOffset]; - if (!o.func) - done(o); - } else - load(o); - }); + // If index based end position then resolve it + if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) + endContainer = endContainer.childNodes[Math.min(startOffset == endOffset ? endOffset : endOffset - 1, endContainer.childNodes.length - 1)]; - allDone(); - }, + // Find common ancestor and end points + ancestor = dom.findCommonAncestor(startContainer, endContainer); - // Static methods - 'static' : { - _addOnLoad : function(f) { - var t = this; + // Same container + if (startContainer == endContainer) + return callback([startContainer]); - t._funcs = t._funcs || []; - t._funcs.push(f); + // Process left side + for (node = startContainer; node; node = node.parentNode) { + if (node == endContainer) + return walkBoundary(startContainer, ancestor, true); - return t._funcs.length - 1; - }, + if (node == ancestor) + break; + } - _onLoad : function(e, u, ix) { - if (!tinymce.isIE || e.readyState == 'complete') - this._funcs[ix].call(this); - }, + // Process right side + for (node = endContainer; node; node = node.parentNode) { + if (node == startContainer) + return walkBoundary(endContainer, ancestor); + + if (node == ancestor) + break; + } - loadScript : function(u, cb) { - var id = tinymce.DOM.uniqueId(), e; + // Find start/end point + startPoint = findEndPoint(startContainer, ancestor) || startContainer; + endPoint = findEndPoint(endContainer, ancestor) || endContainer; - function done() { - Event.clear(id); - tinymce.DOM.remove(id); + // Walk left leaf + walkBoundary(startContainer, startPoint, true); - if (cb) { - cb.call(document, u); - cb = 0; - } - }; + // Walk the middle from start to end point + siblings = collectSiblings( + startPoint == startContainer ? startPoint : startPoint.nextSibling, + 'nextSibling', + endPoint == endContainer ? endPoint.nextSibling : endPoint + ); - if (tinymce.isIE) { -/* Event.add(e, 'readystatechange', function(e) { - if (e.target && e.target.readyState == 'complete') - done(); - });*/ + if (siblings.length) + callback(siblings); - tinymce.util.XHR.send({ - url : tinymce._addVer(u), - async : false, - success : function(co) { - window.execScript(co); - done(); - } - }); - } else { - e = tinymce.DOM.create('script', {id : id, type : 'text/javascript', src : tinymce._addVer(u)}); - Event.add(e, 'load', done); + // Walk right leaf + walkBoundary(endContainer, endPoint); + }; + + /* 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; + }; + + // 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); + } + } else { + // Split startContainer text node if needed + if (startContainer.nodeType == 3 && startOffset != 0) { + startContainer = splitText(startContainer, startOffset); + startOffset = 0; + } - // Check for head or body - (document.getElementsByTagName('head')[0] || document.body).appendChild(e); + // Split endContainer text node if needed + if (endContainer.nodeType == 3 && endOffset != endContainer.nodeValue.length) { + endContainer = splitText(endContainer, endOffset).previousSibling; + endOffset = endContainer.nodeValue.length; } } - } - }); + return { + startContainer : startContainer, + startOffset : startOffset, + endContainer : endContainer, + endOffset : endOffset + }; + }; +*/ + }; - // Global script loader - tinymce.ScriptLoader = new tinymce.dom.ScriptLoader(); + tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) { + if (rng1 && rng2) { + // Compare native IE ranges + if (rng1.item || rng1.duplicate) { + // Both are control ranges and the selected element matches + if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0)) + return true; + + // Both are text ranges and the range matches + if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1)) + return true; + } else { + // Compare w3c ranges + return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset; + } + } + + return false; + }; })(tinymce); + (function(tinymce) { // Shorten class names var DOM = tinymce.DOM, is = tinymce.is; @@ -6872,12 +7470,14 @@ window.tinymce.dom.Sizzle = Sizzle; destroy : function() { tinymce.dom.Event.clear(this.id); } - - }); -})(tinymce);tinymce.create('tinymce.ui.Container:tinymce.ui.Control', { + }); +})(tinymce); +tinymce.create('tinymce.ui.Container:tinymce.ui.Control', { Container : function(id, s) { this.parent(id, s); + this.controls = []; + this.lookup = {}; }, @@ -6891,8 +7491,8 @@ window.tinymce.dom.Sizzle = Sizzle; get : function(n) { return this.lookup[n]; } +}); - }); tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { Separator : function(id, s) { @@ -6903,8 +7503,8 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { renderHTML : function() { return tinymce.DOM.createHTML('span', {'class' : this.classPrefix}); } +}); - }); (function(tinymce) { var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; @@ -6932,9 +7532,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { if (is(t.selected)) t.setSelected(t.selected); } - - }); + }); })(tinymce); + (function(tinymce) { var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; @@ -7031,9 +7631,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { return m; } - - }); -})(tinymce);(function(tinymce) { + }); +})(tinymce); +(function(tinymce) { var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element; tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', { @@ -7359,9 +7959,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { DOM.addClass(ro, 'mceLast'); } - - }); -})(tinymce);(function(tinymce) { + }); +})(tinymce); +(function(tinymce) { var DOM = tinymce.DOM; tinymce.create('tinymce.ui.Button:tinymce.ui.Control', { @@ -7392,9 +7992,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { return s.onclick.call(s.scope, e); }); } - - }); + }); })(tinymce); + (function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; @@ -7403,11 +8003,17 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { var t = this; t.parent(id, s); + t.items = []; + t.onChange = new Dispatcher(t); + t.onPostRender = new Dispatcher(t); + t.onAdd = new Dispatcher(t); + t.onRenderMenu = new tinymce.util.Dispatcher(this); + t.classPrefix = 'mceListBox'; }, @@ -7536,16 +8142,16 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { hideMenu : function(e) { var t = this; - // Prevent double toogles by canceling the mouse click event to the button - if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open')) - return; - - if (!e || !DOM.getParent(e.target, '.mceMenu')) { - DOM.removeClass(t.id, t.classPrefix + 'Selected'); - Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); + if (t.menu && t.menu.isMenuVisible) { + // Prevent double toogles by canceling the mouse click event to the button + if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open')) + return; - if (t.menu) + if (!e || !DOM.getParent(e.target, '.mceMenu')) { + DOM.removeClass(t.id, t.classPrefix + 'Selected'); + Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); t.menu.hideMenu(); + } } }, @@ -7571,13 +8177,25 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { }); each(t.items, function(o) { - o.id = DOM.uniqueId(); - o.onclick = function() { - if (t.settings.onselect(o.value) !== false) - t.select(o.value); // Must be runned after - }; + // No value then treat it as a title + if (o.value === undefined) { + m.add({ + title : o.title, + 'class' : 'mceMenuItemTitle', + onclick : function() { + if (t.settings.onselect('') !== false) + t.select(''); // Must be runned after + } + }); + } else { + o.id = DOM.uniqueId(); + o.onclick = function() { + if (t.settings.onselect(o.value) !== false) + t.select(o.value); // Must be runned after + }; - m.add(o); + m.add(o); + } }); t.onRenderMenu.dispatch(t, m); @@ -7588,7 +8206,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { var t = this, cp = t.classPrefix; Event.add(t.id, 'click', t.showMenu, t); - Event.add(t.id + '_text', 'focus', function(e) { + Event.add(t.id + '_text', 'focus', function() { if (!t._focused) { t.keyDownHandler = Event.add(t.id + '_text', 'keydown', function(e) { var idx = -1, v, kc = e.keyCode; @@ -7645,9 +8263,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { Event.clear(this.id + '_text'); Event.clear(this.id + '_open'); } - - }); -})(tinymce);(function(tinymce) { + }); +})(tinymce); +(function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', { @@ -7720,7 +8338,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { }, getLength : function() { - return DOM.get(this.id).options.length - 1; + return this.items.length; }, renderHTML : function() { @@ -7774,15 +8392,17 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { t.onPostRender.dispatch(t, DOM.get(t.id)); } - - }); -})(tinymce);(function(tinymce) { + }); +})(tinymce); +(function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', { MenuButton : function(id, s) { this.parent(id, s); + this.onRenderMenu = new tinymce.util.Dispatcher(this); + s.menu_container = s.menu_container || DOM.doc.body; }, @@ -7861,9 +8481,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { } }); } - - }); + }); })(tinymce); + (function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; @@ -7927,9 +8547,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { Event.clear(this.id + '_action'); Event.clear(this.id + '_open'); } + }); +})(tinymce); - }); -})(tinymce); (function(tinymce) { var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each; @@ -7946,6 +8566,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { }, t.settings); t.onShowMenu = new tinymce.util.Dispatcher(t); + t.onHideMenu = new tinymce.util.Dispatcher(t); t.value = s.default_color; @@ -8037,7 +8658,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { style : { backgroundColor : '#' + c }, - mce_color : '#' + c + _mce_color : '#' + c }); }); @@ -8059,7 +8680,7 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { e = e.target; - if (e.nodeName == 'A' && (c = e.getAttribute('mce_color'))) + if (e.nodeName == 'A' && (c = e.getAttribute('_mce_color'))) t.setColor(c); return Event.cancel(e); // Prevent IE auto save warning @@ -8093,9 +8714,9 @@ tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { Event.clear(this.id + '_more'); DOM.remove(this.id + '_menu'); } - - }); + }); })(tinymce); + tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { renderHTML : function() { var t = this, h = '', c, co, dom = tinymce.DOM, s = t.settings, i, pr, nx, cl; @@ -8157,32 +8778,30 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { return dom.createHTML('table', {id : t.id, 'class' : 'mceToolbar' + (s['class'] ? ' ' + s['class'] : ''), cellpadding : '0', cellspacing : '0', align : t.settings.align || ''}, '<tbody><tr>' + h + '</tr></tbody>'); } +}); - }); (function(tinymce) { var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each; tinymce.create('tinymce.AddOnManager', { - items : [], - urls : {}, - lookup : {}, - onAdd : new Dispatcher(this), + AddOnManager : function() { + var self = this; + + self.items = []; + self.urls = {}; + self.lookup = {}; + self.onAdd = new Dispatcher(self); + }, get : function(n) { return this.lookup[n]; }, requireLangPack : function(n) { - var u, s = tinymce.EditorManager.settings; - - if (s && s.language) { - u = this.urls[n] + '/langs/' + s.language + '.js'; + var s = tinymce.settings; - if (!tinymce.dom.Event.domLoaded && !s.strict_mode) - tinymce.ScriptLoader.load(u); - else - tinymce.ScriptLoader.add(u); - } + if (s && s.language) + tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js'); }, add : function(id, o) { @@ -8203,47 +8822,57 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { u = tinymce.baseURL + '/' + u; t.urls[n] = u.substring(0, u.lastIndexOf('/')); - tinymce.ScriptLoader.add(u, cb, s); - } - }); + if (!t.lookup[n]) + tinymce.ScriptLoader.add(u, cb, s); + } + }); // Create plugin and theme managers tinymce.PluginManager = new tinymce.AddOnManager(); tinymce.ThemeManager = new tinymce.AddOnManager(); -}(tinymce));(function(tinymce) { +}(tinymce)); + +(function(tinymce) { // Shorten names - var each = tinymce.each, extend = tinymce.extend, DOM = tinymce.DOM, Event = tinymce.dom.Event, ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, explode = tinymce.explode; + var each = tinymce.each, extend = tinymce.extend, + DOM = tinymce.DOM, Event = tinymce.dom.Event, + ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, + explode = tinymce.explode, + Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0; - tinymce.create('static tinymce.EditorManager', { - editors : {}, - i18n : {}, - activeEditor : null, + // Setup some URLs where the editor API is located and where the document is + tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); + if (!/[\/\\]$/.test(tinymce.documentBaseURL)) + tinymce.documentBaseURL += '/'; - preInit : function() { - var t = this, lo = window.location; + tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL); - // Setup some URLs where the editor API is located and where the document is - tinymce.documentBaseURL = lo.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); - if (!/[\/\\]$/.test(tinymce.documentBaseURL)) - tinymce.documentBaseURL += '/'; + tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL); - tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL); - tinymce.EditorManager.baseURI = new tinymce.util.URI(tinymce.baseURL); + // Add before unload listener + // This was required since IE was leaking memory if you added and removed beforeunload listeners + // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event + tinymce.onBeforeUnload = new Dispatcher(tinymce); - // Add before unload listener - // This was required since IE was leaking memory if you added and removed beforeunload listeners - // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event - t.onBeforeUnload = new tinymce.util.Dispatcher(t); + // Must be on window or IE will leak if the editor is placed in frame or iframe + Event.add(window, 'beforeunload', function(e) { + tinymce.onBeforeUnload.dispatch(tinymce, e); + }); - // Must be on window or IE will leak if the editor is placed in frame or iframe - Event.add(window, 'beforeunload', function(e) { - t.onBeforeUnload.dispatch(t, e); - }); - }, + tinymce.onAddEditor = new Dispatcher(tinymce); + + tinymce.onRemoveEditor = new Dispatcher(tinymce); + + tinymce.EditorManager = extend(tinymce, { + editors : [], + + i18n : {}, + + activeEditor : null, init : function(s) { - var t = this, pl, sl = tinymce.ScriptLoader, c, e, el = [], ed; + var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed; function execCallback(se, n, s) { var f = se[n]; @@ -8262,87 +8891,17 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { s = extend({ theme : "simple", - language : "en", - strict_loading_mode : document.contentType == 'application/xhtml+xml' + language : "en" }, s); t.settings = s; - // If page not loaded and strict mode isn't enabled then load them - if (!Event.domLoaded && !s.strict_loading_mode) { - // Load language - if (s.language) - sl.add(tinymce.baseURL + '/langs/' + s.language + '.js'); - - // Load theme - if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme]) - ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js'); - - // Load plugins - if (s.plugins) { - pl = explode(s.plugins); - - // Load compat2x first - if (tinymce.inArray(pl, 'compat2x') != -1) - PluginManager.load('compat2x', 'plugins/compat2x/editor_plugin' + tinymce.suffix + '.js'); - - // Load rest if plugins - each(pl, function(v) { - if (v && v.charAt(0) != '-' && !PluginManager.urls[v]) { - // Skip safari plugin for other browsers - if (!tinymce.isWebKit && v == 'safari') - return; - - PluginManager.load(v, 'plugins/' + v + '/editor_plugin' + tinymce.suffix + '.js'); - } - }); - } - - sl.loadQueue(); - } - // Legacy call Event.add(document, 'init', function() { var l, co; execCallback(s, 'onpageload'); - // Verify that it's a valid browser - if (s.browsers) { - l = false; - - each(explode(s.browsers), function(v) { - switch (v) { - case 'ie': - case 'msie': - if (tinymce.isIE) - l = true; - break; - - case 'gecko': - if (tinymce.isGecko) - l = true; - break; - - case 'safari': - case 'webkit': - if (tinymce.isWebKit) - l = true; - break; - - case 'opera': - if (tinymce.isOpera) - l = true; - - break; - } - }); - - // Not a valid one - if (!l) - return; - } - switch (s.mode) { case "exact": l = s.elements || ''; @@ -8354,12 +8913,10 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { el.push(ed); ed.render(1); } else { - c = 0; - each(document.forms, function(f) { each(f.elements, function(e) { if (e.name === v) { - v = 'mce_editor_' + c; + v = 'mce_editor_' + instanceCounter++; DOM.setAttrib(e, 'id', v); ed = new tinymce.Editor(v, s); @@ -8405,7 +8962,7 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { if (s.oninit) { l = co = 0; - each (el, function(ed) { + each(el, function(ed) { co++; if (!ed.initialized) { @@ -8429,6 +8986,9 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { }, get : function(id) { + if (id === undefined) + return this.editors; + return this.editors[id]; }, @@ -8436,35 +8996,44 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { return this.get(id); }, - add : function(e) { - this.editors[e.id] = e; - this._setActive(e); + add : function(editor) { + var self = this, editors = self.editors; - return e; + // Add named and index editor instance + editors[editor.id] = editor; + editors.push(editor); + + self._setActive(editor); + self.onAddEditor.dispatch(self, editor); + + + return editor; }, - remove : function(e) { - var t = this; + remove : function(editor) { + var t = this, i, editors = t.editors; // Not in the collection - if (!t.editors[e.id]) + if (!editors[editor.id]) return null; - delete t.editors[e.id]; - - // Select another editor since the active one was removed - if (t.activeEditor == e) { - t._setActive(null); + delete editors[editor.id]; - each(t.editors, function(e) { - t._setActive(e); - return false; // Break - }); + for (i = 0; i < editors.length; i++) { + if (editors[i] == editor) { + editors.splice(i, 1); + break; + } } - e.destroy(); + // Select another editor since the active one was removed + if (t.activeEditor == editor) + t._setActive(editors[0]); - return e; + editor.destroy(); + t.onRemoveEditor.dispatch(t, editor); + + return editor; }, execCommand : function(c, u, v) { @@ -8577,75 +9146,109 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { // Private methods - _setActive : function(e) { - this.selectedInstance = this.activeEditor = e; + _setActive : function(editor) { + this.selectedInstance = this.activeEditor = editor; } - - }); - - tinymce.EditorManager.preInit(); + }); })(tinymce); -// Short for editor manager window.tinyMCE is needed when TinyMCE gets loaded though a XHR call -var tinyMCE = window.tinyMCE = tinymce.EditorManager; (function(tinymce) { - var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, Dispatcher = tinymce.util.Dispatcher; - var each = tinymce.each, isGecko = tinymce.isGecko, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit; - var is = tinymce.is, ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, EditorManager = tinymce.EditorManager; - var inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode; + // Shorten these names + var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, + 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; tinymce.create('tinymce.Editor', { Editor : function(id, s) { var t = this; t.id = t.editorId = id; + t.execCommands = {}; t.queryStateCommands = {}; t.queryValueCommands = {}; + + t.isNotDirty = false; + t.plugins = {}; // Add events to the editor each([ 'onPreInit', + 'onBeforeRenderUI', + 'onPostRender', + 'onInit', + 'onRemove', + 'onActivate', + 'onDeactivate', + 'onClick', + 'onEvent', + 'onMouseUp', + 'onMouseDown', + 'onDblClick', + 'onKeyDown', + 'onKeyUp', + 'onKeyPress', + 'onContextMenu', + 'onSubmit', + 'onReset', + 'onPaste', + 'onPreProcess', + 'onPostProcess', + 'onBeforeSetContent', + 'onBeforeGetContent', + 'onSetContent', + 'onGetContent', + 'onLoadContent', + 'onSaveContent', + 'onNodeChange', + 'onChange', + 'onBeforeExecCommand', + 'onExecCommand', + 'onUndo', + 'onRedo', + 'onVisualAid', + 'onSetProgressState' ], function(e) { t[e] = new Dispatcher(t); }); - // Default editor config t.settings = s = extend({ id : id, language : 'en', @@ -8671,16 +9274,14 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; custom_undo_redo_keyboard_shortcuts : 1, custom_undo_redo_restore_selection : 1, custom_undo_redo : 1, - doctype : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', + doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll visual_table_class : 'mceItemTable', visual : 1, - inline_styles : true, - convert_fonts_to_spans : true, font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', apply_source_formatting : 1, directionality : 'ltr', forced_root_block : 'p', - valid_elements : '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],strong/b,em/i,strike,u,#p[align],-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,-blockquote[cite],-table[border=0|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],object[classid|width|height|codebase|*],param[name|value],embed[type|width|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|tabindex|accesskey],kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],q[cite],samp,select[disabled|multiple|name|size],small,textarea[cols|rows|disabled|name|readonly],tt,var,big', + valid_elements : '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],strong/b,em/i,strike,u,#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,-blockquote[cite],-table[border|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],object[classid|width|height|codebase|*],param[name|value],embed[type|width|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|tabindex|accesskey],kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],q[cite],samp,select[disabled|multiple|name|size],small,textarea[cols|rows|disabled|name|readonly],tt,var,big', hidden_input : 1, padd_empty_editor : 1, render_ui : 1, @@ -8689,14 +9290,15 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; indentation : '30px', keep_styles : 1, fix_table_elements : 1, - removeformat_selector : 'span,b,strong,em,i,font,u,strike' + inline_styles : 1, + convert_fonts_to_spans : true }, s); - // Setup URIs t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, { base_uri : tinyMCE.baseURI }); - t.baseURI = EditorManager.baseURI; + + t.baseURI = tinymce.baseURI; // Call setup t.execCallback('setup', t); @@ -8713,20 +9315,17 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; return; } - // Force strict loading mode if render us called by user and not internally - if (!nst) { - s.strict_loading_mode = 1; - tinyMCE.settings = s; - } + tinyMCE.settings = s; // Element not found, then skip initialization if (!t.getElement()) return; - if (s.strict_loading_mode) { - sl.settings.strict_mode = s.strict_loading_mode; - tinymce.DOM.settings.strict = 1; - } + // Is a iPad/iPhone, then skip initialization. We need to sniff here since the + // browser says it has contentEditable support but there is no visible caret + // We will remove this check ones Apple implements full contentEditable support + if (tinymce.isIDevice) + return; // Add hidden input for non input elements inside form elements if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form')) @@ -8777,7 +9376,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; n._mceOldSubmit = n.submit; n.submit = function() { // Save all instances - EditorManager.triggerSave(); + tinymce.triggerSave(); t.isNotDirty = 1; return t.formElement._mceOldSubmit(t.formElement); @@ -8798,8 +9397,8 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; each(explode(s.plugins), function(p) { if (p && p.charAt(0) != '-' && !PluginManager.urls[p]) { - // Skip safari plugin for other browsers - if (!isWebKit && p == 'safari') + // Skip safari plugin, since it is removed as of 3.3b1 + if (p == 'safari') return; PluginManager.load(p, 'plugins/' + p + '/editor_plugin' + tinymce.suffix + '.js'); @@ -8813,20 +9412,14 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }); }; - // Load compat2x first - if (s.plugins.indexOf('compat2x') != -1) { - PluginManager.load('compat2x', 'plugins/compat2x/editor_plugin' + tinymce.suffix + '.js'); - sl.loadQueue(loadScripts); - } else - loadScripts(); + loadScripts(); }, init : function() { var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re; - EditorManager.add(t); + tinymce.add(t); - // Create theme if (s.theme) { s.theme = s.theme.replace(/-/, ''); o = ThemeManager.get(s.theme); @@ -8861,25 +9454,17 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (s.popup_css_add) s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add); - // Setup control factory t.controlManager = new tinymce.ControlManager(t); - t.undoManager = new tinymce.UndoManager(t); - - // Pass through - t.undoManager.onAdd.add(function(um, l) { - if (!l.initial) - return t.onChange.dispatch(t, l, um); - }); - - t.undoManager.onUndo.add(function(um, l) { - return t.onUndo.dispatch(t, l, um); - }); - - t.undoManager.onRedo.add(function(um, l) { - return t.onRedo.dispatch(t, l, um); - }); if (s.custom_undo_redo) { + // Add initial undo level + t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) { + if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) { + if (!t.undoManager.hasUndo()) + t.undoManager.add(); + } + }); + t.onExecCommand.add(function(ed, cmd, ui, val, a) { if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) t.undoManager.add(); @@ -8934,12 +9519,8 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // User specified a document.domain value - // try/catch added by Dan S./Zotero - try { - if (document.domain && location.hostname != document.domain) - tinymce.relaxedDomain = document.domain; - } - catch (e) {} + if (document.domain && location.hostname != document.domain) + tinymce.relaxedDomain = document.domain; // Resize editor DOM.setStyles(o.sizeContainer || o.editorContainer, { @@ -8958,7 +9539,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (s.document_base_url != tinymce.documentBaseURL) t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />'; - t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; + t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; if (tinymce.relaxedDomain) t.iframeHTML += '<script type="text/javascript">document.domain = "' + tinymce.relaxedDomain + '";</script>'; @@ -9040,40 +9621,115 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; DOM.show(b); } - // Setup objects - t.dom = new tinymce.DOM.DOMUtils(t.getDoc(), { + t.dom = new tinymce.dom.DOMUtils(t.getDoc(), { keep_values : true, url_converter : t.convertURL, url_converter_scope : t, hex_colors : s.force_hex_style_colors, class_filter : s.class_filter, update_styles : 1, - fix_ie_paragraphs : 1 + fix_ie_paragraphs : 1, + valid_styles : s.valid_styles }); - t.serializer = new tinymce.dom.Serializer({ - entity_encoding : s.entity_encoding, - entities : s.entities, + t.schema = new tinymce.dom.Schema(); + + t.serializer = new tinymce.dom.Serializer(extend(s, { valid_elements : s.verify_html === false ? '*[*]' : s.valid_elements, - extended_valid_elements : s.extended_valid_elements, - valid_child_elements : s.valid_child_elements, - invalid_elements : s.invalid_elements, - fix_table_elements : s.fix_table_elements, - fix_list_elements : s.fix_list_elements, - fix_content_duplication : s.fix_content_duplication, - convert_fonts_to_spans : s.convert_fonts_to_spans, - font_size_classes : s.font_size_classes, - font_size_style_values : s.font_size_style_values, - apply_source_formatting : s.apply_source_formatting, - remove_linebreaks : s.remove_linebreaks, - element_format : s.element_format, - dom : t.dom - }); + dom : t.dom, + schema : t.schema + })); t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer); + + t.formatter = new tinymce.Formatter(this); + + // Register default formats + t.formatter.register({ + alignleft : [ + {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}}, + {selector : 'img,table', styles : {'float' : 'left'}} + ], + + aligncenter : [ + {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}}, + {selector : 'img', styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}}, + {selector : 'table', styles : {marginLeft : 'auto', marginRight : 'auto'}} + ], + + alignright : [ + {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}}, + {selector : 'img,table', styles : {'float' : 'right'}} + ], + + alignfull : [ + {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}} + ], + + bold : [ + {inline : 'strong'}, + {inline : 'span', styles : {fontWeight : 'bold'}}, + {inline : 'b'} + ], + + italic : [ + {inline : 'em'}, + {inline : 'span', styles : {fontStyle : 'italic'}}, + {inline : 'i'} + ], + + underline : [ + {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}, + {inline : 'u'} + ], + + strikethrough : [ + {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true}, + {inline : 'u'} + ], + + forecolor : {inline : 'span', styles : {color : '%value'}}, + hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}}, + fontname : {inline : 'span', styles : {fontFamily : '%value'}}, + fontsize : {inline : 'span', styles : {fontSize : '%value'}}, + fontsize_class : {inline : 'span', attributes : {'class' : '%value'}}, + blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'}, + + removeformat : [ + {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true}, + {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true}, + {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true} + ] + }); + + // Register default block formats + each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) { + t.formatter.register(name, {block : name, remove : 'all'}); + }); + + // Register user defined formats + t.formatter.register(t.settings.formats); + + t.undoManager = new tinymce.UndoManager(t); + + // Pass through + t.undoManager.onAdd.add(function(um, l) { + if (!l.initial) + return t.onChange.dispatch(t, l, um); + }); + + t.undoManager.onUndo.add(function(um, l) { + return t.onUndo.dispatch(t, l, um); + }); + + t.undoManager.onRedo.add(function(um, l) { + return t.onRedo.dispatch(t, l, um); + }); + t.forceBlocks = new tinymce.ForceBlocks(t, { forced_root_block : s.forced_root_block }); + t.editorCommands = new tinymce.EditorCommands(t); // Pass through @@ -9113,7 +9769,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } else n = 'div'; - o.content = o.content.replace(new RegExp('<(' + v + ')([^>]*)>', 'g'), '<' + n + ' mce_name="$1"$2>'); + o.content = o.content.replace(new RegExp('<(' + v + ')([^>]*)>', 'g'), '<' + n + ' _mce_name="$1"$2>'); o.content = o.content.replace(new RegExp('</(' + v + ')>', 'g'), '</' + n + '>'); }); }; @@ -9196,12 +9852,6 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }; } - if (s.convert_fonts_to_spans) - t._convertFonts(); - - if (s.inline_styles) - t._convertInlineElements(); - if (s.cleanup_callback) { t.onBeforeSetContent.add(function(ed, o) { o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o); @@ -9258,7 +9908,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; var pn = n.parentNode; if (ed.dom.isBlock(pn) && pn.lastChild === n) - ed.dom.add(pn, 'br', {'mce_bogus' : 1}); + ed.dom.add(pn, 'br', {'_mce_bogus' : 1}); }); }; @@ -9289,7 +9939,6 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; t.load({initial : true, format : (s.cleanup_on_startup ? 'html' : 'raw')}); t.startContent = t.getContent({format : 'raw'}); - t.undoManager.add({initial : true}); t.initialized = true; t.onInit.dispatch(t); @@ -9308,7 +9957,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Handle auto focus if (s.auto_focus) { setTimeout(function () { - var ed = EditorManager.get(s.auto_focus); + var ed = tinymce.get(s.auto_focus); ed.selection.select(ed.getBody(), 1); ed.selection.collapse(1); @@ -9322,25 +9971,38 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; focus : function(sf) { - var oed, t = this, ce = t.settings.content_editable; + var oed, t = this, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc(); if (!sf) { - // Is not content editable or the selection is outside the area in IE - // the IE statement is needed to avoid bluring if element selections inside layers since - // the layer is like it's own document in IE - if (!ce && (!isIE || t.selection.getNode().ownerDocument != t.getDoc())) + // Get selected control element + ieRng = t.selection.getRng(); + if (ieRng.item) { + controlElm = ieRng.item(0); + } + + // Is not content editable + if (!ce) t.getWin().focus(); + // Restore selected control element + // This is needed when for example an image is selected within a + // layer a call to focus will then remove the control selection + if (controlElm && controlElm.ownerDocument == doc) { + ieRng = doc.body.createControlRange(); + ieRng.addElement(controlElm); + ieRng.select(); + } + } - if (EditorManager.activeEditor != t) { - if ((oed = EditorManager.activeEditor) != null) + if (tinymce.activeEditor != t) { + if ((oed = tinymce.activeEditor) != null) oed.onDeactivate.dispatch(oed, t); t.onActivate.dispatch(t, oed); } - EditorManager._setActive(t); + tinymce._setActive(t); }, execCallback : function(n) { @@ -9367,7 +10029,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }, translate : function(s) { - var c = this.settings.language || 'en', i18n = EditorManager.i18n; + var c = this.settings.language || 'en', i18n = tinymce.i18n; if (!s) return ''; @@ -9378,7 +10040,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }, getLang : function(n, dv) { - return EditorManager.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}'); + return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}'); }, getParam : function(n, dv, ty) { @@ -9406,14 +10068,26 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }, nodeChanged : function(o) { - var t = this, s = t.selection, n = s.getNode() || t.getBody(); + var t = this, s = t.selection, n = (isIE ? s.getNode() : s.getStart()) || t.getBody(); // Fix for bug #1896577 it seems that this can not be fired while the editor is loading if (t.initialized) { + o = o || {}; + n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state + + // Get parents and add them to object + o.parents = []; + t.dom.getParent(n, function(node) { + if (node.nodeName == 'BODY') + return true; + + o.parents.push(node); + }); + t.onNodeChange.dispatch( t, o ? o.controlManager || t.controlManager : t.controlManager, - isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n, // Fix for IE initial state + n, s.isCollapsed(), o ); @@ -9556,7 +10230,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; t.onExecCommand.dispatch(t, cmd, ui, val, a); }, - queryCommandState : function(c) { + queryCommandState : function(cmd) { var t = this, o, s; // Is hidden then return undefined @@ -9564,7 +10238,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; return; // Registred commands - if (o = t.queryStateCommands[c]) { + if (o = t.queryStateCommands[cmd]) { s = o.func.call(o.scope); // Fall though on true @@ -9573,13 +10247,13 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } // Registred commands - o = t.editorCommands.queryCommandState(c); + o = t.editorCommands.queryCommandState(cmd); if (o !== -1) return o; // Browser commands try { - return this.getDoc().queryCommandState(c); + return this.getDoc().queryCommandState(cmd); } catch (ex) { // Fails sometimes see bug: 1896577 } @@ -9722,7 +10396,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content // It will also be impossible to place the caret in the editor unless there is a BR element present if (!tinymce.isIE && (h.length === 0 || /^\s+$/.test(h))) { - o.content = t.dom.setHTML(t.getBody(), '<br mce_bogus="1" />'); + o.content = t.dom.setHTML(t.getBody(), '<br _mce_bogus="1" />'); o.format = 'raw'; } @@ -9891,7 +10565,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command t.onExecCommand.listeners = []; - EditorManager.remove(t); + tinymce.remove(t); DOM.remove(e); }, @@ -9945,7 +10619,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; _addEvents : function() { // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset - var t = this, i, s = t.settings, lo = { + var t = this, i, s = t.settings, dom = t.dom, lo = { mouseup : 'onMouseUp', mousedown : 'onMouseDown', click : 'onClick', @@ -9979,33 +10653,33 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; case 'contextmenu': if (tinymce.isOpera) { // Fake contextmenu on Opera - t.dom.bind(t.getBody(), 'mousedown', function(e) { + dom.bind(t.getBody(), 'mousedown', function(e) { if (e.ctrlKey) { e.fakeType = 'contextmenu'; eventHandler(e); } }); } else - t.dom.bind(t.getBody(), k, eventHandler); + dom.bind(t.getBody(), k, eventHandler); break; case 'paste': - t.dom.bind(t.getBody(), k, function(e) { + dom.bind(t.getBody(), k, function(e) { eventHandler(e); }); break; case 'submit': case 'reset': - t.dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler); + dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler); break; default: - t.dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler); + dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler); } }); - t.dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) { + dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) { t.focus(true); }); @@ -10013,22 +10687,12 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Fixes bug where a specified document_base_uri could result in broken images // This will also fix drag drop of images in Gecko if (tinymce.isGecko) { - // Convert all images to absolute URLs -/* t.onSetContent.add(function(ed, o) { - each(ed.dom.select('img'), function(e) { - var v; - - if (v = e.getAttribute('mce_src')) - e.src = t.documentBaseURI.toAbsolute(v); - }) - });*/ - - t.dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) { + dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) { var v; e = e.target; - if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('mce_src'))) + if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('_mce_src'))) e.src = t.documentBaseURI.toAbsolute(v); }); } @@ -10069,9 +10733,24 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; t.onMouseDown.add(setOpts); } + // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250 + // WebKit can't even do simple things like selecting an image + // This also fixes so it's possible to select mceItemAnchors + if (tinymce.isWebKit) { + t.onClick.add(function(ed, e) { + e = e.target; + + // Needs tobe the setBaseAndExtend or it will fail to select floated images + if (e.nodeName == 'IMG' || (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor'))) { + t.selection.getSel().setBaseAndExtent(e, 0, e, 1); + t.nodeChanged(); + } + }); + } + // Add node change handlers t.onMouseUp.add(t.nodeChanged); - t.onClick.add(t.nodeChanged); + //t.onClick.add(t.nodeChanged); t.onKeyUp.add(function(ed, e) { var c = e.keyCode; @@ -10092,15 +10771,13 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } // Add default shortcuts for gecko - if (isGecko) { - t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold'); - t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic'); - t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline'); - } + t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold'); + t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic'); + t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline'); // BlockFormat shortcuts keys for (i=1; i<=6; i++) - t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, '<h' + i + '>']); + t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]); t.addShortcut('ctrl+7', '', ['FormatBlock', false, '<p>']); t.addShortcut('ctrl+8', '', ['FormatBlock', false, '<div>']); @@ -10160,7 +10837,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (tinymce.isIE) { // Fix so resize will only update the width and height attributes not the styles of an image // It will also block mceItemNoResize items - t.dom.bind(t.getDoc(), 'controlselect', function(e) { + dom.bind(t.getDoc(), 'controlselect', function(e) { var re = t.resizeInfo, cb; e = e.target; @@ -10170,28 +10847,28 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; return; if (re) - t.dom.unbind(re.node, re.ev, re.cb); + dom.unbind(re.node, re.ev, re.cb); - if (!t.dom.hasClass(e, 'mceItemNoResize')) { + if (!dom.hasClass(e, 'mceItemNoResize')) { ev = 'resizeend'; - cb = t.dom.bind(e, ev, function(e) { + cb = dom.bind(e, ev, function(e) { var v; e = e.target; - if (v = t.dom.getStyle(e, 'width')) { - t.dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, '')); - t.dom.setStyle(e, 'width', ''); + if (v = dom.getStyle(e, 'width')) { + dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, '')); + dom.setStyle(e, 'width', ''); } - if (v = t.dom.getStyle(e, 'height')) { - t.dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, '')); - t.dom.setStyle(e, 'height', ''); + if (v = dom.getStyle(e, 'height')) { + dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, '')); + dom.setStyle(e, 'height', ''); } }); } else { ev = 'resizestart'; - cb = t.dom.bind(e, 'resizestart', Event.cancel, Event); + cb = dom.bind(e, 'resizestart', Event.cancel, Event); } re = t.resizeInfo = { @@ -10206,7 +10883,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; case 8: // Fix IE control + backspace browser bug if (t.selection.getRng().item) { - t.selection.getRng().item(0).removeNode(); + ed.dom.remove(t.selection.getRng().item(0)); return Event.cancel(e); } } @@ -10236,43 +10913,63 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; t.undoManager.add(); }; - // Add undo level on editor blur - if (tinymce.isIE) { - t.dom.bind(t.getWin(), 'blur', function(e) { - var n; + dom.bind(t.getDoc(), 'focusout', function(e) { + if (!t.removed && t.undoManager.typing) + addUndo(); + }); - // Check added for fullscreen bug - if (t.selection) { - n = t.selection.getNode(); + t.onKeyUp.add(function(ed, e) { + if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey) + addUndo(); + }); - // Add undo level is selection was lost to another document - if (!t.removed && n.ownerDocument && n.ownerDocument != t.getDoc()) - addUndo(); - } - }); - } else { - t.dom.bind(t.getDoc(), 'blur', function() { - if (t.selection && !t.removed) - addUndo(); - }); - } + t.onKeyDown.add(function(ed, e) { + var rng, parent, bookmark; + + // IE has a really odd bug where the DOM might include an node that doesn't have + // a proper structure. If you try to access nodeValue it would throw an illegal value exception. + // This seems to only happen when you delete contents and it seems to be avoidable if you refresh the element + // after you delete contents from it. See: #3008923 + if (isIE && e.keyCode == 46) { + rng = t.selection.getRng(); + + if (rng.parentElement) { + parent = rng.parentElement(); + + // Select next word when ctrl key is used in combo with delete + if (e.ctrlKey) { + rng.moveEnd('word', 1); + rng.select(); + } - t.onMouseDown.add(addUndo); + // Delete contents + t.selection.getSel().clear(); - t.onKeyUp.add(function(ed, e) { - if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey) { - t.undoManager.typing = 0; - t.undoManager.add(); + // Check if we are within the same parent + if (rng.parentElement() == parent) { + bookmark = t.selection.getBookmark(); + + try { + // Update the HTML and hopefully it will remove the artifacts + parent.innerHTML = parent.innerHTML; + } catch (ex) { + // And since it's IE it can sometimes produce an unknown runtime error + } + + // Restore the caret position + t.selection.moveToBookmark(bookmark); + } + + // Block the default delete behavior since it might be broken + e.preventDefault(); + return; + } } - }); - t.onKeyDown.add(function(ed, e) { // Is caracter positon keys if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45) { - if (t.undoManager.typing) { - t.undoManager.add(); - t.undoManager.typing = 0; - } + if (t.undoManager.typing) + addUndo(); return; } @@ -10282,165 +10979,42 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; t.undoManager.typing = 1; } }); + + t.onMouseDown.add(function() { + if (t.undoManager.typing) + addUndo(); + }); } }, - _convertInlineElements : function() { - var t = this, s = t.settings, dom = t.dom, v, e, na, st, sp; + _isHidden : function() { + var s; - function convert(ed, o) { - if (!s.inline_styles) - return; + if (!isGecko) + return 0; - if (o.get) { - each(t.dom.select('table,u,strike', o.node), function(n) { - switch (n.nodeName) { - case 'TABLE': - if (v = dom.getAttrib(n, 'height')) { - dom.setStyle(n, 'height', v); - dom.setAttrib(n, 'height', ''); - } - break; + // Weird, wheres that cursor selection? + s = this.selection.getSel(); + return (!s || !s.rangeCount || s.rangeCount == 0); + }, - case 'U': - case 'STRIKE': - //sp = dom.create('span', {style : dom.getAttrib(n, 'style')}); - n.style.textDecoration = n.nodeName == 'U' ? 'underline' : 'line-through'; - dom.setAttrib(n, 'mce_style', ''); - dom.setAttrib(n, 'mce_name', 'span'); - break; - } - }); - } else if (o.set) { - each(t.dom.select('table,span', o.node).reverse(), function(n) { - if (n.nodeName == 'TABLE') { - if (v = dom.getStyle(n, 'height')) - dom.setAttrib(n, 'height', v.replace(/[^0-9%]+/g, '')); - } else { - // Convert spans to elements - if (n.style.textDecoration == 'underline') - na = 'u'; - else if (n.style.textDecoration == 'line-through') - na = 'strike'; - else - na = ''; + // Fix for bug #1867292 + _fixNesting : function(s) { + var d = [], i; - if (na) { - n.style.textDecoration = ''; - dom.setAttrib(n, 'mce_style', ''); + s = s.replace(/<(\/)?([^\s>]+)[^>]*?>/g, function(a, b, c) { + var e; - e = dom.create(na, { - style : dom.getAttrib(n, 'style') - }); + // Handle end element + if (b === '/') { + if (!d.length) + return ''; - dom.replace(e, n, 1); - } - } - }); - } - }; - - t.onPreProcess.add(convert); - - if (!s.cleanup_on_startup) { - t.onSetContent.add(function(ed, o) { - if (o.initial) - convert(t, {node : t.getBody(), set : 1}); - }); - } - }, - - _convertFonts : function() { - var t = this, s = t.settings, dom = t.dom, fz, fzn, sl, cl; - - // No need - if (!s.inline_styles) - return; - - // Font pt values and font size names - fz = [8, 10, 12, 14, 18, 24, 36]; - fzn = ['xx-small', 'x-small','small','medium','large','x-large', 'xx-large']; - - if (sl = s.font_size_style_values) - sl = explode(sl); - - if (cl = s.font_size_classes) - cl = explode(cl); - - function process(no) { - var n, sp, nl, x; - - // Keep unit tests happy - if (!s.inline_styles) - return; - - nl = t.dom.select('font', no); - for (x = nl.length - 1; x >= 0; x--) { - n = nl[x]; - - sp = dom.create('span', { - style : dom.getAttrib(n, 'style'), - 'class' : dom.getAttrib(n, 'class') - }); - - dom.setStyles(sp, { - fontFamily : dom.getAttrib(n, 'face'), - color : dom.getAttrib(n, 'color'), - backgroundColor : n.style.backgroundColor - }); - - if (n.size) { - if (sl) - dom.setStyle(sp, 'fontSize', sl[parseInt(n.size) - 1]); - else - dom.setAttrib(sp, 'class', cl[parseInt(n.size) - 1]); - } - - dom.setAttrib(sp, 'mce_style', ''); - dom.replace(sp, n, 1); - } - }; - - // Run on cleanup - t.onPreProcess.add(function(ed, o) { - if (o.get) - process(o.node); - }); - - t.onSetContent.add(function(ed, o) { - if (o.initial) - process(o.node); - }); - }, - - _isHidden : function() { - var s; - - if (!isGecko) - return 0; - - // Weird, wheres that cursor selection? - s = this.selection.getSel(); - return (!s || !s.rangeCount || s.rangeCount == 0); - }, - - // Fix for bug #1867292 - _fixNesting : function(s) { - var d = [], i; - - s = s.replace(/<(\/)?([^\s>]+)[^>]*?>/g, function(a, b, c) { - var e; - - // Handle end element - if (b === '/') { - if (!d.length) - return ''; - - if (c !== d[d.length - 1].tag) { - for (i=d.length - 1; i>=0; i--) { - if (d[i].tag === c) { - d[i].close = 1; - break; + if (c !== d[d.length - 1].tag) { + for (i=d.length - 1; i>=0; i--) { + if (d[i].tag === c) { + d[i].close = 1; + break; } } @@ -10474,1082 +11048,591 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; return s; } - - }); + }); })(tinymce); + (function(tinymce) { - var each = tinymce.each, isIE = tinymce.isIE, isGecko = tinymce.isGecko, isOpera = tinymce.isOpera, isWebKit = tinymce.isWebKit; + // Added for compression purposes + var each = tinymce.each, undefined, TRUE = true, FALSE = false; - tinymce.create('tinymce.EditorCommands', { - EditorCommands : function(ed) { - this.editor = ed; - }, + tinymce.EditorCommands = function(editor) { + var dom = editor.dom, + selection = editor.selection, + commands = {state: {}, exec : {}, value : {}}, + settings = editor.settings, + bookmark; - execCommand : function(cmd, ui, val) { - var t = this, ed = t.editor, f; + function execCommand(command, ui, value) { + var func; - switch (cmd) { - // Ignore these - case 'mceResetDesignMode': - case 'mceBeginUndoLevel': - return true; + command = command.toLowerCase(); + if (func = commands.exec[command]) { + func(command, ui, value); + return TRUE; + } - // Ignore these - case 'unlink': - t.UnLink(); - return true; + return FALSE; + }; - // Bundle these together - case 'JustifyLeft': - case 'JustifyCenter': - case 'JustifyRight': - case 'JustifyFull': - t.mceJustify(cmd, cmd.substring(7).toLowerCase()); - return true; + function queryCommandState(command) { + var func; - default: - f = this[cmd]; + command = command.toLowerCase(); + if (func = commands.state[command]) + return func(command); - if (f) { - f.call(this, ui, val); - return true; - } - } + return -1; + }; - return false; - }, + function queryCommandValue(command) { + var func; + + command = command.toLowerCase(); + if (func = commands.value[command]) + return func(command); - Indent : function() { - var ed = this.editor, d = ed.dom, s = ed.selection, e, iv, iu; + return FALSE; + }; - // Setup indent level - iv = ed.settings.indentation; - iu = /[a-z%]+$/i.exec(iv); - iv = parseInt(iv); + function addCommands(command_list, type) { + type = type || 'exec'; - if (ed.settings.inline_styles && (!this.queryStateInsertUnorderedList() && !this.queryStateInsertOrderedList())) { - each(s.getSelectedBlocks(), function(e) { - d.setStyle(e, 'paddingLeft', (parseInt(e.style.paddingLeft || 0) + iv) + iu); + each(command_list, function(callback, command) { + each(command.toLowerCase().split(','), function(command) { + commands[type][command] = callback; }); + }); + }; - return; - } + // Expose public methods + tinymce.extend(this, { + execCommand : execCommand, + queryCommandState : queryCommandState, + queryCommandValue : queryCommandValue, + addCommands : addCommands + }); - ed.getDoc().execCommand('Indent', false, null); + // Private methods - if (isIE) { - d.getParent(s.getNode(), function(n) { - if (n.nodeName == 'BLOCKQUOTE') { - n.dir = n.style.cssText = ''; - } - }); - } - }, + function execNativeCommand(command, ui, value) { + if (ui === undefined) + ui = FALSE; - Outdent : function() { - var ed = this.editor, d = ed.dom, s = ed.selection, e, v, iv, iu; + if (value === undefined) + value = null; - // Setup indent level - iv = ed.settings.indentation; - iu = /[a-z%]+$/i.exec(iv); - iv = parseInt(iv); + return editor.getDoc().execCommand(command, ui, value); + }; - if (ed.settings.inline_styles && (!this.queryStateInsertUnorderedList() && !this.queryStateInsertOrderedList())) { - each(s.getSelectedBlocks(), function(e) { - v = Math.max(0, parseInt(e.style.paddingLeft || 0) - iv); - d.setStyle(e, 'paddingLeft', v ? v + iu : ''); - }); + function isFormatMatch(name) { + return editor.formatter.match(name); + }; - return; - } + function toggleFormat(name, value) { + editor.formatter.toggle(name, value ? {value : value} : undefined); + }; - ed.getDoc().execCommand('Outdent', false, null); - }, + function storeSelection(type) { + bookmark = selection.getBookmark(type); + }; -/* - mceSetAttribute : function(u, v) { - var ed = this.editor, d = ed.dom, e; + function restoreSelection() { + selection.moveToBookmark(bookmark); + }; - if (e = d.getParent(ed.selection.getNode(), d.isBlock)) - d.setAttrib(e, v.name, v.value); - }, -*/ - mceSetContent : function(u, v) { - this.editor.setContent(v); - }, + // Add execCommand overrides + addCommands({ + // Ignore these, added for compatibility + 'mceResetDesignMode,mceBeginUndoLevel' : function() {}, - mceToggleVisualAid : function() { - var ed = this.editor; + // Add undo manager logic + 'mceEndUndoLevel,mceAddUndoLevel' : function() { + editor.undoManager.add(); + }, - ed.hasVisual = !ed.hasVisual; - ed.addVisual(); - }, + 'Cut,Copy,Paste' : function(command) { + var doc = editor.getDoc(), failed; - mceReplaceContent : function(u, v) { - var s = this.editor.selection; + // Try executing the native command + try { + execNativeCommand(command); + } catch (ex) { + // Command failed + failed = TRUE; + } - s.setContent(v.replace(/\{\$selection\}/g, s.getContent({format : 'text'}))); - }, + // Present alert message about clipboard access not being available + if (failed || !doc.queryCommandSupported(command)) { + if (tinymce.isGecko) { + editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) { + if (state) + open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank'); + }); + } else + editor.windowManager.alert(editor.getLang('clipboard_no_support')); + } + }, - mceInsertLink : function(u, v) { - var ed = this.editor, s = ed.selection, e = ed.dom.getParent(s.getNode(), 'a'); + // Override unlink command + unlink : function(command) { + if (selection.isCollapsed()) + selection.select(selection.getNode()); - if (tinymce.is(v, 'string')) - v = {href : v}; + execNativeCommand(command); + selection.collapse(FALSE); + }, - function set(e) { - each(v, function(v, k) { - ed.dom.setAttrib(e, k, v); - }); - }; + // Override justify commands to use the text formatter engine + 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { + var align = command.substring(7); - if (!e) { - ed.execCommand('CreateLink', false, 'javascript:mctmp(0);'); - each(ed.dom.select('a[href=javascript:mctmp(0);]'), function(e) { - set(e); + // Remove all other alignments first + each('left,center,right,full'.split(','), function(name) { + if (align != name) + editor.formatter.remove('align' + name); }); - } else { - if (v.href) - set(e); - else - ed.dom.remove(e, 1); - } - }, - UnLink : function() { - var ed = this.editor, s = ed.selection; + toggleFormat('align' + align); + }, - if (s.isCollapsed()) - s.select(s.getNode()); + // Override list commands to fix WebKit bug + 'InsertUnorderedList,InsertOrderedList' : function(command) { + var listElm, listParent; - ed.getDoc().execCommand('unlink', false, null); - s.collapse(0); - }, + execNativeCommand(command); - FontName : function(u, v) { - var t = this, ed = t.editor, s = ed.selection, e; + // WebKit produces lists within block elements so we need to split them + // we will replace the native list creation logic to custom logic later on + // TODO: Remove this when the list creation logic is removed + listElm = dom.getParent(selection.getNode(), 'ol,ul'); + if (listElm) { + listParent = listElm.parentNode; - if (!v) { - if (s.isCollapsed()) - s.select(s.getNode()); - } else { - if (ed.settings.convert_fonts_to_spans) - t._applyInlineStyle('span', {style : {fontFamily : v}}); - else - ed.getDoc().execCommand('FontName', false, v); - } - }, + // If list is within a text block then split that block + if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) { + storeSelection(); + dom.split(listParent, listElm); + restoreSelection(); + } + } + }, - FontSize : function(u, v) { - var ed = this.editor, s = ed.settings, fc, fs; + // Override commands to use the text formatter engine + 'Bold,Italic,Underline,Strikethrough' : function(command) { + toggleFormat(command); + }, - // Use style options instead - if (s.convert_fonts_to_spans && v >= 1 && v <= 7) { - fs = tinymce.explode(s.font_size_style_values); - fc = tinymce.explode(s.font_size_classes); + // Override commands to use the text formatter engine + 'ForeColor,HiliteColor,FontName' : function(command, ui, value) { + toggleFormat(command, value); + }, - if (fc) - v = fc[v - 1] || v; - else - v = fs[v - 1] || v; - } + FontSize : function(command, ui, value) { + var fontClasses, fontSizes; - if (v >= 1 && v <= 7) - ed.getDoc().execCommand('FontSize', false, v); - else - this._applyInlineStyle('span', {style : {fontSize : v}}); - }, + // Convert font size 1-7 to styles + if (value >= 1 && value <= 7) { + fontSizes = tinymce.explode(settings.font_size_style_values); + fontClasses = tinymce.explode(settings.font_size_classes); - queryCommandValue : function(c) { - var f = this['queryValue' + c]; + if (fontClasses) + value = fontClasses[value - 1] || value; + else + value = fontSizes[value - 1] || value; + } - if (f) - return f.call(this, c); + toggleFormat(command, value); + }, - return false; - }, + RemoveFormat : function(command) { + editor.formatter.remove(command); + }, - queryCommandState : function(cmd) { - var f; + mceBlockQuote : function(command) { + toggleFormat('blockquote'); + }, - switch (cmd) { - // Bundle these together - case 'JustifyLeft': - case 'JustifyCenter': - case 'JustifyRight': - case 'JustifyFull': - return this.queryStateJustify(cmd, cmd.substring(7).toLowerCase()); + FormatBlock : function(command, ui, value) { + return toggleFormat(value || 'p'); + }, - default: - if (f = this['queryState' + cmd]) - return f.call(this, cmd); - } + mceCleanup : function() { + var bookmark = selection.getBookmark(); - return -1; - }, + editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE}); - _queryState : function(c) { - try { - return this.editor.getDoc().queryCommandState(c); - } catch (ex) { - // Ignore exception - } - }, + selection.moveToBookmark(bookmark); + }, - _queryVal : function(c) { - try { - return this.editor.getDoc().queryCommandValue(c); - } catch (ex) { - // Ignore exception - } - }, + mceRemoveNode : function(command, ui, value) { + var node = value || selection.getNode(); - queryValueFontSize : function() { - var ed = this.editor, v = 0, p; + // Make sure that the body node isn't removed + if (node != editor.getBody()) { + storeSelection(); + editor.dom.remove(node, TRUE); + restoreSelection(); + } + }, - if (p = ed.dom.getParent(ed.selection.getNode(), 'span')) - v = p.style.fontSize; + mceSelectNodeDepth : function(command, ui, value) { + var counter = 0; - if (!v && (isOpera || isWebKit)) { - if (p = ed.dom.getParent(ed.selection.getNode(), 'font')) - v = p.size; + dom.getParent(selection.getNode(), function(node) { + if (node.nodeType == 1 && counter++ == value) { + selection.select(node); + return FALSE; + } + }, editor.getBody()); + }, - return v; - } + mceSelectNode : function(command, ui, value) { + selection.select(value); + }, - return v || this._queryVal('FontSize'); - }, + mceInsertContent : function(command, ui, value) { + selection.setContent(value); + }, - queryValueFontName : function() { - var ed = this.editor, v = 0, p; + mceInsertRawHTML : function(command, ui, value) { + selection.setContent('tiny_mce_marker'); + editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value })); + }, - if (p = ed.dom.getParent(ed.selection.getNode(), 'font')) - v = p.face; + mceSetContent : function(command, ui, value) { + editor.setContent(value); + }, - if (p = ed.dom.getParent(ed.selection.getNode(), 'span')) - v = p.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase(); + 'Indent,Outdent' : function(command) { + var intentValue, indentUnit, value; - if (!v) - v = this._queryVal('FontName'); + // Setup indent level + intentValue = settings.indentation; + indentUnit = /[a-z%]+$/i.exec(intentValue); + intentValue = parseInt(intentValue); - return v; - }, + if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) { + each(selection.getSelectedBlocks(), function(element) { + if (command == 'outdent') { + value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue); + dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : ''); + } else + dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit); + }); + } else + execNativeCommand(command); + }, - mceJustify : function(c, v) { - var ed = this.editor, se = ed.selection, n = se.getNode(), nn = n.nodeName, bl, nb, dom = ed.dom, rm; + mceRepaint : function() { + var bookmark; - if (ed.settings.inline_styles && this.queryStateJustify(c, v)) - rm = 1; + if (tinymce.isGecko) { + try { + storeSelection(TRUE); - bl = dom.getParent(n, ed.dom.isBlock); + if (selection.getSel()) + selection.getSel().selectAllChildren(editor.getBody()); - if (nn == 'IMG') { - if (v == 'full') - return; + selection.collapse(TRUE); + restoreSelection(); + } catch (ex) { + // Ignore + } + } + }, - if (rm) { - if (v == 'center') - dom.setStyle(bl || n.parentNode, 'textAlign', ''); + mceToggleFormat : function(command, ui, value) { + editor.formatter.toggle(value); + }, - dom.setStyle(n, 'float', ''); - this.mceRepaint(); - return; - } + InsertHorizontalRule : function() { + selection.setContent('<hr />'); + }, - if (v == 'center') { - // Do not change table elements - if (bl && /^(TD|TH)$/.test(bl.nodeName)) - bl = 0; + mceToggleVisualAid : function() { + editor.hasVisual = !editor.hasVisual; + editor.addVisual(); + }, - if (!bl || bl.childNodes.length > 1) { - nb = dom.create('p'); - nb.appendChild(n.cloneNode(false)); + mceReplaceContent : function(command, ui, value) { + selection.setContent(value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'}))); + }, - if (bl) - dom.insertAfter(nb, bl); - else - dom.insertAfter(nb, n); + mceInsertLink : function(command, ui, value) { + var link = dom.getParent(selection.getNode(), 'a'); - dom.remove(n); - n = nb.firstChild; - bl = nb; - } + if (tinymce.is(value, 'string')) + value = {href : value}; - dom.setStyle(bl, 'textAlign', v); - dom.setStyle(n, 'float', ''); + if (!link) { + execNativeCommand('CreateLink', FALSE, 'javascript:mctmp(0);'); + each(dom.select('a[href=javascript:mctmp(0);]'), function(link) { + dom.setAttribs(link, value); + }); } else { - dom.setStyle(n, 'float', v); - dom.setStyle(bl || n.parentNode, 'textAlign', ''); + if (value.href) + dom.setAttribs(link, value); + else + editor.dom.remove(link, TRUE); } + }, + + selectAll : function() { + var root = dom.getRoot(), rng = dom.createRng(); - this.mceRepaint(); - return; + rng.setStart(root, 0); + rng.setEnd(root, root.childNodes.length); + + editor.selection.setRng(rng); } + }); - // Handle the alignment outselfs, less quirks in all browsers - if (ed.settings.inline_styles && ed.settings.forced_root_block) { - if (rm) - v = ''; + // Add queryCommandState overrides + addCommands({ + // Override justify commands + 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { + return isFormatMatch('align' + command.substring(7)); + }, - each(se.getSelectedBlocks(dom.getParent(se.getStart(), dom.isBlock), dom.getParent(se.getEnd(), dom.isBlock)), function(e) { - dom.setAttrib(e, 'align', ''); - dom.setStyle(e, 'textAlign', v == 'full' ? 'justify' : v); - }); + 'Bold,Italic,Underline,Strikethrough' : function(command) { + return isFormatMatch(command); + }, - return; - } else if (!rm) - ed.getDoc().execCommand(c, false, null); - - if (ed.settings.inline_styles) { - if (rm) { - dom.getParent(ed.selection.getNode(), function(n) { - if (n.style && n.style.textAlign) - dom.setStyle(n, 'textAlign', ''); - }); + mceBlockQuote : function() { + return isFormatMatch('blockquote'); + }, - return; + Outdent : function() { + var node; + + if (settings.inline_styles) { + if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0) + return TRUE; + + if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0) + return TRUE; } - each(dom.select('*'), function(n) { - var v = n.align; + return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE')); + }, + + 'InsertUnorderedList,InsertOrderedList' : function(command) { + return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL'); + } + }, 'state'); - if (v) { - if (v == 'full') - v = 'justify'; + // Add queryCommandValue overrides + addCommands({ + 'FontSize,FontName' : function(command) { + var value = 0, parent; - dom.setStyle(n, 'textAlign', v); - dom.setAttrib(n, 'align', ''); - } - }); + if (parent = dom.getParent(selection.getNode(), 'span')) { + if (command == 'fontsize') + value = parent.style.fontSize; + else + value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase(); + } + + return value; } - }, + }, 'value'); - mceSetCSSClass : function(u, v) { - this.mceSetStyleInfo(0, {command : 'setattrib', name : 'class', value : v}); - }, + // Add undo manager logic + if (settings.custom_undo_redo) { + addCommands({ + Undo : function() { + editor.undoManager.undo(); + }, - getSelectedElement : function() { - var t = this, ed = t.editor, dom = ed.dom, se = ed.selection, r = se.getRng(), r1, r2, sc, ec, so, eo, e, sp, ep, re; + Redo : function() { + editor.undoManager.redo(); + } + }); + } + }; +})(tinymce); +(function(tinymce) { + var Dispatcher = tinymce.util.Dispatcher; - if (se.isCollapsed() || r.item) - return se.getNode(); + tinymce.UndoManager = function(editor) { + var self, index = 0, data = []; - // Setup regexp - re = ed.settings.merge_styles_invalid_parents; - if (tinymce.is(re, 'string')) - re = new RegExp(re, 'i'); + function getContent() { + return tinymce.trim(editor.getContent({format : 'raw', no_events : 1})); + }; - if (isIE) { - r1 = r.duplicate(); - r1.collapse(true); - sc = r1.parentElement(); + return self = { + typing : 0, - r2 = r.duplicate(); - r2.collapse(false); - ec = r2.parentElement(); + onAdd : new Dispatcher(self), + onUndo : new Dispatcher(self), + onRedo : new Dispatcher(self), - if (sc != ec) { - r1.move('character', 1); - sc = r1.parentElement(); - } + add : function(level) { + var i, settings = editor.settings, lastLevel; - if (sc == ec) { - r1 = r.duplicate(); - r1.moveToElementText(sc); + level = level || {}; + level.content = getContent(); - if (r1.compareEndPoints('StartToStart', r) == 0 && r1.compareEndPoints('EndToEnd', r) == 0) - return re && re.test(sc.nodeName) ? null : sc; + // Add undo level if needed + lastLevel = data[index]; + if (lastLevel && lastLevel.content == level.content) { + if (index > 0 || data.length == 1) + return null; } - } else { - function getParent(n) { - return dom.getParent(n, '*'); - }; - sc = r.startContainer; - ec = r.endContainer; - so = r.startOffset; - eo = r.endOffset; + // Time to compress + if (settings.custom_undo_redo_levels) { + if (data.length > settings.custom_undo_redo_levels) { + for (i = 0; i < data.length - 1; i++) + data[i] = data[i + 1]; - if (!r.collapsed) { - if (sc == ec) { - if (so - eo < 2) { - if (sc.hasChildNodes()) { - sp = sc.childNodes[so]; - return re && re.test(sp.nodeName) ? null : sp; - } - } + data.length--; + index = data.length; } } - if (sc.nodeType != 3 || ec.nodeType != 3) - return null; - - if (so == 0) { - sp = getParent(sc); + // Get a non intrusive normalized bookmark + level.bookmark = editor.selection.getBookmark(2, true); - if (sp && sp.firstChild != sc) - sp = null; + // Crop array if needed + if (index < data.length - 1) { + // Treat first level as initial + if (index == 0) + data = []; + else + data.length = index + 1; } - if (so == sc.nodeValue.length) { - e = sc.nextSibling; + data.push(level); + index = data.length - 1; - if (e && e.nodeType == 1) - sp = sc.nextSibling; - } + self.onAdd.dispatch(self, level); + editor.isNotDirty = 0; - if (eo == 0) { - e = ec.previousSibling; + return level; + }, + + undo : function() { + var level, i; - if (e && e.nodeType == 1) - ep = e; + if (self.typing) { + self.add(); + self.typing = 0; } - if (eo == ec.nodeValue.length) { - ep = getParent(ec); + if (index > 0) { + level = data[--index]; - if (ep && ep.lastChild != ec) - ep = null; - } + editor.setContent(level.content, {format : 'raw'}); + editor.selection.moveToBookmark(level.bookmark); - // Same element - if (sp == ep) - return re && sp && re.test(sp.nodeName) ? null : sp; - } + self.onUndo.dispatch(self, level); + } - return null; - }, + return level; + }, - mceSetStyleInfo : function(u, v) { - var t = this, ed = t.editor, d = ed.getDoc(), dom = ed.dom, e, b, s = ed.selection, nn = v.wrapper || 'span', b = s.getBookmark(), re; + redo : function() { + var level; - function set(n, e) { - if (n.nodeType == 1) { - switch (v.command) { - case 'setattrib': - return dom.setAttrib(n, v.name, v.value); + if (index < data.length - 1) { + level = data[++index]; - case 'setstyle': - return dom.setStyle(n, v.name, v.value); + editor.setContent(level.content, {format : 'raw'}); + editor.selection.moveToBookmark(level.bookmark); - case 'removeformat': - return dom.setAttrib(n, 'class', ''); - } + self.onRedo.dispatch(self, level); } - }; - // Setup regexp - re = ed.settings.merge_styles_invalid_parents; - if (tinymce.is(re, 'string')) - re = new RegExp(re, 'i'); - - // Set style info on selected element - if ((e = t.getSelectedElement()) && !ed.settings.force_span_wrappers) - set(e, 1); - else { - // Generate wrappers and set styles on them - d.execCommand('FontName', false, '__'); - each(dom.select('span,font'), function(n) { - var sp, e; + return level; + }, - if (dom.getAttrib(n, 'face') == '__' || n.style.fontFamily === '__') { - sp = dom.create(nn, {mce_new : '1'}); + clear : function() { + data = []; + index = self.typing = 0; + }, - set(sp); + hasUndo : function() { + return index > 0 || self.typing; + }, - each (n.childNodes, function(n) { - sp.appendChild(n.cloneNode(true)); - }); - - dom.replace(sp, n); - } - }); - } - - // Remove wrappers inside new ones - each(dom.select(nn).reverse(), function(n) { - var p = n.parentNode; - - // Check if it's an old span in a new wrapper - if (!dom.getAttrib(n, 'mce_new')) { - // Find new wrapper - p = dom.getParent(n, '*[mce_new]'); - - if (p) - dom.remove(n, 1); - } - }); - - // Merge wrappers with parent wrappers - each(dom.select(nn).reverse(), function(n) { - var p = n.parentNode; - - if (!p || !dom.getAttrib(n, 'mce_new')) - return; - - if (ed.settings.force_span_wrappers && p.nodeName != 'SPAN') - return; - - // Has parent of the same type and only child - if (p.nodeName == nn.toUpperCase() && p.childNodes.length == 1) - return dom.remove(p, 1); - - // Has parent that is more suitable to have the class and only child - if (n.nodeType == 1 && (!re || !re.test(p.nodeName)) && p.childNodes.length == 1) { - set(p); // Set style info on parent instead - dom.setAttrib(n, 'class', ''); - } - }); - - // Remove empty wrappers - each(dom.select(nn).reverse(), function(n) { - if (dom.getAttrib(n, 'mce_new') || (dom.getAttribs(n).length <= 1 && n.className === '')) { - if (!dom.getAttrib(n, 'class') && !dom.getAttrib(n, 'style')) - return dom.remove(n, 1); - - dom.setAttrib(n, 'mce_new', ''); // Remove mce_new marker - } - }); - - s.moveToBookmark(b); - }, - - queryStateJustify : function(c, v) { - var ed = this.editor, n = ed.selection.getNode(), dom = ed.dom; - - if (n && n.nodeName == 'IMG') { - if (dom.getStyle(n, 'float') == v) - return 1; - - return n.parentNode.style.textAlign == v; - } - - n = dom.getParent(ed.selection.getStart(), function(n) { - return n.nodeType == 1 && n.style.textAlign; - }); - - if (v == 'full') - v = 'justify'; - - if (ed.settings.inline_styles) - return (n && n.style.textAlign == v); - - return this._queryState(c); - }, - - ForeColor : function(ui, v) { - var ed = this.editor; - - if (ed.settings.convert_fonts_to_spans) { - this._applyInlineStyle('span', {style : {color : v}}); - return; - } else - ed.getDoc().execCommand('ForeColor', false, v); - }, - - HiliteColor : function(ui, val) { - var t = this, ed = t.editor, d = ed.getDoc(); - - if (ed.settings.convert_fonts_to_spans) { - this._applyInlineStyle('span', {style : {backgroundColor : val}}); - return; - } - - function set(s) { - if (!isGecko) - return; - - try { - // Try new Gecko method - d.execCommand("styleWithCSS", 0, s); - } catch (ex) { - // Use old - d.execCommand("useCSS", 0, !s); - } - }; - - if (isGecko || isOpera) { - set(true); - d.execCommand('hilitecolor', false, val); - set(false); - } else - d.execCommand('BackColor', false, val); - }, - - FormatBlock : function(ui, val) { - var t = this, ed = t.editor, s = ed.selection, dom = ed.dom, bl, nb, b; - - function isBlock(n) { - return /^(P|DIV|H[1-6]|ADDRESS|BLOCKQUOTE|PRE)$/.test(n.nodeName); - }; - - bl = dom.getParent(s.getNode(), function(n) { - return isBlock(n); - }); - - // IE has an issue where it removes the parent div if you change format on the paragrah in <div><p>Content</p></div> - // FF and Opera doesn't change parent DIV elements if you switch format - if (bl) { - if ((isIE && isBlock(bl.parentNode)) || bl.nodeName == 'DIV') { - // Rename block element - nb = ed.dom.create(val); - - each(dom.getAttribs(bl), function(v) { - dom.setAttrib(nb, v.nodeName, dom.getAttrib(bl, v.nodeName)); - }); - - b = s.getBookmark(); - dom.replace(nb, bl, 1); - s.moveToBookmark(b); - ed.nodeChanged(); - return; - } - } - - val = ed.settings.forced_root_block ? (val || '<p>') : val; - - if (val.indexOf('<') == -1) - val = '<' + val + '>'; - - if (tinymce.isGecko) - val = val.replace(/<(div|blockquote|code|dt|dd|dl|samp)>/gi, '$1'); - - ed.getDoc().execCommand('FormatBlock', false, val); - }, - - mceCleanup : function() { - var ed = this.editor, s = ed.selection, b = s.getBookmark(); - ed.setContent(ed.getContent()); - s.moveToBookmark(b); - }, - - mceRemoveNode : function(ui, val) { - var ed = this.editor, s = ed.selection, b, n = val || s.getNode(); - - // Make sure that the body node isn't removed - if (n == ed.getBody()) - return; - - b = s.getBookmark(); - ed.dom.remove(n, 1); - s.moveToBookmark(b); - ed.nodeChanged(); - }, - - mceSelectNodeDepth : function(ui, val) { - var ed = this.editor, s = ed.selection, c = 0; - - ed.dom.getParent(s.getNode(), function(n) { - if (n.nodeType == 1 && c++ == val) { - s.select(n); - ed.nodeChanged(); - return false; - } - }, ed.getBody()); - }, - - mceSelectNode : function(u, v) { - this.editor.selection.select(v); - }, - - mceInsertContent : function(ui, val) { - this.editor.selection.setContent(val); - }, - - mceInsertRawHTML : function(ui, val) { - var ed = this.editor; - - ed.selection.setContent('tiny_mce_marker'); - ed.setContent(ed.getContent().replace(/tiny_mce_marker/g, val)); - }, - - mceRepaint : function() { - var s, b, e = this.editor; - - if (tinymce.isGecko) { - try { - s = e.selection; - b = s.getBookmark(true); - - if (s.getSel()) - s.getSel().selectAllChildren(e.getBody()); - - s.collapse(true); - s.moveToBookmark(b); - } catch (ex) { - // Ignore - } - } - }, - - queryStateUnderline : function() { - var ed = this.editor, n = ed.selection.getNode(); - - if (n && n.nodeName == 'A') - return false; - - return this._queryState('Underline'); - }, - - queryStateOutdent : function() { - var ed = this.editor, n; - - if (ed.settings.inline_styles) { - if ((n = ed.dom.getParent(ed.selection.getStart(), ed.dom.isBlock)) && parseInt(n.style.paddingLeft) > 0) - return true; - - if ((n = ed.dom.getParent(ed.selection.getEnd(), ed.dom.isBlock)) && parseInt(n.style.paddingLeft) > 0) - return true; - } - - return this.queryStateInsertUnorderedList() || this.queryStateInsertOrderedList() || (!ed.settings.inline_styles && !!ed.dom.getParent(ed.selection.getNode(), 'BLOCKQUOTE')); - }, - - queryStateInsertUnorderedList : function() { - return this.editor.dom.getParent(this.editor.selection.getNode(), 'UL'); - }, - - queryStateInsertOrderedList : function() { - return this.editor.dom.getParent(this.editor.selection.getNode(), 'OL'); - }, - - queryStatemceBlockQuote : function() { - return !!this.editor.dom.getParent(this.editor.selection.getStart(), function(n) {return n.nodeName === 'BLOCKQUOTE';}); - }, - - _applyInlineStyle : function(na, at, op) { - var t = this, ed = t.editor, dom = ed.dom, bm, lo = {}, kh, found; - - na = na.toUpperCase(); - - if (op && op.check_classes && at['class']) - op.check_classes.push(at['class']); - - function removeEmpty() { - each(dom.select(na).reverse(), function(n) { - var c = 0; - - // Check if there is any attributes - each(dom.getAttribs(n), function(an) { - if (an.nodeName.substring(0, 1) != '_' && dom.getAttrib(n, an.nodeName) != '') { - //console.log(dom.getOuterHTML(n), dom.getAttrib(n, an.nodeName)); - c++; - } - }); - - // No attributes then remove the element and keep the children - if (c == 0) - dom.remove(n, 1); - }); - }; - - function replaceFonts() { - var bm; - - each(dom.select('span,font'), function(n) { - if (n.style.fontFamily == 'mceinline' || n.face == 'mceinline') { - if (!bm) - bm = ed.selection.getBookmark(); - - at._mce_new = '1'; - dom.replace(dom.create(na, at), n, 1); - } - }); - - // Remove redundant elements - each(dom.select(na + '[_mce_new]'), function(n) { - function removeStyle(n) { - if (n.nodeType == 1) { - each(at.style, function(v, k) { - dom.setStyle(n, k, ''); - }); - - // Remove spans with the same class or marked classes - if (at['class'] && n.className && op) { - each(op.check_classes, function(c) { - if (dom.hasClass(n, c)) - dom.removeClass(n, c); - }); - } - } - }; - - // Remove specified style information from child elements - each(dom.select(na, n), removeStyle); - - // Remove the specified style information on parent if current node is only child (IE) - if (n.parentNode && n.parentNode.nodeType == 1 && n.parentNode.childNodes.length == 1) - removeStyle(n.parentNode); - - // Remove the child elements style info if a parent already has it - dom.getParent(n.parentNode, function(pn) { - if (pn.nodeType == 1) { - if (at.style) { - each(at.style, function(v, k) { - var sv; - - if (!lo[k] && (sv = dom.getStyle(pn, k))) { - if (sv === v) - dom.setStyle(n, k, ''); - - lo[k] = 1; - } - }); - } - - // Remove spans with the same class or marked classes - if (at['class'] && pn.className && op) { - each(op.check_classes, function(c) { - if (dom.hasClass(pn, c)) - dom.removeClass(n, c); - }); - } - } - - return false; - }); - - n.removeAttribute('_mce_new'); - }); - - removeEmpty(); - ed.selection.moveToBookmark(bm); - - return !!bm; - }; - - // Create inline elements - ed.focus(); - ed.getDoc().execCommand('FontName', false, 'mceinline'); - replaceFonts(); - - if (kh = t._applyInlineStyle.keyhandler) { - ed.onKeyUp.remove(kh); - ed.onKeyPress.remove(kh); - ed.onKeyDown.remove(kh); - ed.onSetContent.remove(t._applyInlineStyle.chandler); + hasRedo : function() { + return index < data.length - 1; } + }; + }; +})(tinymce); - if (ed.selection.isCollapsed()) { - // IE will format the current word so this code can't be executed on that browser - if (!isIE) { - each(dom.getParents(ed.selection.getNode(), 'span'), function(n) { - each(at.style, function(v, k) { - var kv; - - if (kv = dom.getStyle(n, k)) { - if (kv == v) { - dom.setStyle(n, k, ''); - found = 2; - return false; - } - - found = 1; - return false; - } - }); - - if (found) - return false; - }); - - if (found == 2) { - bm = ed.selection.getBookmark(); - - removeEmpty(); - - ed.selection.moveToBookmark(bm); - - // Node change needs to be detached since the onselect event - // for the select box will run the onclick handler after onselect call. Todo: Add a nicer fix! - window.setTimeout(function() { - ed.nodeChanged(); - }, 1); - - return; - } +(function(tinymce) { + // Shorten names + var Event = tinymce.dom.Event, + isIE = tinymce.isIE, + isGecko = tinymce.isGecko, + isOpera = tinymce.isOpera, + each = tinymce.each, + extend = tinymce.extend, + TRUE = true, + FALSE = false; + + function cloneFormats(node) { + var clone, temp, inner; + + do { + if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) { + if (clone) { + temp = node.cloneNode(false); + temp.appendChild(clone); + clone = temp; + } else { + clone = inner = node.cloneNode(false); } - // Start collecting styles - t._pendingStyles = tinymce.extend(t._pendingStyles || {}, at.style); - - t._applyInlineStyle.chandler = ed.onSetContent.add(function() { - delete t._pendingStyles; - }); - - t._applyInlineStyle.keyhandler = kh = function(e) { - // Use pending styles - if (t._pendingStyles) { - at.style = t._pendingStyles; - delete t._pendingStyles; - } - - if (replaceFonts()) { - ed.onKeyDown.remove(t._applyInlineStyle.keyhandler); - ed.onKeyPress.remove(t._applyInlineStyle.keyhandler); - } - - if (e.type == 'keyup') - ed.onKeyUp.remove(t._applyInlineStyle.keyhandler); - }; - - ed.onKeyDown.add(kh); - ed.onKeyPress.add(kh); - ed.onKeyUp.add(kh); - } else - t._pendingStyles = 0; - } - }); -})(tinymce);(function(tinymce) { - tinymce.create('tinymce.UndoManager', { - index : 0, - data : null, - typing : 0, - - UndoManager : function(ed) { - var t = this, Dispatcher = tinymce.util.Dispatcher; - - t.editor = ed; - t.data = []; - t.onAdd = new Dispatcher(this); - t.onUndo = new Dispatcher(this); - t.onRedo = new Dispatcher(this); - }, - - add : function(l) { - var t = this, i, ed = t.editor, b, s = ed.settings, la; - - l = l || {}; - l.content = l.content || ed.getContent({format : 'raw', no_events : 1}); - - // Add undo level if needed - l.content = l.content.replace(/^\s*|\s*$/g, ''); - la = t.data[t.index > 0 && (t.index == 0 || t.index == t.data.length) ? t.index - 1 : t.index]; - if (!l.initial && la && l.content == la.content) - return null; - - // Time to compress - if (s.custom_undo_redo_levels) { - if (t.data.length > s.custom_undo_redo_levels) { - for (i = 0; i < t.data.length - 1; i++) - t.data[i] = t.data[i + 1]; - - t.data.length--; - t.index = t.data.length; - } + clone.removeAttribute('id'); } + } while (node = node.parentNode); - if (s.custom_undo_redo_restore_selection && !l.initial) - l.bookmark = b = l.bookmark || ed.selection.getBookmark(); - - if (t.index < t.data.length) - t.index++; - - // Only initial marked undo levels should be allowed as first item - // This to workaround a bug with Firefox and the blur event - if (t.data.length === 0 && !l.initial) - return null; - - // Add level - t.data.length = t.index + 1; - t.data[t.index++] = l; - - if (l.initial) - t.index = 0; - - // Set initial bookmark use first real undo level - if (t.data.length == 2 && t.data[0].initial) - t.data[0].bookmark = b; - - t.onAdd.dispatch(t, l); - ed.isNotDirty = 0; - - //console.dir(t.data); - - return l; - }, - - undo : function() { - var t = this, ed = t.editor, l = l, i; - - if (t.typing) { - t.add(); - t.typing = 0; - } + if (clone) + return {wrapper : clone, inner : inner}; + }; - if (t.index > 0) { - // If undo on last index then take snapshot - if (t.index == t.data.length && t.index > 1) { - i = t.index; - t.typing = 0; + // Checks if the selection/caret is at the end of the specified block element + function isAtEnd(rng, par) { + var rng2 = par.ownerDocument.createRange(); - if (!t.add()) - t.index = i; + rng2.setStart(rng.endContainer, rng.endOffset); + rng2.setEndAfter(par); - --t.index; - } + // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element + return rng2.cloneContents().textContent.length == 0; + }; - l = t.data[--t.index]; - ed.setContent(l.content, {format : 'raw'}); - ed.selection.moveToBookmark(l.bookmark); + function isEmpty(n) { + n = n.innerHTML; - t.onUndo.dispatch(t, l); - } + n = n.replace(/<(img|hr|table|input|select|textarea)[ \>]/gi, '-'); // Keep these convert them to - chars + n = n.replace(/<[^>]+>/g, ''); // Remove all tags - return l; - }, + return n.replace(/[ \u00a0\t\r\n]+/g, '') == ''; + }; - redo : function() { - var t = this, ed = t.editor, l = null; + function splitList(selection, dom, li) { + var listBlock, block; - if (t.index < t.data.length - 1) { - l = t.data[++t.index]; - ed.setContent(l.content, {format : 'raw'}); - ed.selection.moveToBookmark(l.bookmark); + if (isEmpty(li)) { + listBlock = dom.getParent(li, 'ul,ol'); - t.onRedo.dispatch(t, l); + if (!dom.getParent(listBlock.parentNode, 'ul,ol')) { + dom.split(listBlock, li); + block = dom.create('p', 0, '<br _mce_bogus="1" />'); + dom.replace(block, li); + selection.select(block, 1); } - return l; - }, - - clear : function() { - var t = this; - - t.data = []; - t.index = 0; - t.typing = 0; - t.add({initial : true}); - }, - - hasUndo : function() { - return this.index != 0 || this.typing; - }, - - hasRedo : function() { - return this.index < this.data.length - 1; + return FALSE; } - }); -})(tinymce); -(function(tinymce) { - // Shorten names - var Event, isIE, isGecko, isOpera, each, extend; - - Event = tinymce.dom.Event; - isIE = tinymce.isIE; - isGecko = tinymce.isGecko; - isOpera = tinymce.isOpera; - each = tinymce.each; - extend = tinymce.extend; - - function isEmpty(n) { - n = n.innerHTML; - - n = n.replace(/<(img|hr|table|input|select|textarea)[ \>]/gi, '-'); // Keep these convert them to - chars - n = n.replace(/<[^>]+>/g, ''); // Remove all tags - - return n.replace(/[ \t\r\n]+/g, '') == ''; + return TRUE; }; tinymce.create('tinymce.ForceBlocks', { @@ -11573,14 +11656,14 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (isOpera) o.content = o.content.replace(t.reOpera, '</' + elm + '>'); - o.content = o.content.replace(t.rePadd, '<' + elm + '$1$2$3$4$5$6>\u00a0</' + elm + '>'); + o.content = tinymce._replace(t.rePadd, '<' + elm + '$1$2$3$4$5$6>\u00a0</' + elm + '>', o.content); if (!isIE && !isOpera && o.set) { // Use instead of BR in padded paragraphs o.content = o.content.replace(t.reNbsp2BR1, '<' + elm + '$1$2><br /></' + elm + '>'); o.content = o.content.replace(t.reNbsp2BR2, '<' + elm + '$1$2><br /></' + elm + '>'); } else - o.content = o.content.replace(t.reBR2Nbsp, '<' + elm + '$1$2>\u00a0</' + elm + '>'); + o.content = tinymce._replace(t.reBR2Nbsp, '<' + elm + '$1$2>\u00a0</' + elm + '>', o.content); }; ed.onBeforeSetContent.add(padd); @@ -11594,10 +11677,11 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }, setup : function() { - var t = this, ed = t.editor, s = ed.settings; + var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection; // Force root blocks when typing and when getting output if (s.forced_root_block) { + ed.onBeforeExecCommand.add(t.forceRoots, t); ed.onKeyUp.add(t.forceRoots, t); ed.onPreProcess.add(t.forceRoots, t); } @@ -11606,40 +11690,69 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Force IE to produce BRs on enter if (isIE) { ed.onKeyPress.add(function(ed, e) { - var n, s = ed.selection; + var n; - if (e.keyCode == 13 && s.getNode().nodeName != 'LI') { - s.setContent('<br id="__" /> ', {format : 'raw'}); - n = ed.dom.get('__'); + if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') { + selection.setContent('<br id="__" /> ', {format : 'raw'}); + n = dom.get('__'); n.removeAttribute('id'); - s.select(n); - s.collapse(); + selection.select(n); + selection.collapse(); return Event.cancel(e); } }); } - - return; } - if (!isIE && s.force_p_newlines) { -/* ed.onPreProcess.add(function(ed, o) { - each(ed.dom.select('br', o.node), function(n) { - var p = n.parentNode; - - // Replace <p><br /></p> with <p> </p> - if (p && p.nodeName == 'p' && (p.childNodes.length == 1 || p.lastChild == n)) { - p.replaceChild(ed.getDoc().createTextNode('\u00a0'), n); - } + if (s.force_p_newlines) { + if (!isIE) { + ed.onKeyPress.add(function(ed, e) { + if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e)) + Event.cancel(e); + }); + } else { + // Ungly hack to for IE to preserve the formatting when you press + // enter at the end of a block element with formatted contents + // This logic overrides the browsers default logic with + // custom logic that enables us to control the output + tinymce.addUnload(function() { + t._previousFormats = 0; // Fix IE leak }); - });*/ - ed.onKeyPress.add(function(ed, e) { - if (e.keyCode == 13 && !e.shiftKey) { - if (!t.insertPara(e)) - Event.cancel(e); - } - }); + ed.onKeyPress.add(function(ed, e) { + t._previousFormats = 0; + + // Clone the current formats, this will later be applied to the new block contents + if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles) + t._previousFormats = cloneFormats(ed.selection.getStart()); + }); + + ed.onKeyUp.add(function(ed, e) { + // Let IE break the element and the wrap the new caret location in the previous formats + if (e.keyCode == 13 && !e.shiftKey) { + var parent = ed.selection.getStart(), fmt = t._previousFormats; + + // Parent is an empty block + if (!parent.hasChildNodes() && fmt) { + parent = dom.getParent(parent, dom.isBlock); + + if (parent && parent.nodeName != 'LI') { + parent.innerHTML = ''; + + if (t._previousFormats) { + parent.appendChild(fmt.wrapper); + fmt.inner.innerHTML = '\uFEFF'; + } else + parent.innerHTML = '\uFEFF'; + + selection.select(parent, 1); + ed.getDoc().execCommand('Delete', false, null); + t._previousFormats = 0; + } + } + } + }); + } if (isGecko) { ed.onKeyDown.add(function(ed, e) { @@ -11649,32 +11762,53 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } } - function ren(rn, na) { - var ne = ed.dom.create(na); + // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973 + if (tinymce.isWebKit) { + function insertBr(ed) { + var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h; - each(rn.attributes, function(a) { - if (a.specified && a.nodeValue) - ne.setAttribute(a.nodeName.toLowerCase(), a.nodeValue); - }); + // Insert BR element + rng.insertNode(br = dom.create('br')); - each(rn.childNodes, function(n) { - ne.appendChild(n.cloneNode(true)); - }); + // Place caret after BR + rng.setStartAfter(br); + rng.setEndAfter(br); + selection.setRng(rng); - rn.parentNode.replaceChild(ne, rn); + // Could not place caret after BR then insert an nbsp entity and move the caret + if (selection.getSel().focusNode == br.previousSibling) { + selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br)); + selection.collapse(TRUE); + } - return ne; - }; + // Create a temporary DIV after the BR and get the position as it + // seems like getPos() returns 0 for text nodes and BR elements. + dom.insertAfter(div, br); + divYPos = dom.getPos(div).y; + dom.remove(div); + + // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117 + if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port. + ed.getWin().scrollTo(0, divYPos); + }; + + ed.onKeyPress.add(function(ed, e) { + if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) { + insertBr(ed); + Event.cancel(e); + } + }); + } // Padd empty inline elements within block elements // For example: <p><strong><em></em></strong></p> becomes <p><strong><em> </em></strong></p> ed.onPreProcess.add(function(ed, o) { - each(ed.dom.select('p,h1,h2,h3,h4,h5,h6,div', o.node), function(p) { + each(dom.select('p,h1,h2,h3,h4,h5,h6,div', o.node), function(p) { if (isEmpty(p)) { - each(ed.dom.select('span,em,strong,b,i', o.node), function(n) { + each(dom.select('span,em,strong,b,i', o.node), function(n) { if (!n.hasChildNodes()) { n.appendChild(ed.getDoc().createTextNode('\u00a0')); - return false; // Break the loop one padding is enough + return FALSE; // Break the loop one padding is enough } }); } @@ -11686,22 +11820,22 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Replaces IE:s auto generated paragraphs with the specified element name if (s.element != 'P') { ed.onKeyPress.add(function(ed, e) { - t.lastElm = ed.selection.getNode().nodeName; + t.lastElm = selection.getNode().nodeName; }); ed.onKeyUp.add(function(ed, e) { - var bl, sel = ed.selection, n = sel.getNode(), b = ed.getBody(); + var bl, n = selection.getNode(), b = ed.getBody(); if (b.childNodes.length === 1 && n.nodeName == 'P') { - n = ren(n, s.element); - sel.select(n); - sel.collapse(); + n = dom.rename(n, s.element); + selection.select(n); + selection.collapse(); ed.nodeChanged(); } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') { - bl = ed.dom.getParent(n, 'p'); + bl = dom.getParent(n, 'p'); if (bl) { - ren(bl, s.element); + dom.rename(bl, s.element); ed.nodeChanged(); } } @@ -11711,7 +11845,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; }, find : function(n, t, s) { - var ed = this.editor, w = ed.getDoc().createTreeWalker(n, 4, null, false), c = -1; + var ed = this.editor, w = ed.getDoc().createTreeWalker(n, 4, null, FALSE), c = -1; while (n = w.nextNode()) { c++; @@ -11734,20 +11868,26 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Fix for bug #1863847 //if (e && e.keyCode == 13) - // return true; + // return TRUE; // Wrap non blocks into blocks for (i = nl.length - 1; i >= 0; i--) { nx = nl[i]; + // Ignore internal elements + if (nx.nodeType === 1 && nx.getAttribute('_mce_type')) { + bl = null; + continue; + } + // Is text or non block element - if (nx.nodeType == 3 || (!t.dom.isBlock(nx) && nx.nodeType != 8)) { + if (nx.nodeType === 3 || (!t.dom.isBlock(nx) && nx.nodeType !== 8 && !/^(script|mce:script|style|mce:style)$/i.test(nx.nodeName))) { if (!bl) { // Create new block but ignore whitespace if (nx.nodeType != 3 || /[^\s]/g.test(nx.nodeValue)) { // Store selection if (si == -2 && r) { - if (!isIE) { + if (!isIE || r.setStart) { // If selection is element then mark it if (r.startContainer.nodeType == 1 && (n = r.startContainer.childNodes[r.startOffset]) && n.nodeType == 1) { // Save the id of the selected element @@ -11763,6 +11903,13 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } } } else { + // Force control range into text range + if (r.item) { + tr = d.body.createTextRange(); + tr.moveToElementText(r.item(0)); + r = tr; + } + tr = d.body.createTextRange(); tr.moveToElementText(b); tr.collapse(1); @@ -11781,9 +11928,11 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } } + // Uses replaceChild instead of cloneNode since it removes selected attribute from option elements on IE + // See: http://support.microsoft.com/kb/829907 bl = ed.dom.create(ed.settings.forced_root_block); - bl.appendChild(nx.cloneNode(1)); nx.parentNode.replaceChild(bl, nx); + bl.appendChild(nx); } } else { if (bl.hasChildNodes()) @@ -11797,7 +11946,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Restore selection if (si != -2) { - if (!isIE) { + if (!isIE || r.setStart) { bl = b.getElementsByTagName(ed.settings.element)[0]; r = d.createRange(); @@ -11829,7 +11978,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // Ignore } } - } else if (!isIE && (n = ed.dom.get('__mce'))) { + } else if ((!isIE || r.setStart) && (n = ed.dom.get('__mce'))) { // Restore the id of the selected element if (eid) n.setAttribute('id', eid); @@ -11857,21 +12006,21 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; // If root blocks are forced then use Operas default behavior since it's really good // Removed due to bug: #1853816 // if (se.forced_root_block && isOpera) -// return true; +// return TRUE; // Setup before range rb = d.createRange(); // If is before the first block element and in body, then move it into first block element rb.setStart(s.anchorNode, s.anchorOffset); - rb.collapse(true); + rb.collapse(TRUE); // Setup after range ra = d.createRange(); // If is before the first block element and in body, then move it into first block element ra.setStart(s.focusNode, s.focusOffset); - ra.collapse(true); + ra.collapse(TRUE); // Setup start/end points dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0; @@ -11902,7 +12051,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; r.collapse(1); ed.selection.setRng(r); - return false; + return FALSE; } // If the caret is in an invalid location in FF we need to move it into the first block @@ -11927,8 +12076,12 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; bn = sb ? sb.nodeName : se.element; // Get block name to create // Return inside list use default browser behavior - if (t.dom.getParent(sb, 'ol,ul,pre')) - return true; + if (n = t.dom.getParent(sb, 'li,pre')) { + if (n.nodeName == 'LI') + return splitList(ed.selection, t.dom, n); + + return TRUE; + } // If caption or absolute layers then always generate new blocks within if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) { @@ -11956,7 +12109,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; aft.removeAttribute('id'); // Is header and cursor is at the end, then force paragraph under - if (/^(H[1-6])$/.test(bn) && sn.nodeValue && so == sn.nodeValue.length) + if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb)) aft = ed.dom.create(se.element); // Find start chop node @@ -12040,7 +12193,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; do { // We only want style specific elements if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) { - nn = n.cloneNode(false); + nn = n.cloneNode(FALSE); dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique nl.push(nn); } @@ -12077,7 +12230,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; bef.normalize(); function first(n) { - return d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false).nextNode() || n; + return d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE).nextNode() || n; }; // Move cursor and scroll into view @@ -12097,11 +12250,26 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; //console.debug('SCROLL!', 'vp.y: ' + vp.y, 'y' + y, 'vp.h' + vp.h, 'clientHeight' + aft.clientHeight, 'yyy: ' + (y < vp.y ? y : y - vp.h + aft.clientHeight)); } - return false; + return FALSE; }, backspaceDelete : function(e, bs) { - var t = this, ed = t.editor, b = ed.getBody(), n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn; + var t = this, ed = t.editor, b = ed.getBody(), dom = ed.dom, n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn, walker; + + // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651 + if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) { + walker = new tinymce.dom.TreeWalker(sc.lastChild, sc); + + // Walk the dom backwards until we find a text node + for (n = sc.lastChild; n; n = walker.prev()) { + if (n.nodeType == 3) { + r.setStart(n, n.nodeValue.length); + r.collapse(true); + se.setRng(r); + return; + } + } + } // The caret sometimes gets stuck in Gecko if you delete empty paragraphs // This workaround removes the element by hand and moves the caret to the previous element @@ -12114,7 +12282,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (n) { if (sc != b.firstChild) { // Find last text node - w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); + w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE); while (tn = w.nextNode()) n = tn; @@ -12132,40 +12300,10 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; } } } - - // Gecko generates BR elements here and there, we don't like those so lets remove them - function handler(e) { - var pr; - - e = e.target; - - // A new BR was created in a block element, remove it - if (e && e.parentNode && e.nodeName == 'BR' && (n = t.getParentBlock(e))) { - pr = e.previousSibling; - - Event.remove(b, 'DOMNodeInserted', handler); - - // Is there whitespace at the end of the node before then we might need the pesky BR - // to place the caret at a correct location see bug: #2013943 - if (pr && pr.nodeType == 3 && /\s+$/.test(pr.nodeValue)) - return; - - // Only remove BR elements that got inserted in the middle of the text - if (e.previousSibling || e.nextSibling) - ed.dom.remove(e); - } - }; - - // Listen for new nodes - Event._add(b, 'DOMNodeInserted', handler); - - // Remove listener - window.setTimeout(function() { - Event._remove(b, 'DOMNodeInserted', handler); - }, 1); } }); })(tinymce); + (function(tinymce) { // Shorten names var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend; @@ -12268,7 +12406,8 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (!s.onclick) { s.onclick = function(v) { - ed.execCommand(s.cmd, s.ui || false, s.value); + if (s.cmd) + ed.execCommand(s.cmd, s.ui || false, s.value); }; } }); @@ -12516,7 +12655,7 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; setControlType : function(n, c) { return this._cls[n.toLowerCase()] = c; }, - + destroy : function() { each(this.controls, function(c) { c.destroy(); @@ -12524,9 +12663,9 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; this.controls = null; } - - }); + }); })(tinymce); + (function(tinymce) { var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera; @@ -12575,463 +12714,1510 @@ var tinyMCE = window.tinyMCE = tinymce.EditorManager; if (tinymce.is(v, 'boolean')) v = v ? 'yes' : 'no'; - if (!/^(name|url)$/.test(k)) { - if (isIE && mo) - f += (f ? ';' : '') + k + ':' + v; - else - f += (f ? ',' : '') + k + '=' + v; + if (!/^(name|url)$/.test(k)) { + if (isIE && mo) + f += (f ? ';' : '') + k + ':' + v; + else + f += (f ? ',' : '') + k + '=' + v; + } + }); + + t.features = s; + t.params = p; + t.onOpen.dispatch(t, s, p); + + u = s.url || s.file; + u = tinymce._addVer(u); + + try { + if (isIE && mo) { + w = 1; + window.showModalDialog(u, window, f); + } else + w = window.open(u, s.name, f); + } catch (ex) { + // Ignore + } + + + if (!w) + alert(t.editor.getLang('popup_blocked')); + }, + + close : function(w) { + w.close(); + this.onClose.dispatch(this); + }, + + createInstance : function(cl, a, b, c, d, e) { + var f = tinymce.resolve(cl); + + return new f(a, b, c, d, e); + }, + + confirm : function(t, cb, s, w) { + w = w || window; + + cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t)))); + }, + + alert : function(tx, cb, s, w) { + var t = this; + + w = w || window; + w.alert(t._decode(t.editor.getLang(tx, tx))); + + if (cb) + cb.call(s || t); + }, + + resizeBy : function(dw, dh, win) { + win.resizeBy(dw, dh); + }, + + // Internal functions + + _decode : function(s) { + return tinymce.DOM.decode(s).replace(/\\n/g, '\n'); + } + }); +}(tinymce)); +(function(tinymce) { + function CommandManager() { + var execCommands = {}, queryStateCommands = {}, queryValueCommands = {}; + + function add(collection, cmd, func, scope) { + if (typeof(cmd) == 'string') + cmd = [cmd]; + + tinymce.each(cmd, function(cmd) { + collection[cmd.toLowerCase()] = {func : func, scope : scope}; + }); + }; + + tinymce.extend(this, { + add : function(cmd, func, scope) { + add(execCommands, cmd, func, scope); + }, + + addQueryStateHandler : function(cmd, func, scope) { + add(queryStateCommands, cmd, func, scope); + }, + + addQueryValueHandler : function(cmd, func, scope) { + add(queryValueCommands, cmd, func, scope); + }, + + execCommand : function(scope, cmd, ui, value, args) { + if (cmd = execCommands[cmd.toLowerCase()]) { + if (cmd.func.call(scope || cmd.scope, ui, value, args) !== false) + return true; + } + }, + + queryCommandValue : function() { + if (cmd = queryValueCommands[cmd.toLowerCase()]) + return cmd.func.call(scope || cmd.scope, ui, value, args); + }, + + queryCommandState : function() { + if (cmd = queryStateCommands[cmd.toLowerCase()]) + return cmd.func.call(scope || cmd.scope, ui, value, args); + } + }); + }; + + tinymce.GlobalCommands = new CommandManager(); +})(tinymce); +(function(tinymce) { + tinymce.Formatter = function(ed) { + var formats = {}, + each = tinymce.each, + dom = ed.dom, + selection = ed.selection, + TreeWalker = tinymce.dom.TreeWalker, + rangeUtils = new tinymce.dom.RangeUtils(dom), + isValid = ed.schema.isValid, + isBlock = dom.isBlock, + forcedRootBlock = ed.settings.forced_root_block, + nodeIndex = dom.nodeIndex, + INVISIBLE_CHAR = '\uFEFF', + MCE_ATTR_RE = /^(src|href|style)$/, + FALSE = false, + TRUE = true, + undefined, + pendingFormats = {apply : [], remove : []}; + + function isArray(obj) { + return obj instanceof Array; + }; + + function getParents(node, selector) { + return dom.getParents(node, selector, dom.getRoot()); + }; + + function isCaretNode(node) { + return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline'); + }; + + // Public functions + + function get(name) { + return name ? formats[name] : formats; + }; + + function register(name, format) { + if (name) { + if (typeof(name) !== 'string') { + each(name, function(format, name) { + register(name, format); + }); + } else { + // Force format into array and add it to internal collection + format = format.length ? format : [format]; + + each(format, function(format) { + // Set deep to false by default on selector formats this to avoid removing + // alignment on images inside paragraphs when alignment is changed on paragraphs + if (format.deep === undefined) + format.deep = !format.selector; + + // Default to true + if (format.split === undefined) + format.split = !format.selector || format.inline; + + // Default to true + if (format.remove === undefined && format.selector && !format.inline) + format.remove = 'none'; + + // Mark format as a mixed format inline + block level + if (format.selector && format.inline) { + format.mixed = true; + format.block_expand = true; + } + + // Split classes if needed + if (typeof(format.classes) === 'string') + format.classes = format.classes.split(/\s+/); + }); + + formats[name] = format; + } + } + }; + + function apply(name, vars, node) { + var formatList = get(name), format = formatList[0], bookmark, rng, i; + + 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; + + if (elm) { + each(fmt.styles, function(value, name) { + dom.setStyle(elm, name, replaceVars(value, vars)); + }); + + each(fmt.attributes, function(value, name) { + dom.setAttrib(elm, name, replaceVars(value, vars)); + }); + + each(fmt.classes, function(value) { + value = replaceVars(value, vars); + + if (!dom.hasClass(elm, value)) + dom.addClass(elm, value); + }); + } + }; + + function applyRngStyle(rng) { + var newWrappers = [], wrapName, wrapElm; + + // Setup wrapper element + wrapName = format.inline || format.block; + wrapElm = dom.create(wrapName); + setElementFormat(wrapElm); + + rangeUtils.walk(rng, function(nodes) { + var currentWrapElm; + + function process(node) { + var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found; + + // Stop wrapping on br elements + if (isEq(nodeName, 'br')) { + currentWrapElm = 0; + + // Remove any br elements when we wrap things + if (format.block) + dom.remove(node); + + return; + } + + // If node is wrapper type + if (format.wrapper && matchNode(node, name, vars)) { + currentWrapElm = 0; + return; + } + + // Can we rename the block + if (format.block && !format.wrapper && isTextBlock(nodeName)) { + node = dom.rename(node, wrapName); + setElementFormat(node); + newWrappers.push(node); + currentWrapElm = 0; + return; + } + + // Handle selector patterns + if (format.selector) { + // Look for matching formats + each(formatList, function(format) { + if (dom.is(node, format.selector) && !isCaretNode(node)) { + setElementFormat(node, format); + found = true; + } + }); + + // Continue processing if a selector match wasn't found and a inline element is defined + if (!format.inline || found) { + currentWrapElm = 0; + return; + } + } + + // Is it valid to wrap this item + if (isValid(wrapName, nodeName) && isValid(parentName, wrapName)) { + // Start wrapping + if (!currentWrapElm) { + // Wrap the node + currentWrapElm = wrapElm.cloneNode(FALSE); + node.parentNode.insertBefore(currentWrapElm, node); + newWrappers.push(currentWrapElm); + } + + currentWrapElm.appendChild(node); + } else { + // Start a new wrapper for possible children + currentWrapElm = 0; + + each(tinymce.grep(node.childNodes), process); + + // End the last wrapper + currentWrapElm = 0; + } + }; + + // Process siblings from range + each(nodes, process); + }); + + // Cleanup + each(newWrappers, function(node) { + var childCount; + + function getChildCount(node) { + var count = 0; + + each(node.childNodes, function(node) { + if (!isWhiteSpaceNode(node) && !isBookmarkNode(node)) + count++; + }); + + return count; + }; + + function mergeStyles(node) { + var child, clone; + + each(node.childNodes, function(node) { + if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) { + child = node; + return FALSE; // break loop + } + }); + + // If child was found and of the same type as the current node + if (child && matchName(child, format)) { + clone = child.cloneNode(FALSE); + setElementFormat(clone); + + dom.replace(clone, node, TRUE); + dom.remove(child, 1); + } + + return clone || node; + }; + + childCount = getChildCount(node); + + // Remove empty nodes + if (childCount === 0) { + dom.remove(node, 1); + return; + } + + if (format.inline || format.wrapper) { + // Merges the current node with it's children of similar type to reduce the number of elements + if (!format.exact && childCount === 1) + node = mergeStyles(node); + + // Remove/merge children + each(formatList, function(format) { + // Merge all children of similar type will move styles from child to parent + // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span> + // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span> + each(dom.select(format.inline, node), function(child) { + removeFormat(format, vars, child, format.exact ? child : null); + }); + }); + + // Remove child if direct parent is of same type + if (matchNode(node.parentNode, name, vars)) { + dom.remove(node, 1); + node = 0; + return TRUE; + } + + // Look for parent with similar style format + if (format.merge_with_parents) { + dom.getParent(node.parentNode, function(parent) { + if (matchNode(parent, name, vars)) { + dom.remove(node, 1); + node = 0; + return TRUE; + } + }); + } + + // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b> + if (node) { + node = mergeSiblings(getNonWhiteSpaceSibling(node), node); + node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE)); + } + } + }); + }; + + if (format) { + if (node) { + rng = dom.createRng(); + + rng.setStartBefore(node); + rng.setEndAfter(node); + + applyRngStyle(expandRng(rng, formatList)); + } else { + if (!selection.isCollapsed() || !format.inline) { + // Apply formatting to selection + bookmark = selection.getBookmark(); + applyRngStyle(expandRng(selection.getRng(TRUE), formatList)); + + selection.moveToBookmark(bookmark); + selection.setRng(moveStart(selection.getRng(TRUE))); + ed.nodeChanged(); + } else + performCaretAction('apply', name, vars); + } + } + }; + + 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) { + var children, i, l; + + // Grab the children first since the nodelist might be changed + children = tinymce.grep(node.childNodes); + + // Process current node + for (i = 0, l = formatList.length; i < l; i++) { + if (removeFormat(formatList[i], vars, node, node)) + break; + } + + // Process the children + if (format.deep) { + for (i = 0, l = children.length; i < l; i++) + process(children[i]); + } + }; + + function findFormatRoot(container) { + var formatRoot; + + // Find format root + each(getParents(container.parentNode).reverse(), function(parent) { + var format; + + // Find format root element + if (!formatRoot && parent.id != '_start' && parent.id != '_end') { + // Is the node matching the format we are looking for + format = matchNode(parent, name, vars); + if (format && format.split !== false) + formatRoot = parent; + } + }); + + return formatRoot; + }; + + function wrapAndSplit(format_root, container, target, split) { + var parent, clone, lastClone, firstClone, i, formatRootParent; + + // Format root found then clone formats and split it + if (format_root) { + formatRootParent = format_root.parentNode; + + for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) { + clone = parent.cloneNode(FALSE); + + for (i = 0; i < formatList.length; i++) { + if (removeFormat(formatList[i], vars, clone, clone)) { + clone = 0; + break; + } + } + + // Build wrapper node + if (clone) { + if (lastClone) + clone.appendChild(lastClone); + + if (!firstClone) + firstClone = clone; + + lastClone = clone; + } + } + + // Never split block elements if the format is mixed + if (split && (!format.mixed || !isBlock(format_root))) + container = dom.split(format_root, container); + + // Wrap container in cloned formats + if (lastClone) { + target.parentNode.insertBefore(lastClone, target); + firstClone.appendChild(target); + } + } + + return container; + }; + + function splitToFormatRoot(container) { + return wrapAndSplit(findFormatRoot(container), container, container, true); + }; + + function unwrap(start) { + var node = dom.get(start ? '_start' : '_end'), + out = node[start ? 'firstChild' : 'lastChild']; + + // If the end is placed within the start the result will be removed + // So this checks if the out node is a bookmark node if it is it + // checks for another more suitable node + if (isBookmarkNode(out)) + out = out[start ? 'firstChild' : 'lastChild']; + + dom.remove(node, true); + + return out; + }; + + function removeRngStyle(rng) { + var startContainer, endContainer; + + rng = expandRng(rng, formatList, TRUE); + + if (format.split) { + startContainer = getContainer(rng, TRUE); + endContainer = getContainer(rng); + + if (startContainer != endContainer) { + // Wrap start/end nodes in span element since these might be cloned/moved + startContainer = wrap(startContainer, 'span', {id : '_start', _mce_type : 'bookmark'}); + endContainer = wrap(endContainer, 'span', {id : '_end', _mce_type : 'bookmark'}); + + // Split start/end + splitToFormatRoot(startContainer); + splitToFormatRoot(endContainer); + + // Unwrap start/end to get real elements again + startContainer = unwrap(TRUE); + endContainer = unwrap(); + } else + startContainer = endContainer = splitToFormatRoot(startContainer); + + // Update range positions since they might have changed after the split operations + rng.startContainer = startContainer.parentNode; + rng.startOffset = nodeIndex(startContainer); + rng.endContainer = endContainer.parentNode; + rng.endOffset = nodeIndex(endContainer) + 1; + } + + // Remove items between start/end + rangeUtils.walk(rng, function(nodes) { + each(nodes, function(node) { + process(node); + }); + }); + }; + + // Handle node + if (node) { + rng = dom.createRng(); + rng.setStartBefore(node); + rng.setEndAfter(node); + removeRngStyle(rng); + return; + } + + if (!selection.isCollapsed() || !format.inline) { + bookmark = selection.getBookmark(); + removeRngStyle(selection.getRng(TRUE)); + selection.moveToBookmark(bookmark); + + // Check if start element still has formatting then we are at: "<b>text|</b>text" and need to move the start into the next text node + if (match(name, vars, selection.getStart())) { + moveStart(selection.getRng(true)); + } + + ed.nodeChanged(); + } else + performCaretAction('remove', name, vars); + }; + + function toggle(name, vars, node) { + if (match(name, vars, node)) + remove(name, vars, node); + else + apply(name, vars, node); + }; + + function matchNode(node, name, vars, similar) { + var formatList = get(name), format, i, classes; + + function matchItems(node, format, item_name) { + var key, value, items = format[item_name], i; + + // Check all items + if (items) { + // Non indexed object + if (items.length === undefined) { + for (key in items) { + if (items.hasOwnProperty(key)) { + if (item_name === 'attributes') + value = dom.getAttrib(node, key); + else + value = getStyle(node, key); + + if (similar && !value && !format.exact) + return; + + if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars))) + return; + } + } + } else { + // Only one match needed for indexed arrays + for (i = 0; i < items.length; i++) { + if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i])) + return format; + } + } + } + + return format; + }; + + if (formatList && node) { + // Check each format in list + for (i = 0; i < formatList.length; i++) { + format = formatList[i]; + + // Name name, attributes, styles and classes + if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) { + // Match classes + if (classes = format.classes) { + for (i = 0; i < classes.length; i++) { + if (!dom.hasClass(node, classes[i])) + return; + } + } + + return format; + } + } + } + }; + + function match(name, vars, node) { + var startNode, i; + + function matchParents(node) { + // Find first node with similar format settings + node = dom.getParent(node, function(node) { + return !!matchNode(node, name, vars, true); + }); + + // Do an exact check on the similar format element + return matchNode(node, name, vars); + }; + + // Check specified node + 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)) + return TRUE; + + // Check start node if it's different + startNode = selection.getStart(); + if (startNode != node) { + if (matchParents(startNode)) + return TRUE; + } + + return FALSE; + }; + + 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) { + var i, name; + + for (i = 0; i < names.length; i++) { + name = names[i]; + + if (!checkedMap[name] && matchNode(node, name, vars)) { + checkedMap[name] = true; + matchedFormatNames.push(name); + } + } + }); + + return matchedFormatNames; + }; + + function canApply(name) { + var formatList = get(name), startNode, parents, i, x, selector; + + if (formatList) { + startNode = selection.getStart(); + parents = getParents(startNode); + + for (x = formatList.length - 1; x >= 0; x--) { + selector = formatList[x].selector; + + // Format is not selector based, then always return TRUE + if (!selector) + return TRUE; + + for (i = parents.length - 1; i >= 0; i--) { + if (dom.is(parents[i], selector)) + return TRUE; + } + } + } + + return FALSE; + }; + + // Expose to public + tinymce.extend(this, { + get : get, + register : register, + apply : apply, + remove : remove, + toggle : toggle, + match : match, + matchAll : matchAll, + matchNode : matchNode, + canApply : canApply + }); + + // Private functions + + function matchName(node, format) { + // Check for inline match + if (isEq(node, format.inline)) + return TRUE; + + // Check for block match + if (isEq(node, format.block)) + return TRUE; + + // Check for selector match + if (format.selector) + return dom.is(node, format.selector); + }; + + function isEq(str1, str2) { + str1 = str1 || ''; + str2 = str2 || ''; + + str1 = '' + (str1.nodeName || str1); + str2 = '' + (str2.nodeName || str2); + + return str1.toLowerCase() == str2.toLowerCase(); + }; + + function getStyle(node, name) { + var styleVal = dom.getStyle(node, name); + + // Force the format to hex + if (name == 'color' || name == 'backgroundColor') + styleVal = dom.toHex(styleVal); + + // Opera will return bold as 700 + if (name == 'fontWeight' && styleVal == 700) + styleVal = 'bold'; + + return '' + styleVal; + }; + + function replaceVars(value, vars) { + if (typeof(value) != "string") + value = value(vars); + else if (vars) { + value = value.replace(/%(\w+)/g, function(str, name) { + return vars[name] || str; + }); + } + + return value; + }; + + function isWhiteSpaceNode(node) { + return node && node.nodeType === 3 && /^([\s\r\n]+|)$/.test(node.nodeValue); + }; + + function wrap(node, name, attrs) { + var wrapper = dom.create(name, attrs); + + node.parentNode.insertBefore(wrapper, node); + wrapper.appendChild(node); + + return wrapper; + }; + + function expandRng(rng, format, remove) { + var startContainer = rng.startContainer, + startOffset = rng.startOffset, + endContainer = rng.endContainer, + endOffset = rng.endOffset, sibling, lastIdx; + + // 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(); + + for (;;) { + // Check if we can move up are we at root level or body level + parent = container.parentNode; + + // Stop expanding on block elements or root depending on format + if (parent == root || (!format[0].block_expand && isBlock(parent))) + return container; + + for (sibling = parent[child_name]; sibling && sibling != container; sibling = sibling[sibling_name]) { + if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) + return container; + + if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling)) + return container; + } + + container = container.parentNode; } - }); - t.features = s; - t.params = p; - t.onOpen.dispatch(t, s, p); + return container; + }; - u = s.url || s.file; - u = tinymce._addVer(u); + // If index based start position then resolve it + if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) { + lastIdx = startContainer.childNodes.length - 1; + startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset]; - try { - if (isIE && mo) { - w = 1; - window.showModalDialog(u, window, f); - } else - w = window.open(u, s.name, f); - } catch (ex) { - // Ignore + if (startContainer.nodeType == 3) + startOffset = 0; } - if (!w) - alert(t.editor.getLang('popup_blocked')); - }, + // If index based end position then resolve it + if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) { + lastIdx = endContainer.childNodes.length - 1; + endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1]; - close : function(w) { - w.close(); - this.onClose.dispatch(this); - }, + if (endContainer.nodeType == 3) + endOffset = endContainer.nodeValue.length; + } - createInstance : function(cl, a, b, c, d, e) { - var f = tinymce.resolve(cl); + // Exclude bookmark nodes if possible + if (isBookmarkNode(startContainer.parentNode)) + startContainer = startContainer.parentNode; - return new f(a, b, c, d, e); - }, + if (isBookmarkNode(startContainer)) + startContainer = startContainer.nextSibling || startContainer; - confirm : function(t, cb, s, w) { - w = w || window; + if (isBookmarkNode(endContainer.parentNode)) + endContainer = endContainer.parentNode; - cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t)))); - }, + if (isBookmarkNode(endContainer)) + endContainer = endContainer.previousSibling || endContainer; - alert : function(tx, cb, s, w) { - var t = this; + // Move start/end point up the tree if the leaves are sharp and if we are in different containers + // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>! + // 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'); + } - w = w || window; - w.alert(t._decode(t.editor.getLang(tx, tx))); + // Expand start/end container to matching selector + if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) { + function findSelectorEndPoint(container, sibling_name) { + var parents, i, y; - if (cb) - cb.call(s || t); - }, + if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name]) + container = container[sibling_name]; - // Internal functions + parents = getParents(container); + for (i = 0; i < parents.length; i++) { + for (y = 0; y < format.length; y++) { + if (dom.is(parents[i], format[y].selector)) + return parents[i]; + } + } - _decode : function(s) { - return tinymce.DOM.decode(s).replace(/\\n/g, '\n'); - } + return container; + }; - }); -}(tinymce));(function(tinymce) { - tinymce.CommandManager = function() { - var execCommands = {}, queryStateCommands = {}, queryValueCommands = {}; + // Find new startContainer/endContainer if there is better one + startContainer = findSelectorEndPoint(startContainer, 'previousSibling'); + endContainer = findSelectorEndPoint(endContainer, 'nextSibling'); + } - function add(collection, cmd, func, scope) { - if (typeof(cmd) == 'string') - cmd = [cmd]; + // Expand start/end container to matching block element or text node + if (format[0].block || format[0].selector) { + function findBlockEndPoint(container, sibling_name, sibling_name2) { + var node; - tinymce.each(cmd, function(cmd) { - collection[cmd.toLowerCase()] = {func : func, scope : scope}; - }); - }; + // Expand to block of similar type + if (!format[0].wrapper) + node = dom.getParent(container, format[0].block); - tinymce.extend(this, { - add : function(cmd, func, scope) { - add(execCommands, cmd, func, scope); - }, + // Expand to first wrappable block element or any block element + if (!node) + node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock); - addQueryStateHandler : function(cmd, func, scope) { - add(queryStateCommands, cmd, func, scope); - }, + // Exclude inner lists from wrapping + if (node && format[0].wrapper) + node = getParents(node, 'ul,ol').reverse()[0] || node; - addQueryValueHandler : function(cmd, func, scope) { - add(queryValueCommands, cmd, func, scope); - }, + // Didn't find a block element look for first/last wrappable element + if (!node) { + node = container; - execCommand : function(scope, cmd, ui, value, args) { - if (cmd = execCommands[cmd.toLowerCase()]) { - if (cmd.func.call(scope || cmd.scope, ui, value, args) !== false) - return true; + while (node[sibling_name] && !isBlock(node[sibling_name])) { + node = node[sibling_name]; + + // Break on BR but include it will be removed later on + // we can't remove it now since we need to check if it can be wrapped + if (isEq(node, 'br')) + break; + } + } + + return node || container; + }; + + // Find new startContainer/endContainer if there is better one + startContainer = findBlockEndPoint(startContainer, 'previousSibling'); + endContainer = findBlockEndPoint(endContainer, 'nextSibling'); + + // Non block element then try to expand up the leaf + if (format[0].block) { + if (!isBlock(startContainer)) + startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling'); + + if (!isBlock(endContainer)) + endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling'); } - }, + } - queryCommandValue : function() { - if (cmd = queryValueCommands[cmd.toLowerCase()]) - return cmd.func.call(scope || cmd.scope, ui, value, args); - }, + // Setup index for startContainer + if (startContainer.nodeType == 1) { + startOffset = nodeIndex(startContainer); + startContainer = startContainer.parentNode; + } - queryCommandState : function() { - if (cmd = queryStateCommands[cmd.toLowerCase()]) - return cmd.func.call(scope || cmd.scope, ui, value, args); + // Setup index for endContainer + if (endContainer.nodeType == 1) { + endOffset = nodeIndex(endContainer) + 1; + endContainer = endContainer.parentNode; } - }); - }; - tinymce.GlobalCommands = new tinymce.CommandManager(); -})(tinymce);(function(tinymce) { - function processRange(dom, start, end, callback) { - var ancestor, n, startPoint, endPoint, sib; + // Return new range like object + return { + startContainer : startContainer, + startOffset : startOffset, + endContainer : endContainer, + endOffset : endOffset + }; + } - function findEndPoint(n, c) { - do { - if (n.parentNode == c) - return n; + function removeFormat(format, vars, node, compare_node) { + var i, attrs, stylesModified; - n = n.parentNode; - } while(n); - }; + // Check if node matches format + if (!matchName(node, format)) + return FALSE; - function process(n) { - callback(n); - tinymce.walk(n, callback, 'childNodes'); - }; + // Should we compare with format attribs and styles + if (format.remove != 'all') { + // Remove styles + each(format.styles, function(value, name) { + value = replaceVars(value, vars); - // Find common ancestor and end points - ancestor = dom.findCommonAncestor(start, end); - startPoint = findEndPoint(start, ancestor) || start; - endPoint = findEndPoint(end, ancestor) || end; + // Indexed array + if (typeof(name) === 'number') { + name = value; + compare_node = 0; + } - // Process left leaf - for (n = start; n && n != startPoint; n = n.parentNode) { - for (sib = n.nextSibling; sib; sib = sib.nextSibling) - process(sib); - } + if (!compare_node || isEq(getStyle(compare_node, name), value)) + dom.setStyle(node, name, ''); - // Process middle from start to end point - if (startPoint != endPoint) { - for (n = startPoint.nextSibling; n && n != endPoint; n = n.nextSibling) - process(n); - } else - process(startPoint); - - // Process right leaf - for (n = end; n && n != endPoint; n = n.parentNode) { - for (sib = n.previousSibling; sib; sib = sib.previousSibling) - process(sib); - } - }; + stylesModified = 1; + }); - tinymce.GlobalCommands.add('RemoveFormat', function() { - var ed = this, dom = ed.dom, s = ed.selection, r = s.getRng(1), nodes = [], bm, start, end, sc, so, ec, eo, n; + // Remove style attribute if it's empty + if (stylesModified && dom.getAttrib(node, 'style') == '') { + node.removeAttribute('style'); + node.removeAttribute('_mce_style'); + } - function findFormatRoot(n) { - var sp; + // Remove attributes + each(format.attributes, function(value, name) { + var valueOut; - dom.getParent(n, function(n) { - if (dom.is(n, ed.getParam('removeformat_selector'))) - sp = n; + value = replaceVars(value, vars); - return dom.isBlock(n); - }, ed.getBody()); + // Indexed array + if (typeof(name) === 'number') { + name = value; + compare_node = 0; + } - return sp; - }; + if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) { + // Keep internal classes + if (name == 'class') { + value = dom.getAttrib(node, name); + if (value) { + // Build new class value where everything is removed except the internal prefixed classes + valueOut = ''; + each(value.split(/\s+/), function(cls) { + if (/mce\w+/.test(cls)) + valueOut += (valueOut ? ' ' : '') + cls; + }); - function collect(n) { - if (dom.is(n, ed.getParam('removeformat_selector'))) - nodes.push(n); - }; + // We got some internal classes left + if (valueOut) { + dom.setAttrib(node, name, valueOut); + return; + } + } + } - function walk(n) { - collect(n); - tinymce.walk(n, collect, 'childNodes'); - }; + // IE6 has a bug where the attribute doesn't get removed correctly + if (name == "class") + node.removeAttribute('className'); + + // Remove mce prefixed attributes + if (MCE_ATTR_RE.test(name)) + node.removeAttribute('_mce_' + name); - bm = s.getBookmark(); - sc = r.startContainer; - ec = r.endContainer; - so = r.startOffset; - eo = r.endOffset; - sc = sc.nodeType == 1 ? sc.childNodes[Math.min(so, sc.childNodes.length - 1)] : sc; - ec = ec.nodeType == 1 ? ec.childNodes[Math.min(so == eo ? eo : eo - 1, ec.childNodes.length - 1)] : ec; + node.removeAttribute(name); + } + }); - // Same container - if (sc == ec) { // TEXT_NODE - start = findFormatRoot(sc); + // Remove classes + each(format.classes, function(value) { + value = replaceVars(value, vars); - // Handle single text node - if (sc.nodeType == 3) { - if (start && start.nodeType == 1) { // ELEMENT - n = sc.splitText(so); - n.splitText(eo - so); - dom.split(start, n); + if (!compare_node || dom.hasClass(compare_node, value)) + dom.removeClass(node, value); + }); - s.moveToBookmark(bm); + // Check for non internal attributes + attrs = dom.getAttribs(node); + for (i = 0; i < attrs.length; i++) { + if (attrs[i].nodeName.indexOf('_') !== 0) + return FALSE; } + } - return; + // Remove the inline child if it's empty for example <b> or <span> + if (format.remove != 'none') { + removeNode(node, format); + return TRUE; } + }; - // Handle single element - walk(dom.split(start, sc) || sc); - } else { - // Find start/end format root - start = findFormatRoot(sc); - end = findFormatRoot(ec); + function removeNode(node, format) { + var parentNode = node.parentNode, rootBlockElm; - // Split start text node - if (start) { - if (sc.nodeType == 3) { // TEXT - // Since IE doesn't support white space nodes in the DOM we need to - // add this invisible character so that the splitText function can split the contents - if (so == sc.nodeValue.length) - sc.nodeValue += '\uFEFF'; // Yet another pesky IE fix + if (format.block) { + if (!forcedRootBlock) { + function find(node, next, inc) { + node = getNonWhiteSpaceSibling(node, next, inc); - sc = sc.splitText(so); + return !node || (node.nodeName == 'BR' || isBlock(node)); + }; + + // Append BR elements if needed before we remove the block + if (isBlock(node) && !isBlock(parentNode)) { + if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1)) + node.insertBefore(dom.create('br'), node.firstChild); + + if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1)) + node.appendChild(dom.create('br')); + } + } else { + // Wrap the block in a forcedRootBlock if we are at the root of document + if (parentNode == dom.getRoot()) { + if (!format.list_block || !isEq(node, format.list_block)) { + each(tinymce.grep(node.childNodes), function(node) { + if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) { + if (!rootBlockElm) + rootBlockElm = wrap(node, forcedRootBlock); + else + rootBlockElm.appendChild(node); + } else + rootBlockElm = 0; + }); + } + } } } - // Split end text node - if (end) { - if (ec.nodeType == 3) // TEXT - ec.splitText(eo); - } + // Never remove nodes that isn't the specified inline element if a selector is specified too + if (format.selector && format.inline && !isEq(format.inline, node)) + return; - // If the start and end format root is the same then we need to wrap - // the end node in a span since the split calls might change the reference - // Example: <p><b><em>x[yz<span>---</span>12]3</em></b></p> - if (start && start == end) - dom.replace(dom.create('span', {id : '__end'}, ec.cloneNode(true)), ec); + dom.remove(node, 1); + }; - // Split all start containers down to the format root - if (start) - start = dom.split(start, sc); - else - start = sc; + function getNonWhiteSpaceSibling(node, next, inc) { + if (node) { + next = next ? 'nextSibling' : 'previousSibling'; - // If there is a span wrapper use that one instead - if (n = dom.get('__end')) { - ec = n; - end = findFormatRoot(ec); + for (node = inc ? node : node[next]; node; node = node[next]) { + if (node.nodeType == 1 || !isWhiteSpaceNode(node)) + return node; + } } + }; - // Split all end containers down to the format root - if (end) - end = dom.split(end, ec); - else - end = ec; + function isBookmarkNode(node) { + return node && node.nodeType == 1 && node.getAttribute('_mce_type') == 'bookmark'; + }; - // Collect nodes in between - processRange(dom, start, end, collect); + function mergeSiblings(prev, next) { + var marker, sibling, tmpSibling; - // Remove invisible character for IE workaround if we find it - if (sc.nodeValue == '\uFEFF') - sc.nodeValue = ''; + function compareElements(node1, node2) { + // Not the same name + if (node1.nodeName != node2.nodeName) + return FALSE; - // Process start/end container elements - walk(ec); - walk(sc); - } + function getAttribs(node) { + var attribs = {}; - // Remove all collected nodes - tinymce.each(nodes, function(n) { - dom.remove(n, 1); - }); + each(dom.getAttribs(node), function(attr) { + var name = attr.nodeName.toLowerCase(); - // Remove leftover wrapper - dom.remove('__end', 1); + // Don't compare internal attributes or style + if (name.indexOf('_') !== 0 && name !== 'style') + attribs[name] = dom.getAttrib(node, name); + }); - s.moveToBookmark(bm); - }); -})(tinymce); -(function(tinymce) { - tinymce.GlobalCommands.add('mceBlockQuote', function() { - var ed = this, s = ed.selection, dom = ed.dom, sb, eb, n, bm, bq, r, bq2, i, nl; + return attribs; + }; - function getBQ(e) { - return dom.getParent(e, function(n) {return n.nodeName === 'BLOCKQUOTE';}); - }; + function compareObjects(obj1, obj2) { + var value, name; - // Get start/end block - sb = dom.getParent(s.getStart(), dom.isBlock); - eb = dom.getParent(s.getEnd(), dom.isBlock); + for (name in obj1) { + // Obj1 has item obj2 doesn't have + if (obj1.hasOwnProperty(name)) { + value = obj2[name]; - // Remove blockquote(s) - if (bq = getBQ(sb)) { - if (sb != eb || sb.childNodes.length > 1 || (sb.childNodes.length == 1 && sb.firstChild.nodeName != 'BR')) - bm = s.getBookmark(); + // Obj2 doesn't have obj1 item + if (value === undefined) + return FALSE; - // Move all elements after the end block into new bq - if (getBQ(eb)) { - bq2 = bq.cloneNode(false); + // Obj2 item has a different value + if (obj1[name] != value) + return FALSE; - while (n = eb.nextSibling) - bq2.appendChild(n.parentNode.removeChild(n)); - } + // Delete similar value + delete obj2[name]; + } + } - // Add new bq after - if (bq2) - dom.insertAfter(bq2, bq); + // Check if obj 2 has something obj 1 doesn't have + for (name in obj2) { + // Obj2 has item obj1 doesn't have + if (obj2.hasOwnProperty(name)) + return FALSE; + } - // Move all selected blocks after the current bq - nl = s.getSelectedBlocks(sb, eb); - for (i = nl.length - 1; i >= 0; i--) { - dom.insertAfter(nl[i], bq); - } + return TRUE; + }; - // Empty bq, then remove it - if (/^\s*$/.test(bq.innerHTML)) - dom.remove(bq, 1); // Keep children so boomark restoration works correctly + // Attribs are not the same + if (!compareObjects(getAttribs(node1), getAttribs(node2))) + return FALSE; - // Empty bq, then remote it - if (bq2 && /^\s*$/.test(bq2.innerHTML)) - dom.remove(bq2, 1); // Keep children so boomark restoration works correctly + // Styles are not the same + if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) + return FALSE; - if (!bm) { - // Move caret inside empty block element - if (!tinymce.isIE) { - r = ed.getDoc().createRange(); - r.setStart(sb, 0); - r.setEnd(sb, 0); - s.setRng(r); - } else { - s.select(sb); - s.collapse(0); + return TRUE; + }; - // IE misses the empty block some times element so we must move back the caret - if (dom.getParent(s.getStart(), dom.isBlock) != sb) { - r = s.getRng(); - r.move('character', -1); - r.select(); + // Check if next/prev exists and that they are elements + if (prev && next) { + function findElementSibling(node, sibling_name) { + for (sibling = node; sibling; sibling = sibling[sibling_name]) { + if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling)) + return node; + + if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) + return sibling; } - } - } else - ed.selection.moveToBookmark(bm); - return; - } + return node; + }; - // Since IE can start with a totally empty document we need to add the first bq and paragraph - if (tinymce.isIE && !sb && !eb) { - ed.getDoc().execCommand('Indent'); - n = getBQ(s.getNode()); - n.style.margin = n.dir = ''; // IE adds margin and dir to bq - return; - } + // If previous sibling is empty then jump over it + prev = findElementSibling(prev, 'previousSibling'); + next = findElementSibling(next, 'nextSibling'); + + // Compare next and previous nodes + if (compareElements(prev, next)) { + // Append nodes between + for (sibling = prev.nextSibling; sibling && sibling != next;) { + tmpSibling = sibling; + sibling = sibling.nextSibling; + prev.appendChild(tmpSibling); + } - if (!sb || !eb) - return; + // Remove next node + dom.remove(next); - // If empty paragraph node then do not use bookmark - if (sb != eb || sb.childNodes.length > 1 || (sb.childNodes.length == 1 && sb.firstChild.nodeName != 'BR')) - bm = s.getBookmark(); + // Move children into prev node + each(tinymce.grep(next.childNodes), function(node) { + prev.appendChild(node); + }); - // Move selected block elements into a bq - tinymce.each(s.getSelectedBlocks(getBQ(s.getStart()), getBQ(s.getEnd())), function(e) { - // Found existing BQ add to this one - if (e.nodeName == 'BLOCKQUOTE' && !bq) { - bq = e; - return; + return prev; + } } - // No BQ found, create one - if (!bq) { - bq = dom.create('blockquote'); - e.parentNode.insertBefore(bq, e); + return next; + }; + + function isTextBlock(name) { + return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name); + }; + + function getContainer(rng, start) { + var container, offset, lastIdx; + + container = rng[start ? 'startContainer' : 'endContainer']; + offset = rng[start ? 'startOffset' : 'endOffset']; + + if (container.nodeType == 1) { + lastIdx = container.childNodes.length - 1; + + if (!start && offset) + offset--; + + container = container.childNodes[offset > lastIdx ? lastIdx : offset]; } - // Add children from existing BQ - if (e.nodeName == 'BLOCKQUOTE' && bq) { - n = e.firstChild; + return container; + }; - while (n) { - bq.appendChild(n.cloneNode(true)); - n = n.nextSibling; - } + function performCaretAction(type, name, vars) { + var i, currentPendingFormats = pendingFormats[type], + otherPendingFormats = pendingFormats[type == 'apply' ? 'remove' : 'apply']; - dom.remove(e); - return; + function hasPending() { + return pendingFormats.apply.length || pendingFormats.remove.length; + }; + + function resetPending() { + pendingFormats.apply = []; + pendingFormats.remove = []; + }; + + function perform(caret_node) { + // Apply pending formats + each(pendingFormats.apply.reverse(), function(item) { + apply(item.name, item.vars, caret_node); + }); + + // Remove pending formats + each(pendingFormats.remove.reverse(), function(item) { + remove(item.name, item.vars, caret_node); + }); + + dom.remove(caret_node, 1); + resetPending(); + }; + + // Check if it already exists then ignore it + for (i = currentPendingFormats.length - 1; i >= 0; i--) { + if (currentPendingFormats[i].name == name) + return; } - // Add non BQ element to BQ - bq.appendChild(dom.remove(e)); - }); + currentPendingFormats.push({name : name, vars : vars}); - if (!bm) { - // Move caret inside empty block element - if (!tinymce.isIE) { - r = ed.getDoc().createRange(); - r.setStart(sb, 0); - r.setEnd(sb, 0); - s.setRng(r); - } else { - s.select(sb); - s.collapse(1); + // 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); } - } else - s.moveToBookmark(bm); - }); -})(tinymce); -(function(tinymce) { - tinymce.each(['Cut', 'Copy', 'Paste'], function(cmd) { - tinymce.GlobalCommands.add(cmd, function() { - var ed = this, doc = ed.getDoc(); - try { - doc.execCommand(cmd, false, null); + // Pending apply or remove formats + if (hasPending()) { + ed.getDoc().execCommand('FontName', false, 'mceinline'); + pendingFormats.lastRng = selection.getRng(); - // On WebKit the command will just be ignored if it's not enabled - // Check disabled by Dan S./Zotero - //if (!doc.queryCommandSupported(cmd)) - //throw 'Error'; - } catch (ex) { - ed.windowManager.alert(ed.getLang('clipboard_no_support')); + // IE will convert the current word + each(dom.select('font,span'), function(node) { + var bookmark; + + if (isCaretNode(node)) { + bookmark = selection.getBookmark(); + perform(node); + selection.moveToBookmark(bookmark); + ed.nodeChanged(); + } + }); + + // Only register listeners once if we need to + if (!pendingFormats.isListening && hasPending()) { + pendingFormats.isListening = true; + + each('onKeyDown,onKeyUp,onKeyPress,onMouseUp'.split(','), function(event) { + ed[event].addToTop(function(ed, e) { + // Do we have pending formats and is the selection moved has moved + if (hasPending() && !tinymce.dom.RangeUtils.compareRanges(pendingFormats.lastRng, selection.getRng())) { + each(dom.select('font,span'), function(node) { + var textNode, rng; + + // Look for marker + if (isCaretNode(node)) { + textNode = node.firstChild; + + if (textNode) { + perform(node); + + rng = dom.createRng(); + rng.setStart(textNode, textNode.nodeValue.length); + rng.setEnd(textNode, textNode.nodeValue.length); + selection.setRng(rng); + ed.nodeChanged(); + } else + dom.remove(node); + } + }); + + // Always unbind and clear pending styles on keyup + if (e.type == 'keyup' || e.type == 'mouseup') + resetPending(); + } + }); + }); + } } - }); - }); + }; + }; })(tinymce); -(function(tinymce) { - tinymce.GlobalCommands.add('InsertHorizontalRule', function() { - if (tinymce.isOpera) - return this.getDoc().execCommand('InsertHorizontalRule', false, ''); - this.selection.setContent('<hr />'); - }); -})(tinymce); -(function() { - var cmds = tinymce.GlobalCommands; +tinymce.onAddEditor.add(function(tinymce, ed) { + var filters, fontSizes, dom, settings = ed.settings; - cmds.add(['mceEndUndoLevel', 'mceAddUndoLevel'], function() { - this.undoManager.add(); - }); + if (settings.inline_styles) { + fontSizes = tinymce.explode(settings.font_size_style_values); - cmds.add('Undo', function() { - var ed = this; + function replaceWithSpan(node, styles) { + tinymce.each(styles, function(value, name) { + if (value) + dom.setStyle(node, name, value); + }); - if (ed.settings.custom_undo_redo) { - ed.undoManager.undo(); - ed.nodeChanged(); - return true; - } + dom.rename(node, 'span'); + }; - return false; // Run browser command - }); + filters = { + font : function(dom, node) { + replaceWithSpan(node, { + backgroundColor : node.style.backgroundColor, + color : node.color, + fontFamily : node.face, + fontSize : fontSizes[parseInt(node.size) - 1] + }); + }, - cmds.add('Redo', function() { - var ed = this; + u : function(dom, node) { + replaceWithSpan(node, { + textDecoration : 'underline' + }); + }, - if (ed.settings.custom_undo_redo) { - ed.undoManager.redo(); - ed.nodeChanged(); - return true; - } + strike : function(dom, node) { + replaceWithSpan(node, { + textDecoration : 'line-through' + }); + } + }; + + function convert(editor, params) { + dom = editor.dom; + + if (settings.convert_fonts_to_spans) { + tinymce.each(dom.select('font,u,strike', params.node), function(node) { + filters[node.nodeName.toLowerCase()](ed.dom, node); + }); + } + }; + + ed.onPreProcess.add(convert); + + ed.onInit.add(function() { + ed.selection.onSetContent.add(convert); + }); + } +}); - return false; // Run browser command - }); -})(); diff --git a/chrome/content/zotero/tinymce/tiny_mce_popup.js b/chrome/content/zotero/tinymce/tiny_mce_popup.js @@ -1,298 +1,5 @@ -/* - * Contains modifications by Zotero (commented) - */ -// Some global instances -var tinymce = null, tinyMCEPopup, tinyMCE; - -tinyMCEPopup = { - init : function() { - var t = this, w, ti, li, q, i, it; - - li = ('' + document.location.search).replace(/^\?/, '').split('&'); - q = {}; - for (i=0; i<li.length; i++) { - it = li[i].split('='); - q[unescape(it[0])] = unescape(it[1]); - } - - if (q.mce_rdomain) - document.domain = q.mce_rdomain; - - // Find window & API - w = t.getWin(); - tinymce = w.tinymce; - tinyMCE = w.tinyMCE; - t.editor = tinymce.EditorManager.activeEditor; - t.params = t.editor.windowManager.params; - t.features = t.editor.windowManager.features; - - // Setup local DOM - t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document); - - // Enables you to skip loading the default css - if (t.features.popup_css !== false) - t.dom.loadCSS(t.features.popup_css || t.editor.settings.popup_css); - - // Setup on init listeners - t.listeners = []; - t.onInit = { - add : function(f, s) { - t.listeners.push({func : f, scope : s}); - } - }; - - t.isWindow = !t.getWindowArg('mce_inline'); - t.id = t.getWindowArg('mce_window_id'); - t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window); - }, - - getWin : function() { - return window.dialogArguments || opener || parent || top; - }, - - getWindowArg : function(n, dv) { - var v = this.params[n]; - - return tinymce.is(v) ? v : dv; - }, - - getParam : function(n, dv) { - return this.editor.getParam(n, dv); - }, - - getLang : function(n, dv) { - return this.editor.getLang(n, dv); - }, - - execCommand : function(cmd, ui, val, a) { - a = a || {}; - a.skip_focus = 1; - - this.restoreSelection(); - return this.editor.execCommand(cmd, ui, val, a); - }, - - resizeToInnerSize : function() { - var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh; - - dw = t.getWindowArg('mce_width') - vp.w; - dh = t.getWindowArg('mce_height') - vp.h; - - if (t.isWindow) - window.resizeBy(dw, dh); - else - t.editor.windowManager.resizeBy(dw, dh, t.id); - }, - - executeOnLoad : function(s) { - this.onInit.add(function() { - throw('evalremoved1'); - }); - }, - - storeSelection : function() { - this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple'); - }, - - restoreSelection : function() { - var t = tinyMCEPopup; - - if (!t.isWindow && tinymce.isIE) - t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark); - }, - - requireLangPack : function() { - var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url'); - - if (u && this.editor.settings.language) { - u += '/langs/' + this.editor.settings.language + '_dlg.js'; - - if (!tinymce.ScriptLoader.isDone(u)) { - document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>'); - tinymce.ScriptLoader.markDone(u); - } - } - }, - - pickColor : function(e, element_id) { - this.execCommand('mceColorPicker', true, { - color : document.getElementById(element_id).value, - func : function(c) { - document.getElementById(element_id).value = c; - - try { - document.getElementById(element_id).onchange(); - } catch (ex) { - // Try fire event, ignore errors - } - } - }); - }, - - openBrowser : function(element_id, type, option) { - tinyMCEPopup.restoreSelection(); - this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window); - }, - - confirm : function(t, cb, s) { - this.editor.windowManager.confirm(t, cb, s, window); - }, - - alert : function(tx, cb, s) { - this.editor.windowManager.alert(tx, cb, s, window); - }, - - close : function() { - var t = this; - - // To avoid domain relaxing issue in Opera - function close() { - t.editor.windowManager.close(window); - tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup - }; - - if (tinymce.isOpera) - t.getWin().setTimeout(close, 0); - else - close(); - }, - - // Internal functions - - _restoreSelection : function() { - var e = window.event.srcElement; - - if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button')) - tinyMCEPopup.restoreSelection(); - }, - -/* _restoreSelection : function() { - var e = window.event.srcElement; - - // If user focus a non text input or textarea - if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text') - tinyMCEPopup.restoreSelection(); - },*/ - - _onDOMLoaded : function() { - var t = this, ti = document.title, bm, h, nv; - - // Translate page - if (t.features.translate_i18n !== false) { - h = document.body.innerHTML; - - // Replace a=x with a="x" in IE - if (tinymce.isIE) - h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"') - - document.dir = t.editor.getParam('directionality',''); - - if ((nv = t.editor.translate(h)) && nv != h) - document.body.innerHTML = nv; - - if ((nv = t.editor.translate(ti)) && nv != ti) - document.title = ti = nv; - } - - document.body.style.display = ''; - - // Restore selection in IE when focus is placed on a non textarea or input element of the type text - if (tinymce.isIE) - document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection); - - t.restoreSelection(); - t.resizeToInnerSize(); - - // Set inline title - if (!t.isWindow) - t.editor.windowManager.setTitle(window, ti); - else - window.focus(); - - if (!tinymce.isIE && !t.isWindow) { - tinymce.dom.Event._add(document, 'focus', function() { - t.editor.windowManager.focus(t.id) - }); - } - - // Patch for accessibility - tinymce.each(t.dom.select('select'), function(e) { - // Disabled by Dan S./Zotero to fix error in link popup - //e.onkeydown = tinyMCEPopup._accessHandler; - }); - - // Call onInit - // Init must be called before focus so the selection won't get lost by the focus call - tinymce.each(t.listeners, function(o) { - o.func.call(o.scope, t.editor); - }); - - // Move focus to window - if (t.getWindowArg('mce_auto_focus', true)) { - window.focus(); - - // Focus element with mceFocus class - tinymce.each(document.forms, function(f) { - tinymce.each(f.elements, function(e) { - if (t.dom.hasClass(e, 'mceFocus') && !e.disabled) { - e.focus(); - return false; // Break loop - } - }); - }); - } - - document.onkeyup = tinyMCEPopup._closeWinKeyHandler; - }, - - _accessHandler : function(e) { - e = e || window.event; - - if (e.keyCode == 13 || e.keyCode == 32) { - e = e.target || e.srcElement; - - if (e.onchange) - e.onchange(); - - return tinymce.dom.Event.cancel(e); - } - }, - - _closeWinKeyHandler : function(e) { - e = e || window.event; - - if (e.keyCode == 27) - tinyMCEPopup.close(); - }, - - _wait : function() { - var t = this, ti; - - if (tinymce.isIE && document.location.protocol != 'https:') { - // Fake DOMContentLoaded on IE - document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>'); - document.getElementById("__ie_onload").onreadystatechange = function() { - if (this.readyState == "complete") { - t._onDOMLoaded(); - document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak - } - }; - } else { - if (tinymce.isIE || tinymce.isWebKit) { - ti = setInterval(function() { - if (/loaded|complete/.test(document.readyState)) { - clearInterval(ti); - t._onDOMLoaded(); - } - }, 10); - } else { - window.addEventListener('DOMContentLoaded', function() { - t._onDOMLoaded(); - }, false); - } - } - } -}; - -tinyMCEPopup.init(); -tinyMCEPopup._wait(); // Wait for DOM Content Loaded + +// Uncomment and change this document.domain value if you are loading the script cross subdomains +// document.domain = 'moxiecode.com'; + +var tinymce=null,tinyMCEPopup,tinyMCE;tinyMCEPopup={init:function(){var b=this,a,c;a=b.getWin();tinymce=a.tinymce;tinyMCE=a.tinyMCE;b.editor=tinymce.EditorManager.activeEditor;b.params=b.editor.windowManager.params;b.features=b.editor.windowManager.features;b.dom=b.editor.windowManager.createInstance("tinymce.dom.DOMUtils",document);if(b.features.popup_css!==false){b.dom.loadCSS(b.features.popup_css||b.editor.settings.popup_css)}b.listeners=[];b.onInit={add:function(e,d){b.listeners.push({func:e,scope:d})}};b.isWindow=!b.getWindowArg("mce_inline");b.id=b.getWindowArg("mce_window_id");b.editor.windowManager.onOpen.dispatch(b.editor.windowManager,window)},getWin:function(){return(!window.frameElement&&window.dialogArguments)||opener||parent||top},getWindowArg:function(c,b){var a=this.params[c];return tinymce.is(a)?a:b},getParam:function(b,a){return this.editor.getParam(b,a)},getLang:function(b,a){return this.editor.getLang(b,a)},execCommand:function(d,c,e,b){b=b||{};b.skip_focus=1;this.restoreSelection();return this.editor.execCommand(d,c,e,b)},resizeToInnerSize:function(){var a=this;setTimeout(function(){var b=a.dom.getViewPort(window);a.editor.windowManager.resizeBy(a.getWindowArg("mce_width")-b.w,a.getWindowArg("mce_height")-b.h,a.id||window)},0)},executeOnLoad:function(s){this.onInit.add(function(){eval(s)})},storeSelection:function(){this.editor.windowManager.bookmark=tinyMCEPopup.editor.selection.getBookmark(1)},restoreSelection:function(){var a=tinyMCEPopup;if(!a.isWindow&&tinymce.isIE){a.editor.selection.moveToBookmark(a.editor.windowManager.bookmark)}},requireLangPack:function(){var b=this,a=b.getWindowArg("plugin_url")||b.getWindowArg("theme_url");if(a&&b.editor.settings.language&&b.features.translate_i18n!==false){a+="/langs/"+b.editor.settings.language+"_dlg.js";if(!tinymce.ScriptLoader.isDone(a)){document.write('<script type="text/javascript" src="'+tinymce._addVer(a)+'"><\/script>');tinymce.ScriptLoader.markDone(a)}}},pickColor:function(b,a){this.execCommand("mceColorPicker",true,{color:document.getElementById(a).value,func:function(e){document.getElementById(a).value=e;try{document.getElementById(a).onchange()}catch(d){}}})},openBrowser:function(a,c,b){tinyMCEPopup.restoreSelection();this.editor.execCallback("file_browser_callback",a,document.getElementById(a).value,c,window)},confirm:function(b,a,c){this.editor.windowManager.confirm(b,a,c,window)},alert:function(b,a,c){this.editor.windowManager.alert(b,a,c,window)},close:function(){var a=this;function b(){a.editor.windowManager.close(window);tinymce=tinyMCE=a.editor=a.params=a.dom=a.dom.doc=null}if(tinymce.isOpera){a.getWin().setTimeout(b,0)}else{b()}},_restoreSelection:function(){var a=window.event.srcElement;if(a.nodeName=="INPUT"&&(a.type=="submit"||a.type=="button")){tinyMCEPopup.restoreSelection()}},_onDOMLoaded:function(){var b=tinyMCEPopup,d=document.title,e,c,a;if(b.domLoaded){return}b.domLoaded=1;if(b.features.translate_i18n!==false){c=document.body.innerHTML;if(tinymce.isIE){c=c.replace(/ (value|title|alt)=([^"][^\s>]+)/gi,' $1="$2"')}document.dir=b.editor.getParam("directionality","");if((a=b.editor.translate(c))&&a!=c){document.body.innerHTML=a}if((a=b.editor.translate(d))&&a!=d){document.title=d=a}}document.body.style.display="";if(tinymce.isIE){document.attachEvent("onmouseup",tinyMCEPopup._restoreSelection);b.dom.add(b.dom.select("head")[0],"base",{target:"_self"})}b.restoreSelection();b.resizeToInnerSize();if(!b.isWindow){b.editor.windowManager.setTitle(window,d)}else{window.focus()}if(!tinymce.isIE&&!b.isWindow){tinymce.dom.Event._add(document,"focus",function(){b.editor.windowManager.focus(b.id)})}tinymce.each(b.dom.select("select"),function(f){f.onkeydown=tinyMCEPopup._accessHandler});tinymce.each(b.listeners,function(f){f.func.call(f.scope,b.editor)});if(b.getWindowArg("mce_auto_focus",true)){window.focus();tinymce.each(document.forms,function(g){tinymce.each(g.elements,function(f){if(b.dom.hasClass(f,"mceFocus")&&!f.disabled){f.focus();return false}})})}document.onkeyup=tinyMCEPopup._closeWinKeyHandler},_accessHandler:function(a){a=a||window.event;if(a.keyCode==13||a.keyCode==32){a=a.target||a.srcElement;if(a.onchange){a.onchange()}return tinymce.dom.Event.cancel(a)}},_closeWinKeyHandler:function(a){a=a||window.event;if(a.keyCode==27){tinyMCEPopup.close()}},_wait:function(){if(document.attachEvent){document.attachEvent("onreadystatechange",function(){if(document.readyState==="complete"){document.detachEvent("onreadystatechange",arguments.callee);tinyMCEPopup._onDOMLoaded()}});if(document.documentElement.doScroll&&window==window.top){(function(){if(tinyMCEPopup.domLoaded){return}try{document.documentElement.doScroll("left")}catch(a){setTimeout(arguments.callee,0);return}tinyMCEPopup._onDOMLoaded()})()}document.attachEvent("onload",tinyMCEPopup._onDOMLoaded)}else{if(document.addEventListener){window.addEventListener("DOMContentLoaded",tinyMCEPopup._onDOMLoaded,false);window.addEventListener("load",tinyMCEPopup._onDOMLoaded,false)}}}};tinyMCEPopup.init();tinyMCEPopup._wait(); +\ No newline at end of file diff --git a/chrome/content/zotero/tinymce/utils/editable_selects.js b/chrome/content/zotero/tinymce/utils/editable_selects.js @@ -1,10 +1,11 @@ /** - * $Id: editable_selects.js 867 2008-06-09 20:33:40Z spocke $ + * editable_selects.js * - * Makes select boxes editable. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ var TinyMCE_EditableSelects = { diff --git a/chrome/content/zotero/tinymce/utils/form_utils.js b/chrome/content/zotero/tinymce/utils/form_utils.js @@ -1,10 +1,11 @@ /** - * $Id: form_utils.js 673 2008-03-06 13:26:20Z spocke $ + * form_utils.js * - * Various form utilitiy functions. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme")); @@ -13,7 +14,7 @@ function getColorPickerHTML(id, target_form_element) { var h = ""; h += '<a id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">'; - h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>'; + h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>'; return h; } @@ -50,7 +51,7 @@ function getBrowserHTML(id, target_form_element, type, prefix) { html = ""; html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">'; - html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"></span></a>'; + html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '"> </span></a>'; return html; } @@ -92,7 +93,7 @@ function selectByValue(form_obj, field_name, value, add_custom, ignore_case) { function getSelectValue(form_obj, field_name) { var elm = form_obj.elements[field_name]; - if (elm == null || elm.options == null) + if (elm == null || elm.options == null || elm.selectedIndex === -1) return ""; return elm.options[elm.selectedIndex].value; diff --git a/chrome/content/zotero/tinymce/utils/mctabs.js b/chrome/content/zotero/tinymce/utils/mctabs.js @@ -1,10 +1,11 @@ /** - * $Id: mctabs.js 758 2008-03-30 13:53:29Z spocke $ + * mctabs.js * - * Moxiecode DHTML Tabs script. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ function MCTabs() { diff --git a/chrome/content/zotero/tinymce/utils/validate.js b/chrome/content/zotero/tinymce/utils/validate.js @@ -1,10 +1,11 @@ /** - * $Id: validate.js 758 2008-03-30 13:53:29Z spocke $ + * validate.js * - * Various form validation methods. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * @author Moxiecode - * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ /** diff --git a/chrome/skin/default/zotero/tinymce/note-ui.css b/chrome/skin/default/zotero/tinymce/note-ui.css @@ -1,32 +0,0 @@ -html, body { - height: 100%; - margin: 0; -} -#tinymce_parent { - display: block; - height: 100%; -} -#tinymce_tbl { - height: 100% !important; - width: 100% !important; -} - -table.mceLayout > tbody > tr.mceLast { - position: absolute; - display: block; - top: 54px; - bottom: 2px; - left: 1px; - right: 1px; -} - -td.mceIframeContainer { - display: block; - height: 100% !important; - width: 100% !important; -} -#tinymce_ifr { - height: 100% !important; - width: 100% !important; -} -