From f0ea59bc8873461e060032f69d46032a97b68331 Mon Sep 17 00:00:00 2001 From: svncommit Date: Wed, 8 Nov 2006 02:23:06 +0000 Subject: upgrade to TinyMCE v2.0.8 --- program/js/tiny_mce/tiny_mce_src.js | 2093 ++++++++++++++++++++++------------- 1 file changed, 1329 insertions(+), 764 deletions(-) (limited to 'program/js/tiny_mce/tiny_mce_src.js') diff --git a/program/js/tiny_mce/tiny_mce_src.js b/program/js/tiny_mce/tiny_mce_src.js index 710a8b67f..2a8be7383 100644 --- a/program/js/tiny_mce/tiny_mce_src.js +++ b/program/js/tiny_mce/tiny_mce_src.js @@ -2,9 +2,11 @@ /* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */ function TinyMCE_Engine() { + var ua; + this.majorVersion = "2"; - this.minorVersion = "0.6.1"; - this.releaseDate = "2006-05-04"; + this.minorVersion = "0.8"; + this.releaseDate = "2006-10-23"; this.instances = new Array(); this.switchClassCache = new Array(); @@ -15,12 +17,17 @@ function TinyMCE_Engine() { this.configs = new Array(); this.currentConfig = 0; this.eventHandlers = new Array(); + this.log = new Array(); + this.undoLevels = []; + this.undoIndex = 0; + this.typingUndoIndex = -1; // Browser check - var ua = navigator.userAgent; + ua = navigator.userAgent; this.isMSIE = (navigator.appName == "Microsoft Internet Explorer"); this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1); this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1); + this.isMSIE7 = this.isMSIE && (ua.indexOf('MSIE 7') != -1); this.isGecko = ua.indexOf('Gecko') != -1; this.isSafari = ua.indexOf('Safari') != -1; this.isOpera = ua.indexOf('Opera') != -1; @@ -42,13 +49,20 @@ function TinyMCE_Engine() { this.isSafari = false; } + this.isIE = this.isMSIE; + this.isRealIE = this.isMSIE && !this.isOpera; + // TinyMCE editor id instance counter this.idCounter = 0; }; TinyMCE_Engine.prototype = { init : function(settings) { - var theme; + var theme, nl, baseHREF = "", i; + + // IE 5.0x is no longer supported since 5.5, 6.0 and 7.0 now exists. We can't support old browsers forever, sorry. + if (this.isMSIE5_0) + return; this.settings = settings; @@ -60,6 +74,13 @@ TinyMCE_Engine.prototype = { if (!tinyMCE.baseURL) { var elements = document.getElementsByTagName('script'); + // If base element found, add that infront of baseURL + nl = document.getElementsByTagName('base'); + for (i=0; i 0 && document.location.protocol != "file:") { @@ -207,7 +235,10 @@ TinyMCE_Engine.prototype = { this.settings['base_href'] = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/"; theme = this.settings['theme']; - this.blockRegExp = new RegExp("^(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|blockquote|center|dl|dt|dd|dir|fieldset|form|noscript|noframes|menu|isindex|samp)$", "i"); + this.inlineStrict = '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'; + this.inlineTransitional = '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'; + this.blockElms = 'H[1-6]|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TD|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|FORM|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP'; + this.blockRegExp = new RegExp("^(" + this.blockElms + ")$", "i"); this.posKeyCodes = new Array(13,45,36,35,33,34,37,38,39,40); this.uniqueURL = 'javascript:TINYMCE_UNIQUEURL();'; // Make unique URL non real URL this.uniqueTag = ''; @@ -216,7 +247,7 @@ TinyMCE_Engine.prototype = { // Theme url this.settings['theme_href'] = tinyMCE.baseURL + "/themes/" + theme; - if (!tinyMCE.isMSIE) + if (!tinyMCE.isIE || tinyMCE.isOpera) this.settings['force_br_newlines'] = false; if (tinyMCE.getParam("popups_css", false)) { @@ -238,8 +269,10 @@ TinyMCE_Engine.prototype = { this.settings['editor_css'] = this.documentBasePath + "/" + cssPath; else this.settings['editor_css'] = cssPath; - } else - this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css"; + } else { + if (this.settings.editor_css != '') + this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css"; + } if (tinyMCE.settings['debug']) { var msg = "Debug: \n"; @@ -255,14 +288,10 @@ TinyMCE_Engine.prototype = { // Only do this once if (this.configs.length == 0) { - // Is Safari enabled - if (this.isSafari && this.getParam('safari_warning', false)) - alert("Safari support is very limited and should be considered experimental.\nSo there is no need to even submit bugreports on this early version.\nYou can disable this message by setting: safari_warning option to false"); - if (typeof(TinyMCECompressed) == "undefined") { tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCE_Engine.prototype.onLoad); - if (tinyMCE.isMSIE && !tinyMCE.isOpera) { + if (tinyMCE.isRealIE) { if (document.body) tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad); else @@ -288,10 +317,12 @@ TinyMCE_Engine.prototype = { } // Setup entities - settings['cleanup_entities'] = new Array(); - var entities = tinyMCE.getParam('entities', '', true, ','); - for (var i=0; i 0) { /* Make sure it doesn't exist. */ for (i=0, lflen=this.loadedFiles.length; i 0) { + tinyMCE.nextUndoRedoAction = 'Undo'; + inst = this.undoLevels[--this.undoIndex]; + inst.select(); + + if (!tinyMCE.nextUndoRedoInstanceId) + inst.execCommand('Undo'); + } + } else + inst.execCommand('Undo'); + return true; + + case "Redo": + if (this.getParam('custom_undo_redo_global')) { + if (this.undoIndex <= this.undoLevels.length - 1) { + tinyMCE.nextUndoRedoAction = 'Redo'; + inst = this.undoLevels[this.undoIndex++]; + inst.select(); + + if (!tinyMCE.nextUndoRedoInstanceId) + inst.execCommand('Redo'); + } + } else + inst.execCommand('Redo'); + + return true; case 'mceFocus': var inst = tinyMCE.getInstanceById(value); if (inst) - inst.contentWindow.focus(); + inst.getWin().focus(); return; case "mceAddControl": @@ -657,7 +733,7 @@ TinyMCE_Engine.prototype = { case "mceResetDesignMode": // Resets the designmode state of the editors in Gecko - if (!tinyMCE.isMSIE) { + if (!tinyMCE.isIE) { for (var n in tinyMCE.instances) { if (!tinyMCE.isInstance(tinyMCE.instances[n])) continue; @@ -673,8 +749,8 @@ TinyMCE_Engine.prototype = { return; } - if (this.selectedInstance) { - this.selectedInstance.execCommand(command, user_interface, value); + if (inst) { + inst.execCommand(command, user_interface, value); } else if (tinyMCE.settings['focus_alert']) alert(tinyMCELang['lang_focus_alert']); }, @@ -696,17 +772,18 @@ TinyMCE_Engine.prototype = { if (aw.indexOf('%') == -1) { aw = parseInt(aw); - aw = aw < 0 ? 300 : aw; + aw = (isNaN(aw) || aw < 0) ? 300 : aw; aw = aw + "px"; } if (ah.indexOf('%') == -1) { ah = parseInt(ah); - ah = ah < 0 ? 240 : ah; + ah = (isNaN(ah) || ah < 0) ? 240 : ah; ah = ah + "px"; } iframe.setAttribute("id", id); + iframe.setAttribute("name", id); iframe.setAttribute("class", "mceEditorIframe"); iframe.setAttribute("border", "0"); iframe.setAttribute("frameBorder", "0"); @@ -723,7 +800,7 @@ TinyMCE_Engine.prototype = { iframe.setAttribute("scrolling", "no"); // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs - if (tinyMCE.isMSIE && !tinyMCE.isOpera) + if (tinyMCE.isRealIE) iframe.setAttribute("src", this.settings['default_document']); iframe.style.width = aw; @@ -734,19 +811,19 @@ TinyMCE_Engine.prototype = { iframe.style.marginBottom = '-5px'; // MSIE 5.0 issue - if (tinyMCE.isMSIE && !tinyMCE.isOpera) + if (tinyMCE.isRealIE) replace_element.outerHTML = iframe.outerHTML; else replace_element.parentNode.replaceChild(iframe, replace_element); - if (tinyMCE.isMSIE && !tinyMCE.isOpera) + if (tinyMCE.isRealIE) return win.frames[id]; else return iframe; }, setupContent : function(editor_id) { - var inst = tinyMCE.instances[editor_id]; + var inst = tinyMCE.instances[editor_id], i; var doc = inst.getDoc(); var head = doc.getElementsByTagName('head').item(0); var content = inst.startContent; @@ -762,7 +839,7 @@ TinyMCE_Engine.prototype = { inst.switchSettings(); // Not loaded correctly hit it again, Mozilla bug #997860 - if (!tinyMCE.isMSIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") { + if (!tinyMCE.isIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") { // This part will remove the designMode status // Failes first time in Firefox 1.5b2 on Mac try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {} @@ -786,6 +863,14 @@ TinyMCE_Engine.prototype = { inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo'); } + // BlockFormat shortcuts keys + for (i=1; i<=6; i++) + inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, ''); + + inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '

'); + inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '

'); + inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '
'); + // Add default shortcuts for gecko if (tinyMCE.isGecko) { inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold'); @@ -795,7 +880,7 @@ TinyMCE_Engine.prototype = { // Setup span styles if (tinyMCE.getParam("convert_fonts_to_spans")) - inst.getDoc().body.setAttribute('id', 'mceSpanFonts'); + inst.getBody().setAttribute('id', 'mceSpanFonts'); if (tinyMCE.settings['nowrap']) doc.body.style.whiteSpace = "nowrap"; @@ -804,7 +889,7 @@ TinyMCE_Engine.prototype = { doc.editorId = editor_id; // Add on document element in Mozilla - if (!tinyMCE.isMSIE) + if (!tinyMCE.isIE) doc.documentElement.editorId = editor_id; inst.setBaseHREF(tinyMCE.settings['base_href']); @@ -823,7 +908,7 @@ TinyMCE_Engine.prototype = { content = tinyMCE.storeAwayURLs(content); content = tinyMCE._customCleanup(inst, "insert_to_editor", content); - if (tinyMCE.isMSIE) { + if (tinyMCE.isIE) { // Ugly!!! window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500); @@ -837,7 +922,7 @@ TinyMCE_Engine.prototype = { content = tinyMCE.cleanupHTMLCode(content); // Fix for bug #958637 - if (!tinyMCE.isMSIE) { + if (!tinyMCE.isIE) { var contentElement = inst.getDoc().createElement("body"); var doc = inst.getDoc(); @@ -849,15 +934,8 @@ TinyMCE_Engine.prototype = { if (tinyMCE.settings['cleanup_on_startup']) tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement)); - else { - // Convert all strong/em to b/i - content = tinyMCE.regexpReplace(content, "", "", "gi"); - content = tinyMCE.regexpReplace(content, "", "", "gi"); - content = tinyMCE.regexpReplace(content, "", "", "gi"); + else tinyMCE.setInnerHTML(inst.getBody(), content); - } tinyMCE.convertAllRelativeURLs(inst.getBody()); } else { @@ -881,11 +959,11 @@ TinyMCE_Engine.prototype = { tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc()); // Re-add design mode on mozilla - if (!tinyMCE.isMSIE) + if (!tinyMCE.isIE) tinyMCE.addEventHandlers(inst); // Add blur handler - if (tinyMCE.isMSIE) { + if (tinyMCE.isIE) { tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch); tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953 @@ -898,7 +976,7 @@ TinyMCE_Engine.prototype = { } // Trigger node change, this call locks buttons for tables and so forth - tinyMCE.selectedInstance = inst; + inst.select(); tinyMCE.selectedElement = inst.contentWindow.document.body; // Call custom DOM cleanup @@ -917,19 +995,21 @@ TinyMCE_Engine.prototype = { if (tinyMCE.isGecko) { // Remove mce_src from textnodes and comments tinyMCE.selectNodes(inst.getBody(), function(n) { - if (n.nodeType == 3 || n.nodeType == 8) { - n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), ""); - n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), ""); - } + if (n.nodeType == 3 || n.nodeType == 8) + n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), ""); return false; }); } + // Remove Gecko spellchecking + if (tinyMCE.isGecko) + inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck"); + // Cleanup any mess left from storyAwayURLs tinyMCE._removeInternal(inst.getBody()); - tinyMCE.selectedInstance = inst; + inst.select(); tinyMCE.triggerNodeChange(false, true); }, @@ -950,42 +1030,14 @@ TinyMCE_Engine.prototype = { if (tinyMCE.isGecko) { // Remove mce_src from textnodes and comments tinyMCE.selectNodes(n, function(n) { - if (n.nodeType == 3 || n.nodeType == 8) { - n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), ""); - n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), ""); - } + if (n.nodeType == 3 || n.nodeType == 8) + n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), ""); return false; }); } }, - removeTinyMCEFormElements : function(form_obj) { - // Check if form is valid - if (typeof(form_obj) == "undefined" || form_obj == null) - return; - - // If not a form, find the form - if (form_obj.nodeName != "FORM") { - if (form_obj.form) - form_obj = form_obj.form; - else - form_obj = tinyMCE.getParentElement(form_obj, "form"); - } - - // Still nothing - if (form_obj == null) - return; - - // Disable all UI form elements that TinyMCE created - for (var i=0; i'; + h += ''; h += ''; h += ''; } else { // Normal button - h += ''; + h += ''; h += ''; h += ''; } @@ -1334,6 +1373,58 @@ TinyMCE_Engine.prototype = { return h; }, + getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) { + var h = '', m, x; + + mcmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + mcmd + '\');'; + cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\''; + + if (typeof(ui) != "undefined" && ui != null) + cmd += ',' + ui; + + if (typeof(val) != "undefined" && val != null) + cmd += ",'" + val + "'"; + + cmd += ');'; + + // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled + if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = tinyMCE.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) { + x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20); + + if (tinyMCE.isRealIE) + h += ''; + else + h += ''; + + h += ''; + h += ''; + h += ''; + h += ''; + } else { + if (tinyMCE.isRealIE) + h += ''; + else + h += ''; + + h += ''; + h += ''; + h += ''; + h += ''; + } + + return h; + }, + + _menuButtonEvent : function(e, o) { + if (o.className == 'mceMenuButtonFocus') + return; + + if (e == 'over') + o.className = o.className + ' mceMenuHover'; + else + o.className = o.className.replace(/\s.*$/, ''); + }, + addButtonMap : function(m) { var i, a = m.replace(/\s+/, '').split(','); @@ -1342,20 +1433,21 @@ TinyMCE_Engine.prototype = { }, submitPatch : function() { - tinyMCE.removeTinyMCEFormElements(this); tinyMCE.triggerSave(); - this.mceOldSubmit(); tinyMCE.isNotDirty = true; + this.mceOldSubmit(); }, onLoad : function() { + var r; + // Wait for everything to be loaded first if (tinyMCE.settings.strict_loading_mode && this.loadingIndex != -1) { window.setTimeout('tinyMCE.onLoad();', 1); return; } - if (tinyMCE.isMSIE && !tinyMCE.isOpera && window.event.type == "readystatechange" && document.readyState != "complete") + if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete") return true; if (tinyMCE.isLoaded) @@ -1363,6 +1455,15 @@ TinyMCE_Engine.prototype = { tinyMCE.isLoaded = true; + // IE produces JS error if TinyMCE is placed in a frame + // It seems to have something to do with the selection not beeing + // correctly initialized in IE so this hack solves the problem + if (tinyMCE.isRealIE && document.body) { + r = document.body.createTextRange(); + r.collapse(true); + r.select(); + } + tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad'); for (var c=0; c 0); @@ -1590,6 +1689,11 @@ TinyMCE_Engine.prototype = { if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined") content = eval(customCleanup + "(type, content, inst);"); + // Trigger theme cleanup + po = tinyMCE.themes[tinyMCE.settings['theme']]; + if (po && po.cleanup) + content = po.cleanup(type, content, inst); + // Trigger plugin cleanups pl = inst.plugins; for (i=0; i 0) { - for (i=ar.length-1; i>=0; i--) { - s = ar[i].substring(2, ar[i].length-1); - - if (s.indexOf('lang_') == 0 && tinyMCELang[s]) - h = tinyMCE.replaceVar(h, s, tinyMCELang[s]); - else if (as && as[s]) - h = tinyMCE.replaceVar(h, s, as[s]); - else if (tinyMCE.settings[s]) - h = tinyMCE.replaceVar(h, s, tinyMCE.settings[s]); - } - } + return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) { + if (s.indexOf('lang_') == 0 && tinyMCELang[s]) + return tinyMCELang[s]; - h = tinyMCE.replaceVar(h, "themeurl", tinyMCE.themeURL); + if (as && as[s]) + return as[s]; - return h; + if (tinyMCE.settings[s]) + return tinyMCE.settings[s]; + + if (m == 'themeurl') + return tinyMCE.themeURL; + + return m; + }); }, replaceVar : function(h, r, v) { @@ -1672,7 +1767,7 @@ TinyMCE_Engine.prototype = { height = 200; // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!! - if (tinyMCE.isMSIE) + if (tinyMCE.isIE) height += 40; else height += 20; @@ -1711,7 +1806,7 @@ TinyMCE_Engine.prototype = { win.resizeTo(width, height); win.focus(); } else { - if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") { + if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") { height += 10; var features = "resizable:" + resizable @@ -1823,7 +1918,7 @@ TinyMCE_Engine.prototype = { if (anchorName != '' && state) { el.title = anchorName; - el.className = 'mceItemAnchor'; + tinyMCE.addCSSClass(el, 'mceItemAnchor'); } else if (anchorName != '' && !state) el.className = ''; @@ -1870,7 +1965,7 @@ TinyMCE_Engine.prototype = { */ fixGeckoBaseHREFBug : function(m, e, h) { - var nl, i, a, n, xsrc, xhref, el; + var xsrc, xhref; if (tinyMCE.isGecko) { if (m == 1) { @@ -1879,38 +1974,40 @@ TinyMCE_Engine.prototype = { return h; } else { - el = new Array('a','img','select','area','iframe','base','input','script','embed','object','link'); - - for (a=0; a 0) + if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0) return true; } } @@ -2208,7 +2305,7 @@ TinyMCE_Engine.prototype = { for (on in l) { o = l[on]; - if (o[n] && (v = tinyMCE.evalFunc(o[n], 3, a)) == s && m > 0) + if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0) return true; } @@ -2216,14 +2313,26 @@ TinyMCE_Engine.prototype = { }, xmlEncode : function(s) { - s = "" + s; - s = s.replace(/&/g, '&'); - s = s.replace(new RegExp('"', 'g'), '"'); - s = s.replace(/\'/g, '''); // ' is not working in MSIE - s = s.replace(//g, '>'); + return s ? ('' + s).replace(new RegExp('[<>&"\']', 'g'), function (c, b) { + switch (c) { + case '&': + return '&'; - return s; + case '"': + return '"'; + + case '\'': + return '''; // ' is not working in MSIE + + case '<': + return '<'; + + case '>': + return '>'; + } + + return c; + }) : s; }, extend : function(p, np) { @@ -2252,19 +2361,9 @@ TinyMCE_Engine.prototype = { tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass); tinyMCE.lastSelectedMenuBtn = null; } - }, - - explode : function(d, s) { - var ar = s.split(d), oar = new Array(), i; - - for (i = 0; i
  •  
  • <" + tag + ">"); - else - this.getDoc().execCommand(command, user_interface, value); + if (focusElm) + this.selection.selectNode(focusElm, false); + } + + this.getDoc().execCommand(command, user_interface, value); + + tinyMCE.isGecko && this.getSel().collapseToEnd(); + + tinyMCE.triggerNodeChange(); + + return true; + + case "FormatBlock": + if (!this.cleanup.isValid(value)) + return true; + this.getDoc().execCommand(command, user_interface, value); tinyMCE.triggerNodeChange(); break; - case "Strikethrough": - if (tinyMCE.isSafari) - this.execCommand("mceInsertContent", false, "" + this.selection.getSelectedHTML() + ""); - else - this.getDoc().execCommand(command, user_interface, value); + case "InsertUnorderedList": + case "InsertOrderedList": + this.getDoc().execCommand(command, user_interface, value); + tinyMCE.triggerNodeChange(); + break; + case "Strikethrough": + this.getDoc().execCommand(command, user_interface, value); tinyMCE.triggerNodeChange(); break; @@ -2691,7 +2860,7 @@ TinyMCE_Control.prototype = { if (tinyMCE.isGecko && new RegExp('<(div|blockquote|code|dt|dd|dl|samp)>', 'gi').test(value)) value = value.replace(/[^a-z]/gi, ''); - if (tinyMCE.isMSIE && new RegExp('blockquote|code|samp', 'gi').test(value)) { + if (tinyMCE.isIE && new RegExp('blockquote|code|samp', 'gi').test(value)) { var b = this.selection.getBookmark(); this.getDoc().execCommand("FormatBlock", false, '

    '); tinyMCE.renameElement(tinyMCE.getParentBlockElement(this.getFocusElement()), value); @@ -2708,7 +2877,7 @@ TinyMCE_Control.prototype = { if (!value) value = tinyMCE.getParentElement(this.getFocusElement()); - if (tinyMCE.isMSIE) { + if (tinyMCE.isIE) { value.outerHTML = value.innerHTML; } else { var rng = value.ownerDocument.createRange(); @@ -2759,7 +2928,7 @@ TinyMCE_Control.prototype = { var invalidParentsRe = tinyMCE.settings['merge_styles_invalid_parents'] != '' ? new RegExp(tinyMCE.settings['merge_styles_invalid_parents'], "gi") : null; // Whole element selected check - if (tinyMCE.isMSIE) { + if (tinyMCE.isIE) { // Control range if (rng.item) parentElm = rng.item(0); @@ -2953,10 +3122,20 @@ TinyMCE_Control.prototype = { return; case "forecolor": + value = value == null ? this.foreColor : value; + value = tinyMCE.trim(value); + value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value; + + this.foreColor = value; this.getDoc().execCommand('forecolor', false, value); break; case "HiliteColor": + value = value == null ? this.backColor : value; + value = tinyMCE.trim(value); + value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value; + this.backColor = value; + if (tinyMCE.isGecko) { this._setUseCSS(true); this.getDoc().execCommand('hilitecolor', false, value); @@ -2994,9 +3173,14 @@ TinyMCE_Control.prototype = { // Call custom cleanup code value = tinyMCE.storeAwayURLs(value); value = tinyMCE._customCleanup(this, "insert_to_editor", value); - tinyMCE._setHTML(doc, value); - tinyMCE.setInnerHTML(doc.body, tinyMCE._cleanupHTML(this, doc, tinyMCE.settings, doc.body)); - tinyMCE.convertAllRelativeURLs(doc.body); + + if (this.getBody().nodeName == 'BODY') + tinyMCE._setHTML(doc, value); + else + this.getBody().innerHTML = value; + + tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, doc, this.settings, this.getBody(), false, false, false, true)); + tinyMCE.convertAllRelativeURLs(this.getBody()); // Cleanup any mess left from storyAwayURLs tinyMCE._removeInternal(this.getBody()); @@ -3005,8 +3189,8 @@ TinyMCE_Control.prototype = { if (tinyMCE.getParam("convert_fonts_to_spans")) tinyMCE.convertSpansToFonts(doc); - tinyMCE.handleVisualAid(doc.body, true, this.visualAid, this); - tinyMCE._setEventsEnabled(doc.body, false); + tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this); + tinyMCE._setEventsEnabled(this.getBody(), false); return true; case "mceCleanup": @@ -3035,7 +3219,7 @@ TinyMCE_Control.prototype = { var selectedText = ""; - if (tinyMCE.isMSIE) { + if (tinyMCE.isIE) { var rng = doc.selection.createRange(); selectedText = rng.text; } else @@ -3074,8 +3258,8 @@ TinyMCE_Control.prototype = { this.execCommand('mceInsertContent', false, key); // Store away scroll pos - var scrollX = this.getDoc().body.scrollLeft + this.getDoc().documentElement.scrollLeft; - var scrollY = this.getDoc().body.scrollTop + this.getDoc().documentElement.scrollTop; + var scrollX = this.getBody().scrollLeft + this.getDoc().documentElement.scrollLeft; + var scrollY = this.getBody().scrollTop + this.getDoc().documentElement.scrollTop; // Find marker and replace with RAW HTML var html = this.getBody().innerHTML; @@ -3095,7 +3279,9 @@ TinyMCE_Control.prototype = { value = ''; var insertHTMLFailed = false; - this.getWin().focus(); + + // Removed since it produced problems in IE + // this.getWin().focus(); if (tinyMCE.isGecko || tinyMCE.isOpera) { try { @@ -3131,15 +3317,7 @@ TinyMCE_Control.prototype = { } } - // Ugly hack in Opera due to non working "inserthtml" - if (tinyMCE.isOpera && insertHTMLFailed) { - this.getDoc().execCommand("insertimage", false, tinyMCE.uniqueURL); - var ar = tinyMCE.getElementsByAttributeValue(this.getBody(), "img", "src", tinyMCE.uniqueURL); - ar[0].outerHTML = value; - return; - } - - if (!tinyMCE.isMSIE) { + if (!tinyMCE.isIE) { var isHTML = value.indexOf('<') != -1; var sel = this.getSel(); var rng = this.getRng(); @@ -3200,18 +3378,23 @@ TinyMCE_Control.prototype = { tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value); } else { - var rng = doc.selection.createRange(); + var rng = doc.selection.createRange(), tmpRng = null; var c = value.indexOf('"; } @@ -4451,7 +4767,7 @@ TinyMCE_Cleanup.prototype = { h += this.fillStr; // End element - if (va) + if (t != null && va) h += ''; return h; @@ -4488,8 +4804,12 @@ TinyMCE_Cleanup.prototype = { if (av.length != 0 && av == "{$uid}") av = "uid_" + (this.idCount++); - if (av.length != 0) - return " " + an + "=" + '"' + this.xmlEncode(av) + '"'; + if (av.length != 0) { + if (an.indexOf('on') != 0) + av = this.xmlEncode(av); + + return " " + an + "=" + '"' + av + '"'; + } return ""; }, @@ -4497,6 +4817,12 @@ TinyMCE_Cleanup.prototype = { formatHTML : function(h) { var s = this.settings, p = '', i = 0, li = 0, o = '', l; + // Replace BR in pre elements to \n + h = h.replace(/]*)>(.*?)<\/pre>/gi, function (a, b, c) { + c = c.replace(//gi, '\n'); + return '' + c + ''; + }); + h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :) h = '\n' + h; h = h.replace(new RegExp('\\n\\s+', 'gi'), '\n'); // Remove previous formatting @@ -4527,7 +4853,7 @@ TinyMCE_Cleanup.prototype = { }, xmlEncode : function(s) { - var i, l, e, o = '', c; + var cl = this; this._setupEntities(); // Will intialize lookup table @@ -4536,29 +4862,16 @@ TinyMCE_Cleanup.prototype = { return tinyMCE.xmlEncode(s); case "named": - for (i=0, l=s.length; i&"\']', 'g'), function (c, b) { + b = cl.entities[c.charCodeAt(0)]; - if (e && e != '') - o += '&' + e + ';'; - else - o += String.fromCharCode(c); - } - - return o; + return b ? '&' + b + ';' : c; + }); case "numeric": - for (i=0, l=s.length; i 127 || c == 60 || c == 62 || c == 38 || c == 39 || c == 34) - o += '&#' + c + ";"; - else - o += String.fromCharCode(c); - } - - return o; + return s.replace(new RegExp('[\u007F-\uFFFF<>&"\']', 'g'), function (c, b) { + return b ? '&#' + c.charCodeAt(0) + ';' : c; + }); } return s; @@ -4596,16 +4909,16 @@ TinyMCE_Cleanup.prototype = { if (n == "class" && !v) v = e.className; - if (this.isMSIE && n == "http-equiv") + if (this.isIE && n == "http-equiv") v = e.httpEquiv; - if (this.isMSIE && e.nodeName == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded") + if (this.isIE && e.nodeName == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded") v = ""; - if (this.isMSIE && e.nodeName == "INPUT" && n == "size" && v == "20") + if (this.isIE && e.nodeName == "INPUT" && n == "size" && v == "20") v = ""; - if (this.isMSIE && e.nodeName == "INPUT" && n == "maxlength" && v == "2147483647") + if (this.isIE && e.nodeName == "INPUT" && n == "maxlength" && v == "2147483647") v = ""; if (n == "style" && !tinyMCE.isOpera) @@ -4679,6 +4992,7 @@ TinyMCE_Cleanup.prototype = { if (!this.rulesDone) { this.addRuleStr(s.valid_elements); this.addRuleStr(s.extended_valid_elements); + this.addChildRemoveRuleStr(s.valid_child_elements); this.rulesDone = true; } @@ -4690,7 +5004,7 @@ TinyMCE_Cleanup.prototype = { if (!this.settings.fix_content_duplication) return false; - if (tinyMCE.isMSIE && !tinyMCE.isOpera && n.nodeType == 1) { + if (tinyMCE.isRealIE && n.nodeType == 1) { // Mark elements if (n.mce_serialized == this.serializationId) return true; @@ -4708,10 +5022,44 @@ TinyMCE_Cleanup.prototype = { return false; } -}; + + }; /* file:jscripts/tiny_mce/classes/TinyMCE_DOMUtils.class.js */ +TinyMCE_Engine.prototype.createTagHTML = function(tn, a, h) { + var o = '', f = tinyMCE.xmlEncode; + + o = '<' + tn; + + if (a) { + for (n in a) { + if (typeof(a[n]) != 'function' && a[n] != null) + o += ' ' + f(n) + '="' + f('' + a[n]) + '"'; + } + } + + o += !h ? ' />' : '>' + h + ''; + + return o; +}; + +TinyMCE_Engine.prototype.createTag = function(d, tn, a, h) { + var o = d.createElement(tn); + + if (a) { + for (n in a) { + if (typeof(a[n]) != 'function' && a[n] != null) + tinyMCE.setAttrib(o, n, a[n]); + } + } + + if (h) + o.innerHTML = h; + + return o; +}; + TinyMCE_Engine.prototype.getElementByAttributeValue = function(n, e, a, v) { return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0]; }; @@ -4731,13 +5079,10 @@ TinyMCE_Engine.prototype.isBlockElement = function(n) { return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName); }; -TinyMCE_Engine.prototype.getParentBlockElement = function(n) { - while (n) { - if (this.isBlockElement(n)) - return n; - - n = n.parentNode; - } +TinyMCE_Engine.prototype.getParentBlockElement = function(n, r) { + return this.getParentNode(n, function(n) { + return tinyMCE.isBlockElement(n); + }, r); return null; }; @@ -4752,7 +5097,16 @@ TinyMCE_Engine.prototype.insertAfter = function(n, r){ TinyMCE_Engine.prototype.setInnerHTML = function(e, h) { var i, nl, n; - if (tinyMCE.isMSIE && !tinyMCE.isOpera) { + // Convert all strong/em to b/i in Gecko + if (tinyMCE.isGecko) { + h = h.replace(//gi, ''); + h = h.replace(/<\/em>/gi, ''); + } + + if (tinyMCE.isRealIE) { // Since MSIE handles invalid HTML better that valid XHTML we // need to make some things invalid.


    gets converted to
    . h = h.replace(/\s\/>/g, '>'); @@ -4782,23 +5136,28 @@ TinyMCE_Engine.prototype.setInnerHTML = function(e, h) { }; TinyMCE_Engine.prototype.getOuterHTML = function(e) { - if (tinyMCE.isMSIE) + if (tinyMCE.isIE) return e.outerHTML; var d = e.ownerDocument.createElement("body"); - d.appendChild(e); + d.appendChild(e.cloneNode(true)); return d.innerHTML; }; -TinyMCE_Engine.prototype.setOuterHTML = function(e, h) { - if (tinyMCE.isMSIE) { +TinyMCE_Engine.prototype.setOuterHTML = function(e, h, d) { + var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t; + + if (tinyMCE.isIE && e.nodeType == 1) e.outerHTML = h; - return; - } + else { + t = d.createElement("body"); + t.innerHTML = h; - var d = e.ownerDocument.createElement("body"); - d.innerHTML = h; - e.parentNode.replaceChild(d.firstChild, e); + for (i=0, nl=t.childNodes; i bookmark.index) { try { @@ -5787,11 +6228,20 @@ TinyMCE_Selection.prototype = { } } } else { - rng = inst.getSel().createRange(); - rng.moveToElementText(inst.getBody()); - rng.collapse(true); - rng.moveStart('character', bookmark.start); - rng.moveEnd('character', bookmark.length); + // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs + try { + // Incorrect bookmark + if (bookmark.start < 0) + return true; + + rng = inst.getSel().createRange(); + rng.moveToElementText(inst.getBody()); + rng.collapse(true); + rng.moveStart('character', bookmark.start); + rng.moveEnd('character', bookmark.length); + } catch (ex) { + return true; + } } rng.select(); @@ -5800,36 +6250,83 @@ TinyMCE_Selection.prototype = { return true; } - if (tinyMCE.isGecko && bookmark.rng) { - sel.removeAllRanges(); - sel.addRange(bookmark.rng); + if (tinyMCE.isGecko || tinyMCE.isOpera) { + if (bookmark.rng) { + sel.removeAllRanges(); + sel.addRange(bookmark.rng); + } + + if (bookmark.start != -1 && bookmark.end != -1) { + try { + sd = this._getTextPos(b, bookmark.start, bookmark.end); + rng = doc.createRange(); + rng.setStart(sd.startNode, sd.startOffset); + rng.setEnd(sd.endNode, sd.endOffset); + sel.removeAllRanges(); + sel.addRange(rng); + win.focus(); + } catch (ex) { + // Ignore + } + } + + /* + if (typeof(bookmark.index) != 'undefined') { + tinyMCE.selectElements(b, 'IMG', function (n) { + if (bookmark.index-- == 0) { + // Select image in Gecko here + } + + return false; + }); + } + */ + win.scrollTo(bookmark.scrollX, bookmark.scrollY); return true; } - if (tinyMCE.isGecko) { - // try { - rng = doc.createRange(); + return false; + }, - nl = doc.getElementsByTagName(bookmark.startTag); - if (nl.length > bookmark.start) - rng.setStart(nl[bookmark.start].childNodes[bookmark.startIndex], bookmark.startOffset); + _getPosText : function(r, sn, en) { + var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}; - nl = doc.getElementsByTagName(bookmark.endTag); - if (nl.length > bookmark.end) - rng.setEnd(nl[bookmark.end].childNodes[bookmark.endIndex], bookmark.endOffset); + while ((n = w.nextNode()) != null) { + if (n == sn) + d.start = p; - sel.removeAllRanges(); - sel.addRange(rng); - /* } catch { - // Ignore - }*/ + if (n == en) { + d.end = p; + return d; + } - win.scrollTo(bookmark.scrollX, bookmark.scrollY); - return true; + p += n.nodeValue ? n.nodeValue.length : 0; } - return false; + return null; + }, + + _getTextPos : function(r, sp, ep) { + var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}; + + while ((n = w.nextNode()) != null) { + p += n.nodeValue ? n.nodeValue.length : 0; + + if (p >= sp && !d.startNode) { + d.startNode = n; + d.startOffset = sp - (p - n.nodeValue.length); + } + + if (p >= ep) { + d.endNode = n; + d.endOffset = ep - (p - n.nodeValue.length); + + return d; + } + } + + return null; }, selectNode : function(node, collapse, select_text_node, to_start) { @@ -5847,8 +6344,11 @@ TinyMCE_Selection.prototype = { if (typeof(to_start) == "undefined") to_start = true; - if (tinyMCE.isMSIE) { - rng = inst.getBody().createTextRange(); + if (inst.settings.auto_resize) + inst.resizeToContent(); + + if (tinyMCE.isRealIE) { + rng = inst.getDoc().body.createTextRange(); try { rng.moveToElementText(node); @@ -5915,69 +6415,79 @@ TinyMCE_Selection.prototype = { }, scrollToNode : function(node) { - var inst = this.instance; - var pos, doc, scrollX, scrollY, height; - - // Scroll to node position - pos = tinyMCE.getAbsPosition(node); - doc = inst.getDoc(); - scrollX = doc.body.scrollLeft + doc.documentElement.scrollLeft; - scrollY = doc.body.scrollTop + doc.documentElement.scrollTop; - height = tinyMCE.isMSIE ? document.getElementById(inst.editorId).style.pixelHeight : inst.targetElement.clientHeight; + var inst = this.instance, w = inst.getWin(), vp = inst.getViewPort(), pos = tinyMCE.getAbsPosition(node), cvp, p, cwin; // Only scroll if out of visible area - if (!tinyMCE.settings['auto_resize'] && !(pos.absTop > scrollY && pos.absTop < (scrollY - 25 + height))) - inst.contentWindow.scrollTo(pos.absLeft, pos.absTop - height + 25); + if (pos.absLeft < vp.left || pos.absLeft > vp.left + vp.width || pos.absTop < vp.top || pos.absTop > vp.top + (vp.height-25)) + w.scrollTo(pos.absLeft, pos.absTop - vp.height + 25); + + // Scroll container window + if (inst.settings.auto_resize) { + cwin = inst.getContainerWin(); + cvp = tinyMCE.getViewPort(cwin); + p = this.getAbsPosition(node); + + if (p.absLeft < cvp.left || p.absLeft > cvp.left + cvp.width || p.absTop < cvp.top || p.absTop > cvp.top + cvp.height) + cwin.scrollTo(p.absLeft, p.absTop - cvp.height + 25); + } + }, + + getAbsPosition : function(n) { + var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement); + + return { + absLeft : ipos.absLeft + pos.absLeft, + absTop : ipos.absTop + pos.absTop + }; }, getSel : function() { var inst = this.instance; - if (tinyMCE.isMSIE && !tinyMCE.isOpera) + if (tinyMCE.isRealIE) return inst.getDoc().selection; return inst.contentWindow.getSelection(); }, getRng : function() { - var inst = this.instance; - var sel = this.getSel(); + var s = this.getSel(); - if (sel == null) + if (s == null) return null; - if (tinyMCE.isMSIE && !tinyMCE.isOpera) - return sel.createRange(); + if (tinyMCE.isRealIE) + return s.createRange(); - if (tinyMCE.isSafari && !sel.getRangeAt) + if (tinyMCE.isSafari && !s.getRangeAt) return '' + window.getSelection(); - return sel.getRangeAt(0); + return s.getRangeAt(0); }, getFocusElement : function() { - var inst = this.instance; + var inst = this.instance, doc, rng, sel, elm; - if (tinyMCE.isMSIE && !tinyMCE.isOpera) { - var doc = inst.getDoc(); - var rng = doc.selection.createRange(); + if (tinyMCE.isRealIE) { + doc = inst.getDoc(); + rng = doc.selection.createRange(); // if (rng.collapse) // rng.collapse(true); - var elm = rng.item ? rng.item(0) : rng.parentElement(); + elm = rng.item ? rng.item(0) : rng.parentElement(); } else { - if (inst.isHidden()) + if (!tinyMCE.isSafari && inst.isHidden()) return inst.getBody(); - var sel = this.getSel(); - var rng = this.getRng(); + sel = this.getSel(); + rng = this.getRng(); if (!sel || !rng) return null; - var elm = rng.commonAncestorContainer; - //var elm = (sel && sel.anchorNode) ? sel.anchorNode : null; + elm = rng.commonAncestorContainer; + //elm = (sel && sel.anchorNode) ? sel.anchorNode : null; // Handle selection a image or other control like element such as anchors if (!rng.collapsed) { @@ -5999,7 +6509,8 @@ TinyMCE_Selection.prototype = { return elm; } -}; + + }; /* file:jscripts/tiny_mce/classes/TinyMCE_UndoRedo.class.js */ @@ -6013,39 +6524,40 @@ function TinyMCE_UndoRedo(inst) { TinyMCE_UndoRedo.prototype = { add : function(l) { - var b; + var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur; if (l) { this.undoLevels[this.undoLevels.length] = l; return true; } - var inst = this.instance; - if (this.typingUndoIndex != -1) { this.undoIndex = this.typingUndoIndex; - // tinyMCE.debug("Override: " + this.undoIndex); + + if (tinyMCE.typingUndoIndex != -1) + tinyMCE.undoIndex = tinyMCE.typingUndoIndex; } - var newHTML = tinyMCE.trim(inst.getBody().innerHTML); + newHTML = tinyMCE.trim(inst.getBody().innerHTML); if (this.undoLevels[this.undoIndex] && newHTML != this.undoLevels[this.undoIndex].content) { - //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex]); + //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex].content); tinyMCE.dispatchCallback(inst, 'onchange_callback', 'onChange', inst); // Time to compress - var customUndoLevels = tinyMCE.settings['custom_undo_redo_levels']; + customUndoLevels = tinyMCE.settings['custom_undo_redo_levels']; if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) { - for (var i=0; i 0) { this.undoIndex--; + tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content); inst.repaint(); + if (inst.settings.custom_undo_redo_restore_selection) inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark); } - - // tinyMCE.debug("Undo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex); }, redo : function() { @@ -6088,23 +6612,28 @@ TinyMCE_UndoRedo.prototype = { if (this.undoIndex < (this.undoLevels.length-1)) { this.undoIndex++; + tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content); inst.repaint(); -// if (this.undoIndex > 0) -// inst.selection.moveToBookmark(this.undoLevels[this.undoIndex-1].bookmark); + if (inst.settings.custom_undo_redo_restore_selection) inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark); - // tinyMCE.debug("Redo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex); } tinyMCE.triggerNodeChange(); } -}; + + }; /* file:jscripts/tiny_mce/classes/TinyMCE_ForceParagraphs.class.js */ var TinyMCE_ForceParagraphs = { _insertPara : function(inst, e) { + var doc = inst.getDoc(), sel = inst.getSel(), body = inst.getBody(), win = inst.contentWindow, rng = sel.getRangeAt(0); + var rootElm = doc.documentElement, blockName = "P", startNode, endNode, startBlock, endBlock; + var rngBefore, rngAfter, direct, startNode, startOffset, endNode, endOffset, b = tinyMCE.isOpera ? inst.selection.getBookmark() : null; + var paraBefore, paraAfter, startChop, endChop, contents; + function isEmpty(para) { function isEmptyHTML(html) { return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == ""; @@ -6133,43 +6662,33 @@ var TinyMCE_ForceParagraphs = { return true; } - var doc = inst.getDoc(); - var sel = inst.getSel(); - var win = inst.contentWindow; - var rng = sel.getRangeAt(0); - var body = doc.body; - var rootElm = doc.documentElement; - var blockName = "P"; - // tinyMCE.debug(body.innerHTML); // debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString()); // Setup before range - var rngBefore = doc.createRange(); + rngBefore = doc.createRange(); rngBefore.setStart(sel.anchorNode, sel.anchorOffset); rngBefore.collapse(true); // Setup after range - var rngAfter = doc.createRange(); + rngAfter = doc.createRange(); rngAfter.setStart(sel.focusNode, sel.focusOffset); rngAfter.collapse(true); // Setup start/end points - var direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0; - var startNode = direct ? sel.anchorNode : sel.focusNode; - var startOffset = direct ? sel.anchorOffset : sel.focusOffset; - var endNode = direct ? sel.focusNode : sel.anchorNode; - var endOffset = direct ? sel.focusOffset : sel.anchorOffset; + direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0; + startNode = direct ? sel.anchorNode : sel.focusNode; + startOffset = direct ? sel.anchorOffset : sel.focusOffset; + endNode = direct ? sel.focusNode : sel.anchorNode; + endOffset = direct ? sel.focusOffset : sel.anchorOffset; startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode; endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode; - // tinyMCE.debug(startNode, endNode); - // Get block elements - var startBlock = tinyMCE.getParentBlockElement(startNode); - var endBlock = tinyMCE.getParentBlockElement(endNode); + startBlock = inst.getParentBlockElement(startNode); + endBlock = inst.getParentBlockElement(endNode); // If absolute force paragraph generation within if (startBlock && new RegExp('absolute|relative|static', 'gi').test(startBlock.style.position)) @@ -6188,7 +6707,7 @@ var TinyMCE_ForceParagraphs = { } // Within a list use normal behaviour - if (tinyMCE.getParentElement(startBlock, "OL,UL") != null) + if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null) return false; // Within a table create new paragraphs @@ -6196,16 +6715,16 @@ var TinyMCE_ForceParagraphs = { startBlock = endBlock = null; // Setup new paragraphs - var paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName); - var paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName); + paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName); + paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName); // Is header, then force paragraph under if (/^(H[1-6])$/.test(blockName)) paraAfter = doc.createElement("p"); // Setup chop nodes - var startChop = startNode; - var endChop = endNode; + startChop = startNode; + endChop = endNode; // Get startChop node node = startChop; @@ -6236,7 +6755,9 @@ var TinyMCE_ForceParagraphs = { if (startBlock == null) { // Delete selection rng.deleteContents(); - sel.removeAllRanges(); + + if (!tinyMCE.isSafari) + sel.removeAllRanges(); if (startChop != rootElm && endChop != rootElm) { // Insert paragraph before @@ -6260,7 +6781,7 @@ var TinyMCE_ForceParagraphs = { if (endChop.nodeName != "#text" && endChop.nodeName != "BODY") rngBefore.setEndAfter(endChop); - var contents = rng.cloneContents(); + contents = rng.cloneContents(); if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY")) paraAfter.innerHTML = contents.firstChild.innerHTML; else @@ -6280,17 +6801,25 @@ var TinyMCE_ForceParagraphs = { rngBefore.deleteContents(); // Insert new paragraphs - paraAfter.normalize(); - rngBefore.insertNode(paraAfter); - paraBefore.normalize(); - rngBefore.insertNode(paraBefore); + if (tinyMCE.isOpera) { + paraBefore.normalize(); + rngBefore.insertNode(paraBefore); + paraAfter.normalize(); + rngBefore.insertNode(paraAfter); + } else { + paraAfter.normalize(); + rngBefore.insertNode(paraAfter); + paraBefore.normalize(); + rngBefore.insertNode(paraBefore); + } - // tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML); + //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML); } else { body.innerHTML = "<" + blockName + "> <" + blockName + "> "; paraAfter = body.childNodes[1]; } + inst.selection.moveToBookmark(b); inst.selection.selectNode(paraAfter, true, true); return true; @@ -6308,7 +6837,7 @@ var TinyMCE_ForceParagraphs = { // Place secound part within new paragraph rngAfter.setEndAfter(endChop); rngAfter.setStart(endNode, endOffset); - var contents = rngAfter.cloneContents(); + contents = rngAfter.cloneContents(); if (contents.firstChild && contents.firstChild.nodeName == blockName) { /* var nodes = contents.firstChild.childNodes; @@ -6331,7 +6860,7 @@ var TinyMCE_ForceParagraphs = { paraAfter.innerHTML = " "; // Create a range around everything - var rng = doc.createRange(); + rng = doc.createRange(); if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) { rng.setStartBefore(startChop.parentNode); @@ -6349,14 +6878,22 @@ var TinyMCE_ForceParagraphs = { // Delete all contents and insert new paragraphs rng.deleteContents(); - rng.insertNode(paraAfter); - rng.insertNode(paraBefore); + + if (tinyMCE.isOpera) { + rng.insertNode(paraBefore); + rng.insertNode(paraAfter); + } else { + rng.insertNode(paraAfter); + rng.insertNode(paraBefore); + } + //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML); // Normalize paraAfter.normalize(); paraBefore.normalize(); + inst.selection.moveToBookmark(b); inst.selection.selectNode(paraAfter, true, true); return true; @@ -6365,21 +6902,26 @@ var TinyMCE_ForceParagraphs = { _handleBackSpace : function(inst) { var r = inst.getRng(), sn = r.startContainer, nv, s = false; - if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR") { + // Added body check for bug #1527787 + if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR" && sn.parentNode.nodeName != "BODY") { nv = sn.nodeValue; - // Handle if a backspace is pressed after a space character #bug 1466054 - if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ') - s = true; + // Handle if a backspace is pressed after a space character #bug 1466054 removed since fix for #1527787 + /*if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ') + s = true;*/ // Only remove BRs if we are at the end of line #bug 1464152 if (nv != null && r.startOffset == nv.length) sn.nextSibling.parentNode.removeChild(sn.nextSibling); } + if (inst.settings.auto_resize) + inst.resizeToContent(); + return s; } -}; + + }; /* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */ @@ -6515,14 +7057,20 @@ TinyMCE_Layer.prototype = { if (!this.blockerElement && this.blockMode) { d = this.doc; - b = d.createElement("iframe"); + b = d.getElementById(this.id + "_blocker"); - b.style.cssText = 'display: none; position: absolute; left: 0; top: 0'; - b.src = 'javascript:false;'; - b.frameBorder = '0'; - b.scrolling = 'no'; + if (!b) { + b = d.createElement("iframe"); + + b.setAttribute('id', this.id + "_blocker"); + b.style.cssText = 'display: none; position: absolute; left: 0; top: 0'; + b.src = 'javascript:false;'; + b.frameBorder = '0'; + b.scrolling = 'no'; + + d.body.appendChild(b); + } - d.body.appendChild(b); this.blockerElement = b; } @@ -6541,7 +7089,7 @@ TinyMCE_Layer.prototype = { return p; }, - create : function(n, c, p) { + create : function(n, c, p, h) { var d = this.doc, e = d.createElement(n); e.setAttribute('id', this.id); @@ -6552,18 +7100,26 @@ TinyMCE_Layer.prototype = { if (!p) p = d.body; + if (h) + e.innerHTML = h; + p.appendChild(e); return this.element = e; }, + exists : function() { + return this.doc.getElementById(this.id) != null; + }, + parseInt : function(s) { if (s == null || s == '') return 0; return parseInt(s); } -}; + + }; /* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */ @@ -6582,7 +7138,6 @@ function TinyMCE_Menu() { this.needsUpdate = true; }; -// Extends the TinyMCE_Layer class TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, { init : function(s) { var n; @@ -6653,7 +7208,7 @@ TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, { break; default: - h += '' + t + '
    '; + h += '' + t + '
    '; } h += ''; @@ -6690,30 +7245,40 @@ TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, { tinyMCE.lastMenu = this; } -}); -/* file:jscripts/tiny_mce/classes/TinyMCE_Debug.class.js */ + }); -TinyMCE_Engine.prototype.debug = function() { - var m = "", e, a, i; +/* file:jscripts/tiny_mce/classes/TinyMCE_Compatibility.class.js */ - e = document.getElementById("tinymce_debug"); - if (!e) { - var d = document.createElement("div"); - d.setAttribute("className", "debugger"); - d.className = "debugger"; - d.innerHTML = 'Debug output:'; +if (!Function.prototype.call) { + Function.prototype.call = function() { + var a = arguments, s = a[0], i, as = '', r, o; - document.body.appendChild(d); - e = document.getElementById("tinymce_debug"); - } + for (i=1; i 1 ? ',' : '') + 'a[' + i + ']'; + + o = s._fu; + s._fu = this; + r = eval('s._fu(' + as + ')'); + s._fu = o; + + return r; + }; +}; - a = this.debug.arguments; - for (i=0; i