Module: JQueryOnRails::Helpers::JQueryUiHelper

Defined in:
lib/jquery_on_rails/helpers/jquery_ui_helper.rb

Constant Summary collapse

FX_OPTIONS =
{
  'Up' => {:mode=>:hide,:direction=>:vertical}, 'Down' => {:mode=>:show,:direction=>:vertical},
  'Left' => {:mode=>:hide,:direction=>:horizontal}, 'Right' => {:mode=>:show,:direction=>:horizontal},
  'Out' => {:mode=>:hide,:direction=>nil}, 'In' => {:mode=>:show,:direction=>nil},
  :fadeIn => {:mode=>:primitive,:direction=>nil}, :fadeOut => {:mode=>:primitive,:direction=>nil},
  :animate => {:mode=>:primitive,:direction=>nil}, :toggleSlide => {:direction=>:up},
  :puff => {:direction=>nil}, :size => {:direction=>nil},
  :toggleAppear => {:direction=>nil,:mode=>"return element[name+(element.is(':hidden')?'In':'Out')](options);"}
}.with_indifferent_access
FX_NAMES =
HashWithIndifferentAccess.new{|h,k| k}

Instance Method Summary collapse

Instance Method Details

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

Generates jQuery UI effects. This expands upon the core jQuery 1.4 effects that are generated by JQueryHelper#visual_effect



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jquery_on_rails/helpers/jquery_ui_helper.rb', line 22

def visual_effect(name, element_id=false, js_options={})
  element = element_id ? ActiveSupport::JSON.encode("##{element_id}") : "element"

  fx_opt, name = FX_OPTIONS[name = name.to_s.camelize(:lower)] || {}, FX_NAMES[name]
  fx_opt ||= FX_NAMES[name]
				fx_opt[:mode], name = :toggle, FX_NAMES[name[6,1].downcase+name[7..-1]] if name.start_with? 'toggle'
				fx_opt = FX_OPTIONS[$1].merge fx_opt if ! FX_OPTIONS.include? name and name.sub! /(Up|Down|Left|Right|In|Out)$/, ''
  fx_opt = FX_OPTIONS[name].merge fx_opt if FX_OPTIONS.include? name
 fx_opt.merge! js_options
 
  if ! fx_opt.include? :direction then fx_opt[:direction] = "'vertical'"
			  elsif fx_opt[:direction].nil? then fx_opt.delete :direction
			  else fx_opt[:direction] = "'#{fx_opt[:direction]}'"
end
 
  # [:endcolor, :direction, :startcolor, :scaleMode, :restorecolor]
  fx = "jQuery(#{element})"
  fx = "#{fx}.css('background-color','#{fx_opt.delete :startcolor}')" if fx_opt[:startcolor]
 if name=='animate' then fx_opt[:backgroundColor] ||= fx_opt.delete :endcolor
 elsif fx_opt[:endcolor] then fx = "#{fx}.animate('background-color','#{fx_opt.delete :endcolor}')"
  end
  method, fx_opt = fx_opt.delete(:mode)||:effect, (options_for_javascript fx_opt unless fx_opt.empty?)
  
  case method; when :primitive; "#{fx}.#{name}(#{fx_opt});"
  when Symbol; "#{fx}.#{method}('#{name}'#{','+fx_opt if fx_opt.present?});"
  else "(function(element,name,options){ #{method} })(#{fx},'#{name}'#{','+fx_opt if fx_opt.present?});"
  end
end