aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-12-31 04:14:07 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-12-31 04:14:07 +0000
commitd7487fffe51d03f46800e266e4c972ab55238c89 (patch)
treee959297f49786eb3025daecb1f8bb45de6a134ef
parent89d8afa2c4f256ffb84b6c9e521546b5dd3e60d8 (diff)
downloadrails-d7487fffe51d03f46800e266e4c972ab55238c89.tar.gz
rails-d7487fffe51d03f46800e266e4c972ab55238c89.tar.bz2
rails-d7487fffe51d03f46800e266e4c972ab55238c89.zip
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
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js14
-rw-r--r--activerecord/test/reflection_test.rb1
-rw-r--r--railties/html/javascripts/prototype.js14
3 files changed, 25 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js
index e9ccd3c885..545f3af040 100644
--- a/actionpack/lib/action_view/helpers/javascripts/prototype.js
+++ b/actionpack/lib/action_view/helpers/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() {
diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb
index 09da3e5986..30cc99677e 100644
--- a/activerecord/test/reflection_test.rb
+++ b/activerecord/test/reflection_test.rb
@@ -98,5 +98,6 @@ class ReflectionTest < Test::Unit::TestCase
assert_equal 12, Firm.reflect_on_all_associations.size
assert_equal 11, Firm.reflect_on_all_associations(:has_many).size
assert_equal 1, Firm.reflect_on_all_associations(:has_one).size
+ assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
end
end
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() {