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