Skip to content

Commit 4d2acb3

Browse files
author
Valentin Hervieu
committed
feat(callbacks): Pass the model and high values to the onStart, onChange and onEnd callbacks.
1 parent d0a5b76 commit 4d2acb3

File tree

7 files changed

+45
-20
lines changed

7 files changed

+45
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 2.5.0 (not-released)
22
## Features
33
- Add a `minRange` option to set a minimal range (#231).
4+
- Pass the slider values to the `onStart`, `onChange` and `onEnd` callbacks.
5+
- Rollback and improve the callback changes brought with 2.4.1 that were no applying the last update to the scope anymore.
46

57
# 2.4.1 (2016-01-15)
68
## Performance improvements

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ $scope.slider = {
252252

253253
**onlyBindHandles** - _Boolean (defaults to false)_: Set to true to only bind events on slider handles.
254254

255-
**onStart** - _Function(sliderId)_: Function to be called when a slider update is started. If an id was set in the options, then it's passed to this callback. This callback is called before any update on the model.
255+
**onStart** - _Function(sliderId, modelValue, highValue)_: Function to be called when a slider update is started. If an id was set in the options, then it's passed to this callback. This callback is called before any update on the model.
256256

257-
**onChange** - _Function(sliderId)_: Function to be called when rz-slider-model or rz-slider-high change. If an id was set in the options, then it's passed to this callback.
257+
**onChange** - _Function(sliderId, modelValue, highValue)_: Function to be called when rz-slider-model or rz-slider-high change. If an id was set in the options, then it's passed to this callback.
258258

259-
**onEnd** - _Function(sliderId)_: Function to be called when a slider update is ended. If an id was set in the options, then it's passed to this callback.
259+
**onEnd** - _Function(sliderId, modelValue, highValue)_: Function to be called when a slider update is ended. If an id was set in the options, then it's passed to this callback.
260260

261261
**vertical** - _Boolean (defaults to false)_: Set to true to display the slider vertically. The slider will take the full height of its parent.
262262
_Changing this value at runtime is not currently supported._

demo/demo.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
7777
$scope.slider_callbacks = {
7878
value: 100,
7979
options: {
80-
onStart: function() {
81-
$scope.otherData.start = $scope.slider_callbacks.value * 10;
80+
onStart: function(id, newValue) {
81+
console.info('start', id, newValue);
82+
$scope.otherData.start = newValue * 10;
8283
},
83-
onChange: function() {
84-
$scope.otherData.change = $scope.slider_callbacks.value * 10;
84+
onChange: function(id, newValue) {
85+
console.info('change', id, newValue);
86+
$scope.otherData.change = newValue * 10;
8587
},
86-
onEnd: function() {
87-
$scope.otherData.end = $scope.slider_callbacks.value * 10;
88+
onEnd: function(id, newValue) {
89+
console.info('end', id, newValue);
90+
$scope.otherData.end = newValue * 10;
8891
}
8992
}
9093
};

dist/rzslider.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.4.1 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-01-22 */
4+
2016-01-24 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -791,36 +791,45 @@
791791

792792
/**
793793
* Call the onStart callback if defined
794+
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
794795
*
795796
* @returns {undefined}
796797
*/
797798
callOnStart: function() {
798799
if (this.options.onStart) {
799-
this.options.onStart(this.options.id);
800+
var self = this;
801+
this.scope.$evalAsync(function () {
802+
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
803+
});
800804
}
801805
},
802806

803807
/**
804808
* Call the onChange callback if defined
809+
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
805810
*
806811
* @returns {undefined}
807812
*/
808813
callOnChange: function() {
809814
if (this.options.onChange) {
810-
this.options.onChange(this.options.id);
815+
var self = this;
816+
this.scope.$evalAsync(function () {
817+
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
818+
});
811819
}
812820
},
813821

814822
/**
815823
* Call the onEnd callback if defined
824+
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
816825
*
817826
* @returns {undefined}
818827
*/
819828
callOnEnd: function() {
820829
if (this.options.onEnd) {
821830
var self = this;
822-
$timeout(function() {
823-
self.options.onEnd(self.options.id);
831+
this.scope.$evalAsync(function () {
832+
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
824833
});
825834
}
826835
},

dist/rzslider.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rzslider.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,36 +795,45 @@
795795

796796
/**
797797
* Call the onStart callback if defined
798+
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
798799
*
799800
* @returns {undefined}
800801
*/
801802
callOnStart: function() {
802803
if (this.options.onStart) {
803-
this.options.onStart(this.options.id);
804+
var self = this;
805+
this.scope.$evalAsync(function () {
806+
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
807+
});
804808
}
805809
},
806810

807811
/**
808812
* Call the onChange callback if defined
813+
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
809814
*
810815
* @returns {undefined}
811816
*/
812817
callOnChange: function() {
813818
if (this.options.onChange) {
814-
this.options.onChange(this.options.id);
819+
var self = this;
820+
this.scope.$evalAsync(function () {
821+
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
822+
});
815823
}
816824
},
817825

818826
/**
819827
* Call the onEnd callback if defined
828+
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
820829
*
821830
* @returns {undefined}
822831
*/
823832
callOnEnd: function() {
824833
if (this.options.onEnd) {
825834
var self = this;
826-
$timeout(function() {
827-
self.options.onEnd(self.options.id);
835+
this.scope.$evalAsync(function () {
836+
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
828837
});
829838
}
830839
},

tests/spec/rz-slider-service-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ describe('rzslider - ', function() {
504504
createSlider(sliderConf);
505505

506506
slider.callOnStart();
507+
$timeout.flush();
507508
sliderConf.options.onStart.calledWith('test').should.be.true;
508509
});
509510

@@ -518,6 +519,7 @@ describe('rzslider - ', function() {
518519
createSlider(sliderConf);
519520

520521
slider.callOnChange();
522+
$timeout.flush();
521523
sliderConf.options.onChange.calledWith('test').should.be.true;
522524
});
523525

0 commit comments

Comments
 (0)