Skip to content

Instantly share code, notes, and snippets.

@basecss
Created January 28, 2014 12:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save basecss/8666646 to your computer and use it in GitHub Desktop.
Save basecss/8666646 to your computer and use it in GitHub Desktop.
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;
}
})();
Copy link

ghost 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