|
1 | 1 | /*! angularjs-slider - v2.11.0 - |
2 | 2 | (c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - |
3 | 3 | https://github.com/angular-slider/angularjs-slider - |
4 | | - 2016-04-01 */ |
| 4 | + 2016-04-22 */ |
5 | 5 | /*jslint unparam: true */ |
6 | 6 | /*global angular: false, console: false, define, module */ |
7 | 7 | (function(root, factory) { |
|
247 | 247 | */ |
248 | 248 | this.valueRange = 0; |
249 | 249 |
|
| 250 | + |
| 251 | + /** |
| 252 | + * If showTicks/showTicksValues options are number. |
| 253 | + * In this case, ticks values should be displayed below the slider. |
| 254 | + * @type {boolean} |
| 255 | + */ |
| 256 | + this.intermediateTicks = false; |
| 257 | + |
250 | 258 | /** |
251 | 259 | * Set to true if init method already executed |
252 | 260 | * |
|
416 | 424 |
|
417 | 425 | this.options.showTicks = this.options.showTicks || this.options.showTicksValues; |
418 | 426 | this.scope.showTicks = this.options.showTicks; //scope is used in the template |
| 427 | + if(angular.isNumber(this.options.showTicks)) |
| 428 | + this.intermediateTicks = true; |
419 | 429 |
|
420 | 430 | this.options.showSelectionBar = this.options.showSelectionBar || this.options.showSelectionBarEnd |
421 | 431 | || this.options.showSelectionBarFromValue !== null; |
|
530 | 540 | else |
531 | 541 | this.maxH.css('display', ''); |
532 | 542 |
|
| 543 | + |
533 | 544 | this.alwaysHide(this.flrLab, this.options.showTicksValues || this.options.hideLimitLabels); |
534 | 545 | this.alwaysHide(this.ceilLab, this.options.showTicksValues || this.options.hideLimitLabels); |
535 | | - this.alwaysHide(this.minLab, this.options.showTicksValues || this.options.hidePointerLabels); |
536 | | - this.alwaysHide(this.maxLab, this.options.showTicksValues || !this.range || this.options.hidePointerLabels); |
537 | | - this.alwaysHide(this.cmbLab, this.options.showTicksValues || !this.range || this.options.hidePointerLabels); |
| 546 | + |
| 547 | + var hideLabelsForTicks = this.options.showTicksValues && !this.intermediateTicks; |
| 548 | + this.alwaysHide(this.minLab, hideLabelsForTicks || this.options.hidePointerLabels); |
| 549 | + this.alwaysHide(this.maxLab, hideLabelsForTicks || !this.range || this.options.hidePointerLabels); |
| 550 | + this.alwaysHide(this.cmbLab, hideLabelsForTicks || !this.range || this.options.hidePointerLabels); |
538 | 551 | this.alwaysHide(this.selBar, !this.range && !this.options.showSelectionBar); |
539 | 552 |
|
540 | 553 | if (this.options.vertical) |
|
544 | 557 | this.selBar.addClass('rz-draggable'); |
545 | 558 | else |
546 | 559 | this.selBar.removeClass('rz-draggable'); |
| 560 | + |
| 561 | + if(this.intermediateTicks && this.options.showTicksValues) |
| 562 | + this.ticks.addClass('rz-ticks-values-under'); |
547 | 563 | }, |
548 | 564 |
|
549 | 565 | alwaysHide: function(el, hide) { |
|
751 | 767 | */ |
752 | 768 | updateTicksScale: function() { |
753 | 769 | if (!this.options.showTicks) return; |
754 | | - |
755 | | - var positions = '', |
756 | | - ticksCount = Math.round((this.maxValue - this.minValue) / this.step) + 1; |
| 770 | + var step = this.step; |
| 771 | + if(this.intermediateTicks) |
| 772 | + step = this.options.showTicks; |
| 773 | + var ticksCount = Math.round((this.maxValue - this.minValue) / step) + 1; |
757 | 774 | this.scope.ticks = []; |
758 | 775 | for (var i = 0; i < ticksCount; i++) { |
759 | | - var value = this.roundStep(this.minValue + i * this.step); |
| 776 | + var value = this.roundStep(this.minValue + i * step); |
760 | 777 | var tick = { |
761 | 778 | selected: this.isTickSelected(value) |
762 | 779 | }; |
|
1077 | 1094 | /** |
1078 | 1095 | * Return the translated value if a translate function is provided else the original value |
1079 | 1096 | * @param value |
| 1097 | + * @param which if it's min or max handle |
1080 | 1098 | * @returns {*} |
1081 | 1099 | */ |
1082 | 1100 | getDisplayValue: function(value, which) { |
|
1087 | 1105 | * Round value to step and precision based on minValue |
1088 | 1106 | * |
1089 | 1107 | * @param {number} value |
| 1108 | + * @param {number} customStep a custom step to override the defined step |
1090 | 1109 | * @returns {number} |
1091 | 1110 | */ |
1092 | | - roundStep: function(value) { |
1093 | | - var steppedDifference = parseFloat((value - this.minValue) / this.step).toPrecision(12); |
1094 | | - steppedDifference = Math.round(steppedDifference) * this.step; |
| 1111 | + roundStep: function(value, customStep) { |
| 1112 | + var step = customStep ? customStep : this.step, |
| 1113 | + steppedDifference = parseFloat((value - this.minValue) / step).toPrecision(12); |
| 1114 | + steppedDifference = Math.round(+steppedDifference) * step; |
1095 | 1115 | var newValue = (this.minValue + steppedDifference).toFixed(this.precision); |
1096 | 1116 | return +newValue; |
1097 | 1117 | }, |
|
1334 | 1354 | this.fullBar.on('mousedown', angular.bind(this, this.onStart, null, null)); |
1335 | 1355 | this.fullBar.on('mousedown', angular.bind(this, this.onMove, this.fullBar)); |
1336 | 1356 | this.ticks.on('mousedown', angular.bind(this, this.onStart, null, null)); |
1337 | | - this.ticks.on('mousedown', angular.bind(this, this.onMove, this.ticks)); |
| 1357 | + this.ticks.on('mousedown', angular.bind(this, this.onTickClick, this.ticks)); |
1338 | 1358 | } |
1339 | 1359 | } |
1340 | 1360 |
|
|
1354 | 1374 | this.fullBar.on('touchstart', angular.bind(this, this.onStart, null, null)); |
1355 | 1375 | this.fullBar.on('touchstart', angular.bind(this, this.onMove, this.fullBar)); |
1356 | 1376 | this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null)); |
1357 | | - this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks)); |
| 1377 | + this.ticks.on('touchstart', angular.bind(this, this.onTickClick, this.ticks)); |
1358 | 1378 | } |
1359 | 1379 | } |
1360 | 1380 |
|
|
1423 | 1443 | * |
1424 | 1444 | * @param {jqLite} pointer |
1425 | 1445 | * @param {Event} event The event |
| 1446 | + * @param {boolean} fromTick if the event occured on a tick or not |
1426 | 1447 | * @returns {undefined} |
1427 | 1448 | */ |
1428 | | - onMove: function(pointer, event) { |
| 1449 | + onMove: function(pointer, event, fromTick) { |
1429 | 1450 | var newOffset = this.getEventPosition(event), |
1430 | 1451 | newValue, |
1431 | 1452 | ceilValue = this.options.rightToLeft ? this.minValue : this.maxValue, |
|
1437 | 1458 | newValue = ceilValue; |
1438 | 1459 | } else { |
1439 | 1460 | newValue = this.offsetToValue(newOffset); |
1440 | | - newValue = this.roundStep(newValue); |
| 1461 | + if(fromTick && angular.isNumber(this.options.showTicks)) |
| 1462 | + newValue = this.roundStep(newValue, this.options.showTicks); |
| 1463 | + else |
| 1464 | + newValue = this.roundStep(newValue); |
1441 | 1465 | } |
1442 | 1466 | this.positionTrackingHandle(newValue); |
1443 | 1467 | }, |
|
1464 | 1488 | this.callOnEnd(); |
1465 | 1489 | }, |
1466 | 1490 |
|
| 1491 | + onTickClick: function(pointer, event) { |
| 1492 | + this.onMove(pointer, event, true); |
| 1493 | + }, |
| 1494 | + |
1467 | 1495 | onPointerFocus: function(pointer, ref) { |
1468 | 1496 | this.tracking = ref; |
1469 | 1497 | pointer.one('blur', angular.bind(this, this.onPointerBlur, pointer)); |
|
0 commit comments