diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-22 18:05:50 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-22 18:05:50 +0000 |
commit | 4e76ae39047b369a192ee1a55cfcb4418c5c1f93 (patch) | |
tree | 378c9860306b682b6da6c39c3728b9e6a3538c45 /actionpack/lib | |
parent | 778d6704d496f7812495e423aa27b54187db682a (diff) | |
download | rails-4e76ae39047b369a192ee1a55cfcb4418c5c1f93.tar.gz rails-4e76ae39047b369a192ee1a55cfcb4418c5c1f93.tar.bz2 rails-4e76ae39047b369a192ee1a55cfcb4418c5c1f93.zip |
Added delayed execution of Javascript from within RJS (closes #3264) [devslashnull@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3335 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index f1e67f05f4..a9a68f474b 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -485,10 +485,21 @@ module ActionView def <<(javascript) @lines << javascript end - + + # Executes the content of the block after a delay of +seconds+. Example: + # + # page.delay(20) do + # page.visual_effect :fade, 'notice' + # end + def delay(seconds = 1) + record "setTimeout(function() {\n\n" + yield + record "}, #{(seconds * 1000).to_i})" + end + private def method_missing(method, *arguments, &block) - record @context.send(method, *arguments, &block) + record(@context.send(method, *arguments, &block)) end def record(line) |