/**
* $RCSfile: tiny_mce_src.js,v $
* $Revision: 1.281 $
* $Date: 2005/12/02 08:12:07 $
*
* @author Moxiecode
* @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved.
*/
function TinyMCE() {
this.majorVersion = "2";
this.minorVersion = "0";
this.releaseDate = "2005-12-01";
this.instances = new Array();
this.stickyClassesLookup = new Array();
this.windowArgs = new Array();
this.loadedFiles = new Array();
this.configs = new Array();
this.currentConfig = 0;
this.eventHandlers = new Array();
// Browser check
var ua = navigator.userAgent;
this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);
this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
this.isGecko = ua.indexOf('Gecko') != -1;
this.isSafari = ua.indexOf('Safari') != -1;
this.isOpera = ua.indexOf('Opera') != -1;
this.isMac = ua.indexOf('Mac') != -1;
this.isNS7 = ua.indexOf('Netscape/7') != -1;
this.isNS71 = ua.indexOf('Netscape/7.1') != -1;
this.dialogCounter = 0;
// Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those
if (this.isOpera) {
this.isMSIE = true;
this.isGecko = false;
this.isSafari = false;
}
// TinyMCE editor id instance counter
this.idCounter = 0;
};
TinyMCE.prototype.defParam = function(key, def_val) {
this.settings[key] = tinyMCE.getParam(key, def_val);
};
TinyMCE.prototype.init = function(settings) {
var theme;
this.settings = settings;
// 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');
this.defParam("font_size_classes", '');
this.defParam("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large');
this.defParam("event_elements", 'a,img');
this.defParam("convert_urls", true);
this.defParam("table_inline_editing", false);
this.defParam("object_resizing", true);
// Browser check IE
if (this.isMSIE && this.settings['browsers'].indexOf('msie') == -1)
return;
// Browser check Gecko
if (this.isGecko && this.settings['browsers'].indexOf('gecko') == -1)
return;
// Browser check Safari
if (this.isSafari && this.settings['browsers'].indexOf('safari') == -1)
return;
// Browser check Opera
if (this.isOpera && this.settings['browsers'].indexOf('opera') == -1)
return;
// If not super absolute make it so
var baseHREF = tinyMCE.settings['document_base_url'];
var h = document.location.href;
var p = h.indexOf('://');
if (p > 0 && document.location.protocol != "file:") {
p = h.indexOf('/', p + 3);
h = h.substring(0, p);
if (baseHREF.indexOf('://') == -1)
baseHREF = h + baseHREF;
tinyMCE.settings['document_base_url'] = baseHREF;
tinyMCE.settings['document_base_prefix'] = h;
}
// Trim away query part
if (baseHREF.indexOf('?') != -1)
baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));
this.settings['base_href'] = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";
theme = this.settings['theme'];
this.blockRegExp = new RegExp("^(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|blockquote|center|dl|dir|fieldset|form|noscript|noframes|menu|isindex)$", "i");
this.posKeyCodes = new Array(13,45,36,35,33,34,37,38,39,40);
this.uniqueURL = 'http://tinymce.moxiecode.cp/mce_temp_url'; // Make unique URL non real URL
this.uniqueTag = 'TMP
';
// Theme url
this.settings['theme_href'] = tinyMCE.baseURL + "/themes/" + theme;
if (!tinyMCE.isMSIE)
this.settings['force_br_newlines'] = false;
if (tinyMCE.getParam("content_css", false)) {
var cssPath = tinyMCE.getParam("content_css", "");
// Is relative
if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
this.settings['content_css'] = this.documentBasePath + "/" + cssPath;
else
this.settings['content_css'] = cssPath;
} else
this.settings['content_css'] = '';
if (tinyMCE.getParam("popups_css", false)) {
var cssPath = tinyMCE.getParam("popups_css", "");
// Is relative
if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
this.settings['popups_css'] = this.documentBasePath + "/" + cssPath;
else
this.settings['popups_css'] = cssPath;
} else
this.settings['popups_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";
if (tinyMCE.getParam("editor_css", false)) {
var cssPath = tinyMCE.getParam("editor_css", "");
// Is relative
if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
this.settings['editor_css'] = this.documentBasePath + "/" + cssPath;
else
this.settings['editor_css'] = cssPath;
} else
this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";
if (tinyMCE.settings['debug']) {
var msg = "Debug: \n";
msg += "baseURL: " + this.baseURL + "\n";
msg += "documentBasePath: " + this.documentBasePath + "\n";
msg += "content_css: " + this.settings['content_css'] + "\n";
msg += "popups_css: " + this.settings['popups_css'] + "\n";
msg += "editor_css: " + this.settings['editor_css'] + "\n";
alert(msg);
}
// Init HTML cleanup
this._initCleanup();
// Only do this once
if (this.configs.length == 0) {
// Is Safari enabled
if (this.isSafari && this.getParam('safari_warning', true))
alert("Safari support is very limited and should be considered experimental.\nSo there is no need to even submit bugreports on this early version.\nYou can disable this message by setting: safari_warning option to false");
tinyMCE.addEvent(window, "load", TinyMCE.prototype.onLoad);
if (tinyMCE.isMSIE) {
if (tinyMCE.settings['add_unload_trigger']) {
tinyMCE.addEvent(window, "unload", TinyMCE.prototype.unloadHandler);
tinyMCE.addEvent(window.document, "beforeunload", TinyMCE.prototype.unloadHandler);
}
} else {
if (tinyMCE.settings['add_unload_trigger'])
tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});
}
}
this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings['theme'] + '/editor_template' + tinyMCE.srcMode + '.js');
this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings['language'] + '.js');
this.loadCSS(this.settings['editor_css']);
// Add plugins
var themePlugins = tinyMCE.getParam('plugins', '', true, ',');
if (this.settings['plugins'] != '') {
for (var i=0; i');
this.loadedFiles[this.loadedFiles.length] = url;
};
TinyMCE.prototype.loadCSS = function(url) {
for (var i=0; i');
this.loadedFiles[this.loadedFiles.length] = url;
};
TinyMCE.prototype.importCSS = function(doc, css_file) {
if (css_file == '')
return;
if (typeof(doc.createStyleSheet) == "undefined") {
var elm = doc.createElement("link");
elm.rel = "stylesheet";
elm.href = css_file;
if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
headArr[0].appendChild(elm);
} else
var styleSheet = doc.createStyleSheet(css_file);
};
TinyMCE.prototype.confirmAdd = function(e, settings) {
var elm = tinyMCE.isMSIE ? event.srcElement : e.target;
var elementId = elm.name ? elm.name : elm.id;
tinyMCE.settings = settings;
if (!elm.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm']))
tinyMCE.addMCEControl(elm, elementId);
elm.setAttribute('mce_noask', 'true');
};
TinyMCE.prototype.updateContent = function(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 (!tinyMCE.isInstance(inst))
continue;
inst.switchSettings();
if (inst.formElement == formElement) {
var doc = inst.getDoc();
tinyMCE._setHTML(doc, inst.formElement.value);
if (!tinyMCE.isMSIE)
doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);
}
}
};
TinyMCE.prototype.addMCEControl = function(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);
};
TinyMCE.prototype.triggerSave = function(skip_cleanup, skip_callback) {
// Cleanup and set all form fields
for (var n in tinyMCE.instances) {
var inst = tinyMCE.instances[n];
if (!tinyMCE.isInstance(inst))
continue;
inst.switchSettings();
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);
// Remove visual aids when cleanup is disabled
if (inst.settings['cleanup'] == false) {
tinyMCE.handleVisualAid(inst.getBody(), true, false, inst);
tinyMCE._setEventsEnabled(inst.getBody(), true);
}
tinyMCE._customCleanup(inst, "submit_content_dom", inst.contentWindow.document.body);
var htm = skip_cleanup ? inst.getBody().innerHTML : tinyMCE._cleanupHTML(inst, inst.getDoc(), this.settings, inst.getBody(), this.visualAid, true);
htm = tinyMCE._customCleanup(inst, "submit_content", htm);
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");
if (inst.formElement)
inst.formElement.value = htm;
}
};
TinyMCE.prototype._setEventsEnabled = function(node, state) {
var events = new Array('onfocus','onblur','onclick','ondblclick',
'onmousedown','onmouseup','onmouseover','onmousemove',
'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup');
var evs = tinyMCE.settings['event_elements'].split(',');
for (var y=0; y", "gi");
content = tinyMCE.regexpReplace(content, "\r", "
", "gi");
content = tinyMCE.regexpReplace(content, "\n", "
", "gi");
}
// Open closed anchors
// content = content.replace(new RegExp('', 'gi'), '');
// Call custom cleanup code
content = tinyMCE.storeAwayURLs(content);
content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
if (tinyMCE.isMSIE) {
// 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 body = document.frames[editor_id].document.body;
tinyMCE.addEvent(body, "beforepaste", TinyMCE.prototype.eventPatch);
tinyMCE.addEvent(body, "beforecut", TinyMCE.prototype.eventPatch);
body.editorId = editor_id;
}
content = tinyMCE.cleanupHTMLCode(content);
// Fix for bug #958637
if (!tinyMCE.isMSIE) {
var contentElement = inst.getDoc().createElement("body");
var doc = inst.getDoc();
contentElement.innerHTML = content;
// Remove weridness!
if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt'])
content = content.replace(new RegExp('<>', 'g'), "");
if (tinyMCE.settings['cleanup_on_startup'])
tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
else {
// Convert all strong/em to b/i
content = tinyMCE.regexpReplace(content, "", "", "gi");
content = tinyMCE.regexpReplace(content, "", "", "gi");
content = tinyMCE.regexpReplace(content, "", "", "gi");
tinyMCE.setInnerHTML(inst.getBody(), content);
}
inst.convertAllRelativeURLs();
} else {
if (tinyMCE.settings['cleanup_on_startup']) {
tinyMCE._setHTML(inst.getDoc(), content);
// Produces permission denied error in MSIE 5.5
eval('try {tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));} catch(e) {}');
} else
tinyMCE._setHTML(inst.getDoc(), content);
}
// Fix for bug #957681
//inst.getDoc().designMode = inst.getDoc().designMode;
// Setup element references
var parentElm = document.getElementById(inst.editorId + '_parent');
if (parentElm.lastChild.nodeName == "INPUT")
inst.formElement = tinyMCE.isGecko ? parentElm.firstChild : parentElm.lastChild;
else
inst.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual'], inst);
tinyMCE.executeCallback('setupcontent_callback', '_setupContent', 0, editor_id, inst.getBody(), inst.getDoc());
// Re-add design mode on mozilla
if (!tinyMCE.isMSIE)
TinyMCE.prototype.addEventHandlers(editor_id);
// Add blur handler
if (tinyMCE.isMSIE)
tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE.prototype.eventPatch);
// Trigger node change, this call locks buttons for tables and so forth
tinyMCE.selectedInstance = inst;
tinyMCE.selectedElement = inst.contentWindow.document.body;
if (!inst.isHidden())
tinyMCE.triggerNodeChange(false, true);
// Call custom DOM cleanup
tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
tinyMCE._setEventsEnabled(inst.getBody(), false);
tinyMCE.cleanupAnchors(inst.getDoc());
if (tinyMCE.getParam("convert_fonts_to_spans"))
tinyMCE.convertSpansToFonts(inst.getDoc());
inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
inst.undoLevels[inst.undoLevels.length] = inst.startContent;
tinyMCE.operaOpacityCounter = -1;
};
TinyMCE.prototype.cleanupHTMLCode = function(s) {
s = s.replace(//gi, '
');
s = s.replace(/\s*<\/p>/gi, '
');
// Open closed tags like to
// tinyMCE.debug("f:" + s);
s = s.replace(/<(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|b|em|strong|i|strike|u|span|a|ul|ol|li|blockquote)([a-z]*)([^\\|>]*?)\/>/gi, '<$1$2$3>$1$2>');
// tinyMCE.debug("e:" + s);
// Remove trailing space to
s = s.replace(new RegExp('\\s+>', 'gi'), '>');
// Close tags to
s = s.replace(/<(img|br|hr)(.*?)><\/(img|br|hr)>/gi, '<$1$2 />');
// Weird MSIE bug,
breaks runtime?
if (tinyMCE.isMSIE)
s = s.replace(/
<\/p>/gi, "
");
// Convert relative anchors to absolute URLs ex: #something to file.htm#something
s = s.replace(new RegExp('(href=\"?)(\\s*?#)', 'gi'), '$1' + tinyMCE.settings['document_base_url'] + "#");
return s;
};
TinyMCE.prototype.storeAwayURLs = function(s) {
// Remove all mce_src, mce_href and replace them with new ones
s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');
s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');
return s;
};
TinyMCE.prototype.cancelEvent = function(e) {
if (tinyMCE.isMSIE) {
e.returnValue = false;
e.cancelBubble = true;
} else
e.preventDefault();
};
TinyMCE.prototype.removeTinyMCEFormElements = function(form_obj) {
// Check if form is valid
if (typeof(form_obj) == "undefined" || form_obj == null)
return;
// If not a form, find the form
if (form_obj.nodeName != "FORM") {
if (form_obj.form)
form_obj = form_obj.form;
else
form_obj = tinyMCE.getParentElement(form_obj, "form");
}
// Still nothing
if (form_obj == null)
return;
// Disable all UI form elements that TinyMCE created
for (var i=0; i');
}
}
// Return key pressed
if (tinyMCE.isMSIE && tinyMCE.settings['force_br_newlines'] && e.keyCode == 13) {
if (e.target.editorId)
tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
if (tinyMCE.selectedInstance) {
var sel = tinyMCE.selectedInstance.getDoc().selection;
var rng = sel.createRange();
if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
return false;
// Cancel event
e.returnValue = false;
e.cancelBubble = true;
// Insert BR element
rng.pasteHTML("
");
rng.collapse(false);
rng.select();
tinyMCE.execCommand("mceAddUndoLevel");
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;
if (tinyMCE.selectedInstance)
tinyMCE.selectedInstance.switchSettings();
var inst = tinyMCE.selectedInstance;
// 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
tinyMCE.execCommand("mceAddUndoLevel");
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'], tinyMCE.selectedInstance);
// Fix empty elements on return/enter, check where enter occured
if (tinyMCE.isMSIE && e.type == "keydown" && e.keyCode == 13)
tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();
// Fix empty elements on return/enter
if (tinyMCE.isMSIE && e.type == "keyup" && e.keyCode == 13) {
var elm = tinyMCE.enterKeyElement;
if (elm) {
var re = new RegExp('^HR|IMG|BR$','g'); // Skip these
var dre = new RegExp('^H[1-6]$','g'); // Add double on these
if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {
if (dre.test(elm.nodeName))
elm.innerHTML = " ";
else
elm.innerHTML = " ";
}
}
}
// Check if it's a position key
var keys = tinyMCE.posKeyCodes;
var posKey = false;
for (var i=0; i -1)
suffix = '?rnd=' + this.operaOpacityCounter++;
element.src = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/images/opacity.png" + suffix;
element.style.backgroundImage = "url('" + element.mceOldSrc + "')";
} else {
if (element.mceOldSrc) {
element.src = element.mceOldSrc;
element.parentNode.style.backgroundImage = "";
element.mceOldSrc = null;
}
}
}
}
};
TinyMCE.prototype.restoreClass = function(element) {
if (element != null && element.oldClassName && !element.classLock) {
element.className = element.oldClassName;
element.oldClassName = null;
}
};
TinyMCE.prototype.setClassLock = function(element, lock_state) {
if (element != null)
element.classLock = lock_state;
};
TinyMCE.prototype.addEvent = function(obj, name, handler) {
if (tinyMCE.isMSIE) {
obj.attachEvent("on" + name, handler);
} else
obj.addEventListener(name, handler, false);
};
TinyMCE.prototype.submitPatch = function() {
tinyMCE.removeTinyMCEFormElements(this);
tinyMCE.triggerSave();
this.mceOldSubmit();
tinyMCE.isNotDirty = true;
};
TinyMCE.prototype.onLoad = function() {
for (var c=0; c 0)
return;
if (val.indexOf('%') == -1)
val += 'px';
break;
case "vspace":
case "hspace":
elm.style.marginTop = val + "px";
elm.style.marginBottom = val + "px";
elm.removeAttribute(attrib);
return;
case "align":
if (elm.nodeName == "IMG") {
if (tinyMCE.isMSIE)
elm.style.styleFloat = val;
else
elm.style.cssFloat = val;
} else
elm.style.textAlign = val;
elm.removeAttribute(attrib);
return;
}
if (val != '') {
eval('elm.style.' + style + ' = val;');
elm.removeAttribute(attrib);
}
}
} else {
if (style == '')
return;
var val = eval('elm.style.' + style) == '' ? tinyMCE.getAttrib(elm, attrib) : eval('elm.style.' + style);
val = val == null ? '' : '' + val;
switch (attrib) {
// Always move background to style
case "background":
if (val.indexOf('url') == -1 && val != '')
val = "url('" + val + "');";
if (val != '') {
elm.style.backgroundImage = val;
elm.removeAttribute(attrib);
}
return;
case "border":
case "width":
case "height":
val = val.replace('px', '');
break;
case "align":
if (tinyMCE.getAttrib(elm, 'align') == '') {
if (elm.nodeName == "IMG") {
if (tinyMCE.isMSIE && elm.style.styleFloat != '') {
val = elm.style.styleFloat;
style = 'styleFloat';
} else if (tinyMCE.isGecko && elm.style.cssFloat != '') {
val = elm.style.cssFloat;
style = 'cssFloat';
}
}
}
break;
}
if (val != '') {
elm.removeAttribute(attrib);
elm.setAttribute(attrib, val);
eval('elm.style.' + style + ' = "";');
}
}
};
TinyMCE.prototype._cleanupAttribute = function(valid_attributes, element_name, attribute_node, element_node) {
var attribName = attribute_node.nodeName.toLowerCase();
var attribValue = attribute_node.nodeValue;
var attribMustBeValue = null;
var verified = false;
// Mozilla attibute, remove them
if (attribName.indexOf('moz_') != -1)
return null;
if (!tinyMCE.cleanup_on_save && (attribName == "mce_href" || attribName == "mce_src"))
return {name : attribName, value : attribValue};
// Verify attrib
if (tinyMCE.cleanup_verify_html && !verified) {
for (var i=1; i 1)
val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";
}
// Force HEX colors
if (tinyMCE.getParam("force_hex_style_colors"))
val = tinyMCE.convertRGBToHex(val, true);
if (val != "url('')")
str += key.toLowerCase() + ": " + val + "; ";
}
}
if (new RegExp('; $').test(str))
str = str.substring(0, str.length - 2);
return str;
};
TinyMCE.prototype.convertRGBToHex = function(s, k) {
if (s.toLowerCase().indexOf('rgb') != -1) {
var re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
var rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');
if (rgb.length == 5) {
r = parseInt(rgb[1]).toString(16);
g = parseInt(rgb[2]).toString(16);
b = parseInt(rgb[3]).toString(16);
r = r.length == 1 ? '0' + r : r;
g = g.length == 1 ? '0' + g : g;
b = b.length == 1 ? '0' + b : b;
s = "#" + r + g + b;
if (k)
s = rgb[0] + s + rgb[4];
}
}
return s;
};
TinyMCE.prototype.convertHexToRGB = function(s) {
if (s.indexOf('#') != -1) {
s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');
return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";
}
return s;
};
TinyMCE.prototype._verifyClass = function(node) {
// Sometimes the class gets set to null, weird Gecko bug?
if (tinyMCE.isGecko) {
var className = node.getAttribute('class');
if (!className)
return false;
}
// 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' + output;
}
}
// Remove deprecated attributes
var re = new RegExp("^(TABLE|TD|TR)$");
if (re.test(node.nodeName)) {
// Move attrib to style
if ((node.nodeName != "TABLE" || tinyMCE.cleanup_inline_styles) && (width = tinyMCE.getAttrib(node, "width")) != '') {
node.style.width = width.indexOf('%') != -1 ? width : width.replace(/[^0-9]/gi, '') + "px";
node.removeAttribute("width");
}
// Is table and not inline
if ((node.nodeName == "TABLE" && !tinyMCE.cleanup_inline_styles) && node.style.width != '') {
tinyMCE.setAttrib(node, "width", node.style.width.replace('px',''));
node.style.width = '';
}
// Move attrib to style
if ((height = tinyMCE.getAttrib(node, "height")) != '') {
height = "" + height; // Force string
node.style.height = height.indexOf('%') != -1 ? height : height.replace(/[^0-9]/gi, '') + "px";
node.removeAttribute("height");
}
}
// Handle inline/outline styles
if (tinyMCE.cleanup_inline_styles) {
var re = new RegExp("^(TABLE|TD|TR|IMG|HR)$");
if (re.test(node.nodeName) && tinyMCE.getAttrib(node, "class").indexOf('mceItem') == -1) {
tinyMCE._moveStyle(node, 'width', 'width');
tinyMCE._moveStyle(node, 'height', 'height');
tinyMCE._moveStyle(node, 'borderWidth', 'border');
tinyMCE._moveStyle(node, '', 'vspace');
tinyMCE._moveStyle(node, '', 'hspace');
tinyMCE._moveStyle(node, 'textAlign', 'align');
tinyMCE._moveStyle(node, 'backgroundColor', 'bgColor');
tinyMCE._moveStyle(node, 'borderColor', 'borderColor');
tinyMCE._moveStyle(node, 'backgroundImage', 'background');
// Refresh element in old MSIE
if (tinyMCE.isMSIE5)
node.outerHTML = node.outerHTML;
} else if (tinyMCE.isBlockElement(node))
tinyMCE._moveStyle(node, 'textAlign', 'align');
if (node.nodeName == "FONT")
tinyMCE._moveStyle(node, 'color', 'color');
}
// Set attrib data
if (elementValidAttribs) {
for (var a=1; a" + node.innerHTML + "";
// Remove empty tables
if (elementName == "table" && !node.hasChildNodes())
return "";
// Handle element attributes
if (node.attributes.length > 0) {
var lastAttrib = "";
for (var i=0; i" + this.convertStringToXML(String.fromCharCode(160)) + "" + elementName + ">";
// Is MSIE script element
if (tinyMCE.isMSIE && elementName == "script")
return "<" + elementName + elementAttribs + ">" + node.text + "" + elementName + ">";
// Clean up children
if (node.hasChildNodes()) {
// If not empty span
if (!(elementName == "span" && elementAttribs == "" && tinyMCE.getParam("trim_span_elements"))) {
// Force BR
if (elementName == "p" && tinyMCE.cleanup_force_br_newlines)
output += "";
else
output += "<" + elementName + elementAttribs + ">";
}
for (var i=0; i
";
else
output += "" + elementName + ">";
}
} else {
if (!nonEmptyTag) {
if (openTag)
output += "<" + elementName + elementAttribs + ">" + elementName + ">";
else
output += "<" + elementName + elementAttribs + " />";
}
}
return output;
case 3: // Text
// Do not convert script elements
if (node.parentNode.nodeName == "SCRIPT" || node.parentNode.nodeName == "NOSCRIPT" || node.parentNode.nodeName == "STYLE")
return node.nodeValue;
return this.convertStringToXML(node.nodeValue);
case 8: // Comment
return "";
default: // Unknown
return "[UNKNOWN NODETYPE " + node.nodeType + "]";
}
};
TinyMCE.prototype.convertStringToXML = function(html_data) {
var output = "";
for (var i=0; i 127)
output += '' + chr + ";";
else
output += String.fromCharCode(chr);
continue;
}
// Raw entities
if (tinyMCE.settings['entity_encoding'] == "raw") {
output += String.fromCharCode(chr);
continue;
}
// Named entities
if (typeof(tinyMCE.settings['cleanup_entities']["c" + chr]) != 'undefined' && tinyMCE.settings['cleanup_entities']["c" + chr] != '')
output += '&' + tinyMCE.settings['cleanup_entities']["c" + chr] + ';';
else
output += '' + String.fromCharCode(chr);
}
return output;
};
TinyMCE.prototype._getCleanupElementName = function(chunk) {
var pos;
if (chunk.charAt(0) == '+')
chunk = chunk.substring(1);
if (chunk.charAt(0) == '-')
chunk = chunk.substring(1);
if ((pos = chunk.indexOf('/')) != -1)
chunk = chunk.substring(0, pos);
if ((pos = chunk.indexOf('[')) != -1)
chunk = chunk.substring(0, pos);
return chunk;
};
TinyMCE.prototype._initCleanup = function() {
// 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/gi, '>');
return html;
}
if (on_save && tinyMCE.getParam("convert_fonts_to_spans"))
tinyMCE.convertFontsToSpans(doc);
// Call custom cleanup code
tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);
// Move bgcolor to style
var n = doc.getElementsByTagName("font");
for (var i=0; i[ \n\r]*[ \n\r]*', '
', 'gi'));
tinyMCE.setInnerHTML(element, tinyMCE.regexpReplace(element.innerHTML, '', '', 'gi'));
}
var html = this.cleanupNode(element);
if (tinyMCE.settings['debug'])
tinyMCE.debug("Cleanup process executed in: " + (new Date().getTime()-startTime) + " ms.");
// Remove pesky HR paragraphs and other crap
html = tinyMCE.regexpReplace(html, '
', '
');
html = tinyMCE.regexpReplace(html, '
', '
');
html = tinyMCE.regexpReplace(html, '\\s* \\s* | ', ' | ');
html = tinyMCE.regexpReplace(html, '\\s*
\\s*
', '
');
html = tinyMCE.regexpReplace(html, '\\s* \\s*
\\s* \\s*
', '
');
html = tinyMCE.regexpReplace(html, '\\s* \\s*
\\s*
', '
');
html = tinyMCE.regexpReplace(html, '\\s*
\\s* \\s*
', '
');
// Remove empty anchors
html = html.replace(new RegExp('(.*?)', 'gi'), '$1');
// Remove some mozilla crap
if (!tinyMCE.isMSIE)
html = html.replace(new RegExp('', 'g'), "");
if (tinyMCE.settings['remove_linebreaks'])
html = html.replace(new RegExp('\r|\n', 'g'), ' ');
if (tinyMCE.getParam('apply_source_formatting')) {
html = html.replace(new RegExp('<(p|div)([^>]*)>', 'g'), "\n<$1$2>\n");
html = html.replace(new RegExp('<\/(p|div)([^>]*)>', 'g'), "\n$1$2>\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.isGecko && tinyMCE.settings['remove_lt_gt']) {
// Remove weridness!
var re = new RegExp('<>', 'g');
html = html.replace(re, "");
}
// Call custom cleanup code
html = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", html);
// Emtpy node, return empty
var chk = tinyMCE.regexpReplace(html, "[ \t\r\n]", "").toLowerCase();
if (chk == "
" || chk == "
" || chk == "
" || chk == "
" || chk == "")
html = "";
if (tinyMCE.settings["preformatted"])
return "" + html + "
";
return html;
};
TinyMCE.prototype.insertLink = function(href, target, title, onclick, style_class) {
tinyMCE.execCommand('mceBeginUndoLevel');
if (this.selectedInstance && this.selectedElement && this.selectedElement.nodeName.toLowerCase() == "img") {
var doc = this.selectedInstance.getDoc();
var linkElement = tinyMCE.getParentElement(this.selectedElement, "a");
var newLink = false;
if (!linkElement) {
linkElement = doc.createElement("a");
newLink = true;
}
var mhref = href;
var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, linkElement);");
mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
tinyMCE.setAttrib(linkElement, 'href', thref);
tinyMCE.setAttrib(linkElement, 'mce_href', mhref);
tinyMCE.setAttrib(linkElement, 'target', target);
tinyMCE.setAttrib(linkElement, 'title', title);
tinyMCE.setAttrib(linkElement, 'onclick', onclick);
tinyMCE.setAttrib(linkElement, 'class', style_class);
if (newLink) {
linkElement.appendChild(this.selectedElement.cloneNode(true));
this.selectedElement.parentNode.replaceChild(linkElement, this.selectedElement);
}
return;
}
if (!this.linkElement && this.selectedInstance) {
if (tinyMCE.isSafari) {
tinyMCE.execCommand("mceInsertContent", false, '' + this.selectedInstance.getSelectedHTML() + '');
} else
this.selectedInstance.contentDocument.execCommand("createlink", false, tinyMCE.uniqueURL);
tinyMCE.linkElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
var elementArray = this.getElementsByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
for (var i=0; i';
tinyMCE.execCommand("mceInsertContent", false, html);
} else {
if (!this.imgElement && this.selectedInstance) {
if (tinyMCE.isSafari)
tinyMCE.execCommand("mceInsertContent", false, '');
else
this.selectedInstance.contentDocument.execCommand("insertimage", false, tinyMCE.uniqueURL);
tinyMCE.imgElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "img", "src", tinyMCE.uniqueURL);
}
}
if (this.imgElement) {
var needsRepaint = false;
var msrc = src;
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, tinyMCE.imgElement);");
if (tinyMCE.getParam('convert_urls'))
msrc = src;
if (onmouseover && onmouseover != "")
onmouseover = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, tinyMCE.imgElement);") + "';";
if (onmouseout && onmouseout != "")
onmouseout = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, tinyMCE.imgElement);") + "';";
// Use alt as title if it's undefined
if (typeof(title) == "undefined")
title = alt;
if (width != this.imgElement.getAttribute("width") || height != this.imgElement.getAttribute("height") || align != this.imgElement.getAttribute("align"))
needsRepaint = true;
tinyMCE.setAttrib(this.imgElement, 'src', src);
tinyMCE.setAttrib(this.imgElement, 'mce_src', msrc);
tinyMCE.setAttrib(this.imgElement, 'alt', alt);
tinyMCE.setAttrib(this.imgElement, 'title', title);
tinyMCE.setAttrib(this.imgElement, 'align', align);
tinyMCE.setAttrib(this.imgElement, 'border', border, true);
tinyMCE.setAttrib(this.imgElement, 'hspace', hspace, true);
tinyMCE.setAttrib(this.imgElement, 'vspace', vspace, true);
tinyMCE.setAttrib(this.imgElement, 'width', width, true);
tinyMCE.setAttrib(this.imgElement, 'height', height, true);
tinyMCE.setAttrib(this.imgElement, 'onmouseover', onmouseover);
tinyMCE.setAttrib(this.imgElement, 'onmouseout', onmouseout);
// Fix for bug #989846 - Image resize bug
if (width && width != "")
this.imgElement.style.pixelWidth = width;
if (height && height != "")
this.imgElement.style.pixelHeight = height;
if (needsRepaint)
tinyMCE.selectedInstance.repaint();
}
tinyMCE.execCommand('mceEndUndoLevel');
};
TinyMCE.prototype.getElementByAttributeValue = function(node, element_name, attrib, value) {
var elements = this.getElementsByAttributeValue(node, element_name, attrib, value);
if (elements.length == 0)
return null;
return elements[0];
};
TinyMCE.prototype.getElementsByAttributeValue = function(node, element_name, attrib, value) {
var elements = new Array();
if (node && node.nodeName.toLowerCase() == element_name) {
if (node.getAttribute(attrib) && node.getAttribute(attrib).indexOf(value) != -1)
elements[elements.length] = node;
}
if (node && node.hasChildNodes()) {
for (var x=0, n=node.childNodes.length; x= 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 targetURL.path;
for (var i=0; i<(strTok1.length-(breakPoint-1)); i++)
outPath += "../";
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 output URL
relURL.protocol = baseURL.protocol;
relURL.host = baseURL.host;
relURL.port = baseURL.port;
// Re-add trailing slash if it's removed
if (relURL.path.charAt(relURL.path.length-1) == "/")
absPath += "/";
relURL.path = absPath;
return TinyMCE.prototype.serializeURL(relURL);
};
TinyMCE.prototype.getParam = function(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;
}
tinyMCE.executeCallback('handleNodeChangeCallback', '_handleNodeChange', 0, editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
}
}
if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
this.selectedInstance.contentWindow.focus();
};
TinyMCE.prototype._customCleanup = function(inst, type, content) {
// Call custom cleanup
var customCleanup = tinyMCE.settings['cleanup_callback'];
if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined")
content = eval(customCleanup + "(type, content, inst);");
// Trigger plugin cleanups
var plugins = tinyMCE.getParam('plugins', '', true, ',');
for (var i=0; i 0)
className += " ";
className += classNames[i];
}
return className;
};
TinyMCE.prototype.handleVisualAid = function(el, deep, state, inst) {
if (!el)
return;
var tableElement = null;
switch (el.nodeName) {
case "TABLE":
var oldW = el.style.width;
var oldH = el.style.height;
var bo = tinyMCE.getAttrib(el, "border");
bo = bo == "" || bo == "0" ? true : false;
tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));
el.style.width = oldW;
el.style.height = oldH;
for (var y=0; y 0) {
tinyMCE.setAttrib(s[i], 'size', fSize);
s[i].style.fontSize = '';
}
var fFace = s[i].style.fontFamily;
if (fFace != null && fFace != "") {
tinyMCE.setAttrib(s[i], 'face', fFace);
s[i].style.fontFamily = '';
}
var fColor = s[i].style.color;
if (fColor != null && fColor != "") {
tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));
s[i].style.color = '';
}
}
};
TinyMCE.prototype.convertFontsToSpans = function(doc) {
var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
var h = doc.body.innerHTML;
h = h.replace(/ 0 && fSize < 8) {
if (fsClasses != null)
tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);
else
s[i].style.fontSize = sizes[fSize-1];
}
s[i].removeAttribute('size');
}
if (fFace != "") {
s[i].style.fontFamily = fFace;
s[i].removeAttribute('face');
}
if (fColor != "") {
s[i].style.color = fColor;
s[i].removeAttribute('color');
}
}
};
/*
TinyMCE.prototype.applyClassesToFonts = function(doc, size) {
var f = doc.getElementsByTagName("font");
for (var i=0; i=0; x--)
tinyMCE.insertAfter(cn[x], an[i]);
}
}
};
TinyMCE.prototype._setHTML = function(doc, html_content) {
// Force closed anchors open
//html_content = html_content.replace(new RegExp('', 'gi'), '');
html_content = tinyMCE.cleanupHTMLCode(html_content);
// Try innerHTML if it fails use pasteHTML in MSIE
try {
tinyMCE.setInnerHTML(doc.body, html_content);
} catch (e) {
if (this.isMSIE)
doc.body.createTextRange().pasteHTML(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
tinyMCE.setInnerHTML(doc.body, html);
}
tinyMCE.cleanupAnchors(doc);
if (tinyMCE.getParam("convert_fonts_to_spans"))
tinyMCE.convertSpansToFonts(doc);
};
TinyMCE.prototype.getImageSrc = function(str) {
var pos = -1;
if (!str)
return "";
if ((pos = str.indexOf('this.src=')) != -1) {
var src = str.substring(pos + 10);
src = src.substring(0, src.indexOf('\''));
return src;
}
return "";
};
TinyMCE.prototype._getElementById = function(element_id) {
var elm = document.getElementById(element_id);
if (!elm) {
// Check for element in forms
for (var j=0; j 0) {
for (var x=0; x 0)
tinyMCE.cssClasses = output;
return output;
};
TinyMCE.prototype.regexpReplace = function(in_str, reg_exp, replace_str, opts) {
if (in_str == null)
return in_str;
if (typeof(opts) == "undefined")
opts = 'g';
var re = new RegExp(reg_exp, opts);
return in_str.replace(re, replace_str);
};
TinyMCE.prototype.trim = function(str) {
return str.replace(/^\s*|\s*$/g, "");
};
TinyMCE.prototype.cleanupEventStr = function(str) {
str = "" + str;
str = str.replace('function anonymous()\n{\n', '');
str = str.replace('\n}', '');
str = str.replace(/^return true;/gi, ''); // Remove event blocker
return str;
};
TinyMCE.prototype.getAbsPosition = function(node) {
var pos = new Object();
pos.absLeft = pos.absTop = 0;
var parentNode = node;
while (parentNode) {
pos.absLeft += parentNode.offsetLeft;
pos.absTop += parentNode.offsetTop;
parentNode = parentNode.offsetParent;
}
return pos;
};
TinyMCE.prototype.getControlHTML = function(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 + "');");
};
TinyMCE.prototype._themeExecCommand = function(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;
};
TinyMCE.prototype._getThemeFunction = function(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;
};
TinyMCE.prototype.isFunc = function(func_name) {
if (func_name == null || func_name == "")
return false;
return eval("typeof(" + func_name + ")") != "undefined";
};
TinyMCE.prototype.exec = function(func_name, args) {
var str = func_name + '(';
// Add all arguments
for (var i=3; i 1 && tinyMCE.currentConfig != this.settings['index']) {
tinyMCE.settings = this.settings;
tinyMCE.currentConfig = this.settings['index'];
}
};
TinyMCEControl.prototype.convertAllRelativeURLs = function() {
var body = this.getBody();
// Convert all image URL:s to absolute URL
var elms = body.getElementsByTagName("img");
for (var i=0; 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);
}
this.scrollToNode(node);
// Set selected element
tinyMCE.selectedElement = null;
if (node.nodeType == 1)
tinyMCE.selectedElement = node;
};
TinyMCEControl.prototype.scrollToNode = function(node) {
// 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 : this.targetElement.clientHeight;
// Only scroll if out of visible area
if (!tinyMCE.settings['auto_resize'] && !(pos.absTop > scrollY && pos.absTop < (scrollY - 25 + height)))
this.contentWindow.scrollTo(pos.absLeft, pos.absTop - height + 25);
};
TinyMCEControl.prototype.getBody = function() {
return this.getDoc().body;
};
TinyMCEControl.prototype.getDoc = function() {
return this.contentWindow.document;
};
TinyMCEControl.prototype.getWin = function() {
return this.contentWindow;
};
TinyMCEControl.prototype.getSel = function() {
if (tinyMCE.isMSIE && !tinyMCE.isOpera)
return this.getDoc().selection;
var sel = this.contentWindow.getSelection();
// Fake getRangeAt
if (tinyMCE.isSafari && !sel.getRangeAt) {
var newSel = new Object();
var doc = this.getDoc();
function getRangeAt(idx) {
var rng = new Object();
rng.startContainer = this.focusNode;
rng.endContainer = this.anchorNode;
rng.commonAncestorContainer = this.focusNode;
rng.createContextualFragment = function (html) {
// Seems to be a tag
if (html.charAt(0) == '<') {
var elm = doc.createElement("div");
elm.innerHTML = html;
return elm.firstChild;
}
return doc.createTextNode("UNSUPPORTED, DUE TO LIMITATIONS IN SAFARI!");
};
rng.deleteContents = function () {
doc.execCommand("Delete", false, "");
};
return rng;
}
// Patch selection
newSel.focusNode = sel.baseNode;
newSel.focusOffset = sel.baseOffset;
newSel.anchorNode = sel.extentNode;
newSel.anchorOffset = sel.extentOffset;
newSel.getRangeAt = getRangeAt;
newSel.text = "" + sel;
newSel.realSelection = sel;
newSel.toString = function () {return this.text;};
return newSel;
}
return sel;
};
TinyMCEControl.prototype.getRng = function() {
var sel = this.getSel();
if (sel == null)
return null;
if (tinyMCE.isMSIE && !tinyMCE.isOpera)
return sel.createRange();
if (tinyMCE.isSafari) {
var rng = this.getDoc().createRange();
var sel = this.getSel().realSelection;
rng.setStart(sel.baseNode, sel.baseOffset);
rng.setEnd(sel.extentNode, sel.extentOffset);
return rng;
}
return this.getSel().getRangeAt(0);
};
TinyMCEControl.prototype._insertPara = function(e) {
function isEmpty(para) {
function isEmptyHTML(html) {
return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == "";
}
// Check for images
if (para.getElementsByTagName("img").length > 0)
return false;
// Check for tables
if (para.getElementsByTagName("table").length > 0)
return false;
// Check for HRs
if (para.getElementsByTagName("hr").length > 0)
return false;
// Check all textnodes
var nodes = tinyMCE.getNodeTree(para, new Array(), 3);
for (var i=0; i " + blockName + "><" + blockName + "> " + blockName + ">";
paraAfter = body.childNodes[1];
}
this.selectNode(paraAfter, true, true);
return true;
}
// Place first part within new paragraph
if (startChop.nodeName == blockName)
rngBefore.setStart(startChop, 0);
else
rngBefore.setStartBefore(startChop);
rngBefore.setEnd(startNode, startOffset);
paraBefore.appendChild(rngBefore.cloneContents());
// Place secound part within new paragraph
rngAfter.setEndAfter(endChop);
rngAfter.setStart(endNode, endOffset);
var contents = rngAfter.cloneContents();
if (contents.firstChild && contents.firstChild.nodeName == blockName) {
/* var nodes = contents.firstChild.childNodes;
for (var i=0; i 0)
rng.pasteHTML('' + rng.htmlText + "
");
tinyMCE.triggerNodeChange();
return;
}
}
}
switch (command) {
case "mceRepaint":
this.repaint();
return true;
case "mceStoreSelection":
this.selectionBookmark = this.getBookmark();
return true;
case "mceRestoreSelection":
this.moveToBookmark(this.selectionBookmark);
return true;
case "InsertUnorderedList":
case "InsertOrderedList":
var tag = (command == "InsertUnorderedList") ? "ul" : "ol";
if (tinyMCE.isSafari)
this.execCommand("mceInsertContent", false, "<" + tag + "> <" + tag + ">");
else
this.getDoc().execCommand(command, user_interface, value);
tinyMCE.triggerNodeChange();
break;
case "Strikethrough":
if (tinyMCE.isSafari)
this.execCommand("mceInsertContent", false, "" + this.getSelectedHTML() + "");
else
this.getDoc().execCommand(command, user_interface, value);
tinyMCE.triggerNodeChange();
break;
case "mceSelectNode":
this.selectNode(value);
tinyMCE.triggerNodeChange();
tinyMCE.selectedNode = value;
break;
case "FormatBlock":
if (value == null || value == "") {
var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address");
if (elm)
this.execCommand("mceRemoveNode", false, elm);
} else
this.getDoc().execCommand("FormatBlock", false, value);
tinyMCE.triggerNodeChange();
break;
case "mceRemoveNode":
if (!value)
value = tinyMCE.getParentElement(this.getFocusElement());
if (tinyMCE.isMSIE) {
value.outerHTML = value.innerHTML;
} else {
var rng = value.ownerDocument.createRange();
rng.setStartBefore(value);
rng.setEndAfter(value);
rng.deleteContents();
rng.insertNode(rng.createContextualFragment(value.innerHTML));
}
tinyMCE.triggerNodeChange();
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 "SetStyleInfo":
var rng = this.getRng();
var sel = this.getSel();
var scmd = value['command'];
var sname = value['name'];
var svalue = value['value'] == null ? '' : value['value'];
//var svalue = value['value'] == null ? '' : value['value'];
var wrapper = value['wrapper'] ? value['wrapper'] : "span";
var parentElm = null;
var invalidRe = new RegExp("^BODY|HTML$", "g");
var invalidParentsRe = tinyMCE.settings['merge_styles_invalid_parents'] != '' ? new RegExp(tinyMCE.settings['merge_styles_invalid_parents'], "gi") : null;
// Whole element selected check
if (tinyMCE.isMSIE) {
// Control range
if (rng.item)
parentElm = rng.item(0);
else {
var pelm = rng.parentElement();
var prng = doc.selection.createRange();
prng.moveToElementText(pelm);
if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {
if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))
parentElm = pelm;
}
}
} else {
var felm = this.getFocusElement();
if (sel.isCollapsed || (/td|tr|tbody|table/ig.test(felm.nodeName) && sel.anchorNode == felm.parentNode))
parentElm = felm;
}
// Whole element selected
if (parentElm && !invalidRe.test(parentElm.nodeName)) {
if (scmd == "setstyle")
tinyMCE.setStyleAttrib(parentElm, sname, svalue);
if (scmd == "setattrib")
tinyMCE.setAttrib(parentElm, sname, svalue);
if (scmd == "removeformat") {
parentElm.style.cssText = '';
tinyMCE.setAttrib(parentElm, 'class', '');
}
// Remove style/attribs from all children
var ch = tinyMCE.getNodeTree(parentElm, new Array(), 1);
for (var z=0; z=0; i--) {
var elm = nodes[i];
var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";
elm.removeAttribute("mce_new");
// Is only child a element
if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {
//tinyMCE.debug("merge1" + isNew);
this._mergeElements(scmd, elm, elm.childNodes[0], isNew);
continue;
}
// Is I the only child
if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {
//tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);
if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))
this._mergeElements(scmd, elm.parentNode, elm, false);
}
}
// Remove empty wrappers
var nodes = doc.getElementsByTagName(wrapper);
for (var i=nodes.length-1; i>=0; i--) {
var elm = nodes[i];
var isEmpty = true;
// Check if it has any attribs
var tmp = doc.createElement("body");
tmp.appendChild(elm.cloneNode(false));
// Is empty span, remove it
tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');
//tinyMCE.debug(tmp.innerHTML);
if (new RegExp('', 'gi').test(tmp.innerHTML)) {
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":
this.execCommand("SetStyleInfo", false, {command : "setattrib", name : "class", value : value});
break;
case "mceInsertRawHTML":
var key = 'tiny_mce_marker';
this.execCommand('mceBeginUndoLevel');
// Insert marker key
this.execCommand('mceInsertContent', false, key);
// Store away scroll pos
var scrollX = this.getDoc().body.scrollLeft + this.getDoc().documentElement.scrollLeft;
var scrollY = this.getDoc().body.scrollTop + this.getDoc().documentElement.scrollTop;
// Find marker and replace with RAW HTML
var html = this.getBody().innerHTML;
if ((pos = html.indexOf(key)) != -1)
tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));
// Restore scoll pos
this.contentWindow.scrollTo(scrollX, scrollY);
this.execCommand('mceEndUndoLevel');
break;
case "mceInsertContent":
var insertHTMLFailed = false;
this.getWin().focus();
/* WP
if (tinyMCE.isGecko || tinyMCE.isOpera) {
try {
// Is plain text or HTML
if (value.indexOf('<') == -1) {
var r = this.getRng();
var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));
var s = this.getSel();
var r2 = r.cloneRange();
// Insert text at cursor position
s.removeAllRanges();
r.deleteContents();
r.insertNode(n);
// Move the cursor to the end of text
r2.selectNode(n);
r2.collapse(false);
s.removeAllRanges();
s.addRange(r2);
} else {
value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);
this.getDoc().execCommand('inserthtml', false, value);
tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
}
} catch (ex) {
insertHTMLFailed = true;
}
if (!insertHTMLFailed) {
tinyMCE.triggerNodeChange();
return;
}
}
*/
// Ugly hack in Opera due to non working "inserthtml"
if (tinyMCE.isOpera && insertHTMLFailed) {
this.getDoc().execCommand("insertimage", false, tinyMCE.uniqueURL);
var ar = tinyMCE.getElementsByAttributeValue(this.getBody(), "img", "src", tinyMCE.uniqueURL);
ar[0].outerHTML = value;
return;
}
if (!tinyMCE.isMSIE) {
var isHTML = value.indexOf('<') != -1;
var sel = this.getSel();
var rng = this.getRng();
if (isHTML) {
if (tinyMCE.isSafari) {
var tmpRng = this.getDoc().createRange();
tmpRng.setStart(this.getBody(), 0);
tmpRng.setEnd(this.getBody(), 0);
value = tmpRng.createContextualFragment(value);
} else
value = rng.createContextualFragment(value);
} else {
// Setup text node
var el = document.createElement("div");
el.innerHTML = value;
value = el.firstChild.nodeValue;
value = doc.createTextNode(value);
}
// Insert plain text in Safari
if (tinyMCE.isSafari && !isHTML) {
this.execCommand('InsertText', false, value.nodeValue);
tinyMCE.triggerNodeChange();
return true;
} else if (tinyMCE.isSafari && isHTML) {
rng.deleteContents();
rng.insertNode(value);
tinyMCE.triggerNodeChange();
return true;
}
rng.deleteContents();
// If target node is text do special treatment, (Mozilla 1.3 fix)
if (rng.startContainer.nodeType == 3) {
var node = rng.startContainer.splitText(rng.startOffset);
node.parentNode.insertBefore(value, node);
} else
rng.insertNode(value);
if (!isHTML) {
// Removes weird selection trails
sel.selectAllChildren(doc.body);
sel.removeAllRanges();
// Move cursor to end of content
var rng = doc.createRange();
rng.selectNode(value);
rng.collapse(false);
sel.addRange(rng);
} else
rng.collapse(false);
} else {
var rng = doc.selection.createRange();
var c = value.indexOf('