]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/classes/html/Writer.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / classes / html / Writer.js
1 /**
2  * Writer.js
3  *
4  * Copyright, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://www.tinymce.com/license
8  * Contributing: http://www.tinymce.com/contributing
9  */
10
11 /**
12  * This class is used to write HTML tags out it can be used with the Serializer or the SaxParser.
13  *
14  * @class tinymce.html.Writer
15  * @example
16  * var writer = new tinymce.html.Writer({indent: true});
17  * var parser = new tinymce.html.SaxParser(writer).parse('<p><br></p>');
18  * console.log(writer.getContent());
19  *
20  * @class tinymce.html.Writer
21  * @version 3.4
22  */
23 define("tinymce/html/Writer", [
24         "tinymce/html/Entities",
25         "tinymce/util/Tools"
26 ], function(Entities, Tools) {
27         var makeMap = Tools.makeMap;
28
29         /**
30          * Constructs a new Writer instance.
31          *
32          * @constructor
33          * @method Writer
34          * @param {Object} settings Name/value settings object.
35          */
36         return function(settings) {
37                 var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
38
39                 settings = settings || {};
40                 indent = settings.indent;
41                 indentBefore = makeMap(settings.indent_before || '');
42                 indentAfter = makeMap(settings.indent_after || '');
43                 encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
44                 htmlOutput = settings.element_format == "html";
45
46                 return {
47                         /**
48                          * Writes the a start element such as <p id="a">.
49                          *
50                          * @method start
51                          * @param {String} name Name of the element.
52                          * @param {Array} attrs Optional attribute array or undefined if it hasn't any.
53                          * @param {Boolean} empty Optional empty state if the tag should end like <br />.
54                          */
55                         start: function(name, attrs, empty) {
56                                 var i, l, attr, value;
57
58                                 if (indent && indentBefore[name] && html.length > 0) {
59                                         value = html[html.length - 1];
60
61                                         if (value.length > 0 && value !== '\n') {
62                                                 html.push('\n');
63                                         }
64                                 }
65
66                                 html.push('<', name);
67
68                                 if (attrs) {
69                                         for (i = 0, l = attrs.length; i < l; i++) {
70                                                 attr = attrs[i];
71                                                 html.push(' ', attr.name, '="', encode(attr.value, true), '"');
72                                         }
73                                 }
74
75                                 if (!empty || htmlOutput) {
76                                         html[html.length] = '>';
77                                 } else {
78                                         html[html.length] = ' />';
79                                 }
80
81                                 if (empty && indent && indentAfter[name] && html.length > 0) {
82                                         value = html[html.length - 1];
83
84                                         if (value.length > 0 && value !== '\n') {
85                                                 html.push('\n');
86                                         }
87                                 }
88                         },
89
90                         /**
91                          * Writes the a end element such as </p>.
92                          *
93                          * @method end
94                          * @param {String} name Name of the element.
95                          */
96                         end: function(name) {
97                                 var value;
98
99                                 /*if (indent && indentBefore[name] && html.length > 0) {
100                                         value = html[html.length - 1];
101
102                                         if (value.length > 0 && value !== '\n')
103                                                 html.push('\n');
104                                 }*/
105
106                                 html.push('</', name, '>');
107
108                                 if (indent && indentAfter[name] && html.length > 0) {
109                                         value = html[html.length - 1];
110
111                                         if (value.length > 0 && value !== '\n') {
112                                                 html.push('\n');
113                                         }
114                                 }
115                         },
116
117                         /**
118                          * Writes a text node.
119                          *
120                          * @method text
121                          * @param {String} text String to write out.
122                          * @param {Boolean} raw Optional raw state if true the contents wont get encoded.
123                          */
124                         text: function(text, raw) {
125                                 if (text.length > 0) {
126                                         html[html.length] = raw ? text : encode(text);
127                                 }
128                         },
129
130                         /**
131                          * Writes a cdata node such as <![CDATA[data]]>.
132                          *
133                          * @method cdata
134                          * @param {String} text String to write out inside the cdata.
135                          */
136                         cdata: function(text) {
137                                 html.push('<![CDATA[', text, ']]>');
138                         },
139
140                         /**
141                          * Writes a comment node such as <!-- Comment -->.
142                          *
143                          * @method cdata
144                          * @param {String} text String to write out inside the comment.
145                          */
146                         comment: function(text) {
147                                 html.push('<!--', text, '-->');
148                         },
149
150                         /**
151                          * Writes a PI node such as <?xml attr="value" ?>.
152                          *
153                          * @method pi
154                          * @param {String} name Name of the pi.
155                          * @param {String} text String to write out inside the pi.
156                          */
157                         pi: function(name, text) {
158                                 if (text) {
159                                         html.push('<?', name, ' ', text, '?>');
160                                 } else {
161                                         html.push('<?', name, '?>');
162                                 }
163
164                                 if (indent) {
165                                         html.push('\n');
166                                 }
167                         },
168
169                         /**
170                          * Writes a doctype node such as <!DOCTYPE data>.
171                          *
172                          * @method doctype
173                          * @param {String} text String to write out inside the doctype.
174                          */
175                         doctype: function(text) {
176                                 html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
177                         },
178
179                         /**
180                          * Resets the internal buffer if one wants to reuse the writer.
181                          *
182                          * @method reset
183                          */
184                         reset: function() {
185                                 html.length = 0;
186                         },
187
188                         /**
189                          * Returns the contents that got serialized.
190                          *
191                          * @method getContent
192                          * @return {String} HTML contents that got written down.
193                          */
194                         getContent: function() {
195                                 return html.join('').replace(/\n$/, '');
196                         }
197                 };
198         };
199 });