JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2.2
[ckeditor.git] / _source / core / htmlparser / filter.js
index 1699eb2..5d16292 100644 (file)
@@ -227,26 +227,52 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                }\r
        }\r
 \r
+       // Invoke filters sequentially on the array, break the iteration\r
+       // when it doesn't make sense to continue anymore.\r
        function callItems( currentEntry )\r
        {\r
-               var isObject = ( typeof currentEntry == 'object' );\r
+               var isNode = currentEntry.type\r
+                       || currentEntry instanceof CKEDITOR.htmlParser.fragment;\r
 \r
                for ( var i = 0 ; i < this.length ; i++ )\r
                {\r
+                       // Backup the node info before filtering.\r
+                       if ( isNode )\r
+                       {\r
+                               var orgType = currentEntry.type,\r
+                                               orgName = currentEntry.name;\r
+                       }\r
+\r
                        var item = this[ i ],\r
                                ret = item.apply( window, arguments );\r
 \r
-                       if ( typeof ret != 'undefined' )\r
-                       {\r
-                               if ( ret === false )\r
-                                       return false;\r
+                       if ( ret === false )\r
+                               return ret;\r
 \r
-                               if ( isObject && ret != currentEntry )\r
+                       // We're filtering node (element/fragment).\r
+                       if ( isNode )\r
+                       {\r
+                               // No further filtering if it's not anymore\r
+                               // fitable for the subsequent filters.\r
+                               if ( ret && ( ret.name != orgName\r
+                                       || ret.type != orgType ) )\r
+                               {\r
+                                       return ret;\r
+                               }\r
+                       }\r
+                       // Filtering value (nodeName/textValue/attrValue).\r
+                       else\r
+                       {\r
+                               // No further filtering if it's not\r
+                               // any more values.\r
+                               if ( typeof ret != 'string' )\r
                                        return ret;\r
                        }\r
+\r
+                       ret != undefined && ( currentEntry = ret );\r
                }\r
 \r
-               return null;\r
+               return currentEntry;\r
        }\r
 })();\r
 \r