Ticket #3266: 3266.patch
File 3266.patch, 5.1 KB (added by , 15 years ago) |
---|
-
_source/core/dom/domobject.js
29 29 * alert( element.$.nodeType ); // "1" 30 30 */ 31 31 this.$ = nativeDomObject; 32 33 // Get the main private function from the custom data. Create it if not34 // defined.35 if ( !( this._ = this.getCustomData( '_' ) ) )36 this.setCustomData( '_', ( this._ = {} ) );37 38 // Call the base event constructor.39 if ( !this._.events )40 CKEDITOR.event.call( this );41 32 } 42 33 }; 43 34 … … 60 51 61 52 return /** @lends CKEDITOR.dom.domObject.prototype */ { 62 53 54 getPrivate : function() 55 { 56 var priv; 57 58 // Get the main private function from the custom data. Create it if not 59 // defined. 60 if ( !( priv = this.getCustomData( '_' ) ) ) 61 this.setCustomData( '_', ( priv = {} ) ); 62 63 return priv; 64 }, 65 63 66 /** @ignore */ 64 67 on : function( eventName ) 65 68 { … … 196 199 }; 197 200 198 201 // Implement CKEDITOR.event. 199 CKEDITOR.event.implementOn( domObjectProto , true);202 CKEDITOR.event.implementOn( domObjectProto ); 200 203 201 204 })( CKEDITOR.dom.domObject.prototype ); -
_source/core/event.js
17 17 * @example 18 18 */ 19 19 CKEDITOR.event = function() 20 { 21 //In case of preserving existed events 22 var preExistedEvents = this._ && this._.events; 23 if( !preExistedEvents ) 24 ( this._ || ( this._ = {} ) ).events = {}; 25 }; 20 {}; 26 21 27 22 /** 28 23 * Implements the {@link CKEDITOR.event} features in an object. 29 24 * @param {Object} targetObject The object in which implement the features. 30 * @param {Boolean} isTargetPrototype If the target is a prototype of31 * constructor, the internal 'events' object will not be copied,32 * which should be composed by the constructor itself.33 25 * @example 34 26 * var myObject = { message : 'Example' }; 35 27 * <b>CKEDITOR.event.implementOn( myObject }</b>; … … 39 31 * }); 40 32 * myObject.fire( 'testEvent' ); 41 33 */ 42 CKEDITOR.event.implementOn = function( targetObject , isTargetPrototype)34 CKEDITOR.event.implementOn = function( targetObject, isTargetPrototype ) 43 35 { 44 if( !isTargetPrototype ) 45 CKEDITOR.event.call( targetObject ); 36 var eventProto = CKEDITOR.event.prototype; 46 37 47 for ( var prop in CKEDITOR.event.prototype)38 for ( var prop in eventProto ) 48 39 { 49 (function(){ 50 51 var property = prop; 52 53 if ( targetObject[ property ] == undefined ) 54 targetObject[ property ] = isTargetPrototype? 55 function() 56 { 57 //pre-setup events model 58 if( ! ( this._ && this._.events ) ) 59 CKEDITOR.event.call( this ); 60 61 ( this[ property ] = CKEDITOR.event.prototype[ property ] ) 62 .apply( this, arguments ); 63 } : 64 CKEDITOR.event.prototype[ property ]; 65 })(); 40 if ( targetObject[ prop ] == undefined ) 41 targetObject[ prop ] = eventProto[ prop ]; 66 42 } 67 43 }; 68 44 69 45 CKEDITOR.event.prototype = (function() 70 46 { 47 // Returns the private events object for a given object. 48 var getPrivate = function( obj ) 49 { 50 var _ = ( obj.getPrivate && obj.getPrivate() ) || obj._ || ( obj._ = {} ); 51 return _.events || ( _.events = {} ); 52 }; 53 71 54 var eventEntry = function( eventName ) 72 55 { 73 56 this.name = eventName; 74 57 this.listeners = []; 75 58 }; 76 59 77 60 eventEntry.prototype = 78 61 { 79 62 // Get the listener index for a specified function. … … 128 111 on : function( eventName, listenerFunction, scopeObj, listenerData, priority ) 129 112 { 130 113 // Get the event entry (create it if needed). 131 var event = this._.events[ eventName ] || ( this._.events[ eventName ] = new eventEntry( eventName ) ); 114 var events = getPrivate( this ), 115 event = events[ eventName ] || ( events[ eventName ] = new eventEntry( eventName ) ); 132 116 133 117 if ( event.getListenerIndex( listenerFunction ) < 0 ) 134 118 { … … 232 216 return function( eventName, data, editor ) 233 217 { 234 218 // Get the event entry. 235 var event = this._.events[ eventName ];219 var event = getPrivate( this )[ eventName ]; 236 220 237 221 // Save the previous stopped and cancelled states. We may 238 222 // be nesting fire() calls. … … 302 286 fireOnce : function( eventName, data, editor ) 303 287 { 304 288 var ret = this.fire( eventName, data, editor ); 305 delete this._.events[ eventName ];289 delete getPrivate( this )[ eventName ]; 306 290 return ret; 307 291 }, 308 292 … … 322 306 removeListener : function( eventName, listenerFunction ) 323 307 { 324 308 // Get the event entry. 325 var event = this._.events[ eventName ];309 var event = getPrivate( this )[ eventName ]; 326 310 327 311 if ( event ) 328 312 { … … 343 327 */ 344 328 hasListeners : function( eventName ) 345 329 { 346 var event = this._.events[ eventName ];330 var event = getPrivate( this )[ eventName ]; 347 331 return ( event && event.listeners.length > 0 ) ; 348 332 } 349 333 };