Added "P" hotkey to post list

This commit is contained in:
Marcin Kurczewski 2014-09-19 17:37:10 +02:00
parent e0bee3b78c
commit 57fb6da4b3
6 changed files with 42 additions and 26 deletions

1
TODO
View file

@ -9,7 +9,6 @@ everything related to posts:
- fix thumbnails for files that are neither youtube or images
- post list
- add P hotkey to post list
- add style for hovered and focused element
- fav count
- score

View file

@ -69,6 +69,7 @@
<script type="text/javascript" src="/js/Api.js"></script>
<script type="text/javascript" src="/js/Auth.js"></script>
<script type="text/javascript" src="/js/Util.js"></script>
<script type="text/javascript" src="/js/Keyboard.js"></script>
<script type="text/javascript" src="/js/BrowsingSettings.js"></script>
<script type="text/javascript" src="/js/Controls/FileDropper.js"></script>
<script type="text/javascript" src="/js/Controls/TagInput.js"></script>

View 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);

View file

@ -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);

View file

@ -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);

View file

@ -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);