Method: ActionView::Helpers::ScriptaculousHelper#visual_effect
- Defined in:
- lib/action_view/helpers/scriptaculous_helper.rb
#visual_effect(name, element_id = false, js_options = {}) ⇒ Object
Returns a JavaScript snippet to be used on the Ajax callbacks for starting visual effects.
If no element_id is given, it assumes “element” which should be a local variable in the generated JavaScript execution context. This can be used for example with drop_receiving_element:
<%= drop_receiving_element (...), :loading => visual_effect(:fade) %>
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 script.aculo.us for more documentation.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/action_view/helpers/scriptaculous_helper.rb', line 41 def visual_effect(name, element_id = false, = {}) element = element_id ? ActiveSupport::JSON.encode(element_id) : "element" [:queue] = if [:queue].is_a?(Hash) '{' + [:queue].map {|k, v| k == :limit ? "#{k}:#{v}" : "#{k}:'#{v}'" }.join(',') + '}' elsif [:queue] "'#{[:queue]}'" end if [:queue] [:endcolor, :direction, :startcolor, :scaleMode, :restorecolor].each do |option| [option] = "'#{[option]}'" if [option] end if TOGGLE_EFFECTS.include? name.to_sym "Effect.toggle(#{element},'#{name.to_s.gsub(/^toggle_/,'')}',#{()});" else "new Effect.#{name.to_s.camelize}(#{element},#{()});" end end |