Changeset 13683

Show
Ignore:
Timestamp:
05/10/08 20:25:50 (5 days ago)
Author:
dante
Message:

fixes #6668 - very exciting stuff - _Widget.destroy(true) will preserve the domNode (does NOT work with _Templated yet, but
that's the plan). This is a compromise between a "widget" and "named behaviors", where you can use _Widget to create
structured "behavioral" widgets around a single domNode. This is a great inclusion, though we be unnecessary if
dojo.behavior had a .remove() method (perhaps based on a handle returned from add()?)

noteworthy: this technically changes the API of an unsupported, unused param "finalize" (probably used in older days for
global cleanup, but unused since 0.9) to "preserveDom" ... true meaning "leave the node alone".

includes simple testcase to check widget count in registry, could easily be converted to unit test.

!strict

Location:
dijit/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/_Widget.js

    r13521 r13683  
    202202        //////////// DESTROY FUNCTIONS //////////////////////////////// 
    203203 
    204         destroyRecursive: function(/*Boolean*/ finalize){ 
     204        destroyRecursive: function(/*Boolean*/ preserveDom){ 
    205205                // summary: 
    206206                //              Destroy this widget and it's descendants. This is the generic 
     
    208208                //              cleanly discard with a widget. Once a widget is destroyed, it's 
    209209                //              removed from the manager object. 
    210                 // finalize: Boolean 
    211                 //              is this function being called part of global environment 
    212                 //              tear-down? 
    213  
    214                 this.destroyDescendants(); 
    215                 this.destroy(); 
    216         }, 
    217  
    218         destroy: function(/*Boolean*/ finalize){ 
     210                // preserveDom: Boolean 
     211                //              If true, this method will leave the original Dom structure alone 
     212                //              of descendant Widgets. Note: This will NOT work with _Templated 
     213                //              widgets. 
     214                // 
     215                this.destroyDescendants(preserveDom); 
     216                this.destroy(preserveDom); 
     217        }, 
     218 
     219        destroy: function(/*Boolean*/ preserveDom){ 
    219220                // summary: 
    220221                //              Destroy this widget, but not its descendants 
    221                 // finalize: Boolean 
    222                 //              is this function being called part of global environment 
    223                 //              tear-down? 
     222                // preserveDom: Boolean 
     223                //              If true, this method will leave the original Dom structure alone. 
     224                //              Note: This will not yet work with _Templated widgets 
    224225 
    225226                this.uninitialize(); 
     
    231232                dojo.forEach(this._supportingWidgets || [], function(w){ w.destroy(); }); 
    232233                 
    233                 this.destroyRendering(finalize); 
     234                this.destroyRendering(preserveDom); 
    234235                dijit.registry.remove(this.id); 
    235236        }, 
    236237 
    237         destroyRendering: function(/*Boolean*/ finalize){ 
     238        destroyRendering: function(/*Boolean*/ preserveDom){ 
    238239                // summary: 
    239240                //              Destroys the DOM nodes associated with this widget 
    240                 // finalize: Boolean 
    241                 //              is this function being called part of global environment 
    242                 //              tear-down? 
    243  
     241                // preserveDom: Boolean 
     242                //              If true, this method will leave the original Dom structure alone 
     243                //              during tear-down. Note: this will not work with _Templated 
     244                //              widgets yet.  
     245                 
    244246                if(this.bgIframe){ 
    245                         this.bgIframe.destroy(); 
     247                        this.bgIframe.destroy(preserveDom); 
    246248                        delete this.bgIframe; 
    247249                } 
    248250 
    249251                if(this.domNode){ 
    250                         dojo._destroyElement(this.domNode); 
     252                        if(!preserveDom){ 
     253                                dojo._destroyElement(this.domNode); 
     254                        } 
    251255                        delete this.domNode; 
    252256                } 
    253257 
    254258                if(this.srcNodeRef){ 
    255                         dojo._destroyElement(this.srcNodeRef); 
     259                        if(!preserveDom){ 
     260                                dojo._destroyElement(this.srcNodeRef); 
     261                        } 
    256262                        delete this.srcNodeRef; 
    257263                } 
    258264        }, 
    259265 
    260         destroyDescendants: function(){ 
     266        destroyDescendants: function(/* Boolean */ preserveDom){ 
    261267                // summary: 
    262268                //              Recursively destroy the children of this widget and their 
    263269                //              descendants. 
    264  
     270                // preserveDom: Boolean 
     271                //              If true, the preserveDom attribute is passed to all descendant 
     272                //              widget's .destroy() method. Not for use with _Templated widgets. 
     273                 
    265274                // TODO: should I destroy in the reverse order, to go bottom up? 
    266                 dojo.forEach(this.getDescendants(), function(widget){ widget.destroy(); }); 
     275                dojo.forEach(this.getDescendants(), function(widget){ widget.destroy(preserveDom); }); 
    267276        }, 
    268277