From c662d52d620227550e34c8aa4e094d07747d7ed8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 25 Oct 2013 15:41:09 +0200 Subject: [PATCH] Closed #34 Introducing keyboard shortcut. Every page: [Q] - focus search [W] - scroll up [S] - scroll down Post: [A] - next post [D] - previous post [E] - edit post Also, when clicking on post edit, browser is scrolled to the form. --- init.php | 3 +++ public_html/media/js/core.js | 7 +++++++ public_html/media/js/post-view.js | 6 ++++++ src/Bootstrap.php | 1 + 4 files changed, 17 insertions(+) diff --git a/init.php b/init.php index da96770f..38481828 100644 --- a/init.php +++ b/init.php @@ -49,6 +49,9 @@ foreach ($lines as $line) download('http://raw.github.com/aehlke/tag-it/master/css/jquery.tagit.css', $libPath . 'tagit' . DS . 'jquery.tagit.css'); download('http://raw.github.com/aehlke/tag-it/master/js/tag-it.min.js', $libPath . 'tagit' . DS . 'jquery.tagit.js'); +//Mousetrap +download('https://raw.github.com/ccampbell/mousetrap/master/mousetrap.min.js', $libPath . 'mousetrap' . DS . 'mousetrap.min.js'); + //fonts download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans.ttf', $fontsPath . 'DroidSans.ttf'); download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans-Bold.ttf', $fontsPath . 'DroidSans-Bold.ttf'); diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index e186526c..525599d7 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -204,3 +204,10 @@ function getTagItOptions() } }; } + +$(function() +{ + Mousetrap.bind('q', function() { $('#top-nav input').focus(); return false; }); + Mousetrap.bind('w', function() { $('body,html').animate({scrollTop: '-=150px'}, 200); }); + Mousetrap.bind('s', function() { $('body,html').animate({scrollTop: '+=150px'}, 200); }); +}); diff --git a/public_html/media/js/post-view.js b/public_html/media/js/post-view.js index 2f005923..6a5f613d 100644 --- a/public_html/media/js/post-view.js +++ b/public_html/media/js/post-view.js @@ -22,6 +22,8 @@ $(function() e.preventDefault(); var formDom = $('form.edit-post'); formDom.show().css('height', formDom.height()).hide().slideDown(); + + $('html, body').animate({ scrollTop: $(formDom).offset().top + 'px' }, 'fast'); }); }); @@ -118,4 +120,8 @@ $(function() $.ajax(ajaxData); }); + + Mousetrap.bind('a', function() { window.location = $('#sidebar .left a').attr('href'); }); + Mousetrap.bind('d', function() { window.location = $('#sidebar .right a').attr('href'); }); + Mousetrap.bind('e', function() { $('li.edit a').trigger('click'); return false; }); }); diff --git a/src/Bootstrap.php b/src/Bootstrap.php index ef68c7cc..04a26175 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -52,6 +52,7 @@ class Bootstrap [ '../lib/jquery/jquery.min.js', '../lib/jquery-ui/jquery-ui.min.js', + '../lib/mousetrap/mousetrap.min.js', 'core.js', ];