active_frontend 8.0.0 → 8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/active_frontend/version.rb +1 -1
- data/vendor/assets/javascripts/inputmask.js +339 -0
- data/vendor/assets/javascripts/slider.js +1478 -0
- data/vendor/assets/stylesheets/_datepicker.scss +10 -3
- data/vendor/assets/stylesheets/_dropdown.scss +39 -27
- data/vendor/assets/stylesheets/_form.scss +5 -0
- data/vendor/assets/stylesheets/_list.scss +1 -0
- data/vendor/assets/stylesheets/_slider.scss +151 -0
- data/vendor/assets/stylesheets/activefrontend.scss +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 696b9e32a78a0fa88311d85c73dd311894c37a4e
|
4
|
+
data.tar.gz: 93fd537ac023ae4f4424628a7acd6574b4a2abc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89d9cd1c90a402f4fdf02eda68960aac0ec6e52d22b28de06e526a1f4081fb16dc9be4dce9cdf70a4df3c23d95035993bc469decf8f99f63c4485eb4fa1cc8aa
|
7
|
+
data.tar.gz: bb95641a19c7a5ba770af159df68640aa7355c7fcb4088964def0e696aa36d4735504fb74459b463d46b8d4ec8ee6bda20887afb177e4740d6d8b564593b8c62
|
data/README.md
CHANGED
@@ -60,6 +60,7 @@ Add the CSS files you want to include:
|
|
60
60
|
*= require placeholder.css
|
61
61
|
*= require progress.css
|
62
62
|
*= require sidebar.css
|
63
|
+
*= require slider.css
|
63
64
|
*= require spinner.css
|
64
65
|
*= require swoggle.css
|
65
66
|
*= require table.css
|
@@ -87,10 +88,12 @@ Add the JS files you want to include:
|
|
87
88
|
//= require dropdown.js
|
88
89
|
//= require file_input.js
|
89
90
|
//= require hoverdown.js
|
91
|
+
//= require inputmask.js
|
90
92
|
//= require loader.js
|
91
93
|
//= require map.js
|
92
94
|
//= require modal.js
|
93
95
|
//= require scrollspy.js
|
96
|
+
//= require slider.js
|
94
97
|
//= require sort.js
|
95
98
|
//= require swoggle.js
|
96
99
|
//= require tab.js
|
@@ -0,0 +1,339 @@
|
|
1
|
+
+function ($) { "use strict";
|
2
|
+
|
3
|
+
var isIphone = (window.orientation !== undefined)
|
4
|
+
var isAndroid = navigator.userAgent.toLowerCase().indexOf("android") > -1
|
5
|
+
var isIE = window.navigator.appName == 'Microsoft Internet Explorer'
|
6
|
+
|
7
|
+
// INPUTMASK PUBLIC CLASS DEFINITION
|
8
|
+
// =================================
|
9
|
+
|
10
|
+
var Inputmask = function (element, options) {
|
11
|
+
if (isAndroid) return // No support because caret positioning doesn't work on Android
|
12
|
+
|
13
|
+
this.$element = $(element)
|
14
|
+
this.options = $.extend({}, Inputmask.DEFAULTS, options)
|
15
|
+
this.mask = String(this.options.mask)
|
16
|
+
|
17
|
+
this.init()
|
18
|
+
this.listen()
|
19
|
+
|
20
|
+
this.checkVal() //Perform initial check for existing values
|
21
|
+
}
|
22
|
+
|
23
|
+
Inputmask.DEFAULTS = {
|
24
|
+
mask: "",
|
25
|
+
placeholder: "_",
|
26
|
+
definitions: {
|
27
|
+
'9': "[0-9]",
|
28
|
+
'a': "[A-Za-z]",
|
29
|
+
'w': "[A-Za-z0-9]",
|
30
|
+
'*': "."
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
Inputmask.prototype.init = function() {
|
35
|
+
var defs = this.options.definitions
|
36
|
+
var len = this.mask.length
|
37
|
+
|
38
|
+
this.tests = []
|
39
|
+
this.partialPosition = this.mask.length
|
40
|
+
this.firstNonMaskPos = null
|
41
|
+
|
42
|
+
$.each(this.mask.split(""), $.proxy(function(i, c) {
|
43
|
+
if (c == '?') {
|
44
|
+
len--
|
45
|
+
this.partialPosition = i
|
46
|
+
} else if (defs[c]) {
|
47
|
+
this.tests.push(new RegExp(defs[c]))
|
48
|
+
if (this.firstNonMaskPos === null)
|
49
|
+
this.firstNonMaskPos = this.tests.length - 1
|
50
|
+
} else {
|
51
|
+
this.tests.push(null)
|
52
|
+
}
|
53
|
+
}, this))
|
54
|
+
|
55
|
+
this.buffer = $.map(this.mask.split(""), $.proxy(function(c, i) {
|
56
|
+
if (c != '?') return defs[c] ? this.options.placeholder : c
|
57
|
+
}, this))
|
58
|
+
|
59
|
+
this.focusText = this.$element.val()
|
60
|
+
|
61
|
+
this.$element.data("rawMaskFn", $.proxy(function() {
|
62
|
+
return $.map(this.buffer, function(c, i) {
|
63
|
+
return this.tests[i] && c != this.options.placeholder ? c : null
|
64
|
+
}).join('')
|
65
|
+
}, this))
|
66
|
+
}
|
67
|
+
|
68
|
+
Inputmask.prototype.listen = function() {
|
69
|
+
if (this.$element.attr("readonly")) return
|
70
|
+
|
71
|
+
var pasteEventName = (isIE ? 'paste' : 'input') + ".mask"
|
72
|
+
|
73
|
+
this.$element
|
74
|
+
.on("unmask.bs.inputmask", $.proxy(this.unmask, this))
|
75
|
+
|
76
|
+
.on("focus.bs.inputmask", $.proxy(this.focusEvent, this))
|
77
|
+
.on("blur.bs.inputmask", $.proxy(this.blurEvent, this))
|
78
|
+
|
79
|
+
.on("keydown.bs.inputmask", $.proxy(this.keydownEvent, this))
|
80
|
+
.on("keypress.bs.inputmask", $.proxy(this.keypressEvent, this))
|
81
|
+
|
82
|
+
.on(pasteEventName, $.proxy(this.pasteEvent, this))
|
83
|
+
}
|
84
|
+
|
85
|
+
//Helper Function for Caret positioning
|
86
|
+
Inputmask.prototype.caret = function(begin, end) {
|
87
|
+
if (this.$element.length === 0) return
|
88
|
+
if (typeof begin == 'number') {
|
89
|
+
end = (typeof end == 'number') ? end : begin
|
90
|
+
return this.$element.each(function() {
|
91
|
+
if (this.setSelectionRange) {
|
92
|
+
this.setSelectionRange(begin, end)
|
93
|
+
} else if (this.createTextRange) {
|
94
|
+
var range = this.createTextRange()
|
95
|
+
range.collapse(true)
|
96
|
+
range.moveEnd('character', end)
|
97
|
+
range.moveStart('character', begin)
|
98
|
+
range.select()
|
99
|
+
}
|
100
|
+
})
|
101
|
+
} else {
|
102
|
+
if (this.$element[0].setSelectionRange) {
|
103
|
+
begin = this.$element[0].selectionStart
|
104
|
+
end = this.$element[0].selectionEnd
|
105
|
+
} else if (document.selection && document.selection.createRange) {
|
106
|
+
var range = document.selection.createRange()
|
107
|
+
begin = 0 - range.duplicate().moveStart('character', -100000)
|
108
|
+
end = begin + range.text.length
|
109
|
+
}
|
110
|
+
return {
|
111
|
+
begin: begin,
|
112
|
+
end: end
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
Inputmask.prototype.seekNext = function(pos) {
|
118
|
+
var len = this.mask.length
|
119
|
+
while (++pos <= len && !this.tests[pos]);
|
120
|
+
|
121
|
+
return pos
|
122
|
+
}
|
123
|
+
|
124
|
+
Inputmask.prototype.seekPrev = function(pos) {
|
125
|
+
while (--pos >= 0 && !this.tests[pos]);
|
126
|
+
|
127
|
+
return pos
|
128
|
+
}
|
129
|
+
|
130
|
+
Inputmask.prototype.shiftL = function(begin,end) {
|
131
|
+
var len = this.mask.length
|
132
|
+
|
133
|
+
if (begin < 0) return
|
134
|
+
|
135
|
+
for (var i = begin, j = this.seekNext(end); i < len; i++) {
|
136
|
+
if (this.tests[i]) {
|
137
|
+
if (j < len && this.tests[i].test(this.buffer[j])) {
|
138
|
+
this.buffer[i] = this.buffer[j]
|
139
|
+
this.buffer[j] = this.options.placeholder
|
140
|
+
} else
|
141
|
+
break
|
142
|
+
j = this.seekNext(j)
|
143
|
+
}
|
144
|
+
}
|
145
|
+
this.writeBuffer()
|
146
|
+
this.caret(Math.max(this.firstNonMaskPos, begin))
|
147
|
+
}
|
148
|
+
|
149
|
+
Inputmask.prototype.shiftR = function(pos) {
|
150
|
+
var len = this.mask.length
|
151
|
+
|
152
|
+
for (var i = pos, c = this.options.placeholder; i < len; i++) {
|
153
|
+
if (this.tests[i]) {
|
154
|
+
var j = this.seekNext(i)
|
155
|
+
var t = this.buffer[i]
|
156
|
+
this.buffer[i] = c
|
157
|
+
if (j < len && this.tests[j].test(t))
|
158
|
+
c = t
|
159
|
+
else
|
160
|
+
break
|
161
|
+
}
|
162
|
+
}
|
163
|
+
},
|
164
|
+
|
165
|
+
Inputmask.prototype.unmask = function() {
|
166
|
+
this.$element
|
167
|
+
.unbind(".mask")
|
168
|
+
.removeData("inputmask")
|
169
|
+
}
|
170
|
+
|
171
|
+
Inputmask.prototype.focusEvent = function() {
|
172
|
+
this.focusText = this.$element.val()
|
173
|
+
var len = this.mask.length
|
174
|
+
var pos = this.checkVal()
|
175
|
+
this.writeBuffer()
|
176
|
+
|
177
|
+
var that = this
|
178
|
+
var moveCaret = function() {
|
179
|
+
if (pos == len)
|
180
|
+
that.caret(0, pos)
|
181
|
+
else
|
182
|
+
that.caret(pos)
|
183
|
+
}
|
184
|
+
|
185
|
+
moveCaret()
|
186
|
+
setTimeout(moveCaret, 50)
|
187
|
+
}
|
188
|
+
|
189
|
+
Inputmask.prototype.blurEvent = function() {
|
190
|
+
this.checkVal()
|
191
|
+
if (this.$element.val() !== this.focusText)
|
192
|
+
this.$element.trigger('change')
|
193
|
+
}
|
194
|
+
|
195
|
+
Inputmask.prototype.keydownEvent = function(e) {
|
196
|
+
var k = e.which
|
197
|
+
|
198
|
+
//backspace, delete, and escape get special treatment
|
199
|
+
if (k == 8 || k == 46 || (isIphone && k == 127)) {
|
200
|
+
var pos = this.caret(),
|
201
|
+
begin = pos.begin,
|
202
|
+
end = pos.end
|
203
|
+
|
204
|
+
if (end - begin === 0) {
|
205
|
+
begin = k != 46 ? this.seekPrev(begin) : (end = this.seekNext(begin - 1))
|
206
|
+
end = k == 46 ? this.seekNext(end) : end
|
207
|
+
}
|
208
|
+
this.clearBuffer(begin, end)
|
209
|
+
this.shiftL(begin, end - 1)
|
210
|
+
|
211
|
+
return false
|
212
|
+
} else if (k == 27) {//escape
|
213
|
+
this.$element.val(this.focusText)
|
214
|
+
this.caret(0, this.checkVal())
|
215
|
+
return false
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
Inputmask.prototype.keypressEvent = function(e) {
|
220
|
+
var len = this.mask.length
|
221
|
+
|
222
|
+
var k = e.which,
|
223
|
+
pos = this.caret()
|
224
|
+
|
225
|
+
if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore
|
226
|
+
return true
|
227
|
+
} else if (k) {
|
228
|
+
if (pos.end - pos.begin !== 0) {
|
229
|
+
this.clearBuffer(pos.begin, pos.end)
|
230
|
+
this.shiftL(pos.begin, pos.end - 1)
|
231
|
+
}
|
232
|
+
|
233
|
+
var p = this.seekNext(pos.begin - 1)
|
234
|
+
if (p < len) {
|
235
|
+
var c = String.fromCharCode(k)
|
236
|
+
if (this.tests[p].test(c)) {
|
237
|
+
this.shiftR(p)
|
238
|
+
this.buffer[p] = c
|
239
|
+
this.writeBuffer()
|
240
|
+
var next = this.seekNext(p)
|
241
|
+
this.caret(next)
|
242
|
+
}
|
243
|
+
}
|
244
|
+
return false
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
Inputmask.prototype.pasteEvent = function() {
|
249
|
+
var that = this
|
250
|
+
|
251
|
+
setTimeout(function() {
|
252
|
+
that.caret(that.checkVal(true))
|
253
|
+
}, 0)
|
254
|
+
}
|
255
|
+
|
256
|
+
Inputmask.prototype.clearBuffer = function(start, end) {
|
257
|
+
var len = this.mask.length
|
258
|
+
|
259
|
+
for (var i = start; i < end && i < len; i++) {
|
260
|
+
if (this.tests[i])
|
261
|
+
this.buffer[i] = this.options.placeholder
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
Inputmask.prototype.writeBuffer = function() {
|
266
|
+
return this.$element.val(this.buffer.join('')).val()
|
267
|
+
}
|
268
|
+
|
269
|
+
Inputmask.prototype.checkVal = function(allow) {
|
270
|
+
var len = this.mask.length
|
271
|
+
//try to place characters where they belong
|
272
|
+
var test = this.$element.val()
|
273
|
+
var lastMatch = -1
|
274
|
+
|
275
|
+
for (var i = 0, pos = 0; i < len; i++) {
|
276
|
+
if (this.tests[i]) {
|
277
|
+
this.buffer[i] = this.options.placeholder
|
278
|
+
while (pos++ < test.length) {
|
279
|
+
var c = test.charAt(pos - 1)
|
280
|
+
if (this.tests[i].test(c)) {
|
281
|
+
this.buffer[i] = c
|
282
|
+
lastMatch = i
|
283
|
+
break
|
284
|
+
}
|
285
|
+
}
|
286
|
+
if (pos > test.length)
|
287
|
+
break
|
288
|
+
} else if (this.buffer[i] == test.charAt(pos) && i != this.partialPosition) {
|
289
|
+
pos++
|
290
|
+
lastMatch = i
|
291
|
+
}
|
292
|
+
}
|
293
|
+
if (!allow && lastMatch + 1 < this.partialPosition) {
|
294
|
+
this.$element.val("")
|
295
|
+
this.clearBuffer(0, len)
|
296
|
+
} else if (allow || lastMatch + 1 >= this.partialPosition) {
|
297
|
+
this.writeBuffer()
|
298
|
+
if (!allow) this.$element.val(this.$element.val().substring(0, lastMatch + 1))
|
299
|
+
}
|
300
|
+
return (this.partialPosition ? i : this.firstNonMaskPos)
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
// INPUTMASK PLUGIN DEFINITION
|
305
|
+
// ===========================
|
306
|
+
|
307
|
+
var old = $.fn.inputmask
|
308
|
+
|
309
|
+
$.fn.inputmask = function (options) {
|
310
|
+
return this.each(function () {
|
311
|
+
var $this = $(this)
|
312
|
+
var data = $this.data('bs.inputmask')
|
313
|
+
|
314
|
+
if (!data) $this.data('bs.inputmask', (data = new Inputmask(this, options)))
|
315
|
+
})
|
316
|
+
}
|
317
|
+
|
318
|
+
$.fn.inputmask.Constructor = Inputmask
|
319
|
+
|
320
|
+
|
321
|
+
// INPUTMASK NO CONFLICT
|
322
|
+
// ====================
|
323
|
+
|
324
|
+
$.fn.inputmask.noConflict = function () {
|
325
|
+
$.fn.inputmask = old
|
326
|
+
return this
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
// INPUTMASK DATA-API
|
331
|
+
// ==================
|
332
|
+
|
333
|
+
$(document).on('focus.bs.inputmask.data-api', '[data-mask]', function (e) {
|
334
|
+
var $this = $(this)
|
335
|
+
if ($this.data('bs.inputmask')) return
|
336
|
+
$this.inputmask($this.data())
|
337
|
+
})
|
338
|
+
|
339
|
+
}(window.jQuery);
|
@@ -0,0 +1,1478 @@
|
|
1
|
+
(function(root, factory) {
|
2
|
+
if(typeof define === "function" && define.amd) {
|
3
|
+
define(["jquery"], factory);
|
4
|
+
}
|
5
|
+
else if(typeof module === "object" && module.exports) {
|
6
|
+
var jQuery;
|
7
|
+
try {
|
8
|
+
jQuery = require("jquery");
|
9
|
+
}
|
10
|
+
catch (err) {
|
11
|
+
jQuery = null;
|
12
|
+
}
|
13
|
+
module.exports = factory(jQuery);
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
root.Slider = factory(root.jQuery);
|
17
|
+
}
|
18
|
+
}(this, function($) {
|
19
|
+
// Reference to Slider constructor
|
20
|
+
var Slider;
|
21
|
+
|
22
|
+
|
23
|
+
(function( $ ) {
|
24
|
+
|
25
|
+
'use strict';
|
26
|
+
|
27
|
+
// -------------------------- utils -------------------------- //
|
28
|
+
|
29
|
+
var slice = Array.prototype.slice;
|
30
|
+
|
31
|
+
function noop() {}
|
32
|
+
|
33
|
+
// -------------------------- definition -------------------------- //
|
34
|
+
|
35
|
+
function defineBridget( $ ) {
|
36
|
+
|
37
|
+
// bail if no jQuery
|
38
|
+
if ( !$ ) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
// -------------------------- addOptionMethod -------------------------- //
|
43
|
+
|
44
|
+
/**
|
45
|
+
* adds option method -> $().plugin('option', {...})
|
46
|
+
* @param {Function} PluginClass - constructor class
|
47
|
+
*/
|
48
|
+
function addOptionMethod( PluginClass ) {
|
49
|
+
// don't overwrite original option method
|
50
|
+
if ( PluginClass.prototype.option ) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
// option setter
|
55
|
+
PluginClass.prototype.option = function( opts ) {
|
56
|
+
// bail out if not an object
|
57
|
+
if ( !$.isPlainObject( opts ) ){
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
this.options = $.extend( true, this.options, opts );
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
// -------------------------- plugin bridge -------------------------- //
|
66
|
+
|
67
|
+
// helper function for logging errors
|
68
|
+
// $.error breaks jQuery chaining
|
69
|
+
var logError = typeof console === 'undefined' ? noop :
|
70
|
+
function( message ) {
|
71
|
+
console.error( message );
|
72
|
+
};
|
73
|
+
|
74
|
+
/**
|
75
|
+
* jQuery plugin bridge, access methods like $elem.plugin('method')
|
76
|
+
* @param {String} namespace - plugin name
|
77
|
+
* @param {Function} PluginClass - constructor class
|
78
|
+
*/
|
79
|
+
function bridge( namespace, PluginClass ) {
|
80
|
+
// add to jQuery fn namespace
|
81
|
+
$.fn[ namespace ] = function( options ) {
|
82
|
+
if ( typeof options === 'string' ) {
|
83
|
+
// call plugin method when first argument is a string
|
84
|
+
// get arguments for method
|
85
|
+
var args = slice.call( arguments, 1 );
|
86
|
+
|
87
|
+
for ( var i=0, len = this.length; i < len; i++ ) {
|
88
|
+
var elem = this[i];
|
89
|
+
var instance = $.data( elem, namespace );
|
90
|
+
if ( !instance ) {
|
91
|
+
logError( "cannot call methods on " + namespace + " prior to initialization; " +
|
92
|
+
"attempted to call '" + options + "'" );
|
93
|
+
continue;
|
94
|
+
}
|
95
|
+
if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) {
|
96
|
+
logError( "no such method '" + options + "' for " + namespace + " instance" );
|
97
|
+
continue;
|
98
|
+
}
|
99
|
+
|
100
|
+
// trigger method with arguments
|
101
|
+
var returnValue = instance[ options ].apply( instance, args);
|
102
|
+
|
103
|
+
// break look and return first value if provided
|
104
|
+
if ( returnValue !== undefined && returnValue !== instance) {
|
105
|
+
return returnValue;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
// return this if no return value
|
109
|
+
return this;
|
110
|
+
} else {
|
111
|
+
var objects = this.map( function() {
|
112
|
+
var instance = $.data( this, namespace );
|
113
|
+
if ( instance ) {
|
114
|
+
// apply options & init
|
115
|
+
instance.option( options );
|
116
|
+
instance._init();
|
117
|
+
} else {
|
118
|
+
// initialize new instance
|
119
|
+
instance = new PluginClass( this, options );
|
120
|
+
$.data( this, namespace, instance );
|
121
|
+
}
|
122
|
+
return $(this);
|
123
|
+
});
|
124
|
+
|
125
|
+
if(!objects || objects.length > 1) {
|
126
|
+
return objects;
|
127
|
+
} else {
|
128
|
+
return objects[0];
|
129
|
+
}
|
130
|
+
}
|
131
|
+
};
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
// -------------------------- bridget -------------------------- //
|
136
|
+
|
137
|
+
/**
|
138
|
+
* converts a Prototypical class into a proper jQuery plugin
|
139
|
+
* the class must have a ._init method
|
140
|
+
* @param {String} namespace - plugin name, used in $().pluginName
|
141
|
+
* @param {Function} PluginClass - constructor class
|
142
|
+
*/
|
143
|
+
$.bridget = function( namespace, PluginClass ) {
|
144
|
+
addOptionMethod( PluginClass );
|
145
|
+
bridge( namespace, PluginClass );
|
146
|
+
};
|
147
|
+
|
148
|
+
return $.bridget;
|
149
|
+
|
150
|
+
}
|
151
|
+
|
152
|
+
// get jquery from browser global
|
153
|
+
defineBridget( $ );
|
154
|
+
|
155
|
+
})( $ );
|
156
|
+
|
157
|
+
|
158
|
+
/*************************************************
|
159
|
+
|
160
|
+
BOOTSTRAP-SLIDER SOURCE CODE
|
161
|
+
|
162
|
+
**************************************************/
|
163
|
+
|
164
|
+
(function($) {
|
165
|
+
|
166
|
+
var ErrorMsgs = {
|
167
|
+
formatInvalidInputErrorMsg : function(input) {
|
168
|
+
return "Invalid input value '" + input + "' passed in";
|
169
|
+
},
|
170
|
+
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"
|
171
|
+
};
|
172
|
+
|
173
|
+
var SliderScale = {
|
174
|
+
linear: {
|
175
|
+
toValue: function(percentage) {
|
176
|
+
var rawValue = percentage/100 * (this.options.max - this.options.min);
|
177
|
+
if (this.options.ticks_positions.length > 0) {
|
178
|
+
var minv, maxv, minp, maxp = 0;
|
179
|
+
for (var i = 0; i < this.options.ticks_positions.length; i++) {
|
180
|
+
if (percentage <= this.options.ticks_positions[i]) {
|
181
|
+
minv = (i > 0) ? this.options.ticks[i-1] : 0;
|
182
|
+
minp = (i > 0) ? this.options.ticks_positions[i-1] : 0;
|
183
|
+
maxv = this.options.ticks[i];
|
184
|
+
maxp = this.options.ticks_positions[i];
|
185
|
+
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
if (i > 0) {
|
190
|
+
var partialPercentage = (percentage - minp) / (maxp - minp);
|
191
|
+
rawValue = minv + partialPercentage * (maxv - minv);
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
var value = this.options.min + Math.round(rawValue / this.options.step) * this.options.step;
|
196
|
+
if (value < this.options.min) {
|
197
|
+
return this.options.min;
|
198
|
+
} else if (value > this.options.max) {
|
199
|
+
return this.options.max;
|
200
|
+
} else {
|
201
|
+
return value;
|
202
|
+
}
|
203
|
+
},
|
204
|
+
toPercentage: function(value) {
|
205
|
+
if (this.options.max === this.options.min) {
|
206
|
+
return 0;
|
207
|
+
}
|
208
|
+
|
209
|
+
if (this.options.ticks_positions.length > 0) {
|
210
|
+
var minv, maxv, minp, maxp = 0;
|
211
|
+
for (var i = 0; i < this.options.ticks.length; i++) {
|
212
|
+
if (value <= this.options.ticks[i]) {
|
213
|
+
minv = (i > 0) ? this.options.ticks[i-1] : 0;
|
214
|
+
minp = (i > 0) ? this.options.ticks_positions[i-1] : 0;
|
215
|
+
maxv = this.options.ticks[i];
|
216
|
+
maxp = this.options.ticks_positions[i];
|
217
|
+
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
if (i > 0) {
|
222
|
+
var partialPercentage = (value - minv) / (maxv - minv);
|
223
|
+
return minp + partialPercentage * (maxp - minp);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
return 100 * (value - this.options.min) / (this.options.max - this.options.min);
|
228
|
+
}
|
229
|
+
},
|
230
|
+
|
231
|
+
logarithmic: {
|
232
|
+
/* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
|
233
|
+
toValue: function(percentage) {
|
234
|
+
var min = (this.options.min === 0) ? 0 : Math.log(this.options.min);
|
235
|
+
var max = Math.log(this.options.max);
|
236
|
+
var value = Math.exp(min + (max - min) * percentage / 100);
|
237
|
+
value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
|
238
|
+
/* Rounding to the nearest step could exceed the min or
|
239
|
+
* max, so clip to those values. */
|
240
|
+
if (value < this.options.min) {
|
241
|
+
return this.options.min;
|
242
|
+
} else if (value > this.options.max) {
|
243
|
+
return this.options.max;
|
244
|
+
} else {
|
245
|
+
return value;
|
246
|
+
}
|
247
|
+
},
|
248
|
+
toPercentage: function(value) {
|
249
|
+
if (this.options.max === this.options.min) {
|
250
|
+
return 0;
|
251
|
+
} else {
|
252
|
+
var max = Math.log(this.options.max);
|
253
|
+
var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
|
254
|
+
var v = value === 0 ? 0 : Math.log(value);
|
255
|
+
return 100 * (v - min) / (max - min);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}
|
259
|
+
};
|
260
|
+
|
261
|
+
|
262
|
+
/*************************************************
|
263
|
+
|
264
|
+
CONSTRUCTOR
|
265
|
+
|
266
|
+
**************************************************/
|
267
|
+
Slider = function(element, options) {
|
268
|
+
createNewSlider.call(this, element, options);
|
269
|
+
return this;
|
270
|
+
};
|
271
|
+
|
272
|
+
function createNewSlider(element, options) {
|
273
|
+
|
274
|
+
if(typeof element === "string") {
|
275
|
+
this.element = document.querySelector(element);
|
276
|
+
} else if(element instanceof HTMLElement) {
|
277
|
+
this.element = element;
|
278
|
+
}
|
279
|
+
|
280
|
+
/*************************************************
|
281
|
+
|
282
|
+
Process Options
|
283
|
+
|
284
|
+
**************************************************/
|
285
|
+
options = options ? options : {};
|
286
|
+
var optionTypes = Object.keys(this.defaultOptions);
|
287
|
+
|
288
|
+
for(var i = 0; i < optionTypes.length; i++) {
|
289
|
+
var optName = optionTypes[i];
|
290
|
+
|
291
|
+
// First check if an option was passed in via the constructor
|
292
|
+
var val = options[optName];
|
293
|
+
// If no data attrib, then check data atrributes
|
294
|
+
val = (typeof val !== 'undefined') ? val : getDataAttrib(this.element, optName);
|
295
|
+
// Finally, if nothing was specified, use the defaults
|
296
|
+
val = (val !== null) ? val : this.defaultOptions[optName];
|
297
|
+
|
298
|
+
// Set all options on the instance of the Slider
|
299
|
+
if(!this.options) {
|
300
|
+
this.options = {};
|
301
|
+
}
|
302
|
+
this.options[optName] = val;
|
303
|
+
}
|
304
|
+
|
305
|
+
/*
|
306
|
+
Validate `tooltip_position` against 'orientation`
|
307
|
+
- if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
|
308
|
+
-- default for "vertical" -> "right"
|
309
|
+
-- default for "horizontal" -> "left"
|
310
|
+
*/
|
311
|
+
if(this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
|
312
|
+
|
313
|
+
this.options.tooltip_position = "right";
|
314
|
+
|
315
|
+
}
|
316
|
+
else if(this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
|
317
|
+
|
318
|
+
this.options.tooltip_position = "top";
|
319
|
+
|
320
|
+
}
|
321
|
+
|
322
|
+
function getDataAttrib(element, optName) {
|
323
|
+
var dataName = "data-slider-" + optName.replace(/_/g, '-');
|
324
|
+
var dataValString = element.getAttribute(dataName);
|
325
|
+
|
326
|
+
try {
|
327
|
+
return JSON.parse(dataValString);
|
328
|
+
}
|
329
|
+
catch(err) {
|
330
|
+
return dataValString;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
/*************************************************
|
335
|
+
|
336
|
+
Create Markup
|
337
|
+
|
338
|
+
**************************************************/
|
339
|
+
|
340
|
+
var origWidth = this.element.style.width;
|
341
|
+
var updateSlider = false;
|
342
|
+
var parent = this.element.parentNode;
|
343
|
+
var sliderTrackSelection;
|
344
|
+
var sliderTrackLow, sliderTrackHigh;
|
345
|
+
var sliderMinHandle;
|
346
|
+
var sliderMaxHandle;
|
347
|
+
|
348
|
+
if (this.sliderElem) {
|
349
|
+
updateSlider = true;
|
350
|
+
} else {
|
351
|
+
/* Create elements needed for slider */
|
352
|
+
this.sliderElem = document.createElement("div");
|
353
|
+
this.sliderElem.className = "slider";
|
354
|
+
|
355
|
+
/* Create slider track elements */
|
356
|
+
var sliderTrack = document.createElement("div");
|
357
|
+
sliderTrack.className = "slider-track";
|
358
|
+
|
359
|
+
sliderTrackLow = document.createElement("div");
|
360
|
+
sliderTrackLow.className = "slider-track-low";
|
361
|
+
|
362
|
+
sliderTrackSelection = document.createElement("div");
|
363
|
+
sliderTrackSelection.className = "slider-selection";
|
364
|
+
|
365
|
+
sliderTrackHigh = document.createElement("div");
|
366
|
+
sliderTrackHigh.className = "slider-track-high";
|
367
|
+
|
368
|
+
sliderMinHandle = document.createElement("div");
|
369
|
+
sliderMinHandle.className = "slider-handle min-slider-handle";
|
370
|
+
|
371
|
+
sliderMaxHandle = document.createElement("div");
|
372
|
+
sliderMaxHandle.className = "slider-handle max-slider-handle";
|
373
|
+
|
374
|
+
sliderTrack.appendChild(sliderTrackLow);
|
375
|
+
sliderTrack.appendChild(sliderTrackSelection);
|
376
|
+
sliderTrack.appendChild(sliderTrackHigh);
|
377
|
+
|
378
|
+
/* Create ticks */
|
379
|
+
this.ticks = [];
|
380
|
+
if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
|
381
|
+
for (i = 0; i < this.options.ticks.length; i++) {
|
382
|
+
var tick = document.createElement('div');
|
383
|
+
tick.className = 'slider-tick';
|
384
|
+
|
385
|
+
this.ticks.push(tick);
|
386
|
+
sliderTrack.appendChild(tick);
|
387
|
+
}
|
388
|
+
|
389
|
+
sliderTrackSelection.className += " tick-slider-selection";
|
390
|
+
}
|
391
|
+
|
392
|
+
sliderTrack.appendChild(sliderMinHandle);
|
393
|
+
sliderTrack.appendChild(sliderMaxHandle);
|
394
|
+
|
395
|
+
this.tickLabels = [];
|
396
|
+
if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
|
397
|
+
this.tickLabelContainer = document.createElement('div');
|
398
|
+
this.tickLabelContainer.className = 'slider-tick-label-container';
|
399
|
+
|
400
|
+
for (i = 0; i < this.options.ticks_labels.length; i++) {
|
401
|
+
var label = document.createElement('div');
|
402
|
+
label.className = 'slider-tick-label';
|
403
|
+
label.innerHTML = this.options.ticks_labels[i];
|
404
|
+
|
405
|
+
this.tickLabels.push(label);
|
406
|
+
this.tickLabelContainer.appendChild(label);
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
410
|
+
|
411
|
+
var createAndAppendTooltipSubElements = function(tooltipElem) {
|
412
|
+
var arrow = document.createElement("div");
|
413
|
+
arrow.className = "tooltip-arrow";
|
414
|
+
|
415
|
+
var inner = document.createElement("div");
|
416
|
+
inner.className = "tooltip-inner";
|
417
|
+
|
418
|
+
tooltipElem.appendChild(arrow);
|
419
|
+
tooltipElem.appendChild(inner);
|
420
|
+
|
421
|
+
};
|
422
|
+
|
423
|
+
/* Create tooltip elements */
|
424
|
+
var sliderTooltip = document.createElement("div");
|
425
|
+
sliderTooltip.className = "tooltip tooltip-main";
|
426
|
+
createAndAppendTooltipSubElements(sliderTooltip);
|
427
|
+
|
428
|
+
var sliderTooltipMin = document.createElement("div");
|
429
|
+
sliderTooltipMin.className = "tooltip tooltip-min";
|
430
|
+
createAndAppendTooltipSubElements(sliderTooltipMin);
|
431
|
+
|
432
|
+
var sliderTooltipMax = document.createElement("div");
|
433
|
+
sliderTooltipMax.className = "tooltip tooltip-max";
|
434
|
+
createAndAppendTooltipSubElements(sliderTooltipMax);
|
435
|
+
|
436
|
+
|
437
|
+
/* Append components to sliderElem */
|
438
|
+
this.sliderElem.appendChild(sliderTrack);
|
439
|
+
this.sliderElem.appendChild(sliderTooltip);
|
440
|
+
this.sliderElem.appendChild(sliderTooltipMin);
|
441
|
+
this.sliderElem.appendChild(sliderTooltipMax);
|
442
|
+
|
443
|
+
if (this.tickLabelContainer) {
|
444
|
+
this.sliderElem.appendChild(this.tickLabelContainer);
|
445
|
+
}
|
446
|
+
|
447
|
+
/* Append slider element to parent container, right before the original <input> element */
|
448
|
+
parent.insertBefore(this.sliderElem, this.element);
|
449
|
+
|
450
|
+
/* Hide original <input> element */
|
451
|
+
this.element.style.display = "none";
|
452
|
+
}
|
453
|
+
/* If JQuery exists, cache JQ references */
|
454
|
+
if($) {
|
455
|
+
this.$element = $(this.element);
|
456
|
+
this.$sliderElem = $(this.sliderElem);
|
457
|
+
}
|
458
|
+
|
459
|
+
/*************************************************
|
460
|
+
|
461
|
+
Setup
|
462
|
+
|
463
|
+
**************************************************/
|
464
|
+
this.eventToCallbackMap = {};
|
465
|
+
this.sliderElem.id = this.options.id;
|
466
|
+
|
467
|
+
this.touchCapable = 'ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch);
|
468
|
+
|
469
|
+
this.tooltip = this.sliderElem.querySelector('.tooltip-main');
|
470
|
+
this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
|
471
|
+
|
472
|
+
this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
|
473
|
+
this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
|
474
|
+
|
475
|
+
this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
|
476
|
+
this.tooltipInner_max= this.tooltip_max.querySelector('.tooltip-inner');
|
477
|
+
|
478
|
+
if (SliderScale[this.options.scale]) {
|
479
|
+
this.options.scale = SliderScale[this.options.scale];
|
480
|
+
}
|
481
|
+
|
482
|
+
if (updateSlider === true) {
|
483
|
+
// Reset classes
|
484
|
+
this._removeClass(this.sliderElem, 'slider-horizontal');
|
485
|
+
this._removeClass(this.sliderElem, 'slider-vertical');
|
486
|
+
this._removeClass(this.tooltip, 'hide');
|
487
|
+
this._removeClass(this.tooltip_min, 'hide');
|
488
|
+
this._removeClass(this.tooltip_max, 'hide');
|
489
|
+
|
490
|
+
// Undo existing inline styles for track
|
491
|
+
["left", "top", "width", "height"].forEach(function(prop) {
|
492
|
+
this._removeProperty(this.trackLow, prop);
|
493
|
+
this._removeProperty(this.trackSelection, prop);
|
494
|
+
this._removeProperty(this.trackHigh, prop);
|
495
|
+
}, this);
|
496
|
+
|
497
|
+
// Undo inline styles on handles
|
498
|
+
[this.handle1, this.handle2].forEach(function(handle) {
|
499
|
+
this._removeProperty(handle, 'left');
|
500
|
+
this._removeProperty(handle, 'top');
|
501
|
+
}, this);
|
502
|
+
|
503
|
+
// Undo inline styles and classes on tooltips
|
504
|
+
[this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function(tooltip) {
|
505
|
+
this._removeProperty(tooltip, 'left');
|
506
|
+
this._removeProperty(tooltip, 'top');
|
507
|
+
this._removeProperty(tooltip, 'margin-left');
|
508
|
+
this._removeProperty(tooltip, 'margin-top');
|
509
|
+
|
510
|
+
this._removeClass(tooltip, 'right');
|
511
|
+
this._removeClass(tooltip, 'top');
|
512
|
+
}, this);
|
513
|
+
}
|
514
|
+
|
515
|
+
if(this.options.orientation === 'vertical') {
|
516
|
+
this._addClass(this.sliderElem,'slider-vertical');
|
517
|
+
this.stylePos = 'top';
|
518
|
+
this.mousePos = 'pageY';
|
519
|
+
this.sizePos = 'offsetHeight';
|
520
|
+
} else {
|
521
|
+
this._addClass(this.sliderElem, 'slider-horizontal');
|
522
|
+
this.sliderElem.style.width = origWidth;
|
523
|
+
this.options.orientation = 'horizontal';
|
524
|
+
this.stylePos = 'left';
|
525
|
+
this.mousePos = 'pageX';
|
526
|
+
this.sizePos = 'offsetWidth';
|
527
|
+
|
528
|
+
}
|
529
|
+
this._setTooltipPosition();
|
530
|
+
/* In case ticks are specified, overwrite the min and max bounds */
|
531
|
+
if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
|
532
|
+
this.options.max = Math.max.apply(Math, this.options.ticks);
|
533
|
+
this.options.min = Math.min.apply(Math, this.options.ticks);
|
534
|
+
}
|
535
|
+
|
536
|
+
if (Array.isArray(this.options.value)) {
|
537
|
+
this.options.range = true;
|
538
|
+
} else if (this.options.range) {
|
539
|
+
// User wants a range, but value is not an array
|
540
|
+
this.options.value = [this.options.value, this.options.max];
|
541
|
+
}
|
542
|
+
|
543
|
+
this.trackLow = sliderTrackLow || this.trackLow;
|
544
|
+
this.trackSelection = sliderTrackSelection || this.trackSelection;
|
545
|
+
this.trackHigh = sliderTrackHigh || this.trackHigh;
|
546
|
+
|
547
|
+
if (this.options.selection === 'none') {
|
548
|
+
this._addClass(this.trackLow, 'hide');
|
549
|
+
this._addClass(this.trackSelection, 'hide');
|
550
|
+
this._addClass(this.trackHigh, 'hide');
|
551
|
+
}
|
552
|
+
|
553
|
+
this.handle1 = sliderMinHandle || this.handle1;
|
554
|
+
this.handle2 = sliderMaxHandle || this.handle2;
|
555
|
+
|
556
|
+
if (updateSlider === true) {
|
557
|
+
// Reset classes
|
558
|
+
this._removeClass(this.handle1, 'round triangle');
|
559
|
+
this._removeClass(this.handle2, 'round triangle hide');
|
560
|
+
|
561
|
+
for (i = 0; i < this.ticks.length; i++) {
|
562
|
+
this._removeClass(this.ticks[i], 'round triangle hide');
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
var availableHandleModifiers = ['round', 'triangle', 'custom'];
|
567
|
+
var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
|
568
|
+
if (isValidHandleType) {
|
569
|
+
this._addClass(this.handle1, this.options.handle);
|
570
|
+
this._addClass(this.handle2, this.options.handle);
|
571
|
+
|
572
|
+
for (i = 0; i < this.ticks.length; i++) {
|
573
|
+
this._addClass(this.ticks[i], this.options.handle);
|
574
|
+
}
|
575
|
+
}
|
576
|
+
|
577
|
+
this.offset = this._offset(this.sliderElem);
|
578
|
+
this.size = this.sliderElem[this.sizePos];
|
579
|
+
this.setValue(this.options.value);
|
580
|
+
|
581
|
+
/******************************************
|
582
|
+
|
583
|
+
Bind Event Listeners
|
584
|
+
|
585
|
+
******************************************/
|
586
|
+
|
587
|
+
// Bind keyboard handlers
|
588
|
+
this.handle1Keydown = this._keydown.bind(this, 0);
|
589
|
+
this.handle1.addEventListener("keydown", this.handle1Keydown, false);
|
590
|
+
|
591
|
+
this.handle2Keydown = this._keydown.bind(this, 1);
|
592
|
+
this.handle2.addEventListener("keydown", this.handle2Keydown, false);
|
593
|
+
|
594
|
+
this.mousedown = this._mousedown.bind(this);
|
595
|
+
if (this.touchCapable) {
|
596
|
+
// Bind touch handlers
|
597
|
+
this.sliderElem.addEventListener("touchstart", this.mousedown, false);
|
598
|
+
}
|
599
|
+
this.sliderElem.addEventListener("mousedown", this.mousedown, false);
|
600
|
+
|
601
|
+
|
602
|
+
// Bind tooltip-related handlers
|
603
|
+
if(this.options.tooltip === 'hide') {
|
604
|
+
this._addClass(this.tooltip, 'hide');
|
605
|
+
this._addClass(this.tooltip_min, 'hide');
|
606
|
+
this._addClass(this.tooltip_max, 'hide');
|
607
|
+
} else if(this.options.tooltip === 'always') {
|
608
|
+
this._showTooltip();
|
609
|
+
this._alwaysShowTooltip = true;
|
610
|
+
} else {
|
611
|
+
this.showTooltip = this._showTooltip.bind(this);
|
612
|
+
this.hideTooltip = this._hideTooltip.bind(this);
|
613
|
+
|
614
|
+
this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
|
615
|
+
this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
|
616
|
+
|
617
|
+
this.handle1.addEventListener("focus", this.showTooltip, false);
|
618
|
+
this.handle1.addEventListener("blur", this.hideTooltip, false);
|
619
|
+
|
620
|
+
this.handle2.addEventListener("focus", this.showTooltip, false);
|
621
|
+
this.handle2.addEventListener("blur", this.hideTooltip, false);
|
622
|
+
}
|
623
|
+
|
624
|
+
if(this.options.enabled) {
|
625
|
+
this.enable();
|
626
|
+
} else {
|
627
|
+
this.disable();
|
628
|
+
}
|
629
|
+
}
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
/*************************************************
|
634
|
+
|
635
|
+
INSTANCE PROPERTIES/METHODS
|
636
|
+
|
637
|
+
- Any methods bound to the prototype are considered
|
638
|
+
part of the plugin's `public` interface
|
639
|
+
|
640
|
+
**************************************************/
|
641
|
+
Slider.prototype = {
|
642
|
+
_init: function() {}, // NOTE: Must exist to support bridget
|
643
|
+
|
644
|
+
constructor: Slider,
|
645
|
+
|
646
|
+
defaultOptions: {
|
647
|
+
id: "",
|
648
|
+
min: 0,
|
649
|
+
max: 10,
|
650
|
+
step: 1,
|
651
|
+
precision: 0,
|
652
|
+
orientation: 'horizontal',
|
653
|
+
value: 5,
|
654
|
+
range: false,
|
655
|
+
selection: 'before',
|
656
|
+
tooltip: 'show',
|
657
|
+
tooltip_split: false,
|
658
|
+
handle: 'round',
|
659
|
+
reversed: false,
|
660
|
+
enabled: true,
|
661
|
+
formatter: function(val) {
|
662
|
+
if (Array.isArray(val)) {
|
663
|
+
return val[0] + " : " + val[1];
|
664
|
+
} else {
|
665
|
+
return val;
|
666
|
+
}
|
667
|
+
},
|
668
|
+
natural_arrow_keys: false,
|
669
|
+
ticks: [],
|
670
|
+
ticks_positions: [],
|
671
|
+
ticks_labels: [],
|
672
|
+
ticks_snap_bounds: 0,
|
673
|
+
scale: 'linear',
|
674
|
+
focus: false,
|
675
|
+
tooltip_position: null
|
676
|
+
},
|
677
|
+
|
678
|
+
over: false,
|
679
|
+
|
680
|
+
inDrag: false,
|
681
|
+
|
682
|
+
getElement: function() {
|
683
|
+
return this.sliderElem;
|
684
|
+
},
|
685
|
+
|
686
|
+
getValue: function() {
|
687
|
+
if (this.options.range) {
|
688
|
+
return this.options.value;
|
689
|
+
}
|
690
|
+
return this.options.value[0];
|
691
|
+
},
|
692
|
+
|
693
|
+
setValue: function(val, triggerSlideEvent, triggerChangeEvent) {
|
694
|
+
if (!val) {
|
695
|
+
val = 0;
|
696
|
+
}
|
697
|
+
var oldValue = this.getValue();
|
698
|
+
this.options.value = this._validateInputValue(val);
|
699
|
+
var applyPrecision = this._applyPrecision.bind(this);
|
700
|
+
|
701
|
+
if (this.options.range) {
|
702
|
+
this.options.value[0] = applyPrecision(this.options.value[0]);
|
703
|
+
this.options.value[1] = applyPrecision(this.options.value[1]);
|
704
|
+
|
705
|
+
this.options.value[0] = Math.max(this.options.min, Math.min(this.options.max, this.options.value[0]));
|
706
|
+
this.options.value[1] = Math.max(this.options.min, Math.min(this.options.max, this.options.value[1]));
|
707
|
+
} else {
|
708
|
+
this.options.value = applyPrecision(this.options.value);
|
709
|
+
this.options.value = [ Math.max(this.options.min, Math.min(this.options.max, this.options.value))];
|
710
|
+
this._addClass(this.handle2, 'hide');
|
711
|
+
if (this.options.selection === 'after') {
|
712
|
+
this.options.value[1] = this.options.max;
|
713
|
+
} else {
|
714
|
+
this.options.value[1] = this.options.min;
|
715
|
+
}
|
716
|
+
}
|
717
|
+
|
718
|
+
if (this.options.max > this.options.min) {
|
719
|
+
this.percentage = [
|
720
|
+
this._toPercentage(this.options.value[0]),
|
721
|
+
this._toPercentage(this.options.value[1]),
|
722
|
+
this.options.step * 100 / (this.options.max - this.options.min)
|
723
|
+
];
|
724
|
+
} else {
|
725
|
+
this.percentage = [0, 0, 100];
|
726
|
+
}
|
727
|
+
|
728
|
+
this._layout();
|
729
|
+
var newValue = this.options.range ? this.options.value : this.options.value[0];
|
730
|
+
|
731
|
+
if(triggerSlideEvent === true) {
|
732
|
+
this._trigger('slide', newValue);
|
733
|
+
}
|
734
|
+
if( (oldValue !== newValue) && (triggerChangeEvent === true) ) {
|
735
|
+
this._trigger('change', {
|
736
|
+
oldValue: oldValue,
|
737
|
+
newValue: newValue
|
738
|
+
});
|
739
|
+
}
|
740
|
+
this._setDataVal(newValue);
|
741
|
+
|
742
|
+
return this;
|
743
|
+
},
|
744
|
+
|
745
|
+
destroy: function(){
|
746
|
+
// Remove event handlers on slider elements
|
747
|
+
this._removeSliderEventHandlers();
|
748
|
+
|
749
|
+
// Remove the slider from the DOM
|
750
|
+
this.sliderElem.parentNode.removeChild(this.sliderElem);
|
751
|
+
/* Show original <input> element */
|
752
|
+
this.element.style.display = "";
|
753
|
+
|
754
|
+
// Clear out custom event bindings
|
755
|
+
this._cleanUpEventCallbacksMap();
|
756
|
+
|
757
|
+
// Remove data values
|
758
|
+
this.element.removeAttribute("data");
|
759
|
+
|
760
|
+
// Remove JQuery handlers/data
|
761
|
+
if($) {
|
762
|
+
this._unbindJQueryEventHandlers();
|
763
|
+
this.$element.removeData('slider');
|
764
|
+
}
|
765
|
+
},
|
766
|
+
|
767
|
+
disable: function() {
|
768
|
+
this.options.enabled = false;
|
769
|
+
this.handle1.removeAttribute("tabindex");
|
770
|
+
this.handle2.removeAttribute("tabindex");
|
771
|
+
this._addClass(this.sliderElem, 'slider-disabled');
|
772
|
+
this._trigger('slideDisabled');
|
773
|
+
|
774
|
+
return this;
|
775
|
+
},
|
776
|
+
|
777
|
+
enable: function() {
|
778
|
+
this.options.enabled = true;
|
779
|
+
this.handle1.setAttribute("tabindex", 0);
|
780
|
+
this.handle2.setAttribute("tabindex", 0);
|
781
|
+
this._removeClass(this.sliderElem, 'slider-disabled');
|
782
|
+
this._trigger('slideEnabled');
|
783
|
+
|
784
|
+
return this;
|
785
|
+
},
|
786
|
+
|
787
|
+
toggle: function() {
|
788
|
+
if(this.options.enabled) {
|
789
|
+
this.disable();
|
790
|
+
} else {
|
791
|
+
this.enable();
|
792
|
+
}
|
793
|
+
return this;
|
794
|
+
},
|
795
|
+
|
796
|
+
isEnabled: function() {
|
797
|
+
return this.options.enabled;
|
798
|
+
},
|
799
|
+
|
800
|
+
on: function(evt, callback) {
|
801
|
+
this._bindNonQueryEventHandler(evt, callback);
|
802
|
+
return this;
|
803
|
+
},
|
804
|
+
|
805
|
+
off: function(evt, callback) {
|
806
|
+
if($) {
|
807
|
+
this.$element.off(evt, callback);
|
808
|
+
this.$sliderElem.off(evt, callback);
|
809
|
+
} else {
|
810
|
+
this._unbindNonQueryEventHandler(evt, callback);
|
811
|
+
}
|
812
|
+
},
|
813
|
+
|
814
|
+
getAttribute: function(attribute) {
|
815
|
+
if(attribute) {
|
816
|
+
return this.options[attribute];
|
817
|
+
} else {
|
818
|
+
return this.options;
|
819
|
+
}
|
820
|
+
},
|
821
|
+
|
822
|
+
setAttribute: function(attribute, value) {
|
823
|
+
this.options[attribute] = value;
|
824
|
+
return this;
|
825
|
+
},
|
826
|
+
|
827
|
+
refresh: function() {
|
828
|
+
this._removeSliderEventHandlers();
|
829
|
+
createNewSlider.call(this, this.element, this.options);
|
830
|
+
if($) {
|
831
|
+
// Bind new instance of slider to the element
|
832
|
+
$.data(this.element, 'slider', this);
|
833
|
+
}
|
834
|
+
return this;
|
835
|
+
},
|
836
|
+
|
837
|
+
relayout: function() {
|
838
|
+
this._layout();
|
839
|
+
return this;
|
840
|
+
},
|
841
|
+
|
842
|
+
/******************************+
|
843
|
+
|
844
|
+
HELPERS
|
845
|
+
|
846
|
+
- Any method that is not part of the public interface.
|
847
|
+
- Place it underneath this comment block and write its signature like so:
|
848
|
+
|
849
|
+
_fnName : function() {...}
|
850
|
+
|
851
|
+
********************************/
|
852
|
+
_removeSliderEventHandlers: function() {
|
853
|
+
// Remove event listeners from handle1
|
854
|
+
this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
|
855
|
+
this.handle1.removeEventListener("focus", this.showTooltip, false);
|
856
|
+
this.handle1.removeEventListener("blur", this.hideTooltip, false);
|
857
|
+
|
858
|
+
// Remove event listeners from handle2
|
859
|
+
this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
|
860
|
+
this.handle2.removeEventListener("focus", this.handle2Keydown, false);
|
861
|
+
this.handle2.removeEventListener("blur", this.handle2Keydown, false);
|
862
|
+
|
863
|
+
// Remove event listeners from sliderElem
|
864
|
+
this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
|
865
|
+
this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
|
866
|
+
this.sliderElem.removeEventListener("touchstart", this.mousedown, false);
|
867
|
+
this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
|
868
|
+
},
|
869
|
+
_bindNonQueryEventHandler: function(evt, callback) {
|
870
|
+
if(this.eventToCallbackMap[evt] === undefined) {
|
871
|
+
this.eventToCallbackMap[evt] = [];
|
872
|
+
}
|
873
|
+
this.eventToCallbackMap[evt].push(callback);
|
874
|
+
},
|
875
|
+
_unbindNonQueryEventHandler: function(evt, callback) {
|
876
|
+
var callbacks = this.eventToCallbackMap[evt];
|
877
|
+
if(callbacks !== undefined) {
|
878
|
+
for (var i = 0; i < callbacks.length; i++) {
|
879
|
+
if (callbacks[i] === callback) {
|
880
|
+
callbacks.splice(i, 1);
|
881
|
+
break;
|
882
|
+
}
|
883
|
+
}
|
884
|
+
}
|
885
|
+
},
|
886
|
+
_cleanUpEventCallbacksMap: function() {
|
887
|
+
var eventNames = Object.keys(this.eventToCallbackMap);
|
888
|
+
for(var i = 0; i < eventNames.length; i++) {
|
889
|
+
var eventName = eventNames[i];
|
890
|
+
this.eventToCallbackMap[eventName] = null;
|
891
|
+
}
|
892
|
+
},
|
893
|
+
_showTooltip: function() {
|
894
|
+
if (this.options.tooltip_split === false ){
|
895
|
+
this._addClass(this.tooltip, 'in');
|
896
|
+
this.tooltip_min.style.display = 'none';
|
897
|
+
this.tooltip_max.style.display = 'none';
|
898
|
+
} else {
|
899
|
+
this._addClass(this.tooltip_min, 'in');
|
900
|
+
this._addClass(this.tooltip_max, 'in');
|
901
|
+
this.tooltip.style.display = 'none';
|
902
|
+
}
|
903
|
+
this.over = true;
|
904
|
+
},
|
905
|
+
_hideTooltip: function() {
|
906
|
+
if (this.inDrag === false && this.alwaysShowTooltip !== true) {
|
907
|
+
this._removeClass(this.tooltip, 'in');
|
908
|
+
this._removeClass(this.tooltip_min, 'in');
|
909
|
+
this._removeClass(this.tooltip_max, 'in');
|
910
|
+
}
|
911
|
+
this.over = false;
|
912
|
+
},
|
913
|
+
_layout: function() {
|
914
|
+
var positionPercentages;
|
915
|
+
|
916
|
+
if(this.options.reversed) {
|
917
|
+
positionPercentages = [ 100 - this.percentage[0], this.options.range ? 100 - this.percentage[1] : this.percentage[1]];
|
918
|
+
} else {
|
919
|
+
positionPercentages = [ this.percentage[0], this.percentage[1] ];
|
920
|
+
}
|
921
|
+
|
922
|
+
this.handle1.style[this.stylePos] = positionPercentages[0]+'%';
|
923
|
+
this.handle2.style[this.stylePos] = positionPercentages[1]+'%';
|
924
|
+
|
925
|
+
/* Position ticks and labels */
|
926
|
+
if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
|
927
|
+
var maxTickValue = Math.max.apply(Math, this.options.ticks);
|
928
|
+
var minTickValue = Math.min.apply(Math, this.options.ticks);
|
929
|
+
|
930
|
+
var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
|
931
|
+
var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
|
932
|
+
var labelSize = this.size / (this.options.ticks.length - 1);
|
933
|
+
|
934
|
+
if (this.tickLabelContainer) {
|
935
|
+
var extraMargin = 0;
|
936
|
+
if (this.options.ticks_positions.length === 0) {
|
937
|
+
this.tickLabelContainer.style[styleMargin] = -labelSize/2 + 'px';
|
938
|
+
extraMargin = this.tickLabelContainer.offsetHeight;
|
939
|
+
} else {
|
940
|
+
/* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
|
941
|
+
for (i = 0 ; i < this.tickLabelContainer.childNodes.length; i++) {
|
942
|
+
if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
|
943
|
+
extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
|
944
|
+
}
|
945
|
+
}
|
946
|
+
}
|
947
|
+
if (this.options.orientation === 'horizontal') {
|
948
|
+
this.sliderElem.style.marginBottom = extraMargin + 'px';
|
949
|
+
}
|
950
|
+
}
|
951
|
+
for (var i = 0; i < this.options.ticks.length; i++) {
|
952
|
+
|
953
|
+
var percentage = this.options.ticks_positions[i] ||
|
954
|
+
100 * (this.options.ticks[i] - minTickValue) / (maxTickValue - minTickValue);
|
955
|
+
|
956
|
+
this.ticks[i].style[this.stylePos] = percentage + '%';
|
957
|
+
|
958
|
+
/* Set class labels to denote whether ticks are in the selection */
|
959
|
+
this._removeClass(this.ticks[i], 'in-selection');
|
960
|
+
if (!this.options.range) {
|
961
|
+
if (this.options.selection === 'after' && percentage >= positionPercentages[0]){
|
962
|
+
this._addClass(this.ticks[i], 'in-selection');
|
963
|
+
} else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
|
964
|
+
this._addClass(this.ticks[i], 'in-selection');
|
965
|
+
}
|
966
|
+
} else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
|
967
|
+
this._addClass(this.ticks[i], 'in-selection');
|
968
|
+
}
|
969
|
+
|
970
|
+
if (this.tickLabels[i]) {
|
971
|
+
this.tickLabels[i].style[styleSize] = labelSize + 'px';
|
972
|
+
|
973
|
+
if (this.options.ticks_positions[i] !== undefined) {
|
974
|
+
this.tickLabels[i].style.position = 'absolute';
|
975
|
+
this.tickLabels[i].style[this.stylePos] = this.options.ticks_positions[i] + '%';
|
976
|
+
this.tickLabels[i].style[styleMargin] = -labelSize/2 + 'px';
|
977
|
+
}
|
978
|
+
}
|
979
|
+
}
|
980
|
+
}
|
981
|
+
|
982
|
+
if (this.options.orientation === 'vertical') {
|
983
|
+
this.trackLow.style.top = '0';
|
984
|
+
this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
|
985
|
+
|
986
|
+
this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
|
987
|
+
this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
|
988
|
+
|
989
|
+
this.trackHigh.style.bottom = '0';
|
990
|
+
this.trackHigh.style.height = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%';
|
991
|
+
} else {
|
992
|
+
this.trackLow.style.left = '0';
|
993
|
+
this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
|
994
|
+
|
995
|
+
this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) +'%';
|
996
|
+
this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) +'%';
|
997
|
+
|
998
|
+
this.trackHigh.style.right = '0';
|
999
|
+
this.trackHigh.style.width = (100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1])) +'%';
|
1000
|
+
|
1001
|
+
var offset_min = this.tooltip_min.getBoundingClientRect();
|
1002
|
+
var offset_max = this.tooltip_max.getBoundingClientRect();
|
1003
|
+
|
1004
|
+
if (offset_min.right > offset_max.left) {
|
1005
|
+
this._removeClass(this.tooltip_max, 'top');
|
1006
|
+
this._addClass(this.tooltip_max, 'bottom');
|
1007
|
+
this.tooltip_max.style.top = 18 + 'px';
|
1008
|
+
} else {
|
1009
|
+
this._removeClass(this.tooltip_max, 'bottom');
|
1010
|
+
this._addClass(this.tooltip_max, 'top');
|
1011
|
+
this.tooltip_max.style.top = this.tooltip_min.style.top;
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
|
1015
|
+
var formattedTooltipVal;
|
1016
|
+
|
1017
|
+
if (this.options.range) {
|
1018
|
+
formattedTooltipVal = this.options.formatter(this.options.value);
|
1019
|
+
this._setText(this.tooltipInner, formattedTooltipVal);
|
1020
|
+
this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0])/2 + '%';
|
1021
|
+
|
1022
|
+
if (this.options.orientation === 'vertical') {
|
1023
|
+
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
|
1024
|
+
} else {
|
1025
|
+
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
if (this.options.orientation === 'vertical') {
|
1029
|
+
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
|
1030
|
+
} else {
|
1031
|
+
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
var innerTooltipMinText = this.options.formatter(this.options.value[0]);
|
1035
|
+
this._setText(this.tooltipInner_min, innerTooltipMinText);
|
1036
|
+
|
1037
|
+
var innerTooltipMaxText = this.options.formatter(this.options.value[1]);
|
1038
|
+
this._setText(this.tooltipInner_max, innerTooltipMaxText);
|
1039
|
+
|
1040
|
+
this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%';
|
1041
|
+
|
1042
|
+
if (this.options.orientation === 'vertical') {
|
1043
|
+
this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
|
1044
|
+
} else {
|
1045
|
+
this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%';
|
1049
|
+
|
1050
|
+
if (this.options.orientation === 'vertical') {
|
1051
|
+
this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px');
|
1052
|
+
} else {
|
1053
|
+
this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px');
|
1054
|
+
}
|
1055
|
+
} else {
|
1056
|
+
formattedTooltipVal = this.options.formatter(this.options.value[0]);
|
1057
|
+
this._setText(this.tooltipInner, formattedTooltipVal);
|
1058
|
+
|
1059
|
+
this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
|
1060
|
+
if (this.options.orientation === 'vertical') {
|
1061
|
+
this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
|
1062
|
+
} else {
|
1063
|
+
this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
|
1064
|
+
}
|
1065
|
+
}
|
1066
|
+
},
|
1067
|
+
_removeProperty: function(element, prop) {
|
1068
|
+
if (element.style.removeProperty) {
|
1069
|
+
element.style.removeProperty(prop);
|
1070
|
+
} else {
|
1071
|
+
element.style.removeAttribute(prop);
|
1072
|
+
}
|
1073
|
+
},
|
1074
|
+
_mousedown: function(ev) {
|
1075
|
+
if(!this.options.enabled) {
|
1076
|
+
return false;
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
this.offset = this._offset(this.sliderElem);
|
1080
|
+
this.size = this.sliderElem[this.sizePos];
|
1081
|
+
|
1082
|
+
var percentage = this._getPercentage(ev);
|
1083
|
+
|
1084
|
+
if (this.options.range) {
|
1085
|
+
var diff1 = Math.abs(this.percentage[0] - percentage);
|
1086
|
+
var diff2 = Math.abs(this.percentage[1] - percentage);
|
1087
|
+
this.dragged = (diff1 < diff2) ? 0 : 1;
|
1088
|
+
} else {
|
1089
|
+
this.dragged = 0;
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
this.percentage[this.dragged] = percentage;
|
1093
|
+
this._layout();
|
1094
|
+
|
1095
|
+
if (this.touchCapable) {
|
1096
|
+
document.removeEventListener("touchmove", this.mousemove, false);
|
1097
|
+
document.removeEventListener("touchend", this.mouseup, false);
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
if(this.mousemove){
|
1101
|
+
document.removeEventListener("mousemove", this.mousemove, false);
|
1102
|
+
}
|
1103
|
+
if(this.mouseup){
|
1104
|
+
document.removeEventListener("mouseup", this.mouseup, false);
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
this.mousemove = this._mousemove.bind(this);
|
1108
|
+
this.mouseup = this._mouseup.bind(this);
|
1109
|
+
|
1110
|
+
if (this.touchCapable) {
|
1111
|
+
// Touch: Bind touch events:
|
1112
|
+
document.addEventListener("touchmove", this.mousemove, false);
|
1113
|
+
document.addEventListener("touchend", this.mouseup, false);
|
1114
|
+
}
|
1115
|
+
// Bind mouse events:
|
1116
|
+
document.addEventListener("mousemove", this.mousemove, false);
|
1117
|
+
document.addEventListener("mouseup", this.mouseup, false);
|
1118
|
+
|
1119
|
+
this.inDrag = true;
|
1120
|
+
var newValue = this._calculateValue();
|
1121
|
+
|
1122
|
+
this._trigger('slideStart', newValue);
|
1123
|
+
|
1124
|
+
this._setDataVal(newValue);
|
1125
|
+
this.setValue(newValue, false, true);
|
1126
|
+
|
1127
|
+
this._pauseEvent(ev);
|
1128
|
+
|
1129
|
+
if (this.options.focus) {
|
1130
|
+
this._triggerFocusOnHandle(this.dragged);
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
return true;
|
1134
|
+
},
|
1135
|
+
_triggerFocusOnHandle: function(handleIdx) {
|
1136
|
+
if(handleIdx === 0) {
|
1137
|
+
this.handle1.focus();
|
1138
|
+
}
|
1139
|
+
if(handleIdx === 1) {
|
1140
|
+
this.handle2.focus();
|
1141
|
+
}
|
1142
|
+
},
|
1143
|
+
_keydown: function(handleIdx, ev) {
|
1144
|
+
if(!this.options.enabled) {
|
1145
|
+
return false;
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
var dir;
|
1149
|
+
switch (ev.keyCode) {
|
1150
|
+
case 37: // left
|
1151
|
+
case 40: // down
|
1152
|
+
dir = -1;
|
1153
|
+
break;
|
1154
|
+
case 39: // right
|
1155
|
+
case 38: // up
|
1156
|
+
dir = 1;
|
1157
|
+
break;
|
1158
|
+
}
|
1159
|
+
if (!dir) {
|
1160
|
+
return;
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
// use natural arrow keys instead of from min to max
|
1164
|
+
if (this.options.natural_arrow_keys) {
|
1165
|
+
var ifVerticalAndNotReversed = (this.options.orientation === 'vertical' && !this.options.reversed);
|
1166
|
+
var ifHorizontalAndReversed = (this.options.orientation === 'horizontal' && this.options.reversed);
|
1167
|
+
|
1168
|
+
if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
|
1169
|
+
dir = -dir;
|
1170
|
+
}
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
var val = this.options.value[handleIdx] + dir * this.options.step;
|
1174
|
+
if (this.options.range) {
|
1175
|
+
val = [ (!handleIdx) ? val : this.options.value[0],
|
1176
|
+
( handleIdx) ? val : this.options.value[1]];
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
this._trigger('slideStart', val);
|
1180
|
+
this._setDataVal(val);
|
1181
|
+
this.setValue(val, true, true);
|
1182
|
+
|
1183
|
+
this._setDataVal(val);
|
1184
|
+
this._trigger('slideStop', val);
|
1185
|
+
this._layout();
|
1186
|
+
|
1187
|
+
this._pauseEvent(ev);
|
1188
|
+
|
1189
|
+
return false;
|
1190
|
+
},
|
1191
|
+
_pauseEvent: function(ev) {
|
1192
|
+
if(ev.stopPropagation) {
|
1193
|
+
ev.stopPropagation();
|
1194
|
+
}
|
1195
|
+
if(ev.preventDefault) {
|
1196
|
+
ev.preventDefault();
|
1197
|
+
}
|
1198
|
+
ev.cancelBubble=true;
|
1199
|
+
ev.returnValue=false;
|
1200
|
+
},
|
1201
|
+
_mousemove: function(ev) {
|
1202
|
+
if(!this.options.enabled) {
|
1203
|
+
return false;
|
1204
|
+
}
|
1205
|
+
|
1206
|
+
var percentage = this._getPercentage(ev);
|
1207
|
+
this._adjustPercentageForRangeSliders(percentage);
|
1208
|
+
this.percentage[this.dragged] = percentage;
|
1209
|
+
this._layout();
|
1210
|
+
|
1211
|
+
var val = this._calculateValue(true);
|
1212
|
+
this.setValue(val, true, true);
|
1213
|
+
|
1214
|
+
return false;
|
1215
|
+
},
|
1216
|
+
_adjustPercentageForRangeSliders: function(percentage) {
|
1217
|
+
if (this.options.range) {
|
1218
|
+
var precision = this._getNumDigitsAfterDecimalPlace(percentage);
|
1219
|
+
precision = precision ? precision - 1 : 0;
|
1220
|
+
var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision);
|
1221
|
+
if (this.dragged === 0 && this._applyToFixedAndParseFloat(this.percentage[1], precision) < percentageWithAdjustedPrecision) {
|
1222
|
+
this.percentage[0] = this.percentage[1];
|
1223
|
+
this.dragged = 1;
|
1224
|
+
} else if (this.dragged === 1 && this._applyToFixedAndParseFloat(this.percentage[0], precision) > percentageWithAdjustedPrecision) {
|
1225
|
+
this.percentage[1] = this.percentage[0];
|
1226
|
+
this.dragged = 0;
|
1227
|
+
}
|
1228
|
+
}
|
1229
|
+
},
|
1230
|
+
_mouseup: function() {
|
1231
|
+
if(!this.options.enabled) {
|
1232
|
+
return false;
|
1233
|
+
}
|
1234
|
+
if (this.touchCapable) {
|
1235
|
+
// Touch: Unbind touch event handlers:
|
1236
|
+
document.removeEventListener("touchmove", this.mousemove, false);
|
1237
|
+
document.removeEventListener("touchend", this.mouseup, false);
|
1238
|
+
}
|
1239
|
+
// Unbind mouse event handlers:
|
1240
|
+
document.removeEventListener("mousemove", this.mousemove, false);
|
1241
|
+
document.removeEventListener("mouseup", this.mouseup, false);
|
1242
|
+
|
1243
|
+
this.inDrag = false;
|
1244
|
+
if (this.over === false) {
|
1245
|
+
this._hideTooltip();
|
1246
|
+
}
|
1247
|
+
var val = this._calculateValue(true);
|
1248
|
+
|
1249
|
+
this._layout();
|
1250
|
+
this._setDataVal(val);
|
1251
|
+
this._trigger('slideStop', val);
|
1252
|
+
|
1253
|
+
return false;
|
1254
|
+
},
|
1255
|
+
_calculateValue: function(snapToClosestTick) {
|
1256
|
+
var val;
|
1257
|
+
if (this.options.range) {
|
1258
|
+
val = [this.options.min,this.options.max];
|
1259
|
+
if (this.percentage[0] !== 0){
|
1260
|
+
val[0] = this._toValue(this.percentage[0]);
|
1261
|
+
val[0] = this._applyPrecision(val[0]);
|
1262
|
+
}
|
1263
|
+
if (this.percentage[1] !== 100){
|
1264
|
+
val[1] = this._toValue(this.percentage[1]);
|
1265
|
+
val[1] = this._applyPrecision(val[1]);
|
1266
|
+
}
|
1267
|
+
} else {
|
1268
|
+
val = this._toValue(this.percentage[0]);
|
1269
|
+
val = parseFloat(val);
|
1270
|
+
val = this._applyPrecision(val);
|
1271
|
+
}
|
1272
|
+
|
1273
|
+
if (snapToClosestTick) {
|
1274
|
+
var min = [val, Infinity];
|
1275
|
+
for (var i = 0; i < this.options.ticks.length; i++) {
|
1276
|
+
var diff = Math.abs(this.options.ticks[i] - val);
|
1277
|
+
if (diff <= min[1]) {
|
1278
|
+
min = [this.options.ticks[i], diff];
|
1279
|
+
}
|
1280
|
+
}
|
1281
|
+
if (min[1] <= this.options.ticks_snap_bounds) {
|
1282
|
+
return min[0];
|
1283
|
+
}
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
return val;
|
1287
|
+
},
|
1288
|
+
_applyPrecision: function(val) {
|
1289
|
+
var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
|
1290
|
+
return this._applyToFixedAndParseFloat(val, precision);
|
1291
|
+
},
|
1292
|
+
_getNumDigitsAfterDecimalPlace: function(num) {
|
1293
|
+
var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
|
1294
|
+
if (!match) { return 0; }
|
1295
|
+
return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
|
1296
|
+
},
|
1297
|
+
_applyToFixedAndParseFloat: function(num, toFixedInput) {
|
1298
|
+
var truncatedNum = num.toFixed(toFixedInput);
|
1299
|
+
return parseFloat(truncatedNum);
|
1300
|
+
},
|
1301
|
+
/*
|
1302
|
+
Credits to Mike Samuel for the following method!
|
1303
|
+
Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
|
1304
|
+
*/
|
1305
|
+
_getPercentage: function(ev) {
|
1306
|
+
if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
|
1307
|
+
ev = ev.touches[0];
|
1308
|
+
}
|
1309
|
+
|
1310
|
+
var eventPosition = ev[this.mousePos];
|
1311
|
+
var sliderOffset = this.offset[this.stylePos];
|
1312
|
+
var distanceToSlide = eventPosition - sliderOffset;
|
1313
|
+
// Calculate what percent of the length the slider handle has slid
|
1314
|
+
var percentage = (distanceToSlide / this.size) * 100;
|
1315
|
+
percentage = Math.round(percentage / this.percentage[2]) * this.percentage[2];
|
1316
|
+
if (this.options.reversed) {
|
1317
|
+
percentage = 100 - percentage;
|
1318
|
+
}
|
1319
|
+
|
1320
|
+
// Make sure the percent is within the bounds of the slider.
|
1321
|
+
// 0% corresponds to the 'min' value of the slide
|
1322
|
+
// 100% corresponds to the 'max' value of the slide
|
1323
|
+
return Math.max(0, Math.min(100, percentage));
|
1324
|
+
},
|
1325
|
+
_validateInputValue: function(val) {
|
1326
|
+
if (typeof val === 'number') {
|
1327
|
+
return val;
|
1328
|
+
} else if (Array.isArray(val)) {
|
1329
|
+
this._validateArray(val);
|
1330
|
+
return val;
|
1331
|
+
} else {
|
1332
|
+
throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(val) );
|
1333
|
+
}
|
1334
|
+
},
|
1335
|
+
_validateArray: function(val) {
|
1336
|
+
for(var i = 0; i < val.length; i++) {
|
1337
|
+
var input = val[i];
|
1338
|
+
if (typeof input !== 'number') { throw new Error( ErrorMsgs.formatInvalidInputErrorMsg(input) ); }
|
1339
|
+
}
|
1340
|
+
},
|
1341
|
+
_setDataVal: function(val) {
|
1342
|
+
var value = "value: '" + val + "'";
|
1343
|
+
this.element.setAttribute('data', value);
|
1344
|
+
this.element.setAttribute('value', val);
|
1345
|
+
this.element.value = val;
|
1346
|
+
},
|
1347
|
+
_trigger: function(evt, val) {
|
1348
|
+
val = (val || val === 0) ? val : undefined;
|
1349
|
+
|
1350
|
+
var callbackFnArray = this.eventToCallbackMap[evt];
|
1351
|
+
if(callbackFnArray && callbackFnArray.length) {
|
1352
|
+
for(var i = 0; i < callbackFnArray.length; i++) {
|
1353
|
+
var callbackFn = callbackFnArray[i];
|
1354
|
+
callbackFn(val);
|
1355
|
+
}
|
1356
|
+
}
|
1357
|
+
|
1358
|
+
/* If JQuery exists, trigger JQuery events */
|
1359
|
+
if($) {
|
1360
|
+
this._triggerJQueryEvent(evt, val);
|
1361
|
+
}
|
1362
|
+
},
|
1363
|
+
_triggerJQueryEvent: function(evt, val) {
|
1364
|
+
var eventData = {
|
1365
|
+
type: evt,
|
1366
|
+
value: val
|
1367
|
+
};
|
1368
|
+
this.$element.trigger(eventData);
|
1369
|
+
this.$sliderElem.trigger(eventData);
|
1370
|
+
},
|
1371
|
+
_unbindJQueryEventHandlers: function() {
|
1372
|
+
this.$element.off();
|
1373
|
+
this.$sliderElem.off();
|
1374
|
+
},
|
1375
|
+
_setText: function(element, text) {
|
1376
|
+
if(typeof element.innerText !== "undefined") {
|
1377
|
+
element.innerText = text;
|
1378
|
+
} else if(typeof element.textContent !== "undefined") {
|
1379
|
+
element.textContent = text;
|
1380
|
+
}
|
1381
|
+
},
|
1382
|
+
_removeClass: function(element, classString) {
|
1383
|
+
var classes = classString.split(" ");
|
1384
|
+
var newClasses = element.className;
|
1385
|
+
|
1386
|
+
for(var i = 0; i < classes.length; i++) {
|
1387
|
+
var classTag = classes[i];
|
1388
|
+
var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
|
1389
|
+
newClasses = newClasses.replace(regex, " ");
|
1390
|
+
}
|
1391
|
+
|
1392
|
+
element.className = newClasses.trim();
|
1393
|
+
},
|
1394
|
+
_addClass: function(element, classString) {
|
1395
|
+
var classes = classString.split(" ");
|
1396
|
+
var newClasses = element.className;
|
1397
|
+
|
1398
|
+
for(var i = 0; i < classes.length; i++) {
|
1399
|
+
var classTag = classes[i];
|
1400
|
+
var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
|
1401
|
+
var ifClassExists = regex.test(newClasses);
|
1402
|
+
|
1403
|
+
if(!ifClassExists) {
|
1404
|
+
newClasses += " " + classTag;
|
1405
|
+
}
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
element.className = newClasses.trim();
|
1409
|
+
},
|
1410
|
+
_offsetLeft: function(obj){
|
1411
|
+
return obj.getBoundingClientRect().left;
|
1412
|
+
},
|
1413
|
+
_offsetTop: function(obj){
|
1414
|
+
var offsetTop = obj.offsetTop;
|
1415
|
+
while((obj = obj.offsetParent) && !isNaN(obj.offsetTop)){
|
1416
|
+
offsetTop += obj.offsetTop;
|
1417
|
+
}
|
1418
|
+
return offsetTop;
|
1419
|
+
},
|
1420
|
+
_offset: function (obj) {
|
1421
|
+
return {
|
1422
|
+
left: this._offsetLeft(obj),
|
1423
|
+
top: this._offsetTop(obj)
|
1424
|
+
};
|
1425
|
+
},
|
1426
|
+
_css: function(elementRef, styleName, value) {
|
1427
|
+
if ($) {
|
1428
|
+
$.style(elementRef, styleName, value);
|
1429
|
+
} else {
|
1430
|
+
var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
|
1431
|
+
return letter.toUpperCase();
|
1432
|
+
});
|
1433
|
+
elementRef.style[style] = value;
|
1434
|
+
}
|
1435
|
+
},
|
1436
|
+
_toValue: function(percentage) {
|
1437
|
+
return this.options.scale.toValue.apply(this, [percentage]);
|
1438
|
+
},
|
1439
|
+
_toPercentage: function(value) {
|
1440
|
+
return this.options.scale.toPercentage.apply(this, [value]);
|
1441
|
+
},
|
1442
|
+
_setTooltipPosition: function(){
|
1443
|
+
var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
|
1444
|
+
if (this.options.orientation === 'vertical'){
|
1445
|
+
this.options.tooltip_position = this.options.tooltip_position || 'right';
|
1446
|
+
var oppositeSide = this.options.tooltip_position === 'left' ? 'right' : 'left';
|
1447
|
+
tooltips.forEach(function(tooltip){
|
1448
|
+
this._addClass(tooltip, this.options.tooltip_position);
|
1449
|
+
tooltip.style[oppositeSide] = '100%';
|
1450
|
+
}.bind(this));
|
1451
|
+
} else if(this.options.tooltip_position === 'bottom') {
|
1452
|
+
tooltips.forEach(function(tooltip){
|
1453
|
+
this._addClass(tooltip, 'bottom');
|
1454
|
+
tooltip.style.top = 22 + 'px';
|
1455
|
+
}.bind(this));
|
1456
|
+
} else {
|
1457
|
+
tooltips.forEach(function(tooltip){
|
1458
|
+
this._addClass(tooltip, 'top');
|
1459
|
+
tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
|
1460
|
+
}.bind(this));
|
1461
|
+
}
|
1462
|
+
}
|
1463
|
+
};
|
1464
|
+
|
1465
|
+
/*********************************
|
1466
|
+
|
1467
|
+
Attach to global namespace
|
1468
|
+
|
1469
|
+
*********************************/
|
1470
|
+
if($) {
|
1471
|
+
var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider';
|
1472
|
+
$.bridget(namespace, Slider);
|
1473
|
+
}
|
1474
|
+
|
1475
|
+
})( $ );
|
1476
|
+
|
1477
|
+
return Slider;
|
1478
|
+
}));
|