1
0
Fork 0

Put the timing code back in.

Occasionally gestures were fired twice. This helps prevent that.
modified:   plugin/leap/leap.js
This commit is contained in:
Rory Hardy 2013-08-05 22:49:39 -05:00
parent dbcbc7aa69
commit 32865b43f8
1 changed files with 17 additions and 3 deletions

View File

@ -25,12 +25,14 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
leapConfig = Reveal.getConfig().leap, leapConfig = Reveal.getConfig().leap,
leapDOM = document.createElement('div'), leapDOM = document.createElement('div'),
body = document.body, body = document.body,
lastGesture = 0,
config = { config = {
naturalSwipe : true, naturalSwipe : true,
pointerDefault : 15, pointerDefault : 15,
pointerColor : '#00aaff', pointerColor : '#00aaff',
pointerOpacity : 0.75 pointerOpacity : 0.75
}; },
now;
// Merge user defined settings with defaults // Merge user defined settings with defaults
if ( leapConfig ) { if ( leapConfig ) {
@ -48,6 +50,12 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
body.appendChild(leapDOM); body.appendChild(leapDOM);
controller.on('frame', function (frame) { controller.on('frame', function (frame) {
// Timing code to rate limit gesture execution
now = new Date().getTime();
if( lastGesture === 0 ) {
lastGesture = now;
}
// Pointer code // Pointer code
if ( frame.hands.length === 1 && frame.fingers.length === 1 ) { if ( frame.hands.length === 1 && frame.fingers.length === 1 ) {
@ -73,13 +81,13 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
} }
// Gestures // Gestures
if ( frame.gestures.length > 0 ) { if ( (now - lastGesture) > 500 && frame.gestures.length > 0 ) {
var gesture = frame.gestures[0]; var gesture = frame.gestures[0];
// One hand gestures // One hand gestures
if( frame.hands.length === 1 ) { if( frame.hands.length === 1 ) {
// Swipe gestures. 2+ fingers. // Swipe gestures. 2+ fingers.
if ( frame.fingers.length > 1 && gesture.speed > 1000 && gesture.state === 'start' && gesture.type === 'swipe' ) { if ( frame.fingers.length > 1 && gesture.speed > 1000 && gesture.type === 'swipe' ) {
var x = gesture.direction[0], var x = gesture.direction[0],
y = gesture.direction[1]; y = gesture.direction[1];
@ -90,6 +98,8 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
} else { } else {
config.naturalSwipe ? Reveal.right() : Reveal.left(); config.naturalSwipe ? Reveal.right() : Reveal.left();
} }
lastGesture = now;
// Up/down swipe gestures // Up/down swipe gestures
} else { } else {
if ( y > 0 ) { if ( y > 0 ) {
@ -97,6 +107,8 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
} else { } else {
config.naturalSwipe ? Reveal.up() : Reveal.down(); config.naturalSwipe ? Reveal.up() : Reveal.down();
} }
lastGesture = now;
} }
} }
// Two hand gestures // Two hand gestures
@ -105,6 +117,8 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
if ( gesture.direction[1] > 0 ) { if ( gesture.direction[1] > 0 ) {
Reveal.toggleOverview(); Reveal.toggleOverview();
} }
lastGesture = now;
} }
} }
}); });