Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add navigation by arrows #87

Merged
merged 1 commit into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ $( document ).ready(function() {
hljs.highlightBlock(block);
});

var KEY_CODES = {
PREVIOUS_KEY: 37,
NEXT_KEY: 39
};

$(document).on('keydown', function (e) {
switch (e.keyCode) {
case KEY_CODES.NEXT_KEY:
e.preventDefault();
window.location.href = $('.nav-chapters.next').attr('href');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it, but you have to check that it actually exists. Because when you are on the first page and then press left arrow you get undefined and that page does not exist. I will fix it now ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. Thank you!

break;
case KEY_CODES.PREVIOUS_KEY:
e.preventDefault();
window.location.href = $('.nav-chapters.previous').attr('href');
break;
}
});

// Interesting DOM Elements
var html = $("html");
Expand Down
4 changes: 2 additions & 2 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@
</div>

{{#previous}}
<a href="{{link}}" class="nav-chapters previous">
<a href="{{link}}" class="nav-chapters previous" title="&larr;">
<i class="fa fa-angle-left"></i>
</a>
{{/previous}}

{{#next}}
<a href="{{link}}" class="nav-chapters next">
<a href="{{link}}" class="nav-chapters next" title="&rarr;">
<i class="fa fa-angle-right"></i>
</a>
{{/next}}
Expand Down