Ticket #3758: 3758_2.patch

File 3758_2.patch, 2.9 KB (added by Martin Kou, 15 years ago)
  • _source/plugins/dialog/plugin.js

     
    9898                // Completes the definition with the default values.
    9999                definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );
    100100
     101                // Clone a functionally independent copy for this dialog.
     102                definition = CKEDITOR.tools.clone( definition );
     103
    101104                // Create a complex definition object, extending it with the API
    102105                // functions.
    103106                definition = new definitionObject( this, definition );
  • _source/core/tools.js

     
    6060                 * alert( obj.cars.Porsche.color );     // red
    6161                 * alert( clone.cars.Porsche.color );   // silver
    6262                 */
    63                 clone : function( object )
     63                clone : ( function()
    6464                {
    65                         if( object === null || typeof( object ) != 'object')
    66                                 return object;
     65                        function isImmutable( obj )
     66                        {
     67                                return obj === null || obj === undefined ||
     68                                        ( typeof obj == 'string' ) ||
     69                                        ( obj instanceof String ) ||
     70                                        ( typeof obj == 'number' ) ||
     71                                        ( obj instanceof Number ) ||
     72                                        ( typeof obj == 'boolean' ) ||
     73                                        ( obj instanceof Boolean ) ||
     74                                        ( typeof obj == 'function' ) ||
     75                                        ( obj instanceof Date );
     76                        }
    6777
    68                         var clone = new object.constructor();
     78                        function isArray( obj )
     79                        {
     80                                return obj && ( typeof obj.splice == 'function' );
     81                        }
    6982
    70                         for ( var propertyName in object )
     83                        function cloneObject( dict )
    7184                        {
    72                                 var property = object[ propertyName ];
    73                                 clone[ propertyName ] = this.clone( property );
     85                                var retval = {};
     86
     87                                for ( var i in dict )
     88                                {
     89                                        var value = dict[ i ];
     90                                        if ( isImmutable( value ) )
     91                                                retval[ i ] = value;
     92                                        else if ( isArray( value ) )
     93                                                retval[ i ] = cloneArray( value );
     94                                        else
     95                                                retval[ i ] = cloneObject( value );
     96                                }
     97
     98                                return retval;
    7499                        }
    75100
    76                         return clone;
    77                 },
     101                        function cloneArray( list )
     102                        {
     103                                var retval = [];
    78104
     105                                for ( var i = 0 ; i < list.length ; i++ )
     106                                {
     107                                        if ( isImmutable( list[ i ] ) )
     108                                                retval.push( list[ i ] );
     109                                        else if ( isArray( list[ i ] ) )
     110                                                retval.push( cloneArray( list[ i ] ) );
     111                                        else
     112                                                retval.push( cloneObject( list[ i ] ) );
     113                                }
     114
     115                                return retval;
     116                        }
     117
     118                        return function( obj )
     119                        {
     120                                if ( isImmutable( obj ) )
     121                                        return obj;
     122                                else if ( isArray( obj ) )
     123                                        return cloneArray( obj );
     124                                else
     125                                        return cloneObject( obj );
     126                        }
     127                } )(),
     128
    79129                /**
    80130                 * Copy the properties from one object to another. By default, properties
    81131                 * already present in the target object <strong>are not</strong> overwritten.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy