2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
8 // Elements that may be considered the "Block boundary" in an element path.
9 var pathBlockElements
= { address
:1,blockquote
:1,dl
:1,h1
:1,h2
:1,h3
:1,h4
:1,h5
:1,h6
:1,p
:1,pre
:1,li
:1,dt
:1,dd
:1, legend
:1,caption
:1 };
11 // Elements that may be considered the "Block limit" in an element path.
12 var pathBlockLimitElements
= { body
:1,div
:1,table
:1,tbody
:1,tr
:1,td
:1,th
:1,form
:1,fieldset
:1 };
14 // Check if an element contains any block element.
15 var checkHasBlock = function( element
)
17 var childNodes
= element
.getChildren();
19 for ( var i
= 0, count
= childNodes
.count() ; i
< count
; i
++ )
21 var child
= childNodes
.getItem( i
);
23 if ( child
.type
== CKEDITOR
.NODE_ELEMENT
&& CKEDITOR
.dtd
.$block
[ child
.getName() ] )
33 CKEDITOR
.dom
.elementPath = function( lastNode
)
36 var blockLimit
= null;
43 if ( e
.type
== CKEDITOR
.NODE_ELEMENT
)
45 if ( !this.lastElement
)
48 var elementName
= e
.getName();
49 if ( CKEDITOR
.env
.ie
&& e
.$.scopeName
!= 'HTML' )
50 elementName
= e
.$.scopeName
.toLowerCase() + ':' + elementName
;
54 if ( !block
&& pathBlockElements
[ elementName
] )
57 if ( pathBlockLimitElements
[ elementName
] )
59 // DIV is considered the Block, if no block is available (#525)
60 // and if it doesn't contain other blocks.
61 if ( !block
&& elementName
== 'div' && !checkHasBlock( e
) )
70 if ( elementName
== 'body' )
77 this.blockLimit
= blockLimit
;
78 this.elements
= elements
;
82 CKEDITOR
.dom
.elementPath
.prototype =
85 * Compares this element path with another one.
86 * @param {CKEDITOR.dom.elementPath} otherPath The elementPath object to be
87 * compared with this one.
88 * @returns {Boolean} "true" if the paths are equal, containing the same
89 * number of elements and the same elements in the same order.
91 compare : function( otherPath
)
93 var thisElements
= this.elements
;
94 var otherElements
= otherPath
&& otherPath
.elements
;
96 if ( !otherElements
|| thisElements
.length
!= otherElements
.length
)
99 for ( var i
= 0 ; i
< thisElements
.length
; i
++ )
101 if ( !thisElements
[ i
].equals( otherElements
[ i
] ) )
108 contains : function( tagNames
)
110 var elements
= this.elements
;
111 for ( var i
= 0 ; i
< elements
.length
; i
++ )
113 if ( elements
[ i
].getName() in tagNames
)
114 return elements
[ i
];