X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Fdomobject.js;h=f10db99bb1adfffbf6a0b5da0d04ee4f5807a288;hb=refs%2Ftags%2Fv3.3;hp=d8c3fde520c2b6fcb148fed0876704565d6bb16b;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/core/dom/domobject.js b/_source/core/dom/domobject.js index d8c3fde..f10db99 100644 --- a/_source/core/dom/domobject.js +++ b/_source/core/dom/domobject.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -115,6 +115,26 @@ CKEDITOR.dom.domObject.prototype = (function() delete nativeListeners[ eventName ]; } } + }, + + /** + * Removes any listener set on this object. + * To avoid memory leaks we must assure that there are no + * references left after the object is no longer needed. + */ + removeAllListeners : function() + { + var nativeListeners = this.getCustomData( '_cke_nativeListeners' ); + for ( var eventName in nativeListeners ) + { + var listener = nativeListeners[ eventName ]; + if ( this.$.removeEventListener ) + this.$.removeEventListener( eventName, listener, false ); + else if ( this.$.detachEvent ) + this.$.detachEvent( 'on' + eventName, listener ); + + delete nativeListeners[ eventName ]; + } } }; })(); @@ -123,6 +143,11 @@ CKEDITOR.dom.domObject.prototype = (function() { var customData = {}; + CKEDITOR.on( 'reset', function() + { + customData = {}; + }); + /** * Determines whether the specified object is equal to the current object. * @name CKEDITOR.dom.domObject.prototype.equals @@ -181,6 +206,9 @@ CKEDITOR.dom.domObject.prototype = (function() return dataSlot && dataSlot[ key ]; }; + /** + * @name CKEDITOR.dom.domObject.prototype.removeCustomData + */ domObjectProto.removeCustomData = function( key ) { var expandoNumber = this.$._cke_expando, @@ -193,6 +221,25 @@ CKEDITOR.dom.domObject.prototype = (function() return retval || null; }; + /** + * Removes any data stored on this object. + * To avoid memory leaks we must assure that there are no + * references left after the object is no longer needed. + * @name CKEDITOR.dom.domObject.prototype.clearCustomData + * @function + */ + domObjectProto.clearCustomData = function() + { + // Clear all event listeners + this.removeAllListeners(); + + var expandoNumber = this.$._cke_expando; + expandoNumber && delete customData[ expandoNumber ]; + }; + + /** + * @name CKEDITOR.dom.domObject.prototype.getCustomData + */ domObjectProto.getUniqueId = function() { return this.$._cke_expando || ( this.$._cke_expando = CKEDITOR.tools.getNextNumber() );