Module: Ujsos::DomUpdater

Defined in:
lib/ujsos/dom_updater.rb

Class Method Summary collapse

Class Method Details

.attributes_for_dom_update(remote_options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ujsos/dom_updater.rb', line 4

def attributes_for_dom_update(remote_options)
  return {} if remote_options.blank?

  #puts "UUUUUUUUU #{remote_options.inspect}"
  html_options = {}
  if (if_option = remote_options[:remote_if])
    html_options['data-ujsos-if'] = if_option
  else
    html_options['data-remote'] = 'true'
  end

  # support :update and :replace params
  dom_id = remote_options.delete(:update)
  if remote_options.is_a?(Hash)   # also support extracting the update arg from :remote hash
    dom_id ||= remote_options[:update]
    html_options["data-ujsos-update-position"] = remote_options[:position] if remote_options[:position]
  end

  html_options["data-ujsos-update"] = dom_id if dom_id

  # support :replace param
  dom_id = remote_options.delete(:replace)
  html_options["data-ujsos-replace"] = dom_id if dom_id

  # support :remote => { :format => }
  if remote_options.is_a?(Hash) && (f =remote_options[:format])
    html_options["data-ujsos-format"] = f
  end

  #puts "HTML ATTRS: #{html_options.inspect}"
  html_options
end