diff --git a/public_html/css/post-list.css b/public_html/css/post-list.css index c62146aa..2e20f632 100644 --- a/public_html/css/post-list.css +++ b/public_html/css/post-list.css @@ -7,6 +7,13 @@ margin: 0 auto; } +#post-list .search { + margin-bottom: 1em; +} +#post-list .search input { + max-width: 20em; +} + #post-list ul { list-style-type: none; padding: 0; diff --git a/public_html/js/Presenters/PostListPresenter.js b/public_html/js/Presenters/PostListPresenter.js index 500df538..6188f2e3 100644 --- a/public_html/js/Presenters/PostListPresenter.js +++ b/public_html/js/Presenters/PostListPresenter.js @@ -7,19 +7,24 @@ App.Presenters.PostListPresenter = function( util, promise, auth, - router, keyboard, pagerPresenter, topNavigationPresenter, messagePresenter) { + var KEY_RETURN = 13; + var $el = jQuery('#content'); + var $searchInput; var listTemplate; var itemTemplate; + var searchArgs; + function init(args, loaded) { topNavigationPresenter.select('posts'); topNavigationPresenter.changeTitle('Posts'); + searchArgs = util.parseComplexRouteArgs(args.searchArgs); promise.waitAll( util.promiseTemplate('post-list'), @@ -53,16 +58,28 @@ App.Presenters.PostListPresenter = function( function reinit(args, loaded) { loaded(); - var searchArgs = util.parseComplexRouteArgs(args.searchArgs); - pagerPresenter.reinit({page: searchArgs.page, searchParams: {query: searchArgs.query, order: searchArgs.order}}); + searchArgs = util.parseComplexRouteArgs(args.searchArgs); + pagerPresenter.reinit({ + page: searchArgs.page, + searchParams: { + query: searchArgs.query, + order: searchArgs.order}}); } function render() { $el.html(listTemplate()); + $searchInput = $el.find('input[name=query]'); + + $searchInput.val(searchArgs.query); + $searchInput.keydown(searchInputKeyPressed); keyboard.keyup('p', function() { $el.find('.posts li a').eq(0).focus(); }); + + keyboard.keyup('q', function() { + $searchInput.eq(0).focus(); + }); } function renderPosts(posts, clear) { @@ -82,6 +99,17 @@ App.Presenters.PostListPresenter = function( } } + function searchInputKeyPressed(e) { + if (e.which !== KEY_RETURN) { + return; + } + + $searchInput.blur(); + pagerPresenter.setSearchParams({ + query: $searchInput.val(), + order: searchArgs.order}); + } + return { init: init, reinit: reinit, @@ -90,4 +118,4 @@ App.Presenters.PostListPresenter = function( }; -App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'router', 'keyboard', 'pagerPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostListPresenter); +App.DI.register('postListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'keyboard', 'pagerPresenter', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostListPresenter); diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js index 27a4f0e3..cb0d867a 100644 --- a/public_html/js/Presenters/PostUploadPresenter.js +++ b/public_html/js/Presenters/PostUploadPresenter.js @@ -13,6 +13,8 @@ App.Presenters.PostUploadPresenter = function( topNavigationPresenter, messagePresenter) { + var KEY_RETURN = 13; + var $el = jQuery('#content'); var $messages; var template; @@ -72,7 +74,7 @@ App.Presenters.PostUploadPresenter = function( } function urlHandlerKeyPressed(e) { - if (e.which !== 13) { + if (e.which !== KEY_RETURN) { return; } diff --git a/public_html/templates/post-list.tpl b/public_html/templates/post-list.tpl index c4852836..5124fd04 100644 --- a/public_html/templates/post-list.tpl +++ b/public_html/templates/post-list.tpl @@ -1,4 +1,9 @@
+ +