JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / core / htmlparser / filter.js
index 6001e68..cbe4bed 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
@@ -45,6 +45,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                // Add the comment.\r
                                this._.comment = transformNamedItem( this._.comment, rules.comment, priority ) || this._.comment;\r
+\r
+                               // Add root fragment.\r
+                               this._.root = transformNamedItem( this._.root, rules.root, priority ) || this._.root;\r
                        },\r
 \r
                        onElementName : function( name )\r
@@ -63,10 +66,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                return textFilter ? textFilter.filter( text ) : text;\r
                        },\r
 \r
-                       onComment : function( commentText )\r
+                       onComment : function( commentText, comment )\r
                        {\r
                                var textFilter = this._.comment;\r
-                               return textFilter ? textFilter.filter( commentText ) : commentText;\r
+                               return textFilter ? textFilter.filter( commentText, comment ) : commentText;\r
+                       },\r
+\r
+                       onFragment : function( element )\r
+                       {\r
+                               var rootFilter = this._.root;\r
+                               return rootFilter ? rootFilter.filter( element ) : element;\r
                        },\r
 \r
                        onElement : function( element )\r
@@ -74,10 +83,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // We must apply filters set to the specific element name as\r
                                // well as those set to the generic $ name. So, add both to an\r
                                // array and process them in a small loop.\r
-                               var filters = [ this._.elements[ element.name ], this._.elements.$ ],\r
+                               var filters = [ this._.elements[ '^' ], this._.elements[ element.name ], this._.elements.$ ],\r
                                        filter, ret;\r
 \r
-                               for ( var i = 0 ; i < 2 ; i++ )\r
+                               for ( var i = 0 ; i < 3 ; i++ )\r
                                {\r
                                        filter = filters[ i ];\r
                                        if ( filter )\r
@@ -88,13 +97,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        return null;\r
 \r
                                                if ( ret && ret != element )\r
-                                                       return this.onElement( ret );\r
+                                                       return this.onNode( ret );\r
+\r
+                                               // The non-root element has been dismissed by one of the filters.\r
+                                               if ( element.parent && !element.name )\r
+                                                       break;\r
                                        }\r
                                }\r
 \r
                                return element;\r
                        },\r
 \r
+                       onNode : function( node )\r
+                       {\r
+                               var type = node.type;\r
+\r
+                               return type == CKEDITOR.NODE_ELEMENT ? this.onElement( node ) :\r
+                                       type == CKEDITOR.NODE_TEXT ? new CKEDITOR.htmlParser.text( this.onText( node.value ) ) :\r
+                                       type == CKEDITOR.NODE_COMMENT ? new CKEDITOR.htmlParser.comment( this.onComment( node.value ) ):\r
+                                       null;\r
+                       },\r
+\r
                        onAttribute : function( element, name, value )\r
                        {\r
                                var filter = this._.attributes[ name ];\r
@@ -144,8 +167,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        for ( j = itemsLength - 1 ; j >= 0 ; j-- )\r
                        {\r
                                var item = items[ j ];\r
-                               item.pri = priority;\r
-                               list.splice( i, 0, item );\r
+                               if ( item )\r
+                               {\r
+                                       item.pri = priority;\r
+                                       list.splice( i, 0, item );\r
+                               }\r
                        }\r
                }\r
        }\r