Skip to content

Commit 04f3050

Browse files
committed
feat(onStart, onChange, onEnd): Add a pointerType arg for the callbacks to identify which handle is
Closes #339
1 parent 5385e18 commit 04f3050

File tree

6 files changed

+52
-26
lines changed

6 files changed

+52
-26
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ Just pass an array with each slider value and that's it; the floor, ceil and ste
328328

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

331-
**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.
331+
**onStart** - _Function(sliderId, modelValue, highValue, pointerType)_: 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. `pointerType` is either 'min' or 'max' depending on which handle is used.
332332

333-
**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.
333+
**onChange** - _Function(sliderId, modelValue, highValue, pointerType)_: 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. `pointerType` is either 'min' or 'max' depending on which handle is used.
334334

335-
**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.
335+
**onEnd** - _Function(sliderId, modelValue, highValue, pointerType)_: 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. `pointerType` is either 'min' or 'max' depending on which handle is used.
336336

337337
**rightToLeft** - _Boolean (defaults to false)_: Set to true to show graphs right to left. If **vertical** is true it will be from top to bottom and left / right arrow functions reversed.
338338

demo/demo.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,27 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
134134
step: 5,
135135
rightToLeft: true
136136
}
137-
}
137+
};
138138

139139
//Slider config with callbacks
140140
$scope.slider_callbacks = {
141141
value: 100,
142142
options: {
143-
onStart: function(id, newValue) {
144-
console.info('start', id, newValue);
143+
onStart: function(id, newValue, highValue, pointerType) {
144+
console.info('start', id, newValue, pointerType);
145145
$scope.otherData.start = newValue * 10;
146146
},
147-
onChange: function(id, newValue) {
148-
console.info('change', id, newValue);
147+
onChange: function(id, newValue, highValue, pointerType) {
148+
console.info('change', id, newValue, pointerType);
149149
$scope.otherData.change = newValue * 10;
150150
},
151-
onEnd: function(id, newValue) {
152-
console.info('end', id, newValue);
151+
onEnd: function(id, newValue, highValue, pointerType) {
152+
console.info('end', id, newValue, pointerType);
153153
$scope.otherData.end = newValue * 10;
154154
}
155155
}
156156
};
157+
157158
$scope.otherData = {
158159
start: 0,
159160
change: 0,

dist/rzslider.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1974,9 +1974,10 @@
19741974
*/
19751975
callOnStart: function() {
19761976
if (this.options.onStart) {
1977-
var self = this;
1977+
var self = this,
1978+
pointerType = this.tracking === 'lowValue' ? 'min' : 'max';
19781979
this.scope.$evalAsync(function() {
1979-
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
1980+
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh, pointerType);
19801981
});
19811982
}
19821983
},
@@ -1989,9 +1990,10 @@
19891990
*/
19901991
callOnChange: function() {
19911992
if (this.options.onChange) {
1992-
var self = this;
1993+
var self = this,
1994+
pointerType = this.tracking === 'lowValue' ? 'min' : 'max';
19931995
this.scope.$evalAsync(function() {
1994-
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
1996+
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh, pointerType);
19951997
});
19961998
}
19971999
},
@@ -2004,9 +2006,10 @@
20042006
*/
20052007
callOnEnd: function() {
20062008
if (this.options.onEnd) {
2007-
var self = this;
2009+
var self = this,
2010+
pointerType = this.tracking === 'lowValue' ? 'min' : 'max';
20082011
this.scope.$evalAsync(function() {
2009-
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
2012+
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh, pointerType);
20102013
});
20112014
}
20122015
this.scope.$emit('slideEnded');

dist/rzslider.min.js

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

src/rzslider.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1978,9 +1978,10 @@
19781978
*/
19791979
callOnStart: function() {
19801980
if (this.options.onStart) {
1981-
var self = this;
1981+
var self = this,
1982+
pointerType = this.tracking === 'lowValue' ? 'min' : 'max';
19821983
this.scope.$evalAsync(function() {
1983-
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
1984+
self.options.onStart(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh, pointerType);
19841985
});
19851986
}
19861987
},
@@ -1993,9 +1994,10 @@
19931994
*/
19941995
callOnChange: function() {
19951996
if (this.options.onChange) {
1996-
var self = this;
1997+
var self = this,
1998+
pointerType = this.tracking === 'lowValue' ? 'min' : 'max';
19971999
this.scope.$evalAsync(function() {
1998-
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
2000+
self.options.onChange(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh, pointerType);
19992001
});
20002002
}
20012003
},
@@ -2008,9 +2010,10 @@
20082010
*/
20092011
callOnEnd: function() {
20102012
if (this.options.onEnd) {
2011-
var self = this;
2013+
var self = this,
2014+
pointerType = this.tracking === 'lowValue' ? 'min' : 'max';
20122015
this.scope.$evalAsync(function() {
2013-
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh);
2016+
self.options.onEnd(self.options.id, self.scope.rzSliderModel, self.scope.rzSliderHigh, pointerType);
20142017
});
20152018
}
20162019
this.scope.$emit('slideEnded');

tests/specs/options-handling-test.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,26 @@
401401
};
402402
helper.createSlider(sliderConf);
403403

404+
helper.slider.tracking = 'lowValue';
404405
helper.slider.callOnStart();
405406
$timeout.flush();
406-
sliderConf.options.onStart.calledWith('test').should.be.true;
407+
sliderConf.options.onStart.calledWith('test', 10, undefined, 'min').should.be.true;
408+
});
409+
410+
it('should call the correct callback for onStart called on high handle', function() {
411+
var sliderConf = {
412+
value: 10,
413+
options: {
414+
id: 'test',
415+
onStart: sinon.spy()
416+
}
417+
};
418+
helper.createSlider(sliderConf);
419+
420+
helper.slider.tracking = 'highValue';
421+
helper.slider.callOnStart();
422+
$timeout.flush();
423+
sliderConf.options.onStart.calledWith('test', 10, undefined, 'max').should.be.true;
407424
});
408425

409426
it('should call the correct callback for onChange', function() {
@@ -416,9 +433,10 @@
416433
};
417434
helper.createSlider(sliderConf);
418435

436+
helper.slider.tracking = 'lowValue';
419437
helper.slider.callOnChange();
420438
$timeout.flush();
421-
sliderConf.options.onChange.calledWith('test').should.be.true;
439+
sliderConf.options.onChange.calledWith('test', 10, undefined, 'min').should.be.true;
422440
});
423441

424442
it('should call the correct callback for onEnd', function() {
@@ -431,9 +449,10 @@
431449
};
432450
helper.createSlider(sliderConf);
433451

452+
helper.slider.tracking = 'lowValue';
434453
helper.slider.callOnEnd();
435454
$timeout.flush();
436-
sliderConf.options.onEnd.calledWith('test').should.be.true;
455+
sliderConf.options.onEnd.calledWith('test', 10, undefined, 'min').should.be.true;
437456
});
438457

439458
it('should set the correct background-color on pointer for single slider', function() {

0 commit comments

Comments
 (0)