Touch and vibrate support
by Maksim Kachurin
JavaScript
// Touch screen support for dragging
var touchSupported = 'ontouchstart' in window,
mousedownEvent = 'mousedown'+( touchSupported ? ' touchstart' : ''),
mousemoveEvent = 'mousemove'+( touchSupported ? ' touchmove' : ''),
mouseupEvent = 'mouseup' + ( touchSupported ? ' touchend' : '');
// Vibrate support
var vibrate = 'vibrate' in navigator,
vibrateTimeout;
// startVibrate(lenght, timeout)
var startVibrate = function(n,t) {
n = n || 50;
t = t || 150;
clearTimeout(vibrateTimeout);
vibrateTimeout = setTimeout(function(){
if (vibrate) navigator.vibrate(n);
},t);
}