From 47489db3c1864c5cd5eed061754a7ef1a0fcb5b4 Mon Sep 17 00:00:00 2001 From: Morten Bartvig Date: Wed, 2 Dec 2015 14:24:46 +0100 Subject: [PATCH 1/2] Issue #1267 by bartvig: Added script that sets focus on the username in the login form, also when the Login tab is clicked. --- scripts/ddbasic.login.js | 13 +++++++++++++ template.php | 4 ++++ 2 files changed, 17 insertions(+) create mode 100644 scripts/ddbasic.login.js diff --git a/scripts/ddbasic.login.js b/scripts/ddbasic.login.js new file mode 100644 index 0000000..0ffb919 --- /dev/null +++ b/scripts/ddbasic.login.js @@ -0,0 +1,13 @@ +(function($) { + "use strict"; + + $(document).ready(function() { + // Focus on username form field when entering login form. + $('#user-login-form #edit-name').focus(); + + // Focus on username form field when clicking login tab. + $('.topbar-link-user').bind('click', function(event) { + $('#user-login-form #edit-name').focus(); + }); + }); +}(jQuery)); diff --git a/template.php b/template.php index 8c479f6..3659302 100644 --- a/template.php +++ b/template.php @@ -122,6 +122,10 @@ function ddbasic_form_alter(&$form, &$form_state, $form_id) { $form['pass']['#field_prefix'] = ''; $form['pass']['#attributes']['placeholder'] = t('Pincode is 4 digits'); + // Add JavaScript that will place focus in the login box, when the Login + // is clicked. + drupal_add_js(drupal_get_path('theme', 'ddbasic') . '/scripts/ddbasic.login.js', 'file'); + unset($form['links']); // Temporary hack to get rid of open id links. From 239fc758b80bbc9e923c97c20d49f92649aedb84 Mon Sep 17 00:00:00 2001 From: Morten Bartvig Date: Wed, 2 Dec 2015 14:35:37 +0100 Subject: [PATCH 2/2] Issue #1267 by bartvig: Added javascript for blurring (unfocus) the user login form, when the user clicks the up or down key. --- scripts/ddbasic.login.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/ddbasic.login.js b/scripts/ddbasic.login.js index 0ffb919..9182587 100644 --- a/scripts/ddbasic.login.js +++ b/scripts/ddbasic.login.js @@ -9,5 +9,18 @@ $('.topbar-link-user').bind('click', function(event) { $('#user-login-form #edit-name').focus(); }); + + // Unfocus login form when user wants to scroll with key buttons (i.e. clicks the up or down button). + $('#user-login-form').bind('keydown', function(event) { + var keymap = { + up: 38, + down: 40 + }; + + // Only unfocus if we press the up or down key. + if (keymap.up == event.which || keymap.down == event.which) { + document.activeElement.blur(); + } + }); }); }(jQuery));