diff options
Diffstat (limited to 'sources/core/dom/elementpath.js')
-rw-r--r-- | sources/core/dom/elementpath.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/sources/core/dom/elementpath.js b/sources/core/dom/elementpath.js index 1ee551b..dd50f10 100644 --- a/sources/core/dom/elementpath.js +++ b/sources/core/dom/elementpath.js | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. | 2 | * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. |
3 | * For licensing, see LICENSE.md or http://ckeditor.com/license | 3 | * For licensing, see LICENSE.md or http://ckeditor.com/license |
4 | */ | 4 | */ |
5 | 5 | ||
@@ -57,6 +57,11 @@ | |||
57 | // Backward compact. | 57 | // Backward compact. |
58 | root = root || startNode.getDocument().getBody(); | 58 | root = root || startNode.getDocument().getBody(); |
59 | 59 | ||
60 | // Assign root value if startNode is null (#424)(https://dev.ckeditor.com/ticket/17028). | ||
61 | if ( !e ) { | ||
62 | e = root; | ||
63 | } | ||
64 | |||
60 | do { | 65 | do { |
61 | if ( e.type == CKEDITOR.NODE_ELEMENT ) { | 66 | if ( e.type == CKEDITOR.NODE_ELEMENT ) { |
62 | elements.push( e ); | 67 | elements.push( e ); |
@@ -84,7 +89,7 @@ | |||
84 | block = e; | 89 | block = e; |
85 | 90 | ||
86 | if ( pathBlockLimitElements[ elementName ] ) { | 91 | if ( pathBlockLimitElements[ elementName ] ) { |
87 | // End level DIV is considered as the block, if no block is available. (#525) | 92 | // End level DIV is considered as the block, if no block is available. (http://dev.ckeditor.com/ticket/525) |
88 | // But it must NOT be the root element (checked above). | 93 | // But it must NOT be the root element (checked above). |
89 | if ( !block && elementName == 'div' && !checkHasBlock( e ) ) | 94 | if ( !block && elementName == 'div' && !checkHasBlock( e ) ) |
90 | block = e; | 95 | block = e; |
@@ -181,7 +186,9 @@ CKEDITOR.dom.elementPath.prototype = { | |||
181 | * @returns {CKEDITOR.dom.element} The first matched dom element or `null`. | 186 | * @returns {CKEDITOR.dom.element} The first matched dom element or `null`. |
182 | */ | 187 | */ |
183 | contains: function( query, excludeRoot, fromTop ) { | 188 | contains: function( query, excludeRoot, fromTop ) { |
184 | var evaluator; | 189 | var i = 0, |
190 | evaluator; | ||
191 | |||
185 | if ( typeof query == 'string' ) | 192 | if ( typeof query == 'string' ) |
186 | evaluator = function( node ) { | 193 | evaluator = function( node ) { |
187 | return node.getName() == query; | 194 | return node.getName() == query; |
@@ -203,14 +210,21 @@ CKEDITOR.dom.elementPath.prototype = { | |||
203 | 210 | ||
204 | var elements = this.elements, | 211 | var elements = this.elements, |
205 | length = elements.length; | 212 | length = elements.length; |
206 | excludeRoot && length--; | 213 | |
214 | if ( excludeRoot ) { | ||
215 | if ( !fromTop ) { | ||
216 | length -= 1; | ||
217 | } else { | ||
218 | i += 1; | ||
219 | } | ||
220 | } | ||
207 | 221 | ||
208 | if ( fromTop ) { | 222 | if ( fromTop ) { |
209 | elements = Array.prototype.slice.call( elements, 0 ); | 223 | elements = Array.prototype.slice.call( elements, 0 ); |
210 | elements.reverse(); | 224 | elements.reverse(); |
211 | } | 225 | } |
212 | 226 | ||
213 | for ( var i = 0; i < length; i++ ) { | 227 | for ( ; i < length; i++ ) { |
214 | if ( evaluator( elements[ i ] ) ) | 228 | if ( evaluator( elements[ i ] ) ) |
215 | return elements[ i ]; | 229 | return elements[ i ]; |
216 | } | 230 | } |