From fcc9c941378633358488d00b4f4f15566df4a34a Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 9 Jul 2014 12:20:06 +0200 Subject: [PATCH] Handle keycodes (left/right/space) to navigate the presentation. --- static/js/directives/pdfcanvas.js | 12 ++++++++++-- static/js/directives/presentation.js | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/static/js/directives/pdfcanvas.js b/static/js/directives/pdfcanvas.js index 9bc4007b..c6fa2165 100644 --- a/static/js/directives/pdfcanvas.js +++ b/static/js/directives/pdfcanvas.js @@ -215,12 +215,20 @@ define(['require', 'underscore', 'jquery', 'pdf'], function(require, _, $, pdf) pdfCanvas.redrawPage(); }); - $scope.prevPage = function() { + $scope.$on("prevPage", function() { pdfCanvas.prevPage(); + }); + + $scope.$on("nextPage", function() { + pdfCanvas.nextPage(); + }); + + $scope.prevPage = function() { + $scope.$emit("prevPage"); }; $scope.nextPage = function() { - pdfCanvas.nextPage(); + $scope.$emit("nextPage"); }; }]; diff --git a/static/js/directives/presentation.js b/static/js/directives/presentation.js index 41c2c3f2..9eb21b0e 100644 --- a/static/js/directives/presentation.js +++ b/static/js/directives/presentation.js @@ -367,6 +367,31 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, mediaStream.webrtc.e.off("statechange", updater); }; + $(document).on("keyup", function(event) { + if (!$scope.layout.presentation) { + return; + } + if ($(event.target).is("input,textarea,select")) { + return; + } + $scope.$apply(function() { + switch (event.keyCode) { + case 37: + // left arrow + $scope.$emit("prevPage"); + event.preventDefault(); + break; + case 39: + // right arrow + case 32: + // space + $scope.$emit("nextPage"); + event.preventDefault(); + break; + } + }); + }); + $scope.$watch("layout.presentation", function(newval, oldval) { if (newval && !oldval) { $scope.showPresentation();