diff --git a/TODO b/TODO index be2faeee..07ad80ce 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/public_html/index.html b/public_html/index.html index c4f6e002..ff6d4ce4 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -69,6 +69,7 @@ + diff --git a/public_html/js/Keyboard.js b/public_html/js/Keyboard.js new file mode 100644 index 00000000..7581dcbc --- /dev/null +++ b/public_html/js/Keyboard.js @@ -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); diff --git a/public_html/js/Presenters/PagedCollectionPresenter.js b/public_html/js/Presenters/PagedCollectionPresenter.js index fab1d837..884c3d3f 100644 --- a/public_html/js/Presenters/PagedCollectionPresenter.js +++ b/public_html/js/Presenters/PagedCollectionPresenter.js @@ -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); diff --git a/public_html/js/Presenters/PostListPresenter.js b/public_html/js/Presenters/PostListPresenter.js index b74ce5ea..7c295ce9 100644 --- a/public_html/js/Presenters/PostListPresenter.js +++ b/public_html/js/Presenters/PostListPresenter.js @@ -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); diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js index 64777ca4..81d027fe 100644 --- a/public_html/js/Presenters/PostUploadPresenter.js +++ b/public_html/js/Presenters/PostUploadPresenter.js @@ -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);