dd-drag-min.js revision 7af29200d4331a905474d97a1a98a5a4bf873927
YUI.add("dd-drag",function(D){var E=D.DD.DDM,V="node",G="dragging",O="dragNode",C="offsetHeight",L="offsetWidth",K="gesturemove",T=K+"end",Q=K+"start",N="dragstart",H="drag:mouseDown",B="drag:afterMouseDown",F="drag:removeHandle",M="drag:addHandle",S="drag:removeInvalid",U="drag:addInvalid",J="drag:start",I="drag:end",P="drag:drag",R="drag:align",A=function(X){this._lazyAddAttrs=false;A.superclass.constructor.apply(this,arguments);var W=E._regDrag(this);if(!W){D.error("Failed to register node, already in use: "+X.node);}};A.NAME="drag";A.ATTRS={node:{setter:function(W){var X=D.one(W);if(!X){D.error("DD.Drag: Invalid Node Given: "+W);}else{X=X.item(0);}return X;}},dragNode:{setter:function(W){var X=D.one(W);if(!X){D.error("DD.Drag: Invalid dragNode Given: "+W);}return X;}},offsetNode:{value:true},startCentered:{value:false},clickPixelThresh:{value:E.get("clickPixelThresh")},clickTimeThresh:{value:E.get("clickTimeThresh")},lock:{value:false,setter:function(W){if(W){this.get(V).addClass(E.CSS_PREFIX+"-locked");}else{this.get(V).removeClass(E.CSS_PREFIX+"-locked");}return W;}},data:{value:false},move:{value:true},useShim:{value:true},activeHandle:{value:false},primaryButtonOnly:{value:true},dragging:{value:false},parent:{value:false},target:{value:false,setter:function(W){this._handleTarget(W);return W;}},dragMode:{value:null,setter:function(W){return E._setDragMode(W);}},groups:{value:["default"],getter:function(){if(!this._groups){this._groups={};}var W=[];D.each(this._groups,function(Y,X){W[W.length]=X;});return W;},setter:function(W){this._groups={};D.each(W,function(Y,X){this._groups[Y]=true;},this);return W;}},handles:{value:null,setter:function(W){if(W){this._handles={};D.each(W,function(Y,X){var Z=Y;if(Y instanceof D.Node||Y instanceof D.NodeList){Z=Y._yuid;}this._handles[Z]=Y;},this);}else{this._handles=null;}return W;}},bubbles:{setter:function(W){this.addTarget(W);return W;}}};D.extend(A,D.Base,{_bubbleTargets:D.DD.DDM,addToGroup:function(W){this._groups[W]=true;E._activateTargets();return this;},removeFromGroup:function(W){delete this._groups[W];E._activateTargets();return this;},target:null,_handleTarget:function(W){if(D.DD.Drop){if(W===false){if(this.target){E._unregTarget(this.target);this.target=null;}return false;}else{if(!D.Lang.isObject(W)){W={};}W.bubbleTargets=("bubbleTargets" in W)?W.bubbleTargets:D.Object.values(this._yuievt.targets);W.node=this.get(V);W.groups=W.groups||this.get("groups");this.target=new D.DD.Drop(W);}}else{return false;}},_groups:null,_createEvents:function(){this.publish(H,{defaultFn:this._defMouseDownFn,queuable:false,emitFacade:true,bubbles:true,prefix:"drag"});this.publish(R,{defaultFn:this._defAlignFn,queuable:false,emitFacade:true,bubbles:true,prefix:"drag"});this.publish(P,{defaultFn:this._defDragFn,queuable:false,emitFacade:true,bubbles:true,prefix:"drag"});this.publish(I,{preventedFn:this._prevEndFn,queuable:false,emitFacade:true,bubbles:true,prefix:"drag"});var W=[B,F,M,S,U,J,"drag:drophit","drag:dropmiss","drag:over","drag:enter","drag:exit"];D.each(W,function(Y,X){this.publish(Y,{type:Y,emitFacade:true,bubbles:true,preventable:false,queuable:false,prefix:"drag"});},this);},_ev_md:null,_startTime:null,_endTime:null,_handles:null,_invalids:null,_invalidsDefault:{"textarea":true,"input":true,"a":true,"button":true,"select":true},_dragThreshMet:null,_fromTimeout:null,_clickTimeout:null,deltaXY:null,startXY:null,nodeXY:null,lastXY:null,actXY:null,realXY:null,mouseXY:null,region:null,_handleMouseUp:function(W){this._fixIEMouseUp();if(E.activeDrag){E._end();}},_fixDragStart:function(W){W.preventDefault();},_ieSelectFix:function(){return false;},_ieSelectBack:null,_fixIEMouseDown:function(){if(D.UA.ie){this._ieSelectBack=D.config.doc.body.onselectstart;D.config.doc.body.onselectstart=this._ieSelectFix;}},_fixIEMouseUp:function(){if(D.UA.ie){D.config.doc.body.onselectstart=this._ieSelectBack;}},_handleMouseDownEvent:function(W){this.fire(H,{ev:W});},_defMouseDownFn:function(Y){var W=Y.ev,X=W._orig||W;this._dragThreshMet=false;this._ev_md=W;if(this.get("primaryButtonOnly")&&W.button>1){}if(this.validClick(W)){this._fixIEMouseDown();X.halt();this._setStartPosition([W.pageX,W.pageY]);E.activeDrag=this;this._clickTimeout=D.later(this.get("clickTimeThresh"),this,this._timeoutCheck);}this.fire(B,{ev:W});},validClick:function(a){var Z=false,d=false,W=a.target,Y=null,X=null,b=null,c=false;if(this._handles){D.each(this._handles,function(e,f){if(e instanceof D.Node||e instanceof D.NodeList){if(!Z){b=e;if(b instanceof D.Node){b=new D.NodeList(e._node);}b.each(function(g){if(g.contains(W)){Z=true;}});}}else{if(D.Lang.isString(f)){if(W.test(f+", "+f+" *")&&!Y){Y=f;Z=true;}}}});}else{d=this.get(V);if(d.contains(W)||d.compareTo(W)){Z=true;}}if(Z){if(this._invalids){D.each(this._invalids,function(e,f){if(D.Lang.isString(f)){if(W.test(f+", "+f+" *")){Z=false;}}});}}if(Z){if(Y){X=a.currentTarget.all(Y);c=false;X.each(function(f,e){if((f.contains(W)||f.compareTo(W))&&!c){c=true;this.set("activeHandle",f);}},this);}else{this.set("activeHandle",this.get(V));}}return Z;},_setStartPosition:function(W){this.startXY=W;this.nodeXY=this.lastXY=this.realXY=this.get(V).getXY();if(this.get("offsetNode")){this.deltaXY=[(this.startXY[0]-this.nodeXY[0]),(this.startXY[1]-this.nodeXY[1])];}else{this.deltaXY=[0,0];}},_timeoutCheck:function(){if(!this.get("lock")&&!this._dragThreshMet&&this._ev_md){this._fromTimeout=this._dragThreshMet=true;this.start();this._alignNode([this._ev_md.pageX,this._ev_md.pageY],true);}},removeHandle:function(X){var W=X;if(X instanceof D.Node||X instanceof D.NodeList){W=X._yuid;}if(this._handles[W]){delete this._handles[W];this.fire(F,{handle:X});}return this;},addHandle:function(X){if(!this._handles){this._handles={};}var W=X;if(X instanceof D.Node||X instanceof D.NodeList){W=X._yuid;}this._handles[W]=X;this.fire(M,{handle:X});return this;},removeInvalid:function(W){if(this._invalids[W]){this._invalids[W]=null;delete this._invalids[W];this.fire(S,{handle:W});
}return this;},addInvalid:function(W){if(D.Lang.isString(W)){this._invalids[W]=true;this.fire(U,{handle:W});}return this;},initializer:function(W){this.get(V).dd=this;if(!this.get(V).get("id")){var X=D.stamp(this.get(V));this.get(V).set("id",X);}this.actXY=[];this._invalids=D.clone(this._invalidsDefault,true);this._createEvents();if(!this.get(O)){this.set(O,this.get(V));}this.on("initializedChange",D.bind(this._prep,this));this.set("groups",this.get("groups"));},_prep:function(){this._dragThreshMet=false;var W=this.get(V);W.addClass(E.CSS_PREFIX+"-draggable");W.on(Q,D.bind(this._handleMouseDownEvent,this),{minDistance:0,minTime:0});W.setData("dd",true);W.on(T,D.bind(this._handleMouseUp,this),{standAlone:true});W.on(N,D.bind(this._fixDragStart,this));W.on(K,D.throttle(D.bind(E._move,E),E.get("throttleTime")),{standAlone:true});},_unprep:function(){var W=this.get(V);W.removeClass(E.CSS_PREFIX+"-draggable");W.detachAll();},start:function(){if(!this.get("lock")&&!this.get(G)){var X=this.get(V),W,Y,Z;this._startTime=(new Date()).getTime();E._start();X.addClass(E.CSS_PREFIX+"-dragging");this.fire(J,{pageX:this.nodeXY[0],pageY:this.nodeXY[1],startTime:this._startTime});X=this.get(O);Z=this.nodeXY;W=X.get(L);Y=X.get(C);if(this.get("startCentered")){this._setStartPosition([Z[0]+(W/2),Z[1]+(Y/2)]);}this.region={"0":Z[0],"1":Z[1],area:0,top:Z[1],right:Z[0]+W,bottom:Z[1]+Y,left:Z[0]};this.set(G,true);}return this;},end:function(){this._endTime=(new Date()).getTime();if(this._clickTimeout){this._clickTimeout.cancel();}this._dragThreshMet=this._fromTimeout=false;this._ev_md=null;if(!this.get("lock")&&this.get(G)){this.fire(I,{pageX:this.lastXY[0],pageY:this.lastXY[1],startTime:this._startTime,endTime:this._endTime});}this.get(V).removeClass(E.CSS_PREFIX+"-dragging");this.set(G,false);this.deltaXY=[0,0];return this;},_prevEndFn:function(W){this.get(O).setXY(this.nodeXY);},_align:function(W){this.fire(R,{pageX:W[0],pageY:W[1]});},_defAlignFn:function(W){this.actXY=[W.pageX-this.deltaXY[0],W.pageY-this.deltaXY[1]];},_alignNode:function(W){this._align(W);this._moveNode();},_moveNode:function(W){var X=[],Y=[],a=this.nodeXY,Z=this.actXY;X[0]=(Z[0]-this.lastXY[0]);X[1]=(Z[1]-this.lastXY[1]);Y[0]=(Z[0]-this.nodeXY[0]);Y[1]=(Z[1]-this.nodeXY[1]);this.region={"0":Z[0],"1":Z[1],area:0,top:Z[1],right:Z[0]+this.get(O).get(L),bottom:Z[1]+this.get(O).get(C),left:Z[0]};this.fire(P,{pageX:Z[0],pageY:Z[1],scroll:W,info:{start:a,xy:Z,delta:X,offset:Y}});this.lastXY=Z;},_defDragFn:function(W){if(this.get("move")){if(W.scroll){W.scroll.node.set("scrollTop",W.scroll.top);W.scroll.node.set("scrollLeft",W.scroll.left);}this.get(O).setXY([W.pageX,W.pageY]);this.realXY=[W.pageX,W.pageY];}},_move:function(Y){if(this.get("lock")){return false;}else{this.mouseXY=[Y.pageX,Y.pageY];if(!this._dragThreshMet){var X=Math.abs(this.startXY[0]-Y.pageX),W=Math.abs(this.startXY[1]-Y.pageY);if(X>this.get("clickPixelThresh")||W>this.get("clickPixelThresh")){this._dragThreshMet=true;this.start();this._alignNode([Y.pageX,Y.pageY]);}}else{if(this._clickTimeout){this._clickTimeout.cancel();}this._alignNode([Y.pageX,Y.pageY]);}}},stopDrag:function(){if(this.get(G)){E._end();}return this;},destructor:function(){this._unprep();this.detachAll();if(this.target){this.target.destroy();}E._unregDrag(this);}});D.namespace("DD");D.DD.Drag=A;},"@VERSION@",{requires:["dd-ddm-base","event-synthetic","event-gestures"],skinnable:false});