scriptaculous_slider 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +63 -0
- data/Rakefile +68 -0
- data/init.rb +2 -0
- data/javascripts/slider.js +275 -0
- data/lib/helpers/slider_helper.rb +130 -0
- data/tasks/scriptaculous_slider.rake +4 -0
- metadata +69 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [Nicolas Cavigneaux]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
-*-markdown-*-
|
2
|
+
|
3
|
+
script.aculo.us Slider
|
4
|
+
======================
|
5
|
+
|
6
|
+
This plugin is of fork of the original [scriptaculous slider plugin](http://github.com/rails/scriptaculous_slider/) which is not maintained anymore.
|
7
|
+
|
8
|
+
It provides helpers for the script.aculo.us slider control.
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
In your Rails app root, use the following command-line :
|
14
|
+
|
15
|
+
cd vendor/plugins
|
16
|
+
hg clone http://bitbucket.org/Bounga/scriptaculous-slider/
|
17
|
+
|
18
|
+
or install it system-wide :
|
19
|
+
|
20
|
+
$ sudo gem install scriptaculous_slider
|
21
|
+
|
22
|
+
and require it in Rails::Initializer (environment.rb) :
|
23
|
+
|
24
|
+
config.gem 'scriptaculous_slider'
|
25
|
+
|
26
|
+
You'll need to run:
|
27
|
+
|
28
|
+
rake scriptaculous_slider_install
|
29
|
+
|
30
|
+
to install the necessary slider.js file in your public/javascripts folder.
|
31
|
+
|
32
|
+
|
33
|
+
Example
|
34
|
+
-------
|
35
|
+
|
36
|
+
<%= slider_stylesheet %>
|
37
|
+
<%= slider_field :object, :method, :range => 1..10 %>
|
38
|
+
<%= slider_element "my_slider", :range => 1..10, :hidden_fields => true %>
|
39
|
+
|
40
|
+
slider_element doesn't create hidden field by default but can be force to create one. It can handle Range for values option.
|
41
|
+
|
42
|
+
slider_field uses a hidden field internally that gets set automatically
|
43
|
+
when using the Slider.
|
44
|
+
|
45
|
+
slider_stylesheet builds a stylesheet for the slider (examine the output and
|
46
|
+
copy/paste to your own CSS files).
|
47
|
+
|
48
|
+
To see the full functionality and possibilities of the slider control,
|
49
|
+
have a look at the functional and unit tests provided in the script.aculo.us
|
50
|
+
GIT repository, see <http://github.com/madrobby/scriptaculous/tree/master>.
|
51
|
+
|
52
|
+
For discussion of this plugin use the [Prototype / Scriptaculous Google group](http://groups.google.com/group/prototype-scriptaculous)!
|
53
|
+
|
54
|
+
Other
|
55
|
+
-----
|
56
|
+
|
57
|
+
For more information see [Project homepage](http://www.bitbucket.org/Bounga/scriptaculous-slider/)
|
58
|
+
|
59
|
+
Problems, comments, and suggestions are welcome on the [ticket system](http://www.bitbucket.org/Bounga/scriptaculous-slider/issues/new/)
|
60
|
+
|
61
|
+
Copyright (c) 2005 Marty Haught, Thomas Fuchs, released under the MIT license
|
62
|
+
|
63
|
+
Copyright (c) 2008 Nicolas Cavigneaux, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/contrib/rubyforgepublisher'
|
5
|
+
require 'rubyforge'
|
6
|
+
|
7
|
+
SPEC = Gem::Specification.new do |s|
|
8
|
+
s.name = 'scriptaculous_slider'
|
9
|
+
s.version = '1.0.0'
|
10
|
+
s.authors = ['Nicolas Cavigneaux']
|
11
|
+
s.email = 'nico@bounga.org'
|
12
|
+
s.homepage = 'http://www.bitbucket.org/Bounga/acts_as_nice_url'
|
13
|
+
s.rubyforge_project = %q{slider}
|
14
|
+
s.summary = 'A Ruby on Rails extension to provide provides helpers for the script.aculo.us slider control'
|
15
|
+
s.description = 'This extension is of fork of the original scriptaculous slider plugin which is not maintained anymore. It provides helpers for the script.aculo.us slider control.'
|
16
|
+
s.files = [ "Rakefile", "init.rb", "README", "LICENSE"] +
|
17
|
+
Dir.glob("{bin,javascripts,doc,lib,tasks,test}/**/*")
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.extra_rdoc_files = ['README']
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.add_dependency('actionpack')
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'run unit tests'
|
25
|
+
task :default => :test
|
26
|
+
|
27
|
+
task :gem
|
28
|
+
Rake::GemPackageTask.new(SPEC) do |pkg|
|
29
|
+
pkg.need_zip = true
|
30
|
+
pkg.need_tar_bz2 = true
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Install gem file #{SPEC.name}-#{SPEC.version}.gem"
|
34
|
+
task :install => [:gem] do
|
35
|
+
sh "gem install pkg/#{SPEC.name}-#{SPEC.version}.gem"
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Publish documentation to RubyForge"
|
39
|
+
task :publish_doc => [:rdoc] do
|
40
|
+
rf = Rake::RubyForgePublisher.new(SPEC.rubyforge_project, 'bounga')
|
41
|
+
rf.upload
|
42
|
+
puts "Published documentation to RubyForge"
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "Release gem #{SPEC.name}-#{SPEC.version}.gem"
|
46
|
+
task :release => [:gem, :publish_doc] do
|
47
|
+
rf = RubyForge.new.configure
|
48
|
+
puts "Logging in"
|
49
|
+
rf.login
|
50
|
+
|
51
|
+
puts "Releasing #{SPEC.name} v.#{SPEC.version}"
|
52
|
+
|
53
|
+
files = Dir.glob('pkg/*.{zip,bz2,gem}')
|
54
|
+
rf.add_release SPEC.rubyforge_project, SPEC.rubyforge_project, SPEC.version, *files
|
55
|
+
end
|
56
|
+
|
57
|
+
Rake::TestTask.new(:test) do |t|
|
58
|
+
t.libs << 'lib'
|
59
|
+
t.pattern = 'test/**/*_test.rb'
|
60
|
+
t.verbose = true
|
61
|
+
end
|
62
|
+
|
63
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
64
|
+
rdoc.title = 'Scriptaculous Slider'
|
65
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
66
|
+
rdoc.rdoc_files.include('README')
|
67
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
68
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
// script.aculo.us slider.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
|
2
|
+
|
3
|
+
// Copyright (c) 2005-2008 Marty Haught, Thomas Fuchs
|
4
|
+
//
|
5
|
+
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
6
|
+
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
7
|
+
|
8
|
+
if (!Control) var Control = { };
|
9
|
+
|
10
|
+
// options:
|
11
|
+
// axis: 'vertical', or 'horizontal' (default)
|
12
|
+
//
|
13
|
+
// callbacks:
|
14
|
+
// onChange(value)
|
15
|
+
// onSlide(value)
|
16
|
+
Control.Slider = Class.create({
|
17
|
+
initialize: function(handle, track, options) {
|
18
|
+
var slider = this;
|
19
|
+
|
20
|
+
if (Object.isArray(handle)) {
|
21
|
+
this.handles = handle.collect( function(e) { return $(e) });
|
22
|
+
} else {
|
23
|
+
this.handles = [$(handle)];
|
24
|
+
}
|
25
|
+
|
26
|
+
this.track = $(track);
|
27
|
+
this.options = options || { };
|
28
|
+
|
29
|
+
this.axis = this.options.axis || 'horizontal';
|
30
|
+
this.increment = this.options.increment || 1;
|
31
|
+
this.step = parseInt(this.options.step || '1');
|
32
|
+
this.range = this.options.range || $R(0,1);
|
33
|
+
|
34
|
+
this.value = 0; // assure backwards compat
|
35
|
+
this.values = this.handles.map( function() { return 0 });
|
36
|
+
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
|
37
|
+
this.options.startSpan = $(this.options.startSpan || null);
|
38
|
+
this.options.endSpan = $(this.options.endSpan || null);
|
39
|
+
|
40
|
+
this.restricted = this.options.restricted || false;
|
41
|
+
|
42
|
+
this.maximum = this.options.maximum || this.range.end;
|
43
|
+
this.minimum = this.options.minimum || this.range.start;
|
44
|
+
|
45
|
+
// Will be used to align the handle onto the track, if necessary
|
46
|
+
this.alignX = parseInt(this.options.alignX || '0');
|
47
|
+
this.alignY = parseInt(this.options.alignY || '0');
|
48
|
+
|
49
|
+
this.trackLength = this.maximumOffset() - this.minimumOffset();
|
50
|
+
|
51
|
+
this.handleLength = this.isVertical() ?
|
52
|
+
(this.handles[0].offsetHeight != 0 ?
|
53
|
+
this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
|
54
|
+
(this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
|
55
|
+
this.handles[0].style.width.replace(/px$/,""));
|
56
|
+
|
57
|
+
this.active = false;
|
58
|
+
this.dragging = false;
|
59
|
+
this.disabled = false;
|
60
|
+
|
61
|
+
if (this.options.disabled) this.setDisabled();
|
62
|
+
|
63
|
+
// Allowed values array
|
64
|
+
this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
|
65
|
+
if (this.allowedValues) {
|
66
|
+
this.minimum = this.allowedValues.min();
|
67
|
+
this.maximum = this.allowedValues.max();
|
68
|
+
}
|
69
|
+
|
70
|
+
this.eventMouseDown = this.startDrag.bindAsEventListener(this);
|
71
|
+
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
|
72
|
+
this.eventMouseMove = this.update.bindAsEventListener(this);
|
73
|
+
|
74
|
+
// Initialize handles in reverse (make sure first handle is active)
|
75
|
+
this.handles.each( function(h,i) {
|
76
|
+
i = slider.handles.length-1-i;
|
77
|
+
slider.setValue(parseFloat(
|
78
|
+
(Object.isArray(slider.options.sliderValue) ?
|
79
|
+
slider.options.sliderValue[i] : slider.options.sliderValue) ||
|
80
|
+
slider.range.start), i);
|
81
|
+
h.makePositioned().observe("mousedown", slider.eventMouseDown);
|
82
|
+
});
|
83
|
+
|
84
|
+
this.track.observe("mousedown", this.eventMouseDown);
|
85
|
+
document.observe("mouseup", this.eventMouseUp);
|
86
|
+
document.observe("mousemove", this.eventMouseMove);
|
87
|
+
|
88
|
+
this.initialized = true;
|
89
|
+
},
|
90
|
+
dispose: function() {
|
91
|
+
var slider = this;
|
92
|
+
Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
|
93
|
+
Event.stopObserving(document, "mouseup", this.eventMouseUp);
|
94
|
+
Event.stopObserving(document, "mousemove", this.eventMouseMove);
|
95
|
+
this.handles.each( function(h) {
|
96
|
+
Event.stopObserving(h, "mousedown", slider.eventMouseDown);
|
97
|
+
});
|
98
|
+
},
|
99
|
+
setDisabled: function(){
|
100
|
+
this.disabled = true;
|
101
|
+
},
|
102
|
+
setEnabled: function(){
|
103
|
+
this.disabled = false;
|
104
|
+
},
|
105
|
+
getNearestValue: function(value){
|
106
|
+
if (this.allowedValues){
|
107
|
+
if (value >= this.allowedValues.max()) return(this.allowedValues.max());
|
108
|
+
if (value <= this.allowedValues.min()) return(this.allowedValues.min());
|
109
|
+
|
110
|
+
var offset = Math.abs(this.allowedValues[0] - value);
|
111
|
+
var newValue = this.allowedValues[0];
|
112
|
+
this.allowedValues.each( function(v) {
|
113
|
+
var currentOffset = Math.abs(v - value);
|
114
|
+
if (currentOffset <= offset){
|
115
|
+
newValue = v;
|
116
|
+
offset = currentOffset;
|
117
|
+
}
|
118
|
+
});
|
119
|
+
return newValue;
|
120
|
+
}
|
121
|
+
if (value > this.range.end) return this.range.end;
|
122
|
+
if (value < this.range.start) return this.range.start;
|
123
|
+
return value;
|
124
|
+
},
|
125
|
+
setValue: function(sliderValue, handleIdx){
|
126
|
+
if (!this.active) {
|
127
|
+
this.activeHandleIdx = handleIdx || 0;
|
128
|
+
this.activeHandle = this.handles[this.activeHandleIdx];
|
129
|
+
this.updateStyles();
|
130
|
+
}
|
131
|
+
handleIdx = handleIdx || this.activeHandleIdx || 0;
|
132
|
+
if (this.initialized && this.restricted) {
|
133
|
+
if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
|
134
|
+
sliderValue = this.values[handleIdx-1];
|
135
|
+
if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
|
136
|
+
sliderValue = this.values[handleIdx+1];
|
137
|
+
}
|
138
|
+
sliderValue = this.getNearestValue(sliderValue);
|
139
|
+
this.values[handleIdx] = sliderValue;
|
140
|
+
this.value = this.values[0]; // assure backwards compat
|
141
|
+
|
142
|
+
this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
|
143
|
+
this.translateToPx(sliderValue);
|
144
|
+
|
145
|
+
this.drawSpans();
|
146
|
+
if (!this.dragging || !this.event) this.updateFinished();
|
147
|
+
},
|
148
|
+
setValueBy: function(delta, handleIdx) {
|
149
|
+
this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
|
150
|
+
handleIdx || this.activeHandleIdx || 0);
|
151
|
+
},
|
152
|
+
translateToPx: function(value) {
|
153
|
+
return Math.round(
|
154
|
+
((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
|
155
|
+
(value - this.range.start)) + "px";
|
156
|
+
},
|
157
|
+
translateToValue: function(offset) {
|
158
|
+
return ((offset/(this.trackLength-this.handleLength) *
|
159
|
+
(this.range.end-this.range.start)) + this.range.start);
|
160
|
+
},
|
161
|
+
getRange: function(range) {
|
162
|
+
var v = this.values.sortBy(Prototype.K);
|
163
|
+
range = range || 0;
|
164
|
+
return $R(v[range],v[range+1]);
|
165
|
+
},
|
166
|
+
minimumOffset: function(){
|
167
|
+
return(this.isVertical() ? this.alignY : this.alignX);
|
168
|
+
},
|
169
|
+
maximumOffset: function(){
|
170
|
+
return(this.isVertical() ?
|
171
|
+
(this.track.offsetHeight != 0 ? this.track.offsetHeight :
|
172
|
+
this.track.style.height.replace(/px$/,"")) - this.alignY :
|
173
|
+
(this.track.offsetWidth != 0 ? this.track.offsetWidth :
|
174
|
+
this.track.style.width.replace(/px$/,"")) - this.alignX);
|
175
|
+
},
|
176
|
+
isVertical: function(){
|
177
|
+
return (this.axis == 'vertical');
|
178
|
+
},
|
179
|
+
drawSpans: function() {
|
180
|
+
var slider = this;
|
181
|
+
if (this.spans)
|
182
|
+
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
|
183
|
+
if (this.options.startSpan)
|
184
|
+
this.setSpan(this.options.startSpan,
|
185
|
+
$R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
|
186
|
+
if (this.options.endSpan)
|
187
|
+
this.setSpan(this.options.endSpan,
|
188
|
+
$R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
|
189
|
+
},
|
190
|
+
setSpan: function(span, range) {
|
191
|
+
if (this.isVertical()) {
|
192
|
+
span.style.top = this.translateToPx(range.start);
|
193
|
+
span.style.height = this.translateToPx(range.end - range.start + this.range.start);
|
194
|
+
} else {
|
195
|
+
span.style.left = this.translateToPx(range.start);
|
196
|
+
span.style.width = this.translateToPx(range.end - range.start + this.range.start);
|
197
|
+
}
|
198
|
+
},
|
199
|
+
updateStyles: function() {
|
200
|
+
this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
|
201
|
+
Element.addClassName(this.activeHandle, 'selected');
|
202
|
+
},
|
203
|
+
startDrag: function(event) {
|
204
|
+
if (Event.isLeftClick(event)) {
|
205
|
+
if (!this.disabled){
|
206
|
+
this.active = true;
|
207
|
+
|
208
|
+
var handle = Event.element(event);
|
209
|
+
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
210
|
+
var track = handle;
|
211
|
+
if (track==this.track) {
|
212
|
+
var offsets = Position.cumulativeOffset(this.track);
|
213
|
+
this.event = event;
|
214
|
+
this.setValue(this.translateToValue(
|
215
|
+
(this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
|
216
|
+
));
|
217
|
+
var offsets = Position.cumulativeOffset(this.activeHandle);
|
218
|
+
this.offsetX = (pointer[0] - offsets[0]);
|
219
|
+
this.offsetY = (pointer[1] - offsets[1]);
|
220
|
+
} else {
|
221
|
+
// find the handle (prevents issues with Safari)
|
222
|
+
while((this.handles.indexOf(handle) == -1) && handle.parentNode)
|
223
|
+
handle = handle.parentNode;
|
224
|
+
|
225
|
+
if (this.handles.indexOf(handle)!=-1) {
|
226
|
+
this.activeHandle = handle;
|
227
|
+
this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
|
228
|
+
this.updateStyles();
|
229
|
+
|
230
|
+
var offsets = Position.cumulativeOffset(this.activeHandle);
|
231
|
+
this.offsetX = (pointer[0] - offsets[0]);
|
232
|
+
this.offsetY = (pointer[1] - offsets[1]);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
Event.stop(event);
|
237
|
+
}
|
238
|
+
},
|
239
|
+
update: function(event) {
|
240
|
+
if (this.active) {
|
241
|
+
if (!this.dragging) this.dragging = true;
|
242
|
+
this.draw(event);
|
243
|
+
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
|
244
|
+
Event.stop(event);
|
245
|
+
}
|
246
|
+
},
|
247
|
+
draw: function(event) {
|
248
|
+
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
249
|
+
var offsets = Position.cumulativeOffset(this.track);
|
250
|
+
pointer[0] -= this.offsetX + offsets[0];
|
251
|
+
pointer[1] -= this.offsetY + offsets[1];
|
252
|
+
this.event = event;
|
253
|
+
this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
|
254
|
+
if (this.initialized && this.options.onSlide)
|
255
|
+
this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
|
256
|
+
},
|
257
|
+
endDrag: function(event) {
|
258
|
+
if (this.active && this.dragging) {
|
259
|
+
this.finishDrag(event, true);
|
260
|
+
Event.stop(event);
|
261
|
+
}
|
262
|
+
this.active = false;
|
263
|
+
this.dragging = false;
|
264
|
+
},
|
265
|
+
finishDrag: function(event, success) {
|
266
|
+
this.active = false;
|
267
|
+
this.dragging = false;
|
268
|
+
this.updateFinished();
|
269
|
+
},
|
270
|
+
updateFinished: function() {
|
271
|
+
if (this.initialized && this.options.onChange)
|
272
|
+
this.options.onChange(this.values.length>1 ? this.values : this.value, this);
|
273
|
+
this.event = null;
|
274
|
+
}
|
275
|
+
});
|
@@ -0,0 +1,130 @@
|
|
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}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
|
+
:slider_value => instance_variable_get("@#{object}").send(method),
|
74
|
+
:hidden_fields => false
|
75
|
+
})
|
76
|
+
hidden_field(object, method) <<
|
77
|
+
content_tag('div',content_tag('div', ''),
|
78
|
+
:class => 'slider', :id => "#{object}_#{method}_slider") <<
|
79
|
+
slider_element("#{object}_#{method}_slider", options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def slider_stylesheet
|
83
|
+
content_tag("style", <<-EOT
|
84
|
+
div.slider {
|
85
|
+
width: 150px;
|
86
|
+
height: 5px;
|
87
|
+
margin-top:5px;
|
88
|
+
margin-bottom:5px;
|
89
|
+
background: #ddd;
|
90
|
+
position: relative;
|
91
|
+
}
|
92
|
+
div.slider div {
|
93
|
+
position:absolute;
|
94
|
+
width:8px;
|
95
|
+
height:15px;
|
96
|
+
margin-top:-5px;
|
97
|
+
background: #999;
|
98
|
+
border:1px outset white;
|
99
|
+
}
|
100
|
+
EOT
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
def options_for_javascript(options)
|
106
|
+
'{' + options.map {|k, v| "#{k}:#{v}"}.sort.join(', ') + '}'
|
107
|
+
end
|
108
|
+
|
109
|
+
def array_or_string_for_javascript(option)
|
110
|
+
if option.kind_of?(Array)
|
111
|
+
"['" + option.join("','") + "']"
|
112
|
+
elsif !option.nil?
|
113
|
+
"'#{option}'"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def array_or_numeric_for_javascript(option)
|
118
|
+
if option.kind_of?(Array)
|
119
|
+
"[" + option.join(',') + "]"
|
120
|
+
elsif !option.nil?
|
121
|
+
option.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
ActionView::Helpers::AssetTagHelper::register_javascript_include_default "slider"
|
130
|
+
ActionView::Base.send :include, ActionView::Helpers::SliderHelper
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scriptaculous_slider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Cavigneaux
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-27 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionpack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: This extension is of fork of the original scriptaculous slider plugin which is not maintained anymore. It provides helpers for the script.aculo.us slider control.
|
26
|
+
email: nico@bounga.org
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- Rakefile
|
35
|
+
- init.rb
|
36
|
+
- README
|
37
|
+
- LICENSE
|
38
|
+
- javascripts/slider.js
|
39
|
+
- lib/helpers
|
40
|
+
- lib/helpers/slider_helper.rb
|
41
|
+
- tasks/scriptaculous_slider.rake
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://www.bitbucket.org/Bounga/acts_as_nice_url
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: slider
|
64
|
+
rubygems_version: 1.3.1
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: A Ruby on Rails extension to provide provides helpers for the script.aculo.us slider control
|
68
|
+
test_files: []
|
69
|
+
|