Ticket #3758: 3758_2.patch
File 3758_2.patch, 2.9 KB (added by , 14 years ago) |
---|
-
_source/plugins/dialog/plugin.js
98 98 // Completes the definition with the default values. 99 99 definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition ); 100 100 101 // Clone a functionally independent copy for this dialog. 102 definition = CKEDITOR.tools.clone( definition ); 103 101 104 // Create a complex definition object, extending it with the API 102 105 // functions. 103 106 definition = new definitionObject( this, definition ); -
_source/core/tools.js
60 60 * alert( obj.cars.Porsche.color ); // red 61 61 * alert( clone.cars.Porsche.color ); // silver 62 62 */ 63 clone : function( object)63 clone : ( function() 64 64 { 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 } 67 77 68 var clone = new object.constructor(); 78 function isArray( obj ) 79 { 80 return obj && ( typeof obj.splice == 'function' ); 81 } 69 82 70 f or ( var propertyName in object )83 function cloneObject( dict ) 71 84 { 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; 74 99 } 75 100 76 return clone; 77 }, 101 function cloneArray( list ) 102 { 103 var retval = []; 78 104 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 79 129 /** 80 130 * Copy the properties from one object to another. By default, properties 81 131 * already present in the target object <strong>are not</strong> overwritten.