Skip to content

Commit

Permalink
Fixed removing id when document fragment is cloned. Tests: for docume…
Browse files Browse the repository at this point in the history
…nt fragment clone and rename node in document fragment.
  • Loading branch information
Piotr Jasiun authored and Reinmar committed Apr 1, 2015
1 parent abe8bd1 commit fb2be3c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/dom/node.js
Expand Up @@ -139,10 +139,10 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
if ( node[ 'data-cke-expando' ] )
node[ 'data-cke-expando' ] = false;

if ( node.nodeType != CKEDITOR.NODE_ELEMENT )
if ( node.nodeType != CKEDITOR.NODE_ELEMENT && node.nodeType != CKEDITOR.NODE_DOCUMENT_FRAGMENT )
return;

if ( !cloneId )
if ( !cloneId && node.nodeType == CKEDITOR.NODE_ELEMENT )
node.removeAttribute( 'id', false );

if ( includeChildren ) {
Expand Down
47 changes: 47 additions & 0 deletions tests/core/dom/documentfragment.js
Expand Up @@ -239,6 +239,53 @@
CKEDITOR.dom.element.createFromHtml( '<figure>foo</figure>' ).appendTo( frag );

assert.areSame( '<figure>foo</figure>', frag.getHtml() );
},

'test clone': function() {
var frag = new CKEDITOR.dom.documentFragment( CKEDITOR.document );

CKEDITOR.dom.element.createFromHtml( '<b>foo</b>' ).appendTo( frag );
CKEDITOR.dom.element.createFromHtml( '<i>bar</i>' ).appendTo( frag );

var clone = frag.clone();

assert.areSame( CKEDITOR.NODE_DOCUMENT_FRAGMENT, clone.type );
assert.areSame( 0, clone.getChildCount() );
},

'test clone with children': function() {
var frag = new CKEDITOR.dom.documentFragment( CKEDITOR.document );

CKEDITOR.dom.element.createFromHtml( '<b>foo</b>' ).appendTo( frag );
CKEDITOR.dom.element.createFromHtml( '<i id="bar">bar</i>' ).appendTo( frag );

var clone = frag.clone( 1 );

assert.areSame( 2, clone.getChildCount() );
assert.areSame( '<b>foo</b>', bender.tools.fixHtml( clone.getChild( 0 ).getOuterHtml() ) );
assert.areSame( '<i>bar</i>', bender.tools.fixHtml( clone.getChild( 1 ).getOuterHtml() ) );
},

'test clone with children and ids': function() {
var frag = new CKEDITOR.dom.documentFragment( CKEDITOR.document );

CKEDITOR.dom.element.createFromHtml( '<b id="foo">foo</b>' ).appendTo( frag );

var clone = frag.clone( 1, 1 );

assert.areSame( 1, clone.getChildCount() );
assert.areSame( '<b id="foo">foo</b>', bender.tools.fixHtml( clone.getChild( 0 ).getOuterHtml() ) );
},

'test clone with html5': function() {
var frag = new CKEDITOR.dom.documentFragment( CKEDITOR.document );

CKEDITOR.dom.element.createFromHtml( '<figure>foo</figure>' ).appendTo( frag );

var clone = frag.clone( 1 );

assert.areSame( 1, clone.getChildCount() );
assert.areSame( '<figure>foo</figure>', bender.tools.fixHtml( clone.getChild( 0 ).getOuterHtml() ) );
}
} );
} )();
11 changes: 11 additions & 0 deletions tests/core/dom/element/element.js
Expand Up @@ -878,6 +878,17 @@ bender.test( appendDomObjectTests(
assert.areEqual( 'p', element.getName(), 'After rename' );
},

test_renameNode_in_documentFragment: function() {
var frag = new CKEDITOR.dom.documentFragment(),
inner = new CKEDITOR.dom.element( 'div' );

frag.append( inner );

assert.areEqual( 'div', frag.getChild( 0 ).getName(), 'Before rename' );
inner.renameNode( 'p' );
assert.areEqual( 'p', frag.getChild( 0 ).getName(), 'After rename' );
},

test_getDirection: function() {
assert.areEqual( 'rtl', doc.getById( 'getDirection' ).getDirection() );
},
Expand Down

0 comments on commit fb2be3c

Please sign in to comment.