Index: _source/tests/core/tools.html
===================================================================
--- _source/tests/core/tools.html (revision 3194)
+++ _source/tests/core/tools.html (working copy)
@@ -46,6 +46,35 @@
assert.areSame( 'Good' , target.prop6, 'prop6 doesn\'t match' );
assert.areSame( fakeArray , target.prop7, 'prop7 doesn\'t match' );
},
+
+ /**
+ * Test extend with 'overwrite' option and 'propertiesList' option.
+ */
+ test_extend2 : function()
+ {
+ var source = {
+ 'prop1' : 1,
+ 'prop2' : 2,
+ 'prop3' : 3
+ };
+
+ var result = CKEDITOR.tools.extend( {
+ 'prop1' : 1,
+ 'prop2' : 1
+ }, {
+ 'prop1' : 2,
+ 'prop2' : 2,
+ 'prop3' : 3
+ }, true, {
+ 'prop2' : 1,
+ 'prop3' : 1
+ } );
+
+ assert.areEqual( 1 , source.prop1);
+ assert.areEqual( 2 , source.prop2);
+ assert.areEqual( 3 , source.prop3);
+
+ },
test_isArray1 : function()
{
Index: _source/tests/core/dom/documentFragment.html
===================================================================
--- _source/tests/core/dom/documentFragment.html (revision 0)
+++ _source/tests/core/dom/documentFragment.html (revision 0)
@@ -0,0 +1,168 @@
+
+
+
+ CKEDITOR.dom.documentFragment
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: _source/core/tools.js
===================================================================
--- _source/core/tools.js (revision 3194)
+++ _source/core/tools.js (working copy)
@@ -83,9 +83,11 @@
* @param {Object} target The object to be extended.
* @param {Object} source[,souce(n)] The objects from which copy
* properties. Any number of objects can be passed to this function.
- * @param {Boolean} [overwrite] Indicates that properties already present
- * in the target object must be overwritten. This must be the last
- * parameter in the function call.
+ * @param {Boolean} overwrite If 'true' is specified it indicates that
+ * properties already present in the target object could be
+ * overwritten by subsequent objects.
+ * @param {Object} properties Only properties within the specified names
+ * list will be received from the source object.
* @returns {Object} the extended object (target).
* @example
* // Create the sample object.
@@ -108,21 +110,28 @@
extend : function( target )
{
var argsLength = arguments.length,
- overwrite = arguments[ argsLength - 1 ];
+ overwrite, propertiesList;
- if ( typeof overwrite == 'boolean' )
+ if ( CKEDITOR.tools.isArray( overwrite = arguments[ argsLength - 1 ] ) )
argsLength--;
- else
- overwrite = false;
-
+ else if ( CKEDITOR.tools.isArray( overwrite = arguments[ argsLength - 2 ] ) )
+ {
+ propertiesList = arguments [ argsLength -1 ];
+ argsLength-=2;
+ }
for ( var i = 1 ; i < argsLength ; i++ )
{
var source = arguments[ i ];
-
for ( var propertyName in source )
{
- if ( overwrite || target[ propertyName ] == undefined )
- target[ propertyName ] = source[ propertyName ];
+ // Only copy existed fields if in overwrite mode.
+ if ( overwrite === true || target[ propertyName ] == undefined )
+ {
+ // Only copy specified fields if list is provided.
+ if ( propertiesList && ( propertyName in propertiesList ) || !propertiesList )
+ target[ propertyName ] = source[ propertyName ];
+
+ }
}
}
Index: _source/core/dom/documentFragment.js
===================================================================
--- _source/core/dom/documentFragment.js (revision 3194)
+++ _source/core/dom/documentFragment.js (working copy)
@@ -2,65 +2,30 @@
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
-
+/**
+ * DocumentFragment is a "lightweight" or "minimal" Document object. It is
+ * commonly used to extract a portion of a document's tree or to create a new
+ * fragment of a document. Various operations may take DocumentFragment objects
+ * as arguments and results in all the child nodes of the DocumentFragment being
+ * moved to the child list of this node.
+ *
+ * @param {Object} ownerDocument
+ */
CKEDITOR.dom.documentFragment = function( ownerDocument )
{
- this.$ = CKEDITOR.env.ie ? ownerDocument.$.createElement( 'div' ) : ownerDocument.$.createDocumentFragment();
+ ownerDocument = ownerDocument || CKEDITOR.document;
+ this.$ = ownerDocument.$.createDocumentFragment();
};
-(function()
-{
- var elementPrototype = CKEDITOR.dom.element.prototype;
-
- CKEDITOR.dom.documentFragment.prototype =
+CKEDITOR.tools.extend( CKEDITOR.dom.documentFragment.prototype,
+ CKEDITOR.dom.element.prototype,
{
- type : CKEDITOR.NODE_DOCUMENT_FRAGMENT,
-
- append : elementPrototype.append,
-
- getFirst : elementPrototype.getFirst,
-
- getLast : elementPrototype.getLast,
-
- appendTo : function( targetElement )
- {
- if ( CKEDITOR.env.ie )
- elementPrototype.moveChildren.call( this, targetElement );
- else
- targetElement.$.appendChild( this.$ );
- },
-
- moveChildren : elementPrototype.moveChildren,
-
+ type :CKEDITOR.NODE_DOCUMENT_FRAGMENT,
insertAfterNode : function( node )
{
- var $ = this.$;
- var $node = node.$;
- var $parent = $node.parentNode;
-
- if ( CKEDITOR.env.ie )
- {
- for ( var child ; child = $.lastChild ; )
- $parent.insertBefore( $.removeChild( child ), $node.nextSibling );
- }
- else
- $parent.insertBefore( $, $node.nextSibling );
- },
-
- replace : function( nodeToReplace )
- {
- this.insertAfterNode( nodeToReplace );
- nodeToReplace.remove();
- },
-
- trim : elementPrototype.trim,
- ltrim : elementPrototype.ltrim,
- rtrim : elementPrototype.rtrim,
- getFirst : elementPrototype.getFirst,
- getLast : elementPrototype.getLast,
- getDocument : elementPrototype.getDocument,
- getChildCount : elementPrototype.getChildCount,
- getChild : elementPrototype.getChild,
- contains : elementPrototype.contains
- };
-})();
+ node = node.$;
+ node.parentNode.insertBefore( this.$, node.nextSibling );
+ }
+ }, [ 'append', 'getFirst', 'getLast', 'appendTo', 'moveChildren',
+ 'insertAfterNode', 'replace', 'trim', 'ltrim', 'rtrim', 'getDocument',
+ 'getChildCount', 'getChild', 'getChildren' ] );