Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / layout / GridContainerLite.js @ 11

History | View | Annotate | Download (10.8 KB)

1
/*
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["dojox.layout.GridContainerLite"]){
9
dojo._hasResource["dojox.layout.GridContainerLite"]=true;
10
dojo.provide("dojox.layout.GridContainerLite");
11
dojo.require("dijit._Templated");
12
dojo.require("dijit.layout._LayoutWidget");
13
dojo.require("dojox.mdnd.AreaManager");
14
dojo.require("dojox.mdnd.DropIndicator");
15
dojo.require("dojox.mdnd.dropMode.OverDropMode");
16
dojo.require("dojox.mdnd.AutoScroll");
17
dojo.declare("dojox.layout.GridContainerLite",[dijit.layout._LayoutWidget,dijit._Templated],{autoRefresh:true,templateString:dojo.cache("dojox.layout","resources/GridContainer.html","<div id=\"${id}\" class=\"gridContainer\" dojoAttachPoint=\"containerNode\" tabIndex=\"0\" dojoAttachEvent=\"onkeypress:_selectFocus\">\n\t<div dojoAttachPoint=\"gridContainerDiv\">\n\t\t<table class=\"gridContainerTable\" dojoAttachPoint=\"gridContainerTable\" cellspacing=\"0\" cellpadding=\"0\">\n\t\t\t<tbody>\n\t\t\t\t<tr dojoAttachPoint=\"gridNode\" >\n\t\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t</tbody>\n\t\t</table>\n\t</div>\n</div>\n"),dragHandleClass:"dojoxDragHandle",nbZones:1,doLayout:true,isAutoOrganized:true,acceptTypes:[],colWidths:"",constructor:function(_1,_2){
18
this.acceptTypes=(_1||{}).acceptTypes||["text"];
19
this._disabled=true;
20
},postCreate:function(){
21
this.inherited(arguments);
22
this._grid=[];
23
this._createCells();
24
this.subscribe("/dojox/mdnd/drop","resizeChildAfterDrop");
25
this.subscribe("/dojox/mdnd/drag/start","resizeChildAfterDragStart");
26
this._dragManager=dojox.mdnd.areaManager();
27
this._dragManager.autoRefresh=this.autoRefresh;
28
this._dragManager.dragHandleClass=this.dragHandleClass;
29
if(this.doLayout){
30
this._border={"h":(dojo.isIE)?dojo._getBorderExtents(this.gridContainerTable).h:0,"w":(dojo.isIE==6)?1:0};
31
}else{
32
dojo.style(this.domNode,"overflowY","hidden");
33
dojo.style(this.gridContainerTable,"height","auto");
34
}
35
this.inherited(arguments);
36
},startup:function(){
37
if(this._started){
38
return;
39
}
40
if(this.isAutoOrganized){
41
this._organizeChildren();
42
}else{
43
this._organizeChildrenManually();
44
}
45
dojo.forEach(this.getChildren(),function(_3){
46
_3.startup();
47
});
48
if(this._isShown()){
49
this.enableDnd();
50
}
51
this.inherited(arguments);
52
},resizeChildAfterDrop:function(_4,_5,_6){
53
if(this._disabled){
54
return false;
55
}
56
if(dijit.getEnclosingWidget(_5.node)==this){
57
var _7=dijit.byNode(_4);
58
if(_7.resize&&dojo.isFunction(_7.resize)){
59
_7.resize();
60
}
61
if(this.doLayout){
62
var _8=this._contentBox.h,_9=dojo.contentBox(this.gridContainerDiv).h;
63
if(_9>=_8){
64
dojo.style(this.gridContainerTable,"height",(_8-this._border.h)+"px");
65
}
66
}
67
return true;
68
}
69
return false;
70
},resizeChildAfterDragStart:function(_a,_b,_c){
71
if(this._disabled){
72
return false;
73
}
74
if(dijit.getEnclosingWidget(_b.node)==this){
75
this._draggedNode=_a;
76
if(this.doLayout){
77
dojo.marginBox(this.gridContainerTable,{"h":dojo.contentBox(this.gridContainerDiv).h-this._border.h});
78
}
79
return true;
80
}
81
return false;
82
},getChildren:function(){
83
var _d=[];
84
dojo.forEach(this._grid,function(_e){
85
_d=_d.concat(dojo.query("> [widgetId]",_e.node).map(dijit.byNode));
86
});
87
return _d;
88
},_isShown:function(){
89
if("open" in this){
90
return this.open;
91
}else{
92
var _f=this.domNode;
93
return (_f.style.display!="none")&&(_f.style.visibility!="hidden")&&!dojo.hasClass(_f,"dijitHidden");
94
}
95
},layout:function(){
96
if(this.doLayout){
97
var _10=this._contentBox;
98
dojo.marginBox(this.gridContainerTable,{"h":_10.h-this._border.h});
99
dojo.contentBox(this.domNode,{"w":_10.w-this._border.w});
100
}
101
dojo.forEach(this.getChildren(),function(_11){
102
if(_11.resize&&dojo.isFunction(_11.resize)){
103
_11.resize();
104
}
105
});
106
},onShow:function(){
107
if(this._disabled){
108
this.enableDnd();
109
}
110
},onHide:function(){
111
if(!this._disabled){
112
this.disableDnd();
113
}
114
},_createCells:function(){
115
if(this.nbZones===0){
116
this.nbZones=1;
117
}
118
var _12=this.acceptTypes.join(","),i=0;
119
var _13=this.colWidths||[];
120
var _14=[];
121
var _15;
122
var _16=0;
123
for(i=0;i<this.nbZones;i++){
124
if(_14.length<_13.length){
125
_16+=_13[i];
126
_14.push(_13[i]);
127
}else{
128
if(!_15){
129
_15=(100-_16)/(this.nbZones-i);
130
}
131
_14.push(_15);
132
}
133
}
134
i=0;
135
while(i<this.nbZones){
136
this._grid.push({"node":dojo.create("td",{"class":"gridContainerZone","accept":_12,"id":this.id+"_dz"+i,"style":{"width":_14[i]+"%"}},this.gridNode)});
137
i++;
138
}
139
},enableDnd:function(){
140
var m=this._dragManager;
141
dojo.forEach(this._grid,function(_17){
142
m.registerByNode(_17.node);
143
});
144
m._dropMode.updateAreas(m._areaList);
145
this._disabled=false;
146
},disableDnd:function(){
147
var m=this._dragManager;
148
dojo.forEach(this._grid,function(_18){
149
m.unregister(_18.node);
150
});
151
m._dropMode.updateAreas(m._areaList);
152
this._disabled=true;
153
},_organizeChildren:function(){
154
var _19=dojox.layout.GridContainerLite.superclass.getChildren.call(this);
155
var _1a=this.nbZones,_1b=Math.floor(_19.length/_1a),mod=_19.length%_1a,i=0;
156
for(var z=0;z<_1a;z++){
157
for(var r=0;r<_1b;r++){
158
this._insertChild(_19[i],z);
159
i++;
160
}
161
if(mod>0){
162
try{
163
this._insertChild(_19[i],z);
164
i++;
165
}
166
catch(e){
167
console.error("Unable to insert child in GridContainer",e);
168
}
169
mod--;
170
}else{
171
if(_1b===0){
172
break;
173
}
174
}
175
}
176
},_organizeChildrenManually:function(){
177
var _1c=dojox.layout.GridContainerLite.superclass.getChildren.call(this),_1d=_1c.length,_1e;
178
for(var i=0;i<_1d;i++){
179
_1e=_1c[i];
180
try{
181
this._insertChild(_1e,_1e.column-1);
182
}
183
catch(e){
184
console.error("Unable to insert child in GridContainer",e);
185
}
186
}
187
},_insertChild:function(_1f,_20,p){
188
var _21=this._grid[_20].node,_22=_21.childNodes.length;
189
if(typeof (p)==undefined||p>_22){
190
p=_22;
191
}
192
if(this._disabled){
193
dojo.place(_1f.domNode,_21,p);
194
dojo.attr(_1f.domNode,"tabIndex","0");
195
}else{
196
if(!_1f.dragRestriction){
197
this._dragManager.addDragItem(_21,_1f.domNode,p,true);
198
}else{
199
dojo.place(_1f.domNode,_21,p);
200
dojo.attr(_1f.domNode,"tabIndex","0");
201
}
202
}
203
return _1f;
204
},removeChild:function(_23){
205
if(this._disabled){
206
this.inherited(arguments);
207
}else{
208
this._dragManager.removeDragItem(_23.domNode.parentNode,_23.domNode);
209
}
210
},addService:function(_24,_25,p){
211
dojo.deprecated("addService is deprecated.","Please use  instead.","Future");
212
this.addChild(_24,_25,p);
213
},addChild:function(_26,_27,p){
214
_26.domNode.id=_26.id;
215
dojox.layout.GridContainerLite.superclass.addChild.call(this,_26,0);
216
if(_27<0||_27==undefined){
217
_27=0;
218
}
219
if(p<=0){
220
p=0;
221
}
222
try{
223
return this._insertChild(_26,_27,p);
224
}
225
catch(e){
226
console.error("Unable to insert child in GridContainer",e);
227
}
228
return null;
229
},_setColWidthsAttr:function(_28){
230
this.colWidths=dojo.isString(_28)?_28.split(","):(dojo.isArray(_28)?_28:[_28]);
231
if(this._started){
232
this._updateColumnsWidth();
233
}
234
},_updateColumnsWidth:function(_29){
235
var _2a=this._grid.length;
236
var _2b=this.colWidths||[];
237
var _2c=[];
238
var _2d;
239
var _2e=0;
240
var i;
241
for(i=0;i<_2a;i++){
242
if(_2c.length<_2b.length){
243
_2e+=_2b[i]*1;
244
_2c.push(_2b[i]);
245
}else{
246
if(!_2d){
247
_2d=(100-_2e)/(this.nbZones-i);
248
if(_2d<0){
249
_2d=100/this.nbZones;
250
}
251
}
252
_2c.push(_2d);
253
_2e+=_2d*1;
254
}
255
}
256
if(_2e>100){
257
var _2f=100/_2e;
258
for(i=0;i<_2c.length;i++){
259
_2c[i]*=_2f;
260
}
261
}
262
for(i=0;i<_2a;i++){
263
this._grid[i].node.style.width=_2c[i]+"%";
264
}
265
},_selectFocus:function(_30){
266
if(this._disabled){
267
return;
268
}
269
var key=_30.keyCode,k=dojo.keys,_31=null,_32=dijit.getFocus(),_33=_32.node,m=this._dragManager,_34,i,j,r,_35,_36,_37;
270
if(_33==this.containerNode){
271
_36=this.gridNode.childNodes;
272
switch(key){
273
case k.DOWN_ARROW:
274
case k.RIGHT_ARROW:
275
_34=false;
276
for(i=0;i<_36.length;i++){
277
_35=_36[i].childNodes;
278
for(j=0;j<_35.length;j++){
279
_31=_35[j];
280
if(_31!=null&&_31.style.display!="none"){
281
dijit.focus(_31);
282
dojo.stopEvent(_30);
283
_34=true;
284
break;
285
}
286
}
287
if(_34){
288
break;
289
}
290
}
291
break;
292
case k.UP_ARROW:
293
case k.LEFT_ARROW:
294
_36=this.gridNode.childNodes;
295
_34=false;
296
for(i=_36.length-1;i>=0;i--){
297
_35=_36[i].childNodes;
298
for(j=_35.length;j>=0;j--){
299
_31=_35[j];
300
if(_31!=null&&_31.style.display!="none"){
301
dijit.focus(_31);
302
dojo.stopEvent(_30);
303
_34=true;
304
break;
305
}
306
}
307
if(_34){
308
break;
309
}
310
}
311
break;
312
}
313
}else{
314
if(_33.parentNode.parentNode==this.gridNode){
315
var _38=(key==k.UP_ARROW||key==k.LEFT_ARROW)?"lastChild":"firstChild";
316
var pos=(key==k.UP_ARROW||key==k.LEFT_ARROW)?"previousSibling":"nextSibling";
317
switch(key){
318
case k.UP_ARROW:
319
case k.DOWN_ARROW:
320
dojo.stopEvent(_30);
321
_34=false;
322
var _39=_33;
323
while(!_34){
324
_35=_39.parentNode.childNodes;
325
var num=0;
326
for(i=0;i<_35.length;i++){
327
if(_35[i].style.display!="none"){
328
num++;
329
}
330
if(num>1){
331
break;
332
}
333
}
334
if(num==1){
335
return;
336
}
337
if(_39[pos]==null){
338
_31=_39.parentNode[_38];
339
}else{
340
_31=_39[pos];
341
}
342
if(_31.style.display==="none"){
343
_39=_31;
344
}else{
345
_34=true;
346
}
347
}
348
if(_30.shiftKey){
349
var _3a=_33.parentNode;
350
for(i=0;i<this.gridNode.childNodes.length;i++){
351
if(_3a==this.gridNode.childNodes[i]){
352
break;
353
}
354
}
355
_35=this.gridNode.childNodes[i].childNodes;
356
for(j=0;j<_35.length;j++){
357
if(_31==_35[j]){
358
break;
359
}
360
}
361
if(dojo.isMoz||dojo.isWebKit){
362
i--;
363
}
364
_37=dijit.byNode(_33);
365
if(!_37.dragRestriction){
366
r=m.removeDragItem(_3a,_33);
367
this.addChild(_37,i,j);
368
dojo.attr(_33,"tabIndex","0");
369
dijit.focus(_33);
370
}else{
371
dojo.publish("/dojox/layout/gridContainer/moveRestriction",[this]);
372
}
373
}else{
374
dijit.focus(_31);
375
}
376
break;
377
case k.RIGHT_ARROW:
378
case k.LEFT_ARROW:
379
dojo.stopEvent(_30);
380
if(_30.shiftKey){
381
var z=0;
382
if(_33.parentNode[pos]==null){
383
if(dojo.isIE&&key==k.LEFT_ARROW){
384
z=this.gridNode.childNodes.length-1;
385
}
386
}else{
387
if(_33.parentNode[pos].nodeType==3){
388
z=this.gridNode.childNodes.length-2;
389
}else{
390
for(i=0;i<this.gridNode.childNodes.length;i++){
391
if(_33.parentNode[pos]==this.gridNode.childNodes[i]){
392
break;
393
}
394
z++;
395
}
396
if(dojo.isMoz||dojo.isWebKit){
397
z--;
398
}
399
}
400
}
401
_37=dijit.byNode(_33);
402
var _3b=_33.getAttribute("dndtype");
403
if(_3b==null){
404
if(_37&&_37.dndType){
405
_3b=_37.dndType.split(/\s*,\s*/);
406
}else{
407
_3b=["text"];
408
}
409
}else{
410
_3b=_3b.split(/\s*,\s*/);
411
}
412
var _3c=false;
413
for(i=0;i<this.acceptTypes.length;i++){
414
for(j=0;j<_3b.length;j++){
415
if(_3b[j]==this.acceptTypes[i]){
416
_3c=true;
417
break;
418
}
419
}
420
}
421
if(_3c&&!_37.dragRestriction){
422
var _3d=_33.parentNode,_3e=0;
423
if(k.LEFT_ARROW==key){
424
var t=z;
425
if(dojo.isMoz||dojo.isWebKit){
426
t=z+1;
427
}
428
_3e=this.gridNode.childNodes[t].childNodes.length;
429
}
430
r=m.removeDragItem(_3d,_33);
431
this.addChild(_37,z,_3e);
432
dojo.attr(r,"tabIndex","0");
433
dijit.focus(r);
434
}else{
435
dojo.publish("/dojox/layout/gridContainer/moveRestriction",[this]);
436
}
437
}else{
438
var _3f=_33.parentNode;
439
while(_31===null){
440
if(_3f[pos]!==null&&_3f[pos].nodeType!==3){
441
_3f=_3f[pos];
442
}else{
443
if(pos==="previousSibling"){
444
_3f=_3f.parentNode.childNodes[_3f.parentNode.childNodes.length-1];
445
}else{
446
_3f=(dojo.isIE)?_3f.parentNode.childNodes[0]:_3f.parentNode.childNodes[1];
447
}
448
}
449
_31=_3f[_38];
450
if(_31&&_31.style.display=="none"){
451
_35=_31.parentNode.childNodes;
452
var _40=null;
453
if(pos=="previousSibling"){
454
for(i=_35.length-1;i>=0;i--){
455
if(_35[i].style.display!="none"){
456
_40=_35[i];
457
break;
458
}
459
}
460
}else{
461
for(i=0;i<_35.length;i++){
462
if(_35[i].style.display!="none"){
463
_40=_35[i];
464
break;
465
}
466
}
467
}
468
if(!_40){
469
_33=_31;
470
_3f=_33.parentNode;
471
_31=null;
472
}else{
473
_31=_40;
474
}
475
}
476
}
477
dijit.focus(_31);
478
}
479
break;
480
}
481
}
482
}
483
},destroy:function(){
484
var m=this._dragManager;
485
dojo.forEach(this._grid,function(_41){
486
m.unregister(_41.node);
487
});
488
this.inherited(arguments);
489
}});
490
dojo.extend(dijit._Widget,{column:"1",dragRestriction:false});
491
}