Skip to content
Permalink
Browse files

Merge branch 't/13101b' into major

  • Loading branch information...
Reinmar committed Apr 1, 2015
2 parents c5090d9 + fb2be3c commit 7342d1806e7534ed14a4ec39d8d5d7b08fd61203
@@ -52,13 +52,12 @@ CKEDITOR.tools.extend( CKEDITOR.dom.documentFragment.prototype, CKEDITOR.dom.ele
getHtml: function() {
var container = new CKEDITOR.dom.element( 'div' );

// Note node.clone( 1 ) would purge ids.
new CKEDITOR.dom.documentFragment( this.$.cloneNode( 1 ) ).appendTo( container );
this.clone( 1, 1 ).appendTo( container );

return container.getHtml();
return container.getHtml().replace( /\s*data-cke-expando=".*?"/g, '' );
}
}, true, {
'append': 1, 'appendBogus': 1, 'getFirst': 1, 'getHtml': 1, 'getLast': 1, 'getParent': 1, 'getNext': 1, 'getPrevious': 1,
'append': 1, 'appendBogus': 1, 'clone': 1, 'getFirst': 1, 'getHtml': 1, 'getLast': 1, 'getParent': 1, 'getNext': 1, 'getPrevious': 1,
'appendTo': 1, 'moveChildren': 1, 'insertBefore': 1, 'insertAfterNode': 1, 'replace': 1, 'trim': 1, 'type': 1,
'ltrim': 1, 'rtrim': 1, 'getDocument': 1, 'getChildCount': 1, 'getChild': 1, 'getChildren': 1
} );
@@ -1774,7 +1774,7 @@ CKEDITOR.dom.element.clearMarkers = function( database, element, removeFromDatab
this.moveChildren( newNode );

// Replace the node.
this.getParent() && this.$.parentNode.replaceChild( newNode.$, this.$ );
this.getParent( true ) && this.$.parentNode.replaceChild( newNode.$, this.$ );
newNode.$[ 'data-cke-expando' ] = this.$[ 'data-cke-expando' ];
this.$ = newNode.$;
// Bust getName's cache. (#8663)
@@ -121,27 +121,55 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
clone: function( includeChildren, cloneId ) {
var $clone = this.$.cloneNode( includeChildren );

var removeIds = function( node ) {
// Reset data-cke-expando only when has been cloned (IE and only for some types of objects).
if ( node[ 'data-cke-expando' ] )
node[ 'data-cke-expando' ] = false;

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

if ( includeChildren ) {
var childs = node.childNodes;
for ( var i = 0; i < childs.length; i++ )
removeIds( childs[ i ] );
}
};

// The "id" attribute should never be cloned to avoid duplication.
removeIds( $clone );

return new CKEDITOR.dom.node( $clone );
var node = new CKEDITOR.dom.node( $clone );

// On IE8 we need to fixed HTML5 node name, see details below.
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 &&
( this.type == CKEDITOR.NODE_ELEMENT || this.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT ) ) {
renameNodes( node );
}

return node;

function removeIds( node ) {
// Reset data-cke-expando only when has been cloned (IE and only for some types of objects).
if ( node[ 'data-cke-expando' ] )
node[ 'data-cke-expando' ] = false;

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

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

if ( includeChildren ) {
var childs = node.childNodes;
for ( var i = 0; i < childs.length; i++ )
removeIds( childs[ i ] );
}
}

// IE8 rename HTML5 nodes by adding `:` at the begging of the tag name when the node is cloned,
// so `<figure>` will be `<:figure>` after 'cloneNode'. We need to fix it (#13101).
function renameNodes( node ) {
if ( node.type != CKEDITOR.NODE_ELEMENT && node.type != CKEDITOR.NODE_DOCUMENT_FRAGMENT )
return;

if ( node.type != CKEDITOR.NODE_DOCUMENT_FRAGMENT ) {
var name = node.getName();
if ( name[ 0 ] == ':' ) {
node.renameNode( name.substring( 1 ) );
}
}

if ( includeChildren ) {
for ( var i = 0; i < node.getChildCount(); i++ )
renameNodes( node.getChild( i ) );
}
}
},

/**
@@ -226,6 +226,66 @@
CKEDITOR.dom.element.createFromHtml( '<i>bar</i>' ).appendTo( frag );

assert.areSame( '<b>foo</b><i>bar</i>', bender.tools.fixHtml( frag.getHtml(), 1, 1 ), 'HTML of documentFragment' );
},

// #13101
'test getHtml with html5': function() {
// IE8 only.
if ( !CKEDITOR.env.ie || CKEDITOR.env.version > 8 )
assert.ignore();

var frag = new CKEDITOR.dom.documentFragment( CKEDITOR.document );

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() ) );
}
} );
} )();
@@ -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() );
},
@@ -306,6 +306,30 @@
assert.isTrue( e.clone() instanceof CKEDITOR.dom.element );
},

'test_clone td': function() {
var td = newElement( 'td' );

td.appendText( 'foo' );

assert.areSame( '<td>foo</td>', getOuterHtml( td.clone( true ) ) );
},


'test_clone HTML5 figure': function() {
var figure = newElement( 'figure' );

assert.areSame( '<figure></figure>', getOuterHtml( figure.clone() ) );
},

'test_clone HTML5 div with figure': function() {
var div = newElement( 'div' ),
figure = newElement( 'figure' );

div.append( figure );

assert.areSame( '<div><figure></figure></div>', getOuterHtml( div.clone( true ) ) );
},

test_hasNext: function() {
var node1 = getNodeByTagName( 'b' ),
node2 = getNodeByTagName( 'i' );
@@ -186,6 +186,12 @@
[ '<div>b<p>{a@]</p>b</div>', 'a', '<div>b<p>[]@!</p>b</div>' ]
],

// #13101
'html5': [
[ '<div>[<figure>img</figure>]</div>', '<figure>img</figure>', '<div>[]@!</div>' ],
[ '<div>[<div><figure>img<figcaption>cap</figcaption></figure></div>]</div>', '<div><figure>img<figcaption>cap</figcaption></figure></div>', '<div>[]@!</div>' ]
],

'tables': [
// #1
[ '<table><tbody><tr><td>{a}</td></tr></tbody></table>', 'a', '<table><tbody><tr><td>[]@!</td></tr></tbody></table>' ],

0 comments on commit 7342d18

Please sign in to comment.
You can’t perform that action at this time.