-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-touch.min.js
1 lines (1 loc) · 4.38 KB
/
vue-touch.min.js
1
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(require("hammerjs")):"function"==typeof define&&define.amd?define(["hammerjs"],n):n(e.Hammer)}(this,function(e){"use strict";function n(e){for(var n=[],t=arguments.length-1;t-- >0;)n[t]=arguments[t+1];for(var i=0;i<n.length;i++)for(var o=n[i],r=Object.keys(o),a=0;a<r.length;a++){var s=r[a];e[s]=o[s]}return e}function t(){return{type:Object,default:function(){return{}}}}function i(e){return e.charAt(0).toUpperCase()+e.slice(1)}function o(n){var t=n.direction;if("string"==typeof t){var i="DIRECTION_"+t.toUpperCase();r.indexOf(t)>-1&&e.hasOwnProperty(i)?n.direction=e[i]:console.warn("[vue-touch] invalid direction: "+t)}return n}e="default"in e?e.default:e;var r=["up","down","left","right","horizontal","vertical","all"],a={},s={},p=["pan","panstart","panmove","panend","pancancel","panleft","panright","panup","pandown","pinch","pinchstart","pinchmove","pinchend","pinchcancel","pinchin","pinchout","press","pressup","rotate","rotatestart","rotatemove","rotateend","rotatecancel","swipe","swipeleft","swiperight","swipeup","swipedown","tap"],c={pan:"pan",panstart:"pan",panmove:"pan",panend:"pan",pancancel:"pan",panleft:"pan",panright:"pan",panup:"pan",pandown:"pan",pinch:"pinch",pinchstart:"pinch",pinchmove:"pinch",pinchend:"pinch",pinchcancel:"pinch",pinchin:"pinch",pinchout:"pinch",press:"press",pressup:"press",rotate:"rotate",rotatestart:"rotate",rotatemove:"rotate",rotateend:"rotate",rotatecancel:"rotate",swipe:"swipe",swipeleft:"swipe",swiperight:"swipe",swipeup:"swipe",swipedown:"swipe",tap:"tap"},l={props:{options:t(),tapOptions:t(),panOptions:t(),pinchOptions:t(),pressOptions:t(),rotateOptions:t(),swipeOptions:t(),tag:{type:String,default:"div"},enabled:{default:!0,type:[Boolean,Object]}},mounted:function(){this.$isServer||(this.hammer=new e.Manager(this.$el,this.options),this.recognizers={},this.setupBuiltinRecognizers(),this.setupCustomRecognizers(),this.updateEnabled(this.enabled))},destroyed:function(){this.$isServer||this.hammer.destroy()},watch:{enabled:{deep:!0,handler:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this).updateEnabled.apply(t,e);var t}}},methods:{setupBuiltinRecognizers:function(){for(var e=this,t=0;t<p.length;t++){var i=p[t];if(e._events[i]){var o=c[i],r=n({},a[o]||{},e[o+"Options"]);e.addRecognizer(o,r),e.addEvent(i)}}},setupCustomRecognizers:function(){for(var e=this,t=Object.keys(s),i=0;i<t.length;i++){var o=t[i];if(e._events[o]){var r=s[o],a=e[o+"Options"]||{},p=n({},r,a);e.addRecognizer(o,p,{mainGesture:p.type}),e.addEvent(o)}}},addRecognizer:function(n,t,r){void 0===r&&(r={});var a=r.mainGesture;if(!this.recognizers[n]){var s=new(e[i(a||n)])(o(t));this.recognizers[n]=s,this.hammer.add(s),s.recognizeWith(this.hammer.recognizers)}},addEvent:function(e){var n=this;this.hammer.on(e,function(t){return n.$emit(e,t)})},updateEnabled:function(e,n){var t=this;if(e===!0)this.enableAll();else if(e===!1)this.disableAll();else if("object"==typeof e)for(var i=Object.keys(e),o=0;o<i.length;o++){var r=i[o];t.recognizers[r]&&(e[r]?t.enable(r):t.disable(r))}},enable:function(e){var n=this.recognizers[e];n.options.enable||n.set({enable:!0})},disable:function(e){var n=this.recognizers[e];n.options.enable&&n.set({enable:!1})},toggle:function(e){var n=this.recognizers[e];n&&(n.options.enable?this.disable(e):this.enable(e))},enableAll:function(e){this.toggleAll({enable:!0})},disableAll:function(e){this.toggleAll({enable:!1})},toggleAll:function(e){for(var n=this,t=e.enable,i=Object.keys(this.recognizers),o=0;o<i.length;o++){var r=n.recognizers[i[o]];r.options.enable!==t&&r.set({enable:t})}},isEnabled:function(e){return this.recognizers[e]&&this.recognizers[e].options.enable}},render:function(e){return e(this.tag,{},this.$slots.default)}},u=!1,h={config:a,customEvents:s};h.install=function(e,t){void 0===t&&(t={});var i=t.name||"v-touch";e.component(i,n(l,{name:i})),u=!0}.bind(h),h.registerCustomEvent=function(e,n){return void 0===n&&(n={}),u?void console.warn("\n [vue-touch]: Custom Event '"+e+"' couldn't be added to vue-touch.\n Custom Events have to be registered before installing the plugin.\n "):(n.event=e,s[e]=n,void(l.props[e+"Options"]={type:Object,default:function(){return{}}}))}.bind(h),h.component=l,"object"==typeof exports?module.exports=h:"function"==typeof define&&define.amd?define([],function(){return h}):"undefined"!=typeof window&&window.Vue&&(window.VueTouch=h,Vue.use(h))});