Skip to content

Instantly share code, notes, and snippets.

@rainly
Forked from huacnlee/will_paginate.js
Created August 24, 2011 05:32
Show Gist options
  • Select an option

  • Save rainly/1167368 to your computer and use it in GitHub Desktop.

Select an option

Save rainly/1167368 to your computer and use it in GitHub Desktop.
使 WillPaginate 支持用左右键翻页
// From Dribbble.com
// Keyboard shortcuts for browsing pages of lists
// 使 WillPaginate 支持用左右键翻页
(function($) {
$(document).keydown(handleKey);
function handleKey(e){
var left_arrow = 37;
var right_arrow = 39;
if (e.target.localName == 'body' || e.target.localName == '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 .prev_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