7fe4f761创建于 4月29日历史提交
!function(){function t(t){var e,i,n,o,s,h;"undefined"==typeof $?alert("InfiniteScroller require jQuery"):(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"}))})))}t.prototype={_isTailOnScreen:function(){var t,e,i;return!(!this.dom.tail.is(":visible")||((t={top:(e=$(window)).scrollTop(),left:e.scrollLeft()}).width=e.width(),t.height=e.height(),t.x=t.left+t.width/2,t.y=t.top+t.height/2,(e=this.dom.tail.offset()).width=this.dom.tail.outerWidth(),e.height=this.dom.tail.outerHeight(),e.x=e.left+e.width/2,e.y=e.top+e.height/2,0==e.left&&0==e.right)||(i=(i=!0)&&2*Math.abs(t.x-e.x)>=t.width+e.width?!1:i)&&2*Math.abs(t.y-e.y)>=t.height+e.height)&&i},_nextCheck:function(){return!(!this.runtime.started||this.runtime.done||this.runtime.processNext||!this._isTailOnScreen()||(this._next(),0))},_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)}());