UNPKG

@progress/kendo-ui

Version:

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

3 lines 7.55 kB
/* @license */ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`kendo.core.min.js`),require(`kendo.draganddrop.min.js`),require(`kendo.icons.min.js`)):typeof define==`function`&&define.amd?define([`exports`,`kendo.core.min`,`kendo.draganddrop.min`,`kendo.icons.min`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Reorderable={}),e.kendo._globals.Core,e.kendo._globals.Draganddrop,e.kendo._globals.Icons))})(this,function(e,t,n,r){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let i={id:`reorderable`,name:`Reorderable`,category:`framework`,depends:[`core`,`draganddrop`,`icons`],advanced:!0};(function(e,t){var n=window.kendo,r=n._outerWidth,i=n._outerHeight,a=n.getOffset,o=n.ui.Widget,s=`change`,c=o.extend({init:function(e,t){var c=this;o.fn.init.call(c,e,t),e=c.element,t=c.options,c._isRtl=n.support.isRtl(e),c._cueUpdatedByDrag=!1,c._initDraggable(),c.options.dropFilter||(c.options.dropFilter=c.draggable.options.filter),c.reorderDropCue=c.options.reorderDropCue,e.find(t.dropFilter).kendoDropTarget({group:c.draggable.options.group,dragenter:function(e){var n=c._externalDraggable(e);if(c._cueUpdatedByDrag=!1,!(!c._draggable&&!n)){n&&c._handleExternalDraggable(n);var o=this.element,s,l=c._isPartOfSortable(c._draggable)?!c._dropTargetAllowed(o)||c._isLastDraggable():!1;if(c.toggleHintClass(e.draggable.hint,l),!l){s=a(o);var u={top:s.top,left:s.left},d=t.orientation===`horizontal`;!t.smartPosition||t.inSameContainer&&!t.inSameContainer({source:o,target:c._draggable,sourceIndex:c._index(o),targetIndex:c._index(c._draggable)})?c._dropTarget=o:(d&&c._isRtl?c._index(o)<c._index(c._draggable):c._index(o)>c._index(c._draggable))&&t.smartPosition&&(u[d?`left`:`top`]+=d?r(o):i(o)),c._normalizeCueOffset(u,o,d),c.reorderDropCue.css({height:i(o),top:u.top,left:u.left,zIndex:19e3}),t.positionDropCue&&t.positionDropCue(c.reorderDropCue,o),c.reorderDropCue.appendTo(document.body)}}},dragleave:function(e){c._dropTarget=null},drop:function(){if(c._dropTarget=null,c._draggable){var e=this.element,n=c._draggable,o=c._index(e),l=a(e);c._normalizeCueOffset(l,e,t.orientation===`horizontal`);var u=l.left+r(e)/2,d=l.top+i(e)/2,f=c._isRtl?a(c.reorderDropCue).left<=u:a(c.reorderDropCue).left>u,p=c.options.orientation===`horizontal`?f:a(c.reorderDropCue).top>d;o=p?o+1:o,c._dropTargetAllowed(e)&&!c._isLastDraggable()&&(c._index(n)!==o||c.options.allowDropAfterLastItem)&&c.trigger(s,{element:c._draggable,target:e,oldIndex:c._index(n),newIndex:c._index(e),position:p?`after`:`before`}),c.reorderDropCue&&c.reorderDropCue.remove()}}}),c.draggable.bind([`dragcancel`,`dragend`,`dragstart`,`drag`],{dragcancel:c._dragcancel.bind(c),dragend:c._dragend.bind(c),dragstart:c._dragstart.bind(c),drag:c._drag.bind(c)})},options:{name:`Reorderable`,filter:`*`,orientation:`horizontal`,deniedIcon:`cancel`,allowIcon:`plus`,reorderDropCue:e(`<div class="k-reorder-cue"></div></div>`),smartPosition:!0},events:[s],toggleHintClass:function(t,r){var i=this.options;t=e(t),t.find(`.k-drag-status`).length>0&&n.ui.icon(t.find(`.k-drag-status`).eq(0),{icon:r?i.deniedIcon:i.allowIcon})},_initDraggable:function(){let e=this,t=e.options;e.draggable=t.draggable||new n.ui.Draggable(e.element,{group:n.guid()+`-reorderable`,autoScroll:!0,filter:t.filter,hint:t.hint});let r=e.draggable._elementUnderCursor;e.draggable._elementUnderCursor=function(t){let n=e.reorderDropCue&&e.reorderDropCue.is(`:visible`);n&&e.reorderDropCue.hide();let i=r.call(e.draggable,t);return n&&e.reorderDropCue.show(),i}},_normalizeCueOffset:function(e,t,n){let i=t.closest(`.k-grid-header-locked,.k-grid-header-wrap`);if(!i.length)return;let o=a(i);n&&(e.left<o.left&&this._isRtl&&(e.left=o.left),e.left>o.left+r(i)&&!this._isRtl&&(e.left=o.left+r(i)))},_handleExternalDraggable:function(e){var t=this,n=t.options.dropFilter.trimStart();n&&n[0]==`>`&&(n=n.substring(1)),t._dragcancelHandler=t._dragcancel.bind(t),t._dragendHandler=t._dragend.bind(t),t._dragstartHandler=t._dragstart.bind(t),t._dragHandler=t._drag.bind(t),t._draggable=e.currentTarget.closest(n),t._draggableInstance=e,t._elements=t.element.find(t.options.dropFilter),e.bind([`dragcancel`,`dragend`,`dragstart`,`drag`],{dragcancel:t._dragcancelHandler,dragend:t._dragendHandler,dragstart:t._dragstartHandler,drag:t._dragHandler})},_dragcancel:function(){var e=this;e._draggableInstance&&(e._dragcancelHandler||e._dragendHandler||e._dragstartHandler||e._dragHandler)&&e._draggableInstance.unbind({dragcancel:e._dragcancelHandler,dragend:e._dragendHandler,dragstart:e._dragstartHandler,drag:e._dragHandler}),e.reorderDropCue&&e.reorderDropCue.remove(),e._draggable=null,e._elements=null},_dragend:function(){var e=this;e._draggableInstance&&(e._dragcancelHandler||e._dragendHandler||e._dragstartHandler||e._dragHandler)&&e._draggableInstance.unbind({dragcancel:e._dragcancelHandler,dragend:e._dragendHandler,dragstart:e._dragstartHandler,drag:e._dragHandler}),e.reorderDropCue&&e.reorderDropCue.remove(),e._draggable=null,e._elements=null},_dragstart:function(t){var n=this,r=e(t.currentTarget),i=n.options.dropFilter.trimStart();i&&i[0]==`>`&&(i=i.substring(1)),n._draggable=r.is(i)?r:r.closest(i),n._elements=n.element.find(n.options.dropFilter)},_drag:function(t){var n=this,o,s,c,l={},u,d=n.options.dropFilter.trimStart();if(d&&d[0]==`>`&&(d=d.substring(1)),u=e(t.currentTarget).closest(d),!(!n._dropTarget||n.options.smartPosition&&t.sender.hint.find(`.k-drag-status`).is(`.k-i-cancel,.k-svg-i-cancel`))){if(o=n._index(n._dropTarget),s=n._index(u),s=o>s?s+1:s,n.options.orientation===`horizontal`){var f=a(n._dropTarget).left,p=r(n._dropTarget),m=t.pageX>f+p/2;n._isRtl?m?l.left=f+p:(l.left=f,o+=1):m?(l.left=f+p,o+=1):l.left=f}else{var h=a(n._dropTarget).top,g=i(n._dropTarget);t.pageY>h+g/2?(l.top=h+g,o+=1):l.top=h}n.reorderDropCue.css(l),n._cueUpdatedByDrag=!0,n.options.positionDropCue&&n.options.positionDropCue(n.reorderDropCue,n._dropTarget),n._isPartOfSortable(u)&&(c=s===o&&!n.options.allowDropAfterLastItem||n.options.dragOverContainers&&!n.options.dragOverContainers(s,o)||t.clickMoveClick&&t.currentTarget.hasClass(`k-drag-cell`)&&e(t.elementUnderCursor).closest(`.k-drag-cell`).length===0,n.toggleHintClass(t.sender.hint,c))}},_isPartOfSortable:function(e){return this._elements.index(e)>=0},_externalDraggable:function(e){var t=this,n=t.options;return!t._draggable&&n.externalDraggable?n.externalDraggable(e):null},_isLastDraggable:function(){var e=this.options.inSameContainer,t=this._draggable[0],n=this._elements.get(),r=!1,i;if(!e)return!1;for(;!r&&n.length>0;)i=n.pop(),r=t!==i&&e({source:t,target:i,sourceIndex:this._index(t),targetIndex:this._index(i)});return!r},_dropTargetAllowed:function(e){var t=this.options.inSameContainer,n=this.options.dragOverContainers,r=this._draggable;return r[0]===e[0]?!1:!t||!n||t({source:r,target:e,sourceIndex:this._index(r),targetIndex:this._index(e)})?!0:n(this._index(r),this._index(e))},_index:function(e){return this._elements.index(e)},destroy:function(){var t=this;o.fn.destroy.call(t),t.element.find(t.options.dropFilter).each(function(){var t=e(this);t.data(`kendoDropTarget`)&&t.data(`kendoDropTarget`).destroy()}),t.draggable&&(t.draggable.destroy(),t.draggable.element=t.draggable=null),t.reorderDropCue.remove(),t.elements=t.reorderDropCue=t._elements=t._draggable=null}});n.ui.plugin(c)})(window.kendo.jQuery);var a=kendo;e.__meta__=i,e.default=a}); //# sourceMappingURL=kendo.reorderable.min.js.map