Changeset 14485

Show
Ignore:
Timestamp:
07/17/08 10:25:43 (6 months ago)
Author:
doughays
Message:

Fixes #7226 !strict. setAttribute('onClick', myfunc) was being called since onClick was in the attributeMap and in the markup (subsequently calling dojo.connect), AND the menu item code was manually calling this.onClick. Changed _Widget.js to not have the lazy connected events in attributeMap, but have a similar but separate object to contain them.

Location:
dijit/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/tests/test_Menu.html

    r14070 r14485  
    8484                                <div dojoType="dijit.PopupMenuItem"> 
    8585                                        <span>Deeper Submenu</span> 
    86                                         <div dojoType="dijit.Menu" id="submenu4""> 
     86                                        <div dojoType="dijit.Menu" id="submenu4"> 
    8787                                                <div dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 1!')">Sub-sub-menu Item One</div> 
    8888                                                <div dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 2!')">Sub-sub-menu Item Two</div> 
  • dijit/trunk/_Widget.js

    r14473 r14485  
    9191        //              on the widget's dom, at the "domNode" attach point, by default. 
    9292        //              Other node references can be specified as properties of 'this' 
    93         attributeMap: {id:"", dir:"", lang:"", "class":"", style:"", title:"", 
     93        attributeMap: {id:"", dir:"", lang:"", "class":"", style:"", title:""}, 
     94 
     95        // _deferredConnects: Object 
     96        //              attributeMap addendum for event handlers that should be connected only on first use 
     97        _deferredConnects: { 
    9498                onClick: "", 
    9599                onDblClick: "", 
     
    213217 
    214218        constructor: function(){ 
    215                 this._onUseEvents = []; // list of events that needs to be connected on first use 
     219                this._deferredConnects = dojo.clone(this._deferredConnects); 
    216220                for(var attr in this.attributeMap){ 
    217                         if(this[attr] === dijit._connectOnUseEventHandler){ 
    218                                 this._onUseEvents[attr] = true; 
     221                        delete this._deferredConnects[attr]; // can't be in both attributeMap and _deferredConnects 
     222                } 
     223                for(var attr in this._deferredConnects){ 
     224                        if(this[attr] !== dijit._connectOnUseEventHandler){ 
     225                                delete this._deferredConnects[attr]; 
    219226                        } 
    220227                } 
     
    285292                        for(var attr in this.attributeMap){ 
    286293                                var value = this[attr]; 
    287                                 if(value !== dijit._connectOnUseEventHandler && (typeof value != "undefined") && (typeof value != "object") && ((value !== "" && value !== false) || (params && params[attr]))){ 
     294                                if((typeof value != "undefined") && (typeof value != "object") && ((value !== "" && value !== false) || (params && params[attr]))){ 
    288295                                        this.setAttribute(attr, value); 
     296                                } 
     297                        } 
     298                        for(var attr in this._deferredConnects){ 
     299                                var value = this[attr]; 
     300                                if(value !== dijit._connectOnUseEventHandler){ 
     301                                        this._onConnect(this, attr); 
    289302                                } 
    290303                        } 
     
    448461        }, 
    449462 
    450         _onConnect: function(/*Widget*/ widget, /*String*/ event){ 
    451                 if(widget && (typeof widget == "object") && widget._onUseEvents && widget._onUseEvents[event]){ 
    452                         widget.setAttribute(event, widget[event]); 
     463        _onConnect: function(/*Widget*/ _this, /*String*/ event){ 
     464                if(typeof this._deferredConnects[event] != "undefined"){ 
     465                        delete this._deferredConnects[event]; 
     466                        var mapNode = this[this._deferredConnects[event]||'domNode']; 
     467                        this.connect(mapNode, event.toLowerCase(), this[event]); 
    453468                } 
    454469        }, 
     
    482497                                } 
    483498                                if(/^on[A-Z][a-zA-Z]*$/.test(attr)){ // eg. onSubmit needs to be onsubmit 
    484                                         if(this._onUseEvents[attr]){ 
    485                                                 delete this._onUseEvents[attr]; 
    486                                         } 
    487499                                        attr = attr.toLowerCase(); 
    488500                                } 
    489501                                dojo.attr(mapNode, attr, value); 
    490  
    491502                } 
    492503        },