X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fcore%2Fdom%2Fdomobject.js;h=f10db99bb1adfffbf6a0b5da0d04ee4f5807a288;hb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;hp=c0c6e63cd9b6e5b9d2a671152fc6683f4ba2bf4e;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/core/dom/domobject.js b/_source/core/dom/domobject.js index c0c6e63..f10db99 100644 --- a/_source/core/dom/domobject.js +++ b/_source/core/dom/domobject.js @@ -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() );