|
243 | 243 | */
|
244 | 244 | this.initHasRun = false;
|
245 | 245 |
|
| 246 | + /** |
| 247 | + * Internal flag to prevent watchers to be called when the sliders value are modified internally. |
| 248 | + * @type {boolean} |
| 249 | + */ |
| 250 | + this.internalChange = false; |
| 251 | + |
246 | 252 | // Slider DOM elements wrapped in jqLite
|
247 | 253 | this.fullBar = null; // The whole slider bar
|
248 | 254 | this.selBar = null; // Highlight between two handles
|
|
328 | 334 | self.resetSlider();
|
329 | 335 | });
|
330 | 336 |
|
331 |
| - // Watchers |
| 337 | + // Watchers (order is important because in case of simultaneous change, |
| 338 | + // watchers will be called in the same order) |
| 339 | + this.scope.$watch('rzSliderOptions', function(newValue, oldValue) { |
| 340 | + if (newValue === oldValue) |
| 341 | + return; |
| 342 | + self.applyOptions(); |
| 343 | + self.resetSlider(); |
| 344 | + }, true); |
| 345 | + |
332 | 346 | this.scope.$watch('rzSliderModel', function(newValue, oldValue) {
|
| 347 | + if(self.internalChange) |
| 348 | + return; |
333 | 349 | if (newValue === oldValue)
|
334 | 350 | return;
|
335 | 351 | thrLow();
|
336 | 352 | });
|
337 | 353 |
|
338 | 354 | this.scope.$watch('rzSliderHigh', function(newValue, oldValue) {
|
| 355 | + if(self.internalChange) |
| 356 | + return; |
339 | 357 | if (newValue === oldValue)
|
340 | 358 | return;
|
341 | 359 | if (newValue != null)
|
|
346 | 364 | }
|
347 | 365 | });
|
348 | 366 |
|
349 |
| - this.scope.$watch('rzSliderOptions', function(newValue, oldValue) { |
350 |
| - if (newValue === oldValue) |
351 |
| - return; |
352 |
| - self.applyOptions(); |
353 |
| - self.resetSlider(); |
354 |
| - }, true); |
355 |
| - |
356 | 367 | this.scope.$on('$destroy', function() {
|
357 | 368 | self.unbindEvents();
|
358 | 369 | angular.element($window).off('resize', calcDimFn);
|
|
1442 | 1453 | this.scope.rzSliderHigh = newMaxValue;
|
1443 | 1454 | this.updateHandles('rzSliderModel', newMinOffset);
|
1444 | 1455 | this.updateHandles('rzSliderHigh', newMaxOffset);
|
1445 |
| - this.scope.$apply(); |
1446 |
| - this.callOnChange(); |
| 1456 | + this.applyModel(); |
1447 | 1457 | },
|
1448 | 1458 |
|
1449 | 1459 | /**
|
|
1491 | 1501 | }
|
1492 | 1502 |
|
1493 | 1503 | if (valueChanged) {
|
1494 |
| - this.scope.$apply(); |
1495 |
| - this.callOnChange(); |
| 1504 | + this.applyModel(); |
1496 | 1505 | }
|
1497 | 1506 | return switched;
|
1498 | 1507 | },
|
|
1519 | 1528 | }
|
1520 | 1529 |
|
1521 | 1530 | return eventNames;
|
| 1531 | + }, |
| 1532 | + |
| 1533 | + /** |
| 1534 | + * Apply the model values using scope.$apply. |
| 1535 | + * We wrap it with the internalChange flag to avoid the watchers to be called |
| 1536 | + */ |
| 1537 | + applyModel: function() { |
| 1538 | + this.internalChange = true; |
| 1539 | + this.scope.$apply(); |
| 1540 | + this.callOnChange(); |
| 1541 | + this.internalChange = false; |
1522 | 1542 | }
|
1523 | 1543 | };
|
1524 | 1544 |
|
|
0 commit comments