filesbox/web/dist/design/designstatic/common/js/dropload.min.js
2024-07-26 14:10:54 +08:00

2 lines
4.5 KiB
JavaScript

(function(s){"use strict";function l(t){t.touches||(t.touches=t.originalEvent.touches)}function u(t,o){o._startY=t.touches[0].pageY,o.touchScrollTop=o.$scrollArea.scrollTop()}function w(t,o){o._curY=t.touches[0].pageY,o._moveY=o._curY-o._startY,o._moveY>0?o.direction="down":o._moveY<0&&(o.direction="up");var n=Math.abs(o._moveY);o.opts.loadUpFn!=""&&o.touchScrollTop<=0&&o.direction=="down"&&!o.isLockUp&&(t.preventDefault(),o.$domUp=s("."+o.opts.domUp.domClass),o.upInsertDOM||(o.$element.prepend('<div class="'+o.opts.domUp.domClass+'"></div>'),o.upInsertDOM=!0),a(o.$domUp,0),n<=o.opts.distance?(o._offsetY=n,o.$domUp.html(o.opts.domUp.domRefresh)):n>o.opts.distance&&n<=2*o.opts.distance?(o._offsetY=o.opts.distance+.5*(n-o.opts.distance),o.$domUp.html(o.opts.domUp.domUpdate)):o._offsetY=o.opts.distance+.5*o.opts.distance+.2*(n-2*o.opts.distance),o.$domUp.css({height:o._offsetY}))}function f(t){var o=Math.abs(t._moveY);t.opts.loadUpFn!=""&&t.touchScrollTop<=0&&t.direction=="down"&&!t.isLockUp&&(a(t.$domUp,300),o>t.opts.distance?(t.$domUp.css({height:t.$domUp.children().height()}),t.$domUp.html(t.opts.domUp.domLoad),t.loading=!0,t.opts.loadUpFn(t)):t.$domUp.css({height:"0"}).on("webkitTransitionEnd mozTransitionEnd transitionend",function(){t.upInsertDOM=!1,s(this).remove()}),t._moveY=0)}function d(t){t.opts.loadDownFn!=""&&t.opts.autoLoad&&t._scrollContentHeight-t._threshold<=t._scrollWindowHeight&&p(t)}function r(t){t._scrollContentHeight=t.opts.scrollArea==i?h.height():t.$element[0].scrollHeight}function p(t){t.direction="up",t.$domDown.html(t.opts.domDown.domLoad),t.loading=!0,t.opts.loadDownFn(t)}function a(t,o){t.css({"-webkit-transition":"all "+o+"ms",transition:"all "+o+"ms"})}var e,i=window,c=document,m=s(i),h=s(c);s.fn.dropload=function(t){return new e(this,t)},e=function(t,o){var n=this;n.$element=t,n.upInsertDOM=!1,n.loading=!1,n.isLockUp=!1,n.isLockDown=!1,n.isData=!0,n._scrollTop=0,n._threshold=0,n.init(o)},e.prototype.init=function(t){var o=this;o.opts=s.extend(!0,{},{scrollArea:o.$element,domUp:{domClass:"dropload-up",domRefresh:'<div class="dropload-refresh">\u2193\u4E0B\u62C9\u5237\u65B0</div>',domUpdate:'<div class="dropload-update">\u2191\u91CA\u653E\u66F4\u65B0</div>',domLoad:'<div class="dropload-load"><span class="loading"></span>\u52A0\u8F7D\u4E2D...</div>'},domDown:{domClass:"dropload-down",domRefresh:'<div class="dropload-refresh">\u2191\u4E0A\u62C9\u52A0\u8F7D\u66F4\u591A</div>',domLoad:'<div class="dropload-load"><span class="loading"></span>\u52A0\u8F7D\u4E2D...</div>',domNoData:'<div class="dropload-noData">\u6682\u65E0\u6570\u636E</div>'},autoLoad:!0,distance:50,threshold:"",loadUpFn:"",loadDownFn:""},t),o.opts.loadDownFn!=""&&(o.$element.append('<div class="'+o.opts.domDown.domClass+'">'+o.opts.domDown.domRefresh+"</div>"),o.$domDown=s("."+o.opts.domDown.domClass)),o._threshold=o.$domDown&&o.opts.threshold===""?Math.floor(1*o.$domDown.height()/3):o.opts.threshold,o.opts.scrollArea==i?(o.$scrollArea=m,o._scrollContentHeight=h.height(),o._scrollWindowHeight=c.documentElement.clientHeight):(o.$scrollArea=o.opts.scrollArea,o._scrollContentHeight=o.$element[0].scrollHeight,o._scrollWindowHeight=o.$element.height()),d(o),m.on("resize",function(){clearTimeout(o.timer),o.timer=setTimeout(function(){o._scrollWindowHeight=o.opts.scrollArea==i?i.innerHeight:o.$element.height(),d(o)},150)}),o.$element.on("touchstart",function(n){o.loading||(l(n),u(n,o))}),o.$element.on("touchmove",function(n){o.loading||(l(n,o),w(n,o))}),o.$element.on("touchend",function(){o.loading||f(o)}),o.$scrollArea.on("scroll",function(){o._scrollTop=o.$scrollArea.scrollTop(),o.opts.loadDownFn!=""&&!o.loading&&!o.isLockDown&&o._scrollContentHeight-o._threshold<=o._scrollWindowHeight+o._scrollTop&&p(o)})},e.prototype.lock=function(t){var o=this;t===void 0?o.direction=="up"?o.isLockDown=!0:o.direction=="down"?o.isLockUp=!0:(o.isLockUp=!0,o.isLockDown=!0):t=="up"?o.isLockUp=!0:t=="down"&&(o.isLockDown=!0,o.direction="up")},e.prototype.unlock=function(){var t=this;t.isLockUp=!1,t.isLockDown=!1,t.direction="up"},e.prototype.noData=function(t){var o=this;t===void 0||t==1?o.isData=!1:t==0&&(o.isData=!0)},e.prototype.resetload=function(){var t=this;t.direction=="down"&&t.upInsertDOM?t.$domUp.css({height:"0"}).on("webkitTransitionEnd mozTransitionEnd transitionend",function(){t.loading=!1,t.upInsertDOM=!1,s(this).remove(),r(t)}):t.direction=="up"&&(t.loading=!1,t.isData?(t.$domDown.html(t.opts.domDown.domRefresh),r(t),d(t)):t.$domDown.html(t.opts.domDown.domNoData))}})(window.Zepto||window.jQuery);