/** * $RCSfile$ * $Revision$ * $Date$ * * @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.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.createMCEControl = TinyMCE_createMCEControl; 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.setEditMode = TinyMCE_setEditMode; 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.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.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.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._selectNode = TinyMCE__selectNode; 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.getCSSClasses = TinyMCE_getCSSClasses; this.regexpReplace = TinyMCE_regexpReplace; this.cleanupEventStr = TinyMCE_cleanupEventStr; } function TinyMCE_init(settings) { var theme; // 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) { if (tinyMCE.isMSIE) var targetElement = event.srcElement; else var targetElement = e.target; var elementId = targetElement.name ? targetElement.name : targetElement.id; if (!targetElement.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm'])) tinyMCE.addMCEControl(targetElement, elementId, tinyMCE.createMCEControl(tinyMCE.settings)); 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 instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; if (instance.formElement == formElement) { tinyMCE._setHTML(instance.contentWindow.document, instance.formElement.value); if (!tinyMCE.isMSIE) instance.contentWindow.document.body.innerHTML = tinyMCE._cleanupHTML(instance.contentWindow.document, this.settings, instance.contentWindow.document.body, instance.visualAid); } } } function TinyMCE_addMCEControl(replace_element, form_element_name, mce_control) { var editorId = "mce_editor_" + tinyMCE.idCounter++; mce_control.editorId = editorId; this.instances[editorId] = mce_control; mce_control.onAdd(replace_element, form_element_name); } function TinyMCE_createMCEControl(settings) { return new TinyMCEControl(settings); } function TinyMCE_triggerSave(skip_cleanup) { // Cleanup and set all form fields for (var instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; tinyMCE.settings['preformatted'] = false; // Default to false if (typeof(skip_cleanup) == "undefined") skip_cleanup = false; tinyMCE._setHTML(instance.contentWindow.document, instance.contentWindow.document.body.innerHTML); var cleanedHTML = skip_cleanup ? instance.contentWindow.document.body.innerHTML : tinyMCE._cleanupHTML(instance.contentWindow.document, this.settings, instance.contentWindow.document.body, this.visualAid, true); //var cleanedHTML = tinyMCE._cleanupHTML(instance.contentWindow.document, tinyMCE.settings, instance.contentWindow.document.body, false, true); if (tinyMCE.settings["encoding"] == "xml" || tinyMCE.settings["encoding"] == "html") cleanedHTML = tinyMCE.convertStringToXML(cleanedHTML); if (tinyMCE.settings['save_callback'] != "") var content = eval(tinyMCE.settings['save_callback'] + "(instance.formTargetElementId,cleanedHTML,instance.contentWindow.document.body);"); // Use callback content if available if ((typeof(content) != "undefined") && content != null) cleanedHTML = content; // Replace some weird entities (Bug: #1056343) cleanedHTML = tinyMCE.regexpReplace(cleanedHTML, "(", "(", "gi"); cleanedHTML = tinyMCE.regexpReplace(cleanedHTML, ")", ")", "gi"); cleanedHTML = tinyMCE.regexpReplace(cleanedHTML, ";", ";", "gi"); cleanedHTML = tinyMCE.regexpReplace(cleanedHTML, """, """, "gi"); cleanedHTML = tinyMCE.regexpReplace(cleanedHTML, "^", "^", "gi"); //alert(cleanedHTML); instance.formElement.value = cleanedHTML; } } 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' + '' + '' + 'blank_page' + '' + '' + '' + '' + ''; try { targetMCEControl.contentWindow.document.designMode = "on"; doc.open(); doc.write(html); doc.close(); } catch (e) { // Failed Mozilla 1.3 targetMCEControl.contentWindow.document.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('" + editor_id + "');", 1); //window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", (tinyMCE.isMSIE ? 1 : 1000)); tinyMCE.setupContent(editor_id); } function TinyMCE_setupContent(editor_id) { var instance = tinyMCE.instances[editor_id]; var doc = instance.contentWindow.document; var head = doc.getElementsByTagName('head').item(0); // Not loaded correctly hit it again, Mozilla bug #997860 if (!tinyMCE.isMSIE && doc.title != "blank_page") { // This part will remove the designMode status doc.location.href = tinyMCE.baseURL + "/blank.htm"; window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000); return; } if (!head) { window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10); return; } doc.body.dir = this.settings['directionality']; doc.editorId = editor_id; // Add on document element in Mozilla if (!tinyMCE.isMSIE) doc.documentElement.editorId = editor_id; // Setup base element base = doc.createElement("base"); base.setAttribute('href', tinyMCE.settings['base_href']); head.appendChild(base); var oldElement = instance.oldTargetElement; if (oldElement.nodeName.toLowerCase() == "textarea") var content = oldElement.value; else var content = instance.oldTargetElement.innerHTML; instance.startContent = content; // Replace new line characters to BRs if (tinyMCE.settings['convert_newlines_to_brs']) { content = tinyMCE.regexpReplace(content, "\r\n", "
", "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(instance.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); }; document.frames[editor_id].document.body.onbeforepaste = patchFunc; document.frames[editor_id].document.body.onbeforecut = patchFunc; document.frames[editor_id].document.body.onpaste = patchFunc; document.frames[editor_id].document.body.editorId = editor_id; } else { var targetDocument = document.getElementById(editor_id).contentWindow.document; // Import editor css var cssImporter = targetDocument.createElement("link"); cssImporter.rel = "stylesheet"; cssImporter.href = instance.settings['content_css']; if (headArr = targetDocument.getElementsByTagName("head")); headArr[0].appendChild(cssImporter); } // Fix for bug #958637 if (!tinyMCE.isMSIE) { if (tinyMCE.settings['cleanup_on_startup']) { var contentElement = instance.contentWindow.document.createElement("body"); contentElement.innerHTML = content; instance.contentWindow.document.body.innerHTML = tinyMCE._cleanupHTML(instance.contentWindow.document, this.settings, contentElement); } else { var contentElement = instance.contentWindow.document.createElement("body"); var doc = instance.contentWindow.document; // Convert all strong/em to b/i content = tinyMCE.regexpReplace(content, "", "", "gi"); content = tinyMCE.regexpReplace(content, "", "", "gi"); contentElement.innerHTML = content; // Convert img src nodes var elms = contentElement.getElementsByTagName("img"); for (var i=0; i"); rng.collapse(false); rng.select(); } } // 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; tinyMCE.selectedElement = null; var elm = tinyMCE.selectedInstance.getFocusElement(); tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a"); tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img"); tinyMCE.selectedElement = elm; // 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 // 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, "
"); } // 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.contentWindow.document; 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); if (tinyMCE.settings['custom_undo_redo']) { undoIndex = tinyMCE.selectedInstance.undoIndex; undoLevels = tinyMCE.selectedInstance.undoLevels.length; } // Trigger plugin nodechanges var plugins = tinyMCE.getParam('plugins', '', true, ','); for (var i=0; i'); } function TinyMCE_importPluginLanguagePack(theme_name, valid_languages) { var lang = "uk"; 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, skip_lang) { var html, width, height, x, y, resizable, scrollbars, url; 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']; if (html) { html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']); html = tinyMCE.applyTemplate(html, args, skip_lang); var win = window.open("", "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",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 + ",modal=yes,width=" + width + ",height=" + height + ",resizable=" + resizable); win.resizeTo(width, height); win.focus(); } } } function TinyMCE_handleVisualAid(element, deep, state) { var tableElement = null; // Remove visual aid elements /* if (!state && element.getAttribute && element.getAttribute('mceVisualAid') == "true") { element.parentNode.removeChild(element); return; }*/ switch (element.nodeName.toLowerCase()) { case "table": var cssText = element.getAttribute("border") == 0 ? tinyMCE.settings['visual_table_style'] : ""; 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.replace('function anonymous()\n{\n', ''); str = str.replace('\n}', ''); return str; } // 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.execCommand = TinyMCEControl_execCommand; this.queryCommandValue = TinyMCEControl_queryCommandValue; this.queryCommandState = TinyMCEControl_queryCommandState; this.onAdd = TinyMCEControl_onAdd; this.getFocusElement = TinyMCEControl_getFocusElement; this.autoResetDesignMode = TinyMCEControl_autoResetDesignMode; } 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(); // Werid, where that cursor selection if (sel.rangeCount == 0) this.contentWindow.document.designMode = "On"; } } 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.contentWindow.document.execCommand("useCSS", false, true); this.useCSS = true; } //alert("command: " + command + ", user_interface: " + user_interface + ", value: " + value); this.contentDocument = this.contentWindow.document; // <-- 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 documentRef = this.contentWindow.document; var alignValue = ""; if (documentRef.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 = documentRef.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 "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 documentRef = this.contentWindow.document; var rng = documentRef.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. name = getAttrib(tinyMCE.imgElement, 'name'); if (name.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); var cleanedHTML = tinyMCE._cleanupHTML(this.contentDocument, this.settings, this.contentDocument.body, this.visualAid); this.contentDocument.body.innerHTML = cleanedHTML; break; case "mceAnchor": if (!user_interface) { var aElm = tinyMCE.getParentElement(this.getFocusElement(), "a", "name"); if (aElm) 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 documentRef = this.contentWindow.document; var rng = documentRef.selection.createRange(); selectedText = (rng.text && rng.text.length > 0); } else selectedText = (this.contentWindow.getSelection().toString().length > 0); if (selectedText) { 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 cols) cols = rowsAr[i].cells.length; cols = cols; rows = rowsAr.length; border = tinyMCE.getAttrib(tinyMCE.tableElement, 'border', border); cellpadding = tinyMCE.getAttrib(tinyMCE.tableElement, 'cellpadding', ""); cellspacing = tinyMCE.getAttrib(tinyMCE.tableElement, 'cellspacing', ""); width = tinyMCE.getAttrib(tinyMCE.tableElement, 'width', width); height = tinyMCE.getAttrib(tinyMCE.tableElement, 'height', height); align = tinyMCE.getAttrib(tinyMCE.tableElement, 'align', align); className = tinyMCE.getAttrib(tinyMCE.tableElement, tinyMCE.isMSIE ? 'className' : "class", ""); if (tinyMCE.isMSIE) { width = tinyMCE.tableElement.style.pixelWidth == 0 ? tinyMCE.tableElement.getAttribute("width") : tinyMCE.tableElement.style.pixelWidth; height = tinyMCE.tableElement.style.pixelHeight == 0 ? tinyMCE.tableElement.getAttribute("height") : tinyMCE.tableElement.style.pixelHeight; } action = "update"; } tinyMCE.openWindow(this.insertTableTemplate, {editor_id : this.editorId, cols : cols, rows : rows, border : border, cellpadding : cellpadding, cellspacing : cellspacing, align : align, width : width, height : height, action : action, className : className}); } else { var html = ''; var cols = 2, rows = 2, border = 0, cellpadding = -1, cellspacing = -1, align, width, height, className; if (typeof(value) == 'object') { cols = value['cols']; rows = value['rows']; border = value['border'] != "" ? value['border'] : 0; cellpadding = value['cellpadding'] != "" ? value['cellpadding'] : -1; cellspacing = value['cellspacing'] != "" ? value['cellspacing'] : -1; align = value['align']; width = value['width']; height = value['height']; className = value['className']; } // Update table if (tinyMCE.tableElement) { tinyMCE.setAttrib(tinyMCE.tableElement, 'cellPadding', cellpadding); tinyMCE.setAttrib(tinyMCE.tableElement, 'cellSpacing', cellspacing); tinyMCE.setAttrib(tinyMCE.tableElement, 'border', border); tinyMCE.setAttrib(tinyMCE.tableElement, 'width', width); tinyMCE.setAttrib(tinyMCE.tableElement, 'height', height); tinyMCE.setAttrib(tinyMCE.tableElement, 'align', align, true); tinyMCE.setAttrib(tinyMCE.tableElement, tinyMCE.isMSIE ? 'className' : "class", className, true); if (tinyMCE.isMSIE) { tinyMCE.tableElement.style.pixelWidth = (width == null || width == "") ? 0 : width; tinyMCE.tableElement.style.pixelHeight = (height == null || height == "") ? 0 : height; } tinyMCE.handleVisualAid(tinyMCE.tableElement, false, this.visualAid); // Fix for stange MSIE align bug tinyMCE.tableElement.outerHTML = tinyMCE.tableElement.outerHTML; //this.contentWindow.dispatchEvent(createEvent("click")); tinyMCE.triggerNodeChange(); return; } // Create new table html += ''; else html += '"; } html += ""; } html += "
'; html += " 
"; this.execCommand('mceInsertContent', false, html); } break; case "mceTableInsertRowBefore": case "mceTableInsertRowAfter": case "mceTableDeleteRow": case "mceTableInsertColBefore": case "mceTableInsertColAfter": case "mceTableDeleteCol": var trElement = tinyMCE.getParentElement(this.getFocusElement(), "tr"); var tdElement = tinyMCE.getParentElement(this.getFocusElement(), "td"); var tableElement = tinyMCE.getParentElement(this.getFocusElement(), "table"); // No table just return (invalid command) if (!tableElement) return; var documentRef = this.contentWindow.document; var tableBorder = tableElement.getAttribute("border"); var visualAidStyle = this.visualAid ? tinyMCE.settings['visual_table_style'] : ""; // Table has a tbody use that reference if (tableElement.firstChild && tableElement.firstChild.nodeName.toLowerCase() == "tbody") tableElement = tableElement.firstChild; if (tableElement && trElement) { switch (command) { case "mceTableInsertRowBefore": var numcells = trElement.cells.length; var rowCount = 0; var tmpTR = trElement; // Count rows while (tmpTR) { if (tmpTR.nodeName.toLowerCase() == "tr") rowCount++; tmpTR = tmpTR.previousSibling; } var r = tableElement.insertRow(rowCount == 0 ? 1 : rowCount-1); for (var i=0; i numCols) numCols = tableElement.rows[y].cells.length; } // Remove whole table if (numCols <= 1) { tinyMCE._selectNode(this.contentWindow, selElm); tableElement.parentNode.removeChild(tableElement); tinyMCE.triggerNodeChange(); return; } // Remove columns for (var y=0; y 0) selElm = tableElement.rows[0].cells[index-1]; tinyMCE._selectNode(this.contentWindow, selElm); break; } tinyMCE.triggerNodeChange(); } break; case "mceAddUndoLevel": if (tinyMCE.settings['custom_undo_redo']) { var customUndoLevels = tinyMCE.settings['custom_undo_redo_levels']; var newHTML = this.contentWindow.document.body.innerHTML; if (newHTML != this.undoLevels[this.undoLevels.length-1]) { // Time to compress if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) { for (var i=0; i 0) { this.undoIndex--; this.contentWindow.document.body.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.contentWindow.document.body.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.contentWindow.document.body, true, this.visualAid); tinyMCE.triggerNodeChange(); break; /* case "removeformat": //this.contentDocument.execCommand('FormatBlock', user_interface, ''); var documentRef = this.contentWindow.document; var rng = documentRef.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('=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; } function TinyMCEControl_queryCommandValue(command) { return this.contentWindow.document.queryCommandValue(command); } function TinyMCEControl_queryCommandState(command) { return this.contentWindow.document.queryCommandState(command); } function TinyMCEControl_onAdd(replace_element, form_element_name) { tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings['theme']; this.settings['themeurl'] = tinyMCE.themeURL; if (!replace_element) { alert("Error: Could not find the target element."); return false; } var templateFunction = tinyMCE._getThemeFunction('_getInsertTableTemplate'); if (eval("typeof(" + templateFunction + ")") != 'undefined') this.insertTableTemplate = eval(templateFunction + '(this.settings);'); var templateFunction = tinyMCE._getThemeFunction('_getInsertLinkTemplate'); if (eval("typeof(" + templateFunction + ")") != 'undefined') this.insertLinkTemplate = eval(templateFunction + '(this.settings);'); var templateFunction = tinyMCE._getThemeFunction('_getInsertImageTemplate'); if (eval("typeof(" + templateFunction + ")") != 'undefined') this.insertImageTemplate = eval(templateFunction + '(this.settings);'); var templateFunction = tinyMCE._getThemeFunction('_getEditorTemplate'); if (eval("typeof(" + templateFunction + ")") == 'undefined') { alert("Error: Could not find the template function: " + templateFunction); return false; } var editorTemplate = eval(templateFunction + '(this.settings, this.editorId);'); var deltaWidth = editorTemplate['delta_width'] ? editorTemplate['delta_width'] : 0; var deltaHeight = editorTemplate['delta_height'] ? editorTemplate['delta_height'] : 0; var html = '' + 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; 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.oldTargetElement = replace_element.cloneNode(true); this.formTargetElementId = form_element_name; // 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; //window.setTimeout("tinyMCE.setEditMode('" + this.editorId + "', true)", 1); tinyMCE.setEditMode(this.editorId, true); return true; } function TinyMCEControl_getFocusElement() { if (tinyMCE.isMSIE) { var documentRef = this.contentWindow.document; var rng = documentRef.selection.createRange(); var elm = rng.item ? rng.item(0) : rng.parentElement(); } else { var sel = this.contentWindow.getSelection(); var elm = sel.anchorNode; if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") elm = tinyMCE.selectedElement; } return elm; } // Global instances var tinyMCE = new TinyMCE(); var tinyMCELang = new Array();