|
52 | 52 | keyboardSupport: true,
|
53 | 53 | scale: 1,
|
54 | 54 | enforceRange: false,
|
| 55 | + noSwitching: false, |
55 | 56 | onlyBindHandles: false,
|
56 | 57 | onStart: null,
|
57 | 58 | onChange: null,
|
|
843 | 844 | updateHandles: function(which, newOffset) {
|
844 | 845 | if (which === 'rzSliderModel')
|
845 | 846 | this.updateLowHandle(newOffset);
|
846 |
| - else if (which === 'rzSliderHigh') |
| 847 | + else |
847 | 848 | this.updateHighHandle(newOffset);
|
848 | 849 |
|
849 | 850 | this.updateSelectionBar();
|
|
883 | 884 | },
|
884 | 885 |
|
885 | 886 | /**
|
886 |
| - * Show / hide floor / ceiling label |
| 887 | + * Show/hide floor/ceiling label |
887 | 888 | *
|
888 | 889 | * @returns {undefined}
|
889 | 890 | */
|
|
1177 | 1178 | if (!this.range) {
|
1178 | 1179 | return this.minH;
|
1179 | 1180 | }
|
1180 |
| - var offset = this.getEventPosition(event); |
1181 |
| - return Math.abs(offset - this.minH.rzsp) < Math.abs(offset - this.maxH.rzsp) ? this.minH : this.maxH; |
| 1181 | + var offset = this.getEventPosition(event), |
| 1182 | + distanceMin = Math.abs(offset - this.minH.rzsp), |
| 1183 | + distanceMax = Math.abs(offset - this.maxH.rzsp); |
| 1184 | + if (distanceMin < distanceMax) |
| 1185 | + return this.minH; |
| 1186 | + else if (distanceMin > distanceMax) |
| 1187 | + return this.maxH; |
| 1188 | + else //if event is at the same distance from min/max then if it's at left of minH, we return minH else maxH |
| 1189 | + return offset < this.minH.rzsp ? this.minH : this.maxH; |
1182 | 1190 | },
|
1183 | 1191 |
|
1184 | 1192 | /**
|
|
1322 | 1330 | newValue;
|
1323 | 1331 |
|
1324 | 1332 | if (newOffset <= 0) {
|
1325 |
| - if (pointer.rzsp === 0) |
1326 |
| - return; |
1327 | 1333 | newValue = this.minValue;
|
1328 |
| - newOffset = 0; |
1329 | 1334 | } else if (newOffset >= this.maxPos) {
|
1330 |
| - if (pointer.rzsp === this.maxPos) |
1331 |
| - return; |
1332 | 1335 | newValue = this.maxValue;
|
1333 |
| - newOffset = this.maxPos; |
1334 | 1336 | } else {
|
1335 | 1337 | newValue = this.offsetToValue(newOffset);
|
1336 | 1338 | newValue = this.roundStep(newValue);
|
1337 |
| - newOffset = this.valueToOffset(newValue); |
1338 | 1339 | }
|
1339 |
| - this.positionTrackingHandle(newValue, newOffset); |
| 1340 | + this.positionTrackingHandle(newValue); |
1340 | 1341 | },
|
1341 | 1342 |
|
1342 | 1343 | /**
|
|
1402 | 1403 | if (action == null || this.tracking === '') return;
|
1403 | 1404 | event.preventDefault();
|
1404 | 1405 |
|
1405 |
| - var newValue = this.roundStep(this.sanitizeValue(action)), |
1406 |
| - newOffset = this.valueToOffset(newValue); |
| 1406 | + var newValue = this.roundStep(this.sanitizeValue(action)); |
1407 | 1407 | if (!this.options.draggableRangeOnly) {
|
1408 |
| - this.positionTrackingHandle(newValue, newOffset); |
| 1408 | + this.positionTrackingHandle(newValue); |
1409 | 1409 | } else {
|
1410 | 1410 | var difference = this.scope.rzSliderHigh - this.scope.rzSliderModel,
|
1411 |
| - newMinOffset, newMaxOffset, |
1412 | 1411 | newMinValue, newMaxValue;
|
1413 | 1412 | if (this.tracking === 'rzSliderModel') {
|
1414 | 1413 | newMinValue = newValue;
|
1415 |
| - newMinOffset = newOffset; |
1416 | 1414 | newMaxValue = newValue + difference;
|
1417 | 1415 | if (newMaxValue > this.maxValue) {
|
1418 | 1416 | newMaxValue = this.maxValue;
|
1419 | 1417 | newMinValue = newMaxValue - difference;
|
1420 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1421 | 1418 | }
|
1422 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1423 | 1419 | } else {
|
1424 | 1420 | newMaxValue = newValue;
|
1425 |
| - newMaxOffset = newOffset; |
1426 | 1421 | newMinValue = newValue - difference;
|
1427 | 1422 | if (newMinValue < this.minValue) {
|
1428 | 1423 | newMinValue = this.minValue;
|
1429 | 1424 | newMaxValue = newMinValue + difference;
|
1430 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1431 | 1425 | }
|
1432 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1433 | 1426 | }
|
1434 |
| - this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset); |
| 1427 | + this.positionTrackingBar(newMinValue, newMaxValue); |
1435 | 1428 | }
|
1436 | 1429 | },
|
1437 | 1430 |
|
|
1469 | 1462 | */
|
1470 | 1463 | onDragMove: function(pointer, event) {
|
1471 | 1464 | var newOffset = this.getEventPosition(event),
|
1472 |
| - newMinOffset, newMaxOffset, |
1473 | 1465 | newMinValue, newMaxValue;
|
1474 | 1466 |
|
1475 | 1467 | if (newOffset <= this.dragging.lowLimit) {
|
1476 | 1468 | if (this.minH.rzsp === 0)
|
1477 | 1469 | return;
|
1478 | 1470 | newMinValue = this.minValue;
|
1479 |
| - newMinOffset = 0; |
1480 | 1471 | newMaxValue = this.minValue + this.dragging.difference;
|
1481 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1482 | 1472 | } else if (newOffset >= this.maxPos - this.dragging.highLimit) {
|
1483 | 1473 | if (this.maxH.rzsp === this.maxPos)
|
1484 | 1474 | return;
|
1485 | 1475 | newMaxValue = this.maxValue;
|
1486 |
| - newMaxOffset = this.maxPos; |
1487 | 1476 | newMinValue = this.maxValue - this.dragging.difference;
|
1488 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1489 | 1477 | } else {
|
1490 | 1478 | newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit);
|
1491 | 1479 | newMinValue = this.roundStep(newMinValue);
|
1492 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1493 | 1480 | newMaxValue = newMinValue + this.dragging.difference;
|
1494 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1495 | 1481 | }
|
1496 | 1482 |
|
1497 |
| - this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset); |
| 1483 | + this.positionTrackingBar(newMinValue, newMaxValue); |
1498 | 1484 | },
|
1499 | 1485 |
|
1500 | 1486 | /**
|
1501 | 1487 | * Set the new value and offset for the entire bar
|
1502 | 1488 | *
|
1503 | 1489 | * @param {number} newMinValue the new minimum value
|
1504 | 1490 | * @param {number} newMaxValue the new maximum value
|
1505 |
| - * @param {number} newMinOffset the new minimum offset |
1506 |
| - * @param {number} newMaxOffset the new maximum offset |
1507 | 1491 | */
|
1508 |
| - positionTrackingBar: function(newMinValue, newMaxValue, newMinOffset, newMaxOffset) { |
| 1492 | + positionTrackingBar: function(newMinValue, newMaxValue) { |
1509 | 1493 | this.scope.rzSliderModel = newMinValue;
|
1510 | 1494 | this.scope.rzSliderHigh = newMaxValue;
|
1511 |
| - this.updateHandles('rzSliderModel', newMinOffset); |
1512 |
| - this.updateHandles('rzSliderHigh', newMaxOffset); |
| 1495 | + this.updateHandles('rzSliderModel', this.valueToOffset(newMinValue)); |
| 1496 | + this.updateHandles('rzSliderHigh', this.valueToOffset(newMaxValue)); |
1513 | 1497 | this.applyModel();
|
1514 | 1498 | },
|
1515 | 1499 |
|
1516 | 1500 | /**
|
1517 | 1501 | * Set the new value and offset to the current tracking handle
|
1518 | 1502 | *
|
1519 | 1503 | * @param {number} newValue new model value
|
1520 |
| - * @param {number} newOffset new offset value |
1521 | 1504 | */
|
1522 |
| - positionTrackingHandle: function(newValue, newOffset) { |
| 1505 | + positionTrackingHandle: function(newValue) { |
1523 | 1506 | var valueChanged = false;
|
1524 |
| - var switched = false; |
1525 | 1507 |
|
1526 | 1508 | if (this.range) {
|
1527 | 1509 | newValue = this.applyMinRange(newValue);
|
1528 |
| - newOffset = this.valueToOffset(newValue); |
1529 | 1510 | /* This is to check if we need to switch the min and max handles */
|
1530 |
| - if (this.tracking === 'rzSliderModel' && newValue >= this.scope.rzSliderHigh) { |
1531 |
| - switched = true; |
1532 |
| - this.scope[this.tracking] = this.scope.rzSliderHigh; |
1533 |
| - this.updateHandles(this.tracking, this.maxH.rzsp); |
1534 |
| - this.updateAriaAttributes(); |
1535 |
| - this.tracking = 'rzSliderHigh'; |
1536 |
| - this.minH.removeClass('rz-active'); |
1537 |
| - this.maxH.addClass('rz-active'); |
1538 |
| - if (this.options.keyboardSupport) |
1539 |
| - this.focusElement(this.maxH); |
| 1511 | + if (this.tracking === 'rzSliderModel' && newValue > this.scope.rzSliderHigh) { |
| 1512 | + if (this.options.noSwitching && this.scope.rzSliderHigh !== this.minValue) { |
| 1513 | + newValue = this.applyMinRange(this.scope.rzSliderHigh); |
| 1514 | + } |
| 1515 | + else { |
| 1516 | + this.scope[this.tracking] = this.scope.rzSliderHigh; |
| 1517 | + this.updateHandles(this.tracking, this.maxH.rzsp); |
| 1518 | + this.updateAriaAttributes(); |
| 1519 | + this.tracking = 'rzSliderHigh'; |
| 1520 | + this.minH.removeClass('rz-active'); |
| 1521 | + this.maxH.addClass('rz-active'); |
| 1522 | + if (this.options.keyboardSupport) |
| 1523 | + this.focusElement(this.maxH); |
| 1524 | + } |
1540 | 1525 | valueChanged = true;
|
1541 |
| - } else if (this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel) { |
1542 |
| - switched = true; |
1543 |
| - this.scope[this.tracking] = this.scope.rzSliderModel; |
1544 |
| - this.updateHandles(this.tracking, this.minH.rzsp); |
1545 |
| - this.updateAriaAttributes(); |
1546 |
| - this.tracking = 'rzSliderModel'; |
1547 |
| - this.maxH.removeClass('rz-active'); |
1548 |
| - this.minH.addClass('rz-active'); |
1549 |
| - if (this.options.keyboardSupport) |
1550 |
| - this.focusElement(this.minH); |
| 1526 | + } else if (this.tracking === 'rzSliderHigh' && newValue < this.scope.rzSliderModel) { |
| 1527 | + if (this.options.noSwitching && this.scope.rzSliderModel !== this.maxValue) { |
| 1528 | + newValue = this.applyMinRange(this.scope.rzSliderModel); |
| 1529 | + } |
| 1530 | + else { |
| 1531 | + this.scope[this.tracking] = this.scope.rzSliderModel; |
| 1532 | + this.updateHandles(this.tracking, this.minH.rzsp); |
| 1533 | + this.updateAriaAttributes(); |
| 1534 | + this.tracking = 'rzSliderModel'; |
| 1535 | + this.maxH.removeClass('rz-active'); |
| 1536 | + this.minH.addClass('rz-active'); |
| 1537 | + if (this.options.keyboardSupport) |
| 1538 | + this.focusElement(this.minH); |
| 1539 | + } |
1551 | 1540 | valueChanged = true;
|
1552 | 1541 | }
|
1553 | 1542 | }
|
1554 | 1543 |
|
1555 | 1544 | if (this.scope[this.tracking] !== newValue) {
|
1556 | 1545 | this.scope[this.tracking] = newValue;
|
1557 |
| - this.updateHandles(this.tracking, newOffset); |
| 1546 | + this.updateHandles(this.tracking, this.valueToOffset(newValue)); |
1558 | 1547 | this.updateAriaAttributes();
|
1559 | 1548 | valueChanged = true;
|
1560 | 1549 | }
|
1561 | 1550 |
|
1562 |
| - if (valueChanged) { |
| 1551 | + if (valueChanged) |
1563 | 1552 | this.applyModel();
|
1564 |
| - } |
1565 |
| - return switched; |
1566 | 1553 | },
|
1567 | 1554 |
|
1568 | 1555 | applyMinRange: function(newValue) {
|
|
0 commit comments