6
6
* Requires: jQuery v1.7+
7
7
*
8
8
* Copyright (c) 2012 Anthony Terrien
9
- * Under MIT and GPL licenses:
10
- * http://www.opensource.org/licenses/mit-license.php
11
- * http://www.gnu.org/licenses/gpl.html
9
+ * Under MIT License (http://www.opensource.org/licenses/mit-license.php)
12
10
*
13
11
* Thanks to vor, eskimoblood, spiffistan, FabrizioC
14
12
*/
141
139
s . v [ k ] = $this . val ( ) ;
142
140
143
141
$this . bind (
144
- 'change keyup '
142
+ 'change blur '
145
143
, function ( ) {
146
144
var val = { } ;
147
145
val [ k ] = $this . val ( ) ;
159
157
( this . v == '' ) && ( this . v = this . o . min ) ;
160
158
161
159
this . $ . bind (
162
- 'change keyup '
160
+ 'change blur '
163
161
, function ( ) {
164
162
s . val ( s . _validate ( s . $ . val ( ) ) ) ;
165
163
}
170
168
( ! this . o . displayInput ) && this . $ . hide ( ) ;
171
169
172
170
// adds needed DOM elements (canvas, div)
173
- this . $c = $ ( document . createElement ( 'canvas' ) ) ;
171
+ this . $c = $ ( document . createElement ( 'canvas' ) ) . attr ( {
172
+ width : this . o . width ,
173
+ height : this . o . height
174
+ } ) ;
175
+
176
+ // wraps all elements in a div
177
+ // add to DOM before Canvas init is triggered
178
+ this . $div = $ ( '<div style="'
179
+ + ( this . o . inline ? 'display:inline;' : '' )
180
+ + 'width:' + this . o . width + 'px;height:' + this . o . height + 'px;'
181
+ + '"></div>' ) ;
182
+
183
+ this . $ . wrap ( this . $div ) . before ( this . $c ) ;
184
+ this . $div = this . $ . parent ( ) ;
185
+
174
186
if ( typeof G_vmlCanvasManager !== 'undefined' ) {
175
187
G_vmlCanvasManager . initElement ( this . $c [ 0 ] ) ;
176
188
}
189
+
177
190
this . c = this . $c [ 0 ] . getContext ? this . $c [ 0 ] . getContext ( '2d' ) : null ;
191
+
178
192
if ( ! this . c ) {
179
193
this . o . error && this . o . error ( ) ;
180
194
return ;
195
209
&& this . o . width . indexOf ( '%' ) ) ;
196
210
this . relativeHeight = ( ( this . o . height % 1 !== 0 )
197
211
&& this . o . height . indexOf ( '%' ) ) ;
198
-
199
212
this . relative = ( this . relativeWidth || this . relativeHeight ) ;
200
213
201
- // wraps all elements in a div
202
- this . $div = $ ( '<div style="'
203
- + ( this . o . inline ? 'display:inline;' : '' )
204
- + '"></div>' ) ;
205
-
206
- this . $ . wrap ( this . $div ) . before ( this . $c ) ;
207
- this . $div = this . $ . parent ( ) ;
208
-
209
214
// computes size and carves the component
210
215
this . _carve ( ) ;
211
216
302
307
e . originalEvent . touches [ s . t ] . pageX ,
303
308
e . originalEvent . touches [ s . t ] . pageY
304
309
) ;
310
+
311
+ if ( v == s . cv ) return ;
312
+
313
+ if (
314
+ s . cH
315
+ && ( s . cH ( v ) === false )
316
+ ) return ;
317
+
305
318
s . change ( s . _validate ( v ) ) ;
306
319
s . _draw ( ) ;
307
320
} ;
319
332
"touchend.k"
320
333
, function ( ) {
321
334
k . c . d . unbind ( 'touchmove.k touchend.k' ) ;
322
-
323
- if (
324
- s . rH
325
- && ( s . rH ( s . cv ) === false )
326
- ) return ;
327
-
328
335
s . val ( s . cv ) ;
329
336
}
330
337
) ;
336
343
337
344
var mouseMove = function ( e ) {
338
345
var v = s . xy2val ( e . pageX , e . pageY ) ;
346
+
347
+ if ( v == s . cv ) return ;
348
+
349
+ if (
350
+ s . cH
351
+ && ( s . cH ( v ) === false )
352
+ ) return ;
353
+
339
354
s . change ( s . _validate ( v ) ) ;
340
355
s . _draw ( ) ;
341
356
} ;
366
381
"mouseup.k"
367
382
, function ( e ) {
368
383
k . c . d . unbind ( 'mousemove.k mouseup.k keyup.k' ) ;
369
-
370
- if (
371
- s . rH
372
- && ( s . rH ( s . cv ) === false )
373
- ) return ;
374
-
375
384
s . val ( s . cv ) ;
376
385
}
377
386
) ;
498
507
) ;
499
508
} ;
500
509
501
- this . val = function ( v ) {
510
+ this . val = function ( v , triggerRelease ) {
502
511
if ( null != v ) {
512
+
513
+ if (
514
+ triggerRelease !== false
515
+ && ( v != this . v )
516
+ && this . rH
517
+ && ( this . rH ( v ) === false )
518
+ ) return ;
519
+
503
520
this . cv = this . o . stopper ? max ( min ( v , this . o . max ) , this . o . min ) : v ;
504
- this . v = this . cv ;
521
+ this . v = this . cv ;
505
522
this . $ . val ( this . v ) ;
506
523
this . _draw ( ) ;
507
524
} else {
537
554
// bind MouseWheel
538
555
var s = this , mwTimerStop , mwTimerRelease ,
539
556
mw = function ( e ) {
540
- e . preventDefault ( ) ;
541
-
542
- var ori = e . originalEvent
543
- , deltaX = ori . detail || ori . wheelDeltaX
544
- , deltaY = ori . detail || ori . wheelDeltaY
545
- , v = s . _validate ( s . $ . val ( ) )
546
- + ( deltaX > 0 || deltaY > 0 ? s . o . step : deltaX < 0 || deltaY < 0 ? - s . o . step : 0 ) ;
547
-
548
- v = max ( min ( v , s . o . max ) , s . o . min ) ;
549
-
550
- s . val ( v ) ;
551
-
552
- if ( s . rH ) {
553
- // Handle mousewheel stop
554
- clearTimeout ( mwTimerStop ) ;
555
- mwTimerStop = setTimeout ( function ( ) {
556
- s . rH ( v ) ;
557
- mwTimerStop = null ;
558
- } , 100 ) ;
559
-
560
- // Handle mousewheel releases
561
- if ( ! mwTimerRelease ) {
562
- mwTimerRelease = setTimeout ( function ( ) {
563
- if ( mwTimerStop ) s . rH ( v ) ;
564
- mwTimerRelease = null ;
565
- } , 200 ) ;
566
- }
567
- }
557
+ e . preventDefault ( ) ;
558
+
559
+ var ori = e . originalEvent
560
+ , deltaX = ori . detail || ori . wheelDeltaX
561
+ , deltaY = ori . detail || ori . wheelDeltaY
562
+ , v = s . _validate ( s . $ . val ( ) )
563
+ + ( deltaX > 0 || deltaY > 0 ? s . o . step : deltaX < 0 || deltaY < 0 ? - s . o . step : 0 ) ;
564
+
565
+ v = max ( min ( v , s . o . max ) , s . o . min ) ;
566
+
567
+ s . val ( v , false ) ;
568
+
569
+ if ( s . rH ) {
570
+ // Handle mousewheel stop
571
+ clearTimeout ( mwTimerStop ) ;
572
+ mwTimerStop = setTimeout ( function ( ) {
573
+ s . rH ( v ) ;
574
+ mwTimerStop = null ;
575
+ } , 100 ) ;
576
+
577
+ // Handle mousewheel releases
578
+ if ( ! mwTimerRelease ) {
579
+ mwTimerRelease = setTimeout ( function ( ) {
580
+ if ( mwTimerStop ) s . rH ( v ) ;
581
+ mwTimerRelease = null ;
582
+ } , 200 ) ;
568
583
}
584
+ }
585
+ }
569
586
, kval , to , m = 1 , kv = { 37 :- s . o . step , 38 :s . o . step , 39 :s . o . step , 40 :- s . o . step } ;
570
587
571
588
this . $
603
620
604
621
// long time keydown speed-up
605
622
to = window . setTimeout (
606
- function ( ) { m *= 2 ; }
607
- , 30
623
+ function ( ) { m *= 2 ; } , 30
608
624
) ;
609
625
}
610
626
}
691
707
} ;
692
708
693
709
this . change = function ( v ) {
694
- if ( v == this . cv ) return ;
695
710
this . cv = v ;
696
- if (
697
- this . cH
698
- && ( this . cH ( v ) === false )
699
- ) return ;
711
+ this . $ . val ( v ) ;
700
712
} ;
701
713
702
714
this . angle = function ( v ) {
761
773
) . parent ( ) ;
762
774
} ;
763
775
764
- } ) ( jQuery ) ;
776
+ } ) ( jQuery ) ;
0 commit comments