Class: Mack::JavaScript::Framework::Jquery

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

Class Method Summary collapse

Class Method Details

.hide(*ids) ⇒ Object



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

def hide(*ids)
  "$(\'##{ids.join(',#')}\').hide()"
end

.insert_html(position, id, html) ⇒ Object



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

def insert_html(position, id, html)
  insertion = position.to_s.downcase
  insertion = 'append' if insertion == 'bottom'
  insertion = 'prepend' if insertion == 'top'
  "$(\'##{id}\').#{insertion}('#{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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mack-javascript/helpers/jquery_helper.rb', line 50

def remote_function(options)
  javascript_options = options_for_ajax(options)
  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 = "$.ajax(#{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/jquery_helper.rb', line 21

def remove(*ids)
  "$(\'##{ids.join(',#')}\').remove()"
end

.replace(id, html) ⇒ Object



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

def replace(id, html)
  "$(\'##{id}\').replaceWith('#{html}')"
end

.replace_html(id, html) ⇒ Object



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

def replace_html(id, html)
  insert_html(:html, id, html)
end

.show(*ids) ⇒ Object



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

def show(*ids)
  "$(\'##{ids.join(',#')}\').show()"
end

.toggle(*ids) ⇒ Object



33
34
35
# File 'lib/mack-javascript/helpers/jquery_helper.rb', line 33

def toggle(*ids)
  "$(\'##{ids.join(',#')}\').toggle()"
end