seamusabshere-scriptaculous_slider 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +4 -0
- data/lib/helpers/slider_helper.rb +129 -0
- metadata +59 -0
data/VERSION.yml
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Copyright (c) 2005 Thomas Fuchs
|
2
|
+
#
|
3
|
+
# Contributors :
|
4
|
+
# - Nicolas Cavigneaux
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
module ActionView
|
26
|
+
module Helpers
|
27
|
+
module SliderHelper
|
28
|
+
|
29
|
+
# Creates a slider control out of an element.
|
30
|
+
def slider_element(element_id, options={})
|
31
|
+
prepare = "Element.cleanWhitespace('#{element_id}');"
|
32
|
+
|
33
|
+
[:change, :slide].each do |k|
|
34
|
+
if options.include?(k)
|
35
|
+
name = 'on' + k.to_s.capitalize
|
36
|
+
options[name] = "function(value){#{options[k]}}"
|
37
|
+
options.delete k
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
[:spans, :axis].each do |k|
|
42
|
+
options[k] = array_or_string_for_javascript(options[k]) if options[k]
|
43
|
+
end
|
44
|
+
|
45
|
+
options[:sliderValue] = array_or_numeric_for_javascript(options[:sliderValue]) if options[:sliderValue]
|
46
|
+
|
47
|
+
options[:range] = "$R(#{options[:range].min},#{options[:range].max})" if options[:range]
|
48
|
+
options[:values] = "$R(#{options[:values].min},#{options[:values].max})" if options[:values]
|
49
|
+
|
50
|
+
slider = ''
|
51
|
+
|
52
|
+
if options[:hidden_fields] == true
|
53
|
+
slider = if options[:handles].kind_of?(Array)
|
54
|
+
hidden_fields = options[:handles].collect { |h| hidden_field_tag(h.to_s + "_value") }
|
55
|
+
hidden_fields.join("\n")
|
56
|
+
elsif !options[:handles].nil?
|
57
|
+
hidden_field_tag(options[:handles].to_s + "_value")
|
58
|
+
end
|
59
|
+
|
60
|
+
options.delete(:hidden_fields)
|
61
|
+
end
|
62
|
+
|
63
|
+
handle = array_or_string_for_javascript(options[:handles]) || "$('#{element_id}').firstChild"
|
64
|
+
options.delete :handles
|
65
|
+
|
66
|
+
slider += javascript_tag("#{prepare} #{element_id} = new Control.Slider(#{handle},'#{element_id}', #{options_for_javascript(options)})")
|
67
|
+
end
|
68
|
+
|
69
|
+
# Creates a simple slider control and associates it with a hidden text field
|
70
|
+
def slider_field(object, method, options={})
|
71
|
+
options.merge!({
|
72
|
+
:change => "$('#{object}_#{method}').value = value",
|
73
|
+
:hidden_fields => false
|
74
|
+
})
|
75
|
+
if slider_value = instance_variable_get("@#{object}").send(method)
|
76
|
+
options.merge!({ :sliderValue => slider_value })
|
77
|
+
end
|
78
|
+
hidden_field(object, method) <<
|
79
|
+
content_tag('div',content_tag('div', ''),
|
80
|
+
:class => 'slider', :id => "#{object}_#{method}_slider") <<
|
81
|
+
slider_element("#{object}_#{method}_slider", options)
|
82
|
+
end
|
83
|
+
|
84
|
+
def slider_stylesheet
|
85
|
+
content_tag("style", <<-EOT
|
86
|
+
div.slider {
|
87
|
+
width: 150px;
|
88
|
+
height: 5px;
|
89
|
+
margin-top:5px;
|
90
|
+
margin-bottom:5px;
|
91
|
+
background: #ddd;
|
92
|
+
position: relative;
|
93
|
+
}
|
94
|
+
div.slider div {
|
95
|
+
position:absolute;
|
96
|
+
width:8px;
|
97
|
+
height:15px;
|
98
|
+
margin-top:-5px;
|
99
|
+
background: #999;
|
100
|
+
border:1px outset white;
|
101
|
+
}
|
102
|
+
EOT
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
def options_for_javascript(options)
|
108
|
+
'{' + options.map {|k, v| "#{k}:#{v}"}.sort.join(', ') + '}'
|
109
|
+
end
|
110
|
+
|
111
|
+
def array_or_string_for_javascript(option)
|
112
|
+
if option.kind_of?(Array)
|
113
|
+
"['" + option.join("','") + "']"
|
114
|
+
elsif !option.nil?
|
115
|
+
"'#{option}'"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def array_or_numeric_for_javascript(option)
|
120
|
+
if option.kind_of?(Array)
|
121
|
+
"[" + option.join(',') + "]"
|
122
|
+
elsif !option.nil?
|
123
|
+
option.to_s
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seamusabshere-scriptaculous_slider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nico Bounga
|
8
|
+
- Marty Haught
|
9
|
+
- Thomas Fuchs
|
10
|
+
- Nicolas Cavigneaux
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-02-05 00:00:00 -08:00
|
16
|
+
default_executable:
|
17
|
+
dependencies: []
|
18
|
+
|
19
|
+
description: Scriptaculous slider plugin
|
20
|
+
email: nico@bounga.org
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- VERSION.yml
|
29
|
+
- lib/helpers
|
30
|
+
- lib/helpers/slider_helper.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/Bounga/scriptaculous_slider
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --inline-source
|
36
|
+
- --charset=UTF-8
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.2.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: Scriptaculous slider plugin
|
58
|
+
test_files: []
|
59
|
+
|