X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=2bf39af58fbcbcc8dba20c589eec20c6539f1734;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=ecf87ed45212310349d1f2696abad5e95bdd39b4;hpb=2f22c0c38f17e75be5541089076885442aaa2377;p=ckeditor.git diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index ecf87ed..2bf39af 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -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,