From b128a46f62ded0713f6ff28bd750cd6e8dbe28d2 Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Fri, 7 Oct 2011 11:05:27 -0700 Subject: [PATCH] Focus the username box when a login/register popup is shown. --- r2/r2/public/static/js/login.js | 19 +++++++++++++++++-- r2/r2/templates/redditheader.html | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/r2/r2/public/static/js/login.js b/r2/r2/public/static/js/login.js index 921a81df6..92d98ed4c 100644 --- a/r2/r2/public/static/js/login.js +++ b/r2/r2/public/static/js/login.js @@ -131,7 +131,7 @@ r.login.ui = { } } - this.popup.show(true, dest && function() { + this.popup.showLogin(true, dest && function() { window.location = dest }) @@ -187,6 +187,10 @@ r.ui.LoginForm.prototype = $.extend(new r.ui.Form(), { } else { r.ui.Form.prototype._handleResult.call(this, result) } + }, + + focus: function() { + this.$el.find('input[name="user"]').focus() } }) @@ -199,7 +203,8 @@ r.ui.RegisterForm.prototype = $.extend(new r.ui.Form(), { r.login.post(this, 'register', $.proxy(this, 'handleResult')) }, - _handleResult: r.ui.LoginForm.prototype._handleResult + _handleResult: r.ui.LoginForm.prototype._handleResult, + focus: r.ui.LoginForm.prototype.focus }) r.ui.LoginPopup = function(el) { @@ -215,5 +220,15 @@ r.ui.LoginPopup.prototype = $.extend(new r.ui.Base(), { this.$el .find(".cover-msg").toggle(!!notice).end() .show() + }, + + showLogin: function() { + this.show.apply(this, arguments) + this.loginForm.focus() + }, + + showRegister: function() { + this.show.apply(this, arguments) + this.registerForm.focus() } }) diff --git a/r2/r2/templates/redditheader.html b/r2/r2/templates/redditheader.html index 2677121f7..0667574e0 100644 --- a/r2/r2/templates/redditheader.html +++ b/r2/r2/templates/redditheader.html @@ -63,7 +63,7 @@ %if thing.enable_login_cover and not g.read_only_mode: ${text_with_js(_("want to join? %(register)s in seconds"), - register=(_("register"), "r.login.ui.popup.show(); return false"))} + register=(_("register"), "r.login.ui.popup.showRegister(); return false"))} ${separator("|")} %endif