Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / mdnd / Moveable.js @ 12

History | View | Annotate | Download (3.01 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.mdnd.Moveable"]){
9
dojo._hasResource["dojox.mdnd.Moveable"]=true;
10
dojo.provide("dojox.mdnd.Moveable");
11
dojo.declare("dojox.mdnd.Moveable",null,{handle:null,skip:true,dragDistance:3,constructor:function(_1,_2){
12
this.node=dojo.byId(_2);
13
this.d=this.node.ownerDocument;
14
if(!_1){
15
_1={};
16
}
17
this.handle=_1.handle?dojo.byId(_1.handle):null;
18
if(!this.handle){
19
this.handle=this.node;
20
}
21
this.skip=_1.skip;
22
this.events=[dojo.connect(this.handle,"onmousedown",this,"onMouseDown")];
23
if(dojox.mdnd.autoScroll){
24
this.autoScroll=dojox.mdnd.autoScroll;
25
}
26
},isFormElement:function(e){
27
var t=e.target;
28
if(t.nodeType==3){
29
t=t.parentNode;
30
}
31
return " a button textarea input select option ".indexOf(" "+t.tagName.toLowerCase()+" ")>=0;
32
},onMouseDown:function(e){
33
if(this._isDragging){
34
return;
35
}
36
var _3=dojo.isIE?(e.button==1):(e.which==1);
37
if(!_3){
38
return;
39
}
40
if(this.skip&&this.isFormElement(e)){
41
return;
42
}
43
if(this.autoScroll){
44
this.autoScroll.setAutoScrollNode(this.node);
45
this.autoScroll.setAutoScrollMaxPage();
46
}
47
this.events.push(dojo.connect(this.d,"onmouseup",this,"onMouseUp"));
48
this.events.push(dojo.connect(this.d,"onmousemove",this,"onFirstMove"));
49
this._selectStart=dojo.connect(dojo.body(),"onselectstart",dojo.stopEvent);
50
this._firstX=e.clientX;
51
this._firstY=e.clientY;
52
dojo.stopEvent(e);
53
},onFirstMove:function(e){
54
dojo.stopEvent(e);
55
var d=(this._firstX-e.clientX)*(this._firstX-e.clientX)+(this._firstY-e.clientY)*(this._firstY-e.clientY);
56
if(d>this.dragDistance*this.dragDistance){
57
this._isDragging=true;
58
dojo.disconnect(this.events.pop());
59
dojo.style(this.node,"width",dojo.contentBox(this.node).w+"px");
60
this.initOffsetDrag(e);
61
this.events.push(dojo.connect(this.d,"onmousemove",this,"onMove"));
62
}
63
},initOffsetDrag:function(e){
64
this.offsetDrag={"l":e.pageX,"t":e.pageY};
65
var s=this.node.style;
66
var _4=dojo.position(this.node,true);
67
this.offsetDrag.l=_4.x-this.offsetDrag.l;
68
this.offsetDrag.t=_4.y-this.offsetDrag.t;
69
var _5={"x":_4.x,"y":_4.y};
70
this.size={"w":_4.w,"h":_4.h};
71
this.onDragStart(this.node,_5,this.size);
72
},onMove:function(e){
73
dojo.stopEvent(e);
74
if(dojo.isIE==8&&new Date()-this.date<20){
75
return;
76
}
77
if(this.autoScroll){
78
this.autoScroll.checkAutoScroll(e);
79
}
80
var _6={"x":this.offsetDrag.l+e.pageX,"y":this.offsetDrag.t+e.pageY};
81
var s=this.node.style;
82
s.left=_6.x+"px";
83
s.top=_6.y+"px";
84
this.onDrag(this.node,_6,this.size,{"x":e.pageX,"y":e.pageY});
85
if(dojo.isIE==8){
86
this.date=new Date();
87
}
88
},onMouseUp:function(e){
89
dojo.stopEvent(e);
90
this._isDragging=false;
91
if(this.autoScroll){
92
this.autoScroll.stopAutoScroll();
93
}
94
dojo.disconnect(this.events.pop());
95
dojo.disconnect(this.events.pop());
96
delete this.onMove;
97
this.onDragEnd(this.node);
98
this.node.focus();
99
},onDragStart:function(_7,_8,_9){
100
},onDragEnd:function(_a){
101
},onDrag:function(_b,_c,_d,_e){
102
},destroy:function(){
103
dojo.forEach(this.events,dojo.disconnect);
104
this.events=this.node=null;
105
}});
106
}