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);
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() { // * * Cleanup and set all form fields for (var instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; tinyMCE.settings['preformatted'] = false;
tinyMCE._setHTML(instance.contentWindow.document, instance.contentWindow.document.body.innerHTML); var cleanedHTML = tinyMCE._cleanupHTML(instance.contentWindow.document, this.settings, instance.contentWindow.document.body, this.visualAid, true);
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;
instance.formElement.value = cleanedHTML; } }
function TinyMCE_execInstanceCommand(editor_id, command, user_interface, value) { var mceControl = tinyMCE._getInstanceById(editor_id); if (mceControl) { mceControl.contentWindow.focus(); this.selectedElement = mceControl.getFocusElement(); this.selectedInstance = mceControl; tinyMCE.execCommand(command, user_interface, value); } }
function TinyMCE_execCommand(command, user_interface, value) { // Command within editor instance? if (this.selectedInstance && tinyMCE.isMSIE) { var node = this.selectedInstance.getFocusElement(); while (node = node.parentNode) { if (node.nodeName == "#document" && (node.location.href.indexOf('blank.htm') == -1)) { this.selectedInstance = null; break; } } }
// Default input user_interface = user_interface ? user_interface : false; value = value ? value : null;
case 'mceFocus': var mceControl = tinyMCE._getInstanceById(value); if (mceControl) mceControl.contentWindow.focus(); return;
case "mceAddControl": case "mceAddEditor": tinyMCE.addMCEControl(tinyMCE._getElementById(value), value, tinyMCE.createMCEControl(tinyMCE.settings)); return;
case "mceRemoveControl": case "mceRemoveEditor": tinyMCE.removeMCEControl(value); return; }
if (this.selectedInstance) this.selectedInstance.execCommand(command, user_interface, value); else if (tinyMCE.settings['focus_alert']) alert(tinyMCELang['lang_focus_alert']); }
// Due to stange focus bug in MSIE this line is disabled for now //document.frames[editor_id].document.onmousedown = patchFunc; document.frames[editor_id].document.onmouseup = patchFunc; document.frames[editor_id].document.onclick = patchFunc; }
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; }
// 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;
if (tinyMCE.isMSIE) { var styleSheet = document.frames[editor_id].document.createStyleSheet(instance.settings['content_css']);
if (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<keys.length; i++) { if (keys[i] == e.keyCode) { tinyMCE.selectedInstance.typing = false; posKey = true; break; } }
case "mousedown": case "mouseup": case "click": case "focus": // Check instance event trigged on var targetBody = tinyMCE.getParentElement(e.target, "body"); for (var instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; if (instance.contentWindow.document.body == targetBody) { tinyMCE.selectedInstance = instance; tinyMCE.selectedElement = e.target; tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a"); tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");
function TinyMCE_restoreClass(element) { if (element != null && element.oldClassName && !element.classLock) { element.className = element.oldClassName; element.oldClassName = null; } }
function TinyMCE_setClassLock(element, lock_state) { if (element != null) element.classLock = lock_state; }
function TinyMCE_onLoad() { // Add submit triggers if (tinyMCE.isMSIE) { if (document.forms && tinyMCE.settings['add_form_submit_trigger']) { for (var i=0; i<document.forms.length; i++) document.forms[i].attachEvent("onsubmit", TinyMCE_triggerSave); } } else { if (document.forms && tinyMCE.settings['add_form_submit_trigger']) { for (var i=0; i<document.forms.length; i++) document.forms[i].addEventListener("submit", TinyMCE_triggerSave, false); } }
// Add editor instances based on mode switch (tinyMCE.settings['mode']) { case "exact": var elements = tinyMCE.settings['elements'].split(',');
for (var i=0; i<elements.length; i++) { var element = tinyMCE._getElementById(elements[i]);
if (element) tinyMCE.addMCEControl(element, elements[i], tinyMCE.createMCEControl(tinyMCE.settings)); else alert("Error: Could not find element by id or name: " + elements[i]); } break;
case "specific_textareas": case "textareas": var nodeList = document.getElementsByTagName("textarea"); var elementRefAr = new Array();
for (var i=0; i<nodeList.length; i++) { if (tinyMCE.settings['mode'] != "specific_textareas" || nodeList.item(i).getAttribute(tinyMCE.settings['textarea_trigger']) == "true") elementRefAr[elementRefAr.length] = nodeList.item(i); }
for (var i=0; i<elementRefAr.length; i++) { var element = elementRefAr[i]; var elementId = element.name ? element.name : element.id;
if (tinyMCE.settings['ask']) { if (tinyMCE.isMSIE) element.attachEvent("onmousedown", TinyMCE_confirmAdd); else element.addEventListener("mousedown", TinyMCE_confirmAdd, false); } else tinyMCE.addMCEControl(element, elementId, tinyMCE.createMCEControl(tinyMCE.settings)); } break; } }
function TinyMCE_removeMCEControl(editor_id) { var mceControl = tinyMCE._getInstanceById(editor_id); if (mceControl) { editor_id = mceControl.editorId; var html = tinyMCE.getContent(editor_id);
// Remove editor instance from instances array var tmpInstances = new Array(); for (var instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; if (instanceName != editor_id) tmpInstances[instanceName] = instance; } tinyMCE.instances = tmpInstances;
function TinyMCE__cleanupElementName(element_name, element) { element_name = element_name.toLowerCase();
// Never include body if (element_name == "body") return null;
// If verification mode if (tinyMCE.cleanup_verify_html) { // Check if invalid element for (var i=0; i<tinyMCE.cleanup_invalidElements.length; i++) { if (tinyMCE.cleanup_invalidElements[i] == element_name) return null; }
// Check if valid element var validElement = false; var elementAttribs = null; for (var i=0; i<tinyMCE.cleanup_validElements.length && !elementAttribs; i++) { for (var x=0; x<tinyMCE.cleanup_validElements[i][0].length; x++) { var elmMatch = tinyMCE.cleanup_validElements[i][0][x];
/** * Converts some element attributes to inline styles. */ function TinyMCE__fixInlineStyles(elm) { // Handle non table elements if (elm.nodeName.toLowerCase() != "table") { var value;
// Setup width value = tinyMCE.isMSIE ? elm.width : elm.getAttribute("width"); if (value && value != "") { if (typeof (value) != "string" || !value.indexOf("%")) value += "px";
elm.style.width = value; }
// Setup height value = tinyMCE.isMSIE ? elm.height : elm.getAttribute("height"); if (value && value != "") { if (typeof (value) != "string" || !value.indexOf("%")) value += "px";
elm.style.height = value; }
// Setup border value = tinyMCE.isMSIE ? elm.border : elm.getAttribute("border"); if (value && value != "") elm.style.border = "solid " + value + "px"; }
// Setup align value = elm.getAttribute("align"); if (value && value != "") elm.style.textAlign = value;
// Setup vspace value = elm.getAttribute("vspace"); if (value && value != "") elm.style.marginTop = value + "px";
// Setup hspace value = elm.getAttribute("hspace"); if (value && value != "") elm.style.marginBottom = value + "px"; }
function TinyMCE__cleanupAttribute(valid_attributes, element_name, attribute_node, element_node) { var attribName = attribute_node.nodeName.toLowerCase(); var attribValue = attribute_node.nodeValue; var attribMustBeValue = null;
// Mozilla attibute, remove them if (attribName.indexOf('moz_') != -1) return null;
// Mozilla fix for drag-drop/copy/paste images if (!tinyMCE.isMSIE && (attribName == "mce_real_href" || attribName == "mce_real_src")) { if (!tinyMCE.cleanup_on_save) { var attrib = new Object();
// Verify attrib if (tinyMCE.cleanup_verify_html) { var verified = false; for (var i=1; i<valid_attributes.length; i++) { var attribMatch = valid_attributes[i][0]; var re = null;
// Compress borders some if (tinyMCE.isMSIE) { var border = element_node.style.border; var bt = element_node.style.borderTop; var bl = element_node.style.borderLeft; var br = element_node.style.borderRight; var bb = element_node.style.borderBottom;
// Convert the URLs of these case "href": case "src": case "mceoversrc": // Fix for dragdrop/copy paste Mozilla issue if (!tinyMCE.isMSIE && attribName == "href" && element_node.getAttribute("mce_real_href")) attribValue = element_node.getAttribute("mce_real_href");
// Fix for dragdrop/copy paste Mozilla issue if (!tinyMCE.isMSIE && attribName == "src" && element_node.getAttribute("mce_real_src")) attribValue = element_node.getAttribute("mce_real_src");
case "colspan": case "rowspan": // Not needed if (attribValue == "1") return null; break;
// Skip these case "_moz-userdefined": case "editorid": case "editor_id": case "mce_real_href": case "mce_real_src": return null; }
// Not the must be value if (attribMustBeValue != null) { var isCorrect = false; for (var i=0; i<attribMustBeValue.length; i++) { if (attribValue == attribMustBeValue[i]) { isCorrect = true; break; } }
function TinyMCE__verifyClass(node) { var className = node.getAttribute('class');
// Trim CSS class if (tinyMCE.isMSIE) var className = node.getAttribute('className');
if (tinyMCE.cleanup_verify_css_classes && tinyMCE.cleanup_on_save) { var csses = tinyMCE.getCSSClasses(); nonDefinedCSS = true; for (var c=0; c<csses.length; c++) { if (csses[c] == className) { nonDefinedCSS = false; break; } }
if (nonDefinedCSS) { node.removeAttribute('className'); node.removeAttribute('class'); return false; } }
return true; }
function TinyMCE_cleanupNode(node) { var output = "";
switch (node.nodeType) { case 1: // Element var elementData = tinyMCE._cleanupElementName(node.nodeName, node); var elementName = elementData ? elementData.element_name : null; var elementValidAttribs = elementData ? elementData.valid_attribs : null; var elementAttribs = "";
// Element not valid (only render children) if (!elementName) { if (node.hasChildNodes()) { for (var i=0; i<node.childNodes.length; i++) output += this.cleanupNode(node.childNodes[i]); }
return output; }
// Has mso/microsuck crap or empty attrib if (node.style && (node.style.cssText.indexOf('mso-') != -1 && tinyMCE.settings['auto_cleanup_word']) || node.style.cssText == "") { node.style.cssText = ""; node.removeAttribute("style"); }
// Handle inline styles if (tinyMCE.cleanup_inline_styles) tinyMCE._fixInlineStyles(node);
// Set attrib data if (elementValidAttribs) { for (var a=1; a<elementValidAttribs.length; a++) { var attribName, attribDefaultValue, attribForceValue, attribValue;
// Is to generate id if (attribValue == "{$uid}") attribValue = "uid_" + (tinyMCE.cleanup_idCount++);
node.setAttribute(attribName, attribValue); } } }
// Remove non needed span elements if (elementName == "span" && tinyMCE.cleanup_trim_span_elements) { var re = new RegExp('^[ \t]+', 'g'); var onlyWhiteSpace = true; for (var a=0; a<node.childNodes.length; a++) { var tmpNode = node.childNodes[a]; if ((tmpNode.nodeType == 3 && !tmpNode.nodeValue.match(re)) || tmpNode.nodeName.toLowerCase() != "span") { onlyWhiteSpace = false; break; } }
// Count attributes tinyMCE._verifyClass(node); var numAttribs = 0; for (var i=0; i<node.attributes.length; i++) { if (node.attributes[i].specified) numAttribs++; }
// Is not a valid span, remove it if (onlyWhiteSpace || numAttribs == 0) { if (node.hasChildNodes()) { for (var i=0; i<node.childNodes.length; i++) output += this.cleanupNode(node.childNodes[i]); }
return output; } }
// Add some visual aids if (elementName == "table" || elementName == "td") { // Handle visual aid if (tinyMCE.cleanup_visual_table_style != "") { // Find parent table var tableElement = node; if (elementName == "td") tableElement = tinyMCE.getParentElement(tableElement, "table");
function TinyMCE_convertStringToXML(html_data) { var output = "";
if (!html_data) return null;
for (var i=0; i<html_data.length; i++) { var chr = html_data.charAt(i);
// * * Check and convert to XML format switch (chr) { case ''+String.fromCharCode(8482): output += "™"; break;
case ''+String.fromCharCode(8211): output += "-"; break;
case '\u0093': case '\u0094': case ''+String.fromCharCode(8220): case ''+String.fromCharCode(8221): case '"': output += """; break;
case ''+String.fromCharCode(8217): case ''+String.fromCharCode(180): case '\'': output += "'"; break;
case '<': output += "<"; break;
case '>': output += ">"; break;
case '&': output += "&"; break;
case ''+String.fromCharCode(8230): output += "..."; break;
case '\\': output += "\"; break;
case ''+String.fromCharCode(160): output += " "; break;
default: output += chr; } }
return output; }
function TinyMCE__initCleanup() { function getElementName(chunk) { var pos;
if ((pos = chunk.indexOf('/')) != -1) chunk = chunk.substring(0, pos);
if ((pos = chunk.indexOf('[')) != -1) chunk = chunk.substring(0, pos);
return chunk; }
// Parse valid elements and attributes var validElements = tinyMCE.settings["valid_elements"]; validElements = validElements.split(',');
// Handle extended valid elements var extendedValidElements = tinyMCE.settings["extended_valid_elements"]; extendedValidElements = extendedValidElements.split(','); for (var i=0; i<extendedValidElements.length; i++) { var elementName = getElementName(extendedValidElements[i]); var skipAdd = false;
// Check if it's defined before, if so override that one for (var x=0; x<validElements.length; x++) { if (getElementName(validElements[x]) == elementName) { validElements[x] = extendedValidElements[i]; skipAdd = true; break; } }
if (!skipAdd) validElements[validElements.length] = extendedValidElements[i]; }
for (var i=0; i<validElements.length; i++) { var item = validElements[i]; item = item.replace('[','|'); item = item.replace(']','');
// * * Split and convert var attribs = item.split('|'); for (var x=0; x<attribs.length; x++) attribs[x] = attribs[x].toLowerCase();
// * * Handle change elements attribs[0] = attribs[0].split('/');
// * * Handle default attribute values for (var x=1; x<attribs.length; x++) { var attribName = attribs[x]; var attribDefault = null; var attribForce = null; var attribMustBe = null;
// Default value if ((pos = attribName.indexOf('=')) != -1) { attribDefault = attribName.substring(pos+1); attribName = attribName.substring(0, pos); }
// Force check if ((pos = attribName.indexOf(':')) != -1) { attribForce = attribName.substring(pos+1); attribName = attribName.substring(0, pos); }
// Force check if ((pos = attribName.indexOf('<')) != -1) { attribMustBe = attribName.substring(pos+1).split('?'); attribName = attribName.substring(0, pos); }
attribs[x] = new Array(attribName, attribDefault, attribForce, attribMustBe); }
validElements[i] = attribs; }
var invalidElements = tinyMCE.settings['invalid_elements'].split(','); for (var i=0; i<invalidElements.length; i++) invalidElements[i] = invalidElements[i].toLowerCase();
function setAttrib(element, name, value, no_fix_value) { if (!no_fix_value && value != null) { var re = new RegExp('[^0-9%]', 'g'); value = value.replace(re, ''); }
if (value != null && value != "") element.setAttribute(name, value); else element.removeAttribute(name); }
function TinyMCE_getElementByAttributeValue(node, element_name, attrib, value) { var elements = this.getElementsByAttributeValue(node, element_name, attrib, value); if (elements.length == 0) return null;
return elements[0]; }
function TinyMCE_getElementsByAttributeValue(node, element_name, attrib, value) { var elements = new Array();
if (node && node.nodeName.toLowerCase() == element_name) { if (node.getAttribute(attrib).indexOf(value) != -1) elements[elements.length] = node; }
if (node.hasChildNodes) { for (var x=0; x<node.childNodes.length; x++) { var childElements = this.getElementsByAttributeValue(node.childNodes[x], element_name, attrib, value); for (var i=0; i<childElements.length; i++) elements[elements.length] = childElements[i]; } }
return elements; }
function TinyMCE_getParentElement(node, names, attrib_name, attrib_value) { var namesAr = names.split(',');
if (node == null) return null;
do { for (var i=0; i<namesAr.length; i++) { if (node.nodeName.toLowerCase() == namesAr[i].toLowerCase() || names == "*") { if (typeof attrib_name == "undefined") return node; else if (node.getAttribute(attrib_name)) { if (typeof attrib_value == "undefined") { if (node.getAttribute(attrib_name) != "") return node; } else if (node.getAttribute(attrib_name) == attrib_value) return node; } } } } while (node = node.parentNode);
return null; }
function TinyMCE_convertURL(url, node, on_save) { var fileProto = (document.location.protocol == "file:");
// Mailto link or anchor (Pass through) if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || tinyMCE.regexpReplace(url,'[ \t\r\n\+]|%20','').charAt(0) == "#") return url;
// Convert to relative urls if (on_save && tinyMCE.settings['relative_urls']) { var urlParts = tinyMCE.parseURL(url);
// If not absolute url, do nothing (Mozilla) if (!urlParts['protocol'] && !tinyMCE.isMSIE) { var urlPrefix = "http://"; urlPrefix += document.location.hostname; if (document.location.port != "") urlPrefix += document.location.port;
var tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings['document_base_url']);
// Link is within this site if (urlParts['host'] == tmpUrlParts['host'] && (!urlParts['port'] || urlParts['port'] == tmpUrlParts['port'])) return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings['document_base_url'], url); }
// Remove current domain if (!fileProto && tinyMCE.settings['remove_script_host']) { var start = document.location.protocol + "//" + document.location.hostname + "/"; if (url.indexOf(start) == 0) url = url.substring(start.length-1); }
return url; }
/** * Parses a URL in to its diffrent components. */ function TinyMCE_parseURL(url_str) { var urlParts = new Array();
// Get query lastPos = pos; if (url_str.charAt(pos) == '?') { pos = url_str.length; urlParts['query'] = url_str.substring(lastPos+1, pos); } }
return urlParts; }
/** * Converts an absolute path to relative path. */ function TinyMCE_convertAbsoluteURLToRelativeURL(base_url, url_to_relative) { var strTok1; var strTok2; var breakPoint = 0; var outputString = "";
// * * Crop away last path part base_url = base_url.substring(0, base_url.lastIndexOf('/')); strTok1 = base_url.split('/'); strTok2 = url_to_relative.split('/');
if (strTok1.length >= strTok2.length) { for (var i=0; i<strTok1.length; i++) { if (i >= strTok2.length || strTok1[i] != strTok2[i]) { breakPoint = i + 1; break; } } }
if (strTok1.length < strTok2.length) { for (var i=0; i<strTok2.length; i++) { if (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<strTok2.length; i++) { if (i != (breakPoint-1)) outputString += "/" + strTok2[i]; else outputString += strTok2[i]; }
function TinyMCE_replaceVar(replace_haystack, replace_var, replace_str) { var re = new RegExp('{\\\$' + replace_var + '}', 'g'); return replace_haystack.replace(re, replace_str); }
function TinyMCE_replaceVars(replace_haystack, replace_vars) { var variables = replace_haystack.match(new RegExp('{\\\$.*?}', 'g'));
if (variables != null) { for (var i=0; i<variables.length; i++) { var variableName = variables[i].substring(2); variableName = variableName.substring(0, variableName.length-1); if (typeof replace_vars[variableName] != "undefined") replace_haystack = replace_haystack.replace(variables[i], replace_vars[variableName]); } }
return replace_haystack; }
function TinyMCE_triggerNodeChange(focus) { if (tinyMCE.settings['handleNodeChangeCallback']) { if (tinyMCE.selectedInstance) { var editorId = tinyMCE.selectedInstance.editorId; var elm = tinyMCE.selectedInstance.getFocusElement(); var undoIndex = -1; var undoLevels = -1;
if (tinyMCE.settings['custom_undo_redo']) { undoIndex = tinyMCE.selectedInstance.undoIndex; undoLevels = tinyMCE.selectedInstance.undoLevels.length; }
/** * 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;
tinyMCE.windowArgs = args;
html = template['html']; if (!(width = template['width'])) width = 320;
if (!(height = template['height'])) height = 200;
x = parseInt(screen.width / 2.0) - (width / 2.0); y = parseInt(screen.height / 2.0) - (height / 2.0);
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<element.rows.length; y++) { for (var x=0; x<element.rows[y].cells.length; x++) element.rows[y].cells[x].style.cssText = state ? cssText : ""; }
break;
/* case "a": var name = element.getAttribute("name"); if (name && name != "" && state) { //element.innerHTML += '<img mceVisualAid="true" src="' + (tinyMCE.themeURL + "/images/anchor.gif") + '" />'; return; }
break;*/ }
if (deep && element.hasChildNodes()) { for (var i=0; i<element.childNodes.length; i++) tinyMCE.handleVisualAid(element.childNodes[i], deep, state); } }
function TinyMCE_getAttrib(elm, name, default_value) { var v = elm.getAttribute(name); return (v && v != "") ? v : default_value; }
function TinyMCE_setAttrib(element, name, value, no_fix_value) { if (typeof value == "number") value = "" + value;
if (!no_fix_value && value != null && value != -1) { var re = new RegExp('[^0-9%]', 'g'); value = value.replace(re, ''); }
if (value != null && value != "" && value != -1) element.setAttribute(name, value); else element.removeAttribute(name); }
function TinyMCE__setHTML(doc, html_content) { // Weird MSIE bug, <p><hr /></p> breaks runtime? if (tinyMCE.isMSIE) { var re = new RegExp('<p><hr /></p>', 'g'); html_content = html_content.replace(re, "<hr>"); }
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<paras.length; i++) { var node = paras[i]; while ((node = node.parentNode) != null) { if (node.nodeName.toLowerCase() == "p") node.outerHTML = node.innerHTML; } }
// Content duplication bug fix (Seems to be word crap) var html = doc.body.createTextRange().htmlText; if (html.indexOf('="mso') != -1) { /* html = tinyMCE.regexpReplace(html, "<p>\s*(<p>\s*)?", "<p>"); html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "</p>"); //html = tinyMCE.regexpReplace(html, "<o:p></o:p>", "<br />"); html = tinyMCE.regexpReplace(html, "/<o:p> <\/o:p>/g", ""); html = tinyMCE.regexpReplace(html, "/o:/g", ""); html = tinyMCE.regexpReplace(html, "/<st1:.*?>/g", "");*/
for (var i=0; i<doc.body.all.length; i++) { var el = doc.body.all[i]; el.removeAttribute("className","",0); el.removeAttribute("style","",0); }
html = doc.body.createTextRange().htmlText;
// html = tinyMCE.regexpReplace(html, "<o:", "<"); html = tinyMCE.regexpReplace(html, "<o:p><\/o:p>", "<br />"); html = tinyMCE.regexpReplace(html, "<o:p> <\/o:p>", ""); html = tinyMCE.regexpReplace(html, "<st1:.*?>", ""); html = tinyMCE.regexpReplace(html, "<p><\/p>", ""); html = tinyMCE.regexpReplace(html, "<p><\/p>\r\n<p><\/p>", ""); html = tinyMCE.regexpReplace(html, "<p> <\/p>", "<br />"); html = tinyMCE.regexpReplace(html, "<p>\s*(<p>\s*)?", "<p>"); html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "</p>");
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<document.forms.length; j++) { for (var k=0; k<document.forms[j].elements.length; k++) { if (document.forms[j].elements[k].name == element_id) { elm = document.forms[j].elements[k]; break; } } } }
return elm; }
function TinyMCE_getEditorId(form_element) { var mceControl = this._getInstanceById(form_element); if (!mceControl) return null;
return mceControl.editorId; }
function TinyMCE__getInstanceById(editor_id) { var mceControl = this.instances[editor_id]; if (!mceControl) { for (var instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; if (instance.formTargetElementId == editor_id) { mceControl = instance; break; } } }
return mceControl; }
function TinyMCE_queryInstanceCommandValue(editor_id, command) { var mceControl = tinyMCE._getInstanceById(editor_id); if (mceControl) return mceControl.queryCommandValue(command);
return false; }
function TinyMCE_queryInstanceCommandState(editor_id, command) { var mceControl = tinyMCE._getInstanceById(editor_id); if (mceControl) return mceControl.queryCommandState(command);
function TinyMCE_getCSSClasses(editor_id, doc) { var output = new Array();
// Is cached, use that if (typeof tinyMCE.cssClasses != "undefined") return tinyMCE.cssClasses;
if (typeof editor_id == "undefined" && typeof doc == "undefined") { var instance;
for (var instanceName in tinyMCE.instances) { instance = tinyMCE.instances[instanceName]; break; }
doc = instance.contentWindow.document; }
if (typeof doc == "undefined") { var instance = tinyMCE._getInstanceById(editor_id); doc = instance.contentWindow.document; }
if (doc) { var styles = tinyMCE.isMSIE ? doc.styleSheets : doc.styleSheets;
if (styles && styles.length > 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<csses.length; i++) { var selectorText = csses[i].selectorText;
// Can be multiple rules per selector var rules = selectorText.split(','); for (var c=0; c<rules.length; c++) { // Is class rule if (rules[c].indexOf('.') != -1) { //alert(rules[c].substring(rules[c].indexOf('.'))); output.push(rules[c].substring(rules[c].indexOf('.')+1)); } } } } }
// Cache em if (output.length > 0) tinyMCE.cssClasses = output;
return output; }
function TinyMCE_regexpReplace(in_str, reg_exp, replace_str) { var re = new RegExp(reg_exp, 'g'); return in_str.replace(re, replace_str); }
// * * TinyMCEControl function TinyMCEControl(settings) { // * * Undo levels this.undoLevels = new Array(); this.undoIndex = 0;
// 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();
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); var cleanedHTML = tinyMCE._cleanupHTML(this.contentDocument, this.settings, this.contentDocument.body, this.visualAid); this.contentDocument.body.innerHTML = cleanedHTML; } } 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<elementArray.length; x++) { elm = elementArray[x];
var aElm = this.contentDocument.createElement("a"); aElm.setAttribute('name', value);
if (elm.hasChildNodes()) { for (var i=0; i<elm.childNodes.length; i++) aElm.appendChild(elm.childNodes[i].cloneNode(true)); }
elm.parentNode.replaceChild(aElm, elm); } }
tinyMCE.triggerNodeChange(); } break;
case "mceReplaceContent": 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 (selectedText.length > 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<elementArray.length; x++) { elm = elementArray[x]; if (elm) { var spanElm = this.contentDocument.createElement("span"); spanElm.className = value; if (elm.hasChildNodes()) { for (var i=0; i<elm.childNodes.length; i++) spanElm.appendChild(elm.childNodes[i].cloneNode(true)); }
elm.parentNode.replaceChild(spanElm, elm); } }
tinyMCE.setContent(this.contentDocument.body.innerHTML); } else { var targetElm = this.getFocusElement(); if (tinyMCE.selectedElement.nodeName.toLowerCase() == "img" || tinyMCE.selectedElement.nodeName.toLowerCase() == "table") targetElm = tinyMCE.selectedElement;
var targetNode = tinyMCE.getParentElement(targetElm, "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address");
// Mozilla img patch if (!tinyMCE.isMSIE && !targetNode) targetNode = tinyMCE.imgElement;
if (targetNode) { if (targetNode.nodeName.toLowerCase() == "span" && (!value || value == "")) { if (targetNode.hasChildNodes()) { for (var i=0; i<targetNode.childNodes.length; i++) targetNode.parentNode.insertBefore(targetNode.childNodes[i].cloneNode(true), targetNode); }
case "mceInsertContent": if (!tinyMCE.isMSIE) { this.contentDocument.execCommand("insertimage", false, "#mce_temp_url#"); elm = tinyMCE.getElementByAttributeValue(this.contentDocument.body, "img", "src", "#mce_temp_url#");
if (elm) { var rng = elm.ownerDocument.createRange(); rng.setStartBefore(elm); var fragment = rng.createContextualFragment(value); elm.parentNode.replaceChild(fragment, elm); } } else { var rng = this.contentWindow.document.selection.createRange();
if (rng.item) rng.item(0).outerHTML = value; else rng.pasteHTML(value); }
if (tinyMCE.tableElement) { var rowsAr = tinyMCE.tableElement.rows; var cols = 0; for (var i=0; i<rowsAr.length; i++) if (rowsAr[i].cells.length > cols) cols = rowsAr[i].cells.length;
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<numcells; i++) { var newTD = documentRef.createElement("td"); newTD.innerHTML = " ";
if (tableBorder == 0) newTD.style.cssText = visualAidStyle;
var c = r.appendChild(newTD);
if (tdElement.parentNode.childNodes[i].colSpan) c.colSpan = tdElement.parentNode.childNodes[i].colSpan; } break;
case "mceTableInsertRowAfter": var numcells = trElement.cells.length; var rowCount = 0; var tmpTR = trElement; var documentRef = this.contentWindow.document;
// Count rows while (tmpTR) { if (tmpTR.nodeName.toLowerCase() == "tr") rowCount++;
tmpTR = tmpTR.previousSibling; }
var r = tableElement.insertRow(rowCount == 0 ? 1 : rowCount); for (var i=0; i<numcells; i++) { var newTD = documentRef.createElement("td"); newTD.innerHTML = " ";
if (tableBorder == 0) newTD.style.cssText = visualAidStyle;
var c = r.appendChild(newTD);
if (tdElement.parentNode.childNodes[i].colSpan) c.colSpan = tdElement.parentNode.childNodes[i].colSpan; } break;
case "mceTableDeleteRow": // Remove whole table if (tableElement.rows.length <= 1) { tableElement.parentNode.removeChild(tableElement); tinyMCE.triggerNodeChange(); return; }
var selElm = this.contentWindow.document.body; if (trElement.previousSibling) selElm = trElement.previousSibling.cells[0];
case "Undo": if (tinyMCE.settings['custom_undo_redo']) { // Is first level if (this.undoIndex == this.undoLevels.length) { this.execCommand("mceAddUndoLevel"); this.undoIndex--; }
// Do undo if (this.undoIndex > 0) { this.undoIndex--; this.contentWindow.document.body.innerHTML = this.undoLevels[this.undoIndex]; }
this.contentDocument.execCommand('FontName', user_interface, '#mce_temp_name#'); var html = this.contentDocument.innerHTML; html.replace('<font face=');
rng.pasteHTML(html);
alert(html);
if (tinyMCE.isMSIE) { var documentRef = this.contentWindow.document; var rngs = documentRef.selection.createRangeCollection();
for (var i=0; i<rngs.length; i++) alert(rngs[i].htmlText);
var html = rng.htmlText; var tmpElm = documentRef.createElement("div"); tmpElm.innerHTML = html; for (var i=0; i<tmpElm.all.length; i++) { tmpElm.all[i].removeAttribute("style"); tmpElm.all[i].removeAttribute("className"); } //alert(tmpElm.innerHTML); rng.pasteHTML(tmpElm.innerHTML); //rng.pasteHTML(rng.text);
function TinyMCE__selectNode(win, node, expand) { if (!tinyMCE.isMSIE) { var rng = win.document.createRange(); rng.selectNode(node); sel = win.getSelection(); sel.addRange(rng); if (expand) sel.extend(node, 0); else sel.collapse(node, 0); } }
function TinyMCE__getThemeFunction(suffix) { var themePlugins = tinyMCE.settings['theme_plugins'].split(','); 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; }
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 = '<span id="' + this.editorId + '_parent">' + editorTemplate['html'];
var templateFunction = tinyMCE._getThemeFunction('_handleNodeChange'); 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");
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();