Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added alt_min and and alt_max #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions js/ion.rangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@
values_separator: " — ",

input_values_separator: ";",
alt_max: false,
alt_min: false,

disable: false,

Expand Down Expand Up @@ -368,6 +370,8 @@
values_separator: $inp.data("valuesSeparator"),

input_values_separator: $inp.data("inputValuesSeparator"),
alt_max: $inp.data("altMax"),
alt_min: $inp.data("altMin"),

disable: $inp.data("disable")
};
Expand All @@ -387,6 +391,16 @@
if (val) {
val = val.split(config_from_data.input_values_separator || options.input_values_separator || ";");

var alt_min = config_from_data.alt_min || options.alt_min || false;
if (alt_min && val[0] && val[0] == alt_min) {
val[0] = config_from_data.min || options.min || config.min;
}

var alt_max = config_from_data.alt_max || options.alt_max || false;
if (alt_max && val[1] && val[1] == alt_max) {
val[1] = config_from_data.max || options.max || config.max;
}

if (val[0] && val[0] == +val[0]) {
val[0] = +val[0];
}
Expand Down Expand Up @@ -1313,9 +1327,9 @@
this.$cache.single[0].style.left = this.labels.p_single_left + "%";

if (this.options.values.length) {
this.$cache.input.prop("value", this.result.from_value);
this.updateInputValue(this.result.from_value);
} else {
this.$cache.input.prop("value", this.result.from);
this.updateInputValue(this.result.from);
}
this.$cache.input.data("from", this.result.from);
} else {
Expand All @@ -1332,9 +1346,9 @@
this.$cache.single[0].style.left = this.labels.p_single_left + "%";

if (this.options.values.length) {
this.$cache.input.prop("value", this.result.from_value + this.options.input_values_separator + this.result.to_value);
this.updateInputValue(this.result.from_value, this.result.to_value);
} else {
this.$cache.input.prop("value", this.result.from + this.options.input_values_separator + this.result.to);
this.updateInputValue(this.result.from, this.result.to);
}
this.$cache.input.data("from", this.result.from);
this.$cache.input.data("to", this.result.to);
Expand Down Expand Up @@ -1368,6 +1382,30 @@
this.force_redraw = false;
},

/**
* Updates the value from the underlying text input.
*
* @param from {Number}
* @param to {Number}
*/
updateInputValue: function(from, to) {
if (this.options.alt_min && from === this.options.min) {
from = this.options.alt_min;
}

var value = from;

if (typeof to !== "undefined") {
if (this.options.alt_max && to === this.options.max) {
to = this.options.alt_max;
}

value += this.options.input_values_separator + to;
}

this.$cache.input.prop("value", value);
},

/**
* Draw labels
* measure labels collisions
Expand Down