JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.1
[ckeditor.git] / _source / plugins / domiterator / plugin.js
index 9fc5fd5..22815c4 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -30,7 +30,17 @@ CKEDITOR.plugins.add( 'domiterator' );
        }\r
 \r
        var beginWhitespaceRegex = /^[\r\n\t ]+$/,\r
-               isBookmark = CKEDITOR.dom.walker.bookmark();\r
+               // Ignore bookmark nodes.(#3783)\r
+               bookmarkGuard = CKEDITOR.dom.walker.bookmark( false, true );\r
+\r
+       // Get a reference for the next element, bookmark nodes are skipped.\r
+       function getNextSourceNode( node, startFromSibling, lastNode )\r
+       {\r
+               var next = node.getNextSourceNode( startFromSibling, null, lastNode );\r
+               while ( !bookmarkGuard( next ) )\r
+                       next = next.getNextSourceNode( startFromSibling, null, lastNode );\r
+               return next;\r
+       }\r
 \r
        iterator.prototype = {\r
                getNextParagraph : function( blockTag )\r
@@ -197,7 +207,7 @@ CKEDITOR.plugins.add( 'domiterator' );
                                // to close the range, otherwise we include the parent within it.\r
                                if ( range && !closeRange )\r
                                {\r
-                                       while ( !currentNode.getNext() && !isLast )\r
+                                       while ( !currentNode.getNext( bookmarkGuard ) && !isLast )\r
                                        {\r
                                                var parentNode = currentNode.getParent();\r
 \r
@@ -220,7 +230,7 @@ CKEDITOR.plugins.add( 'domiterator' );
                                if ( includeNode )\r
                                        range.setEndAt( currentNode, CKEDITOR.POSITION_AFTER_END );\r
 \r
-                               currentNode = currentNode.getNextSourceNode( continueFromSibling, null, lastNode );\r
+                               currentNode = getNextSourceNode ( currentNode, continueFromSibling, lastNode );\r
                                isLast = !currentNode;\r
 \r
                                // We have found a block boundary. Let's close the range and move out of the\r
@@ -256,15 +266,15 @@ CKEDITOR.plugins.add( 'domiterator' );
                                        // Create the fixed block.\r
                                        block = this.range.document.createElement( blockTag || 'p' );\r
 \r
-                                       // Move the contents of the temporary range to the fixed block.\r
-                                       range.extractContents().appendTo( block );\r
-                                       block.trim();\r
+                                               // Move the contents of the temporary range to the fixed block.\r
+                                               range.extractContents().appendTo( block );\r
+                                               block.trim();\r
 \r
-                                       // Insert the fixed block into the DOM.\r
-                                       range.insertNode( block );\r
+                                               // Insert the fixed block into the DOM.\r
+                                               range.insertNode( block );\r
 \r
-                                       removePreviousBr = removeLastBr = true;\r
-                               }\r
+                                               removePreviousBr = removeLastBr = true;\r
+                                       }\r
                                else if ( block.getName() != 'li' )\r
                                {\r
                                        // If the range doesn't includes the entire contents of the\r
@@ -297,14 +307,10 @@ CKEDITOR.plugins.add( 'domiterator' );
                                        // the current range, which could be an <li> child (nested\r
                                        // lists) or the next sibling <li>.\r
 \r
-                                       this._.nextNode = ( block.equals( lastNode ) ? null :\r
-                                               range.getBoundaryNodes().endNode.getNextSourceNode( true, null, lastNode ) );\r
+                                       this._.nextNode = ( block.equals( lastNode ) ? null : getNextSourceNode( range.getBoundaryNodes().endNode, 1, lastNode ) );\r
                                }\r
                        }\r
 \r
-                       // Ignore bookmark nodes.(#3783)\r
-                       var bookmarkGuard = CKEDITOR.dom.walker.bookmark( false, true );\r
-\r
                        if ( removePreviousBr )\r
                        {\r
                                var previousSibling = block.getPrevious();\r
@@ -336,13 +342,7 @@ CKEDITOR.plugins.add( 'domiterator' );
                        if ( !this._.nextNode )\r
                        {\r
                                this._.nextNode = ( isLast || block.equals( lastNode ) ) ? null :\r
-                                       block.getNextSourceNode( true, null, lastNode );\r
-                       }\r
-\r
-                       if ( !bookmarkGuard( this._.nextNode ) )\r
-                       {\r
-                               this._.nextNode = this._.nextNode.getNextSourceNode( true, null, function( node )\r
-                                       { return !node.equals( lastNode ) && bookmarkGuard( node ); } );\r
+                                       getNextSourceNode( block, 1, lastNode );\r
                        }\r
 \r
                        return block;\r