Update ckeditor to version 3.2.1
[gopost.git] / ckeditor / _source / core / htmlparser / basicwriter.js
blob3a0231c8d7423b34f247cee43c1b0ac06328e055
1 /*
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 CKEDITOR.htmlParser.basicWriter = CKEDITOR.tools.createClass(
8 $ : function()
10 this._ =
12 output : []
16 proto :
18 /**
19 * Writes the tag opening part for a opener tag.
20 * @param {String} tagName The element name for this tag.
21 * @param {Object} attributes The attributes defined for this tag. The
22 * attributes could be used to inspect the tag.
23 * @example
24 * // Writes "<p".
25 * writer.openTag( 'p', { class : 'MyClass', id : 'MyId' } );
27 openTag : function( tagName, attributes )
29 this._.output.push( '<', tagName );
32 /**
33 * Writes the tag closing part for a opener tag.
34 * @param {String} tagName The element name for this tag.
35 * @param {Boolean} isSelfClose Indicates that this is a self-closing tag,
36 * like "br" or "img".
37 * @example
38 * // Writes "&gt;".
39 * writer.openTagClose( 'p', false );
40 * @example
41 * // Writes " /&gt;".
42 * writer.openTagClose( 'br', true );
44 openTagClose : function( tagName, isSelfClose )
46 if ( isSelfClose )
47 this._.output.push( ' />' );
48 else
49 this._.output.push( '>' );
52 /**
53 * Writes an attribute. This function should be called after opening the
54 * tag with {@link #openTagClose}.
55 * @param {String} attName The attribute name.
56 * @param {String} attValue The attribute value.
57 * @example
58 * // Writes ' class="MyClass"'.
59 * writer.attribute( 'class', 'MyClass' );
61 attribute : function( attName, attValue )
63 // Browsers don't always escape special character in attribute values. (#4683, #4719).
64 if ( typeof attValue == 'string' )
65 attValue = CKEDITOR.tools.htmlEncodeAttr( attValue );
67 this._.output.push( ' ', attName, '="', attValue, '"' );
70 /**
71 * Writes a closer tag.
72 * @param {String} tagName The element name for this tag.
73 * @example
74 * // Writes "&lt;/p&gt;".
75 * writer.closeTag( 'p' );
77 closeTag : function( tagName )
79 this._.output.push( '</', tagName, '>' );
82 /**
83 * Writes text.
84 * @param {String} text The text value
85 * @example
86 * // Writes "Hello Word".
87 * writer.text( 'Hello Word' );
89 text : function( text )
91 this._.output.push( text );
94 /**
95 * Writes a comment.
96 * @param {String} comment The comment text.
97 * @example
98 * // Writes "&lt;!-- My comment --&gt;".
99 * writer.comment( ' My comment ' );
101 comment : function( comment )
103 this._.output.push( '<!--', comment, '-->' );
107 * Writes any kind of data to the ouput.
108 * @example
109 * writer.write( 'This is an &lt;b&gt;example&lt;/b&gt;.' );
111 write : function( data )
113 this._.output.push( data );
117 * Empties the current output buffer.
118 * @example
119 * writer.reset();
121 reset : function()
123 this._.output = [];
124 this._.indent = false;
128 * Empties the current output buffer.
129 * @param {Boolean} reset Indicates that the {@link reset} function is to
130 * be automatically called after retrieving the HTML.
131 * @returns {String} The HTML written to the writer so far.
132 * @example
133 * var html = writer.getHtml();
135 getHtml : function( reset )
137 var html = this._.output.join( '' );
139 if ( reset )
140 this.reset();
142 return html;