!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.ReactReorderable=e()}}(function(){return function e(t,n,r){function o(a,s){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return o(n?n:e)},c,c.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){(function(e){"use strict";function n(e){for(;e;){if(e.className&&e.className.indexOf("react-reorderable-item")>=0)return e;e=e.parentNode}return null}function r(e){var t=e.touches&&e.touches[0]||e;return{clientX:t.clientX,clientY:t.clientY}}function o(e,t){var n=t.getBoundingClientRect(),o=n.top,i=n.left,a=n.width,s=n.height,l=r(e);return l.clientY<o||l.clientY>o+s?p.NONE:l.clientX>i&&l.clientX<i+.5*a?p.NEXT:l.clientX>i+.5*a&&l.clientX<i+a?p.PREVIOUS:p.NONE}function i(e,t){var n=t.getBoundingClientRect(),o=n.top,i=n.left,a=n.width,s=n.height,l=r(e);return l.clientX<i||l.clientX>i+a?p.NONE:l.clientY>o&&l.clientY<o+.5*s?p.NEXT:l.clientY>o+.5*s&&l.clientY<o+s?p.PREVIOUS:p.NONE}function a(e,t,n){var r,a=t.parentNode,s=a.children,l=!1,u={};n=n||"list";for(var c=0;c<s.length&&!l;c+=1)if(r=s[c],r.getAttribute("data-reorderable-key")!==t.getAttribute("data-reorderable-key")){var d;if(d="list"===n?i(e,r):o(e,r),d!==p.NONE)return u.node=r,u.type=d,u}return u}function s(e){for(var t,n="node-",r={},o=[],i=0;i<e.length;i+=1){var t=n+(i+1);o.push(t),e[i]=c.createElement("div",{className:"react-reorderable-item",key:t,"data-reorderable-key":t},e[i]),r[t]=e[i]}return{map:r,ids:o}}function l(e,t){for(var n=e.parentNode.querySelectorAll(t),r=0;r<n.length;r+=1)if(e===n[r])return!0;return!1}function u(e,t,n){var r=e.getAttribute("data-reorderable-key"),o=n.indexOf(r);n.splice(o,1);var i=t.node.getAttribute("data-reorderable-key"),a=n.indexOf(i);return t.type===p.PREVIOUS?n.splice(a+1,0,r):n.splice(a,0,r),n}var c="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,d=("undefined"!=typeof window?window.ReactDOM:"undefined"!=typeof e?e.ReactDOM:null).findDOMNode,f="undefined"!=typeof window?window.ReactDrag:"undefined"!=typeof e?e.ReactDrag:null,p={NONE:0,NEXT:1,PREVIOUS:2},h=c.createClass({componentWillMount:function(){window.addEventListener("mouseup",this._mouseupHandler=function(){this.setState({mouseDownPosition:null})}.bind(this))},componentWillUnmount:function(){window.removeEventListener("mouseup",this._mouseupHandler)},componentWillReceiveProps:function(e){if(e.children){var t=s(e.children);this.setState({order:t.ids,reorderableMap:t.map})}},getInitialState:function(){var e=s(this.props.children);return{order:e.ids,startPosition:null,activeItem:null,reorderableMap:e.map}},onDragStop:function(e){this.setState({activeItem:null,startPosition:null}),this.props.onDrop(this.state.order.map(function(e){return this.state.reorderableMap[e].props.children},this))},onDrag:function(e){var t=d(this.refs.handle),r=a(e,t,this.props.mode);if(r&&r.node){for(var o=this.state.order.slice(),i=u(n(t),r,this.state.order),s=!1,l=0;l<i.length&&!s;l+=1)i[l]!==o[l]&&(s=!0);s&&this.props.onChange(this.state.order.map(function(e){return this.state.reorderableMap[e].props.children},this)),this.setState({order:i})}},onMouseDown:function(e){var t;(!this.props.handle||l(e.target,this.props.handle))&&(t=r(e),this.setState({mouseDownPosition:{x:t.clientX,y:t.clientY}}))},onTouchStart:function(e){e.preventDefault(),this.onMouseDown(e)},onMouseMove:function(e){var t;if(!this.state.activeItem){var o=this.state.mouseDownPosition;if(!o)return;if(t=r(e),Math.abs(t.clientX-o.x)>=5||Math.abs(t.clientY-o.y)>=5){var i=n(e.target),a=e.nativeEvent,s=i.getAttribute("data-reorderable-key");this.props.onDragStart(this.state.reorderableMap[s]),this.activeItem=i;var l=i.parentNode&&i.parentNode.parentNode;this.setState({mouseDownPosition:null,activeItem:s,startPosition:{x:i.offsetLeft-(l&&l.scrollLeft||0),y:i.offsetTop-(l&&l.scrollTop||0)}},function(){this.refs.handle.handleDragStart(a)}.bind(this))}}},render:function(){var e,t=this.state.order.map(function(e){var t=this.state.activeItem?"noselect ":"";this.state.activeItem===e&&(t+="react-reorderable-item-active");var n=this.state.reorderableMap[e].props.className||"";return n&&(t=n+" "+t),c.cloneElement(this.state.reorderableMap[e],{key:"reaorderable-"+e,ref:"active",onMouseDown:this.onMouseDown,onMouseMove:this.onMouseMove,onTouchStart:this.onTouchStart,onTouchMove:this.onMouseMove,className:t})},this);if(this.state.activeItem){var n=this.state.startPosition,r="react-reorderable-handle",o=this.state.reorderableMap[this.state.activeItem].props.className||"";o&&(r=o+" "+r),e=c.cloneElement(this.state.reorderableMap[this.state.activeItem],{className:r}),e=c.createElement(f,{onStop:this.onDragStop,onDrag:this.onDrag,ref:"handle",start:{x:n.x,y:n.y}},e)}return c.createElement("div",{ref:"wrapper"},t,e)}});h.propTypes={onDragStart:c.PropTypes.func,onDrag:c.PropTypes.func,onDrop:c.PropTypes.func,onChange:c.PropTypes.func},h.defaultProps={onDragStart:function(){},onDrag:function(){},onDrop:function(){},onChange:function(){}},t.exports=h}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1])(1)});