slider.rtl.min.js 23 KB

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