Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created August 24, 2011 01:41
Show Gist options
  • Save huacnlee/1167112 to your computer and use it in GitHub Desktop.
Save huacnlee/1167112 to your computer and use it in GitHub Desktop.
使 WillPaginate 支持用左右键翻页
// Keyboard shortcuts for browsing pages of lists
(function($) {
$(document).keydown(handleKey);
function handleKey(e) {
var left_arrow = 37;
var right_arrow = 39;
if (e.target.nodeName == 'BODY' || e.target.nodeName == 'HTML') {
if (!e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
var code = e.which;
if (code == left_arrow) {
prevPage();
}
else if (code == right_arrow) {
nextPage();
}
}
}
}
function prevPage() {
var href = $('.pagination .previous_page').attr('href');
if (href && href != document.location) {
document.location = href;
}
}
function nextPage() {
var href = $('.pagination .next_page').attr('href');
if (href && href != document.location) {
document.location = href;
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment