Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
createTouchEvent
(function() {
var ua = /iPhone|iP[oa]d/.test(navigator.userAgent) ? 'iOS' : /Android/.test(navigator.userAgent) ? 'Android' : 'PC';
document.addEventListener('DOMContentLoaded', function(event) {
if(ua === 'PC') {
return;
}
document.addEventListener('touchstart', function() {
console.log('Touch!');
}, false);
var touchEvent = createTouchEvent();
setTimeout(function() {
document.dispatchEvent(touchEvent);
}, 3000);
}, false);
function createTouchEvent(option) {
var option = option || {};
var param = {
type: 'touchstart',
canBubble: true,
cancelable: true,
view: window,
detail: 0,
screenX: 0,
screenY: 0,
clientX: 0,
clientY: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
touches: 0,
targetTouches: 0,
changedTouches: 0,
scale: 0,
rotation: 0,
touchItem: 0
};
for(var i in param) {
if(param.hasOwnProperty(i)) {
param[i] = option[i] !== undefined ? option[i] : param[i];
}
}
var event = document.createEvent('TouchEvent');
if(ua === 'Android') {
event.initTouchEvent(param.touchItem, param.touchItem, param.touchItem, param.type, param.view, param.screenX, param.screenY, param.clientX, param.clientY, param.ctrlKey, param.altKey, param.shiftKey, param.metaKey);
} else {
event.initTouchEvent(param.type, param.canBubble, param.cancelable, param.view, param.detail, param.screenX, param.screenY, param.clientX, param.clientY, param.ctrlKey, param.altKey, param.shiftKey, param.metaKey, param.touches, param.targetTouches, param.changedTouches, param.scale, param.rotation);
}
return event;
}
})();
@ghost

This comment has been minimized.

Copy link

commented Jan 25, 2016

SSH URLs can be used locally, or as a secure way of deploying your code to production servers. You can also use SSH agent forwarding with your deploy script to avoid managing keys on the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.