From d7487fffe51d03f46800e266e4c972ab55238c89 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 31 Dec 2005 04:14:07 +0000 Subject: Made Field.focus in prototype friendly to effects by adding optional delay parameter [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3366 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/html/javascripts/prototype.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js index e9ccd3c885..545f3af040 100644 --- a/railties/html/javascripts/prototype.js +++ b/railties/html/javascripts/prototype.js @@ -1154,8 +1154,18 @@ var Field = { $(arguments[i]).value = ''; }, - focus: function(element) { - $(element).focus(); + // Pass the field id or element as the first parameter and optionally a triggering delay in micro-seconds as the second. + // The delay is useful when the focus is part of effects that won't finish instantly since they prevent the focus from + // taking hold. Set the delay to right after the effect finishes and the focus will work. + focus: function() { + element = $(arguments[0]); + delay = arguments[1]; + + if (delay) { + setTimeout(function() { $(element).focus(); }, delay) + } else { + $(element).focus(); + } }, present: function() { -- cgit v1.2.3