]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/core/htmlparser/node.js
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
10 * A lightweight representation of HTML node.
14 * @constructor Creates a node class instance.
16 CKEDITOR
.htmlParser
.node = function() {};
18 CKEDITOR
.htmlParser
.node
.prototype = {
20 * Remove this node from a tree.
25 var children
= this.parent
.children
,
26 index
= CKEDITOR
.tools
.indexOf( children
, this ),
27 previous
= this.previous
,
30 previous
&& ( previous
.next
= next
);
31 next
&& ( next
.previous
= previous
);
32 children
.splice( index
, 1 );
37 * Replace this node with given one.
40 * @param {CKEDITOR.htmlParser.node} node The node that will replace this one.
42 replaceWith: function( node
) {
43 var children
= this.parent
.children
,
44 index
= CKEDITOR
.tools
.indexOf( children
, this ),
45 previous
= node
.previous
= this.previous
,
46 next
= node
.next
= this.next
;
48 previous
&& ( previous
.next
= node
);
49 next
&& ( next
.previous
= node
);
51 children
[ index
] = node
;
53 node
.parent
= this.parent
;
58 * Insert this node after given one.
61 * @param {CKEDITOR.htmlParser.node} node The node that will precede this element.
63 insertAfter: function( node
) {
64 var children
= node
.parent
.children
,
65 index
= CKEDITOR
.tools
.indexOf( children
, node
),
68 children
.splice( index
+ 1, 0, this );
70 this.next
= node
.next
;
73 next
&& ( next
.previous
= this );
75 this.parent
= node
.parent
;
79 * Insert this node before given one.
82 * @param {CKEDITOR.htmlParser.node} node The node that will follow this element.
84 insertBefore: function( node
) {
85 var children
= node
.parent
.children
,
86 index
= CKEDITOR
.tools
.indexOf( children
, node
);
88 children
.splice( index
, 0, this );
91 this.previous
= node
.previous
;
92 node
.previous
&& ( node
.previous
.next
= this );
95 this.parent
= node
.parent
;
99 * Gets the closest ancestor element of this element which satisfies given condition
102 * @param {String/Object/Function} condition Name of an ancestor, hash of names or validator function.
103 * @returns {CKEDITOR.htmlParser.element} The closest ancestor which satisfies given condition or `null`.
105 getAscendant: function( condition
) {
107 typeof condition
== 'function' ?
109 typeof condition
== 'string' ?
111 return el
.name
== condition
;
114 return el
.name
in condition
;
117 var parent
= this.parent
;
119 // Parent has to be an element - don't check doc fragment.
120 while ( parent
&& parent
.type
== CKEDITOR
.NODE_ELEMENT
) {
121 if ( checkFn( parent
) )
123 parent
= parent
.parent
;
130 * Wraps this element with given `wrapper`.
133 * @param {CKEDITOR.htmlParser.element} wrapper The element which will be this element's new parent.
134 * @returns {CKEDITOR.htmlParser.element} Wrapper.
136 wrapWith: function( wrapper
) {
137 this.replaceWith( wrapper
);
143 * Gets this node's index in its parent's children array.
148 getIndex: function() {
149 return CKEDITOR
.tools
.indexOf( this.parent
.children
, this );
152 getFilterContext: function( context
) {
153 return context
|| {};