Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / _Widget.js @ 9

History | View | Annotate | Download (9.31 KB)

1 9 andrej.cim
/*
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
5
*/
6
7
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)){
14
_1._onConnect(_2);
15
}
16
});
17
dijit._connectOnUseEventHandler=function(_3){
18
};
19
dijit._lastKeyDownNode=null;
20
if(dojo.isIE){
21
(function(){
22
var _4=function(_5){
23
dijit._lastKeyDownNode=_5.srcElement;
24
};
25
dojo.doc.attachEvent("onkeydown",_4);
26
dojo.addOnWindowUnload(function(){
27
dojo.doc.detachEvent("onkeydown",_4);
28
});
29
})();
30
}else{
31
dojo.doc.addEventListener("keydown",function(_6){
32
dijit._lastKeyDownNode=_6.target;
33
},true);
34
}
35
(function(){
36
var _7={},_8=function(_9){
37
var dc=_9.declaredClass;
38
if(!_7[dc]){
39
var r=[],_a,_b=_9.constructor.prototype;
40
for(var _c in _b){
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));
43
}
44
}
45
_7[dc]=r;
46
}
47
return _7[dc]||[];
48
};
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){
50
this.create(_d,_e);
51
},create:function(_f,_10){
52
this.srcNodeRef=dojo.byId(_10);
53
this._connects=[];
54
this._subscribes=[];
55
this._deferredConnects=dojo.clone(this._deferredConnects);
56
for(var _11 in this.attributeMap){
57
delete this._deferredConnects[_11];
58
}
59
for(_11 in this._deferredConnects){
60
if(this[_11]!==dijit._connectOnUseEventHandler){
61
delete this._deferredConnects[_11];
62
}
63
}
64
if(this.srcNodeRef&&(typeof this.srcNodeRef.id=="string")){
65
this.id=this.srcNodeRef.id;
66
}
67
if(_f){
68
this.params=_f;
69
dojo.mixin(this,_f);
70
}
71
this.postMixInProperties();
72
if(!this.id){
73
this.id=dijit.getUniqueId(this.declaredClass.replace(/\./g,"_"));
74
}
75
dijit.registry.add(this);
76
this.buildRendering();
77
if(this.domNode){
78
this._applyAttributes();
79
var _12=this.srcNodeRef;
80
if(_12&&_12.parentNode){
81
_12.parentNode.replaceChild(this.domNode,_12);
82
}
83
for(_11 in this.params){
84
this._onConnect(_11);
85
}
86
}
87
if(this.domNode){
88
this.domNode.setAttribute("widgetId",this.id);
89
}
90
this.postCreate();
91
if(this.srcNodeRef&&!this.srcNodeRef.parentNode){
92
delete this.srcNodeRef;
93
}
94
this._created=true;
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]);
99
}
100
};
101
for(var _16 in this.attributeMap){
102
_13(_16,this);
103
}
104
dojo.forEach(_8(this),function(a){
105
if(!(a in this.attributeMap)){
106
_13(a,this);
107
}
108
},this);
109
},postMixInProperties:function(){
110
},buildRendering:function(){
111
this.domNode=this.srcNodeRef||dojo.create("div");
112
},postCreate:function(){
113
if(this.baseClass){
114
var _17=this.baseClass.split(" ");
115
if(!this.isLeftToRight()){
116
_17=_17.concat(dojo.map(_17,function(_18){
117
return _18+"Rtl";
118
}));
119
}
120
dojo.addClass(this.domNode,_17);
121
}
122
},startup:function(){
123
this._started=true;
124
},destroyRecursive:function(_19){
125
this._beingDestroyed=true;
126
this.destroyDescendants(_19);
127
this.destroy(_19);
128
},destroy:function(_1a){
129
this._beingDestroyed=true;
130
this.uninitialize();
131
var d=dojo,dfe=d.forEach,dun=d.unsubscribe;
132
dfe(this._connects,function(_1b){
133
dfe(_1b,d.disconnect);
134
});
135
dfe(this._subscribes,function(_1c){
136
dun(_1c);
137
});
138
dfe(this._supportingWidgets||[],function(w){
139
if(w.destroyRecursive){
140
w.destroyRecursive();
141
}else{
142
if(w.destroy){
143
w.destroy();
144
}
145
}
146
});
147
this.destroyRendering(_1a);
148
dijit.registry.remove(this.id);
149
this._destroyed=true;
150
},destroyRendering:function(_1d){
151
if(this.bgIframe){
152
this.bgIframe.destroy(_1d);
153
delete this.bgIframe;
154
}
155
if(this.domNode){
156
if(_1d){
157
dojo.removeAttr(this.domNode,"widgetId");
158
}else{
159
dojo.destroy(this.domNode);
160
}
161
delete this.domNode;
162
}
163
if(this.srcNodeRef){
164
if(!_1d){
165
dojo.destroy(this.srcNodeRef);
166
}
167
delete this.srcNodeRef;
168
}
169
},destroyDescendants:function(_1e){
170
dojo.forEach(this.getChildren(),function(_1f){
171
if(_1f.destroyRecursive){
172
_1f.destroyRecursive(_1e);
173
}
174
});
175
},uninitialize:function(){
176
return false;
177
},onFocus:function(){
178
},onBlur:function(){
179
},_onFocus:function(e){
180
this.onFocus();
181
},_onBlur:function(){
182
this.onBlur();
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];
188
}
189
},_setClassAttr:function(_22){
190
var _23=this[this.attributeMap["class"]||"domNode"];
191
dojo.removeClass(_23,this["class"]);
192
this["class"]=_22;
193
dojo.addClass(_23,_22);
194
},_setStyleAttr:function(_24){
195
var _25=this[this.attributeMap.style||"domNode"];
196
if(dojo.isObject(_24)){
197
dojo.style(_25,_24);
198
}else{
199
if(_25.style.cssText){
200
_25.style.cssText+="; "+_24;
201
}else{
202
_25.style.cssText=_24;
203
}
204
}
205
this.style=_24;
206
},setAttribute:function(_26,_27){
207
dojo.deprecated(this.declaredClass+"::setAttribute(attr, value) is deprecated. Use set() instead.","","2.0");
208
this.set(_26,_27);
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";
214
switch(_2d){
215
case "attribute":
216
if(dojo.isFunction(_29)){
217
_29=dojo.hitch(this,_29);
218
}
219
var _2e=_2b.attribute?_2b.attribute:(/^on[A-Z][a-zA-Z]*$/.test(_28)?_28.toLowerCase():_28);
220
dojo.attr(_2c,_2e,_29);
221
break;
222
case "innerText":
223
_2c.innerHTML="";
224
_2c.appendChild(dojo.doc.createTextNode(_29));
225
break;
226
case "innerHTML":
227
_2c.innerHTML=_29;
228
break;
229
case "class":
230
dojo.removeClass(_2c,this[_28]);
231
dojo.addClass(_2c,_29);
232
break;
233
}
234
},this);
235
this[_28]=_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();
239
if(!_31[_32]){
240
dojo.deprecated(this.declaredClass+"::attr() is deprecated. Use get() or set() instead, called from "+_32,"","2.0");
241
_31[_32]=true;
242
}
243
}
244
var _33=arguments.length;
245
if(_33>=2||typeof _2f==="object"){
246
return this.set.apply(this,arguments);
247
}else{
248
return this.get(_2f);
249
}
250
},get:function(_34){
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"){
255
for(var x in _36){
256
this.set(x,_36[x]);
257
}
258
return this;
259
}
260
var _38=this._getAttrNames(_36);
261
if(this[_38.s]){
262
var _39=this[_38.s].apply(this,Array.prototype.slice.call(arguments,1));
263
}else{
264
if(_36 in this.attributeMap){
265
this._attrToDom(_36,_37);
266
}
267
var _3a=this[_36];
268
this[_36]=_37;
269
}
270
return _39||this;
271
},_attrPairNames:{},_getAttrNames:function(_3b){
272
var apn=this._attrPairNames;
273
if(apn[_3b]){
274
return apn[_3b];
275
}
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;
292
e.preventDefault();
293
}
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;
297
return m(e);
298
}
299
}));
300
}
301
_3c="onclick";
302
}
303
_3e.push(dc(obj,_3c,this,_3d));
304
this._connects.push(_3e);
305
return _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);
311
return;
312
}
313
}
314
},subscribe:function(_40,_41){
315
var d=dojo,_42=d.subscribe(_40,this,_41);
316
this._subscribes.push(_42);
317
return _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);
323
return;
324
}
325
}
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);
333
}else{
334
dojo.place(this.domNode,_44,_45);
335
}
336
return this;
337
},_onShow:function(){
338
this.onShow();
339
},onShow:function(){
340
},onHide:function(){
341
},onClose:function(){
342
return true;
343
}});
344
})();
345
}