UNPKG

upp-touch

Version:
2 lines 12.2 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("VTouch",[],e):"object"==typeof exports?exports.VTouch=e():t.VTouch=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(i){if(o[i])return o[i].exports;var n=o[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var o={};return e.m=t,e.c=o,e.d=function(t,o,i){e.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/dist/",e(e.s=1)}([function(t,e,o){"use strict";var i=o(9),n=o(10),r=Object(i.a)("transform");e.a={data:function(){return{needTransition:!1}},mounted:function(){this.initialize()},methods:{initialize:function(){var t=this;setTimeout(function(){t.$slots.default||t.throwError(0);var e=t.$refs.touch,o=e.parentNode;t.el=t.$slots.default[0].elm,t.needTransition=t.commonSlideTransition,t.touch={xHasMove:0,yHasMove:0,xTemMove:0,yTemMove:0,systemLockX:t.el.clientHeight<t.$refs.uppTouch.clientWidth,systemLockY:t.el.clientHeight<t.$refs.uppTouch.clientHeight,curDirectionX:void 0,initX:0,initY:0,parentWidth:o?o.clientWidth:window.innerWidth,parentHeight:o?o.clientHeight:window.innerHeight,xLastDistance:0,yLastDistance:0}},0)},touchStart:function(t){var e=t.touches[0];this.touch.startX=e.pageX,this.touch.startY=e.pageY,this.touch.xMoving=!1,this.touch.yMoving=!1},touchMove:function(t){if(!(this.lockX&&this.lockY||this.touch.systemLockX&&this.touch.systemLockY)){this.preventDefault&&t.preventDefault();var e=t.touches[0],o=e.pageX-this.touch.startX,i=e.pageY-this.touch.startY;if(!this.touch.hasMove){if(Math.abs(o)>Math.abs(i)){if(this.touch.directionX=!0,void 0===this.touch.curDirectionX&&(this.touch.curDirectionX=!0),this.lockX||this.touch.systemLockX)return}else if(this.touch.directionY=!0,void 0===this.touch.curDirectionX&&(this.touch.curDirectionX=!1),this.lockY||this.touch.systemLockY)return;this.touch.hasMove=!0}this.touch.curDirectionX?this.moveX(o):this.moveY(i)}},touchEnd:function(){this.touch.hasMove=!1,this.touch.directionX=!1,this.touch.directionY=!1,this.touch.xMoving=!1,this.touch.yMoving=!1,this.touch.curDirectionX=void 0,this.touch.xHasMove+=this.touch.xTemMove,this.touch.yHasMove+=this.touch.yTemMove,this.touch.xTemMove=0,this.touch.yTemMove=0},moveX:function(t){t>0?this.moveXToRight(t):this.moveXToLeft(t)},moveY:function(t){t<0?this.moveYtoTop(t):this.moveYtoBottom(t)},move:function(t,e){if(e){t?this.touch.xMoving=!0:this.touch.yMoving=!0,this.needTransition=this.commonSlideTransition;var o=void 0,i=void 0,s=void 0,u=void 0;t?(i=o=this.touch.xHasMove+e,s=this.touch.yHasMove,u=this.touch.xLastDistance>e?n.b:n.c,this.touch.xLastDistance=e):(i=this.touch.xHasMove,s=o=this.touch.yHasMove+e,u=this.touch.yLastDistance>e?n.d:n.a,this.touch.yLastDistance=e),this.$emit(u,o),this.$refs.touch.style[r]="translate3d("+i+"px, "+s+"px, 0)"}},moveXToLeft:function(t){this.touch.xTemMove=t;var e=this.el.clientWidth-this.touch.parentWidth;this.touch.xHasMove+t<=-e&&(this.touch.xTemMove=-e-this.touch.xHasMove,this.dispatch(1)),this.move(!0,this.touch.xTemMove)},moveXToRight:function(t){this.touch.xTemMove=t,this.touch.xHasMove+t>=this.touch.initX&&(this.touch.xTemMove=this.touch.initX-this.touch.xHasMove,this.dispatch(0)),this.move(!0,this.touch.xTemMove)},moveYtoTop:function(t){this.touch.yTemMove=t;var e=this.el.clientHeight-this.touch.parentHeight;this.touch.yHasMove+t<=-e&&(this.touch.yTemMove=-e-this.touch.yHasMove,this.dispatch(3)),this.move(null,this.touch.yTemMove)},moveYtoBottom:function(t){this.touch.yTemMove=t,this.touch.yHasMove+t>=this.touch.initY&&(this.touch.yTemMove=this.touch.initY-this.touch.yHasMove,this.dispatch(2)),this.move(null,this.touch.yTemMove)},toLeft:function(){this.touch||this.throwError(1),this.methodsMove(!0,0)},toRight:function(){this.touch||this.throwError(1);var t=-(this.el.clientWidth-this.touch.parentWidth);this.methodsMove(!0,t)},toTop:function(){this.touch||this.throwError(1),this.methodsMove(!1,0)},toBottom:function(){this.touch||this.throwError(1);var t=-(this.el.clientHeight-this.touch.parentHeight);this.methodsMove(!1,t)},methodsMove:function(t,e){var o=this;clearTimeout(this.touch.transitionTimer),this.needTransition=!0;var i=void 0,n=void 0;i=t?e:this.touch.xHasMove,n=t?this.touch.yHasMove:e,setTimeout(function(){o.$refs.touch.style[r]="translate3d("+i+"px, "+n+"px, 0)",t?o.touch.xHasMove=e:o.touch.yHasMove=e},0);var s=this.scrollTransitionTime>0?1e3*this.scrollTransitionTime:0;this.touch.transitionTimer=setTimeout(function(){o.needTransition=!1},s)},dispatch:function(t){var e=this;clearTimeout(this.touch.eventTimer);var o=void 0,i=!0;if(0===t&&(o=n.h,this.touch.xTemMove||this.touch.xMoving||(o=n.f,i=!1)),1===t&&(o=n.g,this.touch.xTemMove||this.touch.xMoving||(o=n.e,i=!1)),2===t&&(o=n.l,this.touch.yTemMove||this.touch.yMoving||(o=n.j,i=!1)),3===t&&(o=n.k,this.touch.yTemMove||this.touch.yMoving||(o=n.i,i=!1)),o){var r=this.needTransition&&i?1e3*this.scrollTransitionTime:0;this.touch.eventTimer=setTimeout(function(){e.$emit(o)},r)}},throwError:function(t){var e=void 0;throw 0===t&&(e="没有镶嵌有效DOM!"),1===t&&(e="uppTouch没有正确的初始化"),e||(e="代码Bug,抛出了一个错误的错误类型:"+t),new TypeError(e)}},computed:{touchWrapperStyle:function(){var t={transition:""},e=parseFloat(this.scrollTransitionTime);return this.needTransition&&!isNaN(e)&&e>0&&(t={transition:"transform "+e+"s linear"}),t},touchClass:function(){return"{}"===JSON.stringify(this.diyStyle)?{width:"100%",height:"100%",overflow:"hidden"}:this.diyStyle}},props:{lockX:{type:Boolean,default:!1},lockY:{type:Boolean,default:!1},preventDefault:{type:Boolean,default:!1},scrollTransitionTime:{type:Number,default:.3},commonSlideTransition:{typ:Boolean,default:!1},diyStyle:{type:Object,default:function(){return{}}}}}},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=o(2),n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e.default=i.a,void 0!==("undefined"==typeof window?"undefined":n(window))&&window.Vue&&window.Vue.component("upp-touch",i.a)},function(t,e,o){"use strict";function i(t){o(3)}var n=o(0),r=o(11),s=o(8),u=i,c=s(n.a,r.a,!1,u,"data-v-1911a103",null);e.a=c.exports},function(t,e,o){var i=o(4);"string"==typeof i&&(i=[[t.i,i,""]]),i.locals&&(t.exports=i.locals);o(6)("3e57b1c9",i,!0,{})},function(t,e,o){e=t.exports=o(5)(!1),e.push([t.i,"",""])},function(t,e){function o(t,e){var o=t[1]||"",n=t[3];if(!n)return o;if(e&&"function"==typeof btoa){var r=i(n);return[o].concat(n.sources.map(function(t){return"/*# sourceURL="+n.sourceRoot+t+" */"})).concat([r]).join("\n")}return[o].join("\n")}function i(t){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t))))+" */"}t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var i=o(e,t);return e[2]?"@media "+e[2]+"{"+i+"}":i}).join("")},e.i=function(t,o){"string"==typeof t&&(t=[[null,t,""]]);for(var i={},n=0;n<this.length;n++){var r=this[n][0];"number"==typeof r&&(i[r]=!0)}for(n=0;n<t.length;n++){var s=t[n];"number"==typeof s[0]&&i[s[0]]||(o&&!s[2]?s[2]=o:o&&(s[2]="("+s[2]+") and ("+o+")"),e.push(s))}},e}},function(t,e,o){function i(t){for(var e=0;e<t.length;e++){var o=t[e],i=a[o.id];if(i){i.refs++;for(var n=0;n<i.parts.length;n++)i.parts[n](o.parts[n]);for(;n<o.parts.length;n++)i.parts.push(r(o.parts[n]));i.parts.length>o.parts.length&&(i.parts.length=o.parts.length)}else{for(var s=[],n=0;n<o.parts.length;n++)s.push(r(o.parts[n]));a[o.id]={id:o.id,refs:1,parts:s}}}}function n(){var t=document.createElement("style");return t.type="text/css",f.appendChild(t),t}function r(t){var e,o,i=document.querySelector("style["+y+'~="'+t.id+'"]');if(i){if(v)return p;i.parentNode.removeChild(i)}if(M){var r=l++;i=d||(d=n()),e=s.bind(null,i,r,!1),o=s.bind(null,i,r,!0)}else i=n(),e=u.bind(null,i),o=function(){i.parentNode.removeChild(i)};return e(t),function(i){if(i){if(i.css===t.css&&i.media===t.media&&i.sourceMap===t.sourceMap)return;e(t=i)}else o()}}function s(t,e,o,i){var n=o?"":i.css;if(t.styleSheet)t.styleSheet.cssText=T(e,n);else{var r=document.createTextNode(n),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(r,s[e]):t.appendChild(r)}}function u(t,e){var o=e.css,i=e.media,n=e.sourceMap;if(i&&t.setAttribute("media",i),m.ssrId&&t.setAttribute(y,e.id),n&&(o+="\n/*# sourceURL="+n.sources[0]+" */",o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */"),t.styleSheet)t.styleSheet.cssText=o;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(o))}}var c="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!c)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var h=o(7),a={},f=c&&(document.head||document.getElementsByTagName("head")[0]),d=null,l=0,v=!1,p=function(){},m=null,y="data-vue-ssr-id",M="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());t.exports=function(t,e,o,n){v=o,m=n||{};var r=h(t,e);return i(r),function(e){for(var o=[],n=0;n<r.length;n++){var s=r[n],u=a[s.id];u.refs--,o.push(u)}e?(r=h(t,e),i(r)):r=[];for(var n=0;n<o.length;n++){var u=o[n];if(0===u.refs){for(var c=0;c<u.parts.length;c++)u.parts[c]();delete a[u.id]}}}};var T=function(){var t=[];return function(e,o){return t[e]=o,t.filter(Boolean).join("\n")}}()},function(t,e){t.exports=function(t,e){for(var o=[],i={},n=0;n<e.length;n++){var r=e[n],s=r[0],u=r[1],c=r[2],h=r[3],a={id:t+":"+n,css:u,media:c,sourceMap:h};i[s]?i[s].parts.push(a):o.push(i[s]={id:s,parts:[a]})}return o}},function(t,e){t.exports=function(t,e,o,i,n,r){var s,u=t=t||{},c=typeof t.default;"object"!==c&&"function"!==c||(s=t,u=t.default);var h="function"==typeof u?u.options:u;e&&(h.render=e.render,h.staticRenderFns=e.staticRenderFns,h._compiled=!0),o&&(h.functional=!0),n&&(h._scopeId=n);var a;if(r?(a=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),i&&i.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(r)},h._ssrRegister=a):i&&(a=i),a){var f=h.functional,d=f?h.render:h.beforeCreate;f?(h._injectStyles=a,h.render=function(t,e){return a.call(e),d(t,e)}):h.beforeCreate=d?[].concat(d,a):[a]}return{esModule:s,exports:u,options:h}}},function(t,e,o){"use strict";function i(t){return!1!==r&&("standard"===r?t:r+t.charAt(0).toUpperCase()+t.substr(1))}e.a=i;var n=document.createElement("div").style,r=function(){var t={webkit:"webkitTransform",Moz:"MozTransform",O:"OTransform",ms:"msTransform",standard:"transform"};for(var e in t)return void 0!==n[t[e]]&&e}()},function(t,e,o){"use strict";o.d(e,"h",function(){return i}),o.d(e,"g",function(){return n}),o.d(e,"l",function(){return r}),o.d(e,"k",function(){return s}),o.d(e,"f",function(){return u}),o.d(e,"e",function(){return c}),o.d(e,"j",function(){return h}),o.d(e,"i",function(){return a}),o.d(e,"b",function(){return f}),o.d(e,"c",function(){return d}),o.d(e,"d",function(){return l}),o.d(e,"a",function(){return v});var i="x-start",n="x-end",r="y-start",s="y-end",u="XStart",c="XEnd",h="YStart",a="YEnd",f="leftMoving",d="rightMoving",l="topMoving",v="bottomMoving"},function(t,e,o){"use strict";var i=function(){var t=this,e=t.$createElement,o=t._self._c||e;return o("div",{ref:"uppTouch",style:t.touchClass,attrs:{id:"upp-touch"}},[o("div",{ref:"touch",staticClass:"touch-wrapper",style:t.touchWrapperStyle,on:{touchstart:t.touchStart,touchmove:t.touchMove,touchend:t.touchEnd}},[t._t("default")],2)])},n=[],r={render:i,staticRenderFns:n};e.a=r}])}); //# sourceMappingURL=v-touch.min.js.map