2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Slider @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Slider
|
|
|
|
//>>group: Widgets
|
|
|
|
//>>description: Displays a flexible slider with ranges and accessibility via keyboard.
|
|
|
|
//>>docs: http://api.jqueryui.com/slider/
|
|
|
|
//>>demos: http://jqueryui.com/slider/
|
2014-04-15 14:45:46 +00:00
|
|
|
//>>css.structure: ../themes/base/core.css
|
|
|
|
//>>css.structure: ../themes/base/slider.css
|
|
|
|
//>>css.theme: ../themes/base/theme.css
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
(function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define([
|
|
|
|
"jquery",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./core",
|
|
|
|
"./mouse",
|
|
|
|
"./widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
return $.widget( "ui.slider", $.ui.mouse, {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-02-05 14:19:19 +00:00
|
|
|
widgetEventPrefix: "slide",
|
2010-04-03 03:14:44 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
|
|
|
animate: false,
|
2014-12-03 16:27:19 +00:00
|
|
|
classes: {
|
|
|
|
"ui-slider": "ui-corner-all",
|
|
|
|
"ui-slider-handle": "ui-corner-all",
|
|
|
|
|
|
|
|
// Note: ui-widget-header isn't the most fittingly semantic framework class for this
|
|
|
|
// element, but worked best visually with a variety of themes
|
|
|
|
"ui-slider-range": "ui-corner-all ui-widget-header"
|
|
|
|
},
|
2010-01-07 03:19:50 +00:00
|
|
|
distance: 0,
|
|
|
|
max: 100,
|
|
|
|
min: 0,
|
2010-04-03 03:14:44 +00:00
|
|
|
orientation: "horizontal",
|
2010-01-07 03:19:50 +00:00
|
|
|
range: false,
|
|
|
|
step: 1,
|
|
|
|
value: 0,
|
2013-01-02 19:58:12 +00:00
|
|
|
values: null,
|
|
|
|
|
|
|
|
// callbacks
|
|
|
|
change: null,
|
|
|
|
slide: null,
|
|
|
|
start: null,
|
|
|
|
stop: null
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-04-03 03:14:44 +00:00
|
|
|
|
2013-09-17 13:41:20 +00:00
|
|
|
// number of pages in a slider
|
|
|
|
// (how many times can you page up/down to go through the whole range)
|
|
|
|
numPages: 5,
|
|
|
|
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2008-12-23 10:38:12 +00:00
|
|
|
this._keySliding = false;
|
2010-02-15 14:34:42 +00:00
|
|
|
this._mouseSliding = false;
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = true;
|
2008-12-31 19:55:16 +00:00
|
|
|
this._handleIndex = null;
|
2009-01-29 15:13:47 +00:00
|
|
|
this._detectOrientation();
|
2008-12-23 10:38:12 +00:00
|
|
|
this._mouseInit();
|
2013-10-19 04:56:20 +00:00
|
|
|
this._calculateNewMax();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2014-12-03 16:27:19 +00:00
|
|
|
this._addClass( "ui-slider ui-slider-" + this.orientation,
|
|
|
|
"ui-widget ui-widget-content" );
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
this._refresh();
|
|
|
|
this._setOption( "disabled", this.options.disabled );
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
this._animateOff = false;
|
|
|
|
},
|
2009-02-21 11:40:05 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
_refresh: function() {
|
|
|
|
this._createRange();
|
|
|
|
this._createHandles();
|
|
|
|
this._setupEvents();
|
|
|
|
this._refreshValue();
|
|
|
|
},
|
|
|
|
|
|
|
|
_createHandles: function() {
|
|
|
|
var i, handleCount,
|
|
|
|
options = this.options,
|
2014-12-03 16:27:19 +00:00
|
|
|
existingHandles = this.element.find( ".ui-slider-handle" ),
|
|
|
|
handle = "<span tabindex='0'></span>",
|
2013-01-30 19:07:33 +00:00
|
|
|
handles = [];
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
handleCount = ( options.values && options.values.length ) || 1;
|
|
|
|
|
|
|
|
if ( existingHandles.length > handleCount ) {
|
|
|
|
existingHandles.slice( handleCount ).remove();
|
|
|
|
existingHandles = existingHandles.slice( 0, handleCount );
|
|
|
|
}
|
2012-10-16 18:07:10 +00:00
|
|
|
|
2012-04-02 23:12:21 +00:00
|
|
|
for ( i = existingHandles.length; i < handleCount; i++ ) {
|
2011-05-11 17:13:09 +00:00
|
|
|
handles.push( handle );
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2012-05-09 19:29:14 +00:00
|
|
|
this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) );
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2014-12-03 16:27:19 +00:00
|
|
|
this._addClass( this.handles, "ui-slider-handle", "ui-state-default" );
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
this.handle = this.handles.eq( 0 );
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
this.handles.each(function( i ) {
|
2012-03-01 12:29:56 +00:00
|
|
|
$( this ).data( "ui-slider-handle-index", i );
|
2009-01-12 13:02:47 +00:00
|
|
|
});
|
2013-01-30 19:07:33 +00:00
|
|
|
},
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
_createRange: function() {
|
2014-12-03 16:27:19 +00:00
|
|
|
var options = this.options;
|
2013-01-30 19:07:33 +00:00
|
|
|
|
|
|
|
if ( options.range ) {
|
|
|
|
if ( options.range === true ) {
|
|
|
|
if ( !options.values ) {
|
|
|
|
options.values = [ this._valueMin(), this._valueMin() ];
|
|
|
|
} else if ( options.values.length && options.values.length !== 2 ) {
|
|
|
|
options.values = [ options.values[0], options.values[0] ];
|
|
|
|
} else if ( $.isArray( options.values ) ) {
|
|
|
|
options.values = options.values.slice(0);
|
|
|
|
}
|
|
|
|
}
|
2012-11-16 11:47:22 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
if ( !this.range || !this.range.length ) {
|
2014-12-03 16:27:19 +00:00
|
|
|
this.range = $( "<div>" )
|
2013-01-30 19:07:33 +00:00
|
|
|
.appendTo( this.element );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2014-12-03 16:27:19 +00:00
|
|
|
this._addClass( this.range, "ui-slider-range" );
|
2013-01-30 19:07:33 +00:00
|
|
|
} else {
|
2014-12-03 16:27:19 +00:00
|
|
|
this._removeClass( this.range, "ui-slider-range-min ui-slider-range-max" );
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2014-12-03 16:27:19 +00:00
|
|
|
// Handle range switching from true to min/max
|
|
|
|
this.range.css({
|
|
|
|
"left": "",
|
|
|
|
"bottom": ""
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if ( options.range === "min" || options.range === "max" ) {
|
|
|
|
this._addClass( this.range, "ui-slider-range-" + options.range );
|
|
|
|
}
|
2013-01-30 19:07:33 +00:00
|
|
|
} else {
|
2013-06-03 19:14:08 +00:00
|
|
|
if ( this.range ) {
|
|
|
|
this.range.remove();
|
|
|
|
}
|
|
|
|
this.range = null;
|
2013-01-30 19:07:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_setupEvents: function() {
|
2014-03-06 04:03:17 +00:00
|
|
|
this._off( this.handles );
|
|
|
|
this._on( this.handles, this._handleEvents );
|
|
|
|
this._hoverable( this.handles );
|
|
|
|
this._focusable( this.handles );
|
2008-11-21 04:40:23 +00:00
|
|
|
},
|
|
|
|
|
2012-05-09 19:42:18 +00:00
|
|
|
_destroy: function() {
|
2008-12-23 10:38:12 +00:00
|
|
|
this.handles.remove();
|
2013-06-03 19:14:08 +00:00
|
|
|
if ( this.range ) {
|
|
|
|
this.range.remove();
|
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
this._mouseDestroy();
|
2008-11-21 04:40:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_mouseCapture: function( event ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,
|
|
|
|
that = this,
|
|
|
|
o = this.options;
|
2010-04-03 03:14:44 +00:00
|
|
|
|
|
|
|
if ( o.disabled ) {
|
2008-12-23 10:38:12 +00:00
|
|
|
return false;
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
this.elementSize = {
|
|
|
|
width: this.element.outerWidth(),
|
|
|
|
height: this.element.outerHeight()
|
2008-11-21 04:40:23 +00:00
|
|
|
};
|
2008-12-23 10:38:12 +00:00
|
|
|
this.elementOffset = this.element.offset();
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
position = { x: event.pageX, y: event.pageY };
|
|
|
|
normValue = this._normValueFromMouse( position );
|
|
|
|
distance = this._valueMax() - this._valueMin() + 1;
|
|
|
|
this.handles.each(function( i ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
var thisDistance = Math.abs( normValue - that.values(i) );
|
2012-11-14 01:05:59 +00:00
|
|
|
if (( distance > thisDistance ) ||
|
|
|
|
( distance === thisDistance &&
|
|
|
|
(i === that._lastChangedValue || that.values(i) === o.min ))) {
|
2008-12-23 10:38:12 +00:00
|
|
|
distance = thisDistance;
|
2010-04-03 03:14:44 +00:00
|
|
|
closestHandle = $( this );
|
2008-12-31 19:55:16 +00:00
|
|
|
index = i;
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2009-02-02 03:07:54 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
allowed = this._start( event, index );
|
|
|
|
if ( allowed === false ) {
|
2010-04-01 19:08:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-02-15 14:34:42 +00:00
|
|
|
this._mouseSliding = true;
|
2009-02-17 12:21:42 +00:00
|
|
|
|
2012-05-09 19:29:14 +00:00
|
|
|
this._handleIndex = index;
|
2008-12-31 19:55:16 +00:00
|
|
|
|
2014-12-03 16:27:19 +00:00
|
|
|
this._addClass( closestHandle, null, "ui-state-active" );
|
|
|
|
closestHandle.focus();
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
offset = closestHandle.offset();
|
2012-12-14 16:13:46 +00:00
|
|
|
mouseOverHandle = !$( event.target ).parents().addBack().is( ".ui-slider-handle" );
|
2009-01-28 22:07:46 +00:00
|
|
|
this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
|
2010-04-03 03:14:44 +00:00
|
|
|
left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
|
|
|
|
top: event.pageY - offset.top -
|
|
|
|
( closestHandle.height() / 2 ) -
|
|
|
|
( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
|
|
|
|
( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
|
|
|
|
( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
|
2009-01-28 22:07:46 +00:00
|
|
|
};
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-11-19 15:35:34 +00:00
|
|
|
if ( !this.handles.hasClass( "ui-state-hover" ) ) {
|
|
|
|
this._slide( event, index, normValue );
|
|
|
|
}
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = true;
|
2008-09-11 15:18:33 +00:00
|
|
|
return true;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
_mouseStart: function() {
|
2008-12-23 10:38:12 +00:00
|
|
|
return true;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_mouseDrag: function( event ) {
|
|
|
|
var position = { x: event.pageX, y: event.pageY },
|
|
|
|
normValue = this._normValueFromMouse( position );
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
this._slide( event, this._handleIndex, normValue );
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
return false;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_mouseStop: function( event ) {
|
2014-12-03 16:27:19 +00:00
|
|
|
this._removeClass( this.handles, null, "ui-state-active" );
|
2010-02-15 14:34:42 +00:00
|
|
|
this._mouseSliding = false;
|
2010-04-03 03:14:44 +00:00
|
|
|
|
|
|
|
this._stop( event, this._handleIndex );
|
|
|
|
this._change( event, this._handleIndex );
|
|
|
|
|
2008-12-31 19:55:16 +00:00
|
|
|
this._handleIndex = null;
|
2009-01-28 22:07:46 +00:00
|
|
|
this._clickOffset = null;
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = false;
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
return false;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2009-01-29 15:13:47 +00:00
|
|
|
_detectOrientation: function() {
|
2010-04-03 03:14:44 +00:00
|
|
|
this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
|
2009-01-29 15:13:47 +00:00
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_normValueFromMouse: function( position ) {
|
|
|
|
var pixelTotal,
|
|
|
|
pixelMouse,
|
|
|
|
percentMouse,
|
|
|
|
valueTotal,
|
|
|
|
valueMouse;
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( this.orientation === "horizontal" ) {
|
2008-12-23 10:38:12 +00:00
|
|
|
pixelTotal = this.elementSize.width;
|
2010-04-03 03:14:44 +00:00
|
|
|
pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
|
2008-12-23 10:38:12 +00:00
|
|
|
} else {
|
|
|
|
pixelTotal = this.elementSize.height;
|
2010-04-03 03:14:44 +00:00
|
|
|
pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
percentMouse = ( pixelMouse / pixelTotal );
|
|
|
|
if ( percentMouse > 1 ) {
|
|
|
|
percentMouse = 1;
|
|
|
|
}
|
|
|
|
if ( percentMouse < 0 ) {
|
|
|
|
percentMouse = 0;
|
|
|
|
}
|
|
|
|
if ( this.orientation === "vertical" ) {
|
2008-12-23 10:38:12 +00:00
|
|
|
percentMouse = 1 - percentMouse;
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
valueTotal = this._valueMax() - this._valueMin();
|
|
|
|
valueMouse = this._valueMin() + percentMouse * valueTotal;
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
return this._trimAlignValue( valueMouse );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_start: function( event, index ) {
|
2009-03-10 01:35:09 +00:00
|
|
|
var uiHash = {
|
2010-04-03 03:14:44 +00:00
|
|
|
handle: this.handles[ index ],
|
2009-03-10 01:35:09 +00:00
|
|
|
value: this.value()
|
|
|
|
};
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
uiHash.value = this.values( index );
|
2009-05-07 10:50:38 +00:00
|
|
|
uiHash.values = this.values();
|
2009-03-10 01:35:09 +00:00
|
|
|
}
|
2010-04-03 03:14:44 +00:00
|
|
|
return this._trigger( "start", event, uiHash );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_slide: function( event, index, newVal ) {
|
|
|
|
var otherVal,
|
|
|
|
newValues,
|
|
|
|
allowed;
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
otherVal = this.values( index ? 0 : 1 );
|
2009-01-20 13:31:30 +00:00
|
|
|
|
2012-03-01 12:29:31 +00:00
|
|
|
if ( ( this.options.values.length === 2 && this.options.range === true ) &&
|
2010-04-03 03:14:44 +00:00
|
|
|
( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
|
|
|
|
) {
|
|
|
|
newVal = otherVal;
|
2009-04-19 23:50:48 +00:00
|
|
|
}
|
2009-01-12 13:02:47 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( newVal !== this.values( index ) ) {
|
|
|
|
newValues = this.values();
|
|
|
|
newValues[ index ] = newVal;
|
2008-12-23 10:38:12 +00:00
|
|
|
// A slide can be canceled by returning false from the slide callback
|
2010-04-03 03:14:44 +00:00
|
|
|
allowed = this._trigger( "slide", event, {
|
|
|
|
handle: this.handles[ index ],
|
2009-03-09 12:36:50 +00:00
|
|
|
value: newVal,
|
|
|
|
values: newValues
|
2010-04-03 03:14:44 +00:00
|
|
|
} );
|
|
|
|
otherVal = this.values( index ? 0 : 1 );
|
|
|
|
if ( allowed !== false ) {
|
2013-10-18 15:23:36 +00:00
|
|
|
this.values( index, newVal );
|
2008-12-31 19:55:16 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
} else {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( newVal !== this.value() ) {
|
2008-12-23 10:38:12 +00:00
|
|
|
// A slide can be canceled by returning false from the slide callback
|
2010-04-03 03:14:44 +00:00
|
|
|
allowed = this._trigger( "slide", event, {
|
|
|
|
handle: this.handles[ index ],
|
2009-03-09 12:36:50 +00:00
|
|
|
value: newVal
|
2010-04-03 03:14:44 +00:00
|
|
|
} );
|
|
|
|
if ( allowed !== false ) {
|
|
|
|
this.value( newVal );
|
2009-01-28 19:10:37 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_stop: function( event, index ) {
|
2009-03-09 12:36:50 +00:00
|
|
|
var uiHash = {
|
2010-04-03 03:14:44 +00:00
|
|
|
handle: this.handles[ index ],
|
2009-03-09 12:36:50 +00:00
|
|
|
value: this.value()
|
|
|
|
};
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
uiHash.value = this.values( index );
|
2009-05-07 10:50:38 +00:00
|
|
|
uiHash.values = this.values();
|
2009-03-09 12:36:50 +00:00
|
|
|
}
|
2010-04-03 03:14:44 +00:00
|
|
|
|
|
|
|
this._trigger( "stop", event, uiHash );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_change: function( event, index ) {
|
|
|
|
if ( !this._keySliding && !this._mouseSliding ) {
|
2010-02-15 14:34:42 +00:00
|
|
|
var uiHash = {
|
2010-04-03 03:14:44 +00:00
|
|
|
handle: this.handles[ index ],
|
2010-02-15 14:34:42 +00:00
|
|
|
value: this.value()
|
|
|
|
};
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
uiHash.value = this.values( index );
|
2010-02-15 14:34:42 +00:00
|
|
|
uiHash.values = this.values();
|
|
|
|
}
|
2010-04-03 03:14:44 +00:00
|
|
|
|
2012-11-14 01:05:59 +00:00
|
|
|
//store the last changed value index for reference when handles overlap
|
|
|
|
this._lastChangedValue = index;
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
this._trigger( "change", event, uiHash );
|
2009-03-09 12:36:50 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
value: function( newValue ) {
|
|
|
|
if ( arguments.length ) {
|
|
|
|
this.options.value = this._trimAlignValue( newValue );
|
2009-10-12 10:50:38 +00:00
|
|
|
this._refreshValue();
|
2010-04-03 03:14:44 +00:00
|
|
|
this._change( null, 0 );
|
2011-03-28 21:34:04 +00:00
|
|
|
return;
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
return this._value();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
values: function( index, newValue ) {
|
|
|
|
var vals,
|
|
|
|
newValues,
|
|
|
|
i;
|
2009-01-28 22:13:44 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( arguments.length > 1 ) {
|
|
|
|
this.options.values[ index ] = this._trimAlignValue( newValue );
|
2009-10-12 10:50:38 +00:00
|
|
|
this._refreshValue();
|
2010-04-03 03:14:44 +00:00
|
|
|
this._change( null, index );
|
2011-03-28 21:34:04 +00:00
|
|
|
return;
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( arguments.length ) {
|
|
|
|
if ( $.isArray( arguments[ 0 ] ) ) {
|
|
|
|
vals = this.options.values;
|
|
|
|
newValues = arguments[ 0 ];
|
|
|
|
for ( i = 0; i < vals.length; i += 1 ) {
|
|
|
|
vals[ i ] = this._trimAlignValue( newValues[ i ] );
|
|
|
|
this._change( null, i );
|
2009-10-12 14:32:31 +00:00
|
|
|
}
|
|
|
|
this._refreshValue();
|
2008-12-23 10:38:12 +00:00
|
|
|
} else {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
return this._values( index );
|
2009-10-12 14:32:31 +00:00
|
|
|
} else {
|
|
|
|
return this.value();
|
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
} else {
|
|
|
|
return this._values();
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
},
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_setOption: function( key, value ) {
|
2010-03-17 17:39:29 +00:00
|
|
|
var i,
|
|
|
|
valsLength = 0;
|
2010-04-03 03:14:44 +00:00
|
|
|
|
2013-01-30 19:07:33 +00:00
|
|
|
if ( key === "range" && this.options.range === true ) {
|
|
|
|
if ( value === "min" ) {
|
|
|
|
this.options.value = this._values( 0 );
|
|
|
|
this.options.values = null;
|
|
|
|
} else if ( value === "max" ) {
|
2013-10-16 18:43:09 +00:00
|
|
|
this.options.value = this._values( this.options.values.length - 1 );
|
2013-01-30 19:07:33 +00:00
|
|
|
this.options.values = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( $.isArray( this.options.values ) ) {
|
2010-03-17 17:39:29 +00:00
|
|
|
valsLength = this.options.values.length;
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2009-01-12 13:02:47 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
if ( key === "disabled" ) {
|
2014-12-03 16:27:19 +00:00
|
|
|
this._toggleClass( null, "ui-state-disabled", !!value );
|
2013-03-14 23:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._super( key, value );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case "orientation":
|
2009-01-29 15:13:47 +00:00
|
|
|
this._detectOrientation();
|
2014-12-03 16:27:19 +00:00
|
|
|
this._removeClass( "ui-slider-horizontal ui-slider-vertical" )
|
|
|
|
._addClass( "ui-slider-" + this.orientation );
|
2009-10-12 10:50:38 +00:00
|
|
|
this._refreshValue();
|
2014-06-11 13:28:39 +00:00
|
|
|
|
|
|
|
// Reset positioning from previous orientation
|
|
|
|
this.handles.css( value === "horizontal" ? "bottom" : "left", "" );
|
2008-12-23 10:38:12 +00:00
|
|
|
break;
|
2010-04-03 03:14:44 +00:00
|
|
|
case "value":
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = true;
|
|
|
|
this._refreshValue();
|
2010-04-03 03:14:44 +00:00
|
|
|
this._change( null, 0 );
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = false;
|
|
|
|
break;
|
2010-04-03 03:14:44 +00:00
|
|
|
case "values":
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = true;
|
|
|
|
this._refreshValue();
|
2010-04-03 03:14:44 +00:00
|
|
|
for ( i = 0; i < valsLength; i += 1 ) {
|
|
|
|
this._change( null, i );
|
2010-03-17 17:39:29 +00:00
|
|
|
}
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = false;
|
2008-12-23 10:38:12 +00:00
|
|
|
break;
|
2013-10-19 04:56:20 +00:00
|
|
|
case "step":
|
2012-10-16 17:42:05 +00:00
|
|
|
case "min":
|
|
|
|
case "max":
|
|
|
|
this._animateOff = true;
|
2013-10-19 04:56:20 +00:00
|
|
|
this._calculateNewMax();
|
2012-10-16 17:42:05 +00:00
|
|
|
this._refreshValue();
|
|
|
|
this._animateOff = false;
|
|
|
|
break;
|
2013-01-30 19:07:33 +00:00
|
|
|
case "range":
|
|
|
|
this._animateOff = true;
|
|
|
|
this._refresh();
|
|
|
|
this._animateOff = false;
|
|
|
|
break;
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
//internal value getter
|
|
|
|
// _value() returns value trimmed by min and max, aligned by step
|
2008-12-23 10:38:12 +00:00
|
|
|
_value: function() {
|
|
|
|
var val = this.options.value;
|
2010-04-03 03:14:44 +00:00
|
|
|
val = this._trimAlignValue( val );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
return val;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
//internal values getter
|
|
|
|
// _values() returns array of values trimmed by min and max, aligned by step
|
|
|
|
// _values( index ) returns single value trimmed by min and max, aligned by step
|
|
|
|
_values: function( index ) {
|
|
|
|
var val,
|
|
|
|
vals,
|
|
|
|
i;
|
2009-01-12 13:02:47 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( arguments.length ) {
|
|
|
|
val = this.options.values[ index ];
|
|
|
|
val = this._trimAlignValue( val );
|
2008-12-31 08:22:11 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
return val;
|
2013-01-30 19:07:33 +00:00
|
|
|
} else if ( this.options.values && this.options.values.length ) {
|
2009-08-04 23:35:08 +00:00
|
|
|
// .slice() creates a copy of the array
|
2009-10-12 14:32:31 +00:00
|
|
|
// this copy gets trimmed by min and max and then returned
|
2010-04-03 03:14:44 +00:00
|
|
|
vals = this.options.values.slice();
|
2014-08-13 16:29:28 +00:00
|
|
|
for ( i = 0; i < vals.length; i += 1) {
|
2010-04-03 03:14:44 +00:00
|
|
|
vals[ i ] = this._trimAlignValue( vals[ i ] );
|
2009-10-12 14:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return vals;
|
2013-01-30 19:07:33 +00:00
|
|
|
} else {
|
|
|
|
return [];
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
},
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-01 19:00:45 +00:00
|
|
|
// returns the step-aligned value that val is closest to, between (inclusive) min and max
|
2010-04-03 03:14:44 +00:00
|
|
|
_trimAlignValue: function( val ) {
|
2010-12-06 15:05:46 +00:00
|
|
|
if ( val <= this._valueMin() ) {
|
2010-03-27 00:52:44 +00:00
|
|
|
return this._valueMin();
|
|
|
|
}
|
2010-12-06 15:05:46 +00:00
|
|
|
if ( val >= this._valueMax() ) {
|
2010-03-27 00:52:44 +00:00
|
|
|
return this._valueMax();
|
|
|
|
}
|
2010-05-11 12:17:18 +00:00
|
|
|
var step = ( this.options.step > 0 ) ? this.options.step : 1,
|
2011-02-13 07:11:40 +00:00
|
|
|
valModStep = (val - this._valueMin()) % step,
|
2010-04-02 14:32:33 +00:00
|
|
|
alignValue = val - valModStep;
|
2010-04-01 19:00:45 +00:00
|
|
|
|
2010-05-11 12:17:18 +00:00
|
|
|
if ( Math.abs(valModStep) * 2 >= step ) {
|
|
|
|
alignValue += ( valModStep > 0 ) ? step : ( -step );
|
2010-04-01 19:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since JavaScript has problems with large floats, round
|
|
|
|
// the final value to 5 digits after the decimal point (see #4124)
|
2010-04-03 03:14:44 +00:00
|
|
|
return parseFloat( alignValue.toFixed(5) );
|
2009-10-12 14:32:31 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-10-19 04:56:20 +00:00
|
|
|
_calculateNewMax: function() {
|
2015-01-10 01:06:32 +00:00
|
|
|
var max = this.options.max,
|
|
|
|
min = this._valueMin(),
|
|
|
|
step = this.options.step,
|
2015-03-04 12:23:17 +00:00
|
|
|
aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
|
2015-01-10 01:06:32 +00:00
|
|
|
max = aboveMin + min;
|
|
|
|
this.max = parseFloat( max.toFixed( this._precision() ) );
|
|
|
|
},
|
|
|
|
|
|
|
|
_precision: function() {
|
|
|
|
var precision = this._precisionOf( this.options.step );
|
|
|
|
if ( this.options.min !== null ) {
|
|
|
|
precision = Math.max( precision, this._precisionOf( this.options.min ) );
|
|
|
|
}
|
|
|
|
return precision;
|
|
|
|
},
|
|
|
|
|
|
|
|
_precisionOf: function( num ) {
|
|
|
|
var str = num.toString(),
|
|
|
|
decimal = str.indexOf( "." );
|
|
|
|
return decimal === -1 ? 0 : str.length - decimal - 1;
|
2013-10-19 04:56:20 +00:00
|
|
|
},
|
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
_valueMin: function() {
|
2010-03-27 00:49:56 +00:00
|
|
|
return this.options.min;
|
2008-11-21 04:40:23 +00:00
|
|
|
},
|
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
_valueMax: function() {
|
2013-10-19 04:56:20 +00:00
|
|
|
return this.max;
|
2008-11-21 04:40:23 +00:00
|
|
|
},
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2009-10-12 10:50:38 +00:00
|
|
|
_refreshValue: function() {
|
2012-05-09 19:29:14 +00:00
|
|
|
var lastValPercent, valPercent, value, valueMin, valueMax,
|
|
|
|
oRange = this.options.range,
|
2010-04-03 03:14:44 +00:00
|
|
|
o = this.options,
|
2012-05-09 19:29:14 +00:00
|
|
|
that = this,
|
2010-04-03 03:14:44 +00:00
|
|
|
animate = ( !this._animateOff ) ? o.animate : false,
|
2012-05-09 19:29:14 +00:00
|
|
|
_set = {};
|
2010-04-03 03:14:44 +00:00
|
|
|
|
|
|
|
if ( this.options.values && this.options.values.length ) {
|
2012-10-23 14:36:42 +00:00
|
|
|
this.handles.each(function( i ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100;
|
|
|
|
_set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
|
2010-04-03 03:14:44 +00:00
|
|
|
$( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
|
2012-05-09 19:29:14 +00:00
|
|
|
if ( that.options.range === true ) {
|
|
|
|
if ( that.orientation === "horizontal" ) {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( i === 0 ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
|
|
|
if ( i === 1 ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
} else {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( i === 0 ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
|
|
|
if ( i === 1 ) {
|
2012-05-09 19:29:14 +00:00
|
|
|
that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lastValPercent = valPercent;
|
|
|
|
});
|
|
|
|
} else {
|
2010-04-03 03:14:44 +00:00
|
|
|
value = this.value();
|
|
|
|
valueMin = this._valueMin();
|
|
|
|
valueMax = this._valueMax();
|
|
|
|
valPercent = ( valueMax !== valueMin ) ?
|
|
|
|
( value - valueMin ) / ( valueMax - valueMin ) * 100 :
|
|
|
|
0;
|
2012-05-09 19:29:14 +00:00
|
|
|
_set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
|
2010-04-03 03:14:44 +00:00
|
|
|
this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
|
|
|
|
|
|
|
|
if ( oRange === "min" && this.orientation === "horizontal" ) {
|
|
|
|
this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
|
|
|
|
}
|
|
|
|
if ( oRange === "max" && this.orientation === "horizontal" ) {
|
|
|
|
this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
|
|
|
|
}
|
|
|
|
if ( oRange === "min" && this.orientation === "vertical" ) {
|
|
|
|
this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
|
|
|
|
}
|
|
|
|
if ( oRange === "max" && this.orientation === "vertical" ) {
|
|
|
|
this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
|
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2013-01-08 18:19:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_handleEvents: {
|
|
|
|
keydown: function( event ) {
|
|
|
|
var allowed, curVal, newVal, step,
|
|
|
|
index = $( event.target ).data( "ui-slider-handle-index" );
|
|
|
|
|
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.HOME:
|
|
|
|
case $.ui.keyCode.END:
|
|
|
|
case $.ui.keyCode.PAGE_UP:
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
case $.ui.keyCode.RIGHT:
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.LEFT:
|
|
|
|
event.preventDefault();
|
|
|
|
if ( !this._keySliding ) {
|
|
|
|
this._keySliding = true;
|
2014-12-03 16:27:19 +00:00
|
|
|
this._addClass( $( event.target ), null, "ui-state-active" );
|
2013-01-08 18:19:16 +00:00
|
|
|
allowed = this._start( event, index );
|
|
|
|
if ( allowed === false ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
step = this.options.step;
|
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
curVal = newVal = this.values( index );
|
|
|
|
} else {
|
|
|
|
curVal = newVal = this.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.HOME:
|
|
|
|
newVal = this._valueMin();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.END:
|
|
|
|
newVal = this._valueMax();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_UP:
|
2013-09-17 13:41:20 +00:00
|
|
|
newVal = this._trimAlignValue(
|
2013-10-23 12:15:12 +00:00
|
|
|
curVal + ( ( this._valueMax() - this._valueMin() ) / this.numPages )
|
|
|
|
);
|
2013-01-08 18:19:16 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
2013-09-17 13:41:20 +00:00
|
|
|
newVal = this._trimAlignValue(
|
|
|
|
curVal - ( (this._valueMax() - this._valueMin()) / this.numPages ) );
|
2013-01-08 18:19:16 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
case $.ui.keyCode.RIGHT:
|
|
|
|
if ( curVal === this._valueMax() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
newVal = this._trimAlignValue( curVal + step );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.LEFT:
|
|
|
|
if ( curVal === this._valueMin() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
newVal = this._trimAlignValue( curVal - step );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._slide( event, index, newVal );
|
|
|
|
},
|
|
|
|
keyup: function( event ) {
|
|
|
|
var index = $( event.target ).data( "ui-slider-handle-index" );
|
|
|
|
|
|
|
|
if ( this._keySliding ) {
|
|
|
|
this._keySliding = false;
|
|
|
|
this._stop( event, index );
|
|
|
|
this._change( event, index );
|
2014-12-03 16:27:19 +00:00
|
|
|
this._removeClass( $( event.target ), null, "ui-state-active" );
|
2013-01-08 18:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|