29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'app/helpers/megatron/form_helper.rb', line 29
def slider_input_tag(name, options={})
options = options.stringify_keys
classnames = options.delete('class') || ''
data = options['data'] || {}
data['input'] ||= name
if options['position_label']
data['position_label'] = options['position_label']
end
if values = options['values']
data['values'] = values.join(',')
options['max'] ||= values.size - 1
end
options['labels'] ||= options['label']
if labels = options['labels']
if labels.is_a?(Array)
data['label'] = labels.join(';')
options['max'] ||= labels.size - 1
elsif labels.is_a?(Hash)
labels.each do |label, value|
data['label-'+dasherize(label.to_s.downcase)] = value.join(';')
options['max'] ||= value.size - 1
end
end
end
if labels == false
data['label'] = 'false'
end
if labels = options['external_labels']
if labels.is_a?(Hash)
labels.each do |label, value|
data['external-label-'+dasherize(label.to_s.downcase)] = value.join(';')
end
end
end
if before = options['before']
if before.is_a?(String)
data['before-label'] = before
else
before.each do |key, value|
data["before-label-#{key}"] = value
end
end
end
if mark = options['mark']
data['mark'] = mark.join(',')
end
if after = options['after']
if after.is_a?(String)
data['after-label'] = after
else
after.each do |key, value|
data["after-label-#{key}"] = value
end
end
end
if line_labels = options['line_labels']
data['line_labels'] = []
line_labels.each do |k, v|
data['line_labels'] << "#{k}:#{v}"
end
data['line_labels'] = data['line_labels'].join(';')
end
options['value'] ||= options['min'] || 0
html_options = {"class" => classnames, "type" => "range", "min" => options['min'], "max" => options['max'], "value" => options['value'] }.update('data' => data)
tag :input, html_options
end
|