updateRange was insufficient, added an updateScale
samcov opened this issue · comments
In the demo, if you update the range => $('.range-slider').jRange('updateRange', '0,200');
Then you can call updateScale => $('.range-slider').jRange('updateScale',[0,50,100,150,200]);
Code in jquery.range.js shown below.
updateScale: function(scale, from, to) {
var s = scale || [from, to];
var prc = Math.round((100 / (s.length - 1)) * 10) / 10;
var str = '';
for (var i = 0; i < s.length; i++) {
str += '' + (s[i] != '|' ? '' + s[i] + '' : '') + '';
}
this.scale.html(str);
$('ins', this.scale).each(function() {
$(this).css({
marginLeft: -$(this).outerWidth() / 2
});
});
},
thanks for the update, @samcov could you please send a Pull Request for the same
Hello, I found it only today when I used it. The value was updated but the style was not modified. I tried to modify the style.It is hoped that the users will have this need in the future.
Code in jquery.range.js shown below.
updateRender: function(data) {
return 0 !== this.inputNode.width() || this.options.width ? (this.options.width = this.options.width || this.inputNode.width(), this.domNode.width(this.options.width), this.inputNode.hide(), this.isSingle() && (this.lowPointer.hide(), this.lowLabel.hide()), this.options.showLabels || this.labels.hide(), this.attachEvents(), this.options.showScale && this.updateScale(data), void this.setValue(this.options.value)) : void console.log("jRange : no width found, returning")
},
updateScale: function(scale, from, to) {
for(var t = scale || [from, to], i = Math.round(100 / (t.length - 1) * 10) / 10, s = "", o = 0; o < t.length; o++) s += '<span style="left: ' + o * i + '%">' + ("|" != t[o] ? "<ins>" + t[o] + "</ins>" : "") + "</span>";
this.scale.html(s), $("ins", this.scale).each(function() {
$(this).css({
marginLeft: -$(this).outerWidth() / 2
})
})
},
In the demo, if you update the range => $('.range-slider').jRange('updateRange', '0,10');
Then you can call updateScale => $('.range-slider').jRange('updateRender',[0,1,2,3,4,5,6,7,8,9,10]);