Skip to content

Commit

Permalink
feat(slider): support control over change trigger
Browse files Browse the repository at this point in the history
This PR adds a new option to the set value or set rangeValue behavior to optionally avoid the onChange callback

The change is backward compatible, because when the new parameter is omitted, it behaves like before (triggering the callback)

.slider('set value',10,false)
  • Loading branch information
lubber-de committed Nov 6, 2020
1 parent 4bea8ab commit ce85cf3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/definitions/modules/slider.js
Expand Up @@ -861,11 +861,12 @@ $.fn.slider = function(parameters) {
},

set: {
value: function(newValue) {
value: function(newValue, fireChange) {
fireChange = fireChange !== false;
var toReset = previousValue === undefined;
previousValue = previousValue === undefined ? module.get.value() : previousValue;
module.update.value(newValue, function(value, thumbVal, secondThumbVal) {
if (!initialLoad || settings.fireOnInit){
if ((!initialLoad || settings.fireOnInit) && fireChange){
if (newValue !== previousValue) {
settings.onChange.call(element, value, thumbVal, secondThumbVal);
}
Expand All @@ -876,7 +877,8 @@ $.fn.slider = function(parameters) {
}
});
},
rangeValue: function(first, second) {
rangeValue: function(first, second, fireChange) {
fireChange = fireChange !== false;
if(module.is.range()) {
var
min = module.get.min(),
Expand All @@ -899,7 +901,7 @@ $.fn.slider = function(parameters) {
value = Math.abs(module.thumbVal - module.secondThumbVal);
module.update.position(module.thumbVal, $thumb);
module.update.position(module.secondThumbVal, $secondThumb);
if (!initialLoad || settings.fireOnInit) {
if ((!initialLoad || settings.fireOnInit) && fireChange) {
if (value !== previousValue) {
settings.onChange.call(element, value, module.thumbVal, module.secondThumbVal);
}
Expand Down

0 comments on commit ce85cf3

Please sign in to comment.