39 lines
1.7 KiB
JavaScript
Executable File
39 lines
1.7 KiB
JavaScript
Executable File
/****************************************************************************************************************
|
|
* CLASS vibrate: helper-class for using vibration on mobiles *
|
|
* *
|
|
* methods: start(duration:Number or Array(Number)):void --> starts vibrating for given amount of ms *
|
|
* └-> may also be an array with format: [vibrate,pause,vibrate,pause...] in ms *
|
|
* *
|
|
* stop(void):void --> stops vibrating *
|
|
* *
|
|
* objects: patterns --> predefined vibration-patterns *
|
|
****************************************************************************************************************/
|
|
|
|
|
|
var vibrate = {
|
|
start: function(duration) {
|
|
if (duration==undefined || duration==null) duration = this.patterns.long;
|
|
duration = [duration].reduce(function(a, b) { return [].concat(a).concat(b); });
|
|
|
|
if (navigator.vibrate) {
|
|
navigator.vibrate(duration);
|
|
}
|
|
console.debug('vibrate:', duration);
|
|
},
|
|
|
|
stop: function() {
|
|
if (navigator.vibrate) {
|
|
console.debug('stop vibrating');
|
|
navigator.vibrate([]);
|
|
}
|
|
},
|
|
|
|
patterns: {
|
|
micro: 50,
|
|
mini: 100,
|
|
short: 200,
|
|
long: 2000,
|
|
alarm: [100,50,100],
|
|
poi: [2000,200,2000]
|
|
}
|
|
} |