diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-14 15:12:31 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-14 15:12:31 +0000 |
commit | 0c0a10746f1996c5ed09063cdd74fc5bdbd0c1fe (patch) | |
tree | 09ca4c0a7cecd47d48311165b4f0423a398cba6c /actionpack | |
parent | 8d646006db8cd3f2e5074deab4618120089020c6 (diff) | |
download | rails-0c0a10746f1996c5ed09063cdd74fc5bdbd0c1fe.tar.gz rails-0c0a10746f1996c5ed09063cdd74fc5bdbd0c1fe.tar.bz2 rails-0c0a10746f1996c5ed09063cdd74fc5bdbd0c1fe.zip |
Made async the default approach and add get_elements_by_class
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@903 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 5d87c85647..6ce1d05e2c 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -25,22 +25,24 @@ module ActionView # link_to_remote "Delete this post", :update => "posts", :url => { :action => "destroy", :id => post.id } # link_to_remote(image_tag("refresh"), :update => "emails", :url => { :action => "list_emails" }) # - # Asynchronous requests may be made by specifying a callback function - # to invoke when the request finishes. + # By default, these remote requests are processed asynchronous during which various callbacks can be triggered (for progress indicators + # and the likes). # # Example: # link_to_remote word, # :url => { :action => "undo", :n => word_counter }, - # :before => "if(!prepareForUndo()) return false", # :complete => "undoRequestCompleted(request)" # # The complete list of callbacks that may be specified are: # - # * uninitialized - # * loading - # * loaded - # * interactive - # * complete + # * <tt>:uninitialized</tt> -- EXPLAIN ME! + # * <tt>:loading</tt> -- EXPLAIN ME! + # * <tt>:loaded</tt> -- EXPLAIN ME! + # * <tt>:interactive</tt> -- EXPLAIN ME! + # * <tt>:complete</tt> -- EXPLAIN ME! + # + # If you for some reason or another needs synchronous processing (that'll block the browser while the request is happening), you + # can specify <tt>options[:type] = :sync</tt>. def link_to_remote(name, options = {}, html_options = {}) link_to_function(name, remote_function(options), html_options) end @@ -54,6 +56,18 @@ module ActionView tag("form", options[:html], true) end + def remote_function(options) + function = options[:update] ? + "update_with_response('#{options[:update]}', '#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" : + "xml_request('#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" + + function = "#{options[:before]}; #{function}" if options[:before] + function = "#{function}; #{options[:after]}" if options[:after] + function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] + + return function + end + def define_javascript_functions <<-EOF <script language="JavaScript"> @@ -160,6 +174,17 @@ module ActionView return document.getElementById(id); } + function get_elements_by_class(tag_name, class_name) { + var all = document.all ? document.all : document.getElementsByTagName(tag_name); + var elements = new Array(); + + for (var e = 0; e < all.length; e++) + if (all[e].className == class_name) + elements[elements.length] = all[e]; + + return elements; + } + /* Serialize a form by Sam Stephenson ------------------------------ */ @@ -248,8 +273,9 @@ module ActionView function << "'#{url_for(options[:url])}'" function << ', Form.serialize(this)' if options[:form] - function << ', nil' if !options[:form] && callbacks - function << ", true, " << callbacks if callbacks + function << ', null' if !options[:form] && callbacks + function << ", true" if callbacks || options[:type] != :sync + function << ", #{callbacks}" if callbacks function << ')' function = "#{options[:before]}; #{function}" if options[:before] |