2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Slider @VERSION
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2012-03-08 15:53:08 +00:00
|
|
|
* Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-11-20 04:10:34 +00:00
|
|
|
*
|
2008-06-04 02:34:33 +00:00
|
|
|
* http://docs.jquery.com/UI/Slider
|
|
|
|
*
|
|
|
|
* 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() {
|
2010-04-03 03:14:44 +00:00
|
|
|
var self = this,
|
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>",
|
|
|
|
handleCount = ( o.values && o.values.length ) || 1,
|
|
|
|
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" +
|
2011-05-11 17:13:09 +00:00
|
|
|
" ui-corner-all" +
|
|
|
|
( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );
|
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
|
|
|
|
2011-05-11 17:13:09 +00:00
|
|
|
for ( var i = existingHandles.length; i < handleCount; i += 1 ) {
|
|
|
|
handles.push( handle );
|
2008-12-23 10:38:12 +00:00
|
|
|
}
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2011-05-11 17:13:09 +00:00
|
|
|
this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( self.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();
|
|
|
|
})
|
|
|
|
.hover(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
|
|
|
}
|
|
|
|
}, 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
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
this.handles
|
|
|
|
.keydown(function( event ) {
|
2012-03-01 12:29:56 +00:00
|
|
|
var index = $( this ).data( "ui-slider-handle-index" ),
|
2010-04-03 03:14:44 +00:00
|
|
|
allowed,
|
|
|
|
curVal,
|
|
|
|
newVal,
|
|
|
|
step;
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( self.options.disabled ) {
|
|
|
|
return;
|
|
|
|
}
|
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();
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( !self._keySliding ) {
|
|
|
|
self._keySliding = true;
|
|
|
|
$( this ).addClass( "ui-state-active" );
|
|
|
|
allowed = self._start( event, index );
|
|
|
|
if ( allowed === false ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
step = self.options.step;
|
|
|
|
if ( self.options.values && self.options.values.length ) {
|
|
|
|
curVal = newVal = self.values( index );
|
|
|
|
} else {
|
|
|
|
curVal = newVal = self.value();
|
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.HOME:
|
|
|
|
newVal = self._valueMin();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.END:
|
|
|
|
newVal = self._valueMax();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_UP:
|
2010-05-11 11:31:48 +00:00
|
|
|
newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
2010-05-11 11:31:48 +00:00
|
|
|
newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
case $.ui.keyCode.RIGHT:
|
|
|
|
if ( curVal === self._valueMax() ) {
|
2010-04-01 19:08:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-11 12:36:56 +00:00
|
|
|
newVal = self._trimAlignValue( curVal + step );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.LEFT:
|
|
|
|
if ( curVal === self._valueMin() ) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-11 12:36:56 +00:00
|
|
|
newVal = self._trimAlignValue( curVal - step );
|
2010-04-03 03:14:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
self._slide( event, index, newVal );
|
|
|
|
})
|
|
|
|
.keyup(function( event ) {
|
2012-03-01 12:29:56 +00:00
|
|
|
var index = $( this ).data( "ui-slider-handle-index" );
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( self._keySliding ) {
|
|
|
|
self._keySliding = false;
|
|
|
|
self._stop( event, index );
|
|
|
|
self._change( event, index );
|
|
|
|
$( this ).removeClass( "ui-state-active" );
|
|
|
|
}
|
2012-03-01 12:29:31 +00:00
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
});
|
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
|
|
|
},
|
|
|
|
|
|
|
|
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-slider-disabled" +
|
|
|
|
" ui-widget" +
|
|
|
|
" ui-widget-content" +
|
|
|
|
" ui-corner-all" )
|
|
|
|
.removeData( "slider" )
|
|
|
|
.unbind( ".slider" );
|
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
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
return this;
|
2008-11-21 04:40:23 +00:00
|
|
|
},
|
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_mouseCapture: function( event ) {
|
|
|
|
var o = this.options,
|
|
|
|
position,
|
|
|
|
normValue,
|
|
|
|
distance,
|
|
|
|
closestHandle,
|
|
|
|
self,
|
|
|
|
index,
|
|
|
|
allowed,
|
|
|
|
offset,
|
|
|
|
mouseOverHandle;
|
|
|
|
|
|
|
|
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;
|
|
|
|
self = this;
|
|
|
|
this.handles.each(function( i ) {
|
|
|
|
var thisDistance = Math.abs( normValue - self.values(i) );
|
|
|
|
if ( distance > thisDistance ) {
|
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
|
|
|
|
|
|
|
// workaround for bug #3736 (if both handles of a range are at 0,
|
|
|
|
// the first is always used as the one with least distance,
|
2009-01-28 23:11:15 +00:00
|
|
|
// and moving it is obviously prevented by preventing negative ranges)
|
2010-04-03 03:14:44 +00:00
|
|
|
if( o.range === true && this.values(1) === o.min ) {
|
|
|
|
index += 1;
|
|
|
|
closestHandle = $( this.handles[index] );
|
2009-01-28 19:10:37 +00:00
|
|
|
}
|
2008-11-21 04:40:23 +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
|
|
|
|
2008-12-31 19:55:16 +00:00
|
|
|
self._handleIndex = index;
|
|
|
|
|
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
|
|
|
|
2010-04-03 03:14:44 +00:00
|
|
|
_mouseStart: function( event ) {
|
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
|
|
|
|
|
|
|
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 );
|
2010-04-03 03:14:44 +00:00
|
|
|
this.element.addClass( "ui-disabled" );
|
2009-04-02 00:10:52 +00:00
|
|
|
} else {
|
2011-06-08 21:02:57 +00:00
|
|
|
this.handles.prop( "disabled", false );
|
2010-04-03 03:14:44 +00:00
|
|
|
this.element.removeClass( "ui-disabled" );
|
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;
|
|
|
|
}
|
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() {
|
2010-04-03 03:14:44 +00:00
|
|
|
var oRange = this.options.range,
|
|
|
|
o = this.options,
|
|
|
|
self = this,
|
|
|
|
animate = ( !this._animateOff ) ? o.animate : false,
|
|
|
|
valPercent,
|
|
|
|
_set = {},
|
|
|
|
lastValPercent,
|
|
|
|
value,
|
|
|
|
valueMin,
|
|
|
|
valueMax;
|
|
|
|
|
|
|
|
if ( this.options.values && this.options.values.length ) {
|
|
|
|
this.handles.each(function( i, j ) {
|
|
|
|
valPercent = ( self.values(i) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100;
|
|
|
|
_set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
|
|
|
|
$( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
|
|
|
|
if ( self.options.range === true ) {
|
|
|
|
if ( self.orientation === "horizontal" ) {
|
|
|
|
if ( i === 0 ) {
|
|
|
|
self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
|
|
|
|
}
|
|
|
|
if ( i === 1 ) {
|
|
|
|
self.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
|
|
|
|
}
|
2008-12-23 10:38:12 +00:00
|
|
|
} else {
|
2010-04-03 03:14:44 +00:00
|
|
|
if ( i === 0 ) {
|
|
|
|
self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
|
|
|
|
}
|
|
|
|
if ( i === 1 ) {
|
|
|
|
self.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
|
|
|
|
}
|
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;
|
|
|
|
_set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
|
|
|
|
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));
|