nouislider-rails 6.2.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +29 -7
- data/lib/nouislider/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.nouislider.js +6 -1291
- data/vendor/assets/javascripts/libLink/jquery.liblink.js +311 -0
- data/vendor/assets/javascripts/nouislider/module.base.js +872 -0
- data/vendor/assets/javascripts/nouislider/module.options.js +269 -0
- data/vendor/assets/javascripts/nouislider/module.range.js +290 -0
- data/vendor/assets/javascripts/nouislider/optional.pips.js +234 -0
- data/vendor/assets/javascripts/wnumb/wNumb.js +335 -0
- data/vendor/assets/stylesheets/jquery.nouislider.css +4 -165
- data/vendor/assets/stylesheets/nouislider/jquery.nouislider.css +165 -0
- data/vendor/assets/stylesheets/nouislider/jquery.nouislider.pips.css +98 -0
- metadata +11 -4
- data/vendor/assets/javascripts/Link.js +0 -389
@@ -1,389 +0,0 @@
|
|
1
|
-
/**@preserve
|
2
|
-
$.Link (part of noUiSlider) - WTFPL */
|
3
|
-
|
4
|
-
/*jslint browser: true */
|
5
|
-
/*jslint sub: true */
|
6
|
-
/*jslint white: true */
|
7
|
-
|
8
|
-
(function( $ ){
|
9
|
-
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
// Throw an error if formatting options are incompatible.
|
13
|
-
function throwEqualError( F, a, b ) {
|
14
|
-
if ( (F[a] || F[b]) && (F[a] === F[b]) ) {
|
15
|
-
throw new Error("(Link) '"+a+"' can't match '"+b+"'.'");
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
// Test in an object is an instance of jQuery or Zepto.
|
20
|
-
function isInstance ( a ) {
|
21
|
-
return a instanceof $ || ( $['zepto'] && $['zepto']['isZ'](a) );
|
22
|
-
}
|
23
|
-
|
24
|
-
var
|
25
|
-
/** @const */ Formatting = [
|
26
|
-
/* 0 */ 'decimals'
|
27
|
-
/* 1 */ ,'mark'
|
28
|
-
/* 2 */ ,'thousand'
|
29
|
-
/* 3 */ ,'prefix'
|
30
|
-
/* 4 */ ,'postfix'
|
31
|
-
/* 5 */ ,'encoder'
|
32
|
-
/* 6 */ ,'decoder'
|
33
|
-
/* 7 */ ,'negative'
|
34
|
-
/* 8 */ ,'negativeBefore'
|
35
|
-
/* 9 */ ,'to'
|
36
|
-
/* 10 */ ,'from'
|
37
|
-
],
|
38
|
-
/** @const */ FormatDefaults = [
|
39
|
-
/* 0 */ 2
|
40
|
-
/* 1 */ ,'.'
|
41
|
-
/* 2 */ ,''
|
42
|
-
/* 3 */ ,''
|
43
|
-
/* 4 */ ,''
|
44
|
-
/* 5 */ ,function(a){ return a; }
|
45
|
-
/* 6 */ ,function(a){ return a; }
|
46
|
-
/* 7 */ ,'-'
|
47
|
-
/* 8 */ ,''
|
48
|
-
/* 9 */ ,function(a){ return a; }
|
49
|
-
/* 10 */ ,function(a){ return a; }
|
50
|
-
];
|
51
|
-
|
52
|
-
|
53
|
-
/** @constructor */
|
54
|
-
function Format( options ){
|
55
|
-
|
56
|
-
// If no settings where provided, the defaults will be loaded.
|
57
|
-
if ( options === undefined ){
|
58
|
-
options = {};
|
59
|
-
}
|
60
|
-
|
61
|
-
if ( typeof options !== 'object' ){
|
62
|
-
throw new Error("(Format) 'format' option must be an object.");
|
63
|
-
}
|
64
|
-
|
65
|
-
var settings = {};
|
66
|
-
|
67
|
-
// Copy all values into a new object.
|
68
|
-
$(Formatting).each(function(i, val){
|
69
|
-
|
70
|
-
if ( options[val] === undefined ){
|
71
|
-
|
72
|
-
settings[val] = FormatDefaults[i];
|
73
|
-
|
74
|
-
// When we aren't loading defaults, validate the entry.
|
75
|
-
} else if ( (typeof options[val]) === (typeof FormatDefaults[i]) ) {
|
76
|
-
|
77
|
-
// Support for up to 7 decimals.
|
78
|
-
// More can't be guaranteed due to floating point issues.
|
79
|
-
if ( val === 'decimals' ){
|
80
|
-
if ( options[val] < 0 || options[val] > 7 ){
|
81
|
-
throw new Error("(Format) 'format.decimals' option must be between 0 and 7.");
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
settings[val] = options[val];
|
86
|
-
|
87
|
-
// If the value isn't valid, emit an error.
|
88
|
-
} else {
|
89
|
-
throw new Error("(Format) 'format."+val+"' must be a " + typeof FormatDefaults[i] + ".");
|
90
|
-
}
|
91
|
-
});
|
92
|
-
|
93
|
-
// Some values can't be extracted from a
|
94
|
-
// string if certain combinations are present.
|
95
|
-
throwEqualError(settings, 'mark', 'thousand');
|
96
|
-
throwEqualError(settings, 'prefix', 'negative');
|
97
|
-
throwEqualError(settings, 'prefix', 'negativeBefore');
|
98
|
-
|
99
|
-
this.settings = settings;
|
100
|
-
}
|
101
|
-
|
102
|
-
// Shorthand for internal value get
|
103
|
-
Format.prototype.v = function ( a ) {
|
104
|
-
return this.settings[a];
|
105
|
-
};
|
106
|
-
|
107
|
-
Format.prototype.to = function ( number ) {
|
108
|
-
|
109
|
-
function reverse ( a ) {
|
110
|
-
return a.split('').reverse().join('');
|
111
|
-
}
|
112
|
-
|
113
|
-
number = this.v('encoder')( number );
|
114
|
-
|
115
|
-
var decimals = this.v('decimals'),
|
116
|
-
negative = '', preNegative = '', base = '', mark = '';
|
117
|
-
|
118
|
-
// Rounding away decimals might cause a value of -0
|
119
|
-
// when using very small ranges. Remove those cases.
|
120
|
-
if ( parseFloat(number.toFixed(decimals)) === 0 ) {
|
121
|
-
number = '0';
|
122
|
-
}
|
123
|
-
|
124
|
-
if ( number < 0 ) {
|
125
|
-
negative = this.v('negative');
|
126
|
-
preNegative = this.v('negativeBefore');
|
127
|
-
}
|
128
|
-
|
129
|
-
// Round to proper decimal count
|
130
|
-
number = Math.abs(number).toFixed(decimals).toString();
|
131
|
-
number = number.split('.');
|
132
|
-
|
133
|
-
// Group numbers in sets of three.
|
134
|
-
if ( this.v('thousand') ) {
|
135
|
-
base = reverse(number[0]).match(/.{1,3}/g);
|
136
|
-
base = reverse(base.join(reverse( this.v('thousand') )));
|
137
|
-
} else {
|
138
|
-
base = number[0];
|
139
|
-
}
|
140
|
-
|
141
|
-
// Ignore the decimal separator if decimals are set to 0.
|
142
|
-
if ( this.v('mark') && number.length > 1 ) {
|
143
|
-
mark = this.v('mark') + number[1];
|
144
|
-
}
|
145
|
-
|
146
|
-
// Return the finalized formatted number.
|
147
|
-
return this.v('to')(preNegative +
|
148
|
-
this.v('prefix') +
|
149
|
-
negative +
|
150
|
-
base +
|
151
|
-
mark +
|
152
|
-
this.v('postfix'));
|
153
|
-
};
|
154
|
-
|
155
|
-
Format.prototype.from = function ( input ) {
|
156
|
-
|
157
|
-
function esc(s){
|
158
|
-
return s.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&');
|
159
|
-
}
|
160
|
-
|
161
|
-
var isNeg;
|
162
|
-
// The set request might want to ignore this handle.
|
163
|
-
// Test for 'undefined' too, as a two-handle slider
|
164
|
-
// can still be set with an integer.
|
165
|
-
if ( input === null || input === undefined ) {
|
166
|
-
return false;
|
167
|
-
}
|
168
|
-
|
169
|
-
input = this.v('from')(input);
|
170
|
-
|
171
|
-
// Remove formatting and set period for float parsing.
|
172
|
-
input = input.toString();
|
173
|
-
|
174
|
-
// Replace the preNegative indicator.
|
175
|
-
isNeg = input.replace(new RegExp('^' + esc( this.v('negativeBefore') )), '');
|
176
|
-
|
177
|
-
// Check if the value changed by removing the negativeBefore symbol.
|
178
|
-
if( input !== isNeg ) {
|
179
|
-
input = isNeg;
|
180
|
-
isNeg = '-';
|
181
|
-
} else {
|
182
|
-
isNeg = '';
|
183
|
-
}
|
184
|
-
|
185
|
-
// If prefix is set and the number is actually prefixed.
|
186
|
-
input = input.replace(new RegExp('^'+esc( this.v('prefix') )), '');
|
187
|
-
|
188
|
-
// Only replace if a negative sign is set.
|
189
|
-
if ( this.v('negative') ) {
|
190
|
-
|
191
|
-
// Reset isNeg to prevent double '-' insertion.
|
192
|
-
isNeg = '';
|
193
|
-
|
194
|
-
// Reset the negative sign to '-'
|
195
|
-
input = input.replace(new RegExp('^'+esc( this.v('negative') )), '-');
|
196
|
-
}
|
197
|
-
|
198
|
-
// Clean the input string
|
199
|
-
input = input
|
200
|
-
// If postfix is set and the number is postfixed.
|
201
|
-
.replace( new RegExp(esc( this.v('postfix') ) + '$'), '')
|
202
|
-
// Remove the separator every three digits.
|
203
|
-
.replace( new RegExp(esc( this.v('thousand') ), 'g'), '')
|
204
|
-
// Set the decimal separator back to period.
|
205
|
-
.replace( this.v('mark'), '.');
|
206
|
-
|
207
|
-
// Run the user defined decoder. Returns input by default.
|
208
|
-
input = this.v('decoder')( parseFloat( isNeg + input ) );
|
209
|
-
|
210
|
-
// Ignore invalid input
|
211
|
-
if (isNaN( input )) {
|
212
|
-
return false;
|
213
|
-
}
|
214
|
-
|
215
|
-
return input;
|
216
|
-
};
|
217
|
-
|
218
|
-
|
219
|
-
/** @expose */
|
220
|
-
/** @constructor */
|
221
|
-
function Link ( entry, update ) {
|
222
|
-
|
223
|
-
if ( typeof entry !== "object" ) {
|
224
|
-
$.error("(Link) Initialize with an object.");
|
225
|
-
}
|
226
|
-
|
227
|
-
// Make sure Link isn't called as a function, in which case
|
228
|
-
// the 'this' scope would be the window.
|
229
|
-
return new Link.prototype.init( entry['target']||function(){}, entry['method'], entry['format']||{}, update );
|
230
|
-
}
|
231
|
-
|
232
|
-
Link.prototype.setTooltip = function ( target, method ) {
|
233
|
-
|
234
|
-
// By default, use the 'html' method.
|
235
|
-
this.method = method || 'html';
|
236
|
-
|
237
|
-
// Use jQuery to create the element
|
238
|
-
this.el = $( target.replace('-tooltip-', '') || '<div/>' )[0];
|
239
|
-
};
|
240
|
-
|
241
|
-
Link.prototype.setHidden = function ( target ) {
|
242
|
-
|
243
|
-
this.method = 'val';
|
244
|
-
|
245
|
-
this.el = document.createElement('input');
|
246
|
-
this.el.name = target;
|
247
|
-
this.el.type = 'hidden';
|
248
|
-
};
|
249
|
-
|
250
|
-
Link.prototype.setField = function ( target ) {
|
251
|
-
|
252
|
-
// Returns nulled array.
|
253
|
-
function at(a,b,c){
|
254
|
-
return [c?a:b, c?b:a];
|
255
|
-
}
|
256
|
-
|
257
|
-
// In IE < 9, .bind() isn't available, need this link in .change().
|
258
|
-
var that = this;
|
259
|
-
|
260
|
-
// Default to .val if this is an input element.
|
261
|
-
this.method = 'val';
|
262
|
-
// Set the slider to a new value on change.
|
263
|
-
this.target = target.on('change', function( e ){
|
264
|
-
that.obj.val(
|
265
|
-
at(null, $(e.target).val(), that.N),
|
266
|
-
{ 'link': that, 'set': true }
|
267
|
-
);
|
268
|
-
});
|
269
|
-
};
|
270
|
-
|
271
|
-
|
272
|
-
// Initialisor
|
273
|
-
/** @constructor */
|
274
|
-
Link.prototype.init = function ( target, method, format, update ) {
|
275
|
-
|
276
|
-
// Write all formatting to this object.
|
277
|
-
// No validation needed, as we'll merge these with the parent
|
278
|
-
// format options first.
|
279
|
-
this.formatting = format;
|
280
|
-
|
281
|
-
// Store the update option.
|
282
|
-
this.update = !update;
|
283
|
-
|
284
|
-
// If target is a string, a new hidden input will be created.
|
285
|
-
if ( typeof target === 'string' && target.indexOf('-tooltip-') === 0 ) {
|
286
|
-
this.setTooltip( target, method );
|
287
|
-
return;
|
288
|
-
}
|
289
|
-
|
290
|
-
// If the string doesn't begin with '-', which is reserved, add a new hidden input.
|
291
|
-
if ( typeof target === 'string' && target.indexOf('-') !== 0 ) {
|
292
|
-
this.setHidden( target );
|
293
|
-
return;
|
294
|
-
}
|
295
|
-
|
296
|
-
// The target can also be a function, which will be called.
|
297
|
-
if ( typeof target === 'function' ) {
|
298
|
-
this.target = false;
|
299
|
-
this.method = target;
|
300
|
-
return;
|
301
|
-
}
|
302
|
-
|
303
|
-
if ( isInstance(target) ) {
|
304
|
-
// If a jQuery/Zepto input element is provided, but no method is set,
|
305
|
-
// the element can assume it needs to respond to 'change'...
|
306
|
-
|
307
|
-
if ( !method ) {
|
308
|
-
|
309
|
-
if ( target.is('input, select, textarea') ) {
|
310
|
-
this.setField( target );
|
311
|
-
return;
|
312
|
-
}
|
313
|
-
|
314
|
-
// If no method is set, and we are not auto-binding an input, default to 'html'.
|
315
|
-
method = 'html';
|
316
|
-
}
|
317
|
-
|
318
|
-
// The method must exist on the element.
|
319
|
-
if ( typeof method === 'function' || (typeof method === 'string' && target[method]) ) {
|
320
|
-
this.method = method;
|
321
|
-
this.target = target;
|
322
|
-
return;
|
323
|
-
}
|
324
|
-
}
|
325
|
-
|
326
|
-
// Nothing matched, throw error.
|
327
|
-
throw new RangeError("(Link) Invalid Link.");
|
328
|
-
};
|
329
|
-
|
330
|
-
// Provides external items with the slider value.
|
331
|
-
Link.prototype.write = function ( value, handle, slider, update ) {
|
332
|
-
|
333
|
-
// Don't synchronize this Link.
|
334
|
-
if ( this.update && update === false ) {
|
335
|
-
return;
|
336
|
-
}
|
337
|
-
|
338
|
-
this.actual = value;
|
339
|
-
|
340
|
-
// Format values for display.
|
341
|
-
value = this.format( value );
|
342
|
-
|
343
|
-
// Store the numerical value.
|
344
|
-
this.saved = value;
|
345
|
-
|
346
|
-
// Branch between serialization to a function or an object.
|
347
|
-
if ( typeof this.method === 'function' ) {
|
348
|
-
// When target is undefined, the target was a function.
|
349
|
-
// In that case, provided the slider as the calling scope.
|
350
|
-
// Use [0] to get the DOM element, not the $ instance.
|
351
|
-
this.method.call( this.target[0] || slider[0], value, handle, slider );
|
352
|
-
} else {
|
353
|
-
this.target[ this.method ]( value, handle, slider );
|
354
|
-
}
|
355
|
-
};
|
356
|
-
|
357
|
-
// Set formatting options.
|
358
|
-
Link.prototype.setFormatting = function ( options ) {
|
359
|
-
this.formatting = new Format($.extend({},
|
360
|
-
options,
|
361
|
-
this.formatting instanceof Format ? this.formatting.settings : this.formatting
|
362
|
-
));
|
363
|
-
};
|
364
|
-
|
365
|
-
Link.prototype.setObject = function ( obj ) {
|
366
|
-
this.obj = obj;
|
367
|
-
};
|
368
|
-
|
369
|
-
Link.prototype.setIndex = function ( index ) {
|
370
|
-
this.N = index;
|
371
|
-
};
|
372
|
-
|
373
|
-
// Parses slider value to user defined display.
|
374
|
-
Link.prototype.format = function ( a ) {
|
375
|
-
return this.formatting.to(a);
|
376
|
-
};
|
377
|
-
|
378
|
-
// Converts a formatted value back to a real number.
|
379
|
-
Link.prototype.getValue = function ( a ) {
|
380
|
-
return this.formatting.from(a);
|
381
|
-
};
|
382
|
-
|
383
|
-
// We can now test for Link.init to be an instance of Link.
|
384
|
-
Link.prototype.init.prototype = Link.prototype;
|
385
|
-
|
386
|
-
/** @expose */
|
387
|
-
$.Link = Link;
|
388
|
-
|
389
|
-
}( window['jQuery'] || window['Zepto'] ));
|