!function(){function t(t){var e,i,n,o,s,h;"undefined"!=typeof $?(this.opt=$.extend({container:null,tail:null,autoStart:!0,initCallback:function(){},nextCallback:function(t){},doneCallback:function(){},resetCallback:function(){},pullToRefreshCallback:function(){},pullToRefresh:!1,pullToRefreshDom:null},t),null===this.opt.container&&(this.opt.container=window),this.dom={container:null,tail:null},this.runtime={processNext:!1,done:!1,page:1,started:!1},(e=this).dom.container=$(this.opt.container),this.dom.tail=$(this.opt.tail),this.dom.pullToRefresh=null,this.dom.container.on("scroll",function(){e._nextCheck()}),this.opt.initCallback(),this.opt.autoStart&&(this.runtime.started=!0,e._nextCheck()),this.opt.pullToRefresh&&(e.dom.pullToRefresh=$(this.opt.pullToRefreshDom),i=e.dom.pullToRefresh.height(),n=null,o={x:0,y:0},s=99999,h=0,e.dom.container.on("touchstart",function(t){t=t.originalEvent,h=0,s=99999,"up"==(n=e.dom.container.scrollTop()<=0?"up":n)&&(o.x=t.changedTouches[0].pageX,o.y=t.changedTouches[0].pageY,e.dom.pullToRefresh.find(".status").hide(),e.dom.pullToRefresh.find(".status.pull").show())}),e.dom.container.on("touchmove",function(t){if((t=t.originalEvent).preventDefault(),"up"==n){if(0<Math.abs(t.touches[0].pageX-o.x)-Math.abs(t.touches[0].pageY-o.y))return!1;t=t.changedTouches[0].pageY-o.y;h<t?(h=Math.max(h,t),s=(t=i<t?i:t)-i):(s-=h-t,h=t,s<-i&&(s=-i)),0<t&&e.dom.pullToRefresh.css({marginTop:s+"px"})}}),e.dom.container.on("touchend",function(t){t=t.originalEvent,"up"==n&&(n=null,0==s?(e.dom.pullToRefresh.find(".status").hide(),e.dom.pullToRefresh.find(".status.refreshing").show(),e.runtime.page=1,e.opt.pullToRefreshCallback(e.runtime.page)):e.dom.pullToRefresh.css({marginTop:-i+"px"}))}))):alert("InfiniteScroller require jQuery")}t.prototype={_isTailOnScreen:function(){if(!this.dom.tail.is(":visible"))return!1;var t=$(window),e={top:t.scrollTop(),left:t.scrollLeft()};e.width=t.width(),e.height=t.height(),e.x=e.left+e.width/2,e.y=e.top+e.height/2;var i=this.dom.tail.offset();if(i.width=this.dom.tail.outerWidth(),i.height=this.dom.tail.outerHeight(),i.x=i.left+i.width/2,i.y=i.top+i.height/2,0==i.left&&0==i.right)return!1;t=!0;return t=(t=t&&2*Math.abs(e.x-i.x)>=e.width+i.width?!1:t)&&2*Math.abs(e.y-i.y)>=e.height+i.height?!1:t},_nextCheck:function(){this.runtime.started&&!this.runtime.done&&!this.runtime.processNext&&this._isTailOnScreen()&&this._next()},_next:function(){this.runtime.processNext=!0,this.opt.nextCallback(this.runtime.page)},check:function(){this._nextCheck()},nextDone:function(){this.runtime.processNext=!1,this.runtime.page++,this._nextCheck()},done:function(){this.runtime.done=!0,this.opt.doneCallback()},reset:function(){this.opt.resetCallback(),this.runtime.processNext=!1,this.runtime.done=!1,this.runtime.page=1,this._nextCheck()},start:function(){this.runtime.started=!0,this._nextCheck()},setPage:function(t){this.runtime.page=t},pullToRefreshDone:function(){this.dom.pullToRefresh.css({marginTop:-this.dom.pullToRefresh.height()+"px"}),this.reset()}},"undefined"!=typeof module&&"object"==typeof exports&&define.cmd?module.exports=t:"function"==typeof define&&define.amd?define(function(){return t}):this.InfiniteScroller=t}.call(function(){return this||("undefined"!=typeof window?window:global)}());