Skip to content

Commit b12fef6

Browse files
committed
Update to ionRangeSlider 2.0.10
1 parent 21c7193 commit b12fef6

File tree

3 files changed

+119
-42
lines changed

3 files changed

+119
-42
lines changed

R/input-slider.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ sliderInput <- function(inputId, label, min, max, value, step = NULL,
128128
)
129129
}
130130

131-
dep <- htmlDependency("ionrangeslider", "2.0.6", c(href="shared/ionrangeslider"),
131+
dep <- htmlDependency("ionrangeslider", "2.0.10", c(href="shared/ionrangeslider"),
132132
script = "js/ion.rangeSlider.min.js",
133133
# ion.rangeSlider also needs normalize.css, which is already included in
134134
# Bootstrap.

inst/www/shared/ionrangeslider/js/ion.rangeSlider.js

Lines changed: 116 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Ion.RangeSlider
2-
// version 2.0.6 Build: 300
2+
// version 2.0.10 Build: 323
33
// © Denis Ineshin, 2015
44
// https://github.com/IonDen
55
//
@@ -18,6 +18,7 @@
1818

1919
var plugin_count = 0;
2020

21+
// IE8 fix
2122
var is_old_ie = (function () {
2223
var n = navigator.userAgent,
2324
r = /msie\s\d+/i,
@@ -32,8 +33,6 @@
3233
}
3334
return false;
3435
} ());
35-
36-
// IE8 fix
3736
if (!Function.prototype.bind) {
3837
Function.prototype.bind = function bind(that) {
3938

@@ -139,11 +138,12 @@
139138
// Core
140139

141140
var IonRangeSlider = function (input, options, plugin_count) {
142-
this.VERSION = "2.0.6";
141+
this.VERSION = "2.0.10";
143142
this.input = input;
144143
this.plugin_count = plugin_count;
145144
this.current_plugin = 0;
146145
this.calc_count = 0;
146+
this.update_tm = 0;
147147
this.old_from = 0;
148148
this.old_to = 0;
149149
this.raf_id = null;
@@ -231,7 +231,6 @@
231231
disable: $inp.data("disable")
232232
};
233233
data.values = data.values && data.values.split(",");
234-
options = $.extend(data, options);
235234

236235
// get from and to out of input
237236
var val = $inp.prop("value");
@@ -245,7 +244,7 @@
245244
val[1] = +val[1];
246245
}
247246

248-
if (options.values && options.values.length) {
247+
if (options && options.values && options.values.length) {
249248
data.from = val[0] && options.values.indexOf(val[0]);
250249
data.to = val[1] && options.values.indexOf(val[1]);
251250
} else {
@@ -254,6 +253,9 @@
254253
}
255254
}
256255

256+
// JS config has a priority
257+
options = $.extend(data, options);
258+
257259
// get config from options
258260
this.options = $.extend({
259261
type: "single",
@@ -413,7 +415,6 @@
413415
}
414416

415417
this.updateScene();
416-
this.raf_id = requestAnimationFrame(this.updateScene.bind(this));
417418
},
418419

419420
append: function () {
@@ -446,6 +447,8 @@
446447
this.$cache.s_to = this.$cache.cont.find(".to");
447448
this.$cache.shad_from = this.$cache.cont.find(".shadow-from");
448449
this.$cache.shad_to = this.$cache.cont.find(".shadow-to");
450+
451+
this.setTopHandler();
449452
}
450453

451454
if (this.options.hide_from_to) {
@@ -466,6 +469,19 @@
466469
}
467470
},
468471

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+
469485
appendDisableMask: function () {
470486
this.$cache.cont.append(disable_html);
471487
this.$cache.cont.addClass("irs-disabled");
@@ -580,6 +596,8 @@
580596
if (is_old_ie) {
581597
$("*").prop("unselectable", false);
582598
}
599+
600+
this.updateScene();
583601
},
584602

585603
pointerDown: function (target, e) {
@@ -630,6 +648,8 @@
630648
}
631649

632650
this.$cache.line.trigger("focus");
651+
652+
this.updateScene();
633653
},
634654

635655
pointerClick: function (target, e) {
@@ -679,7 +699,7 @@
679699
return true;
680700
},
681701

682-
// Move by key beta
702+
// Move by key. Beta
683703
// TODO: refactor than have plenty of time
684704
moveByKey: function (right) {
685705
var p = this.coords.p_pointer;
@@ -827,6 +847,10 @@
827847
break;
828848

829849
case "both":
850+
if (this.options.from_fixed || this.options.to_fixed) {
851+
break;
852+
}
853+
830854
real_x = this.toFixed(real_x + (this.coords.p_handle * 0.1));
831855

832856
this.coords.p_from_real = this.calcWithStep((real_x - this.coords.p_gap_left) / real_width * 100);
@@ -890,9 +914,9 @@
890914
} else {
891915
var m_point = this.coords.p_from_real + ((this.coords.p_to_real - this.coords.p_from_real) / 2);
892916
if (real_x >= m_point) {
893-
return "to";
917+
return this.options.to_fixed ? "from" : "to";
894918
} else {
895-
return "from";
919+
return this.options.from_fixed ? "to" : "from";
896920
}
897921
}
898922
},
@@ -947,13 +971,25 @@
947971
// Drawings
948972

949973
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+
950982
if (!this.options) {
951983
return;
952984
}
953985

954986
this.drawHandles();
955987

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+
}
957993
},
958994

959995
drawHandles: function () {
@@ -1119,11 +1155,11 @@
11191155
} else {
11201156

11211157
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);
11231159
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);
11251161
} 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);
11271163
}
11281164
text_from = this.decorate(this._prettify(this.result.from), this.result.from);
11291165
text_to = this.decorate(this._prettify(this.result.to), this.result.to);
@@ -1254,19 +1290,40 @@
12541290
calcReal: function (percent) {
12551291
var min = this.options.min,
12561292
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,
12571297
abs = 0;
12581298

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+
12591311
if (min < 0) {
12601312
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);
12631315
}
12641316

12651317
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;
12671320

12681321
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+
}
12701327
} else {
12711328
number = number / this.options.step;
12721329
number = number * this.options.step;
@@ -1275,19 +1332,27 @@
12751332

12761333
if (abs) {
12771334
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;
12841337
}
12851338

12861339
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+
}
12881345
} 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;
12901353
}
1354+
1355+
return result;
12911356
},
12921357

12931358
calcWithStep: function (percent) {
@@ -1482,16 +1547,28 @@
14821547
o.to = o.max;
14831548
}
14841549

1485-
if (o.from < o.min || o.from > o.max) {
1486-
o.from = o.min;
1487-
}
1550+
if (o.type === "single") {
14881551

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+
}
14921571

1493-
if (o.type === "double" && o.from > o.to) {
1494-
o.from = o.to;
14951572
}
14961573

14971574
if (typeof o.step !== "number" || isNaN(o.step) || !o.step || o.step < 0) {
@@ -1660,6 +1737,7 @@
16601737
local_small_max = small_max;
16611738

16621739
big_w = this.toFixed(big_p * i);
1740+
16631741
if (big_w > 100) {
16641742
big_w = 100;
16651743

@@ -1728,15 +1806,15 @@
17281806
}
17291807

17301808
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;
17331811
finish[0] = this.toFixed(start[0] + this.coords.big_p[0]);
17341812

17351813
this.coords.big_x[0] = this.coords.grid_gap;
17361814
}
17371815

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;
17401818
start[num - 1] = this.toFixed(finish[num - 1] - this.coords.big_p[num - 1]);
17411819

17421820
this.coords.big_x[num - 1] = this.toFixed(this.coords.big_p[num - 1] - this.coords.grid_gap);

0 commit comments

Comments
 (0)