2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit._Widget"]){
9 dojo
._hasResource
["dijit._Widget"]=true;
10 dojo
.provide("dijit._Widget");
11 dojo
.require("dijit._base");
12 dojo
.connect(dojo
,"_connect",function(_1
,_2
){
13 if(_1
&&dojo
.isFunction(_1
._onConnect
)){
17 dijit
._connectOnUseEventHandler=function(_3
){
19 dijit
._lastKeyDownNode
=null;
23 dijit
._lastKeyDownNode
=_5
.srcElement
;
25 dojo
.doc
.attachEvent("onkeydown",_4
);
26 dojo
.addOnWindowUnload(function(){
27 dojo
.doc
.detachEvent("onkeydown",_4
);
31 dojo
.doc
.addEventListener("keydown",function(_6
){
32 dijit
._lastKeyDownNode
=_6
.target
;
36 var _7
={},_8=function(_9
){
37 var dc
=_9
.declaredClass
;
39 var r
=[],_a
,_b
=_9
.constructor.prototype;
41 if(dojo
.isFunction(_b
[_c
])&&(_a
=_c
.match(/^_set([a-zA-Z]*)Attr$/))&&_a
[1]){
42 r
.push(_a
[1].charAt(0).toLowerCase()+_a
[1].substr(1));
49 dojo
.declare("dijit._Widget",null,{id
:"",lang
:"",dir
:"","class":"",style
:"",title
:"",tooltip
:"",baseClass
:"",srcNodeRef
:null,domNode
:null,containerNode
:null,attributeMap
:{id
:"",dir
:"",lang
:"","class":"",style
:"",title
:""},_deferredConnects
:{onClick
:"",onDblClick
:"",onKeyDown
:"",onKeyPress
:"",onKeyUp
:"",onMouseMove
:"",onMouseDown
:"",onMouseOut
:"",onMouseOver
:"",onMouseLeave
:"",onMouseEnter
:"",onMouseUp
:""},onClick
:dijit
._connectOnUseEventHandler
,onDblClick
:dijit
._connectOnUseEventHandler
,onKeyDown
:dijit
._connectOnUseEventHandler
,onKeyPress
:dijit
._connectOnUseEventHandler
,onKeyUp
:dijit
._connectOnUseEventHandler
,onMouseDown
:dijit
._connectOnUseEventHandler
,onMouseMove
:dijit
._connectOnUseEventHandler
,onMouseOut
:dijit
._connectOnUseEventHandler
,onMouseOver
:dijit
._connectOnUseEventHandler
,onMouseLeave
:dijit
._connectOnUseEventHandler
,onMouseEnter
:dijit
._connectOnUseEventHandler
,onMouseUp
:dijit
._connectOnUseEventHandler
,_blankGif
:(dojo
.config
.blankGif
||dojo
.moduleUrl("dojo","resources/blank.gif")).toString(),postscript:function(_d
,_e
){
51 },create:function(_f
,_10
){
52 this.srcNodeRef
=dojo
.byId(_10
);
55 this._deferredConnects
=dojo
.clone(this._deferredConnects
);
56 for(var _11
in this.attributeMap
){
57 delete this._deferredConnects
[_11
];
59 for(_11
in this._deferredConnects
){
60 if(this[_11
]!==dijit
._connectOnUseEventHandler
){
61 delete this._deferredConnects
[_11
];
64 if(this.srcNodeRef
&&(typeof this.srcNodeRef
.id
=="string")){
65 this.id
=this.srcNodeRef
.id
;
71 this.postMixInProperties();
73 this.id
=dijit
.getUniqueId(this.declaredClass
.replace(/\./g,"_"));
75 dijit
.registry
.add(this);
76 this.buildRendering();
78 this._applyAttributes();
79 var _12
=this.srcNodeRef
;
80 if(_12
&&_12
.parentNode
){
81 _12
.parentNode
.replaceChild(this.domNode
,_12
);
83 for(_11
in this.params
){
88 this.domNode
.setAttribute("widgetId",this.id
);
91 if(this.srcNodeRef
&&!this.srcNodeRef
.parentNode
){
92 delete this.srcNodeRef
;
95 },_applyAttributes:function(){
96 var _13=function(_14
,_15
){
97 if((_15
.params
&&_14
in _15
.params
)||_15
[_14
]){
98 _15
.set(_14
,_15
[_14
]);
101 for(var _16
in this.attributeMap
){
104 dojo
.forEach(_8(this),function(a
){
105 if(!(a
in this.attributeMap
)){
109 },postMixInProperties:function(){
110 },buildRendering:function(){
111 this.domNode
=this.srcNodeRef
||dojo
.create("div");
112 },postCreate:function(){
114 var _17
=this.baseClass
.split(" ");
115 if(!this.isLeftToRight()){
116 _17
=_17
.concat(dojo
.map(_17
,function(_18
){
120 dojo
.addClass(this.domNode
,_17
);
122 },startup:function(){
124 },destroyRecursive:function(_19
){
125 this._beingDestroyed
=true;
126 this.destroyDescendants(_19
);
128 },destroy:function(_1a
){
129 this._beingDestroyed
=true;
131 var d
=dojo
,dfe
=d
.forEach
,dun
=d
.unsubscribe
;
132 dfe(this._connects
,function(_1b
){
133 dfe(_1b
,d
.disconnect
);
135 dfe(this._subscribes
,function(_1c
){
138 dfe(this._supportingWidgets
||[],function(w
){
139 if(w
.destroyRecursive
){
140 w
.destroyRecursive();
147 this.destroyRendering(_1a
);
148 dijit
.registry
.remove(this.id
);
149 this._destroyed
=true;
150 },destroyRendering:function(_1d
){
152 this.bgIframe
.destroy(_1d
);
153 delete this.bgIframe
;
157 dojo
.removeAttr(this.domNode
,"widgetId");
159 dojo
.destroy(this.domNode
);
165 dojo
.destroy(this.srcNodeRef
);
167 delete this.srcNodeRef
;
169 },destroyDescendants:function(_1e
){
170 dojo
.forEach(this.getChildren(),function(_1f
){
171 if(_1f
.destroyRecursive
){
172 _1f
.destroyRecursive(_1e
);
175 },uninitialize:function(){
177 },onFocus:function(){
179 },_onFocus:function(e
){
181 },_onBlur:function(){
183 },_onConnect:function(_20
){
184 if(_20
in this._deferredConnects
){
185 var _21
=this[this._deferredConnects
[_20
]||"domNode"];
186 this.connect(_21
,_20
.toLowerCase(),_20
);
187 delete this._deferredConnects
[_20
];
189 },_setClassAttr:function(_22
){
190 var _23
=this[this.attributeMap
["class"]||"domNode"];
191 dojo
.removeClass(_23
,this["class"]);
193 dojo
.addClass(_23
,_22
);
194 },_setStyleAttr:function(_24
){
195 var _25
=this[this.attributeMap
.style
||"domNode"];
196 if(dojo
.isObject(_24
)){
199 if(_25
.style
.cssText
){
200 _25
.style
.cssText
+="; "+_24
;
202 _25
.style
.cssText
=_24
;
206 },setAttribute:function(_26
,_27
){
207 dojo
.deprecated(this.declaredClass
+"::setAttribute(attr, value) is deprecated. Use set() instead.","","2.0");
209 },_attrToDom:function(_28
,_29
){
210 var _2a
=this.attributeMap
[_28
];
211 dojo
.forEach(dojo
.isArray(_2a
)?_2a
:[_2a
],function(_2b
){
212 var _2c
=this[_2b
.node
||_2b
||"domNode"];
213 var _2d
=_2b
.type
||"attribute";
216 if(dojo
.isFunction(_29
)){
217 _29
=dojo
.hitch(this,_29
);
219 var _2e
=_2b
.attribute
?_2b
.attribute
:(/^on[A-Z][a-zA-Z]*$/.test(_28
)?_28
.toLowerCase():_28
);
220 dojo
.attr(_2c
,_2e
,_29
);
224 _2c
.appendChild(dojo
.doc
.createTextNode(_29
));
230 dojo
.removeClass(_2c
,this[_28
]);
231 dojo
.addClass(_2c
,_29
);
236 },attr:function(_2f
,_30
){
237 if(dojo
.config
.isDebug
){
238 var _31
=arguments
.callee
._ach
||(arguments
.callee
._ach
={}),_32
=(arguments
.callee
.caller
||"unknown caller").toString();
240 dojo
.deprecated(this.declaredClass
+"::attr() is deprecated. Use get() or set() instead, called from "+_32
,"","2.0");
244 var _33
=arguments
.length
;
245 if(_33
>=2||typeof _2f
==="object"){
246 return this.set.apply(this,arguments
);
248 return this.get(_2f
);
251 var _35
=this._getAttrNames(_34
);
252 return this[_35
.g
]?this[_35
.g
]():this[_34
];
253 },set:function(_36
,_37
){
254 if(typeof _36
==="object"){
260 var _38
=this._getAttrNames(_36
);
262 var _39
=this[_38
.s
].apply(this,Array
.prototype.slice
.call(arguments
,1));
264 if(_36
in this.attributeMap
){
265 this._attrToDom(_36
,_37
);
271 },_attrPairNames
:{},_getAttrNames:function(_3b
){
272 var apn
=this._attrPairNames
;
276 var uc
=_3b
.charAt(0).toUpperCase()+_3b
.substr(1);
277 return (apn
[_3b
]={n
:_3b
+"Node",s
:"_set"+uc
+"Attr",g
:"_get"+uc
+"Attr"});
278 },toString:function(){
279 return "[Widget "+this.declaredClass
+", "+(this.id
||"NO ID")+"]";
280 },getDescendants:function(){
281 return this.containerNode
?dojo
.query("[widgetId]",this.containerNode
).map(dijit
.byNode
):[];
282 },getChildren:function(){
283 return this.containerNode
?dijit
.findWidgets(this.containerNode
):[];
284 },nodesWithKeyClick
:["input","button"],connect:function(obj
,_3c
,_3d
){
285 var d
=dojo
,dc
=d
._connect
,_3e
=[];
286 if(_3c
=="ondijitclick"){
287 if(dojo
.indexOf(this.nodesWithKeyClick
,obj
.nodeName
.toLowerCase())==-1){
288 var m
=d
.hitch(this,_3d
);
289 _3e
.push(dc(obj
,"onkeydown",this,function(e
){
290 if((e
.keyCode
==d
.keys
.ENTER
||e
.keyCode
==d
.keys
.SPACE
)&&!e
.ctrlKey
&&!e
.shiftKey
&&!e
.altKey
&&!e
.metaKey
){
291 dijit
._lastKeyDownNode
=e
.target
;
294 }),dc(obj
,"onkeyup",this,function(e
){
295 if((e
.keyCode
==d
.keys
.ENTER
||e
.keyCode
==d
.keys
.SPACE
)&&e
.target
===dijit
._lastKeyDownNode
&&!e
.ctrlKey
&&!e
.shiftKey
&&!e
.altKey
&&!e
.metaKey
){
296 dijit
._lastKeyDownNode
=null;
303 _3e
.push(dc(obj
,_3c
,this,_3d
));
304 this._connects
.push(_3e
);
306 },disconnect:function(_3f
){
307 for(var i
=0;i
<this._connects
.length
;i
++){
308 if(this._connects
[i
]==_3f
){
309 dojo
.forEach(_3f
,dojo
.disconnect
);
310 this._connects
.splice(i
,1);
314 },subscribe:function(_40
,_41
){
315 var d
=dojo
,_42
=d
.subscribe(_40
,this,_41
);
316 this._subscribes
.push(_42
);
318 },unsubscribe:function(_43
){
319 for(var i
=0;i
<this._subscribes
.length
;i
++){
320 if(this._subscribes
[i
]==_43
){
321 dojo
.unsubscribe(_43
);
322 this._subscribes
.splice(i
,1);
326 },isLeftToRight:function(){
327 return this.dir
?(this.dir
=="ltr"):dojo
._isBodyLtr();
328 },isFocusable:function(){
329 return this.focus
&&(dojo
.style(this.domNode
,"display")!="none");
330 },placeAt:function(_44
,_45
){
331 if(_44
.declaredClass
&&_44
.addChild
){
332 _44
.addChild(this,_45
);
334 dojo
.place(this.domNode
,_44
,_45
);
337 },_onShow:function(){
341 },onClose:function(){