Created
August 24, 2011 01:41
-
-
Save huacnlee/1167112 to your computer and use it in GitHub Desktop.
使 WillPaginate 支持用左右键翻页
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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