|
1 | 1 | // Ion.RangeSlider |
2 | | -// version 2.1.5 Build: 365 |
| 2 | +// version 2.1.6 Build: 369 |
3 | 3 | // © Denis Ineshin, 2016 |
4 | 4 | // https://github.com/IonDen |
5 | 5 | // |
|
156 | 156 | * @constructor |
157 | 157 | */ |
158 | 158 | var IonRangeSlider = function (input, options, plugin_count) { |
159 | | - this.VERSION = "2.1.5"; |
| 159 | + this.VERSION = "2.1.6"; |
160 | 160 | this.input = input; |
161 | 161 | this.plugin_count = plugin_count; |
162 | 162 | this.current_plugin = 0; |
|
331 | 331 | }; |
332 | 332 |
|
333 | 333 |
|
| 334 | + // check if base element is input |
| 335 | + if ($inp[0].nodeName !== "INPUT") { |
| 336 | + console && console.warn && console.warn("Base element should be <input>!", $inp[0]); |
| 337 | + } |
| 338 | + |
334 | 339 |
|
335 | 340 | // config from data-attributes extends js config |
336 | 341 | config_from_data = { |
|
395 | 400 | } |
396 | 401 |
|
397 | 402 |
|
398 | | - |
399 | 403 | // input value extends default config |
400 | | - if (val !== "") { |
| 404 | + if (val !== undefined && val !== "") { |
401 | 405 | val = val.split(config_from_data.input_values_separator || options.input_values_separator || ";"); |
402 | 406 |
|
403 | 407 | if (val[0] && val[0] == +val[0]) { |
|
1330 | 1334 | this.$cache.s_single[0].style.left = this.coords.p_single_fake + "%"; |
1331 | 1335 |
|
1332 | 1336 | this.$cache.single[0].style.left = this.labels.p_single_left + "%"; |
1333 | | - |
1334 | | - if (this.options.values.length) { |
1335 | | - this.$cache.input.prop("value", this.result.from_value); |
1336 | | - } else { |
1337 | | - this.$cache.input.prop("value", this.result.from); |
1338 | | - } |
1339 | | - this.$cache.input.data("from", this.result.from); |
1340 | 1337 | } else { |
1341 | 1338 | this.$cache.s_from[0].style.left = this.coords.p_from_fake + "%"; |
1342 | 1339 | this.$cache.s_to[0].style.left = this.coords.p_to_fake + "%"; |
|
1349 | 1346 | } |
1350 | 1347 |
|
1351 | 1348 | this.$cache.single[0].style.left = this.labels.p_single_left + "%"; |
1352 | | - |
1353 | | - if (this.options.values.length) { |
1354 | | - this.$cache.input.prop("value", this.result.from_value + this.options.input_values_separator + this.result.to_value); |
1355 | | - } else { |
1356 | | - this.$cache.input.prop("value", this.result.from + this.options.input_values_separator + this.result.to); |
1357 | | - } |
1358 | | - this.$cache.input.data("from", this.result.from); |
1359 | | - this.$cache.input.data("to", this.result.to); |
1360 | 1349 | } |
1361 | 1350 |
|
| 1351 | + this.writeToInput(); |
| 1352 | + |
1362 | 1353 | if ((this.old_from !== this.result.from || this.old_to !== this.result.to) && !this.is_start) { |
1363 | 1354 | this.$cache.input.trigger("change"); |
| 1355 | + this.$cache.input.trigger("input"); |
1364 | 1356 | } |
1365 | 1357 |
|
1366 | 1358 | this.old_from = this.result.from; |
|
1581 | 1573 |
|
1582 | 1574 |
|
1583 | 1575 |
|
| 1576 | + /** |
| 1577 | + * Write values to input element |
| 1578 | + */ |
| 1579 | + writeToInput: function () { |
| 1580 | + if (this.options.type === "single") { |
| 1581 | + if (this.options.values.length) { |
| 1582 | + this.$cache.input.prop("value", this.result.from_value); |
| 1583 | + } else { |
| 1584 | + this.$cache.input.prop("value", this.result.from); |
| 1585 | + } |
| 1586 | + this.$cache.input.data("from", this.result.from); |
| 1587 | + } else { |
| 1588 | + if (this.options.values.length) { |
| 1589 | + this.$cache.input.prop("value", this.result.from_value + this.options.input_values_separator + this.result.to_value); |
| 1590 | + } else { |
| 1591 | + this.$cache.input.prop("value", this.result.from + this.options.input_values_separator + this.result.to); |
| 1592 | + } |
| 1593 | + this.$cache.input.data("from", this.result.from); |
| 1594 | + this.$cache.input.data("to", this.result.to); |
| 1595 | + } |
| 1596 | + }, |
| 1597 | + |
| 1598 | + |
| 1599 | + |
1584 | 1600 | // ============================================================================================================= |
1585 | 1601 | // Callbacks |
1586 | 1602 |
|
1587 | 1603 | callOnStart: function () { |
| 1604 | + this.writeToInput(); |
| 1605 | + |
1588 | 1606 | if (this.options.onStart && typeof this.options.onStart === "function") { |
1589 | 1607 | this.options.onStart(this.result); |
1590 | 1608 | } |
1591 | 1609 | }, |
1592 | 1610 | callOnChange: function () { |
| 1611 | + this.writeToInput(); |
| 1612 | + |
1593 | 1613 | if (this.options.onChange && typeof this.options.onChange === "function") { |
1594 | 1614 | this.options.onChange(this.result); |
1595 | 1615 | } |
1596 | 1616 | }, |
1597 | 1617 | callOnFinish: function () { |
| 1618 | + this.writeToInput(); |
| 1619 | + |
1598 | 1620 | if (this.options.onFinish && typeof this.options.onFinish === "function") { |
1599 | 1621 | this.options.onFinish(this.result); |
1600 | 1622 | } |
1601 | 1623 | }, |
1602 | 1624 | callOnUpdate: function () { |
| 1625 | + this.writeToInput(); |
| 1626 | + |
1603 | 1627 | if (this.options.onUpdate && typeof this.options.onUpdate === "function") { |
1604 | 1628 | this.options.onUpdate(this.result); |
1605 | 1629 | } |
1606 | 1630 | }, |
1607 | 1631 |
|
1608 | 1632 |
|
1609 | 1633 |
|
| 1634 | + |
1610 | 1635 | // ============================================================================================================= |
1611 | 1636 | // Service methods |
1612 | 1637 |
|
|
0 commit comments