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
|
|
|
*
|
2012-07-04 13:08:08 +00:00
|
|
|
* Copyright 2012 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-11-20 04:10:34 +00:00
|
|
|
*
|
2012-09-26 23:06:20 +00:00
|
|
|
* http://api.jqueryui.com/slider/
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.ui.core.js
|
2009-12-22 19:51:24 +00:00
|
|
|
* jquery.ui.mouse.js
|
|
|
|
* jquery.ui.widget.js
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2009-11-09 03:10:57 +00:00
|
|
|
// number of pages in a slider
|
|
|
|
// (how many times can you page up/down to go through the whole range)
|
|
|
|
var numPages = 5;
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
$.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,
|
|
|
|
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,
|
|
|
|
values: null
|
|
|
|
},
|
2010-04-03 03:14:44 +00:00
|
|
|
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2012-10-16 18:07:10 +00:00
|
|
|
var i, handleCount,
|
2011-05-11 17:13:09 +00:00
|
|
|
o = this.options,
|
|
|
|
existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
|
|
|
|
handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
|
|
|
|
handles = [];
|
2008-11-18 02:55:25 +00:00
|
|
|
|
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();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
this.element
|
2010-04-03 03:14:44 +00:00
|
|
|
.addClass( "ui-slider" +
|
|
|
|
" ui-slider-" + this.orientation +
|
|
|
|
" ui-widget" +
|
|
|
|
" ui-widget-content" +
|
2012-11-16 11:47:22 +00:00
|
|
|
" ui-corner-all");
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
this.range = $([]);
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( o.range ) {
|
|
|
|
if ( o.range === true ) {
|
|
|
|
if ( !o.values ) {
|
|
|
|
o.values = [ this._valueMin(), this._valueMin() ];
|
|
|
|
}
|
|
|
|
if ( o.values.length && o.values.length !== 2 ) {
|
|
|
|
o.values = [ o.values[0], o.values[0] ];
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2009-02-21 11:40:05 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 17:13:09 +00:00
|
|
|
this.range = $( "<div></div>" )
|
2010-04-03 03:14:44 +00:00
|
|
|
.appendTo( this.element )
|
2011-05-11 17:13:09 +00:00
|
|
|
.addClass( "ui-slider-range" +
|
|
|
|
// note: this isn't the most fittingly semantic framework class for this element,
|
|
|
|
// but worked best visually with a variety of themes
|
2012-03-01 12:29:31 +00:00
|
|
|
" ui-widget-header" +
|
2011-05-11 17:13:09 +00:00
|
|
|
( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2012-10-16 18:07:10 +00:00
|
|
|
handleCount = ( o.values && o.values.length ) || 1;
|
|
|
|
|
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
|
|
|
|
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.add( this.range ).filter( "a" )
|
|
|
|
.click(function( event ) {
|
2009-04-02 00:10:52 +00:00
|
|
|
event.preventDefault();
|
|
|
|
})
|
2012-05-21 13:55:56 +00:00
|
|
|
.mouseenter(function() {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( !o.disabled ) {
|
|
|
|
$( this ).addClass( "ui-state-hover" );
|
2009-04-02 00:10:52 +00:00
|
|
|
}
|
2012-05-21 13:55:56 +00:00
|
|
|
})
|
|
|
|
.mouseleave(function() {
|
2010-04-03 03:14:44 +00:00
|
|
|
$( this ).removeClass( "ui-state-hover" );
|
2009-04-02 00:10:52 +00:00
|
|
|
})
|
|
|
|
.focus(function() {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( !o.disabled ) {
|
|
|
|
$( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
|
|
|
|
$( this ).addClass( "ui-state-focus" );
|
2009-04-02 00:10:52 +00:00
|
|
|
} else {
|
2010-04-03 03:14:44 +00:00
|
|
|
$( this ).blur();
|
2009-04-02 00:10:52 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.blur(function() {
|
2010-04-03 03:14:44 +00:00
|
|
|
$( this ).removeClass( "ui-state-focus" );
|
2009-04-02 00:10:52 +00:00
|
|
|
});
|
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
|
|
|
});
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-11-16 11:47:22 +00:00
|
|
|
this._setOption( "disabled", o.disabled );
|
|
|
|
|
2012-06-13 12:00:45 +00:00
|
|
|
this._on( this.handles, {
|
2012-05-09 19:29:14 +00:00
|
|
|
keydown: function( event ) {
|
2012-12-06 19:25:48 +00:00
|
|
|
/*jshint maxcomplexity:25*/
|
2012-05-09 19:29:14 +00:00
|
|
|
var allowed, curVal, newVal, step,
|
|
|
|
index = $( event.target ).data( "ui-slider-handle-index" );
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
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:
|
2012-02-09 19:00:21 +00:00
|
|
|
event.preventDefault();
|
2012-05-09 19:29:14 +00:00
|
|
|
if ( !this._keySliding ) {
|
|
|
|
this._keySliding = true;
|
|
|
|
$( event.target ).addClass( "ui-state-active" );
|
|
|
|
allowed = this._start( event, index );
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( allowed === false ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2012-05-09 19:29:14 +00:00
|
|
|
step = this.options.step;
|
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
curVal = newVal = this.values( index );
|
2010-04-03 03:14:44 +00:00
|
|
|
} else {
|
2012-05-09 19:29:14 +00:00
|
|
|
curVal = newVal = this.value();
|
2010-04-03 03:14:44 +00:00
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.HOME:
|
2012-05-09 19:29:14 +00:00
|
|
|
newVal = this._valueMin();
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.END:
|
2012-05-09 19:29:14 +00:00
|
|
|
newVal = this._valueMax();
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_UP:
|
2012-05-09 19:29:14 +00:00
|
|
|
newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
2012-05-09 19:29:14 +00:00
|
|
|
newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
case $.ui.keyCode.RIGHT:
|
2012-05-09 19:29:14 +00:00
|
|
|
if ( curVal === this._valueMax() ) {
|
2010-04-01 19:08:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-09 19:29:14 +00:00
|
|
|
newVal = this._trimAlignValue( curVal + step );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.LEFT:
|
2012-05-09 19:29:14 +00:00
|
|
|
if ( curVal === this._valueMin() ) {
|
2010-04-03 03:14:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-09 19:29:14 +00:00
|
|
|
newVal = this._trimAlignValue( curVal - step );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2012-05-09 19:29:14 +00:00
|
|
|
this._slide( event, index, newVal );
|
|
|
|
},
|
|
|
|
keyup: function( event ) {
|
|
|
|
var index = $( event.target ).data( "ui-slider-handle-index" );
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2012-05-09 19:29:14 +00:00
|
|
|
if ( this._keySliding ) {
|
|
|
|
this._keySliding = false;
|
|
|
|
this._stop( event, index );
|
|
|
|
this._change( event, index );
|
|
|
|
$( event.target ).removeClass( "ui-state-active" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
this._refreshValue();
|
2008-11-21 04:40:23 +00:00
|
|
|
|
2009-10-12 10:50:38 +00:00
|
|
|
this._animateOff = false;
|
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();
|
2009-03-18 08:58:53 +00:00
|
|
|
this.range.remove();
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2008-11-21 04:40:23 +00:00
|
|
|
this.element
|
2010-04-03 03:14:44 +00:00
|
|
|
.removeClass( "ui-slider" +
|
|
|
|
" ui-slider-horizontal" +
|
|
|
|
" ui-slider-vertical" +
|
|
|
|
" ui-widget" +
|
|
|
|
" ui-widget-content" +
|
2012-05-09 19:42:18 +00:00
|
|
|
" ui-corner-all" );
|
2008-11-21 04:40:23 +00:00
|
|
|
|
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
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
closestHandle
|
2010-04-03 03:14:44 +00:00
|
|
|
.addClass( "ui-state-active" )
|
2008-12-23 10:38:12 +00:00
|
|
|
.focus();
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
offset = closestHandle.offset();
|
|
|
|
mouseOverHandle = !$( event.target ).parents().andSelf().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 ) {
|
|
|
|
this.handles.removeClass( "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 ) {
|
|
|
|
this.values( index, newVal, true );
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
$.Widget.prototype._setOption.apply( this, arguments );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case "disabled":
|
|
|
|
if ( value ) {
|
|
|
|
this.handles.filter( ".ui-state-focus" ).blur();
|
|
|
|
this.handles.removeClass( "ui-state-hover" );
|
2011-06-08 21:02:57 +00:00
|
|
|
this.handles.prop( "disabled", true );
|
2009-04-02 00:10:52 +00:00
|
|
|
} else {
|
2011-06-08 21:02:57 +00:00
|
|
|
this.handles.prop( "disabled", false );
|
2009-04-02 00:10:52 +00:00
|
|
|
}
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case "orientation":
|
2009-01-29 15:13:47 +00:00
|
|
|
this._detectOrientation();
|
2008-12-23 10:38:12 +00:00
|
|
|
this.element
|
2010-04-03 03:14:44 +00:00
|
|
|
.removeClass( "ui-slider-horizontal ui-slider-vertical" )
|
|
|
|
.addClass( "ui-slider-" + this.orientation );
|
2009-10-12 10:50:38 +00:00
|
|
|
this._refreshValue();
|
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;
|
2012-10-16 17:42:05 +00:00
|
|
|
case "min":
|
|
|
|
case "max":
|
|
|
|
this._animateOff = true;
|
|
|
|
this._refreshValue();
|
|
|
|
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;
|
2008-06-04 02:34:33 +00:00
|
|
|
} else {
|
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();
|
|
|
|
for ( i = 0; i < vals.length; i+= 1) {
|
|
|
|
vals[ i ] = this._trimAlignValue( vals[ i ] );
|
2009-10-12 14:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return vals;
|
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
|
|
|
|
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() {
|
2010-03-27 00:49:56 +00:00
|
|
|
return this.options.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
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2010-04-03 03:14:44 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
}(jQuery));
|