-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmtouch.min.js
2 lines (2 loc) · 10.9 KB
/
mtouch.min.js
1
2
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.MTouch=e()}(this,function(){"use strict";function t(){var t=document.createElement("style");return t.type="text/css",document.head.appendChild(t),t.sheet}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(!(this instanceof n))return new n(t);this.use={drag:!1,pinch:!1,rotate:!1,singlePinch:!1,singleRotate:!1},this.operator=this.el=r.getEl(t),this.draging=this.pinching=this.rotating=this.singlePinching=this.singleRotating=!1,this.fingers=0,this.startScale=1,this.startPoint={},this.secondPoint={},this.pinchStartLength=null,this.singlePinchStartLength=null,this.vector1={},this.singleBasePoint={},this._css(),this._driveBus(),this._bind()}var i="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},o=void 0,r={getLength:function(t){return"object"!==(void 0===t?"undefined":i(t))?void console.error("getLength error!"):Math.sqrt(t.x*t.x+t.y*t.y)},getAngle:function(t,e){if("object"!==(void 0===t?"undefined":i(t))||"object"!==(void 0===e?"undefined":i(e)))return void console.error("getAngle error!");var n=t.x*e.y-e.x*t.y>0?1:-1,o=this.getLength(t),r=this.getLength(e),s=o*r,h=void 0,c=void 0;return 0===s?0:(h=t.x*e.x+t.y*e.y,c=h/s,c>1&&(c=1),c<-1&&(c=-1),Math.acos(c)*n*180/Math.PI)},getBasePoint:function(t){if(!t)return{x:0,y:0};var e=this.getOffset(t),n=e.left+t.getBoundingClientRect().width/2,i=e.top+t.getBoundingClientRect().width/2;return{x:Math.round(n),y:Math.round(i)}},extend:function(t,e){for(var n in e)e.hasOwnProperty(n)&&("object"!=i(e[n])||e[n]instanceof Node?t[n]=e[n]:("object"!==i(t[n])&&(t[n]={}),this.extend(t[n],e[n])));return t},getVector:function(t,e){return"object"!==(void 0===t?"undefined":i(t))||"object"!==(void 0===e?"undefined":i(e))?void console.error("getvector error!"):{x:Math.round(t.x-e.x),y:Math.round(t.y-e.y)}},getPoint:function(t,e){return t&&t.touches[e]?{x:Math.round(t.touches[e].pageX),y:Math.round(t.touches[e].pageY)}:void console.error("getPoint error!")},getOffset:function(t){t="string"==typeof t?document.querySelector(t):t;var e=t.getBoundingClientRect();return{left:e.left+document.body.scrollLeft,top:e.top+document.body.scrollTop,width:t.offsetWidth,height:t.offsetHeight}},matrixTo:function(t){var e=t.replace("matrix(","").replace(")","").split(","),n=e[0],i=e[1],o=i/n,r=180*Math.atan(o)/Math.PI,s=n/Math.cos(Math.PI/180*r);return{x:parseInt(e[4]),y:parseInt(e[5]),scale:s,rotate:r}},getUseName:function(t){var e=t.replace("start",""),n=-1!==e.indexOf("rotate")?"nd":"end";return e=e.replace(n,"")},domify:function(t){var e=document.implementation.createHTMLDocument();return e.body.innerHTML=t,e.body.children},getEl:function(t){if(!t)return void console.error("el error,there must be a el!");var e=void 0;if("string"==typeof t)e=document.querySelector(t);else{if(!(t instanceof Node))return void console.error("el error,there must be a el!");e=t}return e},data:function(t,e){return t=this.getEl(t),t.getAttribute("data-"+e)},include:function(t,e){return!!t.indexOf&&-1!==t.indexOf(e)},getPos:function(t){if(t){t=this.getEl(t);var e=void 0,n=window.getComputedStyle(t,null),i=n.transform||n.webkitTransform;return e=window.getComputedStyle&&"none"!==i?this.matrixTo(i):{x:0,y:0,scale:1,rotate:0},JSON.parse(t.getAttribute("data-mtouch-status"))||e}},addCssRule:function(e,n){o||(o=t()),o.insertRule(e+"{"+n+"}",o.rules.length)}},s=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),h=function(){function t(n){e(this,t),this.handlers=[],this.el=n}return s(t,[{key:"add",value:function(t){return this.handlers.push(t),this}},{key:"del",value:function(t){var e=this;return t?this.handlers.forEach(function(n,i){n===t&&e.handlers.splice(i,1)}):this.handlers=[],this}},{key:"fire",value:function(){var t=this,e=arguments;if(this.handlers&&0!==!this.handlers.length)return this.handlers.forEach(function(n){"function"==typeof n&&n.apply(t.el,e)}),this}}]),t}(),c=["touchstart","touchmove","touchend","drag","dragstart","dragend","pinch","pinchstart","pinchend","rotate","rotatestart","rotatend","singlePinchstart","singlePinch","singlePinchend","singleRotate","singleRotatestart","singleRotatend"],a=["touchstart","touchmove","touchend","touchcancel"];return n.prototype._driveBus=function(){var t=this;c.forEach(function(e){t[e]=new h(t.el)})},n.prototype._bind=function(){var t=this;a.forEach(function(e){var n="touchcancel"==e?"end":e.replace("touch","");t["_"+n+"_bind"]=t["_"+n].bind(t),t.el.addEventListener(e,t["_"+n+"_bind"],!1)})},n.prototype.destroy=function(){var t=this;a.forEach(function(e){var n="touchcancel"==e?"end":e.replace("touch","");t.el.removeEventListener(e,t["_"+n+"_bind"],!1)})},n.prototype._start=function(t){if(t.touches&&"touchstart"===t.type){if(this.fingers=t.touches.length,this.startPoint=r.getPoint(t,0),this.singleBasePoint=r.getBasePoint(this.operator),this.fingers>1)this.secondPoint=r.getPoint(t,1),this.vector1=r.getVector(this.secondPoint,this.startPoint),this.pinchStartLength=r.getLength(this.vector1);else if(this.use.singlePinch){var e=r.getVector(this.startPoint,this.singleBasePoint);this.singlePinchStartLength=r.getLength(e)}this.touchstart.fire({origin:t,eventType:"touchstart"})}},n.prototype._move=function(t){if(t.touches&&"touchmove"===t.type){var e=r.data(t.target,"singleButton"),n=t.touches.length,i=r.getPoint(t,0),o=void 0,s=void 0,h=void 0,c=void 0,a=void 0;if(n<this.fingers)return this.startPoint=i,void(this.fingers=n);if(!(n>1)||this.secondPoint&&this.vector1&&this.pinchStartLength||(this.secondPoint=r.getPoint(t,1),this.vector1=r.getVector(this.secondPoint,this.startPoint),this.pinchStartLength=r.getLength(this.vector1)),n>1){var u=r.getPoint(t,1),d=r.getVector(u,i);this.use.pinch&&(s=r.getLength(d),this._eventFire("pinch",{delta:{scale:s/this.pinchStartLength},origin:t}),this.pinchStartLength=s),this.use.rotate&&(this._eventFire("rotate",{delta:{rotate:r.getAngle(this.vector1,d)},origin:t}),this.vector1=d)}else this.use.singlePinch&&e&&(a=r.getVector(i,this.singleBasePoint),o=r.getLength(a),this._eventFire("singlePinch",{delta:{scale:o/this.singlePinchStartLength,deltaX:i.x-this.startPoint.x,deltaY:i.y-this.startPoint.y},origin:t}),this.singlePinchStartLength=o),this.use.singleRotate&&e&&(h=r.getVector(this.startPoint,this.singleBasePoint),c=r.getVector(i,this.singleBasePoint),this._eventFire("singleRotate",{delta:{rotate:r.getAngle(h,c)},origin:t}));this.use.drag&&(e||this._eventFire("drag",{delta:{deltaX:i.x-this.startPoint.x,deltaY:i.y-this.startPoint.y},origin:t})),this.startPoint=i,this.touchmove.fire({eventType:"touchmove",origin:t}),t.preventDefault()}},n.prototype._end=function(t){var e=this;(t.touches||"touchend"===t.type||"touchcancel"===t.type)&&(["pinch","drag","rotate","singleRotate","singlePinch"].forEach(function(n){e._eventEnd(n,{origin:t})}),this.touchend.fire({eventType:"touchend",origin:t}))},n.prototype._eventFire=function(t,e){var n=t+"ing",i=t+"start";this[n]?(e.eventType=t,this[t].fire(e)):(e.eventType=i,this[i].fire(e),this[n]=!0)},n.prototype._eventEnd=function(t,e){var n=t+"ing",i=void 0;i="rotate"==t||"singleRotate"==t?t+"nd":t+"end",this[n]&&(e.eventType=i,this[i].fire(e),this[n]=!1)},n.prototype._addButton=function(t){var e=r.domify("<div class=\"mtouch-singleButton\" data-singleButton='true'></div>")[0];t.appendChild(e),t.setAttribute("data-mtouch-addButton",!0)},n.prototype.switch=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=void 0;if(!t)return void(this.operator=this.el);this.operator=n=r.getEl(t),!r.data(n,"mtouch-addButton")&&(this.use.singleRotate||this.use.singlePinch)&&e&&this._addButton(n)},n.prototype.on=function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},i=arguments[2];return r.include(t," ")?t.split(" ").forEach(function(t){e._on(t,n,i)}):this._on(t,n,i),this},n.prototype._on=function(t,e,n){this.use[r.getUseName(t)]=!0,this[t].add(e),this.switch(n)},n.prototype.off=function(t,e){this[t].del(e)},n.prototype._css=function(){r.addCssRule(".mtouch-singleButton","z-index:9999;position:absolute;right:-15px;bottom: -15px;width:30px;height: 30px;background-size: 100% 100%;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTMyIDc5LjE1OTI4NCwgMjAxNi8wNC8xOS0xMzoxMzo0MCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvY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