JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.5
[ckeditor.git] / _source / plugins / htmldataprocessor / plugin.js
index ecf87ed..a55480c 100644 (file)
@@ -21,6 +21,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                return last;\r
        }\r
 \r
+       function getNodeIndex( node ) {\r
+               var parent = node.parent;\r
+               return parent ? CKEDITOR.tools.indexOf( parent.children, node ) : -1;\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
@@ -159,12 +164,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // The contents of table should be in correct order (#4809).\r
                                table : function( element )\r
                                {\r
-                                       var children = element.children;\r
+                                       // Clone the array as it would become empty during the sort call.\r
+                                       var children = element.children.slice( 0 );\r
                                        children.sort( function ( node1, node2 )\r
                                                                   {\r
-                                                                          return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ?\r
-                                                                                       CKEDITOR.tools.indexOf( tableOrder, node1.name )  > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0;\r
-                                                                  } );\r
+                                                                                var index1, index2;\r
+\r
+                                                                                // Compare in the predefined order.\r
+                                                                                if ( node1.type == CKEDITOR.NODE_ELEMENT &&\r
+                                                                                                       node2.type == node1.type )\r
+                                                                                {\r
+                                                                                        index1 = CKEDITOR.tools.indexOf( tableOrder, node1.name );\r
+                                                                                        index2 = CKEDITOR.tools.indexOf( tableOrder, node2.name );\r
+                                                                                }\r
+\r
+                                                                                // Make sure the sort is stable, if no order can be established above.\r
+                                                                                if ( !( index1 > -1 && index2 > -1 && index1 != index2 ) )\r
+                                                                                {\r
+                                                                                        index1 = getNodeIndex( node1 );\r
+                                                                                        index2 = getNodeIndex( node2 );\r
+                                                                                }\r
+\r
+                                                                                return index1 > index2 ? 1 : -1;\r
+                                                                        } );\r
                                },\r
 \r
                                embed : function( element )\r
@@ -288,7 +310,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;\r
        }\r
 \r
-       var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi,\r
+       var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi,\r
                protectAttributeRegex = /\b(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi;\r
 \r
        var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,\r