mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Added "P" hotkey to post list
This commit is contained in:
27
public_html/js/Keyboard.js
Normal file
27
public_html/js/Keyboard.js
Normal file
@ -0,0 +1,27 @@
|
||||
var App = App || {};
|
||||
|
||||
App.Keyboard = function(mousetrap) {
|
||||
|
||||
function keyup(key, callback) {
|
||||
mousetrap.bind(key, simpleKeyPressed(callback), 'keyup');
|
||||
}
|
||||
|
||||
function keydown(key, callback) {
|
||||
mousetrap.bind(key, simpleKeyPressed(callback));
|
||||
}
|
||||
|
||||
function simpleKeyPressed(callback) {
|
||||
return function(e) {
|
||||
if (!e.altKey && !e.ctrlKey) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
keydown: keydown,
|
||||
keyup: keyup,
|
||||
};
|
||||
};
|
||||
|
||||
App.DI.register('keyboard', ['mousetrap'], App.Keyboard);
|
@ -7,7 +7,7 @@ App.Presenters.PagedCollectionPresenter = function(
|
||||
util,
|
||||
promise,
|
||||
api,
|
||||
mousetrap,
|
||||
keyboard,
|
||||
router,
|
||||
presenterManager,
|
||||
browsingSettings) {
|
||||
@ -56,16 +56,8 @@ App.Presenters.PagedCollectionPresenter = function(
|
||||
.fail(loaded);
|
||||
|
||||
if (!endlessScroll) {
|
||||
mousetrap.bind('a', function(e) {
|
||||
if (!e.altKey && !e.ctrlKey) {
|
||||
prevPage();
|
||||
}
|
||||
});
|
||||
mousetrap.bind('d', function(e) {
|
||||
if (!e.altKey && !e.ctrlKey) {
|
||||
nextPage();
|
||||
}
|
||||
});
|
||||
keyboard.keydown('a', prevPage);
|
||||
keyboard.keydown('d', nextPage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,4 +224,4 @@ App.Presenters.PagedCollectionPresenter = function(
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('pagedCollectionPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'mousetrap', 'router', 'presenterManager', 'browsingSettings'], App.Presenters.PagedCollectionPresenter);
|
||||
App.DI.register('pagedCollectionPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'keyboard', 'router', 'presenterManager', 'browsingSettings'], App.Presenters.PagedCollectionPresenter);
|
||||
|
@ -8,6 +8,7 @@ App.Presenters.PostListPresenter = function(
|
||||
promise,
|
||||
auth,
|
||||
router,
|
||||
keyboard,
|
||||
pagedCollectionPresenter,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
@ -57,6 +58,10 @@ App.Presenters.PostListPresenter = function(
|
||||
|
||||
function render() {
|
||||
$el.html(listTemplate());
|
||||
|
||||
keyboard.keyup('p', function() {
|
||||
$el.find('.posts li a').eq(0).focus();
|
||||
});
|
||||
}
|
||||
|
||||
function renderPosts(posts, clear) {
|
||||
@ -84,4 +89,4 @@ App.Presenters.PostListPresenter = function(
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'router', 'pagedCollectionPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostListPresenter);
|
||||
App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'router', 'keyboard', 'pagedCollectionPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostListPresenter);
|
||||
|
@ -4,7 +4,7 @@ App.Presenters = App.Presenters || {};
|
||||
App.Presenters.PostUploadPresenter = function(
|
||||
_,
|
||||
jQuery,
|
||||
mousetrap,
|
||||
keyboard,
|
||||
promise,
|
||||
util,
|
||||
auth,
|
||||
@ -45,8 +45,8 @@ App.Presenters.PostUploadPresenter = function(
|
||||
$el.find('.url-handler button').click(urlHandlerButtonClicked);
|
||||
$el.find('thead th.checkbox').click(postTableSelectAllCheckboxClicked);
|
||||
|
||||
mousetrap.bind('a', simpleKeyPressed(selectPrevPostTableRow), 'keyup');
|
||||
mousetrap.bind('d', simpleKeyPressed(selectNextPostTableRow), 'keyup');
|
||||
keyboard.keyup('a', selectPrevPostTableRow);
|
||||
keyboard.keyup('d', selectNextPostTableRow);
|
||||
|
||||
$el.find('.remove').click(removeButtonClicked);
|
||||
$el.find('.move-up').click(moveUpButtonClicked);
|
||||
@ -54,14 +54,6 @@ App.Presenters.PostUploadPresenter = function(
|
||||
$el.find('.submit').click(submitButtonClicked);
|
||||
}
|
||||
|
||||
function simpleKeyPressed(callback) {
|
||||
return function(e) {
|
||||
if (!e.altKey && !e.ctrlKey) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getDefaultPost() {
|
||||
return {
|
||||
safety: 'safe',
|
||||
@ -563,4 +555,4 @@ App.Presenters.PostUploadPresenter = function(
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('postUploadPresenter', ['_', 'jQuery', 'mousetrap', 'promise', 'util', 'auth', 'api', 'router', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostUploadPresenter);
|
||||
App.DI.register('postUploadPresenter', ['_', 'jQuery', 'keyboard', 'promise', 'util', 'auth', 'api', 'router', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostUploadPresenter);
|
||||
|
Reference in New Issue
Block a user