/** * $Id$ * * @author Moxiecode * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. * * The contents of this file will be wrapped in a class later on. */ /**#@+ * @member TinyMCE_Engine * @method */ tinyMCE.add(TinyMCE_Engine, { /** * Creates a HTML tag by name and attributes array. This will XML encode all attribute values. * * @param {string} tn Tag name to create. * @param {Array} a Optional name/Value array of attributes. * @param {string} h Optional inner HTML of new tag, raw HTML code. */ createTagHTML : function(tn, a, h) { var o = '', f = tinyMCE.xmlEncode, n; o = '<' + tn; if (a) { for (n in a) { if (typeof(a[n]) != 'function' && a[n] != null) o += ' ' + f(n) + '="' + f('' + a[n]) + '"'; } } o += !h ? ' />' : '>' + h + ''; return o; }, /** * Creates a tag by name and attributes array. This will create a DOM node out of the specified * data. * * @param {string} d Document to create DOM node in. * @param {string} tn Tag name to create. * @param {Array} a Optional name/Value array of attributes. * @param {string} h Optional inner HTML of new tag, raw HTML code. */ createTag : function(d, tn, a, h) { var o = d.createElement(tn), n; if (a) { for (n in a) { if (typeof(a[n]) != 'function' && a[n] != null) tinyMCE.setAttrib(o, n, a[n]); } } if (h) o.innerHTML = h; return o; }, /** * Returns a element by a specific attribute and it's value. * * @param {HTMLElement} n Element to search in. * @param {string} e Element name to search for. * @param {string} a Attribute name to search for. * @param {string} v Attribute value to search for. * @return HTML element that matched the criterias or null on failure. * @type HTMLElement */ getElementByAttributeValue : function(n, e, a, v) { return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0]; }, /** * Returns a element array by a specific attribute and it's value. * * @param {HTMLElement} n Element to search in. * @param {string} e Element name to search for. * @param {string} a Attribute name to search for. * @param {string} v Attribute value to search for. * @return HTML element array that matched the criterias or null on failure. * @type Array */ getElementsByAttributeValue : function(n, e, a, v) { var i, nl = n.getElementsByTagName(e), o = []; for (i=0; i]*)>/gi, ''); h = h.replace(/]*)>/gi, ''); h = h.replace(/]*)>/gi, ''); h = h.replace(/]*)>/gi, ''); h = h.replace(/<\/strong>/gi, ''); h = h.replace(/<\/em>/gi, ''); } if (tinyMCE.isRealIE) { // Since MSIE handles invalid HTML better that valid XHTML we // need to make some things invalid.
gets converted to
. h = h.replace(/\s\/>/g, '>'); // Since MSIE auto generated emtpy P tags some times we must tell it to keep the real ones h = h.replace(/]*)>\u00A0?<\/p>/gi, ' 

'); // Keep empty paragraphs h = h.replace(/]*)>\s* \s*<\/p>/gi, ' 

'); // Keep empty paragraphs h = h.replace(/]*)>\s+<\/p>/gi, ' 

'); // Keep empty paragraphs // Remove first comment e.innerHTML = tinyMCE.uniqueTag + h; e.firstChild.removeNode(true); // Remove weird auto generated empty paragraphs unless it's supposed to be there nl = e.getElementsByTagName("p"); for (i=nl.length-1; i>=0; i--) { n = nl[i]; if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep) n.parentNode.removeChild(n); } } else { h = this.fixGeckoBaseHREFBug(1, e, h); e.innerHTML = h; this.fixGeckoBaseHREFBug(2, e, h); } }, /** * Returns the outer HTML of a element, this uses the outerHTML * property in MSIE and Opera and a workaround for Gecko. * * @param {HTMLElement} e HTML element to get outerHTML from. * @return HTML content string. * @type string */ getOuterHTML : function(e) { var d; if (tinyMCE.isIE) return e.outerHTML; d = e.ownerDocument.createElement("body"); d.appendChild(e.cloneNode(true)); return d.innerHTML; }, /** * Sets the outer HTML of a element, this uses the outerHTML * property in MSIE and Opera and a workaround for Gecko. * * @param {HTMLElement} e HTML element to set outerHTML on. * @param {string} h HTML string to set in property. * @param {DOMDocument} d Optional document instance (Required in old IE versions). */ setOuterHTML : function(e, h, d) { var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t; if (tinyMCE.isIE && e.nodeType == 1) e.outerHTML = h; else { t = d.createElement("body"); t.innerHTML = h; for (i=0, nl=t.childNodes; i-1; i--) { if (ar[i].specified && ar[i].nodeValue) ne.setAttribute(ar[i].nodeName.toLowerCase(), ar[i].nodeValue); } ar = e.childNodes; for (i=0; i