aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/prototype_helper.rb
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2006-02-12 01:30:13 +0000
committerSam Stephenson <sam@37signals.com>2006-02-12 01:30:13 +0000
commit838ec413ebe08be71eea3dec0b061c6f609c839f (patch)
tree8df6658227aeeb613ec809d0da6539bb2d956eeb /actionpack/lib/action_view/helpers/prototype_helper.rb
parente90bbbdd837ffc83dccbd05528c4f1521e3956ee (diff)
downloadrails-838ec413ebe08be71eea3dec0b061c6f609c839f.tar.gz
rails-838ec413ebe08be71eea3dec0b061c6f609c839f.tar.bz2
rails-838ec413ebe08be71eea3dec0b061c6f609c839f.zip
Add JavaScriptGenerator#replace_element for replacing an element's "outer HTML". Closes #3246.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3579 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/prototype_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 8aabe04aac..26d877c00a 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -457,6 +457,36 @@ module ActionView
call 'Element.update', id, render(*options_for_render)
end
+ # Replaces the "outer HTML" (i.e., the entire element, not just its
+ # contents) of the DOM element with the given +id+.
+ #
+ # +options_for_render+ may be either a string of HTML to insert, or a hash
+ # of options to be passed to ActionView::Base#render. For example:
+ #
+ # # Replace the DOM element having ID 'person-45' with the
+ # # 'person' partial for the appropriate object.
+ # replace_html 'person-45', :partial => 'person', :object => @person
+ #
+ # This allows the same partial that is used for the +insert_html+ to
+ # be also used for the input to +replace_element+ without resorting to
+ # the use of wrapper elements.
+ #
+ # Examples:
+ #
+ # <div id="people">
+ # <%= render :partial => 'person', :collection => @people %>
+ # </div>
+ #
+ # # Insert a new person
+ # page.insert_html :bottom, :partial => 'person', :object => @person
+ #
+ # # Replace an existing person
+ # page.replace_element 'person_45', :partial => 'person', :object => @person
+ #
+ def replace_element(id, *options_for_render)
+ call 'Element.replace', id, render(*options_for_render)
+ end
+
# Removes the DOM elements with the given +ids+ from the page.
def remove(*ids)
record "#{javascript_object_for(ids)}.each(Element.remove)"