Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.slider.js
1
/*
2
 * jQuery UI Slider 1.8.11
1
/*!
2
 * jQuery UI Slider 1.10.2
3
 * http://jqueryui.com
3 4
 *
4
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
5
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
6 7
 * http://jquery.org/license
7 8
 *
8
 * http://docs.jquery.com/UI/Slider
9
 * http://api.jqueryui.com/slider/
9 10
 *
10 11
 * Depends:
11 12
 *	jquery.ui.core.js
......
19 20
var numPages = 5;
20 21

  
21 22
$.widget( "ui.slider", $.ui.mouse, {
22

  
23
	version: "1.10.2",
23 24
	widgetEventPrefix: "slide",
24 25

  
25 26
	options: {
......
31 32
		range: false,
32 33
		step: 1,
33 34
		value: 0,
34
		values: null
35
		values: null,
36

  
37
		// callbacks
38
		change: null,
39
		slide: null,
40
		start: null,
41
		stop: null
35 42
	},
36 43

  
37 44
	_create: function() {
38
		var self = this,
39
			o = this.options;
40

  
41 45
		this._keySliding = false;
42 46
		this._mouseSliding = false;
43 47
		this._animateOff = true;
......
50 54
				" ui-slider-" + this.orientation +
51 55
				" ui-widget" +
52 56
				" ui-widget-content" +
53
				" ui-corner-all" );
54
		
55
		if ( o.disabled ) {
56
			this.element.addClass( "ui-slider-disabled ui-disabled" );
57
		}
57
				" ui-corner-all");
58 58

  
59
		this.range = $([]);
59
		this._refresh();
60
		this._setOption( "disabled", this.options.disabled );
60 61

  
61
		if ( o.range ) {
62
			if ( o.range === true ) {
63
				this.range = $( "<div></div>" );
64
				if ( !o.values ) {
65
					o.values = [ this._valueMin(), this._valueMin() ];
66
				}
67
				if ( o.values.length && o.values.length !== 2 ) {
68
					o.values = [ o.values[0], o.values[0] ];
69
				}
70
			} else {
71
				this.range = $( "<div></div>" );
72
			}
62
		this._animateOff = false;
63
	},
73 64

  
74
			this.range
75
				.appendTo( this.element )
76
				.addClass( "ui-slider-range" );
65
	_refresh: function() {
66
		this._createRange();
67
		this._createHandles();
68
		this._setupEvents();
69
		this._refreshValue();
70
	},
77 71

  
78
			if ( o.range === "min" || o.range === "max" ) {
79
				this.range.addClass( "ui-slider-range-" + o.range );
80
			}
72
	_createHandles: function() {
73
		var i, handleCount,
74
			options = this.options,
75
			existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
76
			handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
77
			handles = [];
81 78

  
82
			// note: this isn't the most fittingly semantic framework class for this element,
83
			// but worked best visually with a variety of themes
84
			this.range.addClass( "ui-widget-header" );
85
		}
79
		handleCount = ( options.values && options.values.length ) || 1;
86 80

  
87
		if ( $( ".ui-slider-handle", this.element ).length === 0 ) {
88
			$( "<a href='#'></a>" )
89
				.appendTo( this.element )
90
				.addClass( "ui-slider-handle" );
81
		if ( existingHandles.length > handleCount ) {
82
			existingHandles.slice( handleCount ).remove();
83
			existingHandles = existingHandles.slice( 0, handleCount );
91 84
		}
92 85

  
93
		if ( o.values && o.values.length ) {
94
			while ( $(".ui-slider-handle", this.element).length < o.values.length ) {
95
				$( "<a href='#'></a>" )
96
					.appendTo( this.element )
97
					.addClass( "ui-slider-handle" );
98
			}
86
		for ( i = existingHandles.length; i < handleCount; i++ ) {
87
			handles.push( handle );
99 88
		}
100 89

  
101
		this.handles = $( ".ui-slider-handle", this.element )
102
			.addClass( "ui-state-default" +
103
				" ui-corner-all" );
90
		this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) );
104 91

  
105 92
		this.handle = this.handles.eq( 0 );
106 93

  
107
		this.handles.add( this.range ).filter( "a" )
108
			.click(function( event ) {
109
				event.preventDefault();
110
			})
111
			.hover(function() {
112
				if ( !o.disabled ) {
113
					$( this ).addClass( "ui-state-hover" );
114
				}
115
			}, function() {
116
				$( this ).removeClass( "ui-state-hover" );
117
			})
118
			.focus(function() {
119
				if ( !o.disabled ) {
120
					$( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
121
					$( this ).addClass( "ui-state-focus" );
122
				} else {
123
					$( this ).blur();
124
				}
125
			})
126
			.blur(function() {
127
				$( this ).removeClass( "ui-state-focus" );
128
			});
129

  
130 94
		this.handles.each(function( i ) {
131
			$( this ).data( "index.ui-slider-handle", i );
95
			$( this ).data( "ui-slider-handle-index", i );
132 96
		});
97
	},
133 98

  
134
		this.handles
135
			.keydown(function( event ) {
136
				var ret = true,
137
					index = $( this ).data( "index.ui-slider-handle" ),
138
					allowed,
139
					curVal,
140
					newVal,
141
					step;
142
	
143
				if ( self.options.disabled ) {
144
					return;
145
				}
146
	
147
				switch ( event.keyCode ) {
148
					case $.ui.keyCode.HOME:
149
					case $.ui.keyCode.END:
150
					case $.ui.keyCode.PAGE_UP:
151
					case $.ui.keyCode.PAGE_DOWN:
152
					case $.ui.keyCode.UP:
153
					case $.ui.keyCode.RIGHT:
154
					case $.ui.keyCode.DOWN:
155
					case $.ui.keyCode.LEFT:
156
						ret = false;
157
						if ( !self._keySliding ) {
158
							self._keySliding = true;
159
							$( this ).addClass( "ui-state-active" );
160
							allowed = self._start( event, index );
161
							if ( allowed === false ) {
162
								return;
163
							}
164
						}
165
						break;
166
				}
167
	
168
				step = self.options.step;
169
				if ( self.options.values && self.options.values.length ) {
170
					curVal = newVal = self.values( index );
171
				} else {
172
					curVal = newVal = self.value();
173
				}
174
	
175
				switch ( event.keyCode ) {
176
					case $.ui.keyCode.HOME:
177
						newVal = self._valueMin();
178
						break;
179
					case $.ui.keyCode.END:
180
						newVal = self._valueMax();
181
						break;
182
					case $.ui.keyCode.PAGE_UP:
183
						newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) );
184
						break;
185
					case $.ui.keyCode.PAGE_DOWN:
186
						newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) );
187
						break;
188
					case $.ui.keyCode.UP:
189
					case $.ui.keyCode.RIGHT:
190
						if ( curVal === self._valueMax() ) {
191
							return;
192
						}
193
						newVal = self._trimAlignValue( curVal + step );
194
						break;
195
					case $.ui.keyCode.DOWN:
196
					case $.ui.keyCode.LEFT:
197
						if ( curVal === self._valueMin() ) {
198
							return;
199
						}
200
						newVal = self._trimAlignValue( curVal - step );
201
						break;
202
				}
203
	
204
				self._slide( event, index, newVal );
205
	
206
				return ret;
207
	
208
			})
209
			.keyup(function( event ) {
210
				var index = $( this ).data( "index.ui-slider-handle" );
211
	
212
				if ( self._keySliding ) {
213
					self._keySliding = false;
214
					self._stop( event, index );
215
					self._change( event, index );
216
					$( this ).removeClass( "ui-state-active" );
99
	_createRange: function() {
100
		var options = this.options,
101
			classes = "";
102

  
103
		if ( options.range ) {
104
			if ( options.range === true ) {
105
				if ( !options.values ) {
106
					options.values = [ this._valueMin(), this._valueMin() ];
107
				} else if ( options.values.length && options.values.length !== 2 ) {
108
					options.values = [ options.values[0], options.values[0] ];
109
				} else if ( $.isArray( options.values ) ) {
110
					options.values = options.values.slice(0);
217 111
				}
218
	
219
			});
112
			}
220 113

  
221
		this._refreshValue();
114
			if ( !this.range || !this.range.length ) {
115
				this.range = $( "<div></div>" )
116
					.appendTo( this.element );
222 117

  
223
		this._animateOff = false;
118
				classes = "ui-slider-range" +
119
				// note: this isn't the most fittingly semantic framework class for this element,
120
				// but worked best visually with a variety of themes
121
				" ui-widget-header ui-corner-all";
122
			} else {
123
				this.range.removeClass( "ui-slider-range-min ui-slider-range-max" )
124
					// Handle range switching from true to min/max
125
					.css({
126
						"left": "",
127
						"bottom": ""
128
					});
129
			}
130

  
131
			this.range.addClass( classes +
132
				( ( options.range === "min" || options.range === "max" ) ? " ui-slider-range-" + options.range : "" ) );
133
		} else {
134
			this.range = $([]);
135
		}
136
	},
137

  
138
	_setupEvents: function() {
139
		var elements = this.handles.add( this.range ).filter( "a" );
140
		this._off( elements );
141
		this._on( elements, this._handleEvents );
142
		this._hoverable( elements );
143
		this._focusable( elements );
224 144
	},
225 145

  
226
	destroy: function() {
146
	_destroy: function() {
227 147
		this.handles.remove();
228 148
		this.range.remove();
229 149

  
......
231 151
			.removeClass( "ui-slider" +
232 152
				" ui-slider-horizontal" +
233 153
				" ui-slider-vertical" +
234
				" ui-slider-disabled" +
235 154
				" ui-widget" +
236 155
				" ui-widget-content" +
237
				" ui-corner-all" )
238
			.removeData( "slider" )
239
			.unbind( ".slider" );
156
				" ui-corner-all" );
240 157

  
241 158
		this._mouseDestroy();
242

  
243
		return this;
244 159
	},
245 160

  
246 161
	_mouseCapture: function( event ) {
247
		var o = this.options,
248
			position,
249
			normValue,
250
			distance,
251
			closestHandle,
252
			self,
253
			index,
254
			allowed,
255
			offset,
256
			mouseOverHandle;
162
		var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,
163
			that = this,
164
			o = this.options;
257 165

  
258 166
		if ( o.disabled ) {
259 167
			return false;
......
268 176
		position = { x: event.pageX, y: event.pageY };
269 177
		normValue = this._normValueFromMouse( position );
270 178
		distance = this._valueMax() - this._valueMin() + 1;
271
		self = this;
272 179
		this.handles.each(function( i ) {
273
			var thisDistance = Math.abs( normValue - self.values(i) );
274
			if ( distance > thisDistance ) {
180
			var thisDistance = Math.abs( normValue - that.values(i) );
181
			if (( distance > thisDistance ) ||
182
				( distance === thisDistance &&
183
					(i === that._lastChangedValue || that.values(i) === o.min ))) {
275 184
				distance = thisDistance;
276 185
				closestHandle = $( this );
277 186
				index = i;
278 187
			}
279 188
		});
280 189

  
281
		// workaround for bug #3736 (if both handles of a range are at 0,
282
		// the first is always used as the one with least distance,
283
		// and moving it is obviously prevented by preventing negative ranges)
284
		if( o.range === true && this.values(1) === o.min ) {
285
			index += 1;
286
			closestHandle = $( this.handles[index] );
287
		}
288

  
289 190
		allowed = this._start( event, index );
290 191
		if ( allowed === false ) {
291 192
			return false;
292 193
		}
293 194
		this._mouseSliding = true;
294 195

  
295
		self._handleIndex = index;
196
		this._handleIndex = index;
296 197

  
297 198
		closestHandle
298 199
			.addClass( "ui-state-active" )
299 200
			.focus();
300
		
201

  
301 202
		offset = closestHandle.offset();
302
		mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
203
		mouseOverHandle = !$( event.target ).parents().addBack().is( ".ui-slider-handle" );
303 204
		this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
304 205
			left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
305 206
			top: event.pageY - offset.top -
......
316 217
		return true;
317 218
	},
318 219

  
319
	_mouseStart: function( event ) {
220
	_mouseStart: function() {
320 221
		return true;
321 222
	},
322 223

  
323 224
	_mouseDrag: function( event ) {
324 225
		var position = { x: event.pageX, y: event.pageY },
325 226
			normValue = this._normValueFromMouse( position );
326
		
227

  
327 228
		this._slide( event, this._handleIndex, normValue );
328 229

  
329 230
		return false;
......
342 243

  
343 244
		return false;
344 245
	},
345
	
246

  
346 247
	_detectOrientation: function() {
347 248
		this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
348 249
	},
......
399 300
		if ( this.options.values && this.options.values.length ) {
400 301
			otherVal = this.values( index ? 0 : 1 );
401 302

  
402
			if ( ( this.options.values.length === 2 && this.options.range === true ) && 
303
			if ( ( this.options.values.length === 2 && this.options.range === true ) &&
403 304
					( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
404 305
				) {
405 306
				newVal = otherVal;
......
457 358
				uiHash.values = this.values();
458 359
			}
459 360

  
361
			//store the last changed value index for reference when handles overlap
362
			this._lastChangedValue = index;
363

  
460 364
			this._trigger( "change", event, uiHash );
461 365
		}
462 366
	},
......
466 370
			this.options.value = this._trimAlignValue( newValue );
467 371
			this._refreshValue();
468 372
			this._change( null, 0 );
373
			return;
469 374
		}
470 375

  
471 376
		return this._value();
......
480 385
			this.options.values[ index ] = this._trimAlignValue( newValue );
481 386
			this._refreshValue();
482 387
			this._change( null, index );
388
			return;
483 389
		}
484 390

  
485 391
		if ( arguments.length ) {
......
507 413
		var i,
508 414
			valsLength = 0;
509 415

  
416
		if ( key === "range" && this.options.range === true ) {
417
			if ( value === "min" ) {
418
				this.options.value = this._values( 0 );
419
				this.options.values = null;
420
			} else if ( value === "max" ) {
421
				this.options.value = this._values( this.options.values.length-1 );
422
				this.options.values = null;
423
			}
424
		}
425

  
510 426
		if ( $.isArray( this.options.values ) ) {
511 427
			valsLength = this.options.values.length;
512 428
		}
......
514 430
		$.Widget.prototype._setOption.apply( this, arguments );
515 431

  
516 432
		switch ( key ) {
517
			case "disabled":
518
				if ( value ) {
519
					this.handles.filter( ".ui-state-focus" ).blur();
520
					this.handles.removeClass( "ui-state-hover" );
521
					this.handles.attr( "disabled", "disabled" );
522
					this.element.addClass( "ui-disabled" );
523
				} else {
524
					this.handles.removeAttr( "disabled" );
525
					this.element.removeClass( "ui-disabled" );
526
				}
527
				break;
528 433
			case "orientation":
529 434
				this._detectOrientation();
530 435
				this.element
......
546 451
				}
547 452
				this._animateOff = false;
548 453
				break;
454
			case "min":
455
			case "max":
456
				this._animateOff = true;
457
				this._refreshValue();
458
				this._animateOff = false;
459
				break;
460
			case "range":
461
				this._animateOff = true;
462
				this._refresh();
463
				this._animateOff = false;
464
				break;
549 465
		}
550 466
	},
551 467

  
......
571 487
			val = this._trimAlignValue( val );
572 488

  
573 489
			return val;
574
		} else {
490
		} else if ( this.options.values && this.options.values.length ) {
575 491
			// .slice() creates a copy of the array
576 492
			// this copy gets trimmed by min and max and then returned
577 493
			vals = this.options.values.slice();
......
580 496
			}
581 497

  
582 498
			return vals;
499
		} else {
500
			return [];
583 501
		}
584 502
	},
585
	
503

  
586 504
	// returns the step-aligned value that val is closest to, between (inclusive) min and max
587 505
	_trimAlignValue: function( val ) {
588 506
		if ( val <= this._valueMin() ) {
......
592 510
			return this._valueMax();
593 511
		}
594 512
		var step = ( this.options.step > 0 ) ? this.options.step : 1,
595
			valModStep = (val - this._valueMin()) % step;
513
			valModStep = (val - this._valueMin()) % step,
596 514
			alignValue = val - valModStep;
597 515

  
598 516
		if ( Math.abs(valModStep) * 2 >= step ) {
......
611 529
	_valueMax: function() {
612 530
		return this.options.max;
613 531
	},
614
	
532

  
615 533
	_refreshValue: function() {
616
		var oRange = this.options.range,
534
		var lastValPercent, valPercent, value, valueMin, valueMax,
535
			oRange = this.options.range,
617 536
			o = this.options,
618
			self = this,
537
			that = this,
619 538
			animate = ( !this._animateOff ) ? o.animate : false,
620
			valPercent,
621
			_set = {},
622
			lastValPercent,
623
			value,
624
			valueMin,
625
			valueMax;
539
			_set = {};
626 540

  
627 541
		if ( this.options.values && this.options.values.length ) {
628
			this.handles.each(function( i, j ) {
629
				valPercent = ( self.values(i) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100;
630
				_set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
542
			this.handles.each(function( i ) {
543
				valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100;
544
				_set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
631 545
				$( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
632
				if ( self.options.range === true ) {
633
					if ( self.orientation === "horizontal" ) {
546
				if ( that.options.range === true ) {
547
					if ( that.orientation === "horizontal" ) {
634 548
						if ( i === 0 ) {
635
							self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
549
							that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
636 550
						}
637 551
						if ( i === 1 ) {
638
							self.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
552
							that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
639 553
						}
640 554
					} else {
641 555
						if ( i === 0 ) {
642
							self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
556
							that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
643 557
						}
644 558
						if ( i === 1 ) {
645
							self.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
559
							that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
646 560
						}
647 561
					}
648 562
				}
......
655 569
			valPercent = ( valueMax !== valueMin ) ?
656 570
					( value - valueMin ) / ( valueMax - valueMin ) * 100 :
657 571
					0;
658
			_set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
572
			_set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
659 573
			this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
660 574

  
661 575
			if ( oRange === "min" && this.orientation === "horizontal" ) {
......
671 585
				this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
672 586
			}
673 587
		}
674
	}
588
	},
675 589

  
676
});
590
	_handleEvents: {
591
		keydown: function( event ) {
592
			/*jshint maxcomplexity:25*/
593
			var allowed, curVal, newVal, step,
594
				index = $( event.target ).data( "ui-slider-handle-index" );
595

  
596
			switch ( event.keyCode ) {
597
				case $.ui.keyCode.HOME:
598
				case $.ui.keyCode.END:
599
				case $.ui.keyCode.PAGE_UP:
600
				case $.ui.keyCode.PAGE_DOWN:
601
				case $.ui.keyCode.UP:
602
				case $.ui.keyCode.RIGHT:
603
				case $.ui.keyCode.DOWN:
604
				case $.ui.keyCode.LEFT:
605
					event.preventDefault();
606
					if ( !this._keySliding ) {
607
						this._keySliding = true;
608
						$( event.target ).addClass( "ui-state-active" );
609
						allowed = this._start( event, index );
610
						if ( allowed === false ) {
611
							return;
612
						}
613
					}
614
					break;
615
			}
616

  
617
			step = this.options.step;
618
			if ( this.options.values && this.options.values.length ) {
619
				curVal = newVal = this.values( index );
620
			} else {
621
				curVal = newVal = this.value();
622
			}
623

  
624
			switch ( event.keyCode ) {
625
				case $.ui.keyCode.HOME:
626
					newVal = this._valueMin();
627
					break;
628
				case $.ui.keyCode.END:
629
					newVal = this._valueMax();
630
					break;
631
				case $.ui.keyCode.PAGE_UP:
632
					newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
633
					break;
634
				case $.ui.keyCode.PAGE_DOWN:
635
					newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
636
					break;
637
				case $.ui.keyCode.UP:
638
				case $.ui.keyCode.RIGHT:
639
					if ( curVal === this._valueMax() ) {
640
						return;
641
					}
642
					newVal = this._trimAlignValue( curVal + step );
643
					break;
644
				case $.ui.keyCode.DOWN:
645
				case $.ui.keyCode.LEFT:
646
					if ( curVal === this._valueMin() ) {
647
						return;
648
					}
649
					newVal = this._trimAlignValue( curVal - step );
650
					break;
651
			}
652

  
653
			this._slide( event, index, newVal );
654
		},
655
		click: function( event ) {
656
			event.preventDefault();
657
		},
658
		keyup: function( event ) {
659
			var index = $( event.target ).data( "ui-slider-handle-index" );
660

  
661
			if ( this._keySliding ) {
662
				this._keySliding = false;
663
				this._stop( event, index );
664
				this._change( event, index );
665
				$( event.target ).removeClass( "ui-state-active" );
666
			}
667
		}
668
	}
677 669

  
678
$.extend( $.ui.slider, {
679
	version: "1.8.11"
680 670
});
681 671

  
682 672
}(jQuery));

Formats disponibles : Unified diff