/*
	Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/

//>>built
define("dojo/dnd/Source","../_base/array ../_base/declare ../_base/kernel ../_base/lang ../dom-class ../dom-geometry ../mouse ../ready ../topic ./common ./Selector ./Manager".split(" "),function(q,r,t,h,k,p,u,v,m,n,w,l){t.isAsync||v(0,function(){require(["dojo/dnd/AutoSource","dojo/dnd/Target"])});var g=r("dojo.dnd.Source",w,{isSource:!0,horizontal:!1,copyOnly:!1,selfCopy:!1,selfAccept:!0,skipForm:!1,withHandles:!1,autoSync:!1,delay:0,accept:["text"],generateText:!0,constructor:function(a,c){h.mixin(this,
h.mixin({},c));var b=this.accept;if(b.length){this.accept={};for(var d=0;d<b.length;++d)this.accept[b[d]]=1}this.mouseDown=this.isDragging=!1;this.targetBox=this.targetAnchor=null;this.before=!0;this._lastY=this._lastX=0;this.sourceState="";this.isSource&&k.add(this.node,"dojoDndSource");this.targetState="";this.accept&&k.add(this.node,"dojoDndTarget");this.horizontal&&k.add(this.node,"dojoDndHorizontal");this.topics=[m.subscribe("/dnd/source/over",h.hitch(this,"onDndSourceOver")),m.subscribe("/dnd/start",
h.hitch(this,"onDndStart")),m.subscribe("/dnd/drop",h.hitch(this,"onDndDrop")),m.subscribe("/dnd/cancel",h.hitch(this,"onDndCancel"))]},checkAcceptance:function(a,c){if(this==a)return!this.copyOnly||this.selfAccept;for(var b=0;b<c.length;++b){for(var d=a.getItem(c[b].id).type,e=!1,f=0;f<d.length;++f)if(d[f]in this.accept){e=!0;break}if(!e)return!1}return!0},copyState:function(a,c){if(a)return!0;2>arguments.length&&(c=this==l.manager().target);if(c){if(this.copyOnly)return this.selfCopy}else return this.copyOnly;
return!1},destroy:function(){g.superclass.destroy.call(this);q.forEach(this.topics,function(a){a.remove()});this.targetAnchor=null},onMouseMove:function(a){if(!this.isDragging||"Disabled"!=this.targetState){g.superclass.onMouseMove.call(this,a);var c=l.manager();if(!this.isDragging&&this.mouseDown&&this.isSource&&(Math.abs(a.pageX-this._lastX)>this.delay||Math.abs(a.pageY-this._lastY)>this.delay)){var b=this.getSelectedNodes();b.length&&c.startDrag(this,b,this.copyState(n.getCopyKeyState(a),!0))}this.isDragging&&
(b=!1,this.current&&(this.targetBox&&this.targetAnchor==this.current||(this.targetBox=p.position(this.current,!0)),b=this.horizontal?a.pageX-this.targetBox.x<this.targetBox.w/2==p.isBodyLtr(this.current.ownerDocument):a.pageY-this.targetBox.y<this.targetBox.h/2),this.current!=this.targetAnchor||b!=this.before)&&(this._markTargetAnchor(b),c.canDrop(!this.current||c.source!=this||!(this.current.id in this.selection)))}},onMouseDown:function(a){this.mouseDown||!this._legalMouseDown(a)||this.skipForm&&
n.isFormElement(a)||(this.mouseDown=!0,this._lastX=a.pageX,this._lastY=a.pageY,g.superclass.onMouseDown.call(this,a))},onMouseUp:function(a){this.mouseDown&&(this.mouseDown=!1,g.superclass.onMouseUp.call(this,a))},onDndSourceOver:function(a){this!==a?(this.mouseDown=!1,this.targetAnchor&&this._unmarkTargetAnchor()):this.isDragging&&(a=l.manager(),a.canDrop("Disabled"!=this.targetState&&(!this.current||a.source!=this||!(this.current.id in this.selection))))},onDndStart:function(a,c,b){this.autoSync&&
this.sync();this.isSource&&this._changeState("Source",this==a?b?"Copied":"Moved":"");c=this.accept&&this.checkAcceptance(a,c);this._changeState("Target",c?"":"Disabled");this==a&&l.manager().overSource(this);this.isDragging=!0},onDndDrop:function(a,c,b,d){if(this==d)this.onDrop(a,c,b);this.onDndCancel()},onDndCancel:function(){this.targetAnchor&&(this._unmarkTargetAnchor(),this.targetAnchor=null);this.before=!0;this.mouseDown=this.isDragging=!1;this._changeState("Source","");this._changeState("Target",
"")},onDrop:function(a,c,b){if(this!=a)this.onDropExternal(a,c,b);else this.onDropInternal(c,b)},onDropExternal:function(a,c,b){var d=this._normalizedCreator;this._normalizedCreator=this.creator?function(e,f){return d.call(this,a.getItem(e.id).data,f)}:b?function(e){var f=a.getItem(e.id);e=e.cloneNode(!0);e.id=n.getUniqueId();return{node:e,data:f.data,type:f.type}}:function(e){var f=a.getItem(e.id);a.delItem(e.id);return{node:e,data:f.data,type:f.type}};this.selectNone();b||this.creator||a.selectNone();
this.insertNodes(!0,c,this.before,this.current);!b&&this.creator&&a.deleteSelectedNodes();this._normalizedCreator=d},onDropInternal:function(a,c){var b=this._normalizedCreator;if(!(this.current&&this.current.id in this.selection)){if(c)this._normalizedCreator=this.creator?function(d,e){return b.call(this,this.getItem(d.id).data,e)}:function(d){var e=this.getItem(d.id);d=d.cloneNode(!0);d.id=n.getUniqueId();return{node:d,data:e.data,type:e.type}};else{if(!this.current)return;this._normalizedCreator=
function(d){var e=this.getItem(d.id);return{node:d,data:e.data,type:e.type}}}this._removeSelection();this.insertNodes(!0,a,this.before,this.current);this._normalizedCreator=b}},onDraggingOver:function(){},onDraggingOut:function(){},onOverEvent:function(){g.superclass.onOverEvent.call(this);l.manager().overSource(this);if(this.isDragging&&"Disabled"!=this.targetState)this.onDraggingOver()},onOutEvent:function(){g.superclass.onOutEvent.call(this);l.manager().outSource(this);if(this.isDragging&&"Disabled"!=
this.targetState)this.onDraggingOut()},_markTargetAnchor:function(a){if(this.current!=this.targetAnchor||this.before!=a)this.targetAnchor&&this._removeItemClass(this.targetAnchor,this.before?"Before":"After"),this.targetAnchor=this.current,this.targetBox=null,this.before=a,this.targetAnchor&&this._addItemClass(this.targetAnchor,this.before?"Before":"After")},_unmarkTargetAnchor:function(){this.targetAnchor&&(this._removeItemClass(this.targetAnchor,this.before?"Before":"After"),this.targetBox=this.targetAnchor=
null,this.before=!0)},_markDndStatus:function(a){this._changeState("Source",a?"Copied":"Moved")},_legalMouseDown:function(a){if("touchstart"!=a.type&&!u.isLeft(a))return!1;if(!this.withHandles)return!0;for(a=a.target;a&&a!==this.node;a=a.parentNode){if(k.contains(a,"dojoDndHandle"))return!0;if(k.contains(a,"dojoDndItem")||k.contains(a,"dojoDndIgnore"))break}return!1}});return g});