From 0584b5f3bbe7c96501c25d6ef11558f979b0b725 Mon Sep 17 00:00:00 2001 From: cpoppema Date: Sun, 1 Oct 2017 15:53:06 +0200 Subject: [PATCH] Add delay for focus call: https://bugzilla.mozilla.org/show_bug.cgi?id=1324255 --- code/js/popup.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/code/js/popup.js b/code/js/popup.js index 1b934dd..197da0c 100644 --- a/code/js/popup.js +++ b/code/js/popup.js @@ -12,7 +12,20 @@ function autofocus() { var elem = $('[autofocus]:visible'); if (elem && inViewport(elem.get(0))) { - $(elem).focus(); + // do a little dance to grab attention because this doesn't always + // *immediately* work, add a delay for it: + // $(elem).focus(); + // https://bugzilla.mozilla.org/show_bug.cgi?id=1324255 + setTimeout(function setFocusFirst() { + $(elem).focus(); + }, 100); + var secondTimeout = setTimeout(function setFocusSecond() { + $(elem).focus(); + }, 150); + $(window).one('focus', function() { + // cancel second try when window has focus + clearTimeout(secondTimeout); + }); } }