forked from lightningtgc/material-refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial-refresh.min.js
1 lines (1 loc) · 3.54 KB
/
material-refresh.min.js
1
(function(){"use strict";!function(e){function o(o){if(o=o||{},x=o.scrollEl?o.scrollEl:G?x:document,w=e(x),L=o.onBegin,N=o.onEnd,A=o.maxTime||A,Z=o.nav||Z,0===e("#muirefresh").length&&n(),m=e("#muiRefresh"),p=e(".mui-spinner-wrapper",m),h=e(".mui-arrow-wrapper",m),v=e(".mui-arrow-main",m),!d()){m.addClass("mui-refresh-nav"),H=e(Z).height()+20,e(Z).offset()&&(X=e(Z).offset().top,"fixed"!==e(Z).css("position")&&(H+=X),m.css("top",X+"px"));var s=e(Z).css("z-index");m.css("z-index",s-1)}o.index&&m.css("z-index",~~o.index),o.top&&m.css("top",o.top),m.addClass(o.theme?o.theme:T),m.addClass(g),o.freeze||f()}function n(){document.body.insertAdjacentHTML("beforeend",I)}function s(e){J.top=G&&x==document.body?window.scrollY:x!=document?document.querySelector(x).scrollTop:(document.documentElement||document.body.parentNode||document.body).scrollTop,J.top>0||C||(y=H+z,m.show(),e.touches[0]&&(J.x1=e.touches[0].pageX,B=J.y1=e.touches[0].pageY))}function t(e){var o,n,s=(new Date).getTime();if(!(J.top>0||C)&&e.touches&&1===e.touches.length){if(o=e.touches[0],J.x2=o.pageX,J.y2=o.pageY,n=J.y2-J.y1,J.y2-B+q>0){if(e.preventDefault(),90>s-F)return;if(!(H-X+Y>y))return void u();y+=n,r(y)}J.y1=o.pageY,F=s}}function i(e){J.top>0||C||(e.preventDefault(),y>H-X+R?u():c())}function c(){var e=H+z;d()?(m.css("top",e+"px"),m.css("-webkit-transform","scale(0)")):m.css("top",X+"px"),setTimeout(function(){C||(m.css("opacity",0),m.hide())},300)}function r(e){var o=40,n=e/o>1?1:0>e/o?0:e/o,s=H+z+e;d()&&m.css("-webkit-transform","scale("+n+")"),m.css("opacity",n),m.css("top",s+"px"),v.css("-webkit-transform","rotate("+-(3*e)+"deg)")}function u(){if(C=!0,k&&"function"==typeof M?M():"function"==typeof L&&L(),m.css("opacity",1),k)m.addClass(g),m.css("-webkit-transform","scale(1)");else{var e=H+D-20;d()||(e+=j),m.css("top",e+"px")}h.hide(),p.show(),S=setTimeout(a,A)}function a(){E=!0,m.addClass(b),p.hide(),setTimeout(function(){m.removeClass(b),m.hide(),c(),h.show(),C=!1,E=!1,k&&"function"==typeof Q?Q():"function"==typeof N&&N(),k=!1},500)}function d(){return 0===e(Z).length}function f(){w.on("touchstart",s),w.on("touchmove",t),w.on("touchend",i)}function l(){w.off("touchstart",s),w.off("touchmove",t),w.off("touchend",i)}var m,p,h,v,y,w=e(document.body),x=document.body,b="mui-refresh-noshow",g="mui-refresh-main-animat",T="mui-blue-theme",C=!1,E=!1,k=!1,z=-85,D=0,Y=65,R=-25,j=20,B=0,X=0,q=2,A=6e3,H=60,L=null,M=null,N=null,Q=null,S=null,Z="",F=(new Date).getTime(),G=e.os.ios,I='<div id="muiRefresh" class="mui-refresh-main"> <div class="mui-refresh-wrapper "> <div class="mui-arrow-wrapper"> <div class="mui-arrow-main"></div> </div> <div class="mui-spinner-wrapper" style="display:none;"> <div class="mui-spinner-main" > <div class="mui-spinner-left"> <div class="mui-half-circle"></div> </div> <div class="mui-spinner-right"> <div class="mui-half-circle"></div> </div> </div> </div> </div> </div>',J={top:0,x1:0,x2:0,y1:0,y2:0};o.resolve=function(){!E&&S&&(clearTimeout(S),S=null,a())},o.destroy=function(){l(),m.remove()},o.refresh=function(e){if(!C){var o=H+D-20;C=!0,k=!0,e=e||{},M=e.onBegin,Q=e.onEnd,d()||(o+=j),m.show(),m.removeClass(g),m.css("top",o+"px"),m.css("-webkit-transform","scale(0.01)"),setTimeout(u,60)}},o.unbindEvents=function(){l()},o.bindEvents=function(){f()},window.mRefresh=o}(Zepto||jQuery)}).call(this);