|
1 | 1 | // Ion.RangeSlider
|
2 |
| -// version 2.0.6 Build: 300 |
| 2 | +// version 2.0.10 Build: 323 |
3 | 3 | // © Denis Ineshin, 2015
|
4 | 4 | // https://github.com/IonDen
|
5 | 5 | //
|
|
18 | 18 |
|
19 | 19 | var plugin_count = 0;
|
20 | 20 |
|
| 21 | + // IE8 fix |
21 | 22 | var is_old_ie = (function () {
|
22 | 23 | var n = navigator.userAgent,
|
23 | 24 | r = /msie\s\d+/i,
|
|
32 | 33 | }
|
33 | 34 | return false;
|
34 | 35 | } ());
|
35 |
| - |
36 |
| - // IE8 fix |
37 | 36 | if (!Function.prototype.bind) {
|
38 | 37 | Function.prototype.bind = function bind(that) {
|
39 | 38 |
|
|
139 | 138 | // Core
|
140 | 139 |
|
141 | 140 | var IonRangeSlider = function (input, options, plugin_count) {
|
142 |
| - this.VERSION = "2.0.6"; |
| 141 | + this.VERSION = "2.0.10"; |
143 | 142 | this.input = input;
|
144 | 143 | this.plugin_count = plugin_count;
|
145 | 144 | this.current_plugin = 0;
|
146 | 145 | this.calc_count = 0;
|
| 146 | + this.update_tm = 0; |
147 | 147 | this.old_from = 0;
|
148 | 148 | this.old_to = 0;
|
149 | 149 | this.raf_id = null;
|
|
231 | 231 | disable: $inp.data("disable")
|
232 | 232 | };
|
233 | 233 | data.values = data.values && data.values.split(",");
|
234 |
| - options = $.extend(data, options); |
235 | 234 |
|
236 | 235 | // get from and to out of input
|
237 | 236 | var val = $inp.prop("value");
|
|
245 | 244 | val[1] = +val[1];
|
246 | 245 | }
|
247 | 246 |
|
248 |
| - if (options.values && options.values.length) { |
| 247 | + if (options && options.values && options.values.length) { |
249 | 248 | data.from = val[0] && options.values.indexOf(val[0]);
|
250 | 249 | data.to = val[1] && options.values.indexOf(val[1]);
|
251 | 250 | } else {
|
|
254 | 253 | }
|
255 | 254 | }
|
256 | 255 |
|
| 256 | + // JS config has a priority |
| 257 | + options = $.extend(data, options); |
| 258 | + |
257 | 259 | // get config from options
|
258 | 260 | this.options = $.extend({
|
259 | 261 | type: "single",
|
|
413 | 415 | }
|
414 | 416 |
|
415 | 417 | this.updateScene();
|
416 |
| - this.raf_id = requestAnimationFrame(this.updateScene.bind(this)); |
417 | 418 | },
|
418 | 419 |
|
419 | 420 | append: function () {
|
|
446 | 447 | this.$cache.s_to = this.$cache.cont.find(".to");
|
447 | 448 | this.$cache.shad_from = this.$cache.cont.find(".shadow-from");
|
448 | 449 | this.$cache.shad_to = this.$cache.cont.find(".shadow-to");
|
| 450 | + |
| 451 | + this.setTopHandler(); |
449 | 452 | }
|
450 | 453 |
|
451 | 454 | if (this.options.hide_from_to) {
|
|
466 | 469 | }
|
467 | 470 | },
|
468 | 471 |
|
| 472 | + setTopHandler: function () { |
| 473 | + var min = this.options.min, |
| 474 | + max = this.options.max, |
| 475 | + from = this.options.from, |
| 476 | + to = this.options.to; |
| 477 | + |
| 478 | + if (from > min && to === max) { |
| 479 | + this.$cache.s_from.addClass("type_last"); |
| 480 | + } else if (to < max) { |
| 481 | + this.$cache.s_to.addClass("type_last"); |
| 482 | + } |
| 483 | + }, |
| 484 | + |
469 | 485 | appendDisableMask: function () {
|
470 | 486 | this.$cache.cont.append(disable_html);
|
471 | 487 | this.$cache.cont.addClass("irs-disabled");
|
|
580 | 596 | if (is_old_ie) {
|
581 | 597 | $("*").prop("unselectable", false);
|
582 | 598 | }
|
| 599 | + |
| 600 | + this.updateScene(); |
583 | 601 | },
|
584 | 602 |
|
585 | 603 | pointerDown: function (target, e) {
|
|
630 | 648 | }
|
631 | 649 |
|
632 | 650 | this.$cache.line.trigger("focus");
|
| 651 | + |
| 652 | + this.updateScene(); |
633 | 653 | },
|
634 | 654 |
|
635 | 655 | pointerClick: function (target, e) {
|
|
679 | 699 | return true;
|
680 | 700 | },
|
681 | 701 |
|
682 |
| - // Move by key beta |
| 702 | + // Move by key. Beta |
683 | 703 | // TODO: refactor than have plenty of time
|
684 | 704 | moveByKey: function (right) {
|
685 | 705 | var p = this.coords.p_pointer;
|
|
827 | 847 | break;
|
828 | 848 |
|
829 | 849 | case "both":
|
| 850 | + if (this.options.from_fixed || this.options.to_fixed) { |
| 851 | + break; |
| 852 | + } |
| 853 | + |
830 | 854 | real_x = this.toFixed(real_x + (this.coords.p_handle * 0.1));
|
831 | 855 |
|
832 | 856 | this.coords.p_from_real = this.calcWithStep((real_x - this.coords.p_gap_left) / real_width * 100);
|
|
890 | 914 | } else {
|
891 | 915 | var m_point = this.coords.p_from_real + ((this.coords.p_to_real - this.coords.p_from_real) / 2);
|
892 | 916 | if (real_x >= m_point) {
|
893 |
| - return "to"; |
| 917 | + return this.options.to_fixed ? "from" : "to"; |
894 | 918 | } else {
|
895 |
| - return "from"; |
| 919 | + return this.options.from_fixed ? "to" : "from"; |
896 | 920 | }
|
897 | 921 | }
|
898 | 922 | },
|
|
947 | 971 | // Drawings
|
948 | 972 |
|
949 | 973 | updateScene: function () {
|
| 974 | + if (this.raf_id) { |
| 975 | + cancelAnimationFrame(this.raf_id); |
| 976 | + this.raf_id = null; |
| 977 | + } |
| 978 | + |
| 979 | + clearTimeout(this.update_tm); |
| 980 | + this.update_tm = null; |
| 981 | + |
950 | 982 | if (!this.options) {
|
951 | 983 | return;
|
952 | 984 | }
|
953 | 985 |
|
954 | 986 | this.drawHandles();
|
955 | 987 |
|
956 |
| - this.raf_id = requestAnimationFrame(this.updateScene.bind(this)); |
| 988 | + if (this.is_active) { |
| 989 | + this.raf_id = requestAnimationFrame(this.updateScene.bind(this)); |
| 990 | + } else { |
| 991 | + this.update_tm = setTimeout(this.updateScene.bind(this), 300); |
| 992 | + } |
957 | 993 | },
|
958 | 994 |
|
959 | 995 | drawHandles: function () {
|
|
1119 | 1155 | } else {
|
1120 | 1156 |
|
1121 | 1157 | if (this.options.decorate_both) {
|
1122 |
| - text_single = this.decorate(this._prettify(this.result.from)); |
| 1158 | + text_single = this.decorate(this._prettify(this.result.from), this.result.from); |
1123 | 1159 | text_single += this.options.values_separator;
|
1124 |
| - text_single += this.decorate(this._prettify(this.result.to)); |
| 1160 | + text_single += this.decorate(this._prettify(this.result.to), this.result.to); |
1125 | 1161 | } else {
|
1126 |
| - text_single = this.decorate(this._prettify(this.result.from) + this.options.values_separator + this._prettify(this.result.to), this.result.from); |
| 1162 | + text_single = this.decorate(this._prettify(this.result.from) + this.options.values_separator + this._prettify(this.result.to), this.result.to); |
1127 | 1163 | }
|
1128 | 1164 | text_from = this.decorate(this._prettify(this.result.from), this.result.from);
|
1129 | 1165 | text_to = this.decorate(this._prettify(this.result.to), this.result.to);
|
|
1254 | 1290 | calcReal: function (percent) {
|
1255 | 1291 | var min = this.options.min,
|
1256 | 1292 | max = this.options.max,
|
| 1293 | + min_decimals = min.toString().split(".")[1], |
| 1294 | + max_decimals = max.toString().split(".")[1], |
| 1295 | + min_length, max_length, |
| 1296 | + avg_decimals = 0, |
1257 | 1297 | abs = 0;
|
1258 | 1298 |
|
| 1299 | + if (min_decimals) { |
| 1300 | + min_length = min_decimals.length; |
| 1301 | + avg_decimals = min_length; |
| 1302 | + } |
| 1303 | + if (max_decimals) { |
| 1304 | + max_length = max_decimals.length; |
| 1305 | + avg_decimals = max_length; |
| 1306 | + } |
| 1307 | + if (min_length && max_length) { |
| 1308 | + avg_decimals = (min_length >= max_length) ? min_length : max_length; |
| 1309 | + } |
| 1310 | + |
1259 | 1311 | if (min < 0) {
|
1260 | 1312 | abs = Math.abs(min);
|
1261 |
| - min = min + abs; |
1262 |
| - max = max + abs; |
| 1313 | + min = +(min + abs).toFixed(avg_decimals); |
| 1314 | + max = +(max + abs).toFixed(avg_decimals); |
1263 | 1315 | }
|
1264 | 1316 |
|
1265 | 1317 | var number = ((max - min) / 100 * percent) + min,
|
1266 |
| - string = this.options.step.toString().split(".")[1]; |
| 1318 | + string = this.options.step.toString().split(".")[1], |
| 1319 | + result; |
1267 | 1320 |
|
1268 | 1321 | if (string) {
|
1269 |
| - number = +number.toFixed(string.length); |
| 1322 | + if (number !== min && number !== max) { |
| 1323 | + number = +number.toFixed(string.length); |
| 1324 | + } else { |
| 1325 | + number = +number.toFixed(avg_decimals); |
| 1326 | + } |
1270 | 1327 | } else {
|
1271 | 1328 | number = number / this.options.step;
|
1272 | 1329 | number = number * this.options.step;
|
|
1275 | 1332 |
|
1276 | 1333 | if (abs) {
|
1277 | 1334 | number -= abs;
|
1278 |
| - } |
1279 |
| - |
1280 |
| - if (number < this.options.min) { |
1281 |
| - number = this.options.min; |
1282 |
| - } else if (number > this.options.max) { |
1283 |
| - number = this.options.max; |
| 1335 | + min = this.options.min; |
| 1336 | + max = this.options.max; |
1284 | 1337 | }
|
1285 | 1338 |
|
1286 | 1339 | if (string) {
|
1287 |
| - return +number.toFixed(string.length); |
| 1340 | + if (number !== min && number !== max) { |
| 1341 | + result = +number.toFixed(string.length); |
| 1342 | + } else { |
| 1343 | + result = +number.toFixed(avg_decimals); |
| 1344 | + } |
1288 | 1345 | } else {
|
1289 |
| - return this.toFixed(number); |
| 1346 | + result = this.toFixed(number); |
| 1347 | + } |
| 1348 | + |
| 1349 | + if (result < this.options.min) { |
| 1350 | + result = this.options.min; |
| 1351 | + } else if (result > this.options.max) { |
| 1352 | + result = this.options.max; |
1290 | 1353 | }
|
| 1354 | + |
| 1355 | + return result; |
1291 | 1356 | },
|
1292 | 1357 |
|
1293 | 1358 | calcWithStep: function (percent) {
|
|
1482 | 1547 | o.to = o.max;
|
1483 | 1548 | }
|
1484 | 1549 |
|
1485 |
| - if (o.from < o.min || o.from > o.max) { |
1486 |
| - o.from = o.min; |
1487 |
| - } |
| 1550 | + if (o.type === "single") { |
1488 | 1551 |
|
1489 |
| - if (o.to > o.max || o.to < o.min) { |
1490 |
| - o.to = o.max; |
1491 |
| - } |
| 1552 | + if (o.from < o.min) { |
| 1553 | + o.from = o.min; |
| 1554 | + } |
| 1555 | + |
| 1556 | + if (o.from > o.max) { |
| 1557 | + o.from = o.max; |
| 1558 | + } |
| 1559 | + |
| 1560 | + } else { |
| 1561 | + |
| 1562 | + if (o.from < o.min || o.from > o.max) { |
| 1563 | + o.from = o.min; |
| 1564 | + } |
| 1565 | + if (o.to > o.max || o.to < o.min) { |
| 1566 | + o.to = o.max; |
| 1567 | + } |
| 1568 | + if (o.from > o.to) { |
| 1569 | + o.from = o.to; |
| 1570 | + } |
1492 | 1571 |
|
1493 |
| - if (o.type === "double" && o.from > o.to) { |
1494 |
| - o.from = o.to; |
1495 | 1572 | }
|
1496 | 1573 |
|
1497 | 1574 | if (typeof o.step !== "number" || isNaN(o.step) || !o.step || o.step < 0) {
|
|
1660 | 1737 | local_small_max = small_max;
|
1661 | 1738 |
|
1662 | 1739 | big_w = this.toFixed(big_p * i);
|
| 1740 | + |
1663 | 1741 | if (big_w > 100) {
|
1664 | 1742 | big_w = 100;
|
1665 | 1743 |
|
|
1728 | 1806 | }
|
1729 | 1807 |
|
1730 | 1808 | if (this.options.force_edges) {
|
1731 |
| - if (start[0] < this.coords.grid_gap) { |
1732 |
| - start[0] = this.coords.grid_gap; |
| 1809 | + if (start[0] < -this.coords.grid_gap) { |
| 1810 | + start[0] = -this.coords.grid_gap; |
1733 | 1811 | finish[0] = this.toFixed(start[0] + this.coords.big_p[0]);
|
1734 | 1812 |
|
1735 | 1813 | this.coords.big_x[0] = this.coords.grid_gap;
|
1736 | 1814 | }
|
1737 | 1815 |
|
1738 |
| - if (finish[num - 1] > 100 - this.coords.grid_gap) { |
1739 |
| - finish[num - 1] = 100 - this.coords.grid_gap; |
| 1816 | + if (finish[num - 1] > 100 + this.coords.grid_gap) { |
| 1817 | + finish[num - 1] = 100 + this.coords.grid_gap; |
1740 | 1818 | start[num - 1] = this.toFixed(finish[num - 1] - this.coords.big_p[num - 1]);
|
1741 | 1819 |
|
1742 | 1820 | this.coords.big_x[num - 1] = this.toFixed(this.coords.big_p[num - 1] - this.coords.grid_gap);
|
|
0 commit comments