summaryrefslogtreecommitdiffstats
path: root/assets/javascript/core
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-03 15:24:57 -0700
committerSamy Pessé <samypesse@gmail.com>2014-04-03 15:24:57 -0700
commitc934238f3d877e7f774a4b9ec4f33a5342e3914b (patch)
tree0b03fab93550cfc93cdaa971d2fc222aa8f08e67 /assets/javascript/core
parentab489599688f53df5cb53c1661c53e5e320269ad (diff)
downloadgitbook-c934238f3d877e7f774a4b9ec4f33a5342e3914b.zip
gitbook-c934238f3d877e7f774a4b9ec4f33a5342e3914b.tar.gz
gitbook-c934238f3d877e7f774a4b9ec4f33a5342e3914b.tar.bz2
Fix #9: add keyboard navigation using right/left
Diffstat (limited to 'assets/javascript/core')
-rw-r--r--assets/javascript/core/keyboard.js24
-rw-r--r--assets/javascript/core/navigation.js17
2 files changed, 41 insertions, 0 deletions
diff --git a/assets/javascript/core/keyboard.js b/assets/javascript/core/keyboard.js
new file mode 100644
index 0000000..137ad57
--- /dev/null
+++ b/assets/javascript/core/keyboard.js
@@ -0,0 +1,24 @@
+define([
+ "jQuery",
+ "Mousetrap",
+ "core/navigation"
+], function($, Mousetrap, navigation){
+ // Bind keyboard shortcuts
+ var init = function() {
+ // Next
+ Mousetrap.bind(['right'], function(e) {
+ navigation.goNext();
+ return false;
+ });
+
+ // Prev
+ Mousetrap.bind(['left'], function(e) {
+ navigation.goPrev();
+ return false;
+ });
+ };
+
+ return {
+ init: init
+ };
+}); \ No newline at end of file
diff --git a/assets/javascript/core/navigation.js b/assets/javascript/core/navigation.js
new file mode 100644
index 0000000..bb3547c
--- /dev/null
+++ b/assets/javascript/core/navigation.js
@@ -0,0 +1,17 @@
+define([
+ "jQuery"
+], function($) {
+ var goNext = function() {
+ var url = $("link[rel='next']").attr("href");
+ if (url) location.href = url;
+ };
+ var goPrev = function() {
+ var url = $("link[rel='prev']").attr("href");
+ if (url) location.href = url;
+ };
+
+ return {
+ goNext: goNext,
+ goPrev: goPrev
+ };
+}); \ No newline at end of file