PageSourceSearch

https://www.cefaly.com/wp-content/plugins/quiz-master-next/js/jquery.ui.slider-rtl.js?ver=11.2.6

js cefaly.com collected 2026-09-25 04:30:38 UTC 18,877 bytes, 711 lines download raw bytes

1/*
2 * jQuery UI Slider 1.8.9.rtl.1
3 *
4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
7 *
8 * http://docs.jquery.com/UI/Slider
9 *
10 * Depends:
11 *	jquery.ui.core.js
12 *	jquery.ui.mouse.js
13 *	jquery.ui.widget.js
14 */
15(function( $, undefined ) {
16
17// number of pages in a slider
18// (how many times can you page up/down to go through the whole range)
19var numPages = 5;
20
21$.widget( "ui.slider", $.ui.mouse, {
22
23	widgetEventPrefix: "slide",
24
25	options: {
26		animate: false,
27		distance: 0,
28		max: 100,
29		min: 0,
30		orientation: "horizontal",
31		isRTL: false, // RTL
32		range: false,
33		step: 1,
34		value: 0,
35		values: null
36	},
37
38	_create: function() {
39		var self = this,
40			o = this.options;
41
42		this._keySliding = false;
43		this._mouseSliding = false;
44		this._animateOff = true;
45		this._handleIndex = null;
46		this._detectOrientation();
47		this._mouseInit();
48
49		this.element
50			.addClass( "ui-slider" +
51				" ui-slider-" + this.orientation +
52				( o.isRTL ? " ui-slider-rtl" : "" ) + // RTL
53				" ui-widget" +
54				" ui-widget-content" +
55				" ui-corner-all" );
56		
57		if ( o.disabled ) {
58			this.element.addClass( "ui-slider-disabled ui-disabled" );
59		}
60
61		this.range = $([]);
62
63		if ( o.range ) {
64			if ( o.range === true ) {
65				this.range = $( "<div></div>" );
66				if ( !o.values ) {
67					o.values = [ this._valueMin(), this._valueMin() ];
68				}
69				if ( o.values.length && o.values.length !== 2 ) {
70					o.values = [ o.values[0], o.values[0] ];
71				}
72			} else {
73				this.range = $( "<div></div>" );
74			}
75
76			this.range
77				.appendTo( this.element )
78				.addClass( "ui-slider-range" );
79
80			if ( o.range === "min" || o.range === "max" ) {
81				this.range.addClass( "ui-slider-range-" + o.range );
82			}
83
84			// note: this isn't the most fittingly semantic framework class for this element,
85			// but worked best visually with a variety of themes
86			this.range.addClass( "ui-widget-header" );
87		}
88
89		if ( $( ".ui-slider-handle", this.element ).length === 0 ) {
90			$( "<span></span>" )
91				.appendTo( this.element )
92				.addClass( "ui-slider-handle" );
93		}
94
95		if ( o.values && o.values.length ) {
96			while ( $(".ui-slider-handle", this.element).length < o.values.length ) {
97				$( "<span></span>" )
98					.appendTo( this.element )
99					.addClass( "ui-slider-handle" );
100			}
101		}
102
103		this.handles = $( ".ui-slider-handle", this.element )
104			.addClass( "ui-state-default" +
105				" ui-corner-all" );
106
107		this.handle = this.handles.eq( 0 );
108
109		this.handles.add( this.range ).filter( "a" )
110			.click(function( event ) {
111				event.preventDefault();
112			})
113			.hover(function() {
114				if ( !o.disabled ) {
115					$( this ).addClass( "ui-state-hover" );
116				}
117			}, function() {
118				$( this ).removeClass( "ui-state-hover" );
119			})
120			.focus(function() {
121				if ( !o.disabled ) {
122					$( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
123					$( this ).addClass( "ui-state-focus" );
124				} else {
125					$( this ).blur();
126				}
127			})
128			.blur(function() {
129				$( this ).removeClass( "ui-state-focus" );
130			});
131
132		this.handles.each(function( i ) {
133			$( this ).data( "index.ui-slider-handle", i );
134		});
135
136		this.handles
137			.keydown(function( event ) {
138				var ret = true,
139					index = $( this ).data( "index.ui-slider-handle" ),
140					allowed,
141					curVal,
142					newVal,
143					step;
144	
145				if ( self.options.disabled ) {
146					return;
147				}
148	
149				switch ( event.keyCode ) {
150					case $.ui.keyCode.HOME:
151					case $.ui.keyCode.END:
152					case $.ui.keyCode.PAGE_UP:
153					case $.ui.keyCode.PAGE_DOWN:
154					case $.ui.keyCode.UP:
155					case $.ui.keyCode.RIGHT:
156					case $.ui.keyCode.DOWN:
157					case $.ui.keyCode.LEFT:
158						ret = false;
159						if ( !self._keySliding ) {
160							self._keySliding = true;
161							$( this ).addClass( "ui-state-active" );
162							allowed = self._start( event, index );
163							if ( allowed === false ) {
164								return;
165							}
166						}
167						break;
168				}
169	
170				step = self.options.step;
171				if ( self.options.values && self.options.values.length ) {
172					curVal = newVal = self.values( index );
173				} else {
174					curVal = newVal = self.value();
175				}
176	
177				var adjust = function( minMax, offset ) { // RTL
178					if ( curVal === minMax ) {
179						return;
180					}
181					newVal = self._trimAlignValue( curVal + offset );
182				};
183				switch ( event.keyCode ) {
184					case $.ui.keyCode.HOME:
185						newVal = self._valueMin();
186						break;
187					case $.ui.keyCode.END:
188						newVal = self._valueMax();
189						break;
190					case $.ui.keyCode.PAGE_UP:
191						newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) );
192						break;
193					case $.ui.keyCode.PAGE_DOWN:
194						newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) );
195						break;
196					case $.ui.keyCode.UP:
197						adjust( self._valueMax(), step ); // RTL
198						break;
199					case $.ui.keyCode.RIGHT:
200						adjust( self._valueMax(), self.options.isRTL ? -step : step ); // RTL
201						break;
202					case $.ui.keyCode.DOWN:
203						adjust( self._valueMin(), -step ); // RTL
204						break;
205					case $.ui.keyCode.LEFT:
206						adjust( self._valueMin(), self.options.isRTL ? step : -step ); // RTL
207						break;
208				}
209	
210				self._slide( event, index, newVal );
211	
212				return ret;
213	
214			})
215			.keyup(function( event ) {
216				var index = $( this ).data( "index.ui-slider-handle" );
217	
218				if ( self._keySliding ) {
219					self._keySliding = false;
220					self._stop( event, index );
221					self._change( event, index );
222					$( this ).removeClass( "ui-state-active" );
223				}
224	
225			});
226
227		this._refreshValue();
228
229		this._animateOff = false;
230	},
231
232	destroy: function() {
233		this.handles.remove();
234		this.range.remove();
235
236		this.element
237			.removeClass( "ui-slider" +
238				" ui-slider-horizontal" +
239				" ui-slider-vertical" +
240				" ui-slider-disabled" +
241				" ui-widget" +
242				" ui-widget-content" +
243				" ui-corner-all" )
244			.removeData( "slider" )
245			.unbind( ".slider" );
246
247		this._mouseDestroy();
248
249		return this;
250	},
251
252	_mouseCapture: function( event ) {
253		var o = this.options,
254			position,
255			normValue,
256			distance,
257			closestHandle,
258			self,
259			index,
260			allowed,
261			offset,
262			mouseOverHandle;
263
264		if ( o.disabled ) {
265			return false;
266		}
267
268		this.elementSize = {
269			width: this.element.outerWidth(),
270			height: this.element.outerHeight()
271		};
272		this.elementOffset = this.element.offset();
273
274		position = { x: event.pageX, y: event.pageY };
275		normValue = this._normValueFromMouse( position );
276		distance = this._valueMax() - this._valueMin() + 1;
277		self = this;
278		this.handles.each(function( i ) {
279			var thisDistance = Math.abs( normValue - self.values(i) );
280			if ( distance > thisDistance ) {
281				distance = thisDistance;
282				closestHandle = $( this );
283				index = i;
284			}
285		});
286
287		// workaround for bug #3736 (if both handles of a range are at 0,
288		// the first is always used as the one with least distance,
289		// and moving it is obviously prevented by preventing negative ranges)
290		if( o.range === true && this.values(1) === o.min ) {
291			index += 1;
292			closestHandle = $( this.handles[index] );
293		}
294
295		allowed = this._start( event, index );
296		if ( allowed === false ) {
297			return false;
298		}
299		this._mouseSliding = true;
300
301		self._handleIndex = index;
302
303		closestHandle
304			.addClass( "ui-state-active" )
305			.focus();
306		
307		offset = closestHandle.offset();
308		mouseOverHandle = !$( event.target ).parents().addBack().is( ".ui-slider-handle" );
309		this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
310			left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
311			top: event.pageY - offset.top -
312				( closestHandle.height() / 2 ) -
313				( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
314				( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
315				( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
316		};
317
318		if ( !this.handles.hasClass( "ui-state-hover" ) ) {
319			this._slide( event, index, normValue );
320		}
321		this._animateOff = true;
322		return true;
323	},
324
325	_mouseStart: function( event ) {
326		return true;
327	},
328
329	_mouseDrag: function( event ) {
330		var position = { x: event.pageX, y: event.pageY },
331			normValue = this._normValueFromMouse( position );
332		
333		this._slide( event, this._handleIndex, normValue );
334
335		return false;
vendor: 10,653 bytes, lines 336-711
336	},
337
338	_mouseStop: function( event ) {
339		this.handles.removeClass( "ui-state-active" );
340		this._mouseSliding = false;
341
342		this._stop( event, this._handleIndex );
343		this._change( event, this._handleIndex );
344
345		this._handleIndex = null;
346		this._clickOffset = null;
347		this._animateOff = false;
348
349		return false;
350	},
351	
352	_detectOrientation: function() {
353		this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
354	},
355
356	_normValueFromMouse: function( position ) {
357		var pixelTotal,
358			pixelMouse,
359			percentMouse,
360			valueTotal,
361			valueMouse;
362
363		if ( this.orientation === "horizontal" ) {
364			pixelTotal = this.elementSize.width;
365			pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
366		} else {
367			pixelTotal = this.elementSize.height;
368			pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
369		}
370
371		percentMouse = ( pixelMouse / pixelTotal );
372		if ( percentMouse > 1 ) {
373			percentMouse = 1;
374		}
375		if ( percentMouse < 0 ) {
376			percentMouse = 0;
377		}
378		if ( this.orientation === "vertical" ) {
379			percentMouse = 1 - percentMouse;
380		}
381		if ( this.options.isRTL ) { // RTL
382			percentMouse = 1 - percentMouse;
383		}
384
385		valueTotal = this._valueMax() - this._valueMin();
386		valueMouse = this._valueMin() + percentMouse * valueTotal;
387
388		return this._trimAlignValue( valueMouse );
389	},
390
391	_start: function( event, index ) {
392		var uiHash = {
393			handle: this.handles[ index ],
394			value: this.value()
395		};
396		if ( this.options.values && this.options.values.length ) {
397			uiHash.value = this.values( index );
398			uiHash.values = this.values();
399		}
400		return this._trigger( "start", event, uiHash );
401	},
402
403	_slide: function( event, index, newVal ) {
404		var otherVal,
405			newValues,
406			allowed;
407
408		if ( this.options.values && this.options.values.length ) {
409			otherVal = this.values( index ? 0 : 1 );
410
411			if ( ( this.options.values.length === 2 && this.options.range === true ) && 
412					( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
413				) {
414				newVal = otherVal;
415			}
416
417			if ( newVal !== this.values( index ) ) {
418				newValues = this.values();
419				newValues[ index ] = newVal;
420				// A slide can be canceled by returning false from the slide callback
421				allowed = this._trigger( "slide", event, {
422					handle: this.handles[ index ],
423					value: newVal,
424					values: newValues
425				} );
426				otherVal = this.values( index ? 0 : 1 );
427				if ( allowed !== false ) {
428					this.values( index, newVal, true );
429				}
430			}
431		} else {
432			if ( newVal !== this.value() ) {
433				// A slide can be canceled by returning false from the slide callback
434				allowed = this._trigger( "slide", event, {
435					handle: this.handles[ index ],
436					value: newVal
437				} );
438				if ( allowed !== false ) {
439					this.value( newVal );
440				}
441			}
442		}
443	},
444
445	_stop: function( event, index ) {
446		var uiHash = {
447			handle: this.handles[ index ],
448			value: this.value()
449		};
450		if ( this.options.values && this.options.values.length ) {
451			uiHash.value = this.values( index );
452			uiHash.values = this.values();
453		}
454
455		this._trigger( "stop", event, uiHash );
456	},
457
458	_change: function( event, index ) {
459		if ( !this._keySliding && !this._mouseSliding ) {
460			var uiHash = {
461				handle: this.handles[ index ],
462				value: this.value()
463			};
464			if ( this.options.values && this.options.values.length ) {
465				uiHash.value = this.values( index );
466				uiHash.values = this.values();
467			}
468
469			this._trigger( "change", event, uiHash );
470		}
471	},
472
473	value: function( newValue ) {
474		if ( arguments.length ) {
475			this.options.value = this._trimAlignValue( newValue );
476			this._refreshValue();
477			this._change( null, 0 );
478		}
479
480		return this._value();
481	},
482
483	values: function( index, newValue ) {
484		var vals,
485			newValues,
486			i;
487
488		if ( arguments.length > 1 ) {
489			this.options.values[ index ] = this._trimAlignValue( newValue );
490			this._refreshValue();
491			this._change( null, index );
492		}
493
494		if ( arguments.length ) {
495			if ( $.isArray( arguments[ 0 ] ) ) {
496				vals = this.options.values;
497				newValues = arguments[ 0 ];
498				for ( i = 0; i < vals.length; i += 1 ) {
499					vals[ i ] = this._trimAlignValue( newValues[ i ] );
500					this._change( null, i );
501				}
502				this._refreshValue();
503			} else {
504				if ( this.options.values && this.options.values.length ) {
505					return this._values( index );
506				} else {
507					return this.value();
508				}
509			}
510		} else {
511			return this._values();
512		}
513	},
514
515	_setOption: function( key, value ) {
516		var i,
517			valsLength = 0;
518
519		if ( $.isArray( this.options.values ) ) {
520			valsLength = this.options.values.length;
521		}
522
523		$.Widget.prototype._setOption.apply( this, arguments );
524
525		switch ( key ) {
526			case "disabled":
527				if ( value ) {
528					this.handles.filter( ".ui-state-focus" ).blur();
529					this.handles.removeClass( "ui-state-hover" );
530					this.handles.attr( "disabled", "disabled" );
531					this.element.addClass( "ui-disabled" );
532				} else {
533					this.handles.removeAttr( "disabled" );
534					this.element.removeClass( "ui-disabled" );
535				}
536				break;
537			case "orientation":
538				this._detectOrientation();
539				this.element
540					.removeClass( "ui-slider-horizontal ui-slider-vertical" )
541					.addClass( "ui-slider-" + this.orientation );
542				this._refreshValue();
543				break;
544			case "isRTL": // RTL
545				this.element.toggleClass( "ui-slider-rtl", value );
546				this._refreshValue();
547				break;
548			case "value":
549				this._animateOff = true;
550				this._refreshValue();
551				this._change( null, 0 );
552				this._animateOff = false;
553				break;
554			case "values":
555				this._animateOff = true;
556				this._refreshValue();
557				for ( i = 0; i < valsLength; i += 1 ) {
558					this._change( null, i );
559				}
560				this._animateOff = false;
561				break;
562		}
563	},
564
565	//internal value getter
566	// _value() returns value trimmed by min and max, aligned by step
567	_value: function() {
568		var val = this.options.value;
569		val = this._trimAlignValue( val );
570
571		return val;
572	},
573
574	//internal values getter
575	// _values() returns array of values trimmed by min and max, aligned by step
576	// _values( index ) returns single value trimmed by min and max, aligned by step
577	_values: function( index ) {
578		var val,
579			vals,
580			i;
581
582		if ( arguments.length ) {
583			val = this.options.values[ index ];
584			val = this._trimAlignValue( val );
585
586			return val;
587		} else {
588			// .slice() creates a copy of the array
589			// this copy gets trimmed by min and max and then returned
590			vals = this.options.values.slice();
591			for ( i = 0; i < vals.length; i+= 1) {
592				vals[ i ] = this._trimAlignValue( vals[ i ] );
593			}
594
595			return vals;
596		}
597	},
598	
599	// returns the step-aligned value that val is closest to, between (inclusive) min and max
600	_trimAlignValue: function( val ) {
601		if ( val <= this._valueMin() ) {
602			return this._valueMin();
603		}
604		if ( val >= this._valueMax() ) {
605			return this._valueMax();
606		}
607		var step = ( this.options.step > 0 ) ? this.options.step : 1,
608			valModStep = (val - this._valueMin()) % step;
609			alignValue = val - valModStep;
610
611		if ( Math.abs(valModStep) * 2 >= step ) {
612			alignValue += ( valModStep > 0 ) ? step : ( -step );
613		}
614
615		// Since JavaScript has problems with large floats, round
616		// the final value to 5 digits after the decimal point (see #4124)
617		return parseFloat( alignValue.toFixed(5) );
618	},
619
620	_valueMin: function() {
621		return this.options.min;
622	},
623
624	_valueMax: function() {
625		return this.options.max;
626	},
627	
628	_refreshValue: function() {
629		var oRange = this.options.range,
630			o = this.options,
631			self = this,
632			animate = ( !this._animateOff ) ? o.animate : false,
633			valPercent,
634			_set = {},
635			lastValPercent,
636			value,
637			valueMin,
638			valueMax;
639
640		if ( this.options.values && this.options.values.length ) {
641			this.handles.each(function( i, j ) {
642				valPercent = ( self.values( i ) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100;
643				valPercent = ( self.options.isRTL ? 100 - valPercent : valPercent ); // RTL
644				_set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
645				$( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
646				if ( self.options.range === true ) {
647					if ( self.orientation === "horizontal" ) {
648						if ( i === 0 ) {
649							self.range.stop( 1, 1 )[ animate ? "animate" : "css" ](
650								self.options.isRTL ? { right: ( 100 - valPercent ) + "%"} : // RTL
651								{ left: valPercent + "%" }, o.animate );
652						}
653						if ( i === 1 ) {
654							self.range[ animate ? "animate" : "css" ]( {
655								width: ( ( self.options.isRTL ? -1 : +1 ) * ( valPercent - lastValPercent ) ) + "%" }, // RTL
656								{ queue: false, duration: o.animate } );
657						}
658					} else {
659						if ( i === 0 ) {
660							self.range.stop( 1, 1 )[ animate ? "animate" : "css" ](
661								self.options.isRTL ? { top: ( 100 - valPercent ) + "%" } : // RTL
662								{ bottom: ( valPercent ) + "%" }, o.animate );
663						}
664						if ( i === 1 ) {
665							self.range[ animate ? "animate" : "css" ]( {
666								height: ( ( self.options.isRTL ? -1 : +1 ) * ( valPercent - lastValPercent ) ) + "%" }, // RTL
667								{ queue: false, duration: o.animate } );
668						}
669					}
670				}
671				lastValPercent = valPercent;
672			});
673		} else {
674			value = this.value();
675			valueMin = this._valueMin();
676			valueMax = this._valueMax();
677			valPercent = ( valueMax !== valueMin ) ?
678					( value - valueMin ) / ( valueMax - valueMin ) * 100 :
679					0;
680			valPercent = ( self.options.isRTL ? 100 - valPercent : valPercent ); // RTL
681			_set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
682			this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
683
684			if ( oRange === "min" && this.orientation === "horizontal" ) {
685				this.range.stop( 1, 1 )[ animate ? "animate" : "css" ](
686					{ width: ( self.options.isRTL ? 100 - valPercent : valPercent ) + "%" }, o.animate ); // RTL
687			}
688			if ( oRange === "max" && this.orientation === "horizontal" ) {
689				this.range[ animate ? "animate" : "css" ]( {
690					width: ( self.options.isRTL ? valPercent : 100 - valPercent ) + "%" }, // RTL
691					{ queue: false, duration: o.animate } );
692			}
693			if ( oRange === "min" && this.orientation === "vertical" ) {
694				this.range.stop( 1, 1 )[ animate ? "animate" : "css" ](
695					{ height: ( self.options.isRTL ? 100 - valPercent : valPercent ) + "%" }, o.animate ); // RTL
696			}
697			if ( oRange === "max" && this.orientation === "vertical" ) {
698				this.range[ animate ? "animate" : "css" ](
699					{ height: ( self.options.isRTL ? valPercent : 100 - valPercent ) + "%" }, // RTL
700					{ queue: false, duration: o.animate } );
701			}
702		}
703	}
704
705});
706
707$.extend( $.ui.slider, {
708	version: "1.8.9"
709});
710
711}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.