nouislider-rails 7.0.2 → 8.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +70 -0
- data/README.md +7 -36
- data/lib/nouislider/rails/version.rb +1 -1
- data/nouislider-rails.gemspec +2 -2
- data/vendor/assets/javascripts/nouislider.js +1629 -0
- data/vendor/assets/stylesheets/nouislider.css +4 -0
- data/vendor/assets/stylesheets/nouislider/nouislider.css +162 -0
- data/vendor/assets/stylesheets/nouislider/nouislider.pips.css +98 -0
- metadata +10 -11
- data/vendor/assets/javascripts/jquery.nouislider.js +0 -3
- data/vendor/assets/javascripts/libLink/jquery.liblink.js +0 -311
- data/vendor/assets/javascripts/nouislider/jquery.nouislider.js +0 -1626
- data/vendor/assets/javascripts/wnumb/wNumb.js +0 -335
- data/vendor/assets/stylesheets/jquery.nouislider.css +0 -3
- data/vendor/assets/stylesheets/nouislider/jquery.nouislider.css +0 -265
@@ -1,1626 +0,0 @@
|
|
1
|
-
/*! noUiSlider - 7.0.2 - 2014-09-09 09:58:13 */
|
2
|
-
|
3
|
-
/*jslint browser: true */
|
4
|
-
/*jslint white: true */
|
5
|
-
|
6
|
-
(function( $ ){
|
7
|
-
|
8
|
-
'use strict';
|
9
|
-
|
10
|
-
|
11
|
-
// Removes duplicates from an array.
|
12
|
-
function unique(array) {
|
13
|
-
return $.grep(array, function(el, index) {
|
14
|
-
return index === $.inArray(el, array);
|
15
|
-
});
|
16
|
-
}
|
17
|
-
|
18
|
-
// Round a value to the closest 'to'.
|
19
|
-
function closest ( value, to ) {
|
20
|
-
return Math.round(value / to) * to;
|
21
|
-
}
|
22
|
-
|
23
|
-
// Checks whether a value is numerical.
|
24
|
-
function isNumeric ( a ) {
|
25
|
-
return typeof a === 'number' && !isNaN( a ) && isFinite( a );
|
26
|
-
}
|
27
|
-
|
28
|
-
// Rounds a number to 7 supported decimals.
|
29
|
-
function accurateNumber( number ) {
|
30
|
-
var p = Math.pow(10, 7);
|
31
|
-
return Number((Math.round(number*p)/p).toFixed(7));
|
32
|
-
}
|
33
|
-
|
34
|
-
// Sets a class and removes it after [duration] ms.
|
35
|
-
function addClassFor ( element, className, duration ) {
|
36
|
-
element.addClass(className);
|
37
|
-
setTimeout(function(){
|
38
|
-
element.removeClass(className);
|
39
|
-
}, duration);
|
40
|
-
}
|
41
|
-
|
42
|
-
// Limits a value to 0 - 100
|
43
|
-
function limit ( a ) {
|
44
|
-
return Math.max(Math.min(a, 100), 0);
|
45
|
-
}
|
46
|
-
|
47
|
-
// Wraps a variable as an array, if it isn't one yet.
|
48
|
-
function asArray ( a ) {
|
49
|
-
return $.isArray(a) ? a : [a];
|
50
|
-
}
|
51
|
-
|
52
|
-
|
53
|
-
var
|
54
|
-
// Cache the document selector;
|
55
|
-
/** @const */
|
56
|
-
doc = $(document),
|
57
|
-
// Make a backup of the original jQuery/Zepto .val() method.
|
58
|
-
/** @const */
|
59
|
-
$val = $.fn.val,
|
60
|
-
// Namespace for binding and unbinding slider events;
|
61
|
-
/** @const */
|
62
|
-
namespace = '.nui',
|
63
|
-
// Determine the events to bind. IE11 implements pointerEvents without
|
64
|
-
// a prefix, which breaks compatibility with the IE10 implementation.
|
65
|
-
/** @const */
|
66
|
-
actions = window.navigator.pointerEnabled ? {
|
67
|
-
start: 'pointerdown',
|
68
|
-
move: 'pointermove',
|
69
|
-
end: 'pointerup'
|
70
|
-
} : window.navigator.msPointerEnabled ? {
|
71
|
-
start: 'MSPointerDown',
|
72
|
-
move: 'MSPointerMove',
|
73
|
-
end: 'MSPointerUp'
|
74
|
-
} : {
|
75
|
-
start: 'mousedown touchstart',
|
76
|
-
move: 'mousemove touchmove',
|
77
|
-
end: 'mouseup touchend'
|
78
|
-
},
|
79
|
-
// Re-usable list of classes;
|
80
|
-
/** @const */
|
81
|
-
Classes = [
|
82
|
-
/* 0 */ 'noUi-target'
|
83
|
-
/* 1 */ ,'noUi-base'
|
84
|
-
/* 2 */ ,'noUi-origin'
|
85
|
-
/* 3 */ ,'noUi-handle'
|
86
|
-
/* 4 */ ,'noUi-horizontal'
|
87
|
-
/* 5 */ ,'noUi-vertical'
|
88
|
-
/* 6 */ ,'noUi-background'
|
89
|
-
/* 7 */ ,'noUi-connect'
|
90
|
-
/* 8 */ ,'noUi-ltr'
|
91
|
-
/* 9 */ ,'noUi-rtl'
|
92
|
-
/* 10 */ ,'noUi-dragable'
|
93
|
-
/* 11 */ ,''
|
94
|
-
/* 12 */ ,'noUi-state-drag'
|
95
|
-
/* 13 */ ,''
|
96
|
-
/* 14 */ ,'noUi-state-tap'
|
97
|
-
/* 15 */ ,'noUi-active'
|
98
|
-
/* 16 */ ,''
|
99
|
-
/* 17 */ ,'noUi-stacking'
|
100
|
-
];
|
101
|
-
|
102
|
-
|
103
|
-
// Value calculation
|
104
|
-
|
105
|
-
// Determine the size of a sub-range in relation to a full range.
|
106
|
-
function subRangeRatio ( pa, pb ) {
|
107
|
-
return (100 / (pb - pa));
|
108
|
-
}
|
109
|
-
|
110
|
-
// (percentage) How many percent is this value of this range?
|
111
|
-
function fromPercentage ( range, value ) {
|
112
|
-
return (value * 100) / ( range[1] - range[0] );
|
113
|
-
}
|
114
|
-
|
115
|
-
// (percentage) Where is this value on this range?
|
116
|
-
function toPercentage ( range, value ) {
|
117
|
-
return fromPercentage( range, range[0] < 0 ?
|
118
|
-
value + Math.abs(range[0]) :
|
119
|
-
value - range[0] );
|
120
|
-
}
|
121
|
-
|
122
|
-
// (value) How much is this percentage on this range?
|
123
|
-
function isPercentage ( range, value ) {
|
124
|
-
return ((value * ( range[1] - range[0] )) / 100) + range[0];
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
// Range conversion
|
129
|
-
|
130
|
-
function getJ ( value, arr ) {
|
131
|
-
|
132
|
-
var j = 1;
|
133
|
-
|
134
|
-
while ( value >= arr[j] ){
|
135
|
-
j += 1;
|
136
|
-
}
|
137
|
-
|
138
|
-
return j;
|
139
|
-
}
|
140
|
-
|
141
|
-
// (percentage) Input a value, find where, on a scale of 0-100, it applies.
|
142
|
-
function toStepping ( xVal, xPct, value ) {
|
143
|
-
|
144
|
-
if ( value >= xVal.slice(-1)[0] ){
|
145
|
-
return 100;
|
146
|
-
}
|
147
|
-
|
148
|
-
var j = getJ( value, xVal ), va, vb, pa, pb;
|
149
|
-
|
150
|
-
va = xVal[j-1];
|
151
|
-
vb = xVal[j];
|
152
|
-
pa = xPct[j-1];
|
153
|
-
pb = xPct[j];
|
154
|
-
|
155
|
-
return pa + (toPercentage([va, vb], value) / subRangeRatio (pa, pb));
|
156
|
-
}
|
157
|
-
|
158
|
-
// (value) Input a percentage, find where it is on the specified range.
|
159
|
-
function fromStepping ( xVal, xPct, value ) {
|
160
|
-
|
161
|
-
// There is no range group that fits 100
|
162
|
-
if ( value >= 100 ){
|
163
|
-
return xVal.slice(-1)[0];
|
164
|
-
}
|
165
|
-
|
166
|
-
var j = getJ( value, xPct ), va, vb, pa, pb;
|
167
|
-
|
168
|
-
va = xVal[j-1];
|
169
|
-
vb = xVal[j];
|
170
|
-
pa = xPct[j-1];
|
171
|
-
pb = xPct[j];
|
172
|
-
|
173
|
-
return isPercentage([va, vb], (value - pa) * subRangeRatio (pa, pb));
|
174
|
-
}
|
175
|
-
|
176
|
-
// (percentage) Get the step that applies at a certain value.
|
177
|
-
function getStep ( xPct, xSteps, snap, value ) {
|
178
|
-
|
179
|
-
if ( value === 100 ) {
|
180
|
-
return value;
|
181
|
-
}
|
182
|
-
|
183
|
-
var j = getJ( value, xPct ), a, b;
|
184
|
-
|
185
|
-
// If 'snap' is set, steps are used as fixed points on the slider.
|
186
|
-
if ( snap ) {
|
187
|
-
|
188
|
-
a = xPct[j-1];
|
189
|
-
b = xPct[j];
|
190
|
-
|
191
|
-
// Find the closest position, a or b.
|
192
|
-
if ((value - a) > ((b-a)/2)){
|
193
|
-
return b;
|
194
|
-
}
|
195
|
-
|
196
|
-
return a;
|
197
|
-
}
|
198
|
-
|
199
|
-
if ( !xSteps[j-1] ){
|
200
|
-
return value;
|
201
|
-
}
|
202
|
-
|
203
|
-
return xPct[j-1] + closest(
|
204
|
-
value - xPct[j-1],
|
205
|
-
xSteps[j-1]
|
206
|
-
);
|
207
|
-
}
|
208
|
-
|
209
|
-
|
210
|
-
// Entry parsing
|
211
|
-
|
212
|
-
function handleEntryPoint ( index, value, that ) {
|
213
|
-
|
214
|
-
var percentage;
|
215
|
-
|
216
|
-
// Wrap numerical input in an array.
|
217
|
-
if ( typeof value === "number" ) {
|
218
|
-
value = [value];
|
219
|
-
}
|
220
|
-
|
221
|
-
// Reject any invalid input, by testing whether value is an array.
|
222
|
-
if ( Object.prototype.toString.call( value ) !== '[object Array]' ){
|
223
|
-
throw new Error("noUiSlider: 'range' contains invalid value.");
|
224
|
-
}
|
225
|
-
|
226
|
-
// Covert min/max syntax to 0 and 100.
|
227
|
-
if ( index === 'min' ) {
|
228
|
-
percentage = 0;
|
229
|
-
} else if ( index === 'max' ) {
|
230
|
-
percentage = 100;
|
231
|
-
} else {
|
232
|
-
percentage = parseFloat( index );
|
233
|
-
}
|
234
|
-
|
235
|
-
// Check for correct input.
|
236
|
-
if ( !isNumeric( percentage ) || !isNumeric( value[0] ) ) {
|
237
|
-
throw new Error("noUiSlider: 'range' value isn't numeric.");
|
238
|
-
}
|
239
|
-
|
240
|
-
// Store values.
|
241
|
-
that.xPct.push( percentage );
|
242
|
-
that.xVal.push( value[0] );
|
243
|
-
|
244
|
-
// NaN will evaluate to false too, but to keep
|
245
|
-
// logging clear, set step explicitly. Make sure
|
246
|
-
// not to override the 'step' setting with false.
|
247
|
-
if ( !percentage ) {
|
248
|
-
if ( !isNaN( value[1] ) ) {
|
249
|
-
that.xSteps[0] = value[1];
|
250
|
-
}
|
251
|
-
} else {
|
252
|
-
that.xSteps.push( isNaN(value[1]) ? false : value[1] );
|
253
|
-
}
|
254
|
-
}
|
255
|
-
|
256
|
-
function handleStepPoint ( i, n, that ) {
|
257
|
-
|
258
|
-
// Ignore 'false' stepping.
|
259
|
-
if ( !n ) {
|
260
|
-
return true;
|
261
|
-
}
|
262
|
-
|
263
|
-
// Factor to range ratio
|
264
|
-
that.xSteps[i] = fromPercentage([
|
265
|
-
that.xVal[i]
|
266
|
-
,that.xVal[i+1]
|
267
|
-
], n) / subRangeRatio (
|
268
|
-
that.xPct[i],
|
269
|
-
that.xPct[i+1] );
|
270
|
-
}
|
271
|
-
|
272
|
-
|
273
|
-
// Interface
|
274
|
-
|
275
|
-
// The interface to Spectrum handles all direction-based
|
276
|
-
// conversions, so the above values are unaware.
|
277
|
-
|
278
|
-
function Spectrum ( entry, snap, direction, singleStep ) {
|
279
|
-
|
280
|
-
this.xPct = [];
|
281
|
-
this.xVal = [];
|
282
|
-
this.xSteps = [ singleStep || false ];
|
283
|
-
this.xNumSteps = [ false ];
|
284
|
-
|
285
|
-
this.snap = snap;
|
286
|
-
this.direction = direction;
|
287
|
-
|
288
|
-
var that = this, index;
|
289
|
-
|
290
|
-
// Loop all entries.
|
291
|
-
for ( index in entry ) {
|
292
|
-
if ( entry.hasOwnProperty(index) ) {
|
293
|
-
handleEntryPoint(index, entry[index], that);
|
294
|
-
}
|
295
|
-
}
|
296
|
-
|
297
|
-
// Store the actual step values.
|
298
|
-
that.xNumSteps = that.xSteps.slice(0);
|
299
|
-
|
300
|
-
for ( index in that.xNumSteps ) {
|
301
|
-
if ( that.xNumSteps.hasOwnProperty(index) ) {
|
302
|
-
handleStepPoint(Number(index), that.xNumSteps[index], that);
|
303
|
-
}
|
304
|
-
}
|
305
|
-
}
|
306
|
-
|
307
|
-
Spectrum.prototype.getMargin = function ( value ) {
|
308
|
-
return this.xPct.length === 2 ? fromPercentage(this.xVal, value) : false;
|
309
|
-
};
|
310
|
-
|
311
|
-
Spectrum.prototype.toStepping = function ( value ) {
|
312
|
-
|
313
|
-
value = toStepping( this.xVal, this.xPct, value );
|
314
|
-
|
315
|
-
// Invert the value if this is a right-to-left slider.
|
316
|
-
if ( this.direction ) {
|
317
|
-
value = 100 - value;
|
318
|
-
}
|
319
|
-
|
320
|
-
return value;
|
321
|
-
};
|
322
|
-
|
323
|
-
Spectrum.prototype.fromStepping = function ( value ) {
|
324
|
-
|
325
|
-
// Invert the value if this is a right-to-left slider.
|
326
|
-
if ( this.direction ) {
|
327
|
-
value = 100 - value;
|
328
|
-
}
|
329
|
-
|
330
|
-
return accurateNumber(fromStepping( this.xVal, this.xPct, value ));
|
331
|
-
};
|
332
|
-
|
333
|
-
Spectrum.prototype.getStep = function ( value ) {
|
334
|
-
|
335
|
-
// Find the proper step for rtl sliders by search in inverse direction.
|
336
|
-
// Fixes issue #262.
|
337
|
-
if ( this.direction ) {
|
338
|
-
value = 100 - value;
|
339
|
-
}
|
340
|
-
|
341
|
-
value = getStep(this.xPct, this.xSteps, this.snap, value );
|
342
|
-
|
343
|
-
if ( this.direction ) {
|
344
|
-
value = 100 - value;
|
345
|
-
}
|
346
|
-
|
347
|
-
return value;
|
348
|
-
};
|
349
|
-
|
350
|
-
Spectrum.prototype.getApplicableStep = function ( value ) {
|
351
|
-
|
352
|
-
// If the value is 100%, return the negative step twice.
|
353
|
-
var j = getJ(value, this.xPct), offset = value === 100 ? 2 : 1;
|
354
|
-
return [this.xNumSteps[j-2], this.xVal[j-offset], this.xNumSteps[j-offset]];
|
355
|
-
};
|
356
|
-
|
357
|
-
// Outside testing
|
358
|
-
Spectrum.prototype.convert = function ( value ) {
|
359
|
-
return this.getStep(this.toStepping(value));
|
360
|
-
};
|
361
|
-
|
362
|
-
/* Every input option is tested and parsed. This'll prevent
|
363
|
-
endless validation in internal methods. These tests are
|
364
|
-
structured with an item for every option available. An
|
365
|
-
option can be marked as required by setting the 'r' flag.
|
366
|
-
The testing function is provided with three arguments:
|
367
|
-
- The provided value for the option;
|
368
|
-
- A reference to the options object;
|
369
|
-
- The name for the option;
|
370
|
-
|
371
|
-
The testing function returns false when an error is detected,
|
372
|
-
or true when everything is OK. It can also modify the option
|
373
|
-
object, to make sure all values can be correctly looped elsewhere. */
|
374
|
-
|
375
|
-
/** @const */
|
376
|
-
var defaultFormatter = { 'to': function( value ){
|
377
|
-
return value.toFixed(2);
|
378
|
-
}, 'from': Number };
|
379
|
-
|
380
|
-
function testStep ( parsed, entry ) {
|
381
|
-
|
382
|
-
if ( !isNumeric( entry ) ) {
|
383
|
-
throw new Error("noUiSlider: 'step' is not numeric.");
|
384
|
-
}
|
385
|
-
|
386
|
-
// The step option can still be used to set stepping
|
387
|
-
// for linear sliders. Overwritten if set in 'range'.
|
388
|
-
parsed.singleStep = entry;
|
389
|
-
}
|
390
|
-
|
391
|
-
function testRange ( parsed, entry ) {
|
392
|
-
|
393
|
-
// Filter incorrect input.
|
394
|
-
if ( typeof entry !== 'object' || $.isArray(entry) ) {
|
395
|
-
throw new Error("noUiSlider: 'range' is not an object.");
|
396
|
-
}
|
397
|
-
|
398
|
-
// Catch missing start or end.
|
399
|
-
if ( entry.min === undefined || entry.max === undefined ) {
|
400
|
-
throw new Error("noUiSlider: Missing 'min' or 'max' in 'range'.");
|
401
|
-
}
|
402
|
-
|
403
|
-
parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.dir, parsed.singleStep);
|
404
|
-
}
|
405
|
-
|
406
|
-
function testStart ( parsed, entry ) {
|
407
|
-
|
408
|
-
entry = asArray(entry);
|
409
|
-
|
410
|
-
// Validate input. Values aren't tested, as the public .val method
|
411
|
-
// will always provide a valid location.
|
412
|
-
if ( !$.isArray( entry ) || !entry.length || entry.length > 2 ) {
|
413
|
-
throw new Error("noUiSlider: 'start' option is incorrect.");
|
414
|
-
}
|
415
|
-
|
416
|
-
// Store the number of handles.
|
417
|
-
parsed.handles = entry.length;
|
418
|
-
|
419
|
-
// When the slider is initialized, the .val method will
|
420
|
-
// be called with the start options.
|
421
|
-
parsed.start = entry;
|
422
|
-
}
|
423
|
-
|
424
|
-
function testSnap ( parsed, entry ) {
|
425
|
-
|
426
|
-
// Enforce 100% stepping within subranges.
|
427
|
-
parsed.snap = entry;
|
428
|
-
|
429
|
-
if ( typeof entry !== 'boolean' ){
|
430
|
-
throw new Error("noUiSlider: 'snap' option must be a boolean.");
|
431
|
-
}
|
432
|
-
}
|
433
|
-
|
434
|
-
function testAnimate ( parsed, entry ) {
|
435
|
-
|
436
|
-
// Enforce 100% stepping within subranges.
|
437
|
-
parsed.animate = entry;
|
438
|
-
|
439
|
-
if ( typeof entry !== 'boolean' ){
|
440
|
-
throw new Error("noUiSlider: 'animate' option must be a boolean.");
|
441
|
-
}
|
442
|
-
}
|
443
|
-
|
444
|
-
function testConnect ( parsed, entry ) {
|
445
|
-
|
446
|
-
if ( entry === 'lower' && parsed.handles === 1 ) {
|
447
|
-
parsed.connect = 1;
|
448
|
-
} else if ( entry === 'upper' && parsed.handles === 1 ) {
|
449
|
-
parsed.connect = 2;
|
450
|
-
} else if ( entry === true && parsed.handles === 2 ) {
|
451
|
-
parsed.connect = 3;
|
452
|
-
} else if ( entry === false ) {
|
453
|
-
parsed.connect = 0;
|
454
|
-
} else {
|
455
|
-
throw new Error("noUiSlider: 'connect' option doesn't match handle count.");
|
456
|
-
}
|
457
|
-
}
|
458
|
-
|
459
|
-
function testOrientation ( parsed, entry ) {
|
460
|
-
|
461
|
-
// Set orientation to an a numerical value for easy
|
462
|
-
// array selection.
|
463
|
-
switch ( entry ){
|
464
|
-
case 'horizontal':
|
465
|
-
parsed.ort = 0;
|
466
|
-
break;
|
467
|
-
case 'vertical':
|
468
|
-
parsed.ort = 1;
|
469
|
-
break;
|
470
|
-
default:
|
471
|
-
throw new Error("noUiSlider: 'orientation' option is invalid.");
|
472
|
-
}
|
473
|
-
}
|
474
|
-
|
475
|
-
function testMargin ( parsed, entry ) {
|
476
|
-
|
477
|
-
if ( !isNumeric(entry) ){
|
478
|
-
throw new Error("noUiSlider: 'margin' option must be numeric.");
|
479
|
-
}
|
480
|
-
|
481
|
-
parsed.margin = parsed.spectrum.getMargin(entry);
|
482
|
-
|
483
|
-
if ( !parsed.margin ) {
|
484
|
-
throw new Error("noUiSlider: 'margin' option is only supported on linear sliders.");
|
485
|
-
}
|
486
|
-
}
|
487
|
-
|
488
|
-
function testLimit ( parsed, entry ) {
|
489
|
-
|
490
|
-
if ( !isNumeric(entry) ){
|
491
|
-
throw new Error("noUiSlider: 'limit' option must be numeric.");
|
492
|
-
}
|
493
|
-
|
494
|
-
parsed.limit = parsed.spectrum.getMargin(entry);
|
495
|
-
|
496
|
-
if ( !parsed.limit ) {
|
497
|
-
throw new Error("noUiSlider: 'limit' option is only supported on linear sliders.");
|
498
|
-
}
|
499
|
-
}
|
500
|
-
|
501
|
-
function testDirection ( parsed, entry ) {
|
502
|
-
|
503
|
-
// Set direction as a numerical value for easy parsing.
|
504
|
-
// Invert connection for RTL sliders, so that the proper
|
505
|
-
// handles get the connect/background classes.
|
506
|
-
switch ( entry ) {
|
507
|
-
case 'ltr':
|
508
|
-
parsed.dir = 0;
|
509
|
-
break;
|
510
|
-
case 'rtl':
|
511
|
-
parsed.dir = 1;
|
512
|
-
parsed.connect = [0,2,1,3][parsed.connect];
|
513
|
-
break;
|
514
|
-
default:
|
515
|
-
throw new Error("noUiSlider: 'direction' option was not recognized.");
|
516
|
-
}
|
517
|
-
}
|
518
|
-
|
519
|
-
function testBehaviour ( parsed, entry ) {
|
520
|
-
|
521
|
-
// Make sure the input is a string.
|
522
|
-
if ( typeof entry !== 'string' ) {
|
523
|
-
throw new Error("noUiSlider: 'behaviour' must be a string containing options.");
|
524
|
-
}
|
525
|
-
|
526
|
-
// Check if the string contains any keywords.
|
527
|
-
// None are required.
|
528
|
-
var tap = entry.indexOf('tap') >= 0,
|
529
|
-
drag = entry.indexOf('drag') >= 0,
|
530
|
-
fixed = entry.indexOf('fixed') >= 0,
|
531
|
-
snap = entry.indexOf('snap') >= 0;
|
532
|
-
|
533
|
-
parsed.events = {
|
534
|
-
tap: tap || snap,
|
535
|
-
drag: drag,
|
536
|
-
fixed: fixed,
|
537
|
-
snap: snap
|
538
|
-
};
|
539
|
-
}
|
540
|
-
|
541
|
-
function testFormat ( parsed, entry ) {
|
542
|
-
|
543
|
-
parsed.format = entry;
|
544
|
-
|
545
|
-
// Any object with a to and from method is supported.
|
546
|
-
if ( typeof entry.to === 'function' && typeof entry.from === 'function' ) {
|
547
|
-
return true;
|
548
|
-
}
|
549
|
-
|
550
|
-
throw new Error( "noUiSlider: 'format' requires 'to' and 'from' methods.");
|
551
|
-
}
|
552
|
-
|
553
|
-
// Test all developer settings and parse to assumption-safe values.
|
554
|
-
function testOptions ( options ) {
|
555
|
-
|
556
|
-
var parsed = {
|
557
|
-
margin: 0,
|
558
|
-
limit: 0,
|
559
|
-
animate: true,
|
560
|
-
format: defaultFormatter
|
561
|
-
}, tests;
|
562
|
-
|
563
|
-
// Tests are executed in the order they are presented here.
|
564
|
-
tests = {
|
565
|
-
'step': { r: false, t: testStep },
|
566
|
-
'start': { r: true, t: testStart },
|
567
|
-
'connect': { r: true, t: testConnect },
|
568
|
-
'direction': { r: true, t: testDirection },
|
569
|
-
'snap': { r: false, t: testSnap },
|
570
|
-
'animate': { r: false, t: testAnimate },
|
571
|
-
'range': { r: true, t: testRange },
|
572
|
-
'orientation': { r: false, t: testOrientation },
|
573
|
-
'margin': { r: false, t: testMargin },
|
574
|
-
'limit': { r: false, t: testLimit },
|
575
|
-
'behaviour': { r: true, t: testBehaviour },
|
576
|
-
'format': { r: false, t: testFormat }
|
577
|
-
};
|
578
|
-
|
579
|
-
// Set defaults where applicable.
|
580
|
-
options = $.extend({
|
581
|
-
'connect': false,
|
582
|
-
'direction': 'ltr',
|
583
|
-
'behaviour': 'tap',
|
584
|
-
'orientation': 'horizontal'
|
585
|
-
}, options);
|
586
|
-
|
587
|
-
// Run all options through a testing mechanism to ensure correct
|
588
|
-
// input. It should be noted that options might get modified to
|
589
|
-
// be handled properly. E.g. wrapping integers in arrays.
|
590
|
-
$.each( tests, function( name, test ){
|
591
|
-
|
592
|
-
// If the option isn't set, but it is required, throw an error.
|
593
|
-
if ( options[name] === undefined ) {
|
594
|
-
|
595
|
-
if ( test.r ) {
|
596
|
-
throw new Error("noUiSlider: '" + name + "' is required.");
|
597
|
-
}
|
598
|
-
|
599
|
-
return true;
|
600
|
-
}
|
601
|
-
|
602
|
-
test.t( parsed, options[name] );
|
603
|
-
});
|
604
|
-
|
605
|
-
// Pre-define the styles.
|
606
|
-
parsed.style = parsed.ort ? 'top' : 'left';
|
607
|
-
|
608
|
-
return parsed;
|
609
|
-
}
|
610
|
-
|
611
|
-
// Class handling
|
612
|
-
|
613
|
-
// Delimit proposed values for handle positions.
|
614
|
-
function getPositions ( a, b, delimit ) {
|
615
|
-
|
616
|
-
// Add movement to current position.
|
617
|
-
var c = a + b[0], d = a + b[1];
|
618
|
-
|
619
|
-
// Only alter the other position on drag,
|
620
|
-
// not on standard sliding.
|
621
|
-
if ( delimit ) {
|
622
|
-
if ( c < 0 ) {
|
623
|
-
d += Math.abs(c);
|
624
|
-
}
|
625
|
-
if ( d > 100 ) {
|
626
|
-
c -= ( d - 100 );
|
627
|
-
}
|
628
|
-
|
629
|
-
// Limit values to 0 and 100.
|
630
|
-
return [limit(c), limit(d)];
|
631
|
-
}
|
632
|
-
|
633
|
-
return [c,d];
|
634
|
-
}
|
635
|
-
|
636
|
-
|
637
|
-
// Event handling
|
638
|
-
|
639
|
-
// Provide a clean event with standardized offset values.
|
640
|
-
function fixEvent ( e ) {
|
641
|
-
|
642
|
-
// Prevent scrolling and panning on touch events, while
|
643
|
-
// attempting to slide. The tap event also depends on this.
|
644
|
-
e.preventDefault();
|
645
|
-
|
646
|
-
// Filter the event to register the type, which can be
|
647
|
-
// touch, mouse or pointer. Offset changes need to be
|
648
|
-
// made on an event specific basis.
|
649
|
-
var touch = e.type.indexOf('touch') === 0
|
650
|
-
,mouse = e.type.indexOf('mouse') === 0
|
651
|
-
,pointer = e.type.indexOf('pointer') === 0
|
652
|
-
,x,y, event = e;
|
653
|
-
|
654
|
-
// IE10 implemented pointer events with a prefix;
|
655
|
-
if ( e.type.indexOf('MSPointer') === 0 ) {
|
656
|
-
pointer = true;
|
657
|
-
}
|
658
|
-
|
659
|
-
// Get the originalEvent, if the event has been wrapped
|
660
|
-
// by jQuery. Zepto doesn't wrap the event.
|
661
|
-
if ( e.originalEvent ) {
|
662
|
-
e = e.originalEvent;
|
663
|
-
}
|
664
|
-
|
665
|
-
if ( touch ) {
|
666
|
-
// noUiSlider supports one movement at a time,
|
667
|
-
// so we can select the first 'changedTouch'.
|
668
|
-
x = e.changedTouches[0].pageX;
|
669
|
-
y = e.changedTouches[0].pageY;
|
670
|
-
}
|
671
|
-
|
672
|
-
if ( mouse || pointer ) {
|
673
|
-
|
674
|
-
// Polyfill the pageXOffset and pageYOffset
|
675
|
-
// variables for IE7 and IE8;
|
676
|
-
if( !pointer && window.pageXOffset === undefined ){
|
677
|
-
window.pageXOffset = document.documentElement.scrollLeft;
|
678
|
-
window.pageYOffset = document.documentElement.scrollTop;
|
679
|
-
}
|
680
|
-
|
681
|
-
x = e.clientX + window.pageXOffset;
|
682
|
-
y = e.clientY + window.pageYOffset;
|
683
|
-
}
|
684
|
-
|
685
|
-
event.points = [x, y];
|
686
|
-
event.cursor = mouse;
|
687
|
-
|
688
|
-
return event;
|
689
|
-
}
|
690
|
-
|
691
|
-
|
692
|
-
// DOM additions
|
693
|
-
|
694
|
-
// Append a handle to the base.
|
695
|
-
function addHandle ( direction, index ) {
|
696
|
-
|
697
|
-
var handle = $('<div><div/></div>').addClass( Classes[2] ),
|
698
|
-
additions = [ '-lower', '-upper' ];
|
699
|
-
|
700
|
-
if ( direction ) {
|
701
|
-
additions.reverse();
|
702
|
-
}
|
703
|
-
|
704
|
-
handle.children().addClass(
|
705
|
-
Classes[3] + " " + Classes[3]+additions[index]
|
706
|
-
);
|
707
|
-
|
708
|
-
return handle;
|
709
|
-
}
|
710
|
-
|
711
|
-
// Add the proper connection classes.
|
712
|
-
function addConnection ( connect, target, handles ) {
|
713
|
-
|
714
|
-
// Apply the required connection classes to the elements
|
715
|
-
// that need them. Some classes are made up for several
|
716
|
-
// segments listed in the class list, to allow easy
|
717
|
-
// renaming and provide a minor compression benefit.
|
718
|
-
switch ( connect ) {
|
719
|
-
case 1: target.addClass( Classes[7] );
|
720
|
-
handles[0].addClass( Classes[6] );
|
721
|
-
break;
|
722
|
-
case 3: handles[1].addClass( Classes[6] );
|
723
|
-
/* falls through */
|
724
|
-
case 2: handles[0].addClass( Classes[7] );
|
725
|
-
/* falls through */
|
726
|
-
case 0: target.addClass(Classes[6]);
|
727
|
-
break;
|
728
|
-
}
|
729
|
-
}
|
730
|
-
|
731
|
-
// Add handles to the slider base.
|
732
|
-
function addHandles ( nrHandles, direction, base ) {
|
733
|
-
|
734
|
-
var index, handles = [];
|
735
|
-
|
736
|
-
// Append handles.
|
737
|
-
for ( index = 0; index < nrHandles; index += 1 ) {
|
738
|
-
|
739
|
-
// Keep a list of all added handles.
|
740
|
-
handles.push( addHandle( direction, index ).appendTo(base) );
|
741
|
-
}
|
742
|
-
|
743
|
-
return handles;
|
744
|
-
}
|
745
|
-
|
746
|
-
// Initialize a single slider.
|
747
|
-
function addSlider ( direction, orientation, target ) {
|
748
|
-
|
749
|
-
// Apply classes and data to the target.
|
750
|
-
target.addClass([
|
751
|
-
Classes[0],
|
752
|
-
Classes[8 + direction],
|
753
|
-
Classes[4 + orientation]
|
754
|
-
].join(' '));
|
755
|
-
|
756
|
-
return $('<div/>').appendTo(target).addClass( Classes[1] );
|
757
|
-
}
|
758
|
-
|
759
|
-
function closure ( target, options, originalOptions ){
|
760
|
-
|
761
|
-
// Internal variables
|
762
|
-
|
763
|
-
// All variables local to 'closure' are marked $.
|
764
|
-
var $Target = $(target),
|
765
|
-
$Locations = [-1, -1],
|
766
|
-
$Base,
|
767
|
-
$Handles,
|
768
|
-
$Spectrum = options.spectrum,
|
769
|
-
$Values = [],
|
770
|
-
// libLink. For rtl sliders, 'lower' and 'upper' should not be inverted
|
771
|
-
// for one-handle sliders, so trim 'upper' it that case.
|
772
|
-
triggerPos = ['lower', 'upper'].slice(0, options.handles);
|
773
|
-
|
774
|
-
// Invert the libLink connection for rtl sliders.
|
775
|
-
if ( options.dir ) {
|
776
|
-
triggerPos.reverse();
|
777
|
-
}
|
778
|
-
|
779
|
-
// Helpers
|
780
|
-
|
781
|
-
// Shorthand for base dimensions.
|
782
|
-
function baseSize ( ) {
|
783
|
-
return $Base[['width', 'height'][options.ort]]();
|
784
|
-
}
|
785
|
-
|
786
|
-
// External event handling
|
787
|
-
function fireEvents ( events ) {
|
788
|
-
|
789
|
-
// Use the external api to get the values.
|
790
|
-
// Wrap the values in an array, as .trigger takes
|
791
|
-
// only one additional argument.
|
792
|
-
var index, values = [ $Target.val() ];
|
793
|
-
|
794
|
-
for ( index = 0; index < events.length; index += 1 ){
|
795
|
-
$Target.trigger(events[index], values);
|
796
|
-
}
|
797
|
-
}
|
798
|
-
|
799
|
-
// Returns the input array, respecting the slider direction configuration.
|
800
|
-
function inSliderOrder ( values ) {
|
801
|
-
|
802
|
-
// If only one handle is used, return a single value.
|
803
|
-
if ( values.length === 1 ){
|
804
|
-
return values[0];
|
805
|
-
}
|
806
|
-
|
807
|
-
if ( options.dir ) {
|
808
|
-
return values.reverse();
|
809
|
-
}
|
810
|
-
|
811
|
-
return values;
|
812
|
-
}
|
813
|
-
|
814
|
-
// libLink integration
|
815
|
-
|
816
|
-
// Create a new function which calls .val on input change.
|
817
|
-
function createChangeHandler ( trigger ) {
|
818
|
-
return function ( ignore, value ){
|
819
|
-
// Determine which array position to 'null' based on 'trigger'.
|
820
|
-
$Target.val( [ trigger ? null : value, trigger ? value : null ], true );
|
821
|
-
};
|
822
|
-
}
|
823
|
-
|
824
|
-
// Called by libLink when it wants a set of links updated.
|
825
|
-
function linkUpdate ( flag ) {
|
826
|
-
|
827
|
-
var trigger = $.inArray(flag, triggerPos);
|
828
|
-
|
829
|
-
// The API might not have been set yet.
|
830
|
-
if ( $Target[0].linkAPI && $Target[0].linkAPI[flag] ) {
|
831
|
-
$Target[0].linkAPI[flag].change(
|
832
|
-
$Values[trigger],
|
833
|
-
$Handles[trigger].children(),
|
834
|
-
$Target
|
835
|
-
);
|
836
|
-
}
|
837
|
-
}
|
838
|
-
|
839
|
-
// Called by libLink to append an element to the slider.
|
840
|
-
function linkConfirm ( flag, element ) {
|
841
|
-
|
842
|
-
// Find the trigger for the passed flag.
|
843
|
-
var trigger = $.inArray(flag, triggerPos);
|
844
|
-
|
845
|
-
// If set, append the element to the handle it belongs to.
|
846
|
-
if ( element ) {
|
847
|
-
element.appendTo( $Handles[trigger].children() );
|
848
|
-
}
|
849
|
-
|
850
|
-
// The public API is reversed for rtl sliders, so the changeHandler
|
851
|
-
// should not be aware of the inverted trigger positions.
|
852
|
-
if ( options.dir ) {
|
853
|
-
trigger = trigger === 1 ? 0 : 1;
|
854
|
-
}
|
855
|
-
|
856
|
-
return createChangeHandler( trigger );
|
857
|
-
}
|
858
|
-
|
859
|
-
// Place elements back on the slider.
|
860
|
-
function reAppendLink ( ) {
|
861
|
-
|
862
|
-
var i, flag;
|
863
|
-
|
864
|
-
// The API keeps a list of elements: we can re-append them on rebuild.
|
865
|
-
for ( i = 0; i < triggerPos.length; i += 1 ) {
|
866
|
-
if ( this.linkAPI && this.linkAPI[(flag = triggerPos[i])] ) {
|
867
|
-
this.linkAPI[flag].reconfirm(flag);
|
868
|
-
}
|
869
|
-
}
|
870
|
-
}
|
871
|
-
|
872
|
-
target.LinkUpdate = linkUpdate;
|
873
|
-
target.LinkConfirm = linkConfirm;
|
874
|
-
target.LinkDefaultFormatter = options.format;
|
875
|
-
target.LinkDefaultFlag = 'lower';
|
876
|
-
|
877
|
-
target.reappend = reAppendLink;
|
878
|
-
|
879
|
-
|
880
|
-
// Handler for attaching events trough a proxy.
|
881
|
-
function attach ( events, element, callback, data ) {
|
882
|
-
|
883
|
-
// This function can be used to 'filter' events to the slider.
|
884
|
-
|
885
|
-
// Add the noUiSlider namespace to all events.
|
886
|
-
events = events.replace( /\s/g, namespace + ' ' ) + namespace;
|
887
|
-
|
888
|
-
// Bind a closure on the target.
|
889
|
-
return element.on( events, function( e ){
|
890
|
-
|
891
|
-
// jQuery and Zepto (1) handle unset attributes differently,
|
892
|
-
// but always falsy; #208
|
893
|
-
if ( !!$Target.attr('disabled') ) {
|
894
|
-
return false;
|
895
|
-
}
|
896
|
-
|
897
|
-
// Stop if an active 'tap' transition is taking place.
|
898
|
-
if ( $Target.hasClass( Classes[14] ) ) {
|
899
|
-
return false;
|
900
|
-
}
|
901
|
-
|
902
|
-
e = fixEvent(e);
|
903
|
-
e.calcPoint = e.points[ options.ort ];
|
904
|
-
|
905
|
-
// Call the event handler with the event [ and additional data ].
|
906
|
-
callback ( e, data );
|
907
|
-
});
|
908
|
-
}
|
909
|
-
|
910
|
-
// Handle movement on document for handle and range drag.
|
911
|
-
function move ( event, data ) {
|
912
|
-
|
913
|
-
var handles = data.handles || $Handles, positions, state = false,
|
914
|
-
proposal = ((event.calcPoint - data.start) * 100) / baseSize(),
|
915
|
-
h = handles[0][0] !== $Handles[0][0] ? 1 : 0;
|
916
|
-
|
917
|
-
// Calculate relative positions for the handles.
|
918
|
-
positions = getPositions( proposal, data.positions, handles.length > 1);
|
919
|
-
|
920
|
-
state = setHandle ( handles[0], positions[h], handles.length === 1 );
|
921
|
-
|
922
|
-
if ( handles.length > 1 ) {
|
923
|
-
state = setHandle ( handles[1], positions[h?0:1], false ) || state;
|
924
|
-
}
|
925
|
-
|
926
|
-
// Fire the 'slide' event if any handle moved.
|
927
|
-
if ( state ) {
|
928
|
-
fireEvents(['slide']);
|
929
|
-
}
|
930
|
-
}
|
931
|
-
|
932
|
-
// Unbind move events on document, call callbacks.
|
933
|
-
function end ( event ) {
|
934
|
-
|
935
|
-
// The handle is no longer active, so remove the class.
|
936
|
-
$('.' + Classes[15]).removeClass(Classes[15]);
|
937
|
-
|
938
|
-
// Remove cursor styles and text-selection events bound to the body.
|
939
|
-
if ( event.cursor ) {
|
940
|
-
$('body').css('cursor', '').off( namespace );
|
941
|
-
}
|
942
|
-
|
943
|
-
// Unbind the move and end events, which are added on 'start'.
|
944
|
-
doc.off( namespace );
|
945
|
-
|
946
|
-
// Remove dragging class.
|
947
|
-
$Target.removeClass(Classes[12]);
|
948
|
-
|
949
|
-
// Fire the change and set events.
|
950
|
-
fireEvents(['set', 'change']);
|
951
|
-
}
|
952
|
-
|
953
|
-
// Bind move events on document.
|
954
|
-
function start ( event, data ) {
|
955
|
-
|
956
|
-
// Mark the handle as 'active' so it can be styled.
|
957
|
-
if( data.handles.length === 1 ) {
|
958
|
-
data.handles[0].children().addClass(Classes[15]);
|
959
|
-
}
|
960
|
-
|
961
|
-
// A drag should never propagate up to the 'tap' event.
|
962
|
-
event.stopPropagation();
|
963
|
-
|
964
|
-
// Attach the move event.
|
965
|
-
attach ( actions.move, doc, move, {
|
966
|
-
start: event.calcPoint,
|
967
|
-
handles: data.handles,
|
968
|
-
positions: [
|
969
|
-
$Locations[0],
|
970
|
-
$Locations[$Handles.length - 1]
|
971
|
-
]
|
972
|
-
});
|
973
|
-
|
974
|
-
// Unbind all movement when the drag ends.
|
975
|
-
attach ( actions.end, doc, end, null );
|
976
|
-
|
977
|
-
// Text selection isn't an issue on touch devices,
|
978
|
-
// so adding cursor styles can be skipped.
|
979
|
-
if ( event.cursor ) {
|
980
|
-
|
981
|
-
// Prevent the 'I' cursor and extend the range-drag cursor.
|
982
|
-
$('body').css('cursor', $(event.target).css('cursor'));
|
983
|
-
|
984
|
-
// Mark the target with a dragging state.
|
985
|
-
if ( $Handles.length > 1 ) {
|
986
|
-
$Target.addClass(Classes[12]);
|
987
|
-
}
|
988
|
-
|
989
|
-
// Prevent text selection when dragging the handles.
|
990
|
-
$('body').on('selectstart' + namespace, false);
|
991
|
-
}
|
992
|
-
}
|
993
|
-
|
994
|
-
// Move closest handle to tapped location.
|
995
|
-
function tap ( event ) {
|
996
|
-
|
997
|
-
var location = event.calcPoint, total = 0, to;
|
998
|
-
|
999
|
-
// The tap event shouldn't propagate up and cause 'edge' to run.
|
1000
|
-
event.stopPropagation();
|
1001
|
-
|
1002
|
-
// Add up the handle offsets.
|
1003
|
-
$.each( $Handles, function(){
|
1004
|
-
total += this.offset()[ options.style ];
|
1005
|
-
});
|
1006
|
-
|
1007
|
-
// Find the handle closest to the tapped position.
|
1008
|
-
total = ( location < total/2 || $Handles.length === 1 ) ? 0 : 1;
|
1009
|
-
|
1010
|
-
location -= $Base.offset()[ options.style ];
|
1011
|
-
|
1012
|
-
// Calculate the new position.
|
1013
|
-
to = ( location * 100 ) / baseSize();
|
1014
|
-
|
1015
|
-
if ( !options.events.snap ) {
|
1016
|
-
// Flag the slider as it is now in a transitional state.
|
1017
|
-
// Transition takes 300 ms, so re-enable the slider afterwards.
|
1018
|
-
addClassFor( $Target, Classes[14], 300 );
|
1019
|
-
}
|
1020
|
-
|
1021
|
-
// Find the closest handle and calculate the tapped point.
|
1022
|
-
// The set handle to the new position.
|
1023
|
-
setHandle( $Handles[total], to );
|
1024
|
-
|
1025
|
-
fireEvents(['slide', 'set', 'change']);
|
1026
|
-
|
1027
|
-
if ( options.events.snap ) {
|
1028
|
-
start(event, { handles: [$Handles[total]] });
|
1029
|
-
}
|
1030
|
-
}
|
1031
|
-
|
1032
|
-
// Attach events to several slider parts.
|
1033
|
-
function events ( behaviour ) {
|
1034
|
-
|
1035
|
-
var i, drag;
|
1036
|
-
|
1037
|
-
// Attach the standard drag event to the handles.
|
1038
|
-
if ( !behaviour.fixed ) {
|
1039
|
-
|
1040
|
-
for ( i = 0; i < $Handles.length; i += 1 ) {
|
1041
|
-
|
1042
|
-
// These events are only bound to the visual handle
|
1043
|
-
// element, not the 'real' origin element.
|
1044
|
-
attach ( actions.start, $Handles[i].children(), start, {
|
1045
|
-
handles: [ $Handles[i] ]
|
1046
|
-
});
|
1047
|
-
}
|
1048
|
-
}
|
1049
|
-
|
1050
|
-
// Attach the tap event to the slider base.
|
1051
|
-
if ( behaviour.tap ) {
|
1052
|
-
|
1053
|
-
attach ( actions.start, $Base, tap, {
|
1054
|
-
handles: $Handles
|
1055
|
-
});
|
1056
|
-
}
|
1057
|
-
|
1058
|
-
// Make the range dragable.
|
1059
|
-
if ( behaviour.drag ){
|
1060
|
-
|
1061
|
-
drag = $Base.find( '.' + Classes[7] ).addClass( Classes[10] );
|
1062
|
-
|
1063
|
-
// When the range is fixed, the entire range can
|
1064
|
-
// be dragged by the handles. The handle in the first
|
1065
|
-
// origin will propagate the start event upward,
|
1066
|
-
// but it needs to be bound manually on the other.
|
1067
|
-
if ( behaviour.fixed ) {
|
1068
|
-
drag = drag.add($Base.children().not( drag ).children());
|
1069
|
-
}
|
1070
|
-
|
1071
|
-
attach ( actions.start, drag, start, {
|
1072
|
-
handles: $Handles
|
1073
|
-
});
|
1074
|
-
}
|
1075
|
-
}
|
1076
|
-
|
1077
|
-
|
1078
|
-
// Test suggested values and apply margin, step.
|
1079
|
-
function setHandle ( handle, to, noLimitOption ) {
|
1080
|
-
|
1081
|
-
var trigger = handle[0] !== $Handles[0][0] ? 1 : 0,
|
1082
|
-
lowerMargin = $Locations[0] + options.margin,
|
1083
|
-
upperMargin = $Locations[1] - options.margin,
|
1084
|
-
lowerLimit = $Locations[0] + options.limit,
|
1085
|
-
upperLimit = $Locations[1] - options.limit;
|
1086
|
-
|
1087
|
-
// For sliders with multiple handles,
|
1088
|
-
// limit movement to the other handle.
|
1089
|
-
// Apply the margin option by adding it to the handle positions.
|
1090
|
-
if ( $Handles.length > 1 ) {
|
1091
|
-
to = trigger ? Math.max( to, lowerMargin ) : Math.min( to, upperMargin );
|
1092
|
-
}
|
1093
|
-
|
1094
|
-
// The limit option has the opposite effect, limiting handles to a
|
1095
|
-
// maximum distance from another. Limit must be > 0, as otherwise
|
1096
|
-
// handles would be unmoveable. 'noLimitOption' is set to 'false'
|
1097
|
-
// for the .val() method, except for pass 4/4.
|
1098
|
-
if ( noLimitOption !== false && options.limit && $Handles.length > 1 ) {
|
1099
|
-
to = trigger ? Math.min ( to, lowerLimit ) : Math.max( to, upperLimit );
|
1100
|
-
}
|
1101
|
-
|
1102
|
-
// Handle the step option.
|
1103
|
-
to = $Spectrum.getStep( to );
|
1104
|
-
|
1105
|
-
// Limit to 0/100 for .val input, trim anything beyond 7 digits, as
|
1106
|
-
// JavaScript has some issues in its floating point implementation.
|
1107
|
-
to = limit(parseFloat(to.toFixed(7)));
|
1108
|
-
|
1109
|
-
// Return false if handle can't move.
|
1110
|
-
if ( to === $Locations[trigger] ) {
|
1111
|
-
return false;
|
1112
|
-
}
|
1113
|
-
|
1114
|
-
// Set the handle to the new position.
|
1115
|
-
handle.css( options.style, to + '%' );
|
1116
|
-
|
1117
|
-
// Force proper handle stacking
|
1118
|
-
if ( handle.is(':first-child') ) {
|
1119
|
-
handle.toggleClass(Classes[17], to > 50 );
|
1120
|
-
}
|
1121
|
-
|
1122
|
-
// Update locations.
|
1123
|
-
$Locations[trigger] = to;
|
1124
|
-
|
1125
|
-
// Convert the value to the slider stepping/range.
|
1126
|
-
$Values[trigger] = $Spectrum.fromStepping( to );
|
1127
|
-
|
1128
|
-
linkUpdate(triggerPos[trigger]);
|
1129
|
-
|
1130
|
-
return true;
|
1131
|
-
}
|
1132
|
-
|
1133
|
-
// Loop values from value method and apply them.
|
1134
|
-
function setValues ( count, values ) {
|
1135
|
-
|
1136
|
-
var i, trigger, to;
|
1137
|
-
|
1138
|
-
// With the limit option, we'll need another limiting pass.
|
1139
|
-
if ( options.limit ) {
|
1140
|
-
count += 1;
|
1141
|
-
}
|
1142
|
-
|
1143
|
-
// If there are multiple handles to be set run the setting
|
1144
|
-
// mechanism twice for the first handle, to make sure it
|
1145
|
-
// can be bounced of the second one properly.
|
1146
|
-
for ( i = 0; i < count; i += 1 ) {
|
1147
|
-
|
1148
|
-
trigger = i%2;
|
1149
|
-
|
1150
|
-
// Get the current argument from the array.
|
1151
|
-
to = values[trigger];
|
1152
|
-
|
1153
|
-
// Setting with null indicates an 'ignore'.
|
1154
|
-
// Inputting 'false' is invalid.
|
1155
|
-
if ( to !== null && to !== false ) {
|
1156
|
-
|
1157
|
-
// If a formatted number was passed, attemt to decode it.
|
1158
|
-
if ( typeof to === 'number' ) {
|
1159
|
-
to = String(to);
|
1160
|
-
}
|
1161
|
-
|
1162
|
-
to = options.format.from( to );
|
1163
|
-
|
1164
|
-
// Request an update for all links if the value was invalid.
|
1165
|
-
// Do so too if setting the handle fails.
|
1166
|
-
if ( to === false || isNaN(to) || setHandle( $Handles[trigger], $Spectrum.toStepping( to ), i === (3 - options.dir) ) === false ) {
|
1167
|
-
|
1168
|
-
linkUpdate(triggerPos[trigger]);
|
1169
|
-
}
|
1170
|
-
}
|
1171
|
-
}
|
1172
|
-
}
|
1173
|
-
|
1174
|
-
// Set the slider value.
|
1175
|
-
function valueSet ( input ) {
|
1176
|
-
|
1177
|
-
// LibLink: don't accept new values when currently emitting changes.
|
1178
|
-
if ( $Target[0].LinkIsEmitting ) {
|
1179
|
-
return this;
|
1180
|
-
}
|
1181
|
-
|
1182
|
-
var count, values = asArray( input );
|
1183
|
-
|
1184
|
-
// The RTL settings is implemented by reversing the front-end,
|
1185
|
-
// internal mechanisms are the same.
|
1186
|
-
if ( options.dir && options.handles > 1 ) {
|
1187
|
-
values.reverse();
|
1188
|
-
}
|
1189
|
-
|
1190
|
-
// Animation is optional.
|
1191
|
-
// Make sure the initial values where set before using animated
|
1192
|
-
// placement. (no report, unit testing);
|
1193
|
-
if ( options.animate && $Locations[0] !== -1 ) {
|
1194
|
-
addClassFor( $Target, Classes[14], 300 );
|
1195
|
-
}
|
1196
|
-
|
1197
|
-
// Determine how often to set the handles.
|
1198
|
-
count = $Handles.length > 1 ? 3 : 1;
|
1199
|
-
|
1200
|
-
if ( values.length === 1 ) {
|
1201
|
-
count = 1;
|
1202
|
-
}
|
1203
|
-
|
1204
|
-
setValues ( count, values );
|
1205
|
-
|
1206
|
-
// Fire the 'set' event. As of noUiSlider 7,
|
1207
|
-
// this is no longer optional.
|
1208
|
-
fireEvents(['set']);
|
1209
|
-
|
1210
|
-
return this;
|
1211
|
-
}
|
1212
|
-
|
1213
|
-
// Get the slider value.
|
1214
|
-
function valueGet ( ) {
|
1215
|
-
|
1216
|
-
var i, retour = [];
|
1217
|
-
|
1218
|
-
// Get the value from all handles.
|
1219
|
-
for ( i = 0; i < options.handles; i += 1 ){
|
1220
|
-
retour[i] = options.format.to( $Values[i] );
|
1221
|
-
}
|
1222
|
-
|
1223
|
-
return inSliderOrder( retour );
|
1224
|
-
}
|
1225
|
-
|
1226
|
-
// Destroy the slider and unbind all events.
|
1227
|
-
function destroyTarget ( ) {
|
1228
|
-
|
1229
|
-
// Unbind events on the slider, remove all classes and child elements.
|
1230
|
-
$(this).off(namespace)
|
1231
|
-
.removeClass(Classes.join(' '))
|
1232
|
-
.empty();
|
1233
|
-
|
1234
|
-
delete this.LinkUpdate;
|
1235
|
-
delete this.LinkConfirm;
|
1236
|
-
delete this.LinkDefaultFormatter;
|
1237
|
-
delete this.LinkDefaultFlag;
|
1238
|
-
delete this.reappend;
|
1239
|
-
delete this.vGet;
|
1240
|
-
delete this.vSet;
|
1241
|
-
delete this.getCurrentStep;
|
1242
|
-
delete this.getInfo;
|
1243
|
-
delete this.destroy;
|
1244
|
-
|
1245
|
-
// Return the original options from the closure.
|
1246
|
-
return originalOptions;
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
// Get the current step size for the slider.
|
1250
|
-
function getCurrentStep ( ) {
|
1251
|
-
|
1252
|
-
// Check all locations, map them to their stepping point.
|
1253
|
-
// Get the step point, then find it in the input list.
|
1254
|
-
var retour = $.map($Locations, function( location, index ){
|
1255
|
-
|
1256
|
-
var step = $Spectrum.getApplicableStep( location ),
|
1257
|
-
value = $Values[index],
|
1258
|
-
increment = step[2],
|
1259
|
-
decrement = (value - step[2]) >= step[1] ? step[2] : step[0];
|
1260
|
-
|
1261
|
-
return [[decrement, increment]];
|
1262
|
-
});
|
1263
|
-
|
1264
|
-
// Return values in the proper order.
|
1265
|
-
return inSliderOrder( retour );
|
1266
|
-
}
|
1267
|
-
|
1268
|
-
// Get the original set of options.
|
1269
|
-
function getOriginalOptions ( ) {
|
1270
|
-
return originalOptions;
|
1271
|
-
}
|
1272
|
-
|
1273
|
-
|
1274
|
-
// Initialize slider
|
1275
|
-
|
1276
|
-
// Throw an error if the slider was already initialized.
|
1277
|
-
if ( $Target.hasClass(Classes[0]) ) {
|
1278
|
-
throw new Error('Slider was already initialized.');
|
1279
|
-
}
|
1280
|
-
|
1281
|
-
// Create the base element, initialise HTML and set classes.
|
1282
|
-
// Add handles and links.
|
1283
|
-
$Base = addSlider( options.dir, options.ort, $Target );
|
1284
|
-
$Handles = addHandles( options.handles, options.dir, $Base );
|
1285
|
-
|
1286
|
-
// Set the connect classes.
|
1287
|
-
addConnection ( options.connect, $Target, $Handles );
|
1288
|
-
|
1289
|
-
// Attach user events.
|
1290
|
-
events( options.events );
|
1291
|
-
|
1292
|
-
// Methods
|
1293
|
-
|
1294
|
-
target.vSet = valueSet;
|
1295
|
-
target.vGet = valueGet;
|
1296
|
-
target.destroy = destroyTarget;
|
1297
|
-
|
1298
|
-
target.getCurrentStep = getCurrentStep;
|
1299
|
-
target.getOriginalOptions = getOriginalOptions;
|
1300
|
-
|
1301
|
-
target.getInfo = function(){
|
1302
|
-
return [
|
1303
|
-
$Spectrum,
|
1304
|
-
options.style,
|
1305
|
-
options.ort
|
1306
|
-
];
|
1307
|
-
};
|
1308
|
-
|
1309
|
-
// Use the public value method to set the start values.
|
1310
|
-
$Target.val( options.start );
|
1311
|
-
|
1312
|
-
}
|
1313
|
-
|
1314
|
-
|
1315
|
-
// Run the standard initializer
|
1316
|
-
function initialize ( originalOptions ) {
|
1317
|
-
|
1318
|
-
// Throw error if group is empty.
|
1319
|
-
if ( !this.length ){
|
1320
|
-
throw new Error("noUiSlider: Can't initialize slider on empty selection.");
|
1321
|
-
}
|
1322
|
-
|
1323
|
-
// Test the options once, not for every slider.
|
1324
|
-
var options = testOptions( originalOptions, this );
|
1325
|
-
|
1326
|
-
// Loop all items, and provide a new closed-scope environment.
|
1327
|
-
return this.each(function(){
|
1328
|
-
closure(this, options, originalOptions);
|
1329
|
-
});
|
1330
|
-
}
|
1331
|
-
|
1332
|
-
// Destroy the slider, then re-enter initialization.
|
1333
|
-
function rebuild ( options ) {
|
1334
|
-
|
1335
|
-
return this.each(function(){
|
1336
|
-
|
1337
|
-
// The rebuild flag can be used if the slider wasn't initialized yet.
|
1338
|
-
if ( !this.destroy ) {
|
1339
|
-
$(this).noUiSlider( options );
|
1340
|
-
return;
|
1341
|
-
}
|
1342
|
-
|
1343
|
-
// Get the current values from the slider,
|
1344
|
-
// including the initialization options.
|
1345
|
-
var values = $(this).val(), originalOptions = this.destroy(),
|
1346
|
-
|
1347
|
-
// Extend the previous options with the newly provided ones.
|
1348
|
-
newOptions = $.extend( {}, originalOptions, options );
|
1349
|
-
|
1350
|
-
// Run the standard initializer.
|
1351
|
-
$(this).noUiSlider( newOptions );
|
1352
|
-
|
1353
|
-
// Place Link elements back.
|
1354
|
-
this.reappend();
|
1355
|
-
|
1356
|
-
// If the start option hasn't changed,
|
1357
|
-
// reset the previous values.
|
1358
|
-
if ( originalOptions.start === newOptions.start ) {
|
1359
|
-
$(this).val(values);
|
1360
|
-
}
|
1361
|
-
});
|
1362
|
-
}
|
1363
|
-
|
1364
|
-
// Access the internal getting and setting methods based on argument count.
|
1365
|
-
function value ( ) {
|
1366
|
-
return this[0][ !arguments.length ? 'vGet' : 'vSet' ].apply(this[0], arguments);
|
1367
|
-
}
|
1368
|
-
|
1369
|
-
// Override the .val() method. Test every element. Is it a slider? Go to
|
1370
|
-
// the slider value handling. No? Use the standard method.
|
1371
|
-
// Note how $.fn.val expects 'this' to be an instance of $. For convenience,
|
1372
|
-
// the above 'value' function does too.
|
1373
|
-
$.fn.val = function ( ) {
|
1374
|
-
|
1375
|
-
// this === instanceof $
|
1376
|
-
|
1377
|
-
function valMethod( a ){
|
1378
|
-
return a.hasClass(Classes[0]) ? value : $val;
|
1379
|
-
}
|
1380
|
-
|
1381
|
-
var args = arguments,
|
1382
|
-
first = $(this[0]);
|
1383
|
-
|
1384
|
-
if ( !arguments.length ) {
|
1385
|
-
return valMethod(first).call(first);
|
1386
|
-
}
|
1387
|
-
|
1388
|
-
// Return the set so it remains chainable
|
1389
|
-
return this.each(function(){
|
1390
|
-
valMethod($(this)).apply($(this), args);
|
1391
|
-
});
|
1392
|
-
};
|
1393
|
-
|
1394
|
-
// Extend jQuery/Zepto with the noUiSlider method.
|
1395
|
-
$.fn.noUiSlider = function ( options, rebuildFlag ) {
|
1396
|
-
|
1397
|
-
switch ( options ) {
|
1398
|
-
case 'step': return this[0].getCurrentStep();
|
1399
|
-
case 'options': return this[0].getOriginalOptions();
|
1400
|
-
}
|
1401
|
-
|
1402
|
-
return ( rebuildFlag ? rebuild : initialize ).call(this, options);
|
1403
|
-
};
|
1404
|
-
|
1405
|
-
function getGroup ( $Spectrum, mode, values, stepped ) {
|
1406
|
-
|
1407
|
-
// Use the range.
|
1408
|
-
if ( mode === 'range' || mode === 'steps' ) {
|
1409
|
-
return $Spectrum.xVal;
|
1410
|
-
}
|
1411
|
-
|
1412
|
-
if ( mode === 'count' ) {
|
1413
|
-
|
1414
|
-
// Divide 0 - 100 in 'count' parts.
|
1415
|
-
var spread = ( 100 / (values-1) ), v, i = 0;
|
1416
|
-
values = [];
|
1417
|
-
|
1418
|
-
// List these parts and have them handled as 'positions'.
|
1419
|
-
while ((v=i++*spread) <= 100 ) {
|
1420
|
-
values.push(v);
|
1421
|
-
}
|
1422
|
-
|
1423
|
-
mode = 'positions';
|
1424
|
-
}
|
1425
|
-
|
1426
|
-
if ( mode === 'positions' ) {
|
1427
|
-
|
1428
|
-
// Map all percentages to on-range values.
|
1429
|
-
return $.map(values, function( value ){
|
1430
|
-
return $Spectrum.fromStepping( stepped ? $Spectrum.getStep( value ) : value );
|
1431
|
-
});
|
1432
|
-
}
|
1433
|
-
|
1434
|
-
if ( mode === 'values' ) {
|
1435
|
-
|
1436
|
-
// If the value must be stepped, it needs to be converted to a percentage first.
|
1437
|
-
if ( stepped ) {
|
1438
|
-
|
1439
|
-
return $.map(values, function( value ){
|
1440
|
-
|
1441
|
-
// Convert to percentage, apply step, return to value.
|
1442
|
-
return $Spectrum.fromStepping( $Spectrum.getStep( $Spectrum.toStepping( value ) ) );
|
1443
|
-
});
|
1444
|
-
|
1445
|
-
}
|
1446
|
-
|
1447
|
-
// Otherwise, we can simply use the values.
|
1448
|
-
return values;
|
1449
|
-
}
|
1450
|
-
}
|
1451
|
-
|
1452
|
-
function generateSpread ( $Spectrum, density, mode, group ) {
|
1453
|
-
|
1454
|
-
var originalSpectrumDirection = $Spectrum.direction,
|
1455
|
-
indexes = {},
|
1456
|
-
firstInRange = $Spectrum.xVal[0],
|
1457
|
-
lastInRange = $Spectrum.xVal[$Spectrum.xVal.length-1],
|
1458
|
-
ignoreFirst = false,
|
1459
|
-
ignoreLast = false,
|
1460
|
-
prevPct = 0;
|
1461
|
-
|
1462
|
-
// This function loops the spectrum in an ltr linear fashion,
|
1463
|
-
// while the toStepping method is direction aware. Trick it into
|
1464
|
-
// believing it is ltr.
|
1465
|
-
$Spectrum.direction = 0;
|
1466
|
-
|
1467
|
-
// Create a copy of the group, sort it and filter away all duplicates.
|
1468
|
-
group = unique(group.slice().sort(function(a, b){ return a - b; }));
|
1469
|
-
|
1470
|
-
// Make sure the range starts with the first element.
|
1471
|
-
if ( group[0] !== firstInRange ) {
|
1472
|
-
group.unshift(firstInRange);
|
1473
|
-
ignoreFirst = true;
|
1474
|
-
}
|
1475
|
-
|
1476
|
-
// Likewise for the last one.
|
1477
|
-
if ( group[group.length - 1] !== lastInRange ) {
|
1478
|
-
group.push(lastInRange);
|
1479
|
-
ignoreLast = true;
|
1480
|
-
}
|
1481
|
-
|
1482
|
-
$.each(group, function ( index ) {
|
1483
|
-
|
1484
|
-
// Get the current step and the lower + upper positions.
|
1485
|
-
var step, i, q,
|
1486
|
-
low = group[index],
|
1487
|
-
high = group[index+1],
|
1488
|
-
newPct, pctDifference, pctPos, type,
|
1489
|
-
steps, realSteps, stepsize;
|
1490
|
-
|
1491
|
-
// When using 'steps' mode, use the provided steps.
|
1492
|
-
// Otherwise, we'll step on to the next subrange.
|
1493
|
-
if ( mode === 'steps' ) {
|
1494
|
-
step = $Spectrum.xNumSteps[ index ];
|
1495
|
-
}
|
1496
|
-
|
1497
|
-
// Default to a 'full' step.
|
1498
|
-
if ( !step ) {
|
1499
|
-
step = high-low;
|
1500
|
-
}
|
1501
|
-
|
1502
|
-
// Low can be 0, so test for false. If high is undefined,
|
1503
|
-
// we are at the last subrange. Index 0 is already handled.
|
1504
|
-
if ( low === false || high === undefined ) {
|
1505
|
-
return;
|
1506
|
-
}
|
1507
|
-
|
1508
|
-
// Find all steps in the subrange.
|
1509
|
-
for ( i = low; i <= high; i += step ) {
|
1510
|
-
|
1511
|
-
// Get the percentage value for the current step,
|
1512
|
-
// calculate the size for the subrange.
|
1513
|
-
newPct = $Spectrum.toStepping( i );
|
1514
|
-
pctDifference = newPct - prevPct;
|
1515
|
-
|
1516
|
-
steps = pctDifference / density;
|
1517
|
-
realSteps = Math.round(steps);
|
1518
|
-
|
1519
|
-
// This ratio represents the ammount of percentage-space a point indicates.
|
1520
|
-
// For a density 1 the points/percentage = 1. For density 2, that percentage needs to be re-devided.
|
1521
|
-
// Round the percentage offset to an even number, then divide by two
|
1522
|
-
// to spread the offset on both sides of the range.
|
1523
|
-
stepsize = pctDifference/realSteps;
|
1524
|
-
|
1525
|
-
// Divide all points evenly, adding the correct number to this subrange.
|
1526
|
-
// Run up to <= so that 100% gets a point, event if ignoreLast is set.
|
1527
|
-
for ( q = 1; q <= realSteps; q += 1 ) {
|
1528
|
-
|
1529
|
-
// The ratio between the rounded value and the actual size might be ~1% off.
|
1530
|
-
// Correct the percentage offset by the number of points
|
1531
|
-
// per subrange. density = 1 will result in 100 points on the
|
1532
|
-
// full range, 2 for 50, 4 for 25, etc.
|
1533
|
-
pctPos = prevPct + ( q * stepsize );
|
1534
|
-
indexes[pctPos.toFixed(5)] = ['x', 0];
|
1535
|
-
}
|
1536
|
-
|
1537
|
-
// Determine the point type.
|
1538
|
-
type = ($.inArray(i, group) > -1) ? 1 : ( mode === 'steps' ? 2 : 0 );
|
1539
|
-
|
1540
|
-
// Enforce the 'ignoreFirst' option by overwriting the type for 0.
|
1541
|
-
if ( !index && ignoreFirst && !low ) {
|
1542
|
-
type = 0;
|
1543
|
-
}
|
1544
|
-
|
1545
|
-
if ( !(i === high && ignoreLast)) {
|
1546
|
-
// Mark the 'type' of this point. 0 = plain, 1 = real value, 2 = step value.
|
1547
|
-
indexes[newPct.toFixed(5)] = [i, type];
|
1548
|
-
}
|
1549
|
-
|
1550
|
-
// Update the percentage count.
|
1551
|
-
prevPct = newPct;
|
1552
|
-
}
|
1553
|
-
});
|
1554
|
-
|
1555
|
-
// Reset the spectrum.
|
1556
|
-
$Spectrum.direction = originalSpectrumDirection;
|
1557
|
-
|
1558
|
-
return indexes;
|
1559
|
-
}
|
1560
|
-
|
1561
|
-
function addMarking ( CSSstyle, orientation, direction, spread, filterFunc, formatter ) {
|
1562
|
-
|
1563
|
-
var style = ['horizontal', 'vertical'][orientation],
|
1564
|
-
element = $('<div/>');
|
1565
|
-
|
1566
|
-
element.addClass('noUi-pips noUi-pips-'+style);
|
1567
|
-
|
1568
|
-
function getSize( type, value ){
|
1569
|
-
return [ '-normal', '-large', '-sub' ][(type&&filterFunc) ? filterFunc(value, type) : type];
|
1570
|
-
}
|
1571
|
-
function getTags( offset, source, values ) {
|
1572
|
-
return 'class="' + source + ' ' +
|
1573
|
-
source + '-' + style + ' ' +
|
1574
|
-
source + getSize(values[1], values[0]) +
|
1575
|
-
'" style="' + CSSstyle + ': ' + offset + '%"';
|
1576
|
-
}
|
1577
|
-
function addSpread ( offset, values ){
|
1578
|
-
|
1579
|
-
if ( direction ) {
|
1580
|
-
offset = 100 - offset;
|
1581
|
-
}
|
1582
|
-
|
1583
|
-
// Add a marker for every point
|
1584
|
-
element.append('<div '+getTags(offset, 'noUi-marker', values)+'></div>');
|
1585
|
-
|
1586
|
-
// Values are only appended for points marked '1' or '2'.
|
1587
|
-
if ( values[1] ) {
|
1588
|
-
element.append('<div '+getTags(offset, 'noUi-value', values)+'>' + formatter.to(values[0]) + '</div>');
|
1589
|
-
}
|
1590
|
-
}
|
1591
|
-
|
1592
|
-
// Append all points.
|
1593
|
-
$.each(spread, addSpread);
|
1594
|
-
|
1595
|
-
return element;
|
1596
|
-
}
|
1597
|
-
|
1598
|
-
$.fn.noUiSlider_pips = function ( grid ) {
|
1599
|
-
|
1600
|
-
var mode = grid.mode,
|
1601
|
-
density = grid.density || 1,
|
1602
|
-
filter = grid.filter || false,
|
1603
|
-
values = grid.values || false,
|
1604
|
-
format = grid.format || {
|
1605
|
-
to: Math.round
|
1606
|
-
},
|
1607
|
-
stepped = grid.stepped || false;
|
1608
|
-
|
1609
|
-
return this.each(function(){
|
1610
|
-
|
1611
|
-
var info = this.getInfo(),
|
1612
|
-
group = getGroup( info[0], mode, values, stepped ),
|
1613
|
-
spread = generateSpread( info[0], density, mode, group );
|
1614
|
-
|
1615
|
-
return $(this).append(addMarking(
|
1616
|
-
info[1],
|
1617
|
-
info[2],
|
1618
|
-
info[0].direction,
|
1619
|
-
spread,
|
1620
|
-
filter,
|
1621
|
-
format
|
1622
|
-
));
|
1623
|
-
});
|
1624
|
-
};
|
1625
|
-
|
1626
|
-
}( window.jQuery || window.Zepto ));
|