UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines (2 loc) 7.17 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kendo.draganddrop.js")):"function"==typeof define&&define.amd?define(["exports","kendo.draganddrop"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Sortable={}))}(this,(function(e){!function(e){var t=window.kendo,n=t.ui.Widget,i=t._outerWidth,r=t._outerHeight,o="start",s="beforeMove",l="move",a="end",d="change",h="cancel",c="sort",u="remove",g="receive";function f(e){return e.clone()}function p(e){return e.clone().removeAttr("id").css("visibility","hidden")}var m=n.extend({init:function(e,t){var i=this;n.fn.init.call(i,e,t),i.options.placeholder||(i.options.placeholder=p),i.options.hint||(i.options.hint=f),i.draggable=i._createDraggable()},events:[o,s,l,a,d,h],options:{name:"Sortable",hint:null,placeholder:null,filter:">*",holdToDrag:!1,disabled:null,container:null,connectWith:null,handler:null,cursorOffset:null,axis:null,ignore:null,autoScroll:!1,cursor:"auto",moveOnDragEnter:!1},destroy:function(){this.draggable.destroy(),n.fn.destroy.call(this)},_createDraggable:function(){var n=this,i=n.element,r=n.options;return new t.ui.Draggable(i,{filter:r.filter,hint:t.isFunction(r.hint)?r.hint:e(r.hint),holdToDrag:r.holdToDrag,container:r.container?e(r.container):null,cursorOffset:r.cursorOffset,axis:r.axis,ignore:r.ignore,autoScroll:r.autoScroll,dragstart:n._dragstart.bind(n),dragcancel:n._dragcancel.bind(n),drag:n._drag.bind(n),dragend:n._dragend.bind(n)})},_dragstart:function(n){var i=this.draggedElement=n.currentTarget,r=this.options.disabled,s=this.options.handler,l=this.options.placeholder,a=this.placeholder=t.isFunction(l)?e(l.call(this,i)):e(l);r&&i.is(r)||s&&!e(n.initialTarget).is(s)||this.trigger(o,{item:i,draggableEvent:n})?n.preventDefault():(i.css("display","none"),i.before(a),this._setCursor())},_dragcancel:function(){this._cancel(),this.trigger(h,{item:this.draggedElement}),this._resetCursor()},_drag:function(t){var n,i,r,o,s,l=this.draggedElement,a=this._findTarget(t),d={left:t.x.location,top:t.y.location},h={x:t.x.delta,y:t.y.delta},c=this.options.axis,u=this.options.moveOnDragEnter,g={item:l,list:this,draggableEvent:t};if("x"!==c&&"y"!==c){if(a){if(n=this._getElementCenter(a.element),i={left:Math.round(d.left-n.left),top:Math.round(d.top-n.top)},e.extend(g,{target:a.element}),a.appendToBottom)return void this._movePlaceholder(a,null,g);if(a.appendAfterHidden&&this._movePlaceholder(a,"next",g),this._isFloating(a.element)?h.x<0&&u||!u&&i.left<0?r="prev":(h.x>0&&u||!u&&i.left>0)&&(r="next"):h.y<0&&u||!u&&i.top<0?r="prev":(h.y>0&&u||!u&&i.top>0)&&(r="next"),r){for(o=(s="prev"===r?jQuery.fn.prev:jQuery.fn.next).call(a.element);o.length&&!o.is(":visible");)o=s.call(o);o[0]!=this.placeholder[0]&&this._movePlaceholder(a,r,g)}}}else this._movementByAxis(c,d,h[c],g)},_dragend:function(t){var n,i,r,o,s=this.placeholder,l=this.draggedElement,h=this.indexOf(l),f=this.indexOf(s),p=this.options.connectWith;this._resetCursor(),r={action:c,item:l,oldIndex:h,newIndex:f,draggableEvent:t},f>=0?i=this.trigger(a,r):(n=s.parents(p).getKendoSortable(),r.action=u,o=e.extend({},r,{action:g,oldIndex:-1,newIndex:n.indexOf(s)}),i=!(!this.trigger(a,r)&&!n.trigger(a,o))),i||f===h?this._cancel():(s.replaceWith(l),l.show(),this.draggable.dropped=!0,r={action:-1!=this.indexOf(l)?c:u,item:l,oldIndex:h,newIndex:this.indexOf(l),draggableEvent:t},this.trigger(d,r),n&&(o=e.extend({},r,{action:g,oldIndex:-1,newIndex:n.indexOf(l)}),n.trigger(d,o)))},_findTarget:function(t){var n,i,r=this._findElementUnderCursor(t),o=this.options.connectWith;return e.contains(this.element[0],r)?(i=(n=this.items()).filter(r)[0]||n.has(r)[0])?{element:e(i),sortable:this}:null:this.element[0]==r&&this._isEmpty()?{element:this.element,sortable:this,appendToBottom:!0}:this.element[0]==r&&this._isLastHidden()?{element:i=this.items().eq(0),sortable:this,appendAfterHidden:!0}:o?this._searchConnectedTargets(r,t):void 0},_findElementUnderCursor:function(n){var i=t.elementUnderCursor(n),r=n.sender;return function(t,n){try{return e.contains(t,n)||t==n}catch(e){return!1}}(r.hint[0],i)&&(r.hint.hide(),(i=t.elementUnderCursor(n))||(i=t.elementUnderCursor(n)),r.hint.show()),i},_searchConnectedTargets:function(t,n){for(var i,r,o,s=e(this.options.connectWith),l=0;l<s.length;l++)if(i=s.eq(l).getKendoSortable(),e.contains(s[l],t)){if(i)return(o=(r=i.items()).filter(t)[0]||r.has(t)[0])?(i.placeholder=this.placeholder,{element:e(o),sortable:i}):null}else if(s[l]==t){if(i&&i._isEmpty())return{element:s.eq(l),sortable:i,appendToBottom:!0};if(this._isCursorAfterLast(i,n))return{element:o=i.items().last(),sortable:i}}},_isCursorAfterLast:function(e,n){var o,s=e.items().last(),l=n.x.location,a=n.y.location;return(o=t.getOffset(s)).top+=r(s),o.left+=i(s),(this._isFloating(s)?o.left-l:o.top-a)<0},_movementByAxis:function(t,n,i,r){var o,s="x"===t?n.left:n.top,l=i<0?this.placeholder.prev():this.placeholder.next(),a=this.items();l.length&&!l.is(":visible")&&(l=i<0?l.prev():l.next()),a.filter(l).length&&(e.extend(r,{target:l}),(o=this._getElementCenter(l))&&(o="x"===t?o.left:o.top),l.length&&i<0&&s-o<0?this._movePlaceholder({element:l,sortable:this},"prev",r):l.length&&i>0&&s-o>0&&this._movePlaceholder({element:l,sortable:this},"next",r))},_movePlaceholder:function(e,t,n){var i=this.placeholder;e.sortable.trigger(s,n)||(t?"prev"===t?e.element.before(i):"next"===t&&e.element.after(i):e.element.append(i),e.sortable.trigger(l,n))},_setCursor:function(){var t,n=this.options.cursor;n&&"auto"!==n&&(t=e(document.body),this._originalCursorType=t.css("cursor"),t.css({cursor:n}),this._cursorStylesheet||(this._cursorStylesheet=e("<style>* { cursor: "+n+" !important; }</style>")),this._cursorStylesheet.appendTo(t))},_resetCursor:function(){this._originalCursorType&&(e(document.body).css("cursor",this._originalCursorType),this._originalCursorType=null,this._cursorStylesheet.remove())},_getElementCenter:function(e){var n=e.length?t.getOffset(e):null;return n&&(n.top+=r(e)/2,n.left+=i(e)/2),n},_isFloating:function(e){var t=/left|right/.test(e.css("float")),n=/inline|table-cell/.test(e.css("display")),i=/flex/.test(e.parent().css("display"))&&(/row|row-reverse/.test(e.parent().css("flex-direction"))||!e.parent().css("flex-direction"));return t||n||i},_cancel:function(){this.draggedElement&&(this.draggedElement.show(),this.placeholder.remove(),this.draggable.dropped=!0)},_items:function(){var e=this.options.filter;return e?this.element.find(e):this.element.children()},indexOf:function(e){var t=this._items(),n=this.placeholder,i=this.draggedElement;return n&&e[0]==n[0]?t.not(i).index(e):t.not(n).index(e)},items:function(){var e=this.placeholder,t=this._items();return e&&(t=t.not(e)),t},_isEmpty:function(){return!this.items().length},_isLastHidden:function(){return 1===this.items().length&&this.items().is(":hidden")}});t.ui.plugin(m)}(window.kendo.jQuery);var t=kendo;e.__meta__={id:"sortable",name:"Sortable",category:"framework",depends:["draganddrop"]},e.default=t,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.sortable.min.js.map