Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / dnd / BoundingBoxController.js @ 10

History | View | Annotate | Download (2.06 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.dnd.BoundingBoxController"]){
9
dojo._hasResource["dojox.dnd.BoundingBoxController"]=true;
10
dojo.provide("dojox.dnd.BoundingBoxController");
11
dojo.declare("dojox.dnd.BoundingBoxController",null,{_startX:null,_startY:null,_endX:null,_endY:null,constructor:function(_1,_2){
12
this.events=[dojo.connect(dojo.doc,"onmousedown",this,"_onMouseDown"),dojo.connect(dojo.doc,"onmouseup",this,"_onMouseUp"),dojo.connect(dojo.doc,"onscroll",this,"_finishSelecting")];
13
this.subscriptions=[dojo.subscribe("/dojox/bounding/cancel",this,"_finishSelecting")];
14
dojo.forEach(_1,function(_3){
15
if(_3.selectByBBox){
16
this.subscriptions.push(dojo.subscribe("/dojox/dnd/bounding",_3,"selectByBBox"));
17
}
18
},this);
19
this.domNode=dojo.byId(_2);
20
dojo.style(this.domNode,{position:"absolute",display:"none"});
21
},destroy:function(){
22
dojo.forEach(this.events,dojo.disconnect);
23
dojo.forEach(this.subscriptions,dojo.unsubscribe);
24
this.domNode=null;
25
},boundingBoxIsViable:function(){
26
return true;
27
},_onMouseDown:function(_4){
28
if(dojo.mouseButtons.isLeft(_4)){
29
if(this._startX===null){
30
this._startX=_4.clientX;
31
this._startY=_4.clientY;
32
}
33
this.events.push(dojo.connect(dojo.doc,"onmousemove",this,"_onMouseMove"));
34
}
35
},_onMouseMove:function(_5){
36
this._endX=_5.clientX;
37
this._endY=_5.clientY;
38
this._drawBoundingBox();
39
},_onMouseUp:function(_6){
40
if(this._endX!==null&&this.boundingBoxIsViable()){
41
dojo.publish("/dojox/dnd/bounding",[this._startX,this._startY,this._endX,this._endY]);
42
}
43
this._finishSelecting();
44
},_finishSelecting:function(){
45
if(this._startX!==null){
46
dojo.disconnect(this.events.pop());
47
dojo.style(this.domNode,"display","none");
48
this._startX=this._endX=null;
49
}
50
},_drawBoundingBox:function(){
51
dojo.style(this.domNode,{left:Math.min(this._startX,this._endX)+"px",top:Math.min(this._startY,this._endY)+"px",width:Math.abs(this._startX-this._endX)+"px",height:Math.abs(this._startY-this._endY)+"px",display:""});
52
}});
53
}