angular.module("ionic-pullup",[]).constant("ionPullUpFooterState",{COLLAPSED:"COLLAPSED",MINIMIZED:"MINIMIZED",EXPANDED:"EXPANDED"}).constant("ionPullUpFooterBehavior",{HIDE:"HIDE",EXPAND:"EXPAND"}).directive("ionPullUpFooter",[function(){return{restrict:"AE",scope:{state:"=?",onExpand:"&",onCollapse:"&",onMinimize:"&",allowMidRange:"="},controller:["$scope","$element","$attrs","$timeout","$rootScope","$window","$ionicPlatform","ionPullUpFooterState","ionPullUpFooterBehavior",function(t,e,o,n,i,a,s,r,l){function c(){var t=e[0];f=t.closest("ion-tabs"),g=f&&f.classList.contains("tabs-bottom"),E=document.querySelector("ion-nav-bar .nav-bar-block[nav-bar=entering] > .bar-header"),D=f?f.querySelector(".tabs").offsetHeight:0,I=E?E.offsetHeight:0}function u(){n(function(){m.height=m.maxHeight>0?m.maxHeight:a.innerHeight-I-P-D,m.height-=50,"ios"==i.platformOS&&(m.height-=30),e.css({height:m.height+"px"}),m.initialState==r.MINIMIZED?d():p()},300),e.css({transition:"none",padding:0})}function h(){c(),m.height=m.maxHeight>0?m.maxHeight:a.innerHeight-I-P-D,m.height-=50,"ios"==i.platformOS&&(m.height-=30),m.lastPosY=0,e.css({height:m.height+"px","-webkit-transform":"translate3d(0, 0, 0)",transform:"translate3d(0, 0, 0)"}),e.css({transition:"300ms ease-in-out",padding:0}),t.onExpand(),t.state=r.EXPANDED}function p(){m.lastPosY=f?m.height-D:m.height-m.defaultHeight,e.css({"-webkit-transform":"translate3d(0, "+m.lastPosY+"px, 0)",transform:"translate3d(0, "+m.lastPosY+"px, 0)"}),t.onCollapse(),t.state=r.COLLAPSED}function d(){m.lastPosY=m.height,e.css({"-webkit-transform":"translate3d(0, "+m.lastPosY+"px, 0)",transform:"translate3d(0, "+m.lastPosY+"px, 0)"}),t.onMinimize(),t.state=r.MINIMIZED}var f,g,E,D,I,P=0,m={height:0,posY:0,lastPosY:0,defaultHeight:e[0].offsetHeight,maxHeight:parseInt(o.maxHeight,10)||0,initialState:o.initialState?o.initialState.toUpperCase():r.COLLAPSED,defaultBehavior:o.defaultBehavior?o.defaultBehavior.toUpperCase():l.EXPAND};this.$onInit=function(){n(function(){c(),e.css({transition:"300ms ease-in-out",padding:0}),f&&g&&e.css("bottom",D+"px")}),u()},this.setHandleHeight=function(t){P=t},this.getHeight=function(){return e[0].offsetHeight},this.getBackground=function(){return a.getComputedStyle(e[0]).background},this.getInitialState=function(){return m.initialState},this.getDefaultBehavior=function(){return m.defaultBehavior},this.onTap=function(e){e.gesture.srcEvent.preventDefault(),e.gesture.preventDefault(),n(function(){t.state==r.COLLAPSED?m.defaultBehavior==l.HIDE?t.state=r.MINIMIZED:t.state=r.EXPANDED:t.state==r.MINIMIZED?m.defaultBehavior==l.HIDE?t.state=r.COLLAPSED:t.state=r.EXPANDED:t.state=m.initialState==r.MINIMIZED?r.MINIMIZED:r.COLLAPSED})},this.onDrag=function(o){switch(o.gesture.srcEvent.preventDefault(),o.gesture.preventDefault(),o.type){case"dragstart":e.css("transition","none");break;case"drag":if(m.posY=Math.round(o.gesture.deltaY)+m.lastPosY,m.posY<0||m.posY>m.height)return;e.css({"-webkit-transform":"translate3d(0, "+m.posY+"px, 0)",transform:"translate3d(0, "+m.posY+"px, 0)"});break;case"dragend":e.css({transition:"300ms ease-in-out"}),t.allowMidRange?m.lastPosY=m.posY:n(function(){m.lastPosY>m.posY?t.state=r.EXPANDED:m.lastPosY"),this.$onInit=function(){var t=this.FooterController;a.on("tap",t.onTap,e),a.on("drag dragstart dragend",t.onDrag,e),t.setHandleHeight(h);c(t.getInitialState(),t.getDefaultBehavior()),u()},t.$on("ionPullUp:tap",function(t,e,o){c(e,o)}),s.ready(function(){l.addEventListener("orientationchange",u),s.on("resume",u)})}]});