@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) • 4.26 kB
JavaScript
!function(e){"function"==typeof define&&define.amd?define(["kendo.mobile.view.min","kendo.userevents.min"],e):e()}((function(){var e,i,t,n,s,o,r,a,h,l,d,c,u,v,w,f;e=window.kendo.jQuery,i=window.kendo,t=i.mobile,n=i.support.mobileOS,s=i.effects.Transition,o=i.roleSelector,r="x",a=t.ui,h=!(n.ios&&7==n.majorVersion&&!n.appMode),l="beforeShow",d="init",c="show",u="hide",v="afterHide",w={enable:e.noop},f=a.View.extend({init:function(n,s){e(n).parent().prepend(n),t.ui.Widget.fn.init.call(this,n,s),this.options.$angular||(this._layout(),this._scroller()),this._model();var r,a=this.element.closest(o("pane")).data("kendoMobilePane");if(a)this.pane=a,this.pane.bind("viewShow",(function(e){c._viewShow(e)})),this.pane.bind("sameViewRequested",(function(){c.hide()})),r=this.userEvents=new i.UserEvents(a.element,{fastTap:!0,filter:o("view splitview"),allowSelection:!0});else{this.currentView=w;var l=e(this.options.container);if(!l)throw new Error("The drawer needs a container configuration option set.");r=this.userEvents=new i.UserEvents(l,{fastTap:!0,allowSelection:!0}),this._attachTransition(l)}var c=this,u=function(e){c.visible&&(c.hide(),e.preventDefault())};this.options.swipeToOpen&&h?(r.bind("press",(function(){c.transition.cancel()})),r.bind("start",(function(e){c._start(e)})),r.bind("move",(function(e){c._update(e)})),r.bind("end",(function(e){c._end(e)})),r.bind("tap",u)):r.bind("press",u),this.leftPositioned="left"===this.options.position,this.visible=!1,this.element.hide().addClass("km-drawer").addClass(this.leftPositioned?"km-left-drawer":"km-right-drawer"),this.trigger(d)},options:{name:"Drawer",position:"left",views:[],swipeToOpenViews:[],swipeToOpen:!0,title:"",container:null},events:[l,u,v,d,c],show:function(){this._activate()&&this._show()},hide:function(){this.currentView&&(this.currentView.enable(),f.current=null,this._moveViewTo(0),this.trigger(u,{view:this}))},openFor:function(){this.visible?this.hide():this.show()},destroy:function(){a.View.fn.destroy.call(this),this.userEvents.destroy()},_activate:function(){return!!this.visible||!(!this._currentViewIncludedIn(this.options.views)||this.trigger(l,{view:this}))&&(this._setAsCurrent(),this.element.show(),this.trigger(c,{view:this}),this._invokeNgController(),!0)},_currentViewIncludedIn:function(i){if(!this.pane||!i.length)return!0;var t=this.pane.view();return e.inArray(t.id.replace("#",""),i)>-1||e.inArray(t.element.attr("id"),i)>-1},_show:function(){this.currentView.enable(!1),this.visible=!0;var e=this.element.width();this.leftPositioned||(e=-e),this._moveViewTo(e)},_setAsCurrent:function(){f.last!==this&&(f.last&&f.last.element.hide(),this.element.show()),f.last=this,f.current=this},_moveViewTo:function(e){this.userEvents.cancel(),this.transition.moveTo({location:e,duration:400,ease:s.easeOutExpo})},_viewShow:function(e){this.currentView&&this.currentView.enable(),this.currentView!==e.view?(this.currentView=e.view,this._attachTransition(e.view.element)):this.hide()},_attachTransition:function(e){var t=this,n=this.movable,o=n&&n.x;this.transition&&(this.transition.cancel(),this.movable.moveAxis("x",0)),n=this.movable=new i.ui.Movable(e),this.transition=new s({axis:r,movable:this.movable,onEnd:function(){0===n.x&&(e[0].style.cssText="",t.element.hide(),t.trigger(v),t.visible=!1)}}),o&&(e.addClass("k-fx-hidden"),i.animationFrame((function(){e.removeClass("k-fx-hidden"),t.movable.moveAxis(r,o),t.hide()})))},_start:function(e){var t=e.sender;if(Math.abs(e.x.velocity)<Math.abs(e.y.velocity)||i.triggeredByInput(e.event)||!this._currentViewIncludedIn(this.options.swipeToOpenViews))t.cancel();else{var n=this.leftPositioned,s=this.visible,o=n&&s||!n&&!f.current,r=!n&&s||n&&!f.current,a=e.x.velocity<0;(o&&a||r&&!a)&&this._activate()?t.capture():t.cancel()}},_update:function(e){var i,t=this.movable.x+e.x.delta;i=this.leftPositioned?Math.min(Math.max(0,t),this.element.width()):Math.max(Math.min(0,t),-this.element.width()),this.movable.moveAxis(r,i),e.event.preventDefault(),e.event.stopPropagation()},_end:function(e){var i=e.x.velocity,t=Math.abs(this.movable.x)>this.element.width()/2,n=.8;(this.leftPositioned?i>-.8&&(i>n||t):i<n&&(i<-.8||t))?this._show():this.hide()}}),a.plugin(f)}));
//# sourceMappingURL=kendo.mobile.drawer.min.js.map