From 0d06484b019d9a01c7d19714a6b861d09a3ae4d3 Mon Sep 17 00:00:00 2001 From: Matthew Harrison-Jones Date: Tue, 16 Jul 2013 10:18:40 +0100 Subject: [PATCH] Automatically focus on first login input --- core/client/admin-ui-temp.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/core/client/admin-ui-temp.js b/core/client/admin-ui-temp.js index 06e0b266e0..af4964f098 100644 --- a/core/client/admin-ui-temp.js +++ b/core/client/admin-ui-temp.js @@ -1,6 +1,7 @@ // # Temporary Admin UI -/*global window, document, $ */ +/*global window, document, _, $ */ + (function () { "use strict"; @@ -18,14 +19,23 @@ return (obj.textContent || obj.innerText || $(obj).text() || "") === meta[3]; }; - // Called on Window resize - $(window).resize(function () { + var positionCenter = _.debounce(function (e) { - var loginContainer = $(".js-login-container"), - marginTop = Math.floor((loginContainer.parent().height() - loginContainer.height()) / 2) - 15; - loginContainer.css('margin-top', marginTop).delay(250).fadeIn(750); + var loginContainer = $(".js-login-container"), + marginTop = Math.floor((loginContainer.parent().height() - loginContainer.height()) / 2) - 15; + loginContainer.animate({'margin-top': marginTop}, 200); + $(window).trigger('centered'); - }); + }, 100); // Maximum run of once per 100 milliseconds + + function fadeInAndFocus() { + $(".js-login-container").fadeIn(750, function () { + $("[name='email']").focus(); + }); + } + + $(window).on('resize', positionCenter); + $(window).one('centered', fadeInAndFocus); // Allow notifications to be dismissed $(document).on('click', '.js-notification .close', function () { @@ -44,8 +54,8 @@ }); // LOGIN SCREEN + $(window).trigger('resize'); - $(window).resize(); // EDITOR / NOTIFICATIONS