Skip to content

Commit 05cbdc8

Browse files
author
Valentin Hervieu
committed
Fixes #106 (rz-slider-on-change fires before value is changed)
1 parent 84189f1 commit 05cbdc8

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-slider",
3-
"version": "0.1.25",
3+
"version": "0.1.27",
44
"homepage": "https://github.com/rzajac/angularjs-slider",
55
"authors": [
66
"Rafal Zajac <rzajac@gmail.com>",

demo/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h1>AngularJS Touch Slider</h1>
2020
<article>
2121
<h2>Min/max slider example</h2>
2222
Value: <pre>{{ slider_data | json }}</pre>
23+
<p>Value linked on change: {{ otherData.value }}</p>
2324

2425
<rzslider
2526
rz-slider-floor="0.5"
@@ -131,9 +132,11 @@ <h2>Draggable range example</h2>
131132
};
132133

133134
$scope.slider_data = {value: 1};
135+
$scope.otherData = {value: 10};
134136

135137
$scope.onChange = function() {
136138
console.info('changed', $scope.slider_data.value);
139+
$scope.otherData.value = $scope.slider_data.value * 10;
137140
};
138141
});
139142
</script>

dist/rzslider.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jusas-angularjs-slider",
3-
"version": "0.1.25",
3+
"version": "0.1.27",
44
"description": "AngularJS slider directive with no external dependencies. Mobile friendly!.",
55
"main": "rzslider.js",
66
"repository": {

rzslider.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (c) Rafal Zajac <rzajac@gmail.com>
55
* http://github.com/rzajac/angularjs-slider
66
*
7-
* Version: v0.1.21
7+
* Version: v0.1.27
88
*
99
* Licensed under the MIT license
1010
*/
@@ -596,7 +596,10 @@ function throttle(func, wait, options) {
596596
*/
597597
callOnChange: function() {
598598
if(this.scope.rzSliderOnChange) {
599-
this.scope.rzSliderOnChange();
599+
var self = this;
600+
$timeout(function() {
601+
self.scope.rzSliderOnChange();
602+
});
600603
}
601604
},
602605

@@ -608,7 +611,6 @@ function throttle(func, wait, options) {
608611
*/
609612
updateHandles: function(which, newOffset)
610613
{
611-
this.callOnChange();
612614
if(which === 'rzSliderModel')
613615
{
614616
this.updateLowHandle(newOffset);
@@ -1113,6 +1115,7 @@ function throttle(func, wait, options) {
11131115
this.updateHandles('rzSliderModel', newMinOffset);
11141116
this.updateHandles('rzSliderHigh', newMaxOffset);
11151117
this.scope.$apply();
1118+
this.callOnChange();
11161119
},
11171120

11181121
/**
@@ -1135,6 +1138,7 @@ function throttle(func, wait, options) {
11351138
this.maxH.addClass('rz-active');
11361139
/* We need to apply here because we are not sure that we will enter the next block */
11371140
this.scope.$apply();
1141+
this.callOnChange();
11381142
}
11391143
else if(this.tracking === 'rzSliderHigh' && newValue <= this.scope.rzSliderModel)
11401144
{
@@ -1145,6 +1149,7 @@ function throttle(func, wait, options) {
11451149
this.minH.addClass('rz-active');
11461150
/* We need to apply here because we are not sure that we will enter the next block */
11471151
this.scope.$apply();
1152+
this.callOnChange();
11481153
}
11491154
}
11501155

@@ -1153,6 +1158,7 @@ function throttle(func, wait, options) {
11531158
this.scope[this.tracking] = newValue;
11541159
this.updateHandles(this.tracking, newOffset);
11551160
this.scope.$apply();
1161+
this.callOnChange();
11561162
}
11571163
},
11581164

0 commit comments

Comments
 (0)