Selaa lähdekoodia

Updates to leap.js and index.html

Added timing code to limit gesture calls.
Added gesture to access the overview.
index.html includes the leap plugin
Rory Hardy 12 vuotta sitten
vanhempi
commit
70cade3732
2 muutettua tiedostoa jossa 45 lisäystä ja 19 poistoa
  1. 5 1
      index.html
  2. 40 18
      plugin/leap/leap.js

+ 5 - 1
index.html

@@ -359,6 +359,9 @@ function linkify( selector ) {
 				progress: true,
 				progress: true,
 				history: true,
 				history: true,
 				center: true,
 				center: true,
+				leap: {
+			    invert : true
+			  },
 
 
 				theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
 				theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
 				transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
 				transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
@@ -370,7 +373,8 @@ function linkify( selector ) {
 					{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
 					{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
 					{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
 					{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
 					{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
 					{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
-					{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
+					{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
+					{ src: 'plugin/leap/leap.js', async: true, }
 					// { src: 'plugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }
 					// { src: 'plugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }
 					// { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
 					// { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
 				]
 				]

+ 40 - 18
plugin/leap/leap.js

@@ -21,34 +21,56 @@ var b=right.criteria;if(a!==b){if(a>b||a===void 0)return 1;if(a<b||b===void 0)re
  */
  */
 
 
 (function () {
 (function () {
-  var controller = new Leap.Controller({enableGestures: true}),
+  var controller  = new Leap.Controller({enableGestures: true}),
-      config = Reveal.getConfig().leap ||
+      lastGesture = 0,
+      config      = Reveal.getConfig().leap ||
         {
         {
           invert: false
           invert: false
-        };
+        },
+      now;
 
 
   controller.on('frame', function (frame) {
   controller.on('frame', function (frame) {
-    if (frame.gestures.length > 0) {
+    now = new Date().getTime();
-      var gesture = frame.gestures[0];
+
-      //console.log(gesture);
+    if( lastGesture === 0 ) {
-      var x = gesture.direction[0];
+      lastGesture = now;
-      var y = gesture.direction[1];
+    }
-      if (gesture.state === 'start' && gesture.type === 'swipe') {
+
-        if (Math.abs(x) > Math.abs(y)) {
+    if ( (now - lastGesture) > 500 && frame.gestures.length > 0 ) {
-          if (x > 0) {
+      var gesture = frame.gestures[0],
-            config.invert ? Reveal.left() : Reveal.right();
+          x       = gesture.direction[0],
+          y       = gesture.direction[1];
+
+      
+      if ( gesture.speed > 1000 && gesture.state === 'start' && gesture.type === 'swipe' ) {
+        if( frame.fingers.length > 1 ) {
+          if ( Math.abs(x) > Math.abs(y) ) {
+            if ( x > 0 ) {
+              config.invert ? Reveal.left() : Reveal.right();
+            } else {
+              config.invert ? Reveal.right() : Reveal.left();
+            }
+
+            lastGesture = now;
           } else {
           } else {
-            config.invert ? Reveal.right() : Reveal.left();
+            if ( y > 0 ) {
+              config.invert ? Reveal.down() : Reveal.up();
+            } else {
+              config.invert ? Reveal.up() : Reveal.down();
+            }
           }
           }
-        } else {
+
-          if (y > 0) {
+          lastGesture = now;
-            config.invert ? Reveal.down() : Reveal.up();
+        } else if( frame.hands.length == 2 ) {
-          } else {
+          if ( y > 0 ) {
-            config.invert ? Reveal.up() : Reveal.down();
+            Reveal.toggleOverview();
           }
           }
+
+          lastGesture = now;
         }
         }
       }
       }
     }
     }
   });
   });
+
   controller.connect();
   controller.connect();
 })();
 })();