Commit 4d2acb38 authored by Valentin Hervieu's avatar Valentin Hervieu

feat(callbacks): Pass the model and high values to the onStart, onChange and onEnd callbacks.

parent d0a5b769
# 2.5.0 (not-released) # 2.5.0 (not-released)
## Features ## Features
- Add a `minRange` option to set a minimal range (#231). - Add a `minRange` option to set a minimal range (#231).
- Pass the slider values to the `onStart`, `onChange` and `onEnd` callbacks.
- Rollback and improve the callback changes brought with 2.4.1 that were no applying the last update to the scope anymore.
# 2.4.1 (2016-01-15) # 2.4.1 (2016-01-15)
## Performance improvements ## Performance improvements
......
...@@ -252,11 +252,11 @@ $scope.slider = { ...@@ -252,11 +252,11 @@ $scope.slider = {
**onlyBindHandles** - _Boolean (defaults to false)_: Set to true to only bind events on slider handles. **onlyBindHandles** - _Boolean (defaults to false)_: Set to true to only bind events on slider handles.
**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. **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.
**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. **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.
**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. **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.
**vertical** - _Boolean (defaults to false)_: Set to true to display the slider vertically. The slider will take the full height of its parent. **vertical** - _Boolean (defaults to false)_: Set to true to display the slider vertically. The slider will take the full height of its parent.
_Changing this value at runtime is not currently supported._ _Changing this value at runtime is not currently supported._
......
...@@ -77,14 +77,17 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { ...@@ -77,14 +77,17 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
$scope.slider_callbacks = { $scope.slider_callbacks = {
value: 100, value: 100,
options: { options: {
onStart: function() { onStart: function(id, newValue) {
$scope.otherData.start = $scope.slider_callbacks.value * 10; console.info('start', id, newValue);
$scope.otherData.start = newValue * 10;
}, },
onChange: function() { onChange: function(id, newValue) {
$scope.otherData.change = $scope.slider_callbacks.value * 10; console.info('change', id, newValue);
$scope.otherData.change = newValue * 10;
}, },
onEnd: function() { onEnd: function(id, newValue) {
$scope.otherData.end = $scope.slider_callbacks.value * 10; console.info('end', id, newValue);
$scope.otherData.end = newValue * 10;
} }
} }
}; };
......
/*! angularjs-slider - v2.4.1 - /*! angularjs-slider - v2.4.1 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> - (c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
https://github.com/angular-slider/angularjs-slider - https://github.com/angular-slider/angularjs-slider -
2016-01-22 */ 2016-01-24 */
/*jslint unparam: true */ /*jslint unparam: true */
/*global angular: false, console: false, define, module */ /*global angular: false, console: false, define, module */
(function(root, factory) { (function(root, factory) {
...@@ -791,36 +791,45 @@ ...@@ -791,36 +791,45 @@
/** /**
* Call the onStart callback if defined * Call the onStart callback if defined
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
* *
* @returns {undefined} * @returns {undefined}
*/ */
callOnStart: function() { callOnStart: function() {
if (this.options.onStart) { if (this.options.onStart) {
this.options.onStart(this.options.id); var self = this;
this.scope.$evalAsync(function () {
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
});
} }
}, },
/** /**
* Call the onChange callback if defined * Call the onChange callback if defined
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
* *
* @returns {undefined} * @returns {undefined}
*/ */
callOnChange: function() { callOnChange: function() {
if (this.options.onChange) { if (this.options.onChange) {
this.options.onChange(this.options.id); var self = this;
this.scope.$evalAsync(function () {
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
});
} }
}, },
/** /**
* Call the onEnd callback if defined * Call the onEnd callback if defined
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
* *
* @returns {undefined} * @returns {undefined}
*/ */
callOnEnd: function() { callOnEnd: function() {
if (this.options.onEnd) { if (this.options.onEnd) {
var self = this; var self = this;
$timeout(function() { this.scope.$evalAsync(function () {
self.options.onEnd(self.options.id); self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
}); });
} }
}, },
......
This diff is collapsed.
...@@ -795,36 +795,45 @@ ...@@ -795,36 +795,45 @@
/** /**
* Call the onStart callback if defined * Call the onStart callback if defined
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
* *
* @returns {undefined} * @returns {undefined}
*/ */
callOnStart: function() { callOnStart: function() {
if (this.options.onStart) { if (this.options.onStart) {
this.options.onStart(this.options.id); var self = this;
this.scope.$evalAsync(function () {
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
});
} }
}, },
/** /**
* Call the onChange callback if defined * Call the onChange callback if defined
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
* *
* @returns {undefined} * @returns {undefined}
*/ */
callOnChange: function() { callOnChange: function() {
if (this.options.onChange) { if (this.options.onChange) {
this.options.onChange(this.options.id); var self = this;
this.scope.$evalAsync(function () {
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
});
} }
}, },
/** /**
* Call the onEnd callback if defined * Call the onEnd callback if defined
* The callback call is wrapped in a $evalAsync to ensure that its result will be applied to the scope.
* *
* @returns {undefined} * @returns {undefined}
*/ */
callOnEnd: function() { callOnEnd: function() {
if (this.options.onEnd) { if (this.options.onEnd) {
var self = this; var self = this;
$timeout(function() { this.scope.$evalAsync(function () {
self.options.onEnd(self.options.id); self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
}); });
} }
}, },
......
...@@ -504,6 +504,7 @@ describe('rzslider - ', function() { ...@@ -504,6 +504,7 @@ describe('rzslider - ', function() {
createSlider(sliderConf); createSlider(sliderConf);
slider.callOnStart(); slider.callOnStart();
$timeout.flush();
sliderConf.options.onStart.calledWith('test').should.be.true; sliderConf.options.onStart.calledWith('test').should.be.true;
}); });
...@@ -518,6 +519,7 @@ describe('rzslider - ', function() { ...@@ -518,6 +519,7 @@ describe('rzslider - ', function() {
createSlider(sliderConf); createSlider(sliderConf);
slider.callOnChange(); slider.callOnChange();
$timeout.flush();
sliderConf.options.onChange.calledWith('test').should.be.true; sliderConf.options.onChange.calledWith('test').should.be.true;
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment