X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Fdomobject.js;h=e342dc893b13372b4a3fecff0f8587f3c4e5b312;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=c0c6e63cd9b6e5b9d2a671152fc6683f4ba2bf4e;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/core/dom/domobject.js b/_source/core/dom/domobject.js index c0c6e63..e342dc8 100644 --- a/_source/core/dom/domobject.js +++ b/_source/core/dom/domobject.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, 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.$.detachEvent ) + this.$.detachEvent( 'on' + eventName, listener ); + else if ( this.$.removeEventListener ) + this.$.removeEventListener( eventName, listener, false ); + + 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 @@ -142,6 +167,9 @@ CKEDITOR.dom.domObject.prototype = (function() /** * Sets a data slot value for this object. These values are shared by all * instances pointing to that same DOM object. + * Note: The created data slot is only guarantied to be available on this unique dom node, + * thus any wish to continue access it from other element clones (either created by clone node or from innerHtml) + * will fail, for such usage, please use {@link CKEDITOR.dom.element::setAttribute} instead. * @name CKEDITOR.dom.domObject.prototype.setCustomData * @function * @param {String} key A key used to identify the data slot. @@ -175,15 +203,18 @@ CKEDITOR.dom.domObject.prototype = (function() */ domObjectProto.getCustomData = function( key ) { - var expandoNumber = this.$._cke_expando, + var expandoNumber = this.$[ 'data-cke-expando' ], dataSlot = expandoNumber && customData[ expandoNumber ]; return dataSlot && dataSlot[ key ]; }; + /** + * @name CKEDITOR.dom.domObject.prototype.removeCustomData + */ domObjectProto.removeCustomData = function( key ) { - var expandoNumber = this.$._cke_expando, + var expandoNumber = this.$[ 'data-cke-expando' ], dataSlot = expandoNumber && customData[ expandoNumber ], retval = dataSlot && dataSlot[ key ]; @@ -193,9 +224,32 @@ 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.$[ 'data-cke-expando' ]; + expandoNumber && delete customData[ expandoNumber ]; + }; + + /** + * Gets an ID that can be used to identiquely identify this DOM object in + * the running session. + * @name CKEDITOR.dom.domObject.prototype.getUniqueId + * @function + * @returns {Number} A unique ID. + */ domObjectProto.getUniqueId = function() { - return this.$._cke_expando || ( this.$._cke_expando = CKEDITOR.tools.getNextNumber() ); + return this.$[ 'data-cke-expando' ] || ( this.$[ 'data-cke-expando' ] = CKEDITOR.tools.getNextNumber() ); }; // Implement CKEDITOR.event.