X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=2bf39af58fbcbcc8dba20c589eec20c6539f1734;hb=3fe9cac293e090ea459a3ee10d78cbe9e1dd0e03;hp=ad6fa470b9ea54988e0016e3002e80aaeeed6858;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba;p=ckeditor.git diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index ad6fa47..2bf39af 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, 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 @@ -44,14 +49,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license typeof extendEmptyBlock == 'function' && ( extendEmptyBlock( block ) === false ) ) ) return false; - // 1. For IE version >=8, empty blocks are displayed correctly themself in wysiwiyg; - // 2. For the rest, at least table cell and list item need no filler space. - // (#6248) - if ( fromSource && CKEDITOR.env.ie && - ( document.documentMode > 7 - || block.name in CKEDITOR.dtd.tr - || block.name in CKEDITOR.dtd.$listItem ) ) - return false; + // 1. For IE version >=8, empty blocks are displayed correctly themself in wysiwiyg; + // 2. For the rest, at least table cell and list item need no filler space. + // (#6248) + if ( fromSource && CKEDITOR.env.ie && + ( document.documentMode > 7 + || block.name in CKEDITOR.dtd.tr + || block.name in CKEDITOR.dtd.$listItem ) ) + return false; var lastChild = lastNoneSpaceChild( block ); @@ -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,8 +310,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly; } - var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi, - protectAttributeRegex = /\b(href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/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, encodedElementsRegex = /([^<]*)<\/cke:encoded>/gi; @@ -305,9 +327,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { return '<' + tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName ) { + // Avoid corrupting the inline event attributes (#7243). // We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218) - if ( attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 ) - return ' data-cke-saved-' + fullAttr + ' ' + fullAttr; + if ( !( /^on/ ).test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 ) + return ' data-cke-saved-' + fullAttr + ' data-cke-' + CKEDITOR.rnd + '-' + fullAttr; return fullAttr; }) + '>'; @@ -515,10 +538,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Call the browser to help us fixing a possibly invalid HTML // structure. var div = new CKEDITOR.dom.element( 'div' ); + // Add fake character to workaround IE comments bug. (#3801) div.setHtml( 'a' + data ); data = div.getHtml().substr( 1 ); + // Restore shortly protected attribute names. + data = data.replace( new RegExp( ' data-cke-' + CKEDITOR.rnd + '-', 'ig' ), ' ' ); + // Unprotect "some" of the protected elements at this point. data = unprotectElementNames( data );