|
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,
|
|
1322 | 1323 | newValue;
|
1323 | 1324 |
|
1324 | 1325 | if (newOffset <= 0) {
|
1325 |
| - if (pointer.rzsp === 0) |
1326 |
| - return; |
1327 | 1326 | newValue = this.minValue;
|
1328 |
| - newOffset = 0; |
1329 | 1327 | } else if (newOffset >= this.maxPos) {
|
1330 |
| - if (pointer.rzsp === this.maxPos) |
1331 |
| - return; |
1332 | 1328 | newValue = this.maxValue;
|
1333 |
| - newOffset = this.maxPos; |
1334 | 1329 | } else {
|
1335 | 1330 | newValue = this.offsetToValue(newOffset);
|
1336 | 1331 | newValue = this.roundStep(newValue);
|
1337 |
| - newOffset = this.valueToOffset(newValue); |
1338 | 1332 | }
|
1339 |
| - this.positionTrackingHandle(newValue, newOffset); |
| 1333 | + this.positionTrackingHandle(newValue); |
1340 | 1334 | },
|
1341 | 1335 |
|
1342 | 1336 | /**
|
|
1402 | 1396 | if (action == null || this.tracking === '') return;
|
1403 | 1397 | event.preventDefault();
|
1404 | 1398 |
|
1405 |
| - var newValue = this.roundStep(this.sanitizeValue(action)), |
1406 |
| - newOffset = this.valueToOffset(newValue); |
| 1399 | + var newValue = this.roundStep(this.sanitizeValue(action)); |
1407 | 1400 | if (!this.options.draggableRangeOnly) {
|
1408 |
| - this.positionTrackingHandle(newValue, newOffset); |
| 1401 | + this.positionTrackingHandle(newValue); |
1409 | 1402 | } else {
|
1410 | 1403 | var difference = this.scope.rzSliderHigh - this.scope.rzSliderModel,
|
1411 |
| - newMinOffset, newMaxOffset, |
1412 | 1404 | newMinValue, newMaxValue;
|
1413 | 1405 | if (this.tracking === 'rzSliderModel') {
|
1414 | 1406 | newMinValue = newValue;
|
1415 |
| - newMinOffset = newOffset; |
1416 | 1407 | newMaxValue = newValue + difference;
|
1417 | 1408 | if (newMaxValue > this.maxValue) {
|
1418 | 1409 | newMaxValue = this.maxValue;
|
1419 | 1410 | newMinValue = newMaxValue - difference;
|
1420 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1421 | 1411 | }
|
1422 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1423 | 1412 | } else {
|
1424 | 1413 | newMaxValue = newValue;
|
1425 |
| - newMaxOffset = newOffset; |
1426 | 1414 | newMinValue = newValue - difference;
|
1427 | 1415 | if (newMinValue < this.minValue) {
|
1428 | 1416 | newMinValue = this.minValue;
|
1429 | 1417 | newMaxValue = newMinValue + difference;
|
1430 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1431 | 1418 | }
|
1432 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1433 | 1419 | }
|
1434 |
| - this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset); |
| 1420 | + this.positionTrackingBar(newMinValue, newMaxValue); |
1435 | 1421 | }
|
1436 | 1422 | },
|
1437 | 1423 |
|
|
1469 | 1455 | */
|
1470 | 1456 | onDragMove: function(pointer, event) {
|
1471 | 1457 | var newOffset = this.getEventPosition(event),
|
1472 |
| - newMinOffset, newMaxOffset, |
1473 | 1458 | newMinValue, newMaxValue;
|
1474 | 1459 |
|
1475 | 1460 | if (newOffset <= this.dragging.lowLimit) {
|
1476 | 1461 | if (this.minH.rzsp === 0)
|
1477 | 1462 | return;
|
1478 | 1463 | newMinValue = this.minValue;
|
1479 |
| - newMinOffset = 0; |
1480 | 1464 | newMaxValue = this.minValue + this.dragging.difference;
|
1481 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1482 | 1465 | } else if (newOffset >= this.maxPos - this.dragging.highLimit) {
|
1483 | 1466 | if (this.maxH.rzsp === this.maxPos)
|
1484 | 1467 | return;
|
1485 | 1468 | newMaxValue = this.maxValue;
|
1486 |
| - newMaxOffset = this.maxPos; |
1487 | 1469 | newMinValue = this.maxValue - this.dragging.difference;
|
1488 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1489 | 1470 | } else {
|
1490 | 1471 | newMinValue = this.offsetToValue(newOffset - this.dragging.lowLimit);
|
1491 | 1472 | newMinValue = this.roundStep(newMinValue);
|
1492 |
| - newMinOffset = this.valueToOffset(newMinValue); |
1493 | 1473 | newMaxValue = newMinValue + this.dragging.difference;
|
1494 |
| - newMaxOffset = this.valueToOffset(newMaxValue); |
1495 | 1474 | }
|
1496 | 1475 |
|
1497 |
| - this.positionTrackingBar(newMinValue, newMaxValue, newMinOffset, newMaxOffset); |
| 1476 | + this.positionTrackingBar(newMinValue, newMaxValue); |
1498 | 1477 | },
|
1499 | 1478 |
|
1500 | 1479 | /**
|
1501 | 1480 | * Set the new value and offset for the entire bar
|
1502 | 1481 | *
|
1503 | 1482 | * @param {number} newMinValue the new minimum value
|
1504 | 1483 | * @param {number} newMaxValue the new maximum value
|
1505 |
| - * @param {number} newMinOffset the new minimum offset |
1506 |
| - * @param {number} newMaxOffset the new maximum offset |
1507 | 1484 | */
|
1508 |
| - positionTrackingBar: function(newMinValue, newMaxValue, newMinOffset, newMaxOffset) { |
| 1485 | + positionTrackingBar: function(newMinValue, newMaxValue) { |
1509 | 1486 | this.scope.rzSliderModel = newMinValue;
|
1510 | 1487 | this.scope.rzSliderHigh = newMaxValue;
|
1511 |
| - this.updateHandles('rzSliderModel', newMinOffset); |
1512 |
| - this.updateHandles('rzSliderHigh', newMaxOffset); |
| 1488 | + this.updateHandles('rzSliderModel', this.valueToOffset(newMinValue)); |
| 1489 | + this.updateHandles('rzSliderHigh', this.valueToOffset(newMaxValue)); |
1513 | 1490 | this.applyModel();
|
1514 | 1491 | },
|
1515 | 1492 |
|
1516 | 1493 | /**
|
1517 | 1494 | * Set the new value and offset to the current tracking handle
|
1518 | 1495 | *
|
1519 | 1496 | * @param {number} newValue new model value
|
1520 |
| - * @param {number} newOffset new offset value |
1521 | 1497 | */
|
1522 |
| - positionTrackingHandle: function(newValue, newOffset) { |
| 1498 | + positionTrackingHandle: function(newValue) { |
1523 | 1499 | var valueChanged = false;
|
1524 |
| - var switched = false; |
1525 | 1500 |
|
1526 | 1501 | if (this.range) {
|
1527 | 1502 | newValue = this.applyMinRange(newValue);
|
1528 |
| - newOffset = this.valueToOffset(newValue); |
1529 | 1503 | /* 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); |
| 1504 | + if (this.tracking === 'rzSliderModel' && newValue > this.scope.rzSliderHigh) { |
| 1505 | + if(this.options.noSwitching && this.scope.rzSliderHigh !== this.minValue) { |
| 1506 | + newValue = this.scope.rzSliderHigh; |
| 1507 | + } |
| 1508 | + else { |
| 1509 | + this.scope[this.tracking] = this.scope.rzSliderHigh; |
| 1510 | + this.updateHandles(this.tracking, this.maxH.rzsp); |
| 1511 | + this.updateAriaAttributes(); |
| 1512 | + this.tracking = 'rzSliderHigh'; |
| 1513 | + this.minH.removeClass('rz-active'); |
| 1514 | + this.maxH.addClass('rz-active'); |
| 1515 | + if (this.options.keyboardSupport) |
| 1516 | + this.focusElement(this.maxH); |
| 1517 | + } |
1540 | 1518 | 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); |
| 1519 | + } else if (this.tracking === 'rzSliderHigh' && newValue < this.scope.rzSliderModel) { |
| 1520 | + if(this.options.noSwitching && this.scope.rzSliderModel !== this.maxValue) { |
| 1521 | + newValue = this.scope.rzSliderModel; |
| 1522 | + } |
| 1523 | + else { |
| 1524 | + this.scope[this.tracking] = this.scope.rzSliderModel; |
| 1525 | + this.updateHandles(this.tracking, this.minH.rzsp); |
| 1526 | + this.updateAriaAttributes(); |
| 1527 | + this.tracking = 'rzSliderModel'; |
| 1528 | + this.maxH.removeClass('rz-active'); |
| 1529 | + this.minH.addClass('rz-active'); |
| 1530 | + if (this.options.keyboardSupport) |
| 1531 | + this.focusElement(this.minH); |
| 1532 | + } |
1551 | 1533 | valueChanged = true;
|
1552 | 1534 | }
|
1553 | 1535 | }
|
1554 | 1536 |
|
1555 | 1537 | if (this.scope[this.tracking] !== newValue) {
|
1556 | 1538 | this.scope[this.tracking] = newValue;
|
1557 |
| - this.updateHandles(this.tracking, newOffset); |
| 1539 | + this.updateHandles(this.tracking, this.valueToOffset(newValue)); |
1558 | 1540 | this.updateAriaAttributes();
|
1559 | 1541 | valueChanged = true;
|
1560 | 1542 | }
|
1561 | 1543 |
|
1562 |
| - if (valueChanged) { |
| 1544 | + if (valueChanged) |
1563 | 1545 | this.applyModel();
|
1564 |
| - } |
1565 |
| - return switched; |
1566 | 1546 | },
|
1567 | 1547 |
|
1568 | 1548 | applyMinRange: function(newValue) {
|
|
0 commit comments