Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / widget / FisheyeList.js

History | View | Annotate | Download (12.6 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.widget.FisheyeList"]){
9
dojo._hasResource["dojox.widget.FisheyeList"]=true;
10
dojo.provide("dojox.widget.FisheyeList");
11
dojo.require("dijit._Widget");
12
dojo.require("dijit._Templated");
13
dojo.require("dijit._Container");
14
dojo.require("dijit._Contained");
15
dojo.declare("dojox.widget.FisheyeList",[dijit._Widget,dijit._Templated,dijit._Container],{constructor:function(){
16
this.pos={"x":-1,"y":-1};
17
this.timerScale=1;
18
},EDGE:{CENTER:0,LEFT:1,RIGHT:2,TOP:3,BOTTOM:4},templateString:"<div class=\"dojoxFisheyeListBar\" dojoAttachPoint=\"containerNode\"></div>",snarfChildDomOutput:true,itemWidth:40,itemHeight:40,itemMaxWidth:150,itemMaxHeight:150,imgNode:null,orientation:"horizontal",isFixed:false,conservativeTrigger:false,effectUnits:2,itemPadding:10,attachEdge:"center",labelEdge:"bottom",postCreate:function(){
19
var e=this.EDGE;
20
dojo.setSelectable(this.domNode,false);
21
var _1=this.isHorizontal=(this.orientation=="horizontal");
22
this.selectedNode=-1;
23
this.isOver=false;
24
this.hitX1=-1;
25
this.hitY1=-1;
26
this.hitX2=-1;
27
this.hitY2=-1;
28
this.anchorEdge=this._toEdge(this.attachEdge,e.CENTER);
29
this.labelEdge=this._toEdge(this.labelEdge,e.TOP);
30
if(this.labelEdge==e.CENTER){
31
this.labelEdge=e.TOP;
32
}
33
if(_1){
34
if(this.anchorEdge==e.LEFT){
35
this.anchorEdge=e.CENTER;
36
}
37
if(this.anchorEdge==e.RIGHT){
38
this.anchorEdge=e.CENTER;
39
}
40
if(this.labelEdge==e.LEFT){
41
this.labelEdge=e.TOP;
42
}
43
if(this.labelEdge==e.RIGHT){
44
this.labelEdge=e.TOP;
45
}
46
}else{
47
if(this.anchorEdge==e.TOP){
48
this.anchorEdge=e.CENTER;
49
}
50
if(this.anchorEdge==e.BOTTOM){
51
this.anchorEdge=e.CENTER;
52
}
53
if(this.labelEdge==e.TOP){
54
this.labelEdge=e.LEFT;
55
}
56
if(this.labelEdge==e.BOTTOM){
57
this.labelEdge=e.LEFT;
58
}
59
}
60
var _2=this.effectUnits;
61
this.proximityLeft=this.itemWidth*(_2-0.5);
62
this.proximityRight=this.itemWidth*(_2-0.5);
63
this.proximityTop=this.itemHeight*(_2-0.5);
64
this.proximityBottom=this.itemHeight*(_2-0.5);
65
if(this.anchorEdge==e.LEFT){
66
this.proximityLeft=0;
67
}
68
if(this.anchorEdge==e.RIGHT){
69
this.proximityRight=0;
70
}
71
if(this.anchorEdge==e.TOP){
72
this.proximityTop=0;
73
}
74
if(this.anchorEdge==e.BOTTOM){
75
this.proximityBottom=0;
76
}
77
if(this.anchorEdge==e.CENTER){
78
this.proximityLeft/=2;
79
this.proximityRight/=2;
80
this.proximityTop/=2;
81
this.proximityBottom/=2;
82
}
83
},startup:function(){
84
this.children=this.getChildren();
85
this._initializePositioning();
86
if(!this.conservativeTrigger){
87
this._onMouseMoveHandle=dojo.connect(document.documentElement,"onmousemove",this,"_onMouseMove");
88
}
89
if(this.isFixed){
90
this._onScrollHandle=dojo.connect(document,"onscroll",this,"_onScroll");
91
}
92
this._onMouseOutHandle=dojo.connect(document.documentElement,"onmouseout",this,"_onBodyOut");
93
this._addChildHandle=dojo.connect(this,"addChild",this,"_initializePositioning");
94
this._onResizeHandle=dojo.connect(window,"onresize",this,"_initializePositioning");
95
},_initializePositioning:function(){
96
this.itemCount=this.children.length;
97
this.barWidth=(this.isHorizontal?this.itemCount:1)*this.itemWidth;
98
this.barHeight=(this.isHorizontal?1:this.itemCount)*this.itemHeight;
99
this.totalWidth=this.proximityLeft+this.proximityRight+this.barWidth;
100
this.totalHeight=this.proximityTop+this.proximityBottom+this.barHeight;
101
for(var i=0;i<this.children.length;i++){
102
this.children[i].posX=this.itemWidth*(this.isHorizontal?i:0);
103
this.children[i].posY=this.itemHeight*(this.isHorizontal?0:i);
104
this.children[i].cenX=this.children[i].posX+(this.itemWidth/2);
105
this.children[i].cenY=this.children[i].posY+(this.itemHeight/2);
106
var _3=this.isHorizontal?this.itemWidth:this.itemHeight;
107
var r=this.effectUnits*_3;
108
var c=this.isHorizontal?this.children[i].cenX:this.children[i].cenY;
109
var _4=this.isHorizontal?this.proximityLeft:this.proximityTop;
110
var _5=this.isHorizontal?this.proximityRight:this.proximityBottom;
111
var _6=this.isHorizontal?this.barWidth:this.barHeight;
112
var _7=r;
113
var _8=r;
114
if(_7>c+_4){
115
_7=c+_4;
116
}
117
if(_8>(_6-c+_5)){
118
_8=_6-c+_5;
119
}
120
this.children[i].effectRangeLeft=_7/_3;
121
this.children[i].effectRangeRght=_8/_3;
122
}
123
this.domNode.style.width=this.barWidth+"px";
124
this.domNode.style.height=this.barHeight+"px";
125
for(var i=0;i<this.children.length;i++){
126
var _9=this.children[i];
127
var _a=_9.domNode;
128
_a.style.left=_9.posX+"px";
129
_a.style.top=_9.posY+"px";
130
_a.style.width=this.itemWidth+"px";
131
_a.style.height=this.itemHeight+"px";
132
_9.imgNode.style.left=this.itemPadding+"%";
133
_9.imgNode.style.top=this.itemPadding+"%";
134
_9.imgNode.style.width=(100-2*this.itemPadding)+"%";
135
_9.imgNode.style.height=(100-2*this.itemPadding)+"%";
136
}
137
this._calcHitGrid();
138
},_overElement:function(_b,e){
139
_b=dojo.byId(_b);
140
var _c={x:e.pageX,y:e.pageY};
141
var bb=dojo._getBorderBox(_b);
142
var _d=dojo.coords(_b,true);
143
var _e=_d.y;
144
var _f=_e+bb.h;
145
var _10=_d.x;
146
var _11=_10+bb.w;
147
return (_c.x>=_10&&_c.x<=_11&&_c.y>=_e&&_c.y<=_f);
148
},_onBodyOut:function(e){
149
if(this._overElement(dojo.body(),e)){
150
return;
151
}
152
this._setDormant(e);
153
},_setDormant:function(e){
154
if(!this.isOver){
155
return;
156
}
157
this.isOver=false;
158
if(this.conservativeTrigger){
159
dojo.disconnect(this._onMouseMoveHandle);
160
}
161
this._onGridMouseMove(-1,-1);
162
},_setActive:function(e){
163
if(this.isOver){
164
return;
165
}
166
this.isOver=true;
167
if(this.conservativeTrigger){
168
this._onMouseMoveHandle=dojo.connect(document.documentElement,"onmousemove",this,"_onMouseMove");
169
this.timerScale=0;
170
this._onMouseMove(e);
171
this._expandSlowly();
172
}
173
},_onMouseMove:function(e){
174
if((e.pageX>=this.hitX1)&&(e.pageX<=this.hitX2)&&(e.pageY>=this.hitY1)&&(e.pageY<=this.hitY2)){
175
if(!this.isOver){
176
this._setActive(e);
177
}
178
this._onGridMouseMove(e.pageX-this.hitX1,e.pageY-this.hitY1);
179
}else{
180
if(this.isOver){
181
this._setDormant(e);
182
}
183
}
184
},_onScroll:function(){
185
this._calcHitGrid();
186
},onResized:function(){
187
this._calcHitGrid();
188
},_onGridMouseMove:function(x,y){
189
this.pos={x:x,y:y};
190
this._paint();
191
},_paint:function(){
192
var x=this.pos.x;
193
var y=this.pos.y;
194
if(this.itemCount<=0){
195
return;
196
}
197
var pos=this.isHorizontal?x:y;
198
var prx=this.isHorizontal?this.proximityLeft:this.proximityTop;
199
var siz=this.isHorizontal?this.itemWidth:this.itemHeight;
200
var sim=this.isHorizontal?(1-this.timerScale)*this.itemWidth+this.timerScale*this.itemMaxWidth:(1-this.timerScale)*this.itemHeight+this.timerScale*this.itemMaxHeight;
201
var cen=((pos-prx)/siz)-0.5;
202
var _12=(sim/siz)-0.5;
203
if(_12>this.effectUnits){
204
_12=this.effectUnits;
205
}
206
var _13=0;
207
if(this.anchorEdge==this.EDGE.BOTTOM){
208
var _14=(y-this.proximityTop)/this.itemHeight;
209
_13=(_14>0.5)?1:y/(this.proximityTop+(this.itemHeight/2));
210
}
211
if(this.anchorEdge==this.EDGE.TOP){
212
var _14=(y-this.proximityTop)/this.itemHeight;
213
_13=(_14<0.5)?1:(this.totalHeight-y)/(this.proximityBottom+(this.itemHeight/2));
214
}
215
if(this.anchorEdge==this.EDGE.RIGHT){
216
var _14=(x-this.proximityLeft)/this.itemWidth;
217
_13=(_14>0.5)?1:x/(this.proximityLeft+(this.itemWidth/2));
218
}
219
if(this.anchorEdge==this.EDGE.LEFT){
220
var _14=(x-this.proximityLeft)/this.itemWidth;
221
_13=(_14<0.5)?1:(this.totalWidth-x)/(this.proximityRight+(this.itemWidth/2));
222
}
223
if(this.anchorEdge==this.EDGE.CENTER){
224
if(this.isHorizontal){
225
_13=y/(this.totalHeight);
226
}else{
227
_13=x/(this.totalWidth);
228
}
229
if(_13>0.5){
230
_13=1-_13;
231
}
232
_13*=2;
233
}
234
for(var i=0;i<this.itemCount;i++){
235
var _15=this._weighAt(cen,i);
236
if(_15<0){
237
_15=0;
238
}
239
this._setItemSize(i,_15*_13);
240
}
241
var _16=Math.round(cen);
242
var _17=0;
243
if(cen<0){
244
_16=0;
245
}else{
246
if(cen>this.itemCount-1){
247
_16=this.itemCount-1;
248
}else{
249
_17=(cen-_16)*((this.isHorizontal?this.itemWidth:this.itemHeight)-this.children[_16].sizeMain);
250
}
251
}
252
this._positionElementsFrom(_16,_17);
253
},_weighAt:function(cen,i){
254
var _18=Math.abs(cen-i);
255
var _19=((cen-i)>0)?this.children[i].effectRangeRght:this.children[i].effectRangeLeft;
256
return (_18>_19)?0:(1-_18/_19);
257
},_setItemSize:function(p,_1a){
258
_1a*=this.timerScale;
259
var w=Math.round(this.itemWidth+((this.itemMaxWidth-this.itemWidth)*_1a));
260
var h=Math.round(this.itemHeight+((this.itemMaxHeight-this.itemHeight)*_1a));
261
if(this.isHorizontal){
262
this.children[p].sizeW=w;
263
this.children[p].sizeH=h;
264
this.children[p].sizeMain=w;
265
this.children[p].sizeOff=h;
266
var y=0;
267
if(this.anchorEdge==this.EDGE.TOP){
268
y=(this.children[p].cenY-(this.itemHeight/2));
269
}else{
270
if(this.anchorEdge==this.EDGE.BOTTOM){
271
y=(this.children[p].cenY-(h-(this.itemHeight/2)));
272
}else{
273
y=(this.children[p].cenY-(h/2));
274
}
275
}
276
this.children[p].usualX=Math.round(this.children[p].cenX-(w/2));
277
this.children[p].domNode.style.top=y+"px";
278
this.children[p].domNode.style.left=this.children[p].usualX+"px";
279
}else{
280
this.children[p].sizeW=w;
281
this.children[p].sizeH=h;
282
this.children[p].sizeOff=w;
283
this.children[p].sizeMain=h;
284
var x=0;
285
if(this.anchorEdge==this.EDGE.LEFT){
286
x=this.children[p].cenX-(this.itemWidth/2);
287
}else{
288
if(this.anchorEdge==this.EDGE.RIGHT){
289
x=this.children[p].cenX-(w-(this.itemWidth/2));
290
}else{
291
x=this.children[p].cenX-(w/2);
292
}
293
}
294
this.children[p].domNode.style.left=x+"px";
295
this.children[p].usualY=Math.round(this.children[p].cenY-(h/2));
296
this.children[p].domNode.style.top=this.children[p].usualY+"px";
297
}
298
this.children[p].domNode.style.width=w+"px";
299
this.children[p].domNode.style.height=h+"px";
300
if(this.children[p].svgNode){
301
this.children[p].svgNode.setSize(w,h);
302
}
303
},_positionElementsFrom:function(p,_1b){
304
var pos=0;
305
if(this.isHorizontal){
306
pos=Math.round(this.children[p].usualX+_1b);
307
this.children[p].domNode.style.left=pos+"px";
308
}else{
309
pos=Math.round(this.children[p].usualY+_1b);
310
this.children[p].domNode.style.top=pos+"px";
311
}
312
this._positionLabel(this.children[p]);
313
var _1c=pos;
314
for(var i=p-1;i>=0;i--){
315
_1c-=this.children[i].sizeMain;
316
if(this.isHorizontal){
317
this.children[i].domNode.style.left=_1c+"px";
318
}else{
319
this.children[i].domNode.style.top=_1c+"px";
320
}
321
this._positionLabel(this.children[i]);
322
}
323
var _1d=pos;
324
for(var i=p+1;i<this.itemCount;i++){
325
_1d+=this.children[i-1].sizeMain;
326
if(this.isHorizontal){
327
this.children[i].domNode.style.left=_1d+"px";
328
}else{
329
this.children[i].domNode.style.top=_1d+"px";
330
}
331
this._positionLabel(this.children[i]);
332
}
333
},_positionLabel:function(itm){
334
var x=0;
335
var y=0;
336
var mb=dojo.marginBox(itm.lblNode);
337
if(this.labelEdge==this.EDGE.TOP){
338
x=Math.round((itm.sizeW/2)-(mb.w/2));
339
y=-mb.h;
340
}
341
if(this.labelEdge==this.EDGE.BOTTOM){
342
x=Math.round((itm.sizeW/2)-(mb.w/2));
343
y=itm.sizeH;
344
}
345
if(this.labelEdge==this.EDGE.LEFT){
346
x=-mb.w;
347
y=Math.round((itm.sizeH/2)-(mb.h/2));
348
}
349
if(this.labelEdge==this.EDGE.RIGHT){
350
x=itm.sizeW;
351
y=Math.round((itm.sizeH/2)-(mb.h/2));
352
}
353
itm.lblNode.style.left=x+"px";
354
itm.lblNode.style.top=y+"px";
355
},_calcHitGrid:function(){
356
var pos=dojo.coords(this.domNode,true);
357
this.hitX1=pos.x-this.proximityLeft;
358
this.hitY1=pos.y-this.proximityTop;
359
this.hitX2=this.hitX1+this.totalWidth;
360
this.hitY2=this.hitY1+this.totalHeight;
361
},_toEdge:function(inp,def){
362
return this.EDGE[inp.toUpperCase()]||def;
363
},_expandSlowly:function(){
364
if(!this.isOver){
365
return;
366
}
367
this.timerScale+=0.2;
368
this._paint();
369
if(this.timerScale<1){
370
setTimeout(dojo.hitch(this,"_expandSlowly"),10);
371
}
372
},destroyRecursive:function(){
373
dojo.disconnect(this._onMouseOutHandle);
374
dojo.disconnect(this._onMouseMoveHandle);
375
dojo.disconnect(this._addChildHandle);
376
if(this.isFixed){
377
dojo.disconnect(this._onScrollHandle);
378
}
379
dojo.disconnect(this._onResizeHandle);
380
this.inherited("destroyRecursive",arguments);
381
}});
382
dojo.declare("dojox.widget.FisheyeListItem",[dijit._Widget,dijit._Templated,dijit._Contained],{iconSrc:"",label:"",id:"",templateString:"<div class=\"dojoxFisheyeListItem\">"+"  <img class=\"dojoxFisheyeListItemImage\" dojoAttachPoint=\"imgNode\" dojoAttachEvent=\"onmouseover:onMouseOver,onmouseout:onMouseOut,onclick:onClick\">"+"  <div class=\"dojoxFisheyeListItemLabel\" dojoAttachPoint=\"lblNode\"></div>"+"</div>",_isNode:function(wh){
383
if(typeof Element=="function"){
384
try{
385
return wh instanceof Element;
386
}
387
catch(e){
388
}
389
}else{
390
return wh&&!isNaN(wh.nodeType);
391
}
392
},_hasParent:function(_1e){
393
return Boolean(_1e&&_1e.parentNode&&this._isNode(_1e.parentNode));
394
},postCreate:function(){
395
if((this.iconSrc.toLowerCase().substring(this.iconSrc.length-4)==".png")&&dojo.isIE<7){
396
if(this._hasParent(this.imgNode)&&this.id!=""){
397
var _1f=this.imgNode.parentNode;
398
_1f.setAttribute("id",this.id);
399
}
400
this.imgNode.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.iconSrc+"', sizingMethod='scale')";
401
this.imgNode.src=this._blankGif.toString();
402
}else{
403
if(this._hasParent(this.imgNode)&&this.id!=""){
404
var _1f=this.imgNode.parentNode;
405
_1f.setAttribute("id",this.id);
406
}
407
this.imgNode.src=this.iconSrc;
408
}
409
if(this.lblNode){
410
this.lblNode.appendChild(document.createTextNode(this.label));
411
}
412
dojo.setSelectable(this.domNode,false);
413
this.startup();
414
},startup:function(){
415
this.parent=this.getParent();
416
},onMouseOver:function(e){
417
if(!this.parent.isOver){
418
this.parent._setActive(e);
419
}
420
if(this.label!=""){
421
dojo.addClass(this.lblNode,"dojoxFishSelected");
422
this.parent._positionLabel(this);
423
}
424
},onMouseOut:function(e){
425
dojo.removeClass(this.lblNode,"dojoxFishSelected");
426
},onClick:function(e){
427
}});
428
}