minirefresh.theme.default.min.js
8.02 KB
/*!
* minirefresh v2.0.2
* (c) 2017-2018 dailc
* Released under the MIT License.
* https://github.com/minirefresh/minirefresh
*/
!function(s,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):s.MiniRefresh=t()}(this,function(){"use strict";var s=function(){function s(s,t){for(var o=0;o<t.length;o++){var e=t[o];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(s,e.key,e)}}return function(t,o,e){return o&&s(t.prototype,o),e&&s(t,e),t}}(),t=MiniRefreshTools.Core,o=MiniRefreshTools.version,e=MiniRefreshTools.extend,n=MiniRefreshTools.namespace,i="minirefresh-rotate",r="minirefresh-hidden",a={down:{successAnim:{isEnable:!1,duration:300},contentdown:"下拉刷新",contentover:"释放刷新",contentrefresh:"加载中...",contentsuccess:"刷新成功",contenterror:"刷新失败",isWrapCssTranslate:!1},up:{toTop:{isEnable:!0,duration:300,offset:800},contentdown:"",contentrefresh:"加载中...",contentnomore:"没有更多数据了"}},p=function(o){function n(s){!function(s,t){if(!(s instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n);var t=e(!0,{},a,s);return function(s,t){if(!s)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?s:t}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t))}return function(s,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);s.prototype=Object.create(t&&t.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(s,t):s.__proto__=t)}(n,t),s(n,[{key:"_initHook",value:function(){var s=this.container,t=this.contentWrap;s.classList.add("minirefresh-theme-default"),t.classList.add("minirefresh-hardware-speedup"),this.options.isUseBodyScroll&&(s.classList.add("body-scroll-wrap"),t.classList.add("body-scroll-wrap")),this._initDownWrap(),this._initUpWrap(),this._initToTop()}},{key:"_refreshHook",value:function(){this.options.down.isWrapCssTranslate?this._transformDownWrap(-this.downWrapHeight):this._transformDownWrap(0,0,!0),this.options.up.toTop.isEnable||(this.toTopBtn&&this.toTopBtn.classList.add(r),this.isShowToTopBtn=!1)}},{key:"_initDownWrap",value:function(){var s=this.container,t=this.contentWrap,o=this.options,e=document.createElement("div");e.className="minirefresh-downwrap minirefresh-hardware-speedup",e.innerHTML=' \n <div class="downwrap-content">\n <p class="downwrap-progress"></p>\n <p class="downwrap-tips">'+o.down.contentdown+"</p>\n </div>\n ",s.insertBefore(e,t),this.downWrap=e,this.downWrapProgress=this.downWrap.querySelector(".downwrap-progress"),this.downWrapTips=this.downWrap.querySelector(".downwrap-tips"),this.isCanPullDown=!1,this.downWrapHeight=e.offsetHeight||75,this._transformDownWrap(-this.downWrapHeight),n._changeWrapStatusClass(this.downWrap,"status-default")}},{key:"_transformDownWrap",value:function(){var s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(arguments[2]||this.options.down.isWrapCssTranslate){var o=t+"ms",e="translateY("+s+"px) translateZ(0px)";this.downWrap.style.webkitTransitionDuration=o,this.downWrap.style.transitionDuration=o,this.downWrap.style.webkitTransform=e,this.downWrap.style.transform=e}}},{key:"_initUpWrap",value:function(){var s=this.contentWrap,t=this.options,o=document.createElement("div");o.className="minirefresh-upwrap minirefresh-hardware-speedup",o.innerHTML=' \n <p class="upwrap-progress"></p>\n <p class="upwrap-tips">'+t.up.contentdown+"</p>\n ",o.style.visibility="hidden",s.appendChild(o),this.upWrap=o,this.upWrapProgress=this.upWrap.querySelector(".upwrap-progress"),this.upWrapTips=this.upWrap.querySelector(".upwrap-tips"),n._changeWrapStatusClass(this.upWrap,"status-default")}},{key:"_initToTop",value:function(){var s=this,t=this.options,o=t.up.toTop.isEnable,e=t.up.toTop.duration;if(o){var n=document.createElement("div");n.className="minirefresh-totop minirefresh-theme-default",n.onclick=function(){s.scroller.scrollTo(0,e)},n.classList.add(r),this.toTopBtn=n,this.isShowToTopBtn=!1,this.container.appendChild(n)}}},{key:"_pullHook",value:function(s,t){var o=this.options;if(s<t?this.isCanPullDown&&(this.isCanPullDown=!1,n._changeWrapStatusClass(this.downWrap,"status-default"),this.downWrapTips.innerText=o.down.contentdown):this.isCanPullDown||(this.downWrapTips.innerText=o.down.contentover,this.isCanPullDown=!0,n._changeWrapStatusClass(this.downWrap,"status-pull")),this.downWrapProgress){var e="rotate("+360*(s/t)+"deg)";this.downWrapProgress.style.webkitTransform=e,this.downWrapProgress.style.transform=e}this._transformDownWrap(-this.downWrapHeight+s)}},{key:"_scrollHook",value:function(s){var t=this.options,o=t.up.toTop.isEnable,e=this.toTopBtn;o&&e&&(s>=t.up.toTop.offset?this.isShowToTopBtn||(e.classList.remove("minirefresh-fade-out"),e.classList.remove(r),e.classList.add("minirefresh-fade-in"),this.isShowToTopBtn=!0):this.isShowToTopBtn&&(e.classList.add("minirefresh-fade-out"),e.classList.remove("minirefresh-fade-in"),this.isShowToTopBtn=!1))}},{key:"_downLoaingHook",value:function(){this._transformDownWrap(-this.downWrapHeight+this.options.down.offset,this.options.down.bounceTime),this.downWrapTips.innerText=this.options.down.contentrefresh,this.downWrapProgress.classList.add(i),n._changeWrapStatusClass(this.downWrap,"status-loading")}},{key:"_downLoaingSuccessHook",value:function(s,t){this.options.down.contentsuccess=t||this.options.down.contentsuccess,this.downWrapTips.innerText=s?this.options.down.contentsuccess:this.options.down.contenterror,this.downWrapProgress.classList.remove(i),this.downWrapProgress.classList.add("minirefresh-fade-out"),this.downWrapProgress.classList.add(s?"downwrap-success":"downwrap-error"),n._changeWrapStatusClass(this.downWrap,s?"status-success":"status-error")}},{key:"_downLoaingEndHook",value:function(s){this.downWrapTips.innerText=this.options.down.contentdown,this.downWrapProgress.classList.remove(i),this.downWrapProgress.classList.remove("minirefresh-fade-out"),this.downWrapProgress.classList.remove(s?"downwrap-success":"downwrap-error"),this.isCanPullDown=!1,this._transformDownWrap(-this.downWrapHeight,this.options.down.bounceTime),n._changeWrapStatusClass(this.downWrap,"status-default")}},{key:"_cancelLoaingHook",value:function(){this._transformDownWrap(-this.downWrapHeight,this.options.down.bounceTime),n._changeWrapStatusClass(this.downWrap,"status-default")}},{key:"_upLoaingHook",value:function(s){s?(this.upWrapTips.innerText=this.options.up.contentrefresh,this.upWrapProgress.classList.add(i),this.upWrapProgress.classList.remove(r),this.upWrap.style.visibility="visible"):this.upWrap.style.visibility="hidden",n._changeWrapStatusClass(this.upWrap,"status-loading")}},{key:"_upLoaingEndHook",value:function(s){s?(this.upWrapTips.innerText=this.options.up.contentnomore,n._changeWrapStatusClass(this.upWrap,"status-nomore")):(this.upWrapTips.innerText=this.options.up.contentdown,n._changeWrapStatusClass(this.upWrap,"status-default")),this.upWrapProgress.classList.remove(i),this.upWrapProgress.classList.add(r)}},{key:"_resetUpLoadingHook",value:function(){this.upWrapTips.innerText=this.options.up.contentdown,this.upWrapProgress.classList.remove(i),this.upWrapProgress.classList.add(r),n._changeWrapStatusClass(this.upWrap,"status-default")}},{key:"_lockUpLoadingHook",value:function(s){this.upWrap.style.visibility=s?"hidden":"visible"}},{key:"_lockDownLoadingHook",value:function(s){this.downWrap.style.visibility=s?"hidden":"visible"}}],[{key:"_changeWrapStatusClass",value:function(s,t){s.classList.remove("status-nomore"),s.classList.remove("status-default"),s.classList.remove("status-pull"),s.classList.remove("status-loading"),s.classList.remove("status-success"),s.classList.remove("status-error"),s.classList.add(t)}}]),n}();return p.sign="default",p.version=o,n("theme.defaults",p),window.MiniRefresh=p,p});