Module: ActionView::Helpers::ScriptaculousHelper

Defined in:
lib/jquery_for_rjs.rb

Constant Summary collapse

JQUERY_VAR =
ActionView::Helpers::PrototypeHelper::JQUERY_VAR
SCRIPTACULOUS_EFFECTS =
{
  :appear => {:method => 'fadeIn'},
  :blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
  :blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
  :blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
  :blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
  :bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
  :bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
  :drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
  :drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
  :fade => {:method => 'fadeOut'},
  :fold_in => {:method => 'fold', :mode => 'hide'},
  :fold_out => {:method => 'fold', :mode => 'show'},
  :grow => {:method => 'scale', :mode => 'show'},
  :shrink => {:method => 'scale', :mode => 'hide'},
  :slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
  :slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
  :slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
  :slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
  :squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
  :switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
  :switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
  :toggle_appear => {:method => 'fadeToggle'},
  :toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
  :toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
}

Instance Method Summary collapse

Instance Method Details

#visual_effect(name, element_id = false, js_options = {}) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/jquery_for_rjs.rb', line 165

def visual_effect(name, element_id = false, js_options = {})
  element = element_id ? element_id : "this"
  
  if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
    effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
    name = effect[:method]
    mode = effect[:mode]
    js_options = js_options.merge(effect[:options]) if effect[:options]
  end
  
  [:color, :direction].each do |option|
    js_options[option] = "'#{js_options[option]}'" if js_options[option]
  end
  
  if js_options.has_key? :duration
    speed = js_options.delete :duration
    speed = (speed * 1000).to_i unless speed.nil?
  else
    speed = js_options.delete :speed
  end
  
  if ['fadeIn','fadeOut','fadeToggle'].include?(name)
    javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{name}("
    javascript << "#{speed}" unless speed.nil?
    javascript << ");"
  else
    javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{mode || 'effect'}('#{name}'"
    javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
    javascript << ",#{speed}" unless speed.nil?
    javascript << ");"
  end
  
end