Changeset 14473
- Timestamp:
- 07/16/08 19:43:22 (4 months ago)
- Location:
- dijit/trunk
- Files:
-
- 2 modified
-
tests/form/test_DateTextBox.html (modified) (8 diffs)
-
_Widget.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dijit/trunk/tests/form/test_DateTextBox.html
r14346 r14473 43 43 dojo.require("dojo.date.locale"); 44 44 dojo.require("dojo.parser"); // scan page for widgets and instantiate them 45 46 function eventHandler(e){ 47 // use this.domNode.getAttribute('widgetId') to show "this" is the widget 48 // mouseleave/enter map to mouseout/over in all browsers except IE 49 console.log(this.domNode.getAttribute('widgetId') + ' ' + arguments[0].type); 50 } 45 51 </script> 46 52 </head> … … 58 64 <div class="testExample"> 59 65 <input id="q1" name="noDOMvalue" value="2008-12-31" type="text" dojoType="dijit.form.DateTextBox" 60 onChange="dojo.byId('oc1').value=''+arguments[0]" 66 onMouseEnter="eventHandler" 67 onMouseLeave="eventHandler" 68 onKeyDown="eventHandler" 69 onChange="dojo.byId('oc1').value=''+arguments[0]" 61 70 > 62 71 onChange:<input id="oc1" size="34" disabled value="not fired yet!" autocomplete="off"> … … 73 82 </div> 74 83 <div class="testExample"> 75 < inputid="q2" type="text" name="date1" value="2005-12-30"84 <div id="q2" type="text" name="date1" value="2005-12-30" 76 85 dojoType="dijit.form.DateTextBox" 77 86 constraints="{min:'2004-01-01',max:'2006-12-31',formatLength:'long'}" … … 79 88 trim="true" 80 89 onChange="dojo.byId('oc2').value=arguments[0]" 81 invalidMessage="Invalid date." /> 90 invalidMessage="Invalid date." > 91 <script type="dojo/connect" event="onMouseEnter">eventHandler.apply(this, arguments)</script> 92 <script type="dojo/connect" event="onMouseLeave">eventHandler.apply(this, arguments)</script> 93 <script type="dojo/connect" event="onKeyDown">eventHandler.apply(this, arguments)</script> 94 </div> 82 95 onChange:<input id="oc2" size="34" disabled value="not fired yet!" autocomplete="off"> 83 96 <input type="button" value="Destroy" onClick="dijit.byId('q2').destroy(); return false;"> … … 90 103 </div> 91 104 <div class="testExample"> 92 < inputid="q3" type="text" name="date2" value="2005-12-30"105 <div id="q3" type="text" name="date2" value="2005-12-30" 93 106 dojoType="dijit.form.DateTextBox" 94 107 constraints="{min:'2004-01-01',max:'2006-12-31'}" … … 96 109 required="true" 97 110 promptMessage="mm/dd/yyyy" 98 invalidMessage="Invalid date. Use mm/dd/yyyy format." /> 111 invalidMessage="Invalid date. Use mm/dd/yyyy format."> 112 <script type="dojo/method" event="onMouseEnter">eventHandler.call(this, arguments[0])</script> 113 <script type="dojo/method" event="onMouseLeave">eventHandler.call(this, arguments[0])</script> 114 <script type="dojo/method" event="onKeyDown">eventHandler.call(this, arguments[0])</script> 115 </div> 99 116 </div> 100 117 <div class="dojoTitlePaneLabel"> … … 118 135 // See if we can make a widget in script and attach it to the DOM ourselves. 119 136 dojo.addOnLoad(function(){ 137 dojo.connect(dijit.byId('q5'), "onMouseEnter", eventHandler); 138 dojo.connect(dijit.byId('q5'), "onMouseLeave", eventHandler); 139 dojo.connect(dijit.byId('q5'), "onKeyDown", eventHandler); 140 120 141 var props = { 121 142 name: "date4", … … 123 144 constraints: {min:new Date(2004,0,1),max:new Date(2006,11,31)}, 124 145 lang: "de-de", 146 onMouseEnter: eventHandler, 147 onMouseLeave: eventHandler, 148 onKeyDown: eventHandler, 125 149 promptMessage: "dd.mm.yy", 126 150 rangeMessage: "Enter a date in the year range 2004-2006.", -
dijit/trunk/_Widget.js
r14145 r14473 4 4 dojo.require( "dijit._base" ); 5 5 //>>excludeEnd("dijitBaseExclude"); 6 7 dojo.connect(dojo, "connect", 8 function(/*Widget*/ widget, /*String*/ event){ 9 if(widget && dojo.isFunction(widget._onConnect)){ 10 widget._onConnect.apply(widget, arguments); 11 } 12 }); 13 14 dijit._connectOnUseEventHandler = function(/*Event*/ event){}; 6 15 7 16 dojo.declare("dijit._Widget", null, { … … 82 91 // on the widget's dom, at the "domNode" attach point, by default. 83 92 // Other node references can be specified as properties of 'this' 84 attributeMap: {id:"", dir:"", lang:"", "class":"", style:"", title:""}, // TODO: add on* handlers? 93 attributeMap: {id:"", dir:"", lang:"", "class":"", style:"", title:"", 94 onClick: "", 95 onDblClick: "", 96 onKeyDown: "", 97 onKeyPress: "", 98 onKeyUp: "", 99 onMouseMove: "", 100 onMouseDown: "", 101 onMouseOut: "", 102 onMouseOver: "", 103 onMouseLeave: "", 104 onMouseEnter: "", 105 onMouseUp: ""}, 106 107 onClick: dijit._connectOnUseEventHandler, 108 /*===== 109 onClick: function(event){ 110 // summary: 111 // Connect to this function to receive notifications of mouse click events. 112 // event: mouse Event 113 }, 114 =====*/ 115 onDblClick: dijit._connectOnUseEventHandler, 116 /*===== 117 onDblClick: function(event){ 118 // summary: 119 // Connect to this function to receive notifications of mouse double click events. 120 // event: mouse Event 121 }, 122 =====*/ 123 onKeyDown: dijit._connectOnUseEventHandler, 124 /*===== 125 onKeyDown: function(event){ 126 // summary: 127 // Connect to this function to receive notifications of keys being pressed down. 128 // event: key Event 129 }, 130 =====*/ 131 onKeyPress: dijit._connectOnUseEventHandler, 132 /*===== 133 onKeyPress: function(event){ 134 // summary: 135 // Connect to this function to receive notifications of printable keys being typed. 136 // event: key Event 137 }, 138 =====*/ 139 onKeyUp: dijit._connectOnUseEventHandler, 140 /*===== 141 onKeyUp: function(event){ 142 // summary: 143 // Connect to this function to receive notifications of keys being released. 144 // event: key Event 145 }, 146 =====*/ 147 onMouseDown: dijit._connectOnUseEventHandler, 148 /*===== 149 onMouseDown: function(event){ 150 // summary: 151 // Connect to this function to receive notifications of when the mouse button is pressed down. 152 // event: mouse Event 153 }, 154 =====*/ 155 onMouseMove: dijit._connectOnUseEventHandler, 156 /*===== 157 onMouseMove: function(event){ 158 // summary: 159 // Connect to this function to receive notifications of when the mouse moves over nodes contained within this widget. 160 // event: mouse Event 161 }, 162 =====*/ 163 onMouseOut: dijit._connectOnUseEventHandler, 164 /*===== 165 onMouseOut: function(event){ 166 // summary: 167 // Connect to this function to receive notifications of when the mouse moves off of nodes contained within this widget. 168 // event: mouse Event 169 }, 170 =====*/ 171 onMouseOver: dijit._connectOnUseEventHandler, 172 /*===== 173 onMouseOver: function(event){ 174 // summary: 175 // Connect to this function to receive notifications of when the mouse moves onto nodes contained within this widget. 176 // event: mouse Event 177 }, 178 =====*/ 179 onMouseLeave: dijit._connectOnUseEventHandler, 180 /*===== 181 onMouseLeave: function(event){ 182 // summary: 183 // Connect to this function to receive notifications of when the mouse moves off of this widget. 184 // event: mouse Event 185 }, 186 =====*/ 187 onMouseEnter: dijit._connectOnUseEventHandler, 188 /*===== 189 onMouseEnter: function(event){ 190 // summary: 191 // Connect to this function to receive notifications of when the mouse moves onto this widget. 192 // event: mouse Event 193 }, 194 =====*/ 195 onMouseUp: dijit._connectOnUseEventHandler, 196 /*===== 197 onMouseUp: function(event){ 198 // summary: 199 // Connect to this function to receive notifications of when the mouse button is released. 200 // event: mouse Event 201 }, 202 =====*/ 85 203 86 204 // Constants used in templates … … 92 210 postscript: function(/*Object?*/params, /*DomNode|String*/srcNodeRef){ 93 211 this.create(params, srcNodeRef); 212 }, 213 214 constructor: function(){ 215 this._onUseEvents = []; // list of events that needs to be connected on first use 216 for(var attr in this.attributeMap){ 217 if(this[attr] === dijit._connectOnUseEventHandler){ 218 this._onUseEvents[attr] = true; 219 } 220 } 94 221 }, 95 222 … … 158 285 for(var attr in this.attributeMap){ 159 286 var value = this[attr]; 160 if( typeof value != "object"&& ((value !== "" && value !== false) || (params && params[attr]))){287 if(value !== dijit._connectOnUseEventHandler && (typeof value != "undefined") && (typeof value != "object") && ((value !== "" && value !== false) || (params && params[attr]))){ 161 288 this.setAttribute(attr, value); 162 289 } … … 319 446 _onBlur: function(){ 320 447 this.onBlur(); 448 }, 449 450 _onConnect: function(/*Widget*/ widget, /*String*/ event){ 451 if(widget && (typeof widget == "object") && widget._onUseEvents && widget._onUseEvents[event]){ 452 widget.setAttribute(event, widget[event]); 453 } 321 454 }, 322 455 … … 345 478 break; 346 479 default: 347 if(/^on[A-Z]/.test(attr)){ // eg. onSubmit needs to be onsubmit 480 if(dojo.isFunction(value)){ // functions execute in the context of the widget 481 value = dojo.hitch(this, value); 482 } 483 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 } 348 487 attr = attr.toLowerCase(); 349 }350 if(typeof value == "function"){ // functions execute in the context of the widget351 value = dojo.hitch(this, value);352 488 } 353 489 dojo.attr(mapNode, attr, value);