Ticket #2970: 2970.patch

File 2970.patch, 5.1 KB (added by Garry Yao, 15 years ago)
  • _source/core/tools.js

     
    4242                 * @param {Object} target The object to be extended.
    4343                 * @param {Object} source[,souce(n)] The objects from which copy
    4444                 *              properties. Any number of objects can be passed to this function.
    45                  * @param {Boolean} [overwrite] Indicates that properties already present
    46                  *              in the target object must be overwritten. This must be the last
    47                  *              parameter in the function call.
     45                 * @param {Boolean|Array} [overwrite] If 'true' is specified it
     46                 *            indicates that properties already present in the target
     47                 *            object must be overwritten. If an Array of property names
     48                 *            is specified, only names specified in the collection will
     49                 *            be received from the source object.
     50                 *            This must be the last parameter in the function call.
    4851                 * @returns {Object} the extended object (target).
    4952                 * @example
    5053                 * // Create the sample object.
     
    6770                extend : function( target )
    6871                {
    6972                        var argsLength = arguments.length,
    70                                 overwrite = arguments[ argsLength - 1 ];
     73                                overwrite = arguments[ argsLength - 1 ],
     74                                //whether it's a to-receiving properties list
     75                                isList;
    7176
    72                         if ( typeof overwrite == 'boolean' )
    73                                 argsLength--;
     77                        if ( typeof overwrite == 'boolean'
     78                        || ( isList = CKEDITOR.tools.isArray( overwrite ) ) )
     79                            argsLength--;
    7480                        else
    7581                                overwrite = false;
    7682
     
    8086
    8187                                for ( var propertyName in source )
    8288                                {
    83                                         if ( overwrite || target[ propertyName ] == undefined )
     89                                        if ( ( overwrite === true || target[ propertyName ] == undefined )
     90                                                //only copy property in the list
     91                                                || ( isList && CKEDITOR.tools.indexOf( overwrite, propertyName ) != -1 ) )
    8492                                                target[ propertyName ] = source[ propertyName ];
    8593                                }
    8694                        }
  • _source/core/dom/documentFragment.js

     
    22Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    5 
     5/**
     6 * DocumentFragment is a "lightweight" or "minimal" Document object. It is
     7 * commonly used to extract a portion of a document's tree or to create a new
     8 * fragment of a document. Various operations may take DocumentFragment objects
     9 * as arguments and results in all the child nodes of the DocumentFragment being
     10 * moved to the child list of this node.
     11 *
     12 * @param {Object} ownerDocument
     13 */
    614CKEDITOR.dom.documentFragment = function( ownerDocument )
    715{
    8         this.$ = CKEDITOR.env.ie ? ownerDocument.$.createElement( 'div' ) : ownerDocument.$.createDocumentFragment();
     16        ownerDocument = ownerDocument || CKEDITOR.document;
     17        this.$ = ownerDocument.$.createDocumentFragment();
    918};
    1019
    11 (function()
    12 {
    13         var elementPrototype = CKEDITOR.dom.element.prototype;
    14 
    15         CKEDITOR.dom.documentFragment.prototype =
    16         {
    17                 type : CKEDITOR.NODE_DOCUMENT_FRAGMENT,
    18 
    19                 append : elementPrototype.append,
    20 
    21                 getFirst : elementPrototype.getFirst,
    22 
    23                 getLast : elementPrototype.getLast,
    24 
    25                 appendTo : function( targetElement )
    26                 {
    27                         if ( CKEDITOR.env.ie )
    28                                 elementPrototype.moveChildren.call( this, targetElement );
    29                         else
    30                                 targetElement.$.appendChild( this.$ );
    31                 },
    32 
    33                 moveChildren : elementPrototype.moveChildren,
    34 
    35                 insertAfterNode : function( node )
    36                 {
    37                         var $ = this.$;
    38                         var $node = node.$;
    39                         var $parent = $node.parentNode;
    40 
    41                         if ( CKEDITOR.env.ie )
    42                         {
    43                                 for ( var child ; child = $.lastChild ; )
    44                                         $parent.insertBefore( $.removeChild( child ), $node.nextSibling );
    45                         }
    46                         else
    47                                 $parent.insertBefore( $, $node.nextSibling );
    48                 },
    49 
    50                 replace : function( nodeToReplace )
    51                 {
    52                         this.insertAfterNode( nodeToReplace );
    53                         nodeToReplace.remove();
    54                 },
    55 
    56                 trim : elementPrototype.trim,
    57                 ltrim : elementPrototype.ltrim,
    58                 rtrim : elementPrototype.rtrim,
    59                 getFirst : elementPrototype.getFirst,
    60                 getLast : elementPrototype.getLast,
    61                 getDocument : elementPrototype.getDocument,
    62                 getChildCount : elementPrototype.getChildCount,
    63                 getChild : elementPrototype.getChild,
    64                 contains : elementPrototype.contains
    65         };
    66 })();
     20CKEDITOR.tools.extend( CKEDITOR.dom.documentFragment.prototype,
     21    CKEDITOR.dom.element.prototype,
     22    {
     23        type :CKEDITOR.NODE_DOCUMENT_FRAGMENT,
     24        insertAfterNode : function( node )
     25        {
     26                var $ = this.$;
     27                var $node = node.$;
     28                var $parent = $node.parentNode;
     29                $parent.insertBefore( $, $node.nextSibling );
     30        }
     31    }, [ 'type', 'append', 'getFirst', 'getLast', 'appendTo', 'moveChildren',
     32        'insertAfterNode', 'replace', 'trim', 'ltrim', 'rtrim', 'getFirst',
     33        'getLast', 'getDocument', 'getChildCount', 'getChild', 'getChildren',
     34        'contains' ] );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy