JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0.1
[ckeditor.git] / _source / plugins / htmldataprocessor / plugin.js
index d783d66..3ec5db3 100644 (file)
@@ -11,6 +11,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        var protectedSourceMarker = '{cke_protected}';\r
 \r
+\r
+       // Return the last non-space child node of the block (#4344).\r
+       function lastNoneSpaceChild( block )\r
+       {\r
+               var lastIndex = block.children.length,\r
+                       last = block.children[ lastIndex - 1 ];\r
+               while(  last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) )\r
+                       last = block.children[ --lastIndex ];\r
+               return last;\r
+       }\r
+\r
        function trimFillers( block, fromSource )\r
        {\r
                // If the current node is a block, and if we're converting from source or\r
@@ -18,8 +29,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                //\r
                // Also, any   at the end of blocks are fillers, remove them as well.\r
                // (#2886)\r
-               var children = block.children;\r
-               var lastChild = children[ children.length - 1 ];\r
+               var children = block.children, lastChild = lastNoneSpaceChild( block );\r
                if ( lastChild )\r
                {\r
                        if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' )\r
@@ -31,11 +41,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        function blockNeedsExtension( block )\r
        {\r
-               if ( block.children.length < 1 )\r
-                       return true;\r
-\r
-               var lastChild = block.children[ block.children.length - 1 ];\r
-               return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';\r
+               var lastChild = lastNoneSpaceChild( block );\r
+               return !lastChild || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';\r
        }\r
 \r
        function extendBlockForDisplay( block )\r