!function(e,t,o){"use strict";t.module("ui.sortable",[]).value("uiSortableConfig",{items:"> [ng-repeat],> [data-ng-repeat],> [x-ng-repeat]"}).directive("uiSortable",["uiSortableConfig","$timeout","$log",function(e,n,i){return{require:"?ngModel",scope:{ngModel:"=",uiSortable:"=",create:"&uiSortableCreate",start:"&uiSortableStart",activate:"&uiSortableActivate",beforeStop:"&uiSortableBeforeStop",update:"&uiSortableUpdate",remove:"&uiSortableRemove",receive:"&uiSortableReceive",deactivate:"&uiSortableDeactivate",stop:"&uiSortableStop"},link:function(r,l,a,s){var u,c;function d(e,t){var o="function"==typeof t;return"function"==typeof e&&o?function(){e.apply(this,arguments),t.apply(this,arguments)}:o?t:e}function f(e){var t=e.data("ui-sortable");return t&&"object"==typeof t&&"ui-sortable"===t.widgetFullName?t:null}function m(t,o){return y[t]?("stop"===t&&(o=d(o,function(){r.$apply()}),o=d(o,v)),o=d(y[t],o)):C[t]&&(o=C[t](o)),o||"items"!==t&&"ui-model-items"!==t||(o=e.items),o}function p(e,n,i){t.forEach(y,function(e,t){t in h||(h[t]=null)});var r,l=null;n&&t.forEach(n,function(n,i){if(!(e&&i in e)){if(i in S)return void(h[i]="ui-floating"===i?"auto":m(i,o));r||(r=t.element.ui.sortable().options);var a=r[i];a=m(i,a),l||(l={}),l[i]=a,h[i]=a}});return e=t.extend({},e),t.forEach(e,function(o,n){if(n in S){if("ui-floating"!==n||!1!==o&&!0!==o||!i||(i.floating=o),"ui-preserve-size"===n&&(!1===o||!0===o)){var r=h.helper;e.helper=function(e,o){return!0===h["ui-preserve-size"]&&function(e){e.children().each(function(){var e=t.element(this);e.width(e.width())})}(o),(r||function(e,t){return t}).apply(this,arguments)}}h[n]=m(n,o)}}),t.forEach(e,function(e,t){t in S||(e=m(t,e),l||(l={}),l[t]=e,h[t]=e)}),l}function b(e,t){var o=null;return function(e,t){var o=e.sortable("option","helper");return"clone"===o||"function"==typeof o&&t.item.sortable.isCustomHelperUsed()}(e,t)&&"parent"===e.sortable("option","appendTo")&&(o=c),o}function v(e,t){t.item.sortable._destroy()}function g(e){return e.parent().find(h["ui-model-items"]).index(e)}var h={},S={"ui-floating":o,"ui-model-items":e.items,"ui-preserve-size":o},y={create:null,start:null,activate:null,beforeStop:null,update:null,remove:null,receive:null,deactivate:null,stop:null},C={helper:null};function x(){r.$watchCollection("ngModel",function(){n(function(){f(l)&&l.sortable("refresh")},0,!1)}),y.start=function(e,n){if("auto"===h["ui-floating"]){var i=n.item.siblings();f(t.element(e.target)).floating=/left|right/.test((r=i).css("float"))||/inline|table-cell/.test(r.css("display"))}var r,a=g(n.item);n.item.sortable={model:s.$modelValue[a],index:a,source:l,sourceList:n.item.parent(),sourceModel:s.$modelValue,cancel:function(){n.item.sortable._isCanceled=!0},isCanceled:function(){return n.item.sortable._isCanceled},isCustomHelperUsed:function(){return!!n.item.sortable._isCustomHelperUsed},_isCanceled:!1,_isCustomHelperUsed:n.item.sortable._isCustomHelperUsed,_destroy:function(){t.forEach(n.item.sortable,function(e,t){n.item.sortable[t]=o})},_connectedSortables:[],_getElementContext:function(e){return function(e,t){for(var o=0;o/g,"");return e.find('[class="'+t.attr("class")+'"]:not('+o+")")}(l,s);u=u.not(d)}},y.update=function(e,t){if(!t.item.sortable.received){t.item.sortable.dropindex=g(t.item);var o=t.item.parent().closest("[ui-sortable], [data-ui-sortable], [x-ui-sortable]");t.item.sortable.droptarget=o,t.item.sortable.droptargetList=t.item.parent();var n=t.item.sortable._getElementContext(o);t.item.sortable.droptargetModel=n.scope.ngModel,l.sortable("cancel")}var i=!t.item.sortable.received&&b(l,t);i&&i.length&&(u=u.not(i));var a=t.item.sortable._getElementContext(l);u.appendTo(a.savedNodesOrigin),t.item.sortable.received&&(u=null),t.item.sortable.received&&!t.item.sortable.isCanceled()&&(r.$apply(function(){s.$modelValue.splice(t.item.sortable.dropindex,0,t.item.sortable.moved)}),r.$emit("ui-sortable:moved",t))},y.stop=function(e,o){var n="dropindex"in o.item.sortable&&!o.item.sortable.isCanceled();if(n&&!o.item.sortable.received)r.$apply(function(){s.$modelValue.splice(o.item.sortable.dropindex,0,s.$modelValue.splice(o.item.sortable.index,1)[0])}),r.$emit("ui-sortable:moved",o);else if(!n&&!t.equals(l.contents().toArray(),u.toArray())){var i=b(l,o);i&&i.length&&(u=u.not(i));var a=o.item.sortable._getElementContext(l);u.appendTo(a.savedNodesOrigin)}u=null,c=null},y.receive=function(e,t){t.item.sortable.received=!0},y.remove=function(e,t){"dropindex"in t.item.sortable||(l.sortable("cancel"),t.item.sortable.cancel()),t.item.sortable.isCanceled()||r.$apply(function(){t.item.sortable.moved=s.$modelValue.splice(t.item.sortable.index,1)[0]})},t.forEach(y,function(e,t){y[t]=d(y[t],function(){var e,o=r[t];"function"==typeof o&&("uiSortable"+t.substring(0,1).toUpperCase()+t.substring(1)).length&&"function"==typeof(e=o())&&e.apply(this,arguments)})}),C.helper=function(e){return e&&"function"==typeof e?function(n,i){var r=i.sortable,a=g(i);i.sortable={model:s.$modelValue[a],index:a,source:l,sourceList:i.parent(),sourceModel:s.$modelValue,_restore:function(){t.forEach(i.sortable,function(e,t){i.sortable[t]=o}),i.sortable=r}};var u=e.apply(this,arguments);return i.sortable._restore(),i.sortable._isCustomHelperUsed=i!==u,u}:e},r.$watchCollection("uiSortable",function(e,t){var o=f(l);if(o){var n=p(e,t,o);n&&l.sortable("option",n)}},!0),p(h)}function $(){return(!r.uiSortable||!r.uiSortable.disabled)&&(s?x():i.info("ui.sortable: ngModel not provided!",l),l.sortable(h),$.cancelWatcher(),$.cancelWatcher=t.noop,!0)}t.extend(h,S,e,r.uiSortable),t.element.fn&&t.element.fn.jquery?($.cancelWatcher=t.noop,$()||($.cancelWatcher=r.$watch("uiSortable.disabled",$))):i.error("ui.sortable: jQuery should be included before AngularJS!")}}}])}(window,window.angular);