+++ /dev/null
-/*\r
- * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
- * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
- *\r
- * == BEGIN LICENSE ==\r
- *\r
- * Licensed under the terms of any of the following licenses at your\r
- * choice:\r
- *\r
- * - GNU General Public License Version 2 or later (the "GPL")\r
- * http://www.gnu.org/licenses/gpl.html\r
- *\r
- * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
- * http://www.gnu.org/licenses/lgpl.html\r
- *\r
- * - Mozilla Public License Version 1.1 or later (the "MPL")\r
- * http://www.mozilla.org/MPL/MPL-1.1.html\r
- *\r
- * == END LICENSE ==\r
- *\r
- * Defines the FCKXHtml object, responsible for the XHTML operations.\r
- */\r
-\r
-var FCKXHtml = new Object() ;\r
-\r
-FCKXHtml.CurrentJobNum = 0 ;\r
-\r
-FCKXHtml.GetXHTML = function( node, includeNode, format )\r
-{\r
- FCKDomTools.CheckAndRemovePaddingNode( FCKTools.GetElementDocument( node ), FCKConfig.EnterMode ) ;\r
- FCKXHtmlEntities.Initialize() ;\r
-\r
- // Set the correct entity to use for empty blocks.\r
- this._NbspEntity = ( FCKConfig.ProcessHTMLEntities? 'nbsp' : '#160' ) ;\r
-\r
- // Save the current IsDirty state. The XHTML processor may change the\r
- // original HTML, dirtying it.\r
- var bIsDirty = FCK.IsDirty() ;\r
-\r
- // Special blocks are blocks of content that remain untouched during the\r
- // process. It is used for SCRIPTs and STYLEs.\r
- FCKXHtml.SpecialBlocks = new Array() ;\r
-\r
- // Create the XML DOMDocument object.\r
- this.XML = FCKTools.CreateXmlObject( 'DOMDocument' ) ;\r
-\r
- // Add a root element that holds all child nodes.\r
- this.MainNode = this.XML.appendChild( this.XML.createElement( 'xhtml' ) ) ;\r
-\r
- FCKXHtml.CurrentJobNum++ ;\r
-\r
-// var dTimer = new Date() ;\r
-\r
- if ( includeNode )\r
- this._AppendNode( this.MainNode, node ) ;\r
- else\r
- this._AppendChildNodes( this.MainNode, node, false ) ;\r
-\r
- // Get the resulting XHTML as a string.\r
- var sXHTML = this._GetMainXmlString() ;\r
-\r
-// alert( 'Time: ' + ( ( ( new Date() ) - dTimer ) ) + ' ms' ) ;\r
-\r
- this.XML = null ;\r
-\r
- // Safari adds xmlns="http://www.w3.org/1999/xhtml" to the root node (#963)\r
- if ( FCKBrowserInfo.IsSafari )\r
- sXHTML = sXHTML.replace( /^<xhtml.*?>/, '<xhtml>' ) ;\r
-\r
- // Strip the "XHTML" root node.\r
- sXHTML = sXHTML.substr( 7, sXHTML.length - 15 ).Trim() ;\r
-\r
- // According to the doctype set the proper end for self-closing tags\r
- // HTML: <br>\r
- // XHTML: Add a space, like <br/> -> <br />\r
- if (FCKConfig.DocType.length > 0 && FCKRegexLib.HtmlDocType.test( FCKConfig.DocType ) )\r
- sXHTML = sXHTML.replace( FCKRegexLib.SpaceNoClose, '>');\r
- else\r
- sXHTML = sXHTML.replace( FCKRegexLib.SpaceNoClose, ' />');\r
-\r
- if ( FCKConfig.ForceSimpleAmpersand )\r
- sXHTML = sXHTML.replace( FCKRegexLib.ForceSimpleAmpersand, '&' ) ;\r
-\r
- if ( format )\r
- sXHTML = FCKCodeFormatter.Format( sXHTML ) ;\r
-\r
- // Now we put back the SpecialBlocks contents.\r
- for ( var i = 0 ; i < FCKXHtml.SpecialBlocks.length ; i++ )\r
- {\r
- var oRegex = new RegExp( '___FCKsi___' + i ) ;\r
- sXHTML = sXHTML.replace( oRegex, FCKXHtml.SpecialBlocks[i] ) ;\r
- }\r
-\r
- // Replace entities marker with the ampersand.\r
- sXHTML = sXHTML.replace( FCKRegexLib.GeckoEntitiesMarker, '&' ) ;\r
-\r
- // Restore the IsDirty state if it was not dirty.\r
- if ( !bIsDirty )\r
- FCK.ResetIsDirty() ;\r
-\r
- FCKDomTools.EnforcePaddingNode( FCKTools.GetElementDocument( node ), FCKConfig.EnterMode ) ;\r
- return sXHTML ;\r
-}\r
-\r
-FCKXHtml._AppendAttribute = function( xmlNode, attributeName, attributeValue )\r
-{\r
- try\r
- {\r
- if ( attributeValue == undefined || attributeValue == null )\r
- attributeValue = '' ;\r
- else if ( attributeValue.replace )\r
- {\r
- if ( FCKConfig.ForceSimpleAmpersand )\r
- attributeValue = attributeValue.replace( /&/g, '___FCKAmp___' ) ;\r
-\r
- // Entities must be replaced in the attribute values.\r
- attributeValue = attributeValue.replace( FCKXHtmlEntities.EntitiesRegex, FCKXHtml_GetEntity ) ;\r
- }\r
-\r
- // Create the attribute.\r
- var oXmlAtt = this.XML.createAttribute( attributeName ) ;\r
- oXmlAtt.value = attributeValue ;\r
-\r
- // Set the attribute in the node.\r
- xmlNode.attributes.setNamedItem( oXmlAtt ) ;\r
- }\r
- catch (e)\r
- {}\r
-}\r
-\r
-FCKXHtml._AppendChildNodes = function( xmlNode, htmlNode, isBlockElement )\r
-{\r
- var oNode = htmlNode.firstChild ;\r
-\r
- while ( oNode )\r
- {\r
- this._AppendNode( xmlNode, oNode ) ;\r
- oNode = oNode.nextSibling ;\r
- }\r
-\r
- // Trim block elements. This is also needed to avoid Firefox leaving extra\r
- // BRs at the end of them.\r
- if ( isBlockElement && htmlNode.tagName && htmlNode.tagName.toLowerCase() != 'pre' )\r
- {\r
- FCKDomTools.TrimNode( xmlNode ) ;\r
-\r
- if ( FCKConfig.FillEmptyBlocks )\r
- {\r
- var lastChild = xmlNode.lastChild ;\r
- if ( lastChild && lastChild.nodeType == 1 && lastChild.nodeName == 'br' )\r
- this._AppendEntity( xmlNode, this._NbspEntity ) ;\r
- }\r
- }\r
-\r
- // If the resulting node is empty.\r
- if ( xmlNode.childNodes.length == 0 )\r
- {\r
- if ( isBlockElement && FCKConfig.FillEmptyBlocks )\r
- {\r
- this._AppendEntity( xmlNode, this._NbspEntity ) ;\r
- return xmlNode ;\r
- }\r
-\r
- var sNodeName = xmlNode.nodeName ;\r
-\r
- // Some inline elements are required to have something inside (span, strong, etc...).\r
- if ( FCKListsLib.InlineChildReqElements[ sNodeName ] )\r
- return null ;\r
-\r
- // We can't use short representation of empty elements that are not marked\r
- // as empty in th XHTML DTD.\r
- if ( !FCKListsLib.EmptyElements[ sNodeName ] )\r
- xmlNode.appendChild( this.XML.createTextNode('') ) ;\r
- }\r
-\r
- return xmlNode ;\r
-}\r
-\r
-FCKXHtml._AppendNode = function( xmlNode, htmlNode )\r
-{\r
- if ( !htmlNode )\r
- return false ;\r
-\r
- switch ( htmlNode.nodeType )\r
- {\r
- // Element Node.\r
- case 1 :\r
- // If we detect a <br> inside a <pre> in Gecko, turn it into a line break instead.\r
- // This is a workaround for the Gecko bug here: https://bugzilla.mozilla.org/show_bug.cgi?id=92921\r
- if ( FCKBrowserInfo.IsGecko\r
- && htmlNode.tagName.toLowerCase() == 'br'\r
- && htmlNode.parentNode.tagName.toLowerCase() == 'pre' )\r
- {\r
- var val = '\r' ;\r
- if ( htmlNode == htmlNode.parentNode.firstChild )\r
- val += '\r' ;\r
- return FCKXHtml._AppendNode( xmlNode, this.XML.createTextNode( val ) ) ;\r
- }\r
-\r
- // Here we found an element that is not the real element, but a\r
- // fake one (like the Flash placeholder image), so we must get the real one.\r
- if ( htmlNode.getAttribute('_fckfakelement') )\r
- return FCKXHtml._AppendNode( xmlNode, FCK.GetRealElement( htmlNode ) ) ;\r
-\r
- // Ignore bogus BR nodes in the DOM.\r
- if ( FCKBrowserInfo.IsGecko &&\r
- ( htmlNode.hasAttribute('_moz_editor_bogus_node') || htmlNode.getAttribute( 'type' ) == '_moz' ) )\r
- {\r
- if ( htmlNode.nextSibling )\r
- return false ;\r
- else\r
- {\r
- htmlNode.removeAttribute( '_moz_editor_bogus_node' ) ;\r
- htmlNode.removeAttribute( 'type' ) ;\r
- }\r
- }\r
-\r
- // This is for elements that are instrumental to FCKeditor and\r
- // must be removed from the final HTML.\r
- if ( htmlNode.getAttribute('_fcktemp') )\r
- return false ;\r
-\r
- // Get the element name.\r
- var sNodeName = htmlNode.tagName.toLowerCase() ;\r
-\r
- if ( FCKBrowserInfo.IsIE )\r
- {\r
- // IE doens't include the scope name in the nodeName. So, add the namespace.\r
- if ( htmlNode.scopeName && htmlNode.scopeName != 'HTML' && htmlNode.scopeName != 'FCK' )\r
- sNodeName = htmlNode.scopeName.toLowerCase() + ':' + sNodeName ;\r
- }\r
- else\r
- {\r
- if ( sNodeName.StartsWith( 'fck:' ) )\r
- sNodeName = sNodeName.Remove( 0,4 ) ;\r
- }\r
-\r
- // Check if the node name is valid, otherwise ignore this tag.\r
- // If the nodeName starts with a slash, it is a orphan closing tag.\r
- // On some strange cases, the nodeName is empty, even if the node exists.\r
- if ( !FCKRegexLib.ElementName.test( sNodeName ) )\r
- return false ;\r
-\r
- // The already processed nodes must be marked to avoid then to be duplicated (bad formatted HTML).\r
- // So here, the "mark" is checked... if the element is Ok, then mark it.\r
- if ( htmlNode._fckxhtmljob && htmlNode._fckxhtmljob == FCKXHtml.CurrentJobNum )\r
- return false ;\r
-\r
- var oNode = this.XML.createElement( sNodeName ) ;\r
-\r
- // Add all attributes.\r
- FCKXHtml._AppendAttributes( xmlNode, htmlNode, oNode, sNodeName ) ;\r
-\r
- htmlNode._fckxhtmljob = FCKXHtml.CurrentJobNum ;\r
-\r
- // Tag specific processing.\r
- var oTagProcessor = FCKXHtml.TagProcessors[ sNodeName ] ;\r
-\r
- if ( oTagProcessor )\r
- oNode = oTagProcessor( oNode, htmlNode, xmlNode ) ;\r
- else\r
- oNode = this._AppendChildNodes( oNode, htmlNode, Boolean( FCKListsLib.NonEmptyBlockElements[ sNodeName ] ) ) ;\r
-\r
- if ( !oNode )\r
- return false ;\r
-\r
- xmlNode.appendChild( oNode ) ;\r
-\r
- break ;\r
-\r
- // Text Node.\r
- case 3 :\r
- if ( htmlNode.parentNode && htmlNode.parentNode.nodeName.IEquals( 'pre' ) )\r
- return this._AppendTextNode( xmlNode, htmlNode.nodeValue ) ;\r
- return this._AppendTextNode( xmlNode, htmlNode.nodeValue.ReplaceNewLineChars(' ') ) ;\r
-\r
- // Comment\r
- case 8 :\r
- // IE catches the <!DOTYPE ... > as a comment, but it has no\r
- // innerHTML, so we can catch it, and ignore it.\r
- if ( FCKBrowserInfo.IsIE && !htmlNode.innerHTML )\r
- break ;\r
-\r
- try { xmlNode.appendChild( this.XML.createComment( htmlNode.nodeValue ) ) ; }\r
- catch (e) { /* Do nothing... probably this is a wrong format comment. */ }\r
- break ;\r
-\r
- // Unknown Node type.\r
- default :\r
- xmlNode.appendChild( this.XML.createComment( "Element not supported - Type: " + htmlNode.nodeType + " Name: " + htmlNode.nodeName ) ) ;\r
- break ;\r
- }\r
- return true ;\r
-}\r
-\r
-// Append an item to the SpecialBlocks array and returns the tag to be used.\r
-FCKXHtml._AppendSpecialItem = function( item )\r
-{\r
- return '___FCKsi___' + ( FCKXHtml.SpecialBlocks.push( item ) - 1 ) ;\r
-}\r
-\r
-FCKXHtml._AppendEntity = function( xmlNode, entity )\r
-{\r
- xmlNode.appendChild( this.XML.createTextNode( '#?-:' + entity + ';' ) ) ;\r
-}\r
-\r
-FCKXHtml._AppendTextNode = function( targetNode, textValue )\r
-{\r
- var bHadText = textValue.length > 0 ;\r
- if ( bHadText )\r
- targetNode.appendChild( this.XML.createTextNode( textValue.replace( FCKXHtmlEntities.EntitiesRegex, FCKXHtml_GetEntity ) ) ) ;\r
- return bHadText ;\r
-}\r
-\r
-// Retrieves a entity (internal format) for a given character.\r
-function FCKXHtml_GetEntity( character )\r
-{\r
- // We cannot simply place the entities in the text, because the XML parser\r
- // will translate & to &. So we use a temporary marker which is replaced\r
- // in the end of the processing.\r
- var sEntity = FCKXHtmlEntities.Entities[ character ] || ( '#' + character.charCodeAt(0) ) ;\r
- return '#?-:' + sEntity + ';' ;\r
-}\r
-\r
-// An object that hold tag specific operations.\r
-FCKXHtml.TagProcessors =\r
-{\r
- a : function( node, htmlNode )\r
- {\r
- // Firefox may create empty tags when deleting the selection in some special cases (SF-BUG 1556878).\r
- if ( htmlNode.innerHTML.Trim().length == 0 && !htmlNode.name )\r
- return false ;\r
-\r
- var sSavedUrl = htmlNode.getAttribute( '_fcksavedurl' ) ;\r
- if ( sSavedUrl != null )\r
- FCKXHtml._AppendAttribute( node, 'href', sSavedUrl ) ;\r
-\r
-\r
- // Anchors with content has been marked with an additional class, now we must remove it.\r
- if ( FCKBrowserInfo.IsIE )\r
- {\r
- // Buggy IE, doesn't copy the name of changed anchors.\r
- if ( htmlNode.name )\r
- FCKXHtml._AppendAttribute( node, 'name', htmlNode.name ) ;\r
- }\r
-\r
- node = FCKXHtml._AppendChildNodes( node, htmlNode, false ) ;\r
-\r
- return node ;\r
- },\r
-\r
- area : function( node, htmlNode )\r
- {\r
- var sSavedUrl = htmlNode.getAttribute( '_fcksavedurl' ) ;\r
- if ( sSavedUrl != null )\r
- FCKXHtml._AppendAttribute( node, 'href', sSavedUrl ) ;\r
-\r
- // IE ignores the "COORDS" and "SHAPE" attribute so we must add it manually.\r
- if ( FCKBrowserInfo.IsIE )\r
- {\r
- if ( ! node.attributes.getNamedItem( 'coords' ) )\r
- {\r
- var sCoords = htmlNode.getAttribute( 'coords', 2 ) ;\r
- if ( sCoords && sCoords != '0,0,0' )\r
- FCKXHtml._AppendAttribute( node, 'coords', sCoords ) ;\r
- }\r
-\r
- if ( ! node.attributes.getNamedItem( 'shape' ) )\r
- {\r
- var sShape = htmlNode.getAttribute( 'shape', 2 ) ;\r
- if ( sShape && sShape.length > 0 )\r
- FCKXHtml._AppendAttribute( node, 'shape', sShape.toLowerCase() ) ;\r
- }\r
- }\r
-\r
- return node ;\r
- },\r
-\r
- body : function( node, htmlNode )\r
- {\r
- node = FCKXHtml._AppendChildNodes( node, htmlNode, false ) ;\r
- // Remove spellchecker attributes added for Firefox when converting to HTML code (Bug #1351).\r
- node.removeAttribute( 'spellcheck' ) ;\r
- return node ;\r
- },\r
-\r
- // IE loses contents of iframes, and Gecko does give it back HtmlEncoded\r
- // Note: Opera does lose the content and doesn't provide it in the innerHTML string\r
- iframe : function( node, htmlNode )\r
- {\r
- var sHtml = htmlNode.innerHTML ;\r
-\r
- // Gecko does give back the encoded html\r
- if ( FCKBrowserInfo.IsGecko )\r
- sHtml = FCKTools.HTMLDecode( sHtml );\r
-\r
- // Remove the saved urls here as the data won't be processed as nodes\r
- sHtml = sHtml.replace( /\s_fcksavedurl="[^"]*"/g, '' ) ;\r
-\r
- node.appendChild( FCKXHtml.XML.createTextNode( FCKXHtml._AppendSpecialItem( sHtml ) ) ) ;\r
-\r
- return node ;\r
- },\r
-\r
- img : function( node, htmlNode )\r
- {\r
- // The "ALT" attribute is required in XHTML.\r
- if ( ! node.attributes.getNamedItem( 'alt' ) )\r
- FCKXHtml._AppendAttribute( node, 'alt', '' ) ;\r
-\r
- var sSavedUrl = htmlNode.getAttribute( '_fcksavedurl' ) ;\r
- if ( sSavedUrl != null )\r
- FCKXHtml._AppendAttribute( node, 'src', sSavedUrl ) ;\r
-\r
- // Bug #768 : If the width and height are defined inline CSS,\r
- // don't define it again in the HTML attributes.\r
- if ( htmlNode.style.width )\r
- node.removeAttribute( 'width' ) ;\r
- if ( htmlNode.style.height )\r
- node.removeAttribute( 'height' ) ;\r
-\r
- return node ;\r
- },\r
-\r
- // Fix orphaned <li> nodes (Bug #503).\r
- li : function( node, htmlNode, targetNode )\r
- {\r
- // If the XML parent node is already a <ul> or <ol>, then add the <li> as usual.\r
- if ( targetNode.nodeName.IEquals( ['ul', 'ol'] ) )\r
- return FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;\r
-\r
- var newTarget = FCKXHtml.XML.createElement( 'ul' ) ;\r
-\r
- // Reset the _fckxhtmljob so the HTML node is processed again.\r
- htmlNode._fckxhtmljob = null ;\r
-\r
- // Loop through all sibling LIs, adding them to the <ul>.\r
- do\r
- {\r
- FCKXHtml._AppendNode( newTarget, htmlNode ) ;\r
-\r
- // Look for the next element following this <li>.\r
- do\r
- {\r
- htmlNode = FCKDomTools.GetNextSibling( htmlNode ) ;\r
-\r
- } while ( htmlNode && htmlNode.nodeType == 3 && htmlNode.nodeValue.Trim().length == 0 )\r
-\r
- } while ( htmlNode && htmlNode.nodeName.toLowerCase() == 'li' )\r
-\r
- return newTarget ;\r
- },\r
-\r
- // Fix nested <ul> and <ol>.\r
- ol : function( node, htmlNode, targetNode )\r
- {\r
- if ( htmlNode.innerHTML.Trim().length == 0 )\r
- return false ;\r
-\r
- var ePSibling = targetNode.lastChild ;\r
-\r
- if ( ePSibling && ePSibling.nodeType == 3 )\r
- ePSibling = ePSibling.previousSibling ;\r
-\r
- if ( ePSibling && ePSibling.nodeName.toUpperCase() == 'LI' )\r
- {\r
- htmlNode._fckxhtmljob = null ;\r
- FCKXHtml._AppendNode( ePSibling, htmlNode ) ;\r
- return false ;\r
- }\r
-\r
- node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;\r
-\r
- return node ;\r
- },\r
-\r
- pre : function ( node, htmlNode )\r
- {\r
- var firstChild = htmlNode.firstChild ;\r
-\r
- if ( firstChild && firstChild.nodeType == 3 )\r
- node.appendChild( FCKXHtml.XML.createTextNode( FCKXHtml._AppendSpecialItem( '\r\n' ) ) ) ;\r
-\r
- FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;\r
-\r
- return node ;\r
- },\r
-\r
- script : function( node, htmlNode )\r
- {\r
- // The "TYPE" attribute is required in XHTML.\r
- if ( ! node.attributes.getNamedItem( 'type' ) )\r
- FCKXHtml._AppendAttribute( node, 'type', 'text/javascript' ) ;\r
-\r
- node.appendChild( FCKXHtml.XML.createTextNode( FCKXHtml._AppendSpecialItem( htmlNode.text ) ) ) ;\r
-\r
- return node ;\r
- },\r
-\r
- span : function( node, htmlNode )\r
- {\r
- // Firefox may create empty tags when deleting the selection in some special cases (SF-BUG 1084404).\r
- if ( htmlNode.innerHTML.length == 0 )\r
- return false ;\r
-\r
- node = FCKXHtml._AppendChildNodes( node, htmlNode, false ) ;\r
-\r
- return node ;\r
- },\r
-\r
- style : function( node, htmlNode )\r
- {\r
- // The "TYPE" attribute is required in XHTML.\r
- if ( ! node.attributes.getNamedItem( 'type' ) )\r
- FCKXHtml._AppendAttribute( node, 'type', 'text/css' ) ;\r
-\r
- var cssText = htmlNode.innerHTML ;\r
- if ( FCKBrowserInfo.IsIE ) // Bug #403 : IE always appends a \r\n to the beginning of StyleNode.innerHTML\r
- cssText = cssText.replace( /^(\r\n|\n|\r)/, '' ) ;\r
-\r
- node.appendChild( FCKXHtml.XML.createTextNode( FCKXHtml._AppendSpecialItem( cssText ) ) ) ;\r
-\r
- return node ;\r
- },\r
-\r
- title : function( node, htmlNode )\r
- {\r
- node.appendChild( FCKXHtml.XML.createTextNode( FCK.EditorDocument.title ) ) ;\r
-\r
- return node ;\r
- }\r
-} ;\r
-\r
-FCKXHtml.TagProcessors.ul = FCKXHtml.TagProcessors.ol ;\r