JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / core / dom / walker.js
index 4617a81..04ff21e 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -47,7 +47,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        {\r
                                return ( ( !movingOut || !limitLTR.equals( node ) )\r
                                        && ( !blockerLTR || !node.equals( blockerLTR ) )\r
-                                       && ( node.type != CKEDITOR.NODE_ELEMENT || node.getName() != 'body' ) );\r
+                                       && ( node.type != CKEDITOR.NODE_ELEMENT || !movingOut || node.getName() != 'body' ) );\r
                        };\r
                }\r
 \r
@@ -62,7 +62,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        {\r
                                return ( ( !movingOut || !limitRTL.equals( node ) )\r
                                        && ( !blockerRTL || !node.equals( blockerRTL ) )\r
-                                       && ( node.type != CKEDITOR.NODE_ELEMENT || node.getName() != 'body' ) );\r
+                                       && ( node.type != CKEDITOR.NODE_ELEMENT || !movingOut || node.getName() != 'body' ) );\r
                        };\r
                }\r
 \r
@@ -78,7 +78,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                if ( stopGuard( node, movingOut ) === false )\r
                                        return false;\r
 \r
-                               return userGuard( node );\r
+                               return userGuard( node, movingOut );\r
                        };\r
                }\r
                else\r
@@ -396,7 +396,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        };\r
 \r
        /**\r
-        * Whether the node contains only white-spaces characters.\r
+        * Whether the node is a text node containing only whitespaces characters.\r
         * @param isReject\r
         */\r
        CKEDITOR.dom.walker.whitespaces = function( isReject )\r
@@ -408,4 +408,44 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        return isReject ^ isWhitespace;\r
                };\r
        };\r
+\r
+       /**\r
+        * Whether the node is invisible in wysiwyg mode.\r
+        * @param isReject\r
+        */\r
+       CKEDITOR.dom.walker.invisible = function( isReject )\r
+       {\r
+               var whitespace = CKEDITOR.dom.walker.whitespaces();\r
+               return function( node )\r
+               {\r
+                       // Nodes that take no spaces in wysiwyg:\r
+                       // 1. White-spaces but not including NBSP;\r
+                       // 2. Empty inline elements, e.g. <b></b> we're checking here\r
+                       // 'offsetHeight' instead of 'offsetWidth' for properly excluding\r
+                       // all sorts of empty paragraph, e.g. <br />.\r
+                       var isInvisible = whitespace( node ) || node.is && !node.$.offsetHeight;\r
+                       return isReject ^ isInvisible;\r
+               };\r
+       };\r
+\r
+       var tailNbspRegex = /^[\t\r\n ]*(?:&nbsp;|\xa0)$/,\r
+               isNotWhitespaces = CKEDITOR.dom.walker.whitespaces( true ),\r
+               isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true ),\r
+               fillerEvaluator = function( element )\r
+               {\r
+                       return isNotBookmark( element ) && isNotWhitespaces( element );\r
+               };\r
+\r
+       // Check if there's a filler node at the end of an element, and return it.\r
+       CKEDITOR.dom.element.prototype.getBogus = function ()\r
+       {\r
+               var tail = this.getLast( fillerEvaluator );\r
+               if ( tail && ( !CKEDITOR.env.ie ? tail.is && tail.is( 'br' )\r
+                               : tail.getText && tailNbspRegex.test( tail.getText() ) ) )\r
+               {\r
+                       return tail;\r
+               }\r
+               return false;\r
+       };\r
+\r
 })();\r