| 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 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
interval: 3, |
| 19 |
|
| 20 |
|
| 21 |
recursiveTimer: 10, |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
marginMouse: 50, |
| 26 |
|
| 27 |
constructor: function(){ |
| 28 |
|
| 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 |
|
| 37 |
this._html = (sniff("webkit"))? dojo.body() : dojo.body().parentNode; |
| 38 |
this.getViewport(); |
| 39 |
}, |
| 40 |
|
| 41 |
getViewport:function(){ |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 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 }; |
| 49 |
} |
| 50 |
else if(!dojo.isOpera && w.innerWidth){ |
| 51 |
this._v = { 'w': w.innerWidth, 'h': w.innerHeight }; |
| 52 |
} |
| 53 |
else if(!dojo.isOpera && dd && dd.clientWidth){ |
| 54 |
this._v = { 'w': dd.clientWidth, 'h': dd.clientHeight }; |
| 55 |
} |
| 56 |
else if(b.clientWidth){ |
| 57 |
this._v = { 'w': b.clientWidth, 'h': b.clientHeight }; |
| 58 |
} |
| 59 |
}, |
| 60 |
|
| 61 |
setAutoScrollNode: function(node){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
this._node = node; |
| 69 |
}, |
| 70 |
|
| 71 |
setAutoScrollMaxPage: function(){ |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
this._yMax = this._html.scrollHeight; |
| 77 |
this._xMax = this._html.scrollWidth; |
| 78 |
}, |
| 79 |
|
| 80 |
checkAutoScroll: function(e){ |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 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 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 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 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 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 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 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(e){ |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 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 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
if(this._timer){ |
| 187 |
clearTimeout(this._timer); |
| 188 |
} |
| 189 |
this._autoScrollActive = false; |
| 190 |
}, |
| 191 |
|
| 192 |
destroy: function(){ |
| 193 |
|
| 194 |
connect.disconnect(this.resizeHandler); |
| 195 |
} |
| 196 |
}); |
| 197 |
|
| 198 |
as.autoScroll = null; |
| 199 |
|
| 200 |
as.autoScroll = new as(); |
| 201 |
return as; |
| 202 |
}); |