Module: ActionView::Helpers::ScriptaculousHelper

Defined in:
lib/jrails.rb

Constant Summary collapse

JQUERY_VAR =
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

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



396
397
398
# File 'lib/jrails.rb', line 396

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

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



400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/jrails.rb', line 400

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(#{JQUERY_VAR}(ui.draggable).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]    
  [:activeClass, :hoverClass, :tolerance].each do |option|
    options[option] = "'#{options[option]}'" if options[option]
  end
  
  %(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});)
end

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

:nodoc:



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/jrails.rb', line 347

def sortable_element_js(element_id, options = {}) #:nodoc:
  #convert similar attributes
  options[:handle] = ".#{options[:handle]}" if options[:handle]
  if options[:tag] || options[:only]
    options[:items] = "> "
    options[:items] << options.delete(:tag) if options[:tag]
    options[:items] << ".#{options.delete(:only)}" if options[:only]
  end
  options[:connectWith] = options.delete(:containment).map {|x| "##{x}"} if options[:containment]
  options[:containment] = options.delete(:container) if options[:container]
  options[:dropOnEmpty] = false unless options[:dropOnEmpty]
  options[:helper] = "'clone'" if options[:ghosting] == true
  options[:axis] = case options.delete(:constraint)
    when "vertical", :vertical
      "y"
    when "horizontal", :horizontal
      "x"
    when false
      nil
    when nil
      "y"
  end
  options.delete(:axis) if options[:axis].nil?
  options.delete(:overlap)
  options.delete(:ghosting)
  
  if options[:onUpdate] || options[:url]
    if options[:format]
      options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]', expression:#{options[:format]}})"
      options.delete(:format)
    else
      options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})"
    end
    
    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]
  
  [:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option|
    options[option] = "'#{options[option]}'" if options[option]
  end
  
  options[:connectWith] = array_or_string_for_javascript(options[:connectWith]) if options[:connectWith]
  
  %(#{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)});)
end

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



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/jrails.rb', line 311

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, :startcolor, :endcolor].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)
    #	090905 - Jake - changed ' to \" so it passes assert_select_rjs with an id
    javascript = "#{JQUERY_VAR}(\"#{jquery_id(element_id)}\").#{name}("
    javascript << "#{speed}" unless speed.nil?
    javascript << ");"
  else
    #	090905 - Jake - changed ' to \" so it passes "assert_select_rjs :effect, ID"
    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