Class: Mack::JavaScript::Framework::Prototype

Inherits:
Object
  • Object
show all
Defined in:
lib/mack-javascript/helpers/prototype_helper.rb

Constant Summary collapse

@@callbacks =
[:uninitialized, :loading, :loaded, :interactive, :complete, :failure, :success ] + 
[100,101] + (200..206).to_a + (300..307).to_a + (400..417).to_a + (500..505).to_a

Class Method Summary collapse

Class Method Details

.insert_html(position, id, html) ⇒ Object



8
9
10
11
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 8

def insert_html(position, id, html)
  insertion = position.to_s.camelcase
  "new Insertion.#{insertion}('#{id}', '#{html}')"
end

.remote_function(options) ⇒ Object

def draggable(id, options = {})

record @context.send(:draggable_element_js, id, options)

end

def visual_effect(name, id = nil, options = {})

record @context.send(:visual_effect, name, id, options)

end

def drop_receiving(id, options = {})

record @context.send(:drop_receiving_element_js, id, options)

end



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 45

def remote_function(options)
  javascript_options = options_for_ajax(options)
  "new Ajax.Request('#{options[:url]}', #{javascript_options.to_json})"
  update = ''
  if options[:update] && options[:update].is_a?(Hash)
    update  = []
    update << "success:'#{options[:update][:success]}'" if options[:update][:success]
    update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
    update  = '{' + update.join(',') + '}'
  elsif options[:update]
    update << "'#{options[:update]}'"
  end

  function = update.empty? ? 
  "new Ajax.Request(" :
  "new Ajax.Updater(#{update}, "

  url_options = options[:url]
  url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
  function << "'#{url_options}'"
  function << ", #{javascript_options})"

  function = "#{options[:before]}; #{function}" if options[:before]
  function = "#{function}; #{options[:after]}"  if options[:after]
  function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
  function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]

  return function
end

.remove(*ids) ⇒ Object



21
22
23
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 21

def remove(*ids)
  "#{ids.to_json}.each(Element.remove)"
end

.replace(id, html) ⇒ Object



17
18
19
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 17

def replace(id, html)
  "Element.replace('#{id}', '#{html}')"
end

.replace_html(id, html) ⇒ Object



13
14
15
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 13

def replace_html(id, html)
  "Element.update('#{id}', '#{html}')"
end

.show(*ids) ⇒ Object



25
26
27
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 25

def show(*ids)
  "#{ids.to_json}.each(Element.show)"
end

.toggle(*ids) ⇒ Object



29
30
31
# File 'lib/mack-javascript/helpers/prototype_helper.rb', line 29

def toggle(*ids)
  "#{ids.to_json}.each(Element.toggle)"
end