bootstrap-slider-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/bootstrap-slider-rails.gemspec +24 -0
- data/lib/bootstrap-slider-rails/version.rb +5 -0
- data/lib/bootstrap-slider-rails.rb +9 -0
- data/vendor/assets/css/slider.css +139 -0
- data/vendor/assets/javascripts/bootstrap-slider.js +538 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pedr Browne
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Bootstrap-Slider-Rails
|
2
|
+
|
3
|
+
This Gem integrates [Seiyara's fork](https://github.com/seiyria/bootstrap-slider) of [Bootstrap Slider](http://www.eyecon.ro/bootstrap-slider/). The original has no public Github Repo, issues tracking etc.
|
4
|
+
|
5
|
+
It integrates this fork with your Rails project and is versioned to track the fork's versioning.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'bootstrap-slider-rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bootstrap-slider-rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This gem uses a Rails Engine to make Bootstrap Slider's assets available to you.
|
24
|
+
|
25
|
+
Require the JavaScript files from your `application.js` or wherever needed using:
|
26
|
+
|
27
|
+
```
|
28
|
+
//= require bootstrap-slider
|
29
|
+
```
|
30
|
+
|
31
|
+
Require the CSS files from your `application.scss` or wherever needed using:
|
32
|
+
|
33
|
+
```
|
34
|
+
*= require slider
|
35
|
+
```
|
36
|
+
|
37
|
+
*Note: This naming inconsistancy is part of Bootstrap Slider. I have opened a ticket [here](https://github.com/seiyria/bootstrap-slider/issues/41)
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bootstrap-slider-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bootstrap-slider-rails"
|
8
|
+
spec.version = BootstrapSlider::Rails::VERSION
|
9
|
+
spec.authors = ["Pedr Browne"]
|
10
|
+
spec.email = ["pedr.browne@gmail.com"]
|
11
|
+
spec.description = %q{Make Bootstrap Slider available to Rails}
|
12
|
+
spec.summary = %q{This Gem integrates Seiyara's fork of Bootstrap Slider with Rails, exposing its JavaScript and CSS assets via a Rails Engine.
|
13
|
+
}
|
14
|
+
spec.homepage = "http://github.com/stationkeeping/bootstrap-slider-rails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "railties", "~> 3.1"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
/*!
|
2
|
+
* Slider for Bootstrap
|
3
|
+
*
|
4
|
+
* Copyright 2012 Stefan Petre
|
5
|
+
* Licensed under the Apache License v2.0
|
6
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
.slider {
|
10
|
+
display: inline-block;
|
11
|
+
vertical-align: middle;
|
12
|
+
position: relative;
|
13
|
+
}
|
14
|
+
.slider.slider-horizontal {
|
15
|
+
width: 210px;
|
16
|
+
height: 20px;
|
17
|
+
}
|
18
|
+
.slider.slider-horizontal .slider-track {
|
19
|
+
height: 10px;
|
20
|
+
width: 100%;
|
21
|
+
margin-top: -5px;
|
22
|
+
top: 50%;
|
23
|
+
left: 0;
|
24
|
+
}
|
25
|
+
.slider.slider-horizontal .slider-selection {
|
26
|
+
height: 100%;
|
27
|
+
top: 0;
|
28
|
+
bottom: 0;
|
29
|
+
}
|
30
|
+
.slider.slider-horizontal .slider-handle {
|
31
|
+
margin-left: -10px;
|
32
|
+
margin-top: -5px;
|
33
|
+
}
|
34
|
+
.slider.slider-horizontal .slider-handle.triangle {
|
35
|
+
border-width: 0 10px 10px 10px;
|
36
|
+
width: 0;
|
37
|
+
height: 0;
|
38
|
+
border-bottom-color: #0480be;
|
39
|
+
margin-top: 0;
|
40
|
+
}
|
41
|
+
.slider.slider-vertical {
|
42
|
+
height: 210px;
|
43
|
+
width: 20px;
|
44
|
+
}
|
45
|
+
.slider.slider-vertical .slider-track {
|
46
|
+
width: 10px;
|
47
|
+
height: 100%;
|
48
|
+
margin-left: -5px;
|
49
|
+
left: 50%;
|
50
|
+
top: 0;
|
51
|
+
}
|
52
|
+
.slider.slider-vertical .slider-selection {
|
53
|
+
width: 100%;
|
54
|
+
left: 0;
|
55
|
+
top: 0;
|
56
|
+
bottom: 0;
|
57
|
+
}
|
58
|
+
.slider.slider-vertical .slider-handle {
|
59
|
+
margin-left: -5px;
|
60
|
+
margin-top: -10px;
|
61
|
+
}
|
62
|
+
.slider.slider-vertical .slider-handle.triangle {
|
63
|
+
border-width: 10px 0 10px 10px;
|
64
|
+
width: 1px;
|
65
|
+
height: 1px;
|
66
|
+
border-left-color: #0480be;
|
67
|
+
margin-left: 0;
|
68
|
+
}
|
69
|
+
.slider.slider-disabled .slider-handle {
|
70
|
+
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#dfdfdf), to(#bebebe));
|
71
|
+
background-image: -webkit-linear-gradient(top, #dfdfdf 0%, #bebebe 100%);
|
72
|
+
background-image: -moz-linear-gradient(top, #dfdfdf 0%, #bebebe 100%);
|
73
|
+
background-image: linear-gradient(to bottom, #dfdfdf 0%, #bebebe 100%);
|
74
|
+
background-repeat: repeat-x;
|
75
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdfdfdf', endColorstr='#ffbebebe', GradientType=0);
|
76
|
+
}
|
77
|
+
.slider.slider-disabled .slider-track {
|
78
|
+
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#e5e5e5), to(#e9e9e9));
|
79
|
+
background-image: -webkit-linear-gradient(top, #e5e5e5 0%, #e9e9e9 100%);
|
80
|
+
background-image: -moz-linear-gradient(top, #e5e5e5 0%, #e9e9e9 100%);
|
81
|
+
background-image: linear-gradient(to bottom, #e5e5e5 0%, #e9e9e9 100%);
|
82
|
+
background-repeat: repeat-x;
|
83
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe5e5e5', endColorstr='#ffe9e9e9', GradientType=0);
|
84
|
+
}
|
85
|
+
.slider input {
|
86
|
+
display: none;
|
87
|
+
}
|
88
|
+
.slider .tooltip-inner {
|
89
|
+
white-space: nowrap;
|
90
|
+
}
|
91
|
+
.slider-track {
|
92
|
+
position: absolute;
|
93
|
+
cursor: pointer;
|
94
|
+
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f5f5f5), to(#f9f9f9));
|
95
|
+
background-image: -webkit-linear-gradient(top, #f5f5f5 0%, #f9f9f9 100%);
|
96
|
+
background-image: -moz-linear-gradient(top, #f5f5f5 0%, #f9f9f9 100%);
|
97
|
+
background-image: linear-gradient(to bottom, #f5f5f5 0%, #f9f9f9 100%);
|
98
|
+
background-repeat: repeat-x;
|
99
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#fff9f9f9', GradientType=0);
|
100
|
+
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
|
101
|
+
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
|
102
|
+
border-radius: 4px;
|
103
|
+
}
|
104
|
+
.slider-selection {
|
105
|
+
position: absolute;
|
106
|
+
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f9f9f9), to(#f5f5f5));
|
107
|
+
background-image: -webkit-linear-gradient(top, #f9f9f9 0%, #f5f5f5 100%);
|
108
|
+
background-image: -moz-linear-gradient(top, #f9f9f9 0%, #f5f5f5 100%);
|
109
|
+
background-image: linear-gradient(to bottom, #f9f9f9 0%, #f5f5f5 100%);
|
110
|
+
background-repeat: repeat-x;
|
111
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff9f9f9', endColorstr='#fff5f5f5', GradientType=0);
|
112
|
+
-webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);
|
113
|
+
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15);
|
114
|
+
-webkit-box-sizing: border-box;
|
115
|
+
-moz-box-sizing: border-box;
|
116
|
+
box-sizing: border-box;
|
117
|
+
border-radius: 4px;
|
118
|
+
}
|
119
|
+
.slider-handle {
|
120
|
+
position: absolute;
|
121
|
+
width: 20px;
|
122
|
+
height: 20px;
|
123
|
+
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#149bdf), to(#0480be));
|
124
|
+
background-image: -webkit-linear-gradient(top, #149bdf 0%, #0480be 100%);
|
125
|
+
background-image: -moz-linear-gradient(top, #149bdf 0%, #0480be 100%);
|
126
|
+
background-image: linear-gradient(to bottom, #149bdf 0%, #0480be 100%);
|
127
|
+
background-repeat: repeat-x;
|
128
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff149bdf', endColorstr='#ff0480be', GradientType=0);
|
129
|
+
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.05);
|
130
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.05);
|
131
|
+
opacity: 0.8;
|
132
|
+
border: 0px solid transparent;
|
133
|
+
}
|
134
|
+
.slider-handle.round {
|
135
|
+
border-radius: 50%;
|
136
|
+
}
|
137
|
+
.slider-handle.triangle {
|
138
|
+
background: transparent none;
|
139
|
+
}
|
@@ -0,0 +1,538 @@
|
|
1
|
+
/* =========================================================
|
2
|
+
* bootstrap-slider.js v2.0.0
|
3
|
+
* http://www.eyecon.ro/bootstrap-slider
|
4
|
+
* =========================================================
|
5
|
+
* Copyright 2012 Stefan Petre
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
* ========================================================= */
|
19
|
+
|
20
|
+
(function( $ ) {
|
21
|
+
|
22
|
+
var ErrorMsgs = {
|
23
|
+
formatInvalidInputErrorMsg : function(input) {
|
24
|
+
return "Invalid input value '" + input + "' passed in";
|
25
|
+
},
|
26
|
+
callingContextNotSliderInstance : "Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method"
|
27
|
+
};
|
28
|
+
|
29
|
+
var Slider = function(element, options) {
|
30
|
+
var el = this.element = $(element).hide();
|
31
|
+
var origWidth = el.outerWidth();
|
32
|
+
|
33
|
+
var updateSlider = false;
|
34
|
+
var parent = this.element.parent();
|
35
|
+
|
36
|
+
|
37
|
+
if (parent.hasClass('slider') === true) {
|
38
|
+
updateSlider = true;
|
39
|
+
this.picker = parent;
|
40
|
+
} else {
|
41
|
+
this.picker = $('<div class="slider">'+
|
42
|
+
'<div class="slider-track">'+
|
43
|
+
'<div class="slider-selection"></div>'+
|
44
|
+
'<div class="slider-handle"></div>'+
|
45
|
+
'<div class="slider-handle"></div>'+
|
46
|
+
'</div>'+
|
47
|
+
'<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'+
|
48
|
+
'</div>')
|
49
|
+
.insertBefore(this.element)
|
50
|
+
.append(this.element);
|
51
|
+
}
|
52
|
+
|
53
|
+
this.id = this.element.data('slider-id')||options.id;
|
54
|
+
if (this.id) {
|
55
|
+
this.picker[0].id = this.id;
|
56
|
+
}
|
57
|
+
|
58
|
+
if (typeof Modernizr !== 'undefined' && Modernizr.touch) {
|
59
|
+
this.touchCapable = true;
|
60
|
+
}
|
61
|
+
|
62
|
+
var tooltip = this.element.data('slider-tooltip')||options.tooltip;
|
63
|
+
|
64
|
+
this.tooltip = this.picker.find('.tooltip');
|
65
|
+
this.tooltipInner = this.tooltip.find('div.tooltip-inner');
|
66
|
+
|
67
|
+
this.orientation = this.element.data('slider-orientation')||options.orientation;
|
68
|
+
switch(this.orientation) {
|
69
|
+
case 'vertical':
|
70
|
+
this.picker.addClass('slider-vertical');
|
71
|
+
this.stylePos = 'top';
|
72
|
+
this.mousePos = 'pageY';
|
73
|
+
this.sizePos = 'offsetHeight';
|
74
|
+
this.tooltip.addClass('right')[0].style.left = '100%';
|
75
|
+
break;
|
76
|
+
default:
|
77
|
+
this.picker
|
78
|
+
.addClass('slider-horizontal')
|
79
|
+
.css('width', origWidth);
|
80
|
+
this.orientation = 'horizontal';
|
81
|
+
this.stylePos = 'left';
|
82
|
+
this.mousePos = 'pageX';
|
83
|
+
this.sizePos = 'offsetWidth';
|
84
|
+
this.tooltip.addClass('top')[0].style.top = -this.tooltip.outerHeight() - 14 + 'px';
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
|
88
|
+
['min', 'max', 'step', 'value'].forEach(function(attr) {
|
89
|
+
this[attr] = el.data('slider-' + attr) || options[attr] || el.prop(attr);
|
90
|
+
}, this);
|
91
|
+
|
92
|
+
if (this.value instanceof Array) {
|
93
|
+
this.range = true;
|
94
|
+
}
|
95
|
+
|
96
|
+
this.selection = this.element.data('slider-selection')||options.selection;
|
97
|
+
this.selectionEl = this.picker.find('.slider-selection');
|
98
|
+
if (this.selection === 'none') {
|
99
|
+
this.selectionEl.addClass('hide');
|
100
|
+
}
|
101
|
+
|
102
|
+
this.selectionElStyle = this.selectionEl[0].style;
|
103
|
+
|
104
|
+
this.handle1 = this.picker.find('.slider-handle:first');
|
105
|
+
this.handle1Stype = this.handle1[0].style;
|
106
|
+
this.handle2 = this.picker.find('.slider-handle:last');
|
107
|
+
this.handle2Stype = this.handle2[0].style;
|
108
|
+
|
109
|
+
var handle = this.element.data('slider-handle')||options.handle;
|
110
|
+
switch(handle) {
|
111
|
+
case 'round':
|
112
|
+
this.handle1.addClass('round');
|
113
|
+
this.handle2.addClass('round');
|
114
|
+
break;
|
115
|
+
case 'triangle':
|
116
|
+
this.handle1.addClass('triangle');
|
117
|
+
this.handle2.addClass('triangle');
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
|
121
|
+
if (this.range) {
|
122
|
+
this.value[0] = Math.max(this.min, Math.min(this.max, this.value[0]));
|
123
|
+
this.value[1] = Math.max(this.min, Math.min(this.max, this.value[1]));
|
124
|
+
} else {
|
125
|
+
this.value = [ Math.max(this.min, Math.min(this.max, this.value))];
|
126
|
+
this.handle2.addClass('hide');
|
127
|
+
if (this.selection === 'after') {
|
128
|
+
this.value[1] = this.max;
|
129
|
+
} else {
|
130
|
+
this.value[1] = this.min;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
this.diff = this.max - this.min;
|
134
|
+
this.percentage = [
|
135
|
+
(this.value[0]-this.min)*100/this.diff,
|
136
|
+
(this.value[1]-this.min)*100/this.diff,
|
137
|
+
this.step*100/this.diff
|
138
|
+
];
|
139
|
+
|
140
|
+
this.offset = this.picker.offset();
|
141
|
+
this.size = this.picker[0][this.sizePos];
|
142
|
+
|
143
|
+
this.formater = options.formater;
|
144
|
+
|
145
|
+
this.reversed = this.element.data('slider-reversed')||options.reversed;
|
146
|
+
|
147
|
+
this.layout();
|
148
|
+
|
149
|
+
if (this.touchCapable) {
|
150
|
+
// Touch: Bind touch events:
|
151
|
+
this.picker.on({
|
152
|
+
touchstart: $.proxy(this.mousedown, this)
|
153
|
+
});
|
154
|
+
} else {
|
155
|
+
this.picker.on({
|
156
|
+
mousedown: $.proxy(this.mousedown, this)
|
157
|
+
});
|
158
|
+
}
|
159
|
+
|
160
|
+
if (tooltip === 'show') {
|
161
|
+
this.picker.on({
|
162
|
+
mouseenter: $.proxy(this.showTooltip, this),
|
163
|
+
mouseleave: $.proxy(this.hideTooltip, this)
|
164
|
+
});
|
165
|
+
} else {
|
166
|
+
this.tooltip.addClass('hide');
|
167
|
+
}
|
168
|
+
|
169
|
+
if (updateSlider === true) {
|
170
|
+
var old = this.getValue();
|
171
|
+
var val = this.calculateValue();
|
172
|
+
this.element
|
173
|
+
.trigger({
|
174
|
+
type: 'slide',
|
175
|
+
value: val
|
176
|
+
})
|
177
|
+
.data('value', val)
|
178
|
+
.prop('value', val);
|
179
|
+
|
180
|
+
if (old !== val) {
|
181
|
+
this.element
|
182
|
+
.trigger({
|
183
|
+
type: 'slideChange',
|
184
|
+
new: val,
|
185
|
+
old: old
|
186
|
+
})
|
187
|
+
.data('value', val)
|
188
|
+
.prop('value', val);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
this.enabled = options.enabled &&
|
193
|
+
(this.element.data('slider-enabled') === undefined || this.element.data('slider-enabled') === true);
|
194
|
+
if(!this.enabled)
|
195
|
+
{
|
196
|
+
this.disable();
|
197
|
+
}
|
198
|
+
};
|
199
|
+
|
200
|
+
Slider.prototype = {
|
201
|
+
constructor: Slider,
|
202
|
+
|
203
|
+
over: false,
|
204
|
+
inDrag: false,
|
205
|
+
|
206
|
+
showTooltip: function(){
|
207
|
+
this.tooltip.addClass('in');
|
208
|
+
this.over = true;
|
209
|
+
},
|
210
|
+
|
211
|
+
hideTooltip: function(){
|
212
|
+
if (this.inDrag === false) {
|
213
|
+
this.tooltip.removeClass('in');
|
214
|
+
}
|
215
|
+
this.over = false;
|
216
|
+
},
|
217
|
+
|
218
|
+
layout: function(){
|
219
|
+
var positionPercentages;
|
220
|
+
|
221
|
+
if(this.reversed) {
|
222
|
+
positionPercentages = [ 100 - this.percentage[0], this.percentage[1] ];
|
223
|
+
} else {
|
224
|
+
positionPercentages = [ this.percentage[0], this.percentage[1] ];
|
225
|
+
}
|
226
|
+
|
227
|
+
this.handle1Stype[this.stylePos] = positionPercentages[0]+'%';
|
228
|
+
this.handle2Stype[this.stylePos] = positionPercentages[1]+'%';
|
229
|
+
|
230
|
+
if (this.orientation === 'vertical') {
|
231
|
+
this.selectionElStyle.top = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
|
232
|
+
this.selectionElStyle.height = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
|
233
|
+
} else {
|
234
|
+
this.selectionElStyle.left = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
|
235
|
+
this.selectionElStyle.width = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
|
236
|
+
}
|
237
|
+
|
238
|
+
if (this.range) {
|
239
|
+
this.tooltipInner.text(
|
240
|
+
this.formater(this.value[0]) + ' : ' + this.formater(this.value[1])
|
241
|
+
);
|
242
|
+
this.tooltip[0].style[this.stylePos] = this.size * (positionPercentages[0] + (positionPercentages[1] - positionPercentages[0])/2)/100 - (this.orientation === 'vertical' ? this.tooltip.outerHeight()/2 : this.tooltip.outerWidth()/2) +'px';
|
243
|
+
} else {
|
244
|
+
this.tooltipInner.text(
|
245
|
+
this.formater(this.value[0])
|
246
|
+
);
|
247
|
+
this.tooltip[0].style[this.stylePos] = this.size * positionPercentages[0]/100 - (this.orientation === 'vertical' ? this.tooltip.outerHeight()/2 : this.tooltip.outerWidth()/2) +'px';
|
248
|
+
}
|
249
|
+
},
|
250
|
+
|
251
|
+
mousedown: function(ev) {
|
252
|
+
if(!this.isEnabled()) {
|
253
|
+
return false;
|
254
|
+
}
|
255
|
+
// Touch: Get the original event:
|
256
|
+
if (this.touchCapable && ev.type === 'touchstart') {
|
257
|
+
ev = ev.originalEvent;
|
258
|
+
}
|
259
|
+
|
260
|
+
this.offset = this.picker.offset();
|
261
|
+
this.size = this.picker[0][this.sizePos];
|
262
|
+
|
263
|
+
var percentage = this.getPercentage(ev);
|
264
|
+
|
265
|
+
if (this.range) {
|
266
|
+
var diff1 = Math.abs(this.percentage[0] - percentage);
|
267
|
+
var diff2 = Math.abs(this.percentage[1] - percentage);
|
268
|
+
this.dragged = (diff1 < diff2) ? 0 : 1;
|
269
|
+
} else {
|
270
|
+
this.dragged = 0;
|
271
|
+
}
|
272
|
+
|
273
|
+
this.percentage[this.dragged] = this.reversed ? 100 - percentage : percentage;
|
274
|
+
this.layout();
|
275
|
+
|
276
|
+
if (this.touchCapable) {
|
277
|
+
// Touch: Bind touch events:
|
278
|
+
$(document).on({
|
279
|
+
touchmove: $.proxy(this.mousemove, this),
|
280
|
+
touchend: $.proxy(this.mouseup, this)
|
281
|
+
});
|
282
|
+
} else {
|
283
|
+
$(document).on({
|
284
|
+
mousemove: $.proxy(this.mousemove, this),
|
285
|
+
mouseup: $.proxy(this.mouseup, this)
|
286
|
+
});
|
287
|
+
}
|
288
|
+
|
289
|
+
this.inDrag = true;
|
290
|
+
var val = this.calculateValue();
|
291
|
+
this.setValue(val);
|
292
|
+
this.element.trigger({
|
293
|
+
type: 'slideStart',
|
294
|
+
value: val
|
295
|
+
}).trigger({
|
296
|
+
type: 'slide',
|
297
|
+
value: val
|
298
|
+
});
|
299
|
+
return false;
|
300
|
+
},
|
301
|
+
|
302
|
+
mousemove: function(ev) {
|
303
|
+
if(!this.isEnabled()) {
|
304
|
+
return false;
|
305
|
+
}
|
306
|
+
// Touch: Get the original event:
|
307
|
+
if (this.touchCapable && ev.type === 'touchmove') {
|
308
|
+
ev = ev.originalEvent;
|
309
|
+
}
|
310
|
+
|
311
|
+
var percentage = this.getPercentage(ev);
|
312
|
+
if (this.range) {
|
313
|
+
if (this.dragged === 0 && this.percentage[1] < percentage) {
|
314
|
+
this.percentage[0] = this.percentage[1];
|
315
|
+
this.dragged = 1;
|
316
|
+
} else if (this.dragged === 1 && this.percentage[0] > percentage) {
|
317
|
+
this.percentage[1] = this.percentage[0];
|
318
|
+
this.dragged = 0;
|
319
|
+
}
|
320
|
+
}
|
321
|
+
this.percentage[this.dragged] = this.reversed ? 100 - percentage : percentage;
|
322
|
+
this.layout();
|
323
|
+
var val = this.calculateValue();
|
324
|
+
this.setValue(val);
|
325
|
+
this.element
|
326
|
+
.trigger({
|
327
|
+
type: 'slide',
|
328
|
+
value: val
|
329
|
+
})
|
330
|
+
.data('value', val)
|
331
|
+
.prop('value', val);
|
332
|
+
return false;
|
333
|
+
},
|
334
|
+
|
335
|
+
mouseup: function() {
|
336
|
+
if(!this.isEnabled()) {
|
337
|
+
return false;
|
338
|
+
}
|
339
|
+
if (this.touchCapable) {
|
340
|
+
// Touch: Bind touch events:
|
341
|
+
$(document).off({
|
342
|
+
touchmove: this.mousemove,
|
343
|
+
touchend: this.mouseup
|
344
|
+
});
|
345
|
+
} else {
|
346
|
+
$(document).off({
|
347
|
+
mousemove: this.mousemove,
|
348
|
+
mouseup: this.mouseup
|
349
|
+
});
|
350
|
+
}
|
351
|
+
|
352
|
+
this.inDrag = false;
|
353
|
+
if (this.over === false) {
|
354
|
+
this.hideTooltip();
|
355
|
+
}
|
356
|
+
var val = this.calculateValue();
|
357
|
+
this.layout();
|
358
|
+
this.element
|
359
|
+
.trigger({
|
360
|
+
type: 'slideStop',
|
361
|
+
value: val
|
362
|
+
})
|
363
|
+
.data('value', val)
|
364
|
+
.prop('value', val);
|
365
|
+
return false;
|
366
|
+
},
|
367
|
+
|
368
|
+
calculateValue: function() {
|
369
|
+
var val;
|
370
|
+
if (this.range) {
|
371
|
+
val = [
|
372
|
+
(Math.max(this.min, this.min + Math.round((this.diff * this.percentage[0]/100)/this.step)*this.step)),
|
373
|
+
(Math.min(this.max, this.min + Math.round((this.diff * this.percentage[1]/100)/this.step)*this.step))
|
374
|
+
];
|
375
|
+
this.value = val;
|
376
|
+
} else {
|
377
|
+
val = (this.min + Math.round((this.diff * this.percentage[0]/100)/this.step)*this.step);
|
378
|
+
if (val < this.min) {
|
379
|
+
val = this.min;
|
380
|
+
}
|
381
|
+
else if (val > this.max) {
|
382
|
+
val = this.max;
|
383
|
+
}
|
384
|
+
val = parseFloat(val);
|
385
|
+
this.value = [val, this.value[1]];
|
386
|
+
}
|
387
|
+
return val;
|
388
|
+
},
|
389
|
+
|
390
|
+
getPercentage: function(ev) {
|
391
|
+
if (this.touchCapable) {
|
392
|
+
ev = ev.touches[0];
|
393
|
+
}
|
394
|
+
var percentage = (ev[this.mousePos] - this.offset[this.stylePos])*100/this.size;
|
395
|
+
percentage = Math.round(percentage/this.percentage[2])*this.percentage[2];
|
396
|
+
return Math.max(0, Math.min(100, percentage));
|
397
|
+
},
|
398
|
+
|
399
|
+
getValue: function() {
|
400
|
+
if (this.range) {
|
401
|
+
return this.value;
|
402
|
+
}
|
403
|
+
return this.value[0];
|
404
|
+
},
|
405
|
+
|
406
|
+
setValue: function(val) {
|
407
|
+
this.value = this.validateInputValue(val);
|
408
|
+
|
409
|
+
if (this.range) {
|
410
|
+
this.value[0] = Math.max(this.min, Math.min(this.max, this.value[0]));
|
411
|
+
this.value[1] = Math.max(this.min, Math.min(this.max, this.value[1]));
|
412
|
+
} else {
|
413
|
+
this.value = [ Math.max(this.min, Math.min(this.max, this.value))];
|
414
|
+
this.handle2.addClass('hide');
|
415
|
+
if (this.selection === 'after') {
|
416
|
+
this.value[1] = this.max;
|
417
|
+
} else {
|
418
|
+
this.value[1] = this.min;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
this.diff = this.max - this.min;
|
422
|
+
this.percentage = [
|
423
|
+
(this.value[0]-this.min)*100/this.diff,
|
424
|
+
(this.value[1]-this.min)*100/this.diff,
|
425
|
+
this.step*100/this.diff
|
426
|
+
];
|
427
|
+
this.layout();
|
428
|
+
},
|
429
|
+
|
430
|
+
validateInputValue : function(val) {
|
431
|
+
if(typeof val === 'number') {
|
432
|
+
return val;
|
433
|
+
} else if(val instanceof Array) {
|
434
|
+
val.forEach(function(input) { if (typeof input !== 'number') { throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(input) ); }});
|
435
|
+
return val;
|
436
|
+
} else {
|
437
|
+
throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(val) );
|
438
|
+
}
|
439
|
+
},
|
440
|
+
|
441
|
+
destroy: function(){
|
442
|
+
this.element.show().insertBefore(this.picker);
|
443
|
+
this.picker.remove();
|
444
|
+
$(this.element).removeData('slider');
|
445
|
+
$(this.element).off();
|
446
|
+
},
|
447
|
+
|
448
|
+
disable: function() {
|
449
|
+
this.enabled = false;
|
450
|
+
this.picker.addClass('slider-disabled');
|
451
|
+
this.element.trigger('slideDisabled');
|
452
|
+
},
|
453
|
+
|
454
|
+
enable: function() {
|
455
|
+
this.enabled = true;
|
456
|
+
this.picker.removeClass('slider-disabled');
|
457
|
+
this.element.trigger('slideEnabled');
|
458
|
+
},
|
459
|
+
|
460
|
+
toggle: function() {
|
461
|
+
if(this.enabled) {
|
462
|
+
this.disable();
|
463
|
+
} else {
|
464
|
+
this.enable();
|
465
|
+
}
|
466
|
+
},
|
467
|
+
|
468
|
+
isEnabled: function() {
|
469
|
+
return this.enabled;
|
470
|
+
}
|
471
|
+
};
|
472
|
+
|
473
|
+
var publicMethods = {
|
474
|
+
getValue : Slider.prototype.getValue,
|
475
|
+
setValue : Slider.prototype.setValue,
|
476
|
+
destroy : Slider.prototype.destroy,
|
477
|
+
disable : Slider.prototype.disable,
|
478
|
+
enable : Slider.prototype.enable,
|
479
|
+
toggle : Slider.prototype.toggle,
|
480
|
+
isEnabled: Slider.prototype.isEnabled
|
481
|
+
};
|
482
|
+
|
483
|
+
$.fn.slider = function (option) {
|
484
|
+
if (typeof option === 'string') {
|
485
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
486
|
+
return invokePublicMethod.call(this, option, args);
|
487
|
+
} else {
|
488
|
+
return createNewSliderInstance.call(this, option);
|
489
|
+
}
|
490
|
+
};
|
491
|
+
|
492
|
+
function invokePublicMethod(methodName, args) {
|
493
|
+
if(publicMethods[methodName]) {
|
494
|
+
var sliderObject = retrieveSliderObjectFromElement(this);
|
495
|
+
return publicMethods[methodName].apply(sliderObject, args);
|
496
|
+
} else {
|
497
|
+
throw new Error("method '" + methodName + "()' does not exist for slider.");
|
498
|
+
}
|
499
|
+
}
|
500
|
+
|
501
|
+
function retrieveSliderObjectFromElement(element) {
|
502
|
+
var sliderObject = $(element).data('slider');
|
503
|
+
if(sliderObject && sliderObject instanceof Slider) {
|
504
|
+
return sliderObject;
|
505
|
+
} else {
|
506
|
+
throw new Error(ErrorMsgs.callingContextNotSliderInstance);
|
507
|
+
}
|
508
|
+
}
|
509
|
+
|
510
|
+
function createNewSliderInstance(opts) {
|
511
|
+
var $this = $(this),
|
512
|
+
data = $this.data('slider'),
|
513
|
+
options = typeof opts === 'object' && opts;
|
514
|
+
if (!data) {
|
515
|
+
$this.data('slider', (data = new Slider(this, $.extend({}, $.fn.slider.defaults,options))));
|
516
|
+
}
|
517
|
+
return $this;
|
518
|
+
}
|
519
|
+
|
520
|
+
$.fn.slider.defaults = {
|
521
|
+
min: 0,
|
522
|
+
max: 10,
|
523
|
+
step: 1,
|
524
|
+
orientation: 'horizontal',
|
525
|
+
value: 5,
|
526
|
+
selection: 'before',
|
527
|
+
tooltip: 'show',
|
528
|
+
handle: 'round',
|
529
|
+
reversed : false,
|
530
|
+
enabled: true,
|
531
|
+
formater: function(value) {
|
532
|
+
return value;
|
533
|
+
}
|
534
|
+
};
|
535
|
+
|
536
|
+
$.fn.slider.Constructor = Slider;
|
537
|
+
|
538
|
+
})( window.jQuery );
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootstrap-slider-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pedr Browne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Make Bootstrap Slider available to Rails
|
63
|
+
email:
|
64
|
+
- pedr.browne@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bootstrap-slider-rails.gemspec
|
75
|
+
- lib/bootstrap-slider-rails.rb
|
76
|
+
- lib/bootstrap-slider-rails/version.rb
|
77
|
+
- vendor/assets/css/slider.css
|
78
|
+
- vendor/assets/javascripts/bootstrap-slider.js
|
79
|
+
homepage: http://github.com/stationkeeping/bootstrap-slider-rails
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.23
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: This Gem integrates Seiyara's fork of Bootstrap Slider with Rails, exposing
|
104
|
+
its JavaScript and CSS assets via a Rails Engine.
|
105
|
+
test_files: []
|