100 lines
2.2 KiB
JavaScript
100 lines
2.2 KiB
JavaScript
/*
|
|
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
|
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
|
see: http://dojotoolkit.org/license for details
|
|
*/
|
|
|
|
|
|
if(!dojo._hasResource["dojo.dnd.autoscroll"]){
|
|
dojo._hasResource["dojo.dnd.autoscroll"]=true;
|
|
dojo.provide("dojo.dnd.autoscroll");
|
|
dojo.dnd.getViewport=function(){
|
|
var d=dojo.doc,dd=d.documentElement,w=window,b=dojo.body();
|
|
if(dojo.isMozilla){
|
|
return {w:dd.clientWidth,h:w.innerHeight};
|
|
}else{
|
|
if(!dojo.isOpera&&w.innerWidth){
|
|
return {w:w.innerWidth,h:w.innerHeight};
|
|
}else{
|
|
if(!dojo.isOpera&&dd&&dd.clientWidth){
|
|
return {w:dd.clientWidth,h:dd.clientHeight};
|
|
}else{
|
|
if(b.clientWidth){
|
|
return {w:b.clientWidth,h:b.clientHeight};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
dojo.dnd.V_TRIGGER_AUTOSCROLL=32;
|
|
dojo.dnd.H_TRIGGER_AUTOSCROLL=32;
|
|
dojo.dnd.V_AUTOSCROLL_VALUE=16;
|
|
dojo.dnd.H_AUTOSCROLL_VALUE=16;
|
|
dojo.dnd.autoScroll=function(e){
|
|
var v=dojo.dnd.getViewport(),dx=0,dy=0;
|
|
if(e.clientX<dojo.dnd.H_TRIGGER_AUTOSCROLL){
|
|
dx=-dojo.dnd.H_AUTOSCROLL_VALUE;
|
|
}else{
|
|
if(e.clientX>v.w-dojo.dnd.H_TRIGGER_AUTOSCROLL){
|
|
dx=dojo.dnd.H_AUTOSCROLL_VALUE;
|
|
}
|
|
}
|
|
if(e.clientY<dojo.dnd.V_TRIGGER_AUTOSCROLL){
|
|
dy=-dojo.dnd.V_AUTOSCROLL_VALUE;
|
|
}else{
|
|
if(e.clientY>v.h-dojo.dnd.V_TRIGGER_AUTOSCROLL){
|
|
dy=dojo.dnd.V_AUTOSCROLL_VALUE;
|
|
}
|
|
}
|
|
window.scrollBy(dx,dy);
|
|
};
|
|
dojo.dnd._validNodes={"div":1,"p":1,"td":1};
|
|
dojo.dnd._validOverflow={"auto":1,"scroll":1};
|
|
dojo.dnd.autoScrollNodes=function(e){
|
|
for(var n=e.target;n;){
|
|
if(n.nodeType==1&&(n.tagName.toLowerCase() in dojo.dnd._validNodes)){
|
|
var s=dojo.getComputedStyle(n);
|
|
if(s.overflow.toLowerCase() in dojo.dnd._validOverflow){
|
|
var b=dojo._getContentBox(n,s),t=dojo.position(n,true);
|
|
var w=Math.min(dojo.dnd.H_TRIGGER_AUTOSCROLL,b.w/2),h=Math.min(dojo.dnd.V_TRIGGER_AUTOSCROLL,b.h/2),rx=e.pageX-t.x,ry=e.pageY-t.y,dx=0,dy=0;
|
|
if(dojo.isWebKit||dojo.isOpera){
|
|
rx+=dojo.body().scrollLeft,ry+=dojo.body().scrollTop;
|
|
}
|
|
if(rx>0&&rx<b.w){
|
|
if(rx<w){
|
|
dx=-w;
|
|
}else{
|
|
if(rx>b.w-w){
|
|
dx=w;
|
|
}
|
|
}
|
|
}
|
|
if(ry>0&&ry<b.h){
|
|
if(ry<h){
|
|
dy=-h;
|
|
}else{
|
|
if(ry>b.h-h){
|
|
dy=h;
|
|
}
|
|
}
|
|
}
|
|
var _1=n.scrollLeft,_2=n.scrollTop;
|
|
n.scrollLeft=n.scrollLeft+dx;
|
|
n.scrollTop=n.scrollTop+dy;
|
|
if(_1!=n.scrollLeft||_2!=n.scrollTop){
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
try{
|
|
n=n.parentNode;
|
|
}
|
|
catch(x){
|
|
n=null;
|
|
}
|
|
}
|
|
dojo.dnd.autoScroll(e);
|
|
};
|
|
}
|