/** * $RCSfile: tiny_mce_src.js,v $ * $Revision: 1.1 $ * $Date: 2005/03/06 06:22:26 $ * * @author Moxiecode * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved. */ function TinyMCE() { this.instances = new Array(); this.stickyClassesLookup = new Array(); this.windowArgs = new Array(); // Browser check this.isMSIE = (navigator.appName == "Microsoft Internet Explorer"); this.isMSIE5 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5') != -1); this.isMSIE5_0 = this.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1); this.isGecko = navigator.userAgent.indexOf('Gecko') != -1; // TinyMCE editor id instance counter this.idCounter = 0; // Editor functions this.init = TinyMCE_init; this.addMCEControl = TinyMCE_addMCEControl; this.triggerSave = TinyMCE_triggerSave; this._convertOnClick = TinyMCE__convertOnClick; this.resetForm = TinyMCE_resetForm; this.execCommand = TinyMCE_execCommand; this.execInstanceCommand = TinyMCE_execInstanceCommand; this._createIFrame = TinyMCE__createIFrame; this.handleEvent = TinyMCE_handleEvent; this.setupContent = TinyMCE_setupContent; this.switchClass = TinyMCE_switchClass; this.restoreAndSwitchClass = TinyMCE_restoreAndSwitchClass; this.switchClassSticky = TinyMCE_switchClassSticky; this.restoreClass = TinyMCE_restoreClass; this.setClassLock = TinyMCE_setClassLock; this.addEvent = TinyMCE_addEvent; this.onLoad = TinyMCE_onLoad; this.removeMCEControl = TinyMCE_removeMCEControl; this._initCleanup = TinyMCE__initCleanup; this._cleanupHTML = TinyMCE__cleanupHTML; this._cleanupAttribute = TinyMCE__cleanupAttribute; this._fixInlineStyles = TinyMCE__fixInlineStyles; this._cleanupElementName = TinyMCE__cleanupElementName; this._verifyClass = TinyMCE__verifyClass; this.cleanupNode = TinyMCE_cleanupNode; this.convertStringToXML = TinyMCE_convertStringToXML; this.insertLink = TinyMCE_insertLink; this.insertImage = TinyMCE_insertImage; this.getElementByAttributeValue = TinyMCE_getElementByAttributeValue; this.getElementsByAttributeValue = TinyMCE_getElementsByAttributeValue; this.isBlockElement = TinyMCE_isBlockElement; this.getParentBlockElement = TinyMCE_getParentBlockElement; this.getNodeTree = TinyMCE_getNodeTree; this.getParentElement = TinyMCE_getParentElement; this.getParam = TinyMCE_getParam; this.getLang = TinyMCE_getLang; this.replaceVar = TinyMCE_replaceVar; this.replaceVars = TinyMCE_replaceVars; this.triggerNodeChange = TinyMCE_triggerNodeChange; this.parseURL = TinyMCE_parseURL; this.convertAbsoluteURLToRelativeURL = TinyMCE_convertAbsoluteURLToRelativeURL; this.convertRelativeToAbsoluteURL = TinyMCE_convertRelativeToAbsoluteURL; this.updateContent = TinyMCE_updateContent; this._customCleanup = TinyMCE__customCleanup; this.getContent = TinyMCE_getContent; this.setContent = TinyMCE_setContent; this.importThemeLanguagePack = TinyMCE_importThemeLanguagePack; this.importPluginLanguagePack = TinyMCE_importPluginLanguagePack; this.applyTemplate = TinyMCE_applyTemplate; this.openWindow = TinyMCE_openWindow; this.handleVisualAid = TinyMCE_handleVisualAid; this.setAttrib = TinyMCE_setAttrib; this.getAttrib = TinyMCE_getAttrib; this._getThemeFunction = TinyMCE__getThemeFunction; this._themeExecCommand = TinyMCE__themeExecCommand; this.getControlHTML = TinyMCE_getControlHTML; this._setHTML = TinyMCE__setHTML; this._getElementById = TinyMCE__getElementById; this.getInstanceById = TinyMCE_getInstanceById; this.getEditorId = TinyMCE_getEditorId; this.queryInstanceCommandValue = TinyMCE_queryInstanceCommandValue; this.queryInstanceCommandState = TinyMCE_queryInstanceCommandState; this.getWindowArg = TinyMCE_getWindowArg; this.setWindowArg = TinyMCE_setWindowArg; this.getCSSClasses = TinyMCE_getCSSClasses; this.regexpReplace = TinyMCE_regexpReplace; this.cleanupEventStr = TinyMCE_cleanupEventStr; this.getAbsPosition = TinyMCE_getAbsPosition; this.openFileBrowser = TinyMCE_openFileBrowser; } function TinyMCE_init(settings) { var theme, srcMode; this.settings = settings; function defParam(key, def_val) { settings[key] = tinyMCE.getParam(key, def_val); } // Check if valid browser has execcommand support if (typeof(document.execCommand) == 'undefined') return; // Get script base path if (!tinyMCE.baseURL) { var elements = document.getElementsByTagName('script'); for (var i=0; i'); document.write(''); document.write(''); // Add theme plugins var themePlugins = tinyMCE.getParam('plugins', '', true, ','); if (this.settings['plugins'] != '') { for (var i=0; i'); } } function TinyMCE_confirmAdd(e) { var elm = tinyMCE.isMSIE ? event.srcElement : e.target; var elementId = elm.name ? elm.name : elm.id; if (!targetElement.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm'])) tinyMCE.addMCEControl(elm, elementId); else targetElement.setAttribute('mce_noask', 'true'); } function TinyMCE_updateContent(form_element_name) { // Find MCE instance linked to given form element and copy it's value var formElement = document.getElementById(form_element_name); for (var n in tinyMCE.instances) { var inst = tinyMCE.instances[n]; if (inst.formElement == formElement) { var doc = inst.getDoc(); tinyMCE._setHTML(doc, inst.formElement.value); if (!tinyMCE.isMSIE) doc.body.innerHTML = tinyMCE._cleanupHTML(doc, this.settings, doc.body, inst.visualAid); } } } function TinyMCE_addMCEControl(replace_element, form_element_name, target_document) { var id = "mce_editor_" + tinyMCE.idCounter++; var inst = new TinyMCEControl(tinyMCE.settings); inst.editorId = id; this.instances[id] = inst; inst.onAdd(replace_element, form_element_name, target_document); } function TinyMCE_triggerSave(skip_cleanup, skip_callback) { // Cleanup and set all form fields for (var n in tinyMCE.instances) { var inst = tinyMCE.instances[n]; tinyMCE.settings['preformatted'] = false; // Default to false if (typeof(skip_cleanup) == "undefined") skip_cleanup = false; // Default to false if (typeof(skip_callback) == "undefined") skip_callback = false; tinyMCE._setHTML(inst.getDoc(), inst.getBody().innerHTML); var htm = skip_cleanup ? inst.getBody().innerHTML : tinyMCE._cleanupHTML(inst.getDoc(), this.settings, inst.getBody(), this.visualAid, true); //var htm = tinyMCE._cleanupHTML(inst.getDoc(), tinyMCE.settings, inst.getBody(), false, true); if (tinyMCE.settings["encoding"] == "xml" || tinyMCE.settings["encoding"] == "html") htm = tinyMCE.convertStringToXML(htm); if (!skip_callback && tinyMCE.settings['save_callback'] != "") var content = eval(tinyMCE.settings['save_callback'] + "(inst.formTargetElementId,htm,inst.getBody());"); // Use callback content if available if ((typeof(content) != "undefined") && content != null) htm = content; // Replace some weird entities (Bug: #1056343) htm = tinyMCE.regexpReplace(htm, "(", "(", "gi"); htm = tinyMCE.regexpReplace(htm, ")", ")", "gi"); htm = tinyMCE.regexpReplace(htm, ";", ";", "gi"); htm = tinyMCE.regexpReplace(htm, """, """, "gi"); htm = tinyMCE.regexpReplace(htm, "^", "^", "gi"); inst.formElement.value = htm; } } function TinyMCE__convertOnClick(node) { // Skip on MSIE < 6+ if (tinyMCE.isMSIE5) return; // Convert all onclick to mce_onclick var elms = node.getElementsByTagName("a"); for (var i=0; i", "gi"); content = tinyMCE.regexpReplace(content, "\r", "
", "gi"); content = tinyMCE.regexpReplace(content, "\n", "
", "gi"); } // Call custom cleanup code content = tinyMCE._customCleanup("insert_to_editor", content); if (tinyMCE.isMSIE) { var styleSheet = document.frames[editor_id].document.createStyleSheet(inst.settings['content_css']); // Ugly!!! window.setInterval('try{tinyMCE.getCSSClasses(document.frames["' + editor_id + '"].document, "' + editor_id + '");}catch(e){}', 500); if (tinyMCE.settings["force_br_newlines"]) document.frames[editor_id].document.styleSheets[0].addRule("p", "margin: 0px;"); var patchFunc = function() { var event = document.frames[editor_id].event; event.target = document.frames[editor_id].document; TinyMCE_handleEvent(event); }; var body = document.frames[editor_id].document.body; body.onbeforepaste = patchFunc; body.onbeforecut = patchFunc; body.onpaste = patchFunc; body.editorId = editor_id; } else { // Import editor css var cssImporter = doc.createElement("link"); cssImporter.rel = "stylesheet"; cssImporter.href = inst.settings['content_css']; if (headArr = doc.getElementsByTagName("head")); headArr[0].appendChild(cssImporter); } // Fix for bug #958637 if (!tinyMCE.isMSIE) { var contentElement = inst.getDoc().createElement("body"); var doc = inst.getDoc(); contentElement.innerHTML = content; // Remove weridness! if (tinyMCE.settings['force_p_newlines']) content = content.replace(new RegExp('<>', 'g'), ""); if (tinyMCE.settings['cleanup_on_startup']) inst.getBody().innerHTML = tinyMCE._cleanupHTML(doc, this.settings, contentElement); else { // Convert all strong/em to b/i content = tinyMCE.regexpReplace(content, "", "", "gi"); content = tinyMCE.regexpReplace(content, "", "", "gi"); inst.getBody().innerHTML = contentElement.innerHTML; } inst.convertAllRelativeURLs(); } else { if (tinyMCE.settings['cleanup_on_startup']) { tinyMCE._setHTML(inst.getDoc(), content); // Produces permission denied error in MSIE 5.5 eval('try {inst.getBody().innerHTML = tinyMCE._cleanupHTML(inst.contentDocument, this.settings, inst.getBody());} catch(e) {}'); } else inst.getBody().innerHTML = content; } tinyMCE._convertOnClick(inst.getBody()); // Fix for bug #957681 //inst.getDoc().designMode = inst.getDoc().designMode; // Setup element references var parentElm = document.getElementById(inst.editorId + '_parent'); if (parentElm.lastChild.nodeName.toLowerCase() == "input") inst.formElement = parentElm.lastChild; else inst.formElement = parentElm.nextSibling; tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual']); inst.executeCallback('setupcontent_callback', '_setupContent', 0, editor_id, inst.getBody(), inst.getDoc()); // Re-add design mode on mozilla if (!tinyMCE.isMSIE) TinyMCE_addEventHandlers(editor_id); // Trigger node change tinyMCE.selectedInstance = inst; inst.selectNode(inst.getBody(), true, true); tinyMCE.triggerNodeChange(false); } function TinyMCE_handleEvent(e) { //window.status = e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""); switch (e.type) { case "submit": var formObj = tinyMCE.isMSIE ? window.event.srcElement : e.target; // Disable all UI form elements that TinyMCE created for (var i=0; i"); rng.collapse(false); rng.select(); tinyMCE.triggerNodeChange(false); return false; } } // Backspace or delete if (e.keyCode == 8 || e.keyCode == 46) { tinyMCE.selectedElement = e.target; tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a"); tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img"); tinyMCE.triggerNodeChange(false); } return false; break; case "keyup": case "keydown": if (e.target.editorId) tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId]; else return; // Handle backspace if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) { // Insert P element instead of BR if (tinyMCE.selectedInstance._handleBackSpace(e.type)) { // Cancel event e.preventDefault(); return false; } } tinyMCE.selectedElement = null; tinyMCE.selectedNode = null; var elm = tinyMCE.selectedInstance.getFocusElement(); tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a"); tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img"); tinyMCE.selectedElement = elm; // Update visualaids on tabs if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9) tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings['visual']); // Run image/link fix on Gecko if diffrent document base on paste if (tinyMCE.isGecko && tinyMCE.settings['document_base_url'] != "" + document.location.href && e.type == "keyup" && e.ctrlKey && e.keyCode == 86) tinyMCE.selectedInstance.fixBrokenURLs(); // Insert space instead of   /* if (e.type == "keydown" && e.keyCode == 32) { if (tinyMCE.selectedInstance._insertSpace()) { // Cancel event e.returnValue = false; e.cancelBubble = true; return false; } }*/ // MSIE custom key handling if (tinyMCE.isMSIE && tinyMCE.settings['custom_undo_redo']) { // Check if it's a position key press var keys = new Array(13,45,36,35,33,34,37,38,39,40); var posKey = false; for (var i=0; i 18 && e.keyCode != 255)) { tinyMCE.selectedInstance.execCommand("mceAddUndoLevel"); tinyMCE.selectedInstance.typing = true; tinyMCE.triggerNodeChange(false); } if (posKey && e.type == "keyup") tinyMCE.triggerNodeChange(false); var ctrlKeys = new Array(66,73,85,86,88); // B/I/U/V/X var keys = new Array(8,46); // Backspace,Delete for (var i=0; i 0) { for (var i=0; i "; // Is MSIE script element if (tinyMCE.isMSIE && elementName == "script") return "<" + elementName + elementAttribs + ">" + node.text + ""; // Clean up children if (node.hasChildNodes()) { // Force BR if (elementName == "p" && tinyMCE.cleanup_force_br_newlines) output += ""; else output += "<" + elementName + elementAttribs + ">"; for (var i=0; i"; } else { // Allways leave anchor elements open if (elementName == "a") output += "<" + elementName + elementAttribs + ">"; else { // No children output += "<" + elementName + elementAttribs + " />"; } } return output; case 3: // Text // Do not convert script elements if (node.parentNode.nodeName.toLowerCase() == "script") return node.nodeValue; return this.convertStringToXML(node.nodeValue); case 8: // Comment return ""; default: // Unknown return "[UNKNOWN NODETYPE " + node.nodeType + "]"; } } function TinyMCE_convertStringToXML(html_data) { var output = ""; for (var i=0; i', '', 'gi'); var html = this.cleanupNode(element); if (tinyMCE.settings['debug']) alert("Cleanup process executed in: " + (new Date().getTime()-startTime) + " ms."); // Remove pesky HR paragraphs html = tinyMCE.regexpReplace(html, '


', '
'); html = tinyMCE.regexpReplace(html, '

 


 

', '
'); // Remove some mozilla crap if (!tinyMCE.isMSIE) html = html.replace(new RegExp('', 'g'), ""); if (tinyMCE.settings['apply_source_formatting']) { html = html.replace(new RegExp('<(p|div)([^>]*)>', 'g'), "\n<$1$2>\n"); html = html.replace(new RegExp('<\/(p|div)([^>]*)>', 'g'), "\n\n"); html = html.replace(new RegExp('
', 'g'), "
\n"); } if (tinyMCE.settings['force_br_newlines']) { var re = new RegExp('

 

', 'g'); html = html.replace(re, "
"); } if (tinyMCE.settings['force_p_newlines']) { // Remove weridness! var re = new RegExp('<>', 'g'); html = html.replace(re, ""); } // Emtpy node, return empty if (html == "
" || html == "

 

") html = ""; // Call custom cleanup code html = tinyMCE._customCleanup(on_save ? "get_from_editor" : "insert_to_editor", html); if (tinyMCE.settings["preformatted"]) return "
" + html + "
"; return html; } function TinyMCE_insertLink(href, target, title, onclick) { function setAttrib(element, name, value) { if (value != null && value != "") element.setAttribute(name, value); else element.removeAttribute(name); } this.execCommand("mceAddUndoLevel"); if (this.selectedInstance && this.selectedElement && this.selectedElement.nodeName.toLowerCase() == "img") { var doc = this.selectedInstance.getDoc(); var linkElement = doc.createElement("a"); href = eval(tinyMCE.settings['urlconvertor_callback'] + "(href, linkElement);"); setAttrib(linkElement, 'href', href); setAttrib(linkElement, 'target', target); setAttrib(linkElement, 'title', title); setAttrib(linkElement, 'mce_onclick', onclick); linkElement.appendChild(this.selectedElement.cloneNode(true)); this.selectedElement.parentNode.replaceChild(linkElement, this.selectedElement); return; } if (!this.linkElement && this.selectedInstance) { this.selectedInstance.contentDocument.execCommand("createlink", false, "#mce_temp_url#"); tinyMCE.linkElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", "#mce_temp_url#"); var elementArray = this.getElementsByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", "#mce_temp_url#"); for (var i=0; i= strTok2.length) { for (var i=0; i= strTok2.length || strTok1[i] != strTok2[i]) { breakPoint = i + 1; break; } } } if (strTok1.length < strTok2.length) { for (var i=0; i= strTok1.length || strTok1[i] != strTok2[i]) { breakPoint = i + 1; break; } } } if (breakPoint == 1) return url_to_relative; for (var i=0; i<(strTok1.length-(breakPoint-1)); i++) outputString += "../"; for (var i=breakPoint-1; i=0; i--) { if (baseURLParts[i].length == 0) continue; newBaseURLParts[newBaseURLParts.length] = baseURLParts[i]; } baseURLParts = newBaseURLParts.reverse(); // Merge relURLParts chunks var newRelURLParts = new Array(); var numBack = 0; for (var i=relURLParts.length-1; i>=0; i--) { if (relURLParts[i].length == 0 || relURLParts[i] == ".") continue; if (relURLParts[i] == '..') { numBack++; continue; } if (numBack > 0) { numBack--; continue; } newRelURLParts[newRelURLParts.length] = relURLParts[i]; } relURLParts = newRelURLParts.reverse(); // Remove end from absolute path var len = baseURLParts.length-numBack; var absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/'); var start = "", end = ""; // Build start part if (baseURL['protocol']) start += baseURL['protocol'] + "://"; if (baseURL['host']) start += baseURL['host']; if (baseURL['port']) start += ":" + baseURL['port']; // Build end part if (relURL['query']) end += "?" + relURL['query']; if (relURL['anchor']) end += "#" + relURL['anchor']; return start + absPath + end; } function TinyMCE_getParam(name, default_value, strip_whitespace, split_chr) { var value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name]; // Fix bool values if (value == "true" || value == "false") return (value == "true"); if (strip_whitespace) value = tinyMCE.regexpReplace(value, "[ \t\r\n]", ""); if (typeof(split_chr) != "undefined" && split_chr != null) { value = value.split(split_chr); var outArray = new Array(); for (var i=0; i 0); if (tinyMCE.settings['custom_undo_redo']) { undoIndex = inst.undoIndex; undoLevels = inst.undoLevels.length; } inst.executeCallback('handleNodeChangeCallback', '_handleNodeChange', 0, editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection); } } if (this.selectedInstance && (typeof(focus) == "undefined" || focus)) this.selectedInstance.contentWindow.focus(); } function TinyMCE__customCleanup(type, content) { // Call custom cleanup var customCleanup = tinyMCE.settings['cleanup_callback']; if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined") content = eval(customCleanup + "(type, content);"); // Trigger plugin cleanups var plugins = tinyMCE.getParam('plugins', '', true, ','); for (var i=0; i'); } function TinyMCE_importPluginLanguagePack(name, valid_languages) { var lang = "en"; valid_languages = valid_languages.split(','); for (var i=0; i'); } /** * Adds themeurl, settings and lang to HTML code. */ function TinyMCE_applyTemplate(html, args) { html = tinyMCE.replaceVar(html, "themeurl", tinyMCE.themeURL); if (typeof(args) != "undefined") html = tinyMCE.replaceVars(html, args); html = tinyMCE.replaceVars(html, tinyMCE.settings); html = tinyMCE.replaceVars(html, tinyMCELang); return html; } function TinyMCE_openWindow(template, args) { var html, width, height, x, y, resizable, scrollbars, url; args['mce_template_file'] = template['file']; tinyMCE.windowArgs = args; html = template['html']; if (!(width = template['width'])) width = 320; if (!(height = template['height'])) height = 200; // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!! if (tinyMCE.isMSIE) height += 30; x = parseInt(screen.width / 2.0) - (width / 2.0); y = parseInt(screen.height / 2.0) - (height / 2.0); resizable = (args && args['resizable']) ? args['resizable'] : "no"; scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no"; url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file']; // Replace all args as variables in URL for (var name in args) url = tinyMCE.replaceVar(url, name, escape(args[name])); if (html) { html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']); html = tinyMCE.applyTemplate(html, args); var win = window.open("", "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,minimizable=" + resizable + ",modal=yes,width=" + width + ",height=" + height + ",resizable=" + resizable); win.document.write(html); win.document.close(); win.resizeTo(width, height); win.focus(); } else { if (tinyMCE.isMSIE && resizable != 'yes') { var features = "resizable:" + resizable + ";scroll:" + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:" + width + "px;dialogHeight:" + height + "px;"; window.showModalDialog(url, window, features); } else { var win = window.open(url, "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,minimizable=" + resizable + ",modal=yes,width=" + width + ",height=" + height + ",resizable=" + resizable); eval('try { win.resizeTo(width, height); } catch(e) { }'); win.focus(); } } } function TinyMCE_handleVisualAid(element, deep, state) { function getAttrib(elm, name) { return elm.getAttribute(name) ? elm.getAttribute(name) : ""; } var tableElement = null; switch (element.nodeName.toLowerCase()) { case "table": var cssText = element.getAttribute("border") == 0 ? tinyMCE.settings['visual_table_style'] : ""; // Fix width var attribValue = getAttrib(element, "width"); if (attribValue == "") attribValue = element.clientWidth; element.setAttribute("width", attribValue); // Fix height var attribValue = getAttrib(element, "height"); if (attribValue == "") attribValue = element.clientHeight; element.setAttribute("height", attribValue); element.style.cssText = state ? cssText : ""; for (var y=0; y'; return; } break;*/ } if (deep && element.hasChildNodes()) { for (var i=0; i

breaks runtime? if (tinyMCE.isMSIE) { var re = new RegExp('


', 'g'); html_content = html_content.replace(re, "
"); } doc.body.innerHTML = html_content; // Content duplication bug fix if (tinyMCE.isMSIE && tinyMCE.settings['fix_content_duplication']) { // Remove P elements in P elements var paras = doc.getElementsByTagName("P"); for (var i=0; i<\/o:p>", "
"); html = tinyMCE.regexpReplace(html, " <\/o:p>", ""); html = tinyMCE.regexpReplace(html, "", ""); html = tinyMCE.regexpReplace(html, "

<\/p>", ""); html = tinyMCE.regexpReplace(html, "

<\/p>\r\n

<\/p>", ""); html = tinyMCE.regexpReplace(html, "

 <\/p>", "
"); html = tinyMCE.regexpReplace(html, "

\s*(

\s*)?", "

"); html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "

"); } // Always set the htmlText output doc.body.innerHTML = html; } } function TinyMCE__getElementById(element_id) { var elm = document.getElementById(element_id); if (!elm) { // Check for element in forms for (var j=0; j 0) { var csses = null; // Just ignore any errors eval("try {var csses = tinyMCE.isMSIE ? doc.styleSheets(0).rules : doc.styleSheets[0].cssRules;} catch(e) {}"); if (!csses) return null; for (var i=0; i 0) tinyMCE.cssClasses = output; return output; } function TinyMCE_regexpReplace(in_str, reg_exp, replace_str, opts) { if (typeof(opts) == "undefined") opts = 'g'; var re = new RegExp(reg_exp, opts); return in_str.replace(re, replace_str); } function TinyMCE_cleanupEventStr(str) { str = "" + str; str = str.replace('function anonymous()\n{\n', ''); str = str.replace('\n}', ''); return str; } function TinyMCE_getAbsPosition(node) { var x = 0, y = 0; var pos = new Object(); var parentNode = node; while (parentNode) { x += parentNode.offsetLeft; y += parentNode.offsetTop; parentNode = parentNode.offsetParent; } pos.absLeft = x; pos.absTop = y; return pos; } function TinyMCE_openFileBrowser(field_name, url, type, win) { var cb = tinyMCE.getParam("file_browser_callback"); this.setWindowArg("window", win); // Call to external callback if(eval('typeof('+cb+')') == "undefined") alert("Callback function: " + cb + " could not be found."); else eval(cb + "(field_name, url, type, win);"); } function TinyMCE_getControlHTML(control_name) { var themePlugins = tinyMCE.getParam('plugins', '', true, ','); var templateFunction; // Is it defined in any plugins for (var i=themePlugins.length; i>=0; i--) { templateFunction = 'TinyMCE_' + themePlugins[i] + "_getControlHTML"; if (eval("typeof(" + templateFunction + ")") != 'undefined') { var html = eval(templateFunction + "('" + control_name + "');"); if (html != "") return tinyMCE.replaceVar(html, "pluginurl", tinyMCE.baseURL + "/plugins/" + themePlugins[i]); } } return eval('TinyMCE_' + tinyMCE.settings['theme'] + "_getControlHTML" + "('" + control_name + "');"); } function TinyMCE__themeExecCommand(editor_id, element, command, user_interface, value) { var themePlugins = tinyMCE.getParam('plugins', '', true, ','); var templateFunction; // Is it defined in any plugins for (var i=themePlugins.length; i>=0; i--) { templateFunction = 'TinyMCE_' + themePlugins[i] + "_execCommand"; if (eval("typeof(" + templateFunction + ")") != 'undefined') { if (eval(templateFunction + "(editor_id, element, command, user_interface, value);")) return true; } } // Theme funtion templateFunction = 'TinyMCE_' + tinyMCE.settings['theme'] + "_execCommand"; if (eval("typeof(" + templateFunction + ")") != 'undefined') return eval(templateFunction + "(editor_id, element, command, user_interface, value);"); // Pass to normal return false; } function TinyMCE__getThemeFunction(suffix, skip_plugins) { if (skip_plugins) return 'TinyMCE_' + tinyMCE.settings['theme'] + suffix; var themePlugins = tinyMCE.getParam('plugins', '', true, ','); var templateFunction; // Is it defined in any plugins for (var i=themePlugins.length; i>=0; i--) { templateFunction = 'TinyMCE_' + themePlugins[i] + suffix; if (eval("typeof(" + templateFunction + ")") != 'undefined') return templateFunction; } return 'TinyMCE_' + tinyMCE.settings['theme'] + suffix; } // TinyMCEControl function TinyMCEControl(settings) { // Undo levels this.undoLevels = new Array(); this.undoIndex = 0; // Default settings this.settings = settings; this.settings['theme'] = tinyMCE.getParam("theme", "default"); this.settings['width'] = tinyMCE.getParam("width", -1); this.settings['height'] = tinyMCE.getParam("height", -1); // Functions this.executeCallback = TinyMCEControl_executeCallback; this.fixBrokenURLs = TinyMCEControl_fixBrokenURLs; this.convertAllRelativeURLs = TinyMCEControl_convertAllRelativeURLs; this.execCommand = TinyMCEControl_execCommand; this.queryCommandValue = TinyMCEControl_queryCommandValue; this.queryCommandState = TinyMCEControl_queryCommandState; this.onAdd = TinyMCEControl_onAdd; this.getFocusElement = TinyMCEControl_getFocusElement; this.autoResetDesignMode = TinyMCEControl_autoResetDesignMode; this._insertPara = TinyMCEControl__insertPara; this._insertSpace = TinyMCEControl__insertSpace; this._handleBackSpace = TinyMCEControl__handleBackSpace; this.selectNode = TinyMCEControl_selectNode; this.getBody = TinyMCEControl_getBody; this.getDoc = TinyMCEControl_getDoc; this.getWin = TinyMCEControl_getWin; this.getSel = TinyMCEControl_getSel; this.getRng = TinyMCEControl_getRng; } function TinyMCEControl_executeCallback(param, suffix, mode) { function isFunc(func_name) { if (func_name == null || func_name == "") return false; return eval("typeof(" + func_name + ")") != "undefined"; } function exec(func_name, args) { var str = func_name + '('; // Add all arguments for (var i=3; i 0) rng.selectNodeContents(nodes[0]); else rng.selectNodeContents(node); } else rng.selectNode(node); if (collapse) { // Special treatment of textnode collapse if (!to_start && node.nodeType == 3) { rng.setStart(node, node.nodeValue.length); rng.setEnd(node, node.nodeValue.length); } else rng.collapse(to_start); } sel.removeAllRanges(); sel.addRange(rng); } // Scroll to node position var pos = tinyMCE.getAbsPosition(node); var doc = this.getDoc(); var scrollX = doc.body.scrollLeft + doc.documentElement.scrollLeft; var scrollY = doc.body.scrollTop + doc.documentElement.scrollTop; var height = tinyMCE.isMSIE ? document.getElementById(this.editorId).style.pixelHeight : parseInt(this.targetElement.style.height); // Only scroll if out of visible area if (!tinyMCE.settings['auto_resize'] && !(node.absTop > scrollY && node.absTop < (scrollY - 25 + height))) this.contentWindow.scrollTo(pos.absLeft, pos.absTop - height + 25); // Set selected element tinyMCE.selectedElement = null; if (node.nodeType == 1) tinyMCE.selectedElement = node; } function TinyMCEControl_getBody() { return this.getDoc().body; } function TinyMCEControl_getDoc() { return this.contentWindow.document; } function TinyMCEControl_getWin() { return this.contentWindow; } function TinyMCEControl_getSel() { if (tinyMCE.isMSIE) return this.getDoc().selection; return this.contentWindow.getSelection(); } function TinyMCEControl_getRng() { var sel = this.getSel(); if (sel == null) return null; if (tinyMCE.isMSIE) return sel.createRange(); return this.getSel().getRangeAt(0); } function TinyMCEControl__insertPara() { function getNodeText(node) { var nodes = tinyMCE.getNodeTree(node, new Array(), 3); var text = ""; for (var i=0; i") paraBefore.innerHTML = " "; // Check if it's a empty paragraph if (getNodeText(paraAfter) == "" || paraAfter.innerHTML == "
") paraAfter.innerHTML = " "; // Delete old contents rngBefore.deleteContents(); rng.deleteContents(); // Insert new paragraphs paraAfter.normalize(); rng.insertNode(paraAfter); paraBefore.normalize(); rngBefore.insertNode(paraBefore); } else { body.innerHTML = "

 

 

"; paraAfter = body.childNodes[1]; } this.selectNode(paraAfter, true, true); //showHTML(this.getBody().innerHTML); return true; } // Place first part within new paragraph rngBefore.setStartBefore(startChop); rngBefore.setEnd(startNode, startOffset); paraBefore.appendChild(rngBefore.cloneContents()); // Place secound part within new paragraph rngAfter.setEndAfter(endChop); rngAfter.setStart(endNode, endOffset); paraAfter.appendChild(rngAfter.cloneContents()); // Check if it's a empty paragraph if (getNodeText(paraBefore) == "" || paraBefore.innerHTML == "
") paraBefore.innerHTML = " "; // Check if it's a empty paragraph if (getNodeText(paraAfter) == "" || paraAfter.innerHTML == "
") paraAfter.innerHTML = " "; // Create a range around everything var rng = doc.createRange(); if (!startChop.previousSibling && startChop.parentNode.nodeName.toLowerCase() == 'p') rng.setStartBefore(startChop.parentNode); else { if (rngBefore.startContainer.nodeName.toLowerCase() == 'p' && rngBefore.startOffset == 0) rng.setStartBefore(rngBefore.startContainer); else rng.setStart(rngBefore.startContainer, rngBefore.startOffset); } if (!endChop.nextSibling && endChop.parentNode.nodeName.toLowerCase() == 'p') rng.setEndAfter(endChop.parentNode); else rng.setEnd(rngAfter.endContainer, rngAfter.endOffset); // Delete all contents and insert new paragraphs rng.deleteContents(); rng.insertNode(paraAfter); rng.insertNode(paraBefore); paraAfter.normalize(); paraBefore.normalize(); this.selectNode(paraAfter, true, true); //showHTML(this.getBody().innerHTML); return true; } function TinyMCEControl__handleBackSpace(evt_type) { var doc = this.getDoc(); var sel = this.contentWindow.getSelection(); if (sel == null) return false; var rng = sel.getRangeAt(0); var node = rng.startContainer; var elm = node.nodeType == 3 ? node.parentNode : node; if (node == null) return; // Empty node, wrap contents in paragraph if (elm && elm.nodeName == "") { var para = doc.createElement("p"); while (elm.firstChild) para.appendChild(elm.firstChild); elm.parentNode.insertBefore(para, elm); elm.parentNode.removeChild(elm); var rng = rng.cloneRange(); rng.setStartBefore(node.nextSibling); rng.setEndAfter(node.nextSibling); rng.extractContents(); this.selectNode(node.nextSibling, true, true); } // Remove empty paragraphs var para = tinyMCE.getParentBlockElement(node); if (para != null && para.nodeName.toLowerCase() == 'p' && evt_type == "keypress") { var htm = para.innerHTML; var block = tinyMCE.getParentBlockElement(node); // Empty node, we do the killing!! if (htm == "" || htm == " " || block.nodeName.toLowerCase() == "li") { var prevElm = para.previousSibling; while (prevElm != null && prevElm.nodeType != 1) prevElm = prevElm.previousSibling; if (prevElm == null) return false; // Get previous elements last text node var nodes = tinyMCE.getNodeTree(prevElm, new Array(), 3); var lastTextNode = nodes.length == 0 ? null : nodes[nodes.length-1]; // Select the last text node and move curstor to end if (lastTextNode != null) this.selectNode(lastTextNode, true, false, false); // Remove the empty paragrapsh para.parentNode.removeChild(para); //debug("within p element" + para.innerHTML); //showHTML(this.getBody().innerHTML); return true; } } // Remove BR elements /* while (node != null && (node = node.nextSibling) != null) { if (node.nodeName.toLowerCase() == 'br') node.parentNode.removeChild(node); else if (node.nodeType == 1) // Break at other element break; }*/ //showHTML(this.getBody().innerHTML); return false; } function TinyMCEControl__insertSpace() { return true; } function TinyMCEControl_autoResetDesignMode() { // Add fix for tab/style.display none/block problems in Gecko if (!tinyMCE.isMSIE && tinyMCE.settings['auto_reset_designmode']) { var sel = this.contentWindow.getSelection(); // Weird, wheres that cursor selection? if (!sel || !sel.rangeCount || sel.rangeCount == 0) eval('try { this.getDoc().designMode = "On"; } catch(e) {}'); } } function TinyMCEControl_execCommand(command, user_interface, value) { function getAttrib(elm, name) { return elm.getAttribute(name) ? elm.getAttribute(name) : ""; } // Mozilla issue if (!tinyMCE.isMSIE && !this.useCSS) { this.getDoc().execCommand("useCSS", false, true); this.useCSS = true; } //alert("command: " + command + ", user_interface: " + user_interface + ", value: " + value); this.contentDocument = this.getDoc(); // <-- Strange!! // Call theme execcommand if (tinyMCE._themeExecCommand(this.editorId, this.contentDocument.body, command, user_interface, value)) return; // Add undo level of operation if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceImage" && command != "mceLink" && command != "mceToggleVisualAid" && (command != "mceInsertTable" && !user_interface)) this.execCommand("mceAddUndoLevel"); // Fix align on images if (this.getFocusElement() && this.getFocusElement().nodeName.toLowerCase() == "img") { var align = this.getFocusElement().getAttribute('align'); switch (command) { case "JustifyLeft": if (align == 'left') this.getFocusElement().removeAttribute('align'); else this.getFocusElement().setAttribute('align', 'left'); tinyMCE.triggerNodeChange(); return; case "JustifyCenter": if (align == 'middle') this.getFocusElement().removeAttribute('align'); else this.getFocusElement().setAttribute('align', 'middle'); tinyMCE.triggerNodeChange(); return; case "JustifyRight": if (align == 'right') this.getFocusElement().removeAttribute('align'); else this.getFocusElement().setAttribute('align', 'right'); tinyMCE.triggerNodeChange(); return; } } if (tinyMCE.settings['force_br_newlines']) { var doc = this.getDoc(); var alignValue = ""; if (doc.selection.type != "Control") { switch (command) { case "JustifyLeft": alignValue = "left"; break; case "JustifyCenter": alignValue = "center"; break; case "JustifyFull": alignValue = "justify"; break; case "JustifyRight": alignValue = "right"; break; } if (alignValue != "") { var rng = doc.selection.createRange(); if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null) divElm.setAttribute("align", alignValue); else if (rng.pasteHTML && rng.htmlText.length > 0) rng.pasteHTML('
' + rng.htmlText + "
"); tinyMCE.triggerNodeChange(); return; } } } switch (command) { case "mceSelectNode": this.selectNode(value); tinyMCE.triggerNodeChange(); tinyMCE.selectedNode = value; break; case "mceSelectNodeDepth": var parentNode = this.getFocusElement(); for (var i=0; parentNode; i++) { if (parentNode.nodeName.toLowerCase() == "body") break; if (parentNode.nodeName.toLowerCase() == "#text") { i--; parentNode = parentNode.parentNode; continue; } if (i == value) { this.selectNode(parentNode, false); tinyMCE.triggerNodeChange(); tinyMCE.selectedNode = parentNode; return; } parentNode = parentNode.parentNode; } break; case "HiliteColor": if (tinyMCE.isGecko) { this.contentDocument.execCommand("useCSS", false, false); this.contentDocument.execCommand('hilitecolor', false, value); this.contentDocument.execCommand("useCSS", false, true); } else this.contentDocument.execCommand('backcolor', false, value); break; case "Cut": case "Copy": case "Paste": var cmdFailed = false; // Try executing command eval('try {this.contentDocument.execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}'); // Alert error in gecko if command failed if (tinyMCE.isGecko && cmdFailed) { // Confirm more info if (confirm(tinyMCE.getLang('lang_clipboard_msg'))) window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal'); return; } else tinyMCE.triggerNodeChange(); break; case "mceLink": var selectedText = ""; if (tinyMCE.isMSIE) { var doc = this.getDoc(); var rng = doc.selection.createRange(); selectedText = rng.text; } else selectedText = this.contentWindow.getSelection().toString(); if (!tinyMCE.linkElement) { if ((tinyMCE.selectedElement.nodeName.toLowerCase() != "img") && (selectedText.length <= 0)) return; } var href = "", target = "", title = "", onclick = "", action = "insert"; if (tinyMCE.selectedElement.nodeName.toLowerCase() == "a") tinyMCE.linkElement = tinyMCE.selectedElement; // Is anchor not a link if (tinyMCE.linkElement != null && getAttrib(tinyMCE.linkElement, 'href') == "") tinyMCE.linkElement = null; if (tinyMCE.linkElement) { href = getAttrib(tinyMCE.linkElement, 'href'); target = getAttrib(tinyMCE.linkElement, 'target'); title = getAttrib(tinyMCE.linkElement, 'title'); onclick = getAttrib(tinyMCE.linkElement, 'mce_onclick'); // Try old onclick to if copy/pasted content if (onclick == "") onclick = getAttrib(tinyMCE.linkElement, 'onclick'); onclick = tinyMCE.cleanupEventStr(onclick); // Fix for drag-drop/copy paste bug in Mozilla mceRealHref = getAttrib(tinyMCE.linkElement, 'mce_real_href'); if (mceRealHref != "") href = mceRealHref; href = eval(tinyMCE.settings['urlconvertor_callback'] + "(href, tinyMCE.linkElement, true);"); action = "update"; } if (this.settings['insertlink_callback']) { var returnVal = eval(this.settings['insertlink_callback'] + "(href, target, title, onclick, action);"); if (returnVal && returnVal['href']) tinyMCE.insertLink(returnVal['href'], returnVal['target'], returnVal['title'], returnVal['onclick']); } else { tinyMCE.openWindow(this.insertLinkTemplate, {href : href, target : target, title : title, onclick : onclick, action : action}); } break; case "mceImage": var src = "", alt = "", border = "", hspace = "", vspace = "", width = "", height = "", align = ""; var title = "", onmouseover = "", onmouseout = "", action = "insert"; if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") tinyMCE.imgElement = tinyMCE.selectedElement; if (tinyMCE.imgElement) { // Is it a internal MCE visual aid image, then skip this one. var imgName = getAttrib(tinyMCE.imgElement, 'name'); if (imgName.substring(0, 4)=='mce_') return; src = getAttrib(tinyMCE.imgElement, 'src'); alt = getAttrib(tinyMCE.imgElement, 'alt'); // Try polling out the title if (alt == "") alt = getAttrib(tinyMCE.imgElement, 'title'); border = getAttrib(tinyMCE.imgElement, 'border'); hspace = getAttrib(tinyMCE.imgElement, 'hspace'); vspace = getAttrib(tinyMCE.imgElement, 'vspace'); width = getAttrib(tinyMCE.imgElement, 'width'); height = getAttrib(tinyMCE.imgElement, 'height'); align = getAttrib(tinyMCE.imgElement, 'align'); onmouseover = getAttrib(tinyMCE.imgElement, 'onmouseover'); onmouseout = getAttrib(tinyMCE.imgElement, 'onmouseout'); title = getAttrib(tinyMCE.imgElement, 'title'); onmouseover = tinyMCE.cleanupEventStr(onmouseover); onmouseout = tinyMCE.cleanupEventStr(onmouseout); // Fix for drag-drop/copy paste bug in Mozilla mceRealSrc = getAttrib(tinyMCE.imgElement, 'mce_real_src'); if (mceRealSrc != "") src = mceRealSrc; src = eval(tinyMCE.settings['urlconvertor_callback'] + "(src, tinyMCE.imgElement, true);"); action = "update"; } if (this.settings['insertimage_callback']) { var returnVal = eval(this.settings['insertimage_callback'] + "(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout, action);"); if (returnVal && returnVal['src']) tinyMCE.insertImage(returnVal['src'], returnVal['alt'], returnVal['border'], returnVal['hspace'], returnVal['vspace'], returnVal['width'], returnVal['height'], returnVal['align'], returnVal['title'], returnVal['onmouseover'], returnVal['onmouseout']); } else tinyMCE.openWindow(this.insertImageTemplate, {src : src, alt : alt, border : border, hspace : hspace, vspace : vspace, width : width, height : height, align : align, title : title, onmouseover : onmouseover, onmouseout : onmouseout, action : action}); break; case "mceCleanupWord": if (tinyMCE.isMSIE) { var html = this.contentDocument.body.createTextRange().htmlText; if (html.indexOf('="mso') != -1) { tinyMCE._setHTML(this.contentDocument, this.contentDocument.body.innerHTML); html = tinyMCE._cleanupHTML(this.contentDocument, this.settings, this.contentDocument.body, this.visualAid); } this.contentDocument.body.innerHTML = html; } break; case "mceCleanup": tinyMCE._setHTML(this.contentDocument, this.contentDocument.body.innerHTML); this.contentDocument.body.innerHTML = tinyMCE._cleanupHTML(this.contentDocument, this.settings, this.contentDocument.body, this.visualAid); tinyMCE.triggerNodeChange(); break; case "mceAnchor": if (!user_interface) { var aElm = tinyMCE.getParentElement(this.getFocusElement(), "a", "name"); if (aElm) { if (value == null || value == "") { if (tinyMCE.isMSIE) { aElm.outerHTML = aElm.innerHTML; } else { var rng = aElm.ownerDocument.createRange(); rng.setStartBefore(aElm); rng.setEndAfter(aElm); rng.deleteContents(); rng.insertNode(rng.createContextualFragment(aElm.innerHTML)); } } else aElm.setAttribute('name', value); } else { this.contentDocument.execCommand("fontname", false, "#mce_temp_font#"); var elementArray = tinyMCE.getElementsByAttributeValue(this.contentDocument.body, "font", "face", "#mce_temp_font#"); for (var x=0; x 0) { value = tinyMCE.replaceVar(value, "selection", selectedText); tinyMCE.execCommand('mceInsertContent',false,value); } tinyMCE.triggerNodeChange(); break; case "mceSetAttribute": if (typeof(value) == 'object') { var targetElms = (typeof(value['targets']) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value['targets']; var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms); if (targetNode) { targetNode.setAttribute(value['name'], value['value']); tinyMCE.triggerNodeChange(); } } break; case "mceSetCSSClass": var selectedText = false; if (tinyMCE.isMSIE) { var doc = this.getDoc(); var rng = doc.selection.createRange(); selectedText = (rng.text && rng.text.length > 0); } else selectedText = (this.contentWindow.getSelection().toString().length > 0); // Use selectedNode instead if defined if (tinyMCE.selectedNode) tinyMCE.selectedElement = tinyMCE.selectedNode; if (selectedText && !tinyMCE.selectedNode) { this.contentDocument.execCommand("removeformat", false, null); this.contentDocument.execCommand("fontname", false, "#mce_temp_font#"); var elementArray = tinyMCE.getElementsByAttributeValue(this.contentDocument.body, "font", "face", "#mce_temp_font#"); /* this.contentDocument.execCommand("createlink", false, "#mce_temp_url#"); var elementArray = tinyMCE.getElementsByAttributeValue(this.contentDocument.body, "a", "href", "#mce_temp_url#"); */ // Change them all for (var x=0; x customUndoLevels) { for (var i=0; i 0) { this.undoIndex--; this.getBody().innerHTML = this.undoLevels[this.undoIndex]; } //window.status = "Undo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex; tinyMCE.triggerNodeChange(); } else this.contentDocument.execCommand(command, user_interface, value); break; case "Redo": if (tinyMCE.settings['custom_undo_redo']) { if (this.undoIndex < (this.undoLevels.length-1)) { this.undoIndex++; this.getBody().innerHTML = this.undoLevels[this.undoIndex]; //window.status = "Redo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex; } tinyMCE.triggerNodeChange(); } else this.contentDocument.execCommand(command, user_interface, value); break; case "mceToggleVisualAid": this.visualAid = !this.visualAid; tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid); tinyMCE.triggerNodeChange(); break; /* case "removeformat": //this.contentDocument.execCommand('FormatBlock', user_interface, ''); var doc = this.getDoc(); var rng = doc.selection.createRange(); var elm = rng.item ? rng.item(0) : rng.parentElement(); html = "" + rng.text + "<" + elm.nodeName + ">"; this.contentDocument.execCommand('FontName', user_interface, '#mce_temp_name#'); var html = this.contentDocument.innerHTML; html.replace('' + editorTemplate['html']; var templateFunction = tinyMCE._getThemeFunction('_handleNodeChange', true); if (eval("typeof(" + templateFunction + ")") != 'undefined') this.settings['handleNodeChangeCallback'] = templateFunction; html = tinyMCE.replaceVar(html, "editor_id", this.editorId); html = tinyMCE.replaceVar(html, "default_document", tinyMCE.baseURL + "/blank.htm"); this.settings['default_document'] = tinyMCE.baseURL + "/blank.htm"; this.settings['old_width'] = this.settings['width']; this.settings['old_height'] = this.settings['height']; // Set default width, height if (this.settings['width'] == -1) this.settings['width'] = replace_element.offsetWidth; if (this.settings['height'] == -1) this.settings['height'] = replace_element.offsetHeight; // If no width/height then default to 320x240, better than nothing if (replace_element.offsetWidth == 0) this.settings['width'] = 320; if (replace_element.offsetHeight == 0) this.settings['height'] = 240; this.settings['area_width'] = this.settings['width']; this.settings['area_height'] = this.settings['height']; this.settings['area_width'] += deltaWidth; this.settings['area_height'] += deltaHeight; // Special % handling if (("" + this.settings['width']).indexOf('%') != -1) this.settings['area_width'] = "100%"; if (("" + this.settings['height']).indexOf('%') != -1) this.settings['area_height'] = "100%"; if (("" + replace_element.style.width).indexOf('%') != -1) { this.settings['width'] = replace_element.style.width; this.settings['area_width'] = "100%"; } if (("" + replace_element.style.height).indexOf('%') != -1) { this.settings['height'] = replace_element.style.height; this.settings['area_height'] = "100%"; } html = tinyMCE.applyTemplate(html); this.settings['width'] = this.settings['old_width']; this.settings['height'] = this.settings['old_height']; this.visualAid = this.settings['visual']; this.formTargetElementId = form_element_name; // Get replace_element contents if (replace_element.nodeName.toLowerCase() == "textarea") this.startContent = replace_element.value; else this.startContent = replace_element.innerHTML; // If not text area if (replace_element.nodeName.toLowerCase() != "textarea") { this.oldTargetElement = replace_element.cloneNode(true); // Debug mode if (tinyMCE.settings['debug']) html += ''; else html += ''; html += ''; // Output HTML and set editable if (!tinyMCE.isMSIE) { var rng = replace_element.ownerDocument.createRange(); rng.setStartBefore(replace_element); var fragment = rng.createContextualFragment(html); replace_element.parentNode.replaceChild(fragment, replace_element); } else replace_element.outerHTML = html; } else { html += ''; // Just hide the textarea element this.oldTargetElement = replace_element; if (!tinyMCE.settings['debug']) this.oldTargetElement.style.display = "none"; // Output HTML and set editable if (!tinyMCE.isMSIE) { var rng = replace_element.ownerDocument.createRange(); rng.setStartBefore(replace_element); var fragment = rng.createContextualFragment(html); replace_element.parentNode.insertBefore(fragment, replace_element); } else replace_element.insertAdjacentHTML("beforeBegin", html); } // Setup iframe var dynamicIFrame = false; var tElm = targetDoc.getElementById(this.editorId); if (!tinyMCE.isMSIE) { if (tElm && tElm.nodeName.toLowerCase() == "span") { tElm = tinyMCE._createIFrame(tElm); dynamicIFrame = true; } this.targetElement = tElm; this.iframeElement = tElm; this.contentDocument = tElm.contentDocument; this.contentWindow = tElm.contentWindow; //this.getDoc().designMode = "on"; } else { if (tElm && tElm.nodeName.toLowerCase() == "span") tElm = tinyMCE._createIFrame(tElm); else tElm = targetDoc.frames[this.editorId]; this.targetElement = tElm; this.iframeElement = targetDoc.getElementById(this.editorId); this.contentDocument = tElm.window.document; this.contentWindow = tElm.window; this.contentDocument.designMode = "on"; } // Setup base HTML var doc = this.contentDocument; if (dynamicIFrame) { var html = "" + '' + '' + '' + '' + 'blank_page' + '' + '' + '' + '' + ''; try { this.getDoc().designMode = "on"; doc.open(); doc.write(html); doc.close(); } catch (e) { // Failed Mozilla 1.3 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm"; } } // This timeout is needed in MSIE 5.5 for some odd reason // it seems that the document.frames isn't initialized yet? if (tinyMCE.isMSIE) window.setTimeout("TinyMCE_addEventHandlers('" + this.editorId + "');", 1); //window.setTimeout("tinyMCE.setupContent('" + this.editorId + "');", (tinyMCE.isMSIE ? 1 : 1000)); tinyMCE.setupContent(this.editorId); return true; } function TinyMCEControl_getFocusElement() { if (tinyMCE.isMSIE) { var doc = this.getDoc(); var rng = doc.selection.createRange(); var elm = rng.item ? rng.item(0) : rng.parentElement(); } else { var sel = this.contentWindow.getSelection(); var elm = (sel && sel.anchorNode) ? sel.anchorNode : null; if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") elm = tinyMCE.selectedElement; } return elm; } // Global instances var tinyMCE = new TinyMCE(); var tinyMCELang = new Array();