From ef4d46b5e1d67d562aa535bcea55dfb4757d8b03 Mon Sep 17 00:00:00 2001 From: Ryan Angilly Date: Thu, 1 Jan 2009 06:46:29 -0500 Subject: [PATCH] adding options[:stop] to link_to_remote to allow the optional prevention of event bubbling --- .../lib/action_view/helpers/prototype_helper.rb | 6 ++++++ actionpack/test/template/prototype_helper_test.rb | 3 +++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 18a209d..3c5ebbc 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -252,6 +252,11 @@ module ActionView # link_to_remote "Delete this post", # { :update => "posts", :url => { :action => "destroy", :id => post.id } }, # :href => url_for(:action => "destroy", :id => post.id) + # + # You can use specify options[:stop] = true in order to + # stop event bubbling on the link. This is desirable if, for example, + # you have a link in a div, and the div has an onclick registered that + # you want to ignore when the link is clicked. def link_to_remote(name, options = {}, html_options = nil) link_to_function(name, remote_function(options), html_options || options.delete(:html)) end @@ -467,6 +472,7 @@ module ActionView function << "'#{escape_javascript(url_for(url_options))}'" function << ", #{javascript_options})" + function = "Event.extend(event).stop(); #{function}" if options[:stop] function = "#{options[:before]}; #{function}" if options[:before] function = "#{function}; #{options[:after]}" if options[:after] function = "if (#{options[:condition]}) { #{function}; }" if options[:condition] diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index d6b86a3..c2a6539 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -81,6 +81,9 @@ class PrototypeHelperTest < PrototypeHelperBaseTest link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :type => :synchronous) assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :position => :bottom) + assert_dom_equal %(Remote outauthor), + link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :position => :bottom, :stop => true) + end def test_link_to_remote_html_options -- 1.5.4.3