diff options
Diffstat (limited to 'sources/core/htmlparser/comment.js')
-rw-r--r-- | sources/core/htmlparser/comment.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sources/core/htmlparser/comment.js b/sources/core/htmlparser/comment.js new file mode 100644 index 0000000..171c62e --- /dev/null +++ b/sources/core/htmlparser/comment.js | |||
@@ -0,0 +1,80 @@ | |||
1 | /** | ||
2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. | ||
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | ||
4 | */ | ||
5 | |||
6 | 'use strict'; | ||
7 | |||
8 | /** | ||
9 | * A lightweight representation of an HTML comment. | ||
10 | * | ||
11 | * @class | ||
12 | * @extends CKEDITOR.htmlParser.node | ||
13 | * @constructor Creates a comment class instance. | ||
14 | * @param {String} value The comment text value. | ||
15 | */ | ||
16 | CKEDITOR.htmlParser.comment = function( value ) { | ||
17 | /** | ||
18 | * The comment text. | ||
19 | * | ||
20 | * @property {String} | ||
21 | */ | ||
22 | this.value = value; | ||
23 | |||
24 | /** @private */ | ||
25 | this._ = { | ||
26 | isBlockLike: false | ||
27 | }; | ||
28 | }; | ||
29 | |||
30 | CKEDITOR.htmlParser.comment.prototype = CKEDITOR.tools.extend( new CKEDITOR.htmlParser.node(), { | ||
31 | /** | ||
32 | * The node type. This is a constant value set to {@link CKEDITOR#NODE_COMMENT}. | ||
33 | * | ||
34 | * @readonly | ||
35 | * @property {Number} [=CKEDITOR.NODE_COMMENT] | ||
36 | */ | ||
37 | type: CKEDITOR.NODE_COMMENT, | ||
38 | |||
39 | /** | ||
40 | * Filter this comment with given filter. | ||
41 | * | ||
42 | * @since 4.1 | ||
43 | * @param {CKEDITOR.htmlParser.filter} filter | ||
44 | * @returns {Boolean} Method returns `false` when this comment has | ||
45 | * been removed or replaced with other node. This is an information for | ||
46 | * {@link CKEDITOR.htmlParser.element#filterChildren} that it has | ||
47 | * to repeat filter on current position in parent's children array. | ||
48 | */ | ||
49 | filter: function( filter, context ) { | ||
50 | var comment = this.value; | ||
51 | |||
52 | if ( !( comment = filter.onComment( context, comment, this ) ) ) { | ||
53 | this.remove(); | ||
54 | return false; | ||
55 | } | ||
56 | |||
57 | if ( typeof comment != 'string' ) { | ||
58 | this.replaceWith( comment ); | ||
59 | return false; | ||
60 | } | ||
61 | |||
62 | this.value = comment; | ||
63 | |||
64 | return true; | ||
65 | }, | ||
66 | |||
67 | /** | ||
68 | * Writes the HTML representation of this comment to a CKEDITOR.htmlWriter. | ||
69 | * | ||
70 | * @param {CKEDITOR.htmlParser.basicWriter} writer The writer to which write the HTML. | ||
71 | * @param {CKEDITOR.htmlParser.filter} [filter] The filter to be applied to this node. | ||
72 | * **Note:** it's unsafe to filter offline (not appended) node. | ||
73 | */ | ||
74 | writeHtml: function( writer, filter ) { | ||
75 | if ( filter ) | ||
76 | this.filter( filter ); | ||
77 | |||
78 | writer.comment( this.value ); | ||
79 | } | ||
80 | } ); | ||