From 60337ee2038d08ecabf8df1324a360c27af078f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Wed, 9 May 2018 15:03:15 +0000 Subject: [PATCH] Add CTRL+K and CTRL+L shortcuts --- static/js/shortcuts.js | 34 ++++++++++++++++++++++++++++++++++ templates/base.html | 5 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 static/js/shortcuts.js diff --git a/static/js/shortcuts.js b/static/js/shortcuts.js new file mode 100644 index 00000000..807ff5c4 --- /dev/null +++ b/static/js/shortcuts.js @@ -0,0 +1,34 @@ +$(document).ready(function() { + ctrl = false; + alt = false; +}); + +$(document).keydown(function(event) { + // Update state keys + if (event.which == "17") + ctrl = true; + else if (event.which == "18") + alt = true; + + // CTRL+K will focus on the search bar + else if (ctrl && event.which == "75") { + event.stopPropagation(); + event.preventDefault(); + $("#search-term")[0].focus(); + } + + // CTRL+L will trigger the login/logout + else if (ctrl && event.which == "76") { + event.stopPropagation(); + event.preventDefault(); + window.location.href = $("#toggle_login")[0].href; + } +}); + +$(document).keyup(function(event) { + // Update state keys + if (event.which == "17") + ctrl = false; + else if (event.which == "18") + alt = false; +}); diff --git a/templates/base.html b/templates/base.html index f198feec..d257464f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -50,6 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc., + {{ site_name }} : {% block title %}Accueil{% endblock %} @@ -74,7 +75,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} @@ -129,7 +130,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %}
  • - + Login