Skip to content

Commit 9d6c2fa

Browse files
author
Valentin Hervieu
committed
Implement a on-start and on-end callback as requested in #121 and #86.
1 parent 61ca53c commit 9d6c2fa

File tree

7 files changed

+59
-9
lines changed

7 files changed

+59
-9
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,18 @@ $scope.priceSlider = {
114114

115115
> Custom translate function. Use this if you want to translate values displayed on the slider. For example if you want to display dollar amounts instead of just numbers do this:
116116
117+
**rz-slider-on-start**
118+
119+
> Function to be called when a slider update is started.
120+
117121
**rz-slider-on-change**
118122

119123
> Function to be called when rz-slider-model or rz-slider-high change.
120124
125+
**rz-slider-on-end**
126+
127+
> Function to be called when a slider update is ended.
128+
121129
```javascript
122130
// In your controller
123131

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularjs-slider",
3-
"version": "0.1.28",
3+
"version": "0.1.29",
44
"homepage": "https://github.com/rzajac/angularjs-slider",
55
"authors": [
66
"Rafal Zajac <[email protected]>",

demo/index.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ <h2>Min/max slider example</h2>
2929
rz-slider-step="0.3"
3030
rz-slider-precision="1"
3131
rz-slider-model="slider_data.value"
32-
rz-slider-on-change="onChange()"></rzslider>
32+
rz-slider-on-start="onStart()"
33+
rz-slider-on-change="onChange()"
34+
rz-slider-on-end="onEnd()"></rzslider>
3335
</article>
3436

3537
<article>
@@ -142,11 +144,19 @@ <h2>Toggle slider example</h2>
142144
$scope.slider_data = {value: 1};
143145
$scope.otherData = {value: 10};
144146

147+
$scope.onStart = function() {
148+
console.info('started', $scope.slider_data.value);
149+
};
150+
145151
$scope.onChange = function() {
146152
console.info('changed', $scope.slider_data.value);
147153
$scope.otherData.value = $scope.slider_data.value * 10;
148154
};
149155

156+
$scope.onEnd = function() {
157+
console.info('ended', $scope.slider_data.value);
158+
};
159+
150160
$scope.visible = false;
151161

152162
$scope.toggle = function() {
@@ -157,7 +167,7 @@ <h2>Toggle slider example</h2>
157167
};
158168

159169
$scope.toggleSlider = {
160-
value: 0,
170+
value: 1,
161171
ceil: 500,
162172
floor: 0
163173
};

dist/rzslider.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.

package.json

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

rzslider.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (c) Rafal Zajac <[email protected]>
55
* http://github.com/rzajac/angularjs-slider
66
*
7-
* Version: v0.1.28
7+
* Version: v0.1.29
88
*
99
* Licensed under the MIT license
1010
*/
@@ -589,6 +589,20 @@ function throttle(func, wait, options) {
589589
this.getWidth(this.flrLab);
590590
},
591591

592+
/**
593+
* Call the onStart callback if defined
594+
*
595+
* @returns {undefined}
596+
*/
597+
callOnStart: function() {
598+
if(this.scope.rzSliderOnStart) {
599+
var self = this;
600+
$timeout(function() {
601+
self.scope.rzSliderOnStart();
602+
});
603+
}
604+
},
605+
592606
/**
593607
* Call the onChange callback if defined
594608
*
@@ -603,6 +617,20 @@ function throttle(func, wait, options) {
603617
}
604618
},
605619

620+
/**
621+
* Call the onEnd callback if defined
622+
*
623+
* @returns {undefined}
624+
*/
625+
callOnEnd: function() {
626+
if(this.scope.rzSliderOnEnd) {
627+
var self = this;
628+
$timeout(function() {
629+
self.scope.rzSliderOnEnd();
630+
});
631+
}
632+
},
633+
606634
/**
607635
* Update slider handles and label positions
608636
*
@@ -991,6 +1019,7 @@ function throttle(func, wait, options) {
9911019

9921020
$document.on(eventNames.moveEvent, ehMove);
9931021
$document.one(eventNames.endEvent, ehEnd);
1022+
this.callOnStart();
9941023
},
9951024

9961025
/**
@@ -1182,6 +1211,7 @@ function throttle(func, wait, options) {
11821211
this.tracking = '';
11831212

11841213
this.dragging.active = false;
1214+
this.callOnEnd();
11851215
},
11861216

11871217
/**
@@ -1231,7 +1261,9 @@ function throttle(func, wait, options) {
12311261
rzSliderHideLimitLabels: '=?',
12321262
rzSliderAlwaysShowBar: '=?',
12331263
rzSliderPresentOnly: '@',
1234-
rzSliderOnChange: '&'
1264+
rzSliderOnStart: '&',
1265+
rzSliderOnChange: '&',
1266+
rzSliderOnEnd: '&'
12351267
},
12361268

12371269
/**

0 commit comments

Comments
 (0)