root / trunk / web / dojo / dojox / mdnd / AutoScroll.js @ 9
History | View | Annotate | Download (3.36 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.mdnd.AutoScroll"]){ |
||
9 | dojo._hasResource["dojox.mdnd.AutoScroll"]=true; |
||
10 | dojo.provide("dojox.mdnd.AutoScroll");
|
||
11 | dojo.declare("dojox.mdnd.AutoScroll",null,{interval:3,recursiveTimer:10,marginMouse:50,constructor:function(){ |
||
12 | this.resizeHandler=dojo.connect(dojo.global,"onresize",this,function(){ |
||
13 | this.getViewport();
|
||
14 | }); |
||
15 | dojo.ready(dojo.hitch(this,"init")); |
||
16 | },init:function(){ |
||
17 | this._html=(dojo.isWebKit)?dojo.body():dojo.body().parentNode;
|
||
18 | this.getViewport();
|
||
19 | },getViewport:function(){ |
||
20 | var d=dojo.doc,dd=d.documentElement,w=window,b=dojo.body();
|
||
21 | if(dojo.isMozilla){
|
||
22 | this._v={"w":dd.clientWidth,"h":w.innerHeight}; |
||
23 | }else{
|
||
24 | if(!dojo.isOpera&&w.innerWidth){
|
||
25 | this._v={"w":w.innerWidth,"h":w.innerHeight}; |
||
26 | }else{
|
||
27 | if(!dojo.isOpera&&dd&&dd.clientWidth){
|
||
28 | this._v={"w":dd.clientWidth,"h":dd.clientHeight}; |
||
29 | }else{
|
||
30 | if(b.clientWidth){
|
||
31 | this._v={"w":b.clientWidth,"h":b.clientHeight}; |
||
32 | } |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 | },setAutoScrollNode:function(_1){ |
||
37 | this._node=_1;
|
||
38 | },setAutoScrollMaxPage:function(){ |
||
39 | this._yMax=this._html.scrollHeight; |
||
40 | this._xMax=this._html.scrollWidth; |
||
41 | },checkAutoScroll:function(e){ |
||
42 | if(this._autoScrollActive){ |
||
43 | this.stopAutoScroll();
|
||
44 | } |
||
45 | this._y=e.pageY;
|
||
46 | this._x=e.pageX;
|
||
47 | if(e.clientX<this.marginMouse){ |
||
48 | this._autoScrollActive=true; |
||
49 | this._autoScrollLeft(e);
|
||
50 | }else{
|
||
51 | if(e.clientX>this._v.w-this.marginMouse){ |
||
52 | this._autoScrollActive=true; |
||
53 | this._autoScrollRight(e);
|
||
54 | } |
||
55 | } |
||
56 | if(e.clientY<this.marginMouse){ |
||
57 | this._autoScrollActive=true; |
||
58 | this._autoScrollUp(e);
|
||
59 | }else{
|
||
60 | if(e.clientY>this._v.h-this.marginMouse){ |
||
61 | this._autoScrollActive=true; |
||
62 | this._autoScrollDown();
|
||
63 | } |
||
64 | } |
||
65 | },_autoScrollDown:function(){ |
||
66 | if(this._timer){ |
||
67 | clearTimeout(this._timer);
|
||
68 | } |
||
69 | if(this._autoScrollActive&&this._y+this.marginMouse<this._yMax){ |
||
70 | this._html.scrollTop+=this.interval; |
||
71 | this._node.style.top=(parseInt(this._node.style.top)+this.interval)+"px"; |
||
72 | this._y+=this.interval; |
||
73 | this._timer=setTimeout(dojo.hitch(this,"_autoScrollDown"),this.recursiveTimer); |
||
74 | } |
||
75 | },_autoScrollUp:function(){ |
||
76 | if(this._timer){ |
||
77 | clearTimeout(this._timer);
|
||
78 | } |
||
79 | if(this._autoScrollActive&&this._y-this.marginMouse>0){ |
||
80 | this._html.scrollTop-=this.interval; |
||
81 | this._node.style.top=(parseInt(this._node.style.top)-this.interval)+"px"; |
||
82 | this._y-=this.interval; |
||
83 | this._timer=setTimeout(dojo.hitch(this,"_autoScrollUp"),this.recursiveTimer); |
||
84 | } |
||
85 | },_autoScrollRight:function(){ |
||
86 | if(this._timer){ |
||
87 | clearTimeout(this._timer);
|
||
88 | } |
||
89 | if(this._autoScrollActive&&this._x+this.marginMouse<this._xMax){ |
||
90 | this._html.scrollLeft+=this.interval; |
||
91 | this._node.style.left=(parseInt(this._node.style.left)+this.interval)+"px"; |
||
92 | this._x+=this.interval; |
||
93 | this._timer=setTimeout(dojo.hitch(this,"_autoScrollRight"),this.recursiveTimer); |
||
94 | } |
||
95 | },_autoScrollLeft:function(e){ |
||
96 | if(this._timer){ |
||
97 | clearTimeout(this._timer);
|
||
98 | } |
||
99 | if(this._autoScrollActive&&this._x-this.marginMouse>0){ |
||
100 | this._html.scrollLeft-=this.interval; |
||
101 | this._node.style.left=(parseInt(this._node.style.left)-this.interval)+"px"; |
||
102 | this._x-=this.interval; |
||
103 | this._timer=setTimeout(dojo.hitch(this,"_autoScrollLeft"),this.recursiveTimer); |
||
104 | } |
||
105 | },stopAutoScroll:function(){ |
||
106 | if(this._timer){ |
||
107 | clearTimeout(this._timer);
|
||
108 | } |
||
109 | this._autoScrollActive=false; |
||
110 | },destroy:function(){ |
||
111 | dojo.disconnect(this.resizeHandler);
|
||
112 | }}); |
||
113 | dojox.mdnd.autoScroll=null;
|
||
114 | (function(){
|
||
115 | dojox.mdnd.autoScroll=new dojox.mdnd.AutoScroll();
|
||
116 | }()); |
||
117 | } |