@@ -5,20 +5,14 @@ $.Link (part of noUiSlider) - WTFPL */
5
5
/*jslint sub: true */
6
6
/*jslint white: true */
7
7
8
- // ==ClosureCompiler==
9
- // @externs_url http://refreshless.com/externs/jquery-1.8.js
10
- // @compilation_level ADVANCED_OPTIMIZATIONS
11
- // @warning_level VERBOSE
12
- // ==/ClosureCompiler==
13
-
14
8
( function ( $ ) {
15
9
16
10
'use strict' ;
17
11
18
12
// Throw an error if formatting options are incompatible.
19
13
function throwEqualError ( F , a , b ) {
20
14
if ( ( F [ a ] || F [ b ] ) && ( F [ a ] === F [ b ] ) ) {
21
- throwError ( "(Link) '" + a + "' can't match '" + b + "'.'" ) ;
15
+ throw new Error ( "(Link) '" + a + "' can't match '" + b + "'.'" ) ;
22
16
}
23
17
}
24
18
65
59
}
66
60
67
61
if ( typeof options !== 'object' ) {
68
- throwError ( "(Format) 'format' option must be an object." ) ;
62
+ throw new Error ( "(Format) 'format' option must be an object." ) ;
69
63
}
70
64
71
65
var settings = { } ;
84
78
// More can't be guaranteed due to floating point issues.
85
79
if ( val === 'decimals' ) {
86
80
if ( options [ val ] < 0 || options [ val ] > 7 ) {
87
- throwError ( "(Format) 'format.decimals' option must be between 0 and 7." ) ;
81
+ throw new Error ( "(Format) 'format.decimals' option must be between 0 and 7." ) ;
88
82
}
89
83
}
90
84
91
85
settings [ val ] = options [ val ] ;
92
86
93
87
// If the value isn't valid, emit an error.
94
88
} else {
95
- throwError ( "(Format) 'format." + val + "' must be a " + typeof FormatDefaults [ i ] + "." ) ;
89
+ throw new Error ( "(Format) 'format." + val + "' must be a " + typeof FormatDefaults [ i ] + "." ) ;
96
90
}
97
91
} ) ;
98
92
@@ -118,23 +112,24 @@ var
118
112
119
113
number = this . v ( 'encoder' ) ( number ) ;
120
114
121
- var negative = '' , preNegative = '' , base = '' , mark = '' ;
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
+ }
122
123
123
124
if ( number < 0 ) {
124
125
negative = this . v ( 'negative' ) ;
125
126
preNegative = this . v ( 'negativeBefore' ) ;
126
127
}
127
128
128
129
// Round to proper decimal count
129
- number = Math . abs ( number ) . toFixed ( this . v ( ' decimals' ) ) . toString ( ) ;
130
+ number = Math . abs ( number ) . toFixed ( decimals ) . toString ( ) ;
130
131
number = number . split ( '.' ) ;
131
132
132
- // Rounding away decimals might cause a value of -0
133
- // when using very small ranges. Remove those cases.
134
- if ( parseFloat ( number ) === 0 ) {
135
- number [ 0 ] = '0' ;
136
- }
137
-
138
133
// Group numbers in sets of three.
139
134
if ( this . v ( 'thousand' ) ) {
140
135
base = reverse ( number [ 0 ] ) . match ( / .{ 1 , 3 } / g) ;
@@ -167,10 +162,12 @@ var
167
162
// The set request might want to ignore this handle.
168
163
// Test for 'undefined' too, as a two-handle slider
169
164
// can still be set with an integer.
170
- if ( input === null || input === undefined ) {
165
+ if ( input === null || input === undefined ) {
171
166
return false ;
172
167
}
173
168
169
+ input = this . v ( 'from' ) ( input ) ;
170
+
174
171
// Remove formatting and set period for float parsing.
175
172
input = input . toString ( ) ;
176
173
189
186
input = input . replace ( new RegExp ( '^' + esc ( this . v ( 'prefix' ) ) ) , '' ) ;
190
187
191
188
// Only replace if a negative sign is set.
192
- if ( this . v [ 'negative' ] ) {
189
+ if ( this . v ( 'negative' ) ) {
193
190
194
191
// Reset isNeg to prevent double '-' insertion.
195
192
isNeg = '' ;
215
212
return false ;
216
213
}
217
214
218
- return this . v ( 'from' ) ( input ) ;
215
+ return input ;
219
216
} ;
220
217
221
218
273
270
274
271
275
272
// Initialisor
273
+ /** @constructor */
276
274
Link . prototype . init = function ( target , method , format , update ) {
277
275
278
276
// Write all formatting to this object.
291
289
292
290
// If the string doesn't begin with '-', which is reserved, add a new hidden input.
293
291
if ( typeof target === 'string' && target . indexOf ( '-' ) !== 0 ) {
294
- this . setHidden ( target , method ) ;
292
+ this . setHidden ( target ) ;
295
293
return ;
296
294
}
297
295
327
325
328
326
// Nothing matched, throw error.
329
327
throw new RangeError ( "(Link) Invalid Link." ) ;
330
- }
328
+ } ;
331
329
332
330
// Provides external items with the slider value.
333
331
Link . prototype . write = function ( value , handle , slider , update ) {
@@ -358,16 +356,19 @@ var
358
356
359
357
// Set formatting options.
360
358
Link . prototype . setFormatting = function ( options ) {
361
- this . formatting = new Format ( $ . extend ( { } , options , this . formatting ) ) ;
359
+ this . formatting = new Format ( $ . extend ( { } ,
360
+ options ,
361
+ this . formatting instanceof Format ? this . formatting . settings : this . formatting
362
+ ) ) ;
362
363
} ;
363
364
364
365
Link . prototype . setObject = function ( obj ) {
365
366
this . obj = obj ;
366
- }
367
+ } ;
367
368
368
369
Link . prototype . setIndex = function ( index ) {
369
370
this . N = index ;
370
- }
371
+ } ;
371
372
372
373
// Parses slider value to user defined display.
373
374
Link . prototype . format = function ( a ) {
0 commit comments