diff --git a/scripts/ddbasic.login.js b/scripts/ddbasic.login.js new file mode 100644 index 0000000..9182587 --- /dev/null +++ b/scripts/ddbasic.login.js @@ -0,0 +1,26 @@ +(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(); + }); + + // 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)); 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.