1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * The Data Processor is responsible for transforming the input and output data 22 * in the editor. For more info: 23 * http://dev.fckeditor.net/wiki/Components/DataProcessor 24 * 25 * The default implementation offers the base XHTML compatibility features of 26 * FCKeditor. Further Data Processors may be implemented for other purposes. 27 * 28 */ 29 30var FCKDataProcessor = function() 31{} 32 33FCKDataProcessor.prototype = 34{ 35 /* 36 * Returns a string representing the HTML format of "data". The returned 37 * value will be loaded in the editor. 38 * The HTML must be from <html> to </html>, including <head>, <body> and 39 * eventually the DOCTYPE. 40 * Note: HTML comments may already be part of the data because of the 41 * pre-processing made with ProtectedSource. 42 * @param {String} data The data to be converted in the 43 * DataProcessor specific format. 44 */ 45 ConvertToHtml : function( data ) 46 { 47 // The default data processor must handle two different cases depending 48 // on the FullPage setting. Custom Data Processors will not be 49 // compatible with FullPage, much probably. 50 if ( FCKConfig.FullPage ) 51 { 52 // Save the DOCTYPE. 53 FCK.DocTypeDeclaration = data.match( FCKRegexLib.DocTypeTag ) ; 54 55 // Check if the <body> tag is available. 56 if ( !FCKRegexLib.HasBodyTag.test( data ) ) 57 data = '<body>' + data + '</body>' ; 58 59 // Check if the <html> tag is available. 60 if ( !FCKRegexLib.HtmlOpener.test( data ) ) 61 data = '<html dir="' + FCKConfig.ContentLangDirection + '">' + data + '</html>' ; 62 63 // Check if the <head> tag is available. 64 if ( !FCKRegexLib.HeadOpener.test( data ) ) 65 data = data.replace( FCKRegexLib.HtmlOpener, '$&<head><title></title></head>' ) ; 66 67 return data ; 68 } 69 else 70 { 71 var html = 72 FCKConfig.DocType + 73 '<html dir="' + FCKConfig.ContentLangDirection + '"' ; 74 75 // On IE, if you are using a DOCTYPE different of HTML 4 (like 76 // XHTML), you must force the vertical scroll to show, otherwise 77 // the horizontal one may appear when the page needs vertical scrolling. 78 // TODO : Check it with IE7 and make it IE6- if it is the case. 79 if ( FCKBrowserInfo.IsIE && FCKConfig.DocType.length > 0 && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) ) 80 html += ' style="overflow-y: scroll"' ; 81 82 html += '><head><title></title></head>' + 83 '<body' + FCKConfig.GetBodyAttributes() + '>' + 84 data + 85 '</body></html>' ; 86 87 return html ; 88 } 89 }, 90 91 /* 92 * Converts a DOM (sub-)tree to a string in the data format. 93 * @param {Object} rootNode The node that contains the DOM tree to be 94 * converted to the data format. 95 * @param {Boolean} excludeRoot Indicates that the root node must not 96 * be included in the conversion, only its children. 97 * @param {Boolean} format Indicates that the data must be formatted 98 * for human reading. Not all Data Processors may provide it. 99 */ 100 ConvertToDataFormat : function( rootNode, excludeRoot, ignoreIfEmptyParagraph, format ) 101 { 102 var data = FCKXHtml.GetXHTML( rootNode, !excludeRoot, format ) ; 103 104 if ( ignoreIfEmptyParagraph && FCKRegexLib.EmptyOutParagraph.test( data ) ) 105 return '' ; 106 107 return data ; 108 }, 109 110 /* 111 * Makes any necessary changes to a piece of HTML for insertion in the 112 * editor selection position. 113 * @param {String} html The HTML to be fixed. 114 */ 115 FixHtml : function( html ) 116 { 117 return html ; 118 } 119} ;