Debian Codegraph @

dojox/mdnd/AutoScroll.js

raw symbols SCIP
1 define(["dojo/_base/kernel",
2 "dojo/_base/declare",
3 "dojo/_base/lang",
4 "dojo/_base/connect",
5 "dojo/_base/sniff",
6 "dojo/ready",
7 "dojo/_base/window"
8 ],function(dojo, declare, lang, connect, sniff, ready){
9 var as = declare(
10 "dojox.mdnd.AutoScroll",
11 null,
12 {
13 // summary:
14 // Activate scrolling while dragging a widget.
15
16 // interval: Integer
17 // default mouse move offset
18 interval: 3,
19
20 // recursiveTimer: Integer
21 recursiveTimer: 10,
22
23 // marginMouse: Integer
24 // Default mouse margin
25 marginMouse: 50,
26
27 constructor: function(){
28 //console.log("dojox.mdnd.AutoScroll ::: constructor ");
29 this.resizeHandler = connect.connect(dojo.global,"onresize", this, function(){
30 this.getViewport();
31 });
32 ready(lang.hitch(this, "init"));
33 },
34
35 init: function(){
36 //console.log("dojox.mdnd.AutoScroll ::: init ");
37 this._html = (sniff("webkit"))? dojo.body() : dojo.body().parentNode;
38 this.getViewport();
39 },
40
41 getViewport:function(){
42 // summary:
43 // Set the visible part of the window. Varies accordion to Navigator.
44
45 //console.log("dojox.mdnd.AutoScroll ::: getViewport ");
46 var d = dojo.doc, dd = d.documentElement, w = window, b = dojo.body();
47 if(dojo.isMozilla){
48 this._v = { 'w': dd.clientWidth, 'h': w.innerHeight }; // Object
49 }
50 else if(!dojo.isOpera && w.innerWidth){
51 this._v = { 'w': w.innerWidth, 'h': w.innerHeight }; // Object
52 }
53 else if(!dojo.isOpera && dd && dd.clientWidth){
54 this._v = { 'w': dd.clientWidth, 'h': dd.clientHeight }; // Object
55 }
56 else if(b.clientWidth){
57 this._v = { 'w': b.clientWidth, 'h': b.clientHeight }; // Object
58 }
59 },
60
61 setAutoScrollNode: function(/*Node*/node){
62 // summary:
63 // set the node which is dragged
64 // node:
65 // node to scroll
66
67 //console.log("dojox.mdnd.AutoScroll ::: setAutoScrollNode ");
68 this._node = node;
69 },
70
71 setAutoScrollMaxPage: function(){
72 // summary:
73 // Set the hightest heigh and width authorized scroll.
74
75 //console.log("dojox.mdnd.AutoScroll ::: setAutoScrollMaxPage ");
76 this._yMax = this._html.scrollHeight;
77 this._xMax = this._html.scrollWidth;
78 },
79
80 checkAutoScroll: function(/*Event*/e){
81 // summary:
82 // Check if an autoScroll have to be launched.
83
84 //console.log("dojox.mdnd.AutoScroll ::: checkAutoScroll");
85 if(this._autoScrollActive){
86 this.stopAutoScroll();
87 }
88 this._y = e.pageY;
89 this._x = e.pageX;
90 if(e.clientX < this.marginMouse){
91 this._autoScrollActive = true;
92 this._autoScrollLeft(e);
93 }
94 else if(e.clientX > this._v.w - this.marginMouse){
95 this._autoScrollActive = true;
96 this._autoScrollRight(e);
97 }
98 if(e.clientY < this.marginMouse){
99 this._autoScrollActive = true;
100 this._autoScrollUp(e);
101
102 }
103 else if(e.clientY > this._v.h - this.marginMouse){
104 this._autoScrollActive = true;
105 this._autoScrollDown();
106 }
107 },
108
109 _autoScrollDown: function(){
110 // summary:
111 // Manage the down autoscroll.
112 // tags:
113 // protected
114
115 //console.log("dojox.mdnd.AutoScroll ::: _autoScrollDown ");
116 if(this._timer){
117 clearTimeout(this._timer);
118 }
119 if(this._autoScrollActive && this._y + this.marginMouse < this._yMax){
120 this._html.scrollTop += this.interval;
121 this._node.style.top = (parseInt(this._node.style.top) + this.interval) + "px";
122 this._y += this.interval;
123 this._timer = setTimeout(lang.hitch(this, "_autoScrollDown"), this.recursiveTimer);
124 }
125 },
126
127 _autoScrollUp: function(){
128 // summary:
129 // Manage the up autoscroll.
130 // tags:
131 // protected
132
133 //console.log("dojox.mdnd.AutoScroll ::: _autoScrollUp ");
134 if(this._timer){
135 clearTimeout(this._timer);
136 }
137 if(this._autoScrollActive && this._y - this.marginMouse > 0){
138 this._html.scrollTop -= this.interval;
139 this._node.style.top = (parseInt(this._node.style.top) - this.interval) + "px";
140 this._y -= this.interval;
141 this._timer = setTimeout(lang.hitch(this, "_autoScrollUp"),this.recursiveTimer);
142 }
143 },
144
145 _autoScrollRight: function(){
146 // summary:
147 // Manage the right autoscroll.
148 // tags:
149 // protected
150
151 //console.log("dojox.mdnd.AutoScroll ::: _autoScrollRight ");
152 if(this._timer){
153 clearTimeout(this._timer);
154 }
155 if(this._autoScrollActive && this._x + this.marginMouse < this._xMax){
156 this._html.scrollLeft += this.interval;
157 this._node.style.left = (parseInt(this._node.style.left) + this.interval) + "px";
158 this._x += this.interval;
159 this._timer = setTimeout(lang.hitch(this, "_autoScrollRight"), this.recursiveTimer);
160 }
161 },
162
163 _autoScrollLeft: function(/*Event*/e){
164 // summary:
165 // Manage the left autoscroll.
166 // tags:
167 // protected
168
169 //console.log("dojox.mdnd.AutoScroll ::: _autoScrollLeft ");
170 if(this._timer){
171 clearTimeout(this._timer);
172 }
173 if(this._autoScrollActive && this._x - this.marginMouse > 0){
174 this._html.scrollLeft -= this.interval;
175 this._node.style.left = (parseInt(this._node.style.left) - this.interval) + "px";
176 this._x -= this.interval;
177 this._timer = setTimeout(lang.hitch(this, "_autoScrollLeft"),this.recursiveTimer);
178 }
179 },
180
181 stopAutoScroll: function(){
182 // summary:
183 // Stop the autoscroll.
184
185 //console.log("dojox.mdnd.AutoScroll ::: stopAutoScroll ");
186 if(this._timer){
187 clearTimeout(this._timer);
188 }
189 this._autoScrollActive = false;
190 },
191
192 destroy: function(){
193 //console.log("dojox.mdnd.AutoScroll ::: destroy ");
194 connect.disconnect(this.resizeHandler);
195 }
196 });
197
198 as.autoScroll = null;
199
200 as.autoScroll = new as();
201 return as;
202 });