X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=a55480cfdfbb37ae1affe48c087b33c981bae5e4;hp=ecf87ed45212310349d1f2696abad5e95bdd39b4;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hpb=6e682412d5cc0dfaedb376482e585bf2989c6863 diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index ecf87ed..a55480c 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -21,6 +21,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return last; } + function getNodeIndex( node ) { + var parent = node.parent; + return parent ? CKEDITOR.tools.indexOf( parent.children, node ) : -1; + } + function trimFillers( block, fromSource ) { // If the current node is a block, and if we're converting from source or @@ -159,12 +164,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // The contents of table should be in correct order (#4809). table : function( element ) { - var children = element.children; + // Clone the array as it would become empty during the sort call. + var children = element.children.slice( 0 ); children.sort( function ( node1, node2 ) { - return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ? - CKEDITOR.tools.indexOf( tableOrder, node1.name ) > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0; - } ); + var index1, index2; + + // Compare in the predefined order. + if ( node1.type == CKEDITOR.NODE_ELEMENT && + node2.type == node1.type ) + { + index1 = CKEDITOR.tools.indexOf( tableOrder, node1.name ); + index2 = CKEDITOR.tools.indexOf( tableOrder, node2.name ); + } + + // Make sure the sort is stable, if no order can be established above. + if ( !( index1 > -1 && index2 > -1 && index1 != index2 ) ) + { + index1 = getNodeIndex( node1 ); + index2 = getNodeIndex( node2 ); + } + + return index1 > index2 ? 1 : -1; + } ); }, embed : function( element ) @@ -288,7 +310,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly; } - var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi, + var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi, protectAttributeRegex = /\b(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi; var protectElementsRegex = /(?:])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,