1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Thomas Fuchs 2005-12-25 18:53:22 +00:00
parent 1455697ee8
commit eb53467bdf
3 changed files with 26 additions and 1 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Added support for toggling visual effects to ScriptaculousHelper::visual_effect, #3323. [Thomas Fuchs]
* Update to script.aculo.us to 1.5.0 rev. 3343 [Thomas Fuchs]
* Added :select option for JavaScriptMacroHelper#auto_complete_field that makes it easier to only use part of the auto-complete suggestion as the value for insertion [Thomas Fuchs]

View file

@ -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:

View file

@ -29,6 +29,16 @@ class ScriptaculousHelperTest < Test::Unit::TestCase
assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
assert_equal "new Effect.DropOut('dropme',{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end)
end
def test_toggle_effects
assert_equal "Effect.toggle('posts','appear',{});", visual_effect(:toggle_appear, "posts")
assert_equal "Effect.toggle('posts','slide',{});", visual_effect(:toggle_slide, "posts")
assert_equal "Effect.toggle('posts','blind',{});", visual_effect(:toggle_blind, "posts")
assert_equal "Effect.toggle('posts','appear',{});", visual_effect("toggle_appear", "posts")
assert_equal "Effect.toggle('posts','slide',{});", visual_effect("toggle_slide", "posts")
assert_equal "Effect.toggle('posts','blind',{});", visual_effect("toggle_blind", "posts")
end
def test_parallel_effects
actual = parallel_effects(:duration => 2) do