if(typeof Effect=="undefined"){
throw ("dragdrop.js requires including script.aculo.us' effects.js library");
}
var Droppables={drops:[],remove:function(_1){
this.drops=this.drops.reject(function(d){
return d.element==$(_1);
});
},add:function(_3){
_3=$(_3);
var _4=Object.extend({greedy:true,hoverclass:null,tree:false},arguments[1]||{});
if(_4.containment){
_4._containers=[];
var _5=_4.containment;
if((typeof _5=="object")&&(_5.constructor==Array)){
_5.each(function(c){
_4._containers.push($(c));
});
}else{
_4._containers.push($(_5));
}
}
if(_4.accept){
_4.accept=[_4.accept].flatten();
}
Element.makePositioned(_3);
_4.element=_3;
this.drops.push(_4);
},findDeepestChild:function(_7){
deepest=_7[0];
for(i=1;i<_7.length;++i){
if(Element.isParent(_7[i].element,deepest.element)){
deepest=_7[i];
}
}
return deepest;
},isContained:function(_8,_9){
var _a;
if(_9.tree){
_a=_8.treeNode;
}else{
_a=_8.parentNode;
}
return _9._containers.detect(function(c){
return _a==c;
});
},isAffected:function(_c,_d,_e){
return ((_e.element!=_d)&&((!_e._containers)||this.isContained(_d,_e))&&((!_e.accept)||(Element.classNames(_d).detect(function(v){
return _e.accept.include(v);
})))&&Position.within(_e.element,_c[0],_c[1]));
},deactivate:function(_10){
if(_10.hoverclass){
Element.removeClassName(_10.element,_10.hoverclass);
}
this.last_active=null;
},activate:function(_11){
if(_11.hoverclass){
Element.addClassName(_11.element,_11.hoverclass);
}
this.last_active=_11;
},show:function(_12,_13){
if(!this.drops.length){
return;
}
var _14=[];
if(this.last_active){
this.deactivate(this.last_active);
}
this.drops.each(function(_15){
if(Droppables.isAffected(_12,_13,_15)){
_14.push(_15);
}
});
if(_14.length>0){
drop=Droppables.findDeepestChild(_14);
Position.within(drop.element,_12[0],_12[1]);
if(drop.onHover){
drop.onHover(_13,drop.element,Position.overlap(drop.overlap,drop.element));
}
Droppables.activate(drop);
}
},fire:function(_16,_17){
if(!this.last_active){
return;
}
Position.prepare();
if(this.isAffected([Event.pointerX(_16),Event.pointerY(_16)],_17,this.last_active)){
if(this.last_active.onDrop){
this.last_active.onDrop(_17,this.last_active.element,_16);
}
}
},reset:function(){
if(this.last_active){
this.deactivate(this.last_active);
}
}};
var Draggables={drags:[],observers:[],register:function(_18){
if(this.drags.length==0){
this.eventMouseUp=this.endDrag.bindAsEventListener(this);
this.eventMouseMove=this.updateDrag.bindAsEventListener(this);
this.eventKeypress=this.keyPress.bindAsEventListener(this);
Event.observe(document,"mouseup",this.eventMouseUp);
Event.observe(document,"mousemove",this.eventMouseMove);
Event.observe(document,"keypress",this.eventKeypress);
}
this.drags.push(_18);
},unregister:function(_19){
this.drags=this.drags.reject(function(d){
return d==_19;
});
if(this.drags.length==0){
Event.stopObserving(document,"mouseup",this.eventMouseUp);
Event.stopObserving(document,"mousemove",this.eventMouseMove);
Event.stopObserving(document,"keypress",this.eventKeypress);
}
},activate:function(_1b){
if(_1b.options.delay){
this._timeout=setTimeout(function(){
Draggables._timeout=null;
window.focus();
Draggables.activeDraggable=_1b;
}.bind(this),_1b.options.delay);
}else{
window.focus();
this.activeDraggable=_1b;
}
},deactivate:function(){
this.activeDraggable=null;
},updateDrag:function(_1c){
if(!this.activeDraggable){
return;
}
var _1d=[Event.pointerX(_1c),Event.pointerY(_1c)];
if(this._lastPointer&&(this._lastPointer.inspect()==_1d.inspect())){
return;
}
this._lastPointer=_1d;
this.activeDraggable.updateDrag(_1c,_1d);
},endDrag:function(_1e){
if(this._timeout){
clearTimeout(this._timeout);
this._timeout=null;
}
if(!this.activeDraggable){
return;
}
this._lastPointer=null;
this.activeDraggable.endDrag(_1e);
this.activeDraggable=null;
},keyPress:function(_1f){
if(this.activeDraggable){
this.activeDraggable.keyPress(_1f);
}
},addObserver:function(_20){
this.observers.push(_20);
this._cacheObserverCallbacks();
},removeObserver:function(_21){
this.observers=this.observers.reject(function(o){
return o.element==_21;
});
this._cacheObserverCallbacks();
},notify:function(_23,_24,_25){
if(this[_23+"Count"]>0){
this.observers.each(function(o){
if(o[_23]){
o[_23](_23,_24,_25);
}
});
}
if(_24.options[_23]){
_24.options[_23](_24,_25);
}
},_cacheObserverCallbacks:function(){
["onStart","onEnd","onDrag"].each(function(_27){
Draggables[_27+"Count"]=Draggables.observers.select(function(o){
return o[_27];
}).length;
});
}};
var Draggable=Class.create();
Draggable._dragging={};
Draggable.prototype={initialize:function(_29){
var zdd=zk.ie&&arguments[1]&&arguments[1].z_dragdrop;
var _2b={handle:false,reverteffect:function(_2c,_2d,_2e){
var _2f=_2c.style.position;
var dur=Math.sqrt(Math.abs(_2d^2)+Math.abs(_2e^2))*0.02;
new Effect.Move(_2c,{x:-_2e,y:-_2d,duration:dur,queue:{scope:"_draggable",position:"end"}});
if(zdd&&_2f!="absolute"&&_2f!="relative"){
setTimeout(function(){
zkau._fixie4drop(_2c,_2f);
},dur*1000+10);
}
},endeffect:function(_31){
var _32=typeof _31._opacity=="number"?_31._opacity:1;
new Effect.Opacity(_31,{duration:0.2,from:0.7,to:_32,queue:{scope:"_draggable",position:"end"},afterFinish:function(){
Draggable._dragging[_31]=false;
}});
},zindex:1000,revert:false,scroll:false,scrollSensitivity:20,scrollSpeed:15,snap:false,delay:0};
if(!arguments[1]||typeof arguments[1].endeffect=="undefined"){
Object.extend(_2b,{starteffect:function(_33){
_33._opacity=Element.getOpacity(_33);
Draggable._dragging[_33]=true;
new Effect.Opacity(_33,{duration:0.2,from:_33._opacity,to:0.7});
}});
}
var _34=Object.extend(_2b,arguments[1]||{});
this.element=$(_29);
if(_34.handle&&(typeof _34.handle=="string")){
this.handle=this.element.down("."+_34.handle,0);
}
if(!this.handle){
this.handle=$(_34.handle);
}
if(!this.handle){
this.handle=this.element;
}
if(_34.scroll&&!_34.scroll.scrollTo&&!_34.scroll.outerHTML){
_34.scroll=$(_34.scroll);
this._isScrollChild=Element.childOf(this.element,_34.scroll);
}
if(zk.opera||!_34.z_dragdrop){
Element.makePositioned(this.element);
}
this.delta=this.currentDelta();
this.options=_34;
this.dragging=false;
this.eventMouseDown=this.initDrag.bindAsEventListener(this);
Event.observe(this.handle,"mousedown",this.eventMouseDown);
Draggables.register(this);
},destroy:function(){
Event.stopObserving(this.handle,"mousedown",this.eventMouseDown);
Draggables.unregister(this);
},currentDelta:function(){
return ([parseInt(Element.getStyle(this.element,"left")||"0"),parseInt(Element.getStyle(this.element,"top")||"0")]);
},initDrag:function(_35){
if(typeof Draggable._dragging[this.element]!="undefined"&&Draggable._dragging[this.element]){
return;
}
if(Event.isLeftClick(_35)){
var src=Event.element(_35);
if((tag_name=src.tagName.toUpperCase())&&(tag_name=="INPUT"||tag_name=="SELECT"||tag_name=="OPTION"||tag_name=="BUTTON"||tag_name=="TEXTAREA")){
return;
}
for(var n=src;n&&n!=this.element;n=n.parentNode){
if(Element.getStyle(n,"position")=="absolute"){
return;
}
}
var _38=[Event.pointerX(_35),Event.pointerY(_35)];
if(this.options.ignoredrag&&this.options.ignoredrag(this.element,_38)){
return;
}
zk.disableSelection(this.handle);
var pos=Position.cumulativeOffset(this.element);
this.offset=[0,1].map(function(i){
return (_38[i]-pos[i]);
});
Draggables.activate(this);
Event.stop(_35);
zkau.autoZIndex(src,false,true);
}
},startDrag:function(_3b){
this.dragging=true;
if(this.options.ghosting){
var _3c=true;
if(typeof this.options.ghosting=="function"){
_3c=this.options.ghosting(this,true);
}
if(_3c){
this._clone=this.element.cloneNode(true);
this.z_orgpos=this.element.style.position;
if(this.z_orgpos!="absolute"){
Position.absolutize(this.element);
}
this.element.parentNode.insertBefore(this._clone,this.element);
}
}
if(this.options.zindex){
this.originalZ=parseInt(Element.getStyle(this.element,"z-index")||0);
this.element.style.zIndex=this.options.zindex;
}
if(this.options.scroll){
if(this.options.scroll==window){
var _3d=this._getWindowScroll(this.options.scroll);
this.originalScrollLeft=_3d.left;
this.originalScrollTop=_3d.top;
}else{
this.originalScrollLeft=this.options.scroll.scrollLeft;
this.originalScrollTop=this.options.scroll.scrollTop;
}
}
Draggables.notify("onStart",this,_3b);
if(this.options.starteffect){
this.options.starteffect(this.element);
}
},updateDrag:function(_3e,_3f){
if(!this.dragging){
this.startDrag(_3e);
}
Position.prepare();
Droppables.show(_3f,this.element);
Draggables.notify("onDrag",this,_3e);
this.draw(_3f);
if(this.options.change){
this.options.change(this,_3f);
}
if(this.options.scroll){
this.stopScrolling();
var p;
if(this.options.scroll==window){
with(this._getWindowScroll(this.options.scroll)){
p=[left,top,left+width,top+height];
}
}else{
p=Position.page(this.options.scroll);
p[0]+=this.options.scroll.scrollLeft+Position.deltaX;
p[1]+=this.options.scroll.scrollTop+Position.deltaY;
p.push(p[0]+this.options.scroll.offsetWidth);
p.push(p[1]+this.options.scroll.offsetHeight);
}
var _41=[0,0];
if(_3f[0]<(p[0]+this.options.scrollSensitivity)){
_41[0]=_3f[0]-(p[0]+this.options.scrollSensitivity);
}
if(_3f[1]<(p[1]+this.options.scrollSensitivity)){
_41[1]=_3f[1]-(p[1]+this.options.scrollSensitivity);
}
if(_3f[0]>(p[2]-this.options.scrollSensitivity)){
_41[0]=_3f[0]-(p[2]-this.options.scrollSensitivity);
}
if(_3f[1]>(p[3]-this.options.scrollSensitivity)){
_41[1]=_3f[1]-(p[3]-this.options.scrollSensitivity);
}
this.startScrolling(_41);
}
if(navigator.appVersion.indexOf("AppleWebKit")>0){
window.scrollBy(0,0);
}
Event.stop(_3e);
},finishDrag:function(_42,_43){
this.dragging=false;
zk.enableSelection(this.handle);
setTimeout("zk.clearSelection()",0);
if(this.options.ghosting){
var _44=true;
if(typeof this.options.ghosting=="function"){
_44=this.options.ghosting(this,false);
}
if(_44){
if(this.z_orgpos!="absolute"){
Position.relativize(this.element);
this.element.style.position=this.z_orgpos;
}
Element.remove(this._clone);
this._clone=null;
}
}
if(_43){
Droppables.fire(_42,this.element);
}
Draggables.notify("onEnd",this,_42);
var _45=[Event.pointerX(_42),Event.pointerY(_42)];
var _46=this.options.revert;
if(_46&&typeof _46=="function"){
_46=_46(this.element,_45);
}
var d=this.currentDelta();
if(_46&&this.options.reverteffect){
this.options.reverteffect(this.element,d[1]-this.delta[1],d[0]-this.delta[0]);
}else{
this.delta=d;
}
if(this.options.zindex){
this.element.style.zIndex=this.originalZ;
}
if(this.options.endeffect){
this.options.endeffect(this.element,_42);
}
Draggables.deactivate(this);
Droppables.reset();
},keyPress:function(_48){
if(_48.keyCode!=Event.KEY_ESC){
return;
}
this.finishDrag(_48,false);
Event.stop(_48);
},endDrag:function(_49){
if(!this.dragging){
return;
}
this.stopScrolling();
this.finishDrag(_49,true);
Event.stop(_49);
},draw:function(_4a){
var pos=Position.cumulativeOffset(this.element);
if(this.options.ghosting){
var r=Position.realOffset(this.element);
pos[0]+=r[0]-Position.deltaX;
pos[1]+=r[1]-Position.deltaY;
}
var d=this.currentDelta();
pos[0]-=d[0];
pos[1]-=d[1];
if(this.options.scroll&&(this.options.scroll!=window&&this._isScrollChild)){
pos[0]-=this.options.scroll.scrollLeft-this.originalScrollLeft;
pos[1]-=this.options.scroll.scrollTop-this.originalScrollTop;
}
var p=[0,1].map(function(i){
return (_4a[i]-pos[i]-this.offset[i]);
}.bind(this));
if(this.options.snap){
if(typeof this.options.snap=="function"){
p=this.options.snap(p[0],p[1],this);
}else{
if(this.options.snap instanceof Array){
p=p.map(function(v,i){
return Math.round(v/this.options.snap[i])*this.options.snap[i];
}.bind(this));
}else{
p=p.map(function(v){
return Math.round(v/this.options.snap)*this.options.snap;
}.bind(this));
}
}
}
if(this.z_scrl){
p[0]-=this.z_scrl[0];
p[1]-=this.z_scrl[1];
}
var _53=this.element.style;
if(typeof this.options.constraint=="function"){
var np=this.options.constraint(this,p);
if(np){
p=np;
}
_53.left=p[0]+"px";
_53.top=p[1]+"px";
}else{
if((!this.options.constraint)||(this.options.constraint=="horizontal")){
_53.left=p[0]+"px";
}
if((!this.options.constraint)||(this.options.constraint=="vertical")){
_53.top=p[1]+"px";
}
}
if(_53.visibility=="hidden"){
_53.visibility="";
}
},stopScrolling:function(){
if(this.scrollInterval){
clearInterval(this.scrollInterval);
this.scrollInterval=null;
Draggables._lastScrollPointer=null;
}
},startScrolling:function(_55){
if(!(_55[0]||_55[1])){
return;
}
this.scrollSpeed=[_55[0]*this.options.scrollSpeed,_55[1]*this.options.scrollSpeed];
this.lastScrolled=new Date();
this.scrollInterval=setInterval(this.scroll.bind(this),10);
},scroll:function(){
var _56=new Date();
var _57=_56-this.lastScrolled;
this.lastScrolled=_56;
if(this.options.scroll==window){
with(this._getWindowScroll(this.options.scroll)){
if(this.scrollSpeed[0]||this.scrollSpeed[1]){
var d=_57/1000;
this.options.scroll.scrollTo(left+d*this.scrollSpeed[0],top+d*this.scrollSpeed[1]);
}
}
}else{
this.options.scroll.scrollLeft+=this.scrollSpeed[0]*_57/1000;
this.options.scroll.scrollTop+=this.scrollSpeed[1]*_57/1000;
}
Position.prepare();
Droppables.show(Draggables._lastPointer,this.element);
Draggables.notify("onDrag",this);
if(this._isScrollChild){
Draggables._lastScrollPointer=Draggables._lastScrollPointer||$A(Draggables._lastPointer);
Draggables._lastScrollPointer[0]+=this.scrollSpeed[0]*_57/1000;
Draggables._lastScrollPointer[1]+=this.scrollSpeed[1]*_57/1000;
if(Draggables._lastScrollPointer[0]<0){
Draggables._lastScrollPointer[0]=0;
}
if(Draggables._lastScrollPointer[1]<0){
Draggables._lastScrollPointer[1]=0;
}
this.draw(Draggables._lastScrollPointer);
}
if(this.options.change){
this.options.change(this);
}
},_getWindowScroll:function(w){
var T,L,W,H;
with(w.document){
if(w.document.documentElement&&documentElement.scrollTop){
T=documentElement.scrollTop;
L=documentElement.scrollLeft;
}else{
if(w.document.body){
T=body.scrollTop;
L=body.scrollLeft;
}
}
if(w.innerWidth){
W=w.innerWidth;
H=w.innerHeight;
}else{
if(w.document.documentElement&&documentElement.clientWidth){
W=documentElement.clientWidth;
H=documentElement.clientHeight;
}else{
W=body.offsetWidth;
H=body.offsetHeight;
}
}
}
return {top:T,left:L,width:W,height:H};
}};
Element.isParent=function(_5b,_5c){
if(!_5b.parentNode||_5b==_5c){
return false;
}
if(_5b.parentNode==_5c){
return true;
}
return Element.isParent(_5b.parentNode,_5c);
};
Element.findChildren=function(_5d,_5e,_5f,_60){
if(!_5d.hasChildNodes()){
return null;
}
_60=_60.toUpperCase();
if(_5e){
_5e=[_5e].flatten();
}
var _61=[];
$A(_5d.childNodes).each(function(e){
if(e.tagName&&e.tagName.toUpperCase()==_60&&(!_5e||(Element.classNames(e).detect(function(v){
return _5e.include(v);
})))){
_61.push(e);
}
if(_5f){
var _64=Element.findChildren(e,_5e,_5f,_60);
if(_64){
_61.push(_64);
}
}
});
return (_61.length>0?_61.flatten():[]);
};
Element.offsetSize=function(_65,_66){
if(_66=="vertical"||_66=="height"){
return zk.offsetHeight(_65);
}else{
return zk.offsetWidth(_65);
}
};

