Build mobile apps with simple HTML, CSS, and JS components. http://goratchet.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6 lines
2.5 KiB

/*!
* TouchFaker - v1.1.0 - 2015-05-21
* https://github.com/Johann-S/TouchFaker
* Copyright (c) 2015 Johann SERVOIRE; Licensed MIT
*/
!function(){"use strict";function a(a,b,c,d,e){d=d||0,e=e||0,this.identifier=b,this.target=a,this.clientX=c.clientX+d||0,this.clientY=c.clientY+e||0,this.screenX=c.screenX+d||0,this.screenY=c.screenY+e||0,this.pageX=c.pageX+d||0,this.pageY=c.pageY+e||0}function b(){var a=[];return a.item=function(a){return this[a]||null},a.identifiedTouch=function(a){return this[a+1]||null},a}function c(){for(var a=[window,document.documentElement],b=["ontouchstart","ontouchmove","ontouchcancel","ontouchend"],c=0;c<a.length;c++)for(var d=0;d<b.length;d++)a[c]&&void 0===a[c][b[d]]&&(a[c][b[d]]=null)}function d(){return"ontouchstart"in window||window.Modernizr&&window.Modernizr.touch||(navigator.msMaxTouchPoints||navigator.maxTouchPoints)>2}function e(a,b,c){var d=document.createEvent("Event");d.initEvent(a,!0,!0);var e="undefined"!=typeof c?g(c):f(b);d.touches=i(e,a,b),d.targetTouches=i(e,a,b),d.changedTouches=j(e,a,b),b.dispatchEvent(d)}function f(a){var b=a.getBoundingClientRect();return{pageX:b.left,pageY:b.top}}function g(a){var b={};return b.clientX=a.hasOwnProperty("clientX")?a.clientX:0,b.clientY=a.hasOwnProperty("clientY")?a.clientY:0,b.pageX=a.hasOwnProperty("pageX")?a.pageX:0,b.pageY=a.hasOwnProperty("pageY")?a.pageY:0,b.screenX=a.hasOwnProperty("screenX")?a.screenX:0,b.screenY=a.hasOwnProperty("screenY")?a.screenY:0,b}function h(c,d){var e=new b;return e.push(new a(d,1,c,0,0)),e}function i(a,c,d){var e=new b;return"touchend"!==c&&(e=h(a,d)),e}function j(a,b,c){var d=h(a,c);return("touchstart"===b||"touchend"===b)&&d.splice(0,1),d}document.createTouch||(document.createTouch=function(b,c,d,e,f,g,h,i,j){return(void 0===i||void 0===j)&&(i=e-window.pageXOffset,j=f-window.pageYOffset),new a(c,d,{pageX:e,pageY:f,screenX:g,screenY:h,clientX:i,clientY:j})}),document.createTouchList||(document.createTouchList=function(){for(var a=new b,c=0;c<arguments.length;c++)a[c]=arguments[c];return a.length=arguments.length,a}),"undefined"==typeof window.TouchFaker&&(window.TouchFaker={}),window.TouchFaker.multiTouchOffset=75,window.TouchFaker.init=function(){d()||c()}(),window.TouchFaker.fakeEvent=function(a,b,c){var d=b;if("string"==typeof b&&(d=document.querySelector(b)),!d)throw new Error("Target cannot be found");if(-1===a.indexOf("touch"))throw new Error("Not a touch event");if("undefined"!=typeof c&&"object"!=typeof c)throw new Error("Params has to be an Object");e(a,d,c)}}();