in tapestry-framework/src/js/dojo-0.4.3-custom-4.1.6/src/dnd/HtmlDragAndDrop.js [202:356]
dojo.declare("dojo.dnd.HtmlDropTarget",dojo.dnd.DropTarget,{vertical:false,onDragOver:function(e){
if(!this.accepts(e.dragObjects)){
return false;
}
this.childBoxes=[];
for(var i=0,_31;i<this.domNode.childNodes.length;i++){
_31=this.domNode.childNodes[i];
if(_31.nodeType!=dojo.html.ELEMENT_NODE){
continue;
}
var pos=dojo.html.getAbsolutePosition(_31,true);
var _33=dojo.html.getBorderBox(_31);
this.childBoxes.push({top:pos.y,bottom:pos.y+_33.height,left:pos.x,right:pos.x+_33.width,height:_33.height,width:_33.width,node:_31});
}
return true;
},_getNodeUnderMouse:function(e){
for(var i=0,_36;i<this.childBoxes.length;i++){
with(this.childBoxes[i]){
if(e.pageX>=left&&e.pageX<=right&&e.pageY>=top&&e.pageY<=bottom){
return i;
}
}
}
return -1;
},createDropIndicator:function(){
this.dropIndicator=document.createElement("div");
with(this.dropIndicator.style){
position="absolute";
zIndex=999;
if(this.vertical){
borderLeftWidth="1px";
borderLeftColor="black";
borderLeftStyle="solid";
height=dojo.html.getBorderBox(this.domNode).height+"px";
top=dojo.html.getAbsolutePosition(this.domNode,true).y+"px";
}else{
borderTopWidth="1px";
borderTopColor="black";
borderTopStyle="solid";
width=dojo.html.getBorderBox(this.domNode).width+"px";
left=dojo.html.getAbsolutePosition(this.domNode,true).x+"px";
}
}
},onDragMove:function(e,_38){
var i=this._getNodeUnderMouse(e);
if(!this.dropIndicator){
this.createDropIndicator();
}
var _3a=this.vertical?dojo.html.gravity.WEST:dojo.html.gravity.NORTH;
var _3b=false;
if(i<0){
if(this.childBoxes.length){
var _3c=(dojo.html.gravity(this.childBoxes[0].node,e)&_3a);
if(_3c){
_3b=true;
}
}else{
var _3c=true;
}
}else{
var _3d=this.childBoxes[i];
var _3c=(dojo.html.gravity(_3d.node,e)&_3a);
if(_3d.node===_38[0].dragSource.domNode){
_3b=true;
}else{
var _3e=_3c?(i>0?this.childBoxes[i-1]:_3d):(i<this.childBoxes.length-1?this.childBoxes[i+1]:_3d);
if(_3e.node===_38[0].dragSource.domNode){
_3b=true;
}
}
}
if(_3b){
this.dropIndicator.style.display="none";
return;
}else{
this.dropIndicator.style.display="";
}
this.placeIndicator(e,_38,i,_3c);
if(!dojo.html.hasParent(this.dropIndicator)){
dojo.body().appendChild(this.dropIndicator);
}
},placeIndicator:function(e,_40,_41,_42){
var _43=this.vertical?"left":"top";
var _44;
if(_41<0){
if(this.childBoxes.length){
_44=_42?this.childBoxes[0]:this.childBoxes[this.childBoxes.length-1];
}else{
this.dropIndicator.style[_43]=dojo.html.getAbsolutePosition(this.domNode,true)[this.vertical?"x":"y"]+"px";
}
}else{
_44=this.childBoxes[_41];
}
if(_44){
this.dropIndicator.style[_43]=(_42?_44[_43]:_44[this.vertical?"right":"bottom"])+"px";
if(this.vertical){
this.dropIndicator.style.height=_44.height+"px";
this.dropIndicator.style.top=_44.top+"px";
}else{
this.dropIndicator.style.width=_44.width+"px";
this.dropIndicator.style.left=_44.left+"px";
}
}
},onDragOut:function(e){
if(this.dropIndicator){
dojo.html.removeNode(this.dropIndicator);
delete this.dropIndicator;
}
},onDrop:function(e){
this.onDragOut(e);
var i=this._getNodeUnderMouse(e);
var _48=this.vertical?dojo.html.gravity.WEST:dojo.html.gravity.NORTH;
if(i<0){
if(this.childBoxes.length){
if(dojo.html.gravity(this.childBoxes[0].node,e)&_48){
return this.insert(e,this.childBoxes[0].node,"before");
}else{
return this.insert(e,this.childBoxes[this.childBoxes.length-1].node,"after");
}
}
return this.insert(e,this.domNode,"append");
}
var _49=this.childBoxes[i];
if(dojo.html.gravity(_49.node,e)&_48){
return this.insert(e,_49.node,"before");
}else{
return this.insert(e,_49.node,"after");
}
},insert:function(e,_4b,_4c){
var _4d=e.dragObject.domNode;
if(_4c=="before"){
return dojo.html.insertBefore(_4d,_4b);
}else{
if(_4c=="after"){
return dojo.html.insertAfter(_4d,_4b);
}else{
if(_4c=="append"){
_4b.appendChild(_4d);
return true;
}
}
}
return false;
}},function(_4e,_4f){
if(arguments.length==0){
return;
}
this.domNode=dojo.byId(_4e);
dojo.dnd.DropTarget.call(this);
if(_4f&&dojo.lang.isString(_4f)){
_4f=[_4f];
}
this.acceptedTypes=_4f||[];
dojo.dnd.dragManager.registerDropTarget(this);
});