@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1 lines • 7.14 kB
JavaScript
module.exports=function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}({0:function(e,t,n){e.exports=n(1309)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},1005:function(e,t){e.exports=require("jquery")},1061:function(e,t){e.exports=require("./kendo.draganddrop")},1309:function(e,t,n){var r,i,o;(function(s){!function(s,define){i=[n(1061)],r=s,o="function"==typeof r?r.apply(t,i):r,!(void 0!==o&&(e.exports=o))}(function(){return function(e,t){function n(t,n){try{return e.contains(t,n)||t==n}catch(r){return!1}}function r(e){return e.clone()}function i(e){return e.clone().removeAttr("id").css("visibility","hidden")}var o=window.kendo,l=o.ui.Widget,a=o._outerWidth,d=o._outerHeight,h="start",c="beforeMove",u="move",f="end",g="change",p="cancel",m="sort",x="remove",_="receive",v=">*",y=-1,b=l.extend({init:function(e,t){var n=this;l.fn.init.call(n,e,t),n.options.placeholder||(n.options.placeholder=i),n.options.hint||(n.options.hint=r),n.draggable=n._createDraggable()},events:[h,c,u,f,g,p],options:{name:"Sortable",hint:null,placeholder:null,filter:v,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(),l.fn.destroy.call(this)},_createDraggable:function(){var t=this,n=t.element,r=t.options;return new o.ui.Draggable(n,{filter:r.filter,hint:o.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:e.proxy(t._dragstart,t),dragcancel:e.proxy(t._dragcancel,t),drag:e.proxy(t._drag,t),dragend:e.proxy(t._dragend,t)})},_dragstart:function(t){var n=this.draggedElement=t.currentTarget,r=this.options.disabled,i=this.options.handler,s=this.options.placeholder,l=this.placeholder=e(o.isFunction(s)?s.call(this,n):s);r&&n.is(r)?t.preventDefault():i&&!e(t.initialTarget).is(i)?t.preventDefault():this.trigger(h,{item:n,draggableEvent:t})?t.preventDefault():(n.css("display","none"),n.before(l),this._setCursor())},_dragcancel:function(){this._cancel(),this.trigger(p,{item:this.draggedElement}),this._resetCursor()},_drag:function(n){var r,i,o,l,a,d=this.draggedElement,h=this._findTarget(n),c={left:n.x.location,top:n.y.location},u={x:n.x.delta,y:n.y.delta},f=this.options.axis,g=this.options.moveOnDragEnter,p={item:d,list:this,draggableEvent:n};if("x"===f||"y"===f)return this._movementByAxis(f,c,u[f],p),t;if(h){if(r=this._getElementCenter(h.element),i={left:Math.round(c.left-r.left),top:Math.round(c.top-r.top)},e.extend(p,{target:h.element}),h.appendToBottom)return this._movePlaceholder(h,null,p),t;if(h.appendAfterHidden&&this._movePlaceholder(h,"next",p),this._isFloating(h.element)?u.x<0&&g||!g&&i.left<0?o="prev":(u.x>0&&g||!g&&i.left>0)&&(o="next"):u.y<0&&g||!g&&i.top<0?o="prev":(u.y>0&&g||!g&&i.top>0)&&(o="next"),o){for(a="prev"===o?s.fn.prev:s.fn.next,l=a.call(h.element);l.length&&!l.is(":visible");)l=a.call(l);l[0]!=this.placeholder[0]&&this._movePlaceholder(h,o,p)}}},_dragend:function(n){var r,i,o,s,l=this.placeholder,a=this.draggedElement,d=this.indexOf(a),h=this.indexOf(l),c=this.options.connectWith;return this._resetCursor(),o={action:m,item:a,oldIndex:d,newIndex:h,draggableEvent:n},h>=0?i=this.trigger(f,o):(r=l.parents(c).getKendoSortable(),o.action=x,s=e.extend({},o,{action:_,oldIndex:y,newIndex:r.indexOf(l)}),i=!(!this.trigger(f,o)&&!r.trigger(f,s))),i||h===d?(this._cancel(),t):(l.replaceWith(a),a.show(),this.draggable.dropped=!0,o={action:this.indexOf(a)!=y?m:x,item:a,oldIndex:d,newIndex:this.indexOf(a),draggableEvent:n},this.trigger(g,o),r&&(s=e.extend({},o,{action:_,oldIndex:y,newIndex:r.indexOf(a)}),r.trigger(g,s)),t)},_findTarget:function(n){var r,i,o=this._findElementUnderCursor(n),s=this.options.connectWith;return e.contains(this.element[0],o)?(r=this.items(),i=r.filter(o)[0]||r.has(o)[0],i?{element:e(i),sortable:this}:null):this.element[0]==o&&this._isEmpty()?{element:this.element,sortable:this,appendToBottom:!0}:this.element[0]==o&&this._isLastHidden()?(i=this.items().eq(0),{element:i,sortable:this,appendAfterHidden:!0}):s?this._searchConnectedTargets(o,n):t},_findElementUnderCursor:function(e){var t=o.elementUnderCursor(e),r=e.sender;return n(r.hint[0],t)&&(r.hint.hide(),t=o.elementUnderCursor(e),t||(t=o.elementUnderCursor(e)),r.hint.show()),t},_searchConnectedTargets:function(t,n){var r,i,o,s,l=e(this.options.connectWith);for(s=0;s<l.length;s++)if(r=l.eq(s).getKendoSortable(),e.contains(l[s],t)){if(r)return i=r.items(),o=i.filter(t)[0]||i.has(t)[0],o?(r.placeholder=this.placeholder,{element:e(o),sortable:r}):null}else if(l[s]==t){if(r&&r._isEmpty())return{element:l.eq(s),sortable:r,appendToBottom:!0};if(this._isCursorAfterLast(r,n))return o=r.items().last(),{element:o,sortable:r}}},_isCursorAfterLast:function(e,t){var n,r,i=e.items().last(),s={left:t.x.location,top:t.y.location};return n=o.getOffset(i),n.top+=d(i),n.left+=a(i),r=this._isFloating(i)?n.left-s.left:n.top-s.top,r<0},_movementByAxis:function(t,n,r,i){var o,s="x"===t?n.left:n.top,l=r<0?this.placeholder.prev():this.placeholder.next(),a=this.items();l.length&&!l.is(":visible")&&(l=r<0?l.prev():l.next()),a.filter(l).length&&(e.extend(i,{target:l}),o=this._getElementCenter(l),o&&(o="x"===t?o.left:o.top),l.length&&r<0&&s-o<0?this._movePlaceholder({element:l,sortable:this},"prev",i):l.length&&r>0&&s-o>0&&this._movePlaceholder({element:l,sortable:this},"next",i))},_movePlaceholder:function(e,t,n){var r=this.placeholder;e.sortable.trigger(c,n)||(t?"prev"===t?e.element.before(r):"next"===t&&e.element.after(r):e.element.append(r),e.sortable.trigger(u,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 t=e.length?o.getOffset(e):null;return t&&(t.top+=d(e)/2,t.left+=a(e)/2),t},_isFloating:function(e){return/left|right/.test(e.css("float"))||/inline|table-cell/.test(e.css("display"))},_cancel:function(){this.draggedElement.show(),this.placeholder.remove()},_items:function(){var e,t=this.options.filter;return e=t?this.element.find(t):this.element.children()},indexOf:function(e){var t=this._items(),n=this.placeholder,r=this.draggedElement;return n&&e[0]==n[0]?t.not(r).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")}});o.ui.plugin(b)}(window.kendo.jQuery),window.kendo},n(3))}).call(t,n(1005))}});