From f0cfe83e3725f9a3928da97a6e3085e79cb25309 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 18 Mar 2013 10:26:24 +0400 Subject: upgrade dojo to 1.8.3 (refs #570) --- lib/dijit/Destroyable.js.uncompressed.js | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lib/dijit/Destroyable.js.uncompressed.js (limited to 'lib/dijit/Destroyable.js.uncompressed.js') diff --git a/lib/dijit/Destroyable.js.uncompressed.js b/lib/dijit/Destroyable.js.uncompressed.js new file mode 100644 index 000000000..ee6b8893e --- /dev/null +++ b/lib/dijit/Destroyable.js.uncompressed.js @@ -0,0 +1,59 @@ +define("dijit/Destroyable", [ + "dojo/_base/array", // array.forEach array.map + "dojo/aspect", + "dojo/_base/declare" +], function(array, aspect, declare){ + +// module: +// dijit/Destroyable + +return declare("dijit.Destroyable", null, { + // summary: + // Mixin to track handles and release them when instance is destroyed. + // description: + // Call this.own(...) on list of handles (returned from dojo/aspect, dojo/on, + // dojo/Stateful::watch, or any class (including widgets) with a destroyRecursive() or destroy() method. + // Then call destroy() later to destroy this instance and release the resources. + + destroy: function(/*Boolean*/ preserveDom){ + // summary: + // Destroy this class, releasing any resources registered via own(). + this._destroyed = true; + }, + + own: function(){ + // summary: + // Track specified handles and remove/destroy them when this instance is destroyed, unless they were + // already removed/destroyed manually. + // tags: + // protected + // returns: + // The array of specified handles, so you can do for example: + // | var handle = this.own(on(...))[0]; + + array.forEach(arguments, function(handle){ + var destroyMethodName = + "destroyRecursive" in handle ? "destroyRecursive" : // remove "destroyRecursive" for 2.0 + "destroy" in handle ? "destroy" : + "remove"; + + // When this.destroy() is called, destroy handle. Since I'm using aspect.before(), + // the handle will be destroyed before a subclass's destroy() method starts running, before it calls + // this.inherited() or even if it doesn't call this.inherited() at all. If that's an issue, make an + // onDestroy() method and connect to that instead. + var odh = aspect.before(this, "destroy", function(preserveDom){ + handle[destroyMethodName](preserveDom); + }); + + // If handle is destroyed manually before this.destroy() is called, remove the listener set directly above. + var hdh = aspect.after(handle, destroyMethodName, function(){ + odh.remove(); + hdh.remove(); + }, true); + }, this); + + return arguments; // handle + } +}); + +}); -- cgit v1.2.3