16 lines
11 KiB
JavaScript
16 lines
11 KiB
JavaScript
/**
|
|
* Copyright 2014 Telerik AD
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
!function(e,define){define(["./kendo.core.min","./kendo.userevents.min"],e)}(function(){return function(e,t){function n(t,n){try{return e.contains(t,n)||t==n}catch(i){return!1}}function i(e,t){return parseInt(e.css(t),10)||0}function r(e,t){return Math.min(Math.max(e,t.min),t.max)}function o(e,t){var n=x(e),r=n.left+i(e,"borderLeftWidth")+i(e,"paddingLeft"),o=n.top+i(e,"borderTopWidth")+i(e,"paddingTop"),a=r+e.width()-t.outerWidth(!0),s=o+e.height()-t.outerHeight(!0);return{x:{min:r,max:a},y:{min:o,max:s}}}function a(e,n,i){for(var r,o,a=0,s=n&&n.length,u=i&&i.length;e&&e.parentNode;){for(a=0;s>a;a++)if(r=n[a],r.element[0]===e)return{target:r,targetElement:e};for(a=0;u>a;a++)if(o=i[a],p.matchesSelector.call(e,o.options.filter))return{target:o,targetElement:e};e=e.parentNode}return t}var s,u,l,c,d,f,h=window.kendo,p=h.support,g=window.document,m=h.Class,v=h.ui.Widget,y=h.Observable,_=h.UserEvents,b=e.proxy,w=e.extend,x=h.getOffset,F={},k={},S={},T=h.elementUnderCursor,M="keyup",C="change",D="dragstart",E="hold",z="drag",O="dragend",A="dragcancel",P="dragenter",N="dragleave",H="drop",R=y.extend({init:function(t,n){var i=this,r=t[0];i.capture=!1,r.addEventListener?(e.each(h.eventMap.down.split(" "),function(){r.addEventListener(this,b(i._press,i),!0)}),e.each(h.eventMap.up.split(" "),function(){r.addEventListener(this,b(i._release,i),!0)})):(e.each(h.eventMap.down.split(" "),function(){r.attachEvent(this,b(i._press,i))}),e.each(h.eventMap.up.split(" "),function(){r.attachEvent(this,b(i._release,i))})),y.fn.init.call(i),i.bind(["press","release"],n||{})},captureNext:function(){this.capture=!0},cancelCapture:function(){this.capture=!1},_press:function(e){var t=this;t.trigger("press"),t.capture&&e.preventDefault()},_release:function(e){var t=this;t.trigger("release"),t.capture&&(e.preventDefault(),t.cancelCapture())}}),I=y.extend({init:function(t){var n=this;y.fn.init.call(n),n.forcedEnabled=!1,e.extend(n,t),n.scale=1,n.horizontal?(n.measure="offsetWidth",n.scrollSize="scrollWidth",n.axis="x"):(n.measure="offsetHeight",n.scrollSize="scrollHeight",n.axis="y")},makeVirtual:function(){e.extend(this,{virtual:!0,forcedEnabled:!0,_virtualMin:0,_virtualMax:0})},virtualSize:function(e,t){(this._virtualMin!==e||this._virtualMax!==t)&&(this._virtualMin=e,this._virtualMax=t,this.update())},outOfBounds:function(e){return e>this.max||this.min>e},forceEnabled:function(){this.forcedEnabled=!0},getSize:function(){return this.container[0][this.measure]},getTotal:function(){return this.element[0][this.scrollSize]},rescale:function(e){this.scale=e},update:function(e){var t=this,n=t.virtual?t._virtualMax:t.getTotal(),i=n*t.scale,r=t.getSize();0!==n&&(t.max=t.virtual?-t._virtualMin:0,t.size=r,t.total=i,t.min=Math.min(t.max,r-i),t.minScale=r/n,t.centerOffset=(i-r)/2,t.enabled=t.forcedEnabled||i>r,e||t.trigger(C,t))}}),B=y.extend({init:function(e){var t=this;y.fn.init.call(t),t.x=new I(w({horizontal:!0},e)),t.y=new I(w({horizontal:!1},e)),t.container=e.container,t.forcedMinScale=e.minScale,t.maxScale=e.maxScale||100,t.bind(C,e)},rescale:function(e){this.x.rescale(e),this.y.rescale(e),this.refresh()},centerCoordinates:function(){return{x:Math.min(0,-this.x.centerOffset),y:Math.min(0,-this.y.centerOffset)}},refresh:function(){var e=this;e.x.update(),e.y.update(),e.enabled=e.x.enabled||e.y.enabled,e.minScale=e.forcedMinScale||Math.min(e.x.minScale,e.y.minScale),e.fitScale=Math.max(e.x.minScale,e.y.minScale),e.trigger(C)}}),q=y.extend({init:function(e){var t=this;w(t,e),y.fn.init.call(t)},outOfBounds:function(){return this.dimension.outOfBounds(this.movable[this.axis])},dragMove:function(e){var t=this,n=t.dimension,i=t.axis,r=t.movable,o=r[i]+e;n.enabled&&((n.min>o&&0>e||o>n.max&&e>0)&&(e*=t.resistance),r.translateAxis(i,e),t.trigger(C,t))}}),L=m.extend({init:function(e){var t,n,i,r,o=this;w(o,{elastic:!0},e),i=o.elastic?.5:0,r=o.movable,o.x=t=new q({axis:"x",dimension:o.dimensions.x,resistance:i,movable:r}),o.y=n=new q({axis:"y",dimension:o.dimensions.y,resistance:i,movable:r}),o.userEvents.bind(["move","end","gesturestart","gesturechange"],{gesturestart:function(e){o.gesture=e,o.offset=o.dimensions.container.offset()},gesturechange:function(e){var i,a,s,u=o.gesture,l=u.center,c=e.center,d=e.distance/u.distance,f=o.dimensions.minScale,h=o.dimensions.maxScale;f>=r.scale&&1>d&&(d+=.8*(1-d)),r.scale*d>=h&&(d=h/r.scale),a=r.x+o.offset.left,s=r.y+o.offset.top,i={x:(a-l.x)*d+c.x-a,y:(s-l.y)*d+c.y-s},r.scaleWith(d),t.dragMove(i.x),n.dragMove(i.y),o.dimensions.rescale(r.scale),o.gesture=e,e.preventDefault()},move:function(e){e.event.target.tagName.match(/textarea|input/i)||(t.dimension.enabled||n.dimension.enabled?(t.dragMove(e.x.delta),n.dragMove(e.y.delta),e.preventDefault()):e.touch.skip())},end:function(e){e.preventDefault()}})}}),j=p.transitions.prefix+"Transform";u=p.hasHW3D?function(e,t,n){return"translate3d("+e+"px,"+t+"px,0) scale("+n+")"}:function(e,t,n){return"translate("+e+"px,"+t+"px) scale("+n+")"},l=y.extend({init:function(t){var n=this;y.fn.init.call(n),n.element=e(t),n.element[0].style.webkitTransformOrigin="left top",n.x=0,n.y=0,n.scale=1,n._saveCoordinates(u(n.x,n.y,n.scale))},translateAxis:function(e,t){this[e]+=t,this.refresh()},scaleTo:function(e){this.scale=e,this.refresh()},scaleWith:function(e){this.scale*=e,this.refresh()},translate:function(e){this.x+=e.x,this.y+=e.y,this.refresh()},moveAxis:function(e,t){this[e]=t,this.refresh()},moveTo:function(e){w(this,e),this.refresh()},refresh:function(){var e,t=this,n=t.x,i=t.y;t.round&&(n=Math.round(n),i=Math.round(i)),e=u(n,i,t.scale),e!=t.coordinates&&(h.support.browser.msie&&10>h.support.browser.version?(t.element[0].style.position="absolute",t.element[0].style.left=t.x+"px",t.element[0].style.top=t.y+"px"):t.element[0].style[j]=e,t._saveCoordinates(e),t.trigger(C))},_saveCoordinates:function(e){this.coordinates=e}}),c=v.extend({init:function(e,t){var n,i=this;v.fn.init.call(i,e,t),n=i.options.group,n in k?k[n].push(i):k[n]=[i]},events:[P,N,H],options:{name:"DropTarget",group:"default"},destroy:function(){var e,t=this.options.group,n=k[t]||S[t];if(n.length>1){for(v.fn.destroy.call(this),e=0;n.length>e;e++)if(n[e]==this){n.splice(e,1);break}}else c.destroyGroup(t)},_trigger:function(e,n){var i=this,r=F[i.options.group];return r?i.trigger(e,w({},n.event,{draggable:r,dropTarget:n.dropTarget})):t},_over:function(e){this._trigger(P,e)},_out:function(e){this._trigger(N,e)},_drop:function(e){var t=this,n=F[t.options.group];n&&(n.dropped=!t._trigger(H,e))}}),c.destroyGroup=function(e){var t,n=k[e]||S[e];if(n){for(t=0;n.length>t;t++)v.fn.destroy.call(n[t]);n.length=0,delete k[e],delete S[e]}},c._cache=k,d=c.extend({init:function(e,t){var n,i=this;v.fn.init.call(i,e,t),n=i.options.group,n in S?S[n].push(i):S[n]=[i]},options:{name:"DropTargetArea",group:"default",filter:null}}),f=v.extend({init:function(e,t){var n=this;v.fn.init.call(n,e,t),n._activated=!1,n.userEvents=new _(n.element,{global:!0,allowSelection:!0,filter:n.options.filter,threshold:n.options.distance,start:b(n._start,n),hold:b(n._hold,n),move:b(n._drag,n),end:b(n._end,n),cancel:b(n._cancel,n),select:b(n._select,n)}),n._afterEndHandler=b(n._afterEnd,n),n._captureEscape=b(n._captureEscape,n)},events:[E,D,z,O,A],options:{name:"Draggable",distance:5,group:"default",cursorOffset:null,axis:null,container:null,filter:null,ignore:null,holdToDrag:!1,dropped:!1},cancelHold:function(){this._activated=!1},_captureEscape:function(e){var t=this;e.keyCode===h.keys.ESC&&(t._trigger(A,{event:e}),t.userEvents.cancel())},_updateHint:function(t){var n,i=this,o=i.options,a=i.boundaries,s=o.axis,u=i.options.cursorOffset;u?n={left:t.x.location+u.left,top:t.y.location+u.top}:(i.hintOffset.left+=t.x.delta,i.hintOffset.top+=t.y.delta,n=e.extend({},i.hintOffset)),a&&(n.top=r(n.top,a.y),n.left=r(n.left,a.x)),"x"===s?delete n.top:"y"===s&&delete n.left,i.hint.css(n)},_shouldIgnoreTarget:function(t){var n=this.options.ignore;return n&&e(t).is(n)},_select:function(e){this._shouldIgnoreTarget(e.event.target)||e.preventDefault()},_start:function(n){var i,r=this,a=r.options,s=a.container,u=a.hint;return this._shouldIgnoreTarget(n.touch.initialTouch)||a.holdToDrag&&!r._activated?(r.userEvents.cancel(),t):(r.currentTarget=n.target,r.currentTargetOffset=x(r.currentTarget),u&&(r.hint&&r.hint.stop(!0,!0).remove(),r.hint=h.isFunction(u)?e(u.call(r,r.currentTarget)):u,i=x(r.currentTarget),r.hintOffset=i,r.hint.css({position:"absolute",zIndex:2e4,left:i.left,top:i.top}).appendTo(g.body),r.angular("compile",function(){return r.hint.removeAttr("ng-repeat"),{elements:r.hint.get(),scopeFrom:n.target}})),F[a.group]=r,r.dropped=!1,s&&(r.boundaries=o(s,r.hint)),r._trigger(D,n)&&(r.userEvents.cancel(),r._afterEnd()),e(g).on(M,r._captureEscape),t)},_hold:function(e){this.currentTarget=e.target,this._trigger(E,e)?this.userEvents.cancel():this._activated=!0},_drag:function(n){var i=this;n.preventDefault(),i._withDropTarget(n,function(i,r){if(!i)return s&&(s._trigger(N,w(n,{dropTarget:e(s.targetElement)})),s=null),t;if(s){if(r===s.targetElement)return;s._trigger(N,w(n,{dropTarget:e(s.targetElement)}))}i._trigger(P,w(n,{dropTarget:e(r)})),s=w(i,{targetElement:r})}),i._trigger(z,w(n,{dropTarget:s})),i.hint&&i._updateHint(n)},_end:function(t){var n=this;n._withDropTarget(t,function(n,i){n&&(n._drop(w({},t,{dropTarget:e(i)})),s=null)}),n._trigger(O,t),n._cancel(t.event)},_cancel:function(){var e=this;e._activated=!1,e.hint&&!e.dropped?setTimeout(function(){e.hint.stop(!0,!0).animate(e.currentTargetOffset,"fast",e._afterEndHandler)},0):e._afterEnd()},_trigger:function(e,t){var n=this;return n.trigger(e,w({},t.event,{x:t.x,y:t.y,currentTarget:n.currentTarget,dropTarget:t.dropTarget}))},_withDropTarget:function(e,t){var i,r,o=this,s=o.options,u=k[s.group],l=S[s.group];(u&&u.length||l&&l.length)&&(i=T(e),o.hint&&n(o.hint[0],i)&&(o.hint.hide(),i=T(e),i||(i=T(e)),o.hint.show()),r=a(i,u,l),r?t(r.target,r.targetElement):t())},destroy:function(){var e=this;v.fn.destroy.call(e),e._afterEnd(),e.userEvents.destroy(),e.currentTarget=null},_afterEnd:function(){var t=this;t.hint&&t.hint.remove(),delete F[t.options.group],t.trigger("destroy"),e(g).off(M,t._captureEscape)}}),h.ui.plugin(c),h.ui.plugin(d),h.ui.plugin(f),h.TapCapture=R,h.containerBoundaries=o,w(h.ui,{Pane:L,PaneDimensions:B,Movable:l})}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |