Skip to content

Commit

Permalink
fix: Hotkey of switching post is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Mar 12, 2020
1 parent 79ae4ff commit e77f00b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion source/js/stun-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $(document).ready(function () {
Stun.utils.showThemeInConsole();

if (CONFIG.shortcuts && CONFIG.shortcuts.switch_post) {
Stun.utils.registerHotkeyToSwitchPost();
Stun.utils.registerSwitchPost();
}

// Not reload this, because it's changeless.
Expand Down
22 changes: 12 additions & 10 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,20 @@ Stun.utils = Stun.$u = {
.append($icon);
},
// Switch to the prev / next post by shortcuts.
registerHotkeyToSwitchPost: function () {
var _this = this;
registerSwitchPost: function () {
var keyLeft = this.codeToKeyCode('ArrowLeft');
var keyRight = this.codeToKeyCode('ArrowRight');

$(document).on('keydown', function (e) {
var isPrev = e.keyCode === _this.codeToKeyCode('ArrowLeft');
var isNext = e.keyCode === _this.codeToKeyCode('ArrowRight');
var isPrev = e.keyCode === keyLeft;
var isNext = e.keyCode === keyRight;

if (e.ctrlKey && isPrev) {
var prev = $('.paginator-post-prev').find('a')[0];
prev && prev.click();
} else if (e.ctrlKey && isNext) {
var next = $('.paginator-post-next').find('a')[0];
next && next.click();
if (e.ctrlKey) {
if (isPrev) {
$('.paginator-prev a')[0].click();
} else if (isNext) {
$('.paginator-next a')[0].click();
}
}
});
},
Expand Down

0 comments on commit e77f00b

Please sign in to comment.