UNPKG

4.31 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).SlideForMoreBase=e()}(this,function(){"use strict";var t=function(t,e,i,o,s,n,r,h,a,p){"boolean"!=typeof r&&(a=h,h=r,r=!1);var c,d="function"==typeof i?i.options:i;if(t&&t.render&&(d.render=t.render,d.staticRenderFns=t.staticRenderFns,d._compiled=!0,s&&(d.functional=!0)),o&&(d._scopeId=o),n?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,a(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},d._ssrRegister=c):e&&(c=r?function(){e.call(this,p(this.$root.$options.shadowRoot))}:function(t){e.call(this,h(t))}),c)if(d.functional){var u=d.render;d.render=function(t,e){return c.call(e),u(t,e)}}else{var l=d.beforeCreate;d.beforeCreate=l?[].concat(l,c):[c]}return i},e={name:"SlideForMoreBase",props:{slideValue:{default:100,type:Number},isSearching:Boolean,tipHeight:{type:String,default:"40px"}},data:function(){return{isBottom:!1,isTop:!1,startPointer:null,heights:{wrap:0,wrapOffset:0,content:0},height:0,type:""}},computed:{distance:function(){return Math.abs(+this.slideValue)},slideType:function(){return this.isSearching?this.type:""},cHeight:function(){return this.height?Math.abs(+this.height)+"px":this.tipHeight},showUpTip:function(){return this.height<0||this.isSearching&&"slideDown"===this.type},showBottomTip:function(){return 0<this.height||this.isSearching&&"slideUp"===this.type},tipWrap:function(){return this.showUpTip?{height:this.cHeight,opacity:1,bottom:this.bottom+"px"}:{opacity:0}},bottom:function(){var t=this.heights,e=t.wrap,i=t.content;return Math.min(0,e-i)},bottomTipWrap:function(){return this.showBottomTip?{height:this.cHeight,opacity:1,bottom:this.bottom+"px"}:{opacity:0}},contentStyle:function(){return this.height?{bottom:(this.height<0?"-":"")+this.cHeight}:{bottom:this.isSearching?("slideDown"===this.type?"-":"")+this.cHeight:"0px"}},transition:function(){return this.height?"":"transition"}},methods:{start:function(t){var e=this.heights,i=e.wrap,o=e.content,s=this.getScrollTop();this.isTop=s<=0,this.isBottom=o-i<=s,this.startPointer={pageY:t.changedTouches[0].pageY}},move:function(t){if((this.isBottom||this.isTop)&&!this.isSearching){var e=this.startPointer.pageY-t.changedTouches[0].pageY;(0<e&&this.isBottom||e<0&&this.isTop)&&(this.height=e,t.preventDefault())}},end:function(t){if(this.isBottom||this.isTop){var e=this.startPointer.pageY-t.changedTouches[0].pageY;this.distance<=e&&this.isBottom?(this.$emit(this.type="slideUp"),this.$emit("loadMore")):this.distance<=-e&&this.isTop&&(this.$emit(this.type="slideDown"),this.$emit("refresh")),this.height=0}},getHeights:function(){var o=this;this.$nextTick(function(){var t=o.$refs,e=t.wrap,i=t.content;i&&(o.heights.content=i.offsetHeight,o.heights.wrap=e.clientHeight,o.validPaddingTopBottom())})},getScrollTop:function(){return this.$refs.wrap?this.$refs.wrap.scrollTop:0},validPaddingTopBottom:function(){var t=this.$refs.wrap,e=window.getComputedStyle(t),i=e.paddingTop,o=e.paddingBottom;(parseInt(i,10)||parseInt(o,10))&&console.warn("SlideForMore: The wrap element should not have paddingTop and paddingBottom. You can set padding to content element instead")}},mounted:function(){this.getHeights()},updated:function(){this.getHeights()}},i=function(){var t=this,e=t.$createElement,i=t._self._c||e;return i("div",{ref:"wrap",staticClass:"slide-for-more-base-wrap",staticStyle:{padding:"0"},on:{touchstart:t.start,touchend:t.end,touchmove:t.move}},[i("div",{directives:[{name:"show",rawName:"v-show",value:t.showUpTip,expression:"showUpTip"}],staticClass:"slide-for-more-top-tip-wrap",class:t.transition,style:t.tipWrap},[t._t("topTip")],2),t._v(" "),i("div",{ref:"content",staticClass:"slide-for-more-content",class:t.transition,style:t.contentStyle},[t._t("default")],2),t._v(" "),i("div",{directives:[{name:"show",rawName:"v-show",value:t.showBottomTip,expression:"showBottomTip"}],staticClass:"slide-for-more-tip-wrap",class:t.transition,style:t.bottomTipWrap},[t._t("tip")],2)])};i._withStripped=!0;return t({render:i,staticRenderFns:[]},void 0,e,void 0,!1,void 0,void 0,void 0)});