From eb53467bdf7397503e7f709ae65a320b698e367b Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Sun, 25 Dec 2005 18:53:22 +0000 Subject: Added support for toggling visual effects to ScriptaculousHelper::visual_effect, #3323. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3350 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/scriptaculous_helper.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/scriptaculous_helper.rb b/actionpack/lib/action_view/helpers/scriptaculous_helper.rb index fac628caef..5f7e90ec33 100644 --- a/actionpack/lib/action_view/helpers/scriptaculous_helper.rb +++ b/actionpack/lib/action_view/helpers/scriptaculous_helper.rb @@ -14,6 +14,10 @@ module ActionView # See the documentation at http://script.aculo.us for more information on # using these helpers in your application. module ScriptaculousHelper + unless const_defined? :TOGGLE_EFFECTS + TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind] + end + # Returns a JavaScript snippet to be used on the Ajax callbacks for # starting visual effects. # @@ -31,12 +35,21 @@ module ActionView # This would fade the element that was dropped on the drop receiving # element. # + # For toggling visual effects, you can use :toggle_appear, :toggle_slide, and + # :toggle_blind which will alternate between appear/fade, slidedown/slideup, and + # blinddown/blindup respectively. + # # You can change the behaviour with various options, see # http://script.aculo.us for more documentation. def visual_effect(name, element_id = false, js_options = {}) element = element_id ? "'#{element_id}'" : "element" js_options[:queue] = "'#{js_options[:queue]}'" if js_options[:queue] - "new Effect.#{name.to_s.camelize}(#{element},#{options_for_javascript(js_options)});" + + if TOGGLE_EFFECTS.include? name.to_sym + "Effect.toggle(#{element},'#{name.to_s.gsub(/^toggle_/,'')}',#{options_for_javascript(js_options)});" + else + "new Effect.#{name.to_s.camelize}(#{element},#{options_for_javascript(js_options)});" + end end # Needs more work so + isn't required for concation of effects. Currently, you have to do: -- cgit v1.2.3