3
3
* For licensing, see LICENSE.html or http://ckeditor.com/license
4
4
*/
5
5
6
+ 'use strict' ;
7
+
6
8
/**
7
9
* A lightweight representation of an HTML comment.
8
10
*
9
11
* @class
12
+ * @extends CKEDITOR.htmlParser.node
10
13
* @constructor Creates a comment class instance.
11
14
* @param {String } value The comment text value.
12
15
*/
@@ -24,7 +27,7 @@ CKEDITOR.htmlParser.comment = function( value ) {
24
27
} ;
25
28
} ;
26
29
27
- CKEDITOR . htmlParser . comment . prototype = {
30
+ CKEDITOR . htmlParser . comment . prototype = CKEDITOR . tools . extend ( new CKEDITOR . htmlParser . node ( ) , {
28
31
/**
29
32
* The node type. This is a constant value set to {@link CKEDITOR#NODE_COMMENT}.
30
33
*
@@ -34,24 +37,41 @@ CKEDITOR.htmlParser.comment.prototype = {
34
37
type : CKEDITOR . NODE_COMMENT ,
35
38
36
39
/**
37
- * Writes the HTML representation of this comment to a CKEDITOR.htmlWriter .
40
+ * Filter this comment with given filter .
38
41
*
39
- * @param {CKEDITOR.htmlParser.basicWriter } writer The writer to which write the HTML.
42
+ * @param {CKEDITOR.htmlParser.filter } filter
43
+ * @returns {Boolean } Method returns `false` when this comment has
44
+ * been removed or replaced with other node. This is an information for
45
+ * {@link CKEDITOR.htmlParser.element#filterChildren} that it has
46
+ * to repeat filter on current position in parent's children array.
40
47
*/
41
- writeHtml : function ( writer , filter ) {
48
+ filter : function ( filter ) {
42
49
var comment = this . value ;
43
50
44
- if ( filter ) {
45
- if ( ! ( comment = filter . onComment ( comment , this ) ) )
46
- return ;
51
+ if ( ! ( comment = filter . onComment ( comment , this ) ) ) {
52
+ this . remove ( ) ;
53
+ return false ;
54
+ }
47
55
48
- if ( typeof comment != 'string' ) {
49
- comment . parent = this . parent ;
50
- comment . writeHtml ( writer , filter ) ;
51
- return ;
52
- }
56
+ if ( typeof comment != 'string' ) {
57
+ this . replaceWith ( comment ) ;
58
+ return false ;
53
59
}
54
60
55
- writer . comment ( comment ) ;
61
+ this . value = comment ;
62
+ } ,
63
+
64
+ /**
65
+ * Writes the HTML representation of this comment to a CKEDITOR.htmlWriter.
66
+ *
67
+ * @param {CKEDITOR.htmlParser.basicWriter } writer The writer to which write the HTML.
68
+ * @param {CKEDITOR.htmlParser.filter } [filter] The filter to be applied to this node.
69
+ * **Note:** it's unsafe to filter offline (not appended) node.
70
+ */
71
+ writeHtml : function ( writer , filter ) {
72
+ if ( filter )
73
+ this . filter ( filter ) ;
74
+
75
+ writer . comment ( this . value ) ;
56
76
}
57
- } ;
77
+ } ) ;
0 commit comments