Module: ActionView::Helpers::ScriptaculousHelper

Defined in:
lib/jrails.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#draggable_element_js(element_id, options = {}) ⇒ Object



259
260
261
# File 'lib/jrails.rb', line 259

def draggable_element_js(element_id, options = {})
  %($("##{element_id}").draggable(#{options_for_javascript(options)});)
end

#drop_receiving_element_js(element_id, options = {}) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/jrails.rb', line 263

def drop_receiving_element_js(element_id, options = {})
  #convert similar options
  options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
  options[:drop] = options.delete(:onDrop) if options[:onDrop]
  
  if options[:drop] || options[:url]
    options[:with] ||= "'id=' + encodeURIComponent($(ui.draggable).clone().attr('id'))"
    options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
  end
  
  options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }

  options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]    
  options[:hoverClass] = "'#{options[:hoverClass]}'" if options[:hoverClass]
  
  %($("##{element_id}").droppable(#{options_for_javascript(options)});)
end

#sortable_element_js(element_id, options = {}) ⇒ Object

:nodoc:



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/jrails.rb', line 237

def sortable_element_js(element_id, options = {}) #:nodoc:
  #convert similar attributes
  options[:items] = options[:only] if options[:only]
  
  if options[:onUpdate] || options[:url]
    options[:with] ||= "$(this).sortable('serialize')"
    options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
  end
  
  options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
  options[:update] = options.delete(:onUpdate) if options[:onUpdate]
  
  [:handle].each do |option|
    options[option] = "'#{options[option]}'" if options[option]
  end
  
  options[:containment] = array_or_string_for_javascript(options[:containment]) if options[:containment]
  options[:items] = array_or_string_for_javascript(options[:items]) if options[:items]
  
  %($("##{element_id}").sortable(#{options_for_javascript(options)});)
end

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



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/jrails.rb', line 207

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]
    js_options = js_options.merge effect[:options]
  end
  
  [:color, :direction, :mode].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 TOGGLE_EFFECTS.include? name.to_sym
  #  "Effect.toggle(#{element},'#{name.to_s.gsub(/^toggle_/,'')}',#{options_for_javascript(js_options)});"
  
  javascript = "$(\"##{element_id}\").effect(\"#{name.to_s.downcase}\""
  javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
  javascript << ",#{speed}" unless speed.nil?
  javascript << ")"
  
end