/*
Copyright 2013, KISSY UI Library v1.31
MIT Licensed
build time: Jan 15 13:39
*/
KISSY.add("dd/base",function(g,l,h,f){g={Draggable:h,DDM:l,DraggableDelegate:f};return KISSY.DD=g},{requires:["./base/ddm","./base/draggable","./base/draggable-delegate"]});
KISSY.add("dd/base/ddm",function(g,l,h,f,t){function n(){n.superclass.constructor.apply(this,arguments)}function o(a){a.preventDefault();C.call(this,a)}function s(a,u,i){var d=i.get("mode"),c=a.get("validDrops"),e=0,f=0,h=j(i.get("node")),k=p(h);g.each(c,function(a){var c;if(c=a.getNodeFromTarget(u,i.get("dragNode")[0],i.get("node")[0]))if("point"==d)v(j(c),i.mousePos)&&(c=p(j(c)),e?c<f&&(e=a,f=c):(e=a,f=c));else if("intersect"==d)c=p(b(h,j(c))),c>f&&(f=c,e=a);else if("strict"==d&&(c=p(b(h,j(c))),
c==k))return e=a,!1});if((c=a.get("activeDrop"))&&c!=e)c._handleOut(u),i._handleOut(u);a.setInternal("activeDrop",e);e&&(c!=e?e._handleEnter(u):e._handleOver(u))}function q(a){a._shim=(new f('<div style="background-color:red;position:'+(w?"absolute":"fixed")+";left:0;width:100%;height:100%;top:0;cursor:"+m.get("dragCursor")+";z-index:"+D+';"></div>')).prependTo(r.body||r.documentElement).css("opacity",0);q=c;if(w)h.on(e,"resize scroll",y,a);c(a)}function c(a){var b=a.get("activeDrag").get("activeHandler"),
c="auto";b&&(c=b.css("cursor"));"auto"==c&&(c=a.get("dragCursor"));a._shim.css({cursor:c,display:"block"});w&&y.call(a)}function x(a){var b=a.get("drops");a.setInternal("validDrops",[]);g.each(b,function(a){a._active()})}function k(a){var b=a.get("drops");a.setInternal("validDrops",[]);g.each(b,function(a){a._deActive()})}function j(a){var b=a.offset();return{left:b.left,right:b.left+(a.__dd_cached_width||a.outerWidth()),top:b.top,bottom:b.top+(a.__dd_cached_height||a.outerHeight())}}function v(a,
b){return a.left<=b.left&&a.right>=b.left&&a.top<=b.top&&a.bottom>=b.top}function p(a){return a.top>=a.bottom||a.left>=a.right?0:(a.right-a.left)*(a.bottom-a.top)}function b(a,b){var c=Math.max(a.top,b.top),i=Math.min(a.right,b.right),d=Math.min(a.bottom,b.bottom);return{left:Math.max(a.left,b.left),right:i,top:c,bottom:d}}function i(a){a&&(a.__dd_cached_width=a.outerWidth(),a.__dd_cached_height=a.outerHeight())}var d=g.UA,e=g.Env.host,r=e.document,w=6===d.ie,D=999999,z=h.Gesture,A=z.move,B=z.end;
n.ATTRS={dragCursor:{value:"move"},clickPixelThresh:{value:3},bufferTime:{value:1},activeDrag:{},activeDrop:{},drops:{value:[]},validDrops:{value:[]}};var C=g.throttle(function(a){var b;if(a=m._normalEvent(a))if(a.preventDefault(),b=this.__activeToDrag)b._move(a);else if(b=this.get("activeDrag"))b._move(a),s(this,a,b)},30),y=g.throttle(function(){var a;(a=this.get("activeDrag"))&&a.get("shim")&&this._shim.css({width:l.docWidth(),height:l.docHeight()})},30);g.extend(n,t,{__activeToDrag:0,_regDrop:function(a){this.get("drops").push(a)},
_unRegDrop:function(a){a=g.indexOf(a,this.get("drops"));-1!=a&&this.get("drops").splice(a,1)},_regToDrag:function(a){this.__activeToDrag=a;h.on(r,B,this._end,this);h.on(r,A,o,this);6===d.ie&&r.body.setCapture()},_start:function(){this.get("drops");var a=this.__activeToDrag;this.setInternal("activeDrag",a);this.__activeToDrag=0;a.get("shim")&&q(this);i(a.get("node"));x(this)},_addValidDrop:function(a){this.get("validDrops").push(a)},_end:function(){var a=this.get("activeDrag"),b=this.get("activeDrop");
h.remove(r,A,o,this);h.remove(r,B,this._end,this);6===d.ie&&r.body.releaseCapture();this.__activeToDrag&&(this.__activeToDrag._end(),this.__activeToDrag=0);this._shim&&this._shim.hide();a&&(a._end(),k(this),b&&b._end(),this.setInternal("activeDrag",null),this.setInternal("activeDrop",null))}});var m=new n;m.inRegion=v;m.region=j;m.area=p;m.cacheWH=i;m.PREFIX_CLS="ks-dd-";m._normalEvent=function(a){var b=a.touches;if(b){if(1!=b.length)return;b=b[0];a.target=a.target||b.target;a.currentTarget=a.currentTarget||
b.currentTarget;a.which=1;a.pageX=b.pageX;a.pageY=b.pageY}return a};return m},{requires:["dom","event","node","base"]});
KISSY.add("dd/base/draggable-delegate",function(g,l,h,f,t,n){var o=l.PREFIX_CLS,s=n.Gesture.start,q=function(c){if(c=l._normalEvent(c)){var f,g;if(this._checkDragStartValid(c)){f=this.get("handlers");var h=new t(c.target);(f=f.length?this._getHandler(h):h)&&(g=this._getNode(f));g&&(this.setInternal("activeHandler",f),this.setInternal("node",g),this.setInternal("dragNode",g),this._prepare(c))}}};return h.extend({_onSetNode:function(){},_onSetContainer:function(){this.bindDragEvent()},_onSetDisabledChange:function(c){this.get("container")[c?
"addClass":"removeClass"](o+"-disabled")},bindDragEvent:function(){this.get("container").on(s,q,this).on("dragstart",this._fixDragStart)},detachDragEvent:function(){this.get("container").detach(s,q,this).detach("dragstart",this._fixDragStart)},_getHandler:function(c){for(var h=void 0,k=this.get("container"),j=this.get("handlers");c&&c[0]!==k[0];){g.each(j,function(g){if(f.test(c[0],g))return h=c,!1});if(h)break;c=c.parent()}return h},_getNode:function(c){return c.closest(this.get("selector"),this.get("container"))}},
{ATTRS:{container:{setter:function(c){return t.one(c)}},selector:{},handlers:{value:[],getter:0}}})},{requires:["./ddm","./draggable","dom","node","event"]});
KISSY.add("dd/base/draggable",function(g,l,h,f,t){function n(){return!1}var o=l.all,s=g.each,q=t.Gesture.start,c=g.UA.ie,x=g.Features,k=f.PREFIX_CLS,j=g.Env.host.document,h=h.extend({initializer:function(){this.addTarget(f)},_onSetNode:function(b){this.setInternal("dragNode",b);this.bindDragEvent()},bindDragEvent:function(){this.get("node").on(q,p,this).on("dragstart",this._fixDragStart)},detachDragEvent:function(){this.get("node").detach(q,p,this).detach("dragstart",this._fixDragStart)},_bufferTimer:null,
_onSetDisabledChange:function(b){this.get("dragNode")[b?"addClass":"removeClass"](k+"-disabled")},_fixDragStart:function(b){b.preventDefault()},_checkHandler:function(b){var c=this,d=c.get("handlers"),e=0;s(d,function(d){if(d.contains(b)||d[0]==b)return e=1,c.setInternal("activeHandler",d),!1});return e},_checkDragStartValid:function(b){return this.get("primaryButtonOnly")&&1!=b.which||this.get("disabled")?0:1},_prepare:function(b){if(b){var i=this;o(b.target);c&&(v=j.body.onselectstart,j.body.onselectstart=
n);i.get("halt")&&b.stopPropagation();x.isTouchSupported()||b.preventDefault();var d=i.get("node"),e=b.pageX,b=b.pageY,d=d.offset();i.setInternal("startMousePos",i.mousePos={left:e,top:b});i.setInternal("startNodePos",d);i.setInternal("deltaPos",{left:e-d.left,top:b-d.top});f._regToDrag(i);if(e=i.get("bufferTime"))i._bufferTimer=setTimeout(function(){i._start()},1E3*e)}},_clearBufferTimer:function(){this._bufferTimer&&(clearTimeout(this._bufferTimer),this._bufferTimer=0)},_move:function(b){var c;
c=b.pageX;b=b.pageY;if(this.get("dragging")){var d=this.get("deltaPos"),e=c-d.left,d=b-d.top;this.mousePos={left:c,top:b};c={left:e,top:d,pageX:c,pageY:b,drag:this};this.setInternal("actualPos",{left:e,top:d});this.fire("dragalign",c);b=1;!1===this.fire("drag",c)&&(b=0);b&&this.get("move")&&this.get("node").offset(this.get("actualPos"))}else e=this.get("startMousePos"),d=this.get("clickPixelThresh"),(Math.abs(c-e.left)>=d||Math.abs(b-e.top)>=d)&&this._start()},stopDrag:function(){f._end()},_end:function(){var b;
this._clearBufferTimer();c&&(j.body.onselectstart=v);this.get("dragging")&&(this.get("node").removeClass(k+"drag-over"),(b=f.get("activeDrop"))?this.fire("dragdrophit",{drag:this,drop:b}):this.fire("dragdropmiss",{drag:this}),this.setInternal("dragging",0),this.fire("dragend",{drag:this}))},_handleOut:function(){this.get("node").removeClass(k+"drag-over");this.fire("dragexit",{drag:this,drop:f.get("activeDrop")})},_handleEnter:function(b){this.get("node").addClass(k+"drag-over");this.fire("dragenter",
b)},_handleOver:function(b){this.fire("dragover",b)},_start:function(){this._clearBufferTimer();this.setInternal("dragging",1);f._start();this.fire("dragstart",{drag:this})},destructor:function(){this.detachDragEvent();this.detach()}},{ATTRS:{node:{setter:function(b){if(!(b instanceof l))return o(b)}},clickPixelThresh:{valueFn:function(){return f.get("clickPixelThresh")}},bufferTime:{valueFn:function(){return f.get("bufferTime")}},dragNode:{},shim:{value:!0},handlers:{value:[],getter:function(b){var c=
this;b.length||(b[0]=c.get("node"));s(b,function(d,e){g.isFunction(d)&&(d=d.call(c));"string"==typeof d&&(d=c.get("node").one(d));d.nodeType&&(d=o(d));b[e]=d});c.setInternal("handlers",b);return b}},activeHandler:{},dragging:{value:!1,setter:function(b){this.get("dragNode")[b?"addClass":"removeClass"](k+"dragging")}},mode:{value:"point"},disabled:{value:!1},move:{value:!1},primaryButtonOnly:{value:!0},halt:{value:!0},groups:{value:{}},startMousePos:{},startNodePos:{},deltaPos:{},actualPos:{}}});h.DropMode=
{POINT:"point",INTERSECT:"intersect",STRICT:"strict"};var v,p=function(b){if(b=f._normalEvent(b)){var c=b.target;this._checkDragStartValid(b)&&this._checkHandler(c)&&this._prepare(b)}};return h},{requires:["node","rich-base","./ddm","event"]});
