root / trunk / web / dojo / dojox / dnd / Selector.js @ 12
History | View | Annotate | Download (1.83 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["dojox.dnd.Selector"]){ |
||
9 | dojo._hasResource["dojox.dnd.Selector"]=true; |
||
10 | dojo.provide("dojox.dnd.Selector");
|
||
11 | dojo.require("dojo.dnd.Selector");
|
||
12 | dojo.declare("dojox.dnd.Selector",dojo.dnd.Selector,{isSelected:function(_1){ |
||
13 | var id=dojo.isString(_1)?_1:_1.id,_2=this.getItem(id); |
||
14 | return _2&&this.selected[id]; |
||
15 | },selectNode:function(_3,_4){ |
||
16 | if(!_4){
|
||
17 | this.selectNone();
|
||
18 | } |
||
19 | var id=dojo.isString(_3)?_3:_3.id,_5=this.getItem(id); |
||
20 | if(_5){
|
||
21 | this._removeAnchor();
|
||
22 | this.anchor=dojo.byId(_3);
|
||
23 | this._addItemClass(this.anchor,"Anchor"); |
||
24 | this.selection[id]=1; |
||
25 | this._addItemClass(this.anchor,"Selected"); |
||
26 | } |
||
27 | return this; |
||
28 | },deselectNode:function(_6){ |
||
29 | var id=dojo.isString(_6)?_6:_6.id,_7=this.getItem(id); |
||
30 | if(_7&&this.selection[id]){ |
||
31 | if(this.anchor===dojo.byId(_6)){ |
||
32 | this._removeAnchor();
|
||
33 | } |
||
34 | delete this.selection[id]; |
||
35 | this._removeItemClass(this.anchor,"Selected"); |
||
36 | } |
||
37 | return this; |
||
38 | },selectByBBox:function(_8,_9,_a,_b,_c){ |
||
39 | if(!_c){
|
||
40 | this.selectNone();
|
||
41 | } |
||
42 | this.forInItems(function(_d,id){ |
||
43 | var _e=dojo.byId(id);
|
||
44 | if(_e&&this._isBoundedByBox(_e,_8,_9,_a,_b)){ |
||
45 | this.selectNode(id,true); |
||
46 | } |
||
47 | },this);
|
||
48 | return this; |
||
49 | },_isBoundedByBox:function(_f,_10,top,_11,_12){ |
||
50 | var c=dojo.coords(_f),t;
|
||
51 | if(_10>_11){
|
||
52 | t=_10; |
||
53 | _10=_11; |
||
54 | _11=t; |
||
55 | } |
||
56 | if(top>_12){
|
||
57 | t=top; |
||
58 | top=_12; |
||
59 | _12=t; |
||
60 | } |
||
61 | return c.x>=_10&&c.x+c.w<=_11&&c.y>=top&&c.y+c.h<=_12;
|
||
62 | },shift:function(_13,add){ |
||
63 | var _14=this.getSelectedNodes(); |
||
64 | if(_14&&_14.length){
|
||
65 | this.selectNode(this._getNodeId(_14[_14.length-1].id,_13),add); |
||
66 | } |
||
67 | },_getNodeId:function(_15,_16){ |
||
68 | var _17=this.getAllNodes(),_18=_15; |
||
69 | for(var i=0,l=_17.length;i<l;++i){ |
||
70 | if(_17[i].id==_15){
|
||
71 | var j=Math.min(l-1,Math.max(0,i+(_16?1:-1))); |
||
72 | if(i!=j){
|
||
73 | _18=_17[j].id; |
||
74 | } |
||
75 | break;
|
||
76 | } |
||
77 | } |
||
78 | return _18;
|
||
79 | }}); |
||
80 | } |