X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fconnexionswing-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fcore%2Feditor.js;fp=sources%2Fcore%2Feditor.js;h=31188d24cb266f7d87ce624fd4a9dd6f39eb6a8c;hp=f29be63f7da35fd56620402d8db0c22c412605ff;hb=3b35bd273a79f6b01fda7a246aed64aca147ea7a;hpb=7adcb81e4f83f98c468889aaa5a85558ba88c770 diff --git a/sources/core/editor.js b/sources/core/editor.js index f29be63f..31188d24 100644 --- a/sources/core/editor.js +++ b/sources/core/editor.js @@ -1,5 +1,5 @@ /** - * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. + * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ @@ -654,6 +654,47 @@ return editor.blockless ? CKEDITOR.ENTER_BR : enterMode; } + // Create DocumentFragment from specified ranges. For now it handles only tables in Firefox + // and returns DocumentFragment from the 1. range for other cases. (#13884) + function createDocumentFragmentFromRanges( ranges, editable ) { + var docFragment = new CKEDITOR.dom.documentFragment(), + tableClone, + currentRow, + currentRowClone; + + for ( var i = 0; i < ranges.length; i++ ) { + var range = ranges[ i ], + container = range.startContainer; + + if ( container.getName && container.getName() == 'tr' ) { + if ( !tableClone ) { + tableClone = container.getAscendant( 'table' ).clone(); + tableClone.append( container.getAscendant( 'tbody' ).clone() ); + docFragment.append( tableClone ); + tableClone = tableClone.findOne( 'tbody' ); + } + + if ( !( currentRow && currentRow.equals( container ) ) ) { + currentRow = container; + currentRowClone = container.clone(); + tableClone.append( currentRowClone ); + } + + currentRowClone.append( range.cloneContents() ); + } else { + // If there was something else copied with table, + // append it to DocumentFragment. + docFragment.append( range.cloneContents() ); + } + } + + if ( !tableClone ) { + return editable.getHtmlFromRange( ranges[ 0 ] ); + } + + return docFragment; + } + CKEDITOR.tools.extend( CKEDITOR.editor.prototype, { /** * Adds a command definition to the editor instance. Commands added with @@ -1133,7 +1174,7 @@ return null; } - var docFragment = editable.getHtmlFromRange( ranges[ 0 ] ); + var docFragment = createDocumentFragmentFromRanges( ranges, editable ); return toString ? docFragment.getHtml() : docFragment; },