From eb476ffdd2442e17cf07ad769a9b82d86cdc5eb1 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Tue, 6 Nov 2018 06:35:23 +0300 Subject: better sliders --- web/js/tools.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'web/js/tools.js') diff --git a/web/js/tools.js b/web/js/tools.js index 068032ac..22ef0a28 100644 --- a/web/js/tools.js +++ b/web/js/tools.js @@ -36,12 +36,38 @@ var tools = new function() { }; }; + this.setOnUpSlider = function(el, delay, display_callback, execute_callback) { + el.execution_timer = null; + el.activated = false; + + var clear_timer = function() { + if (el.execution_timer) { + clearTimeout(el.execution_timer); + el.execution_timer = null; + } + }; + + el.oninput = el.onchange = () => display_callback(el.value); + + el.onmousedown = el.ontouchstart = function() { + clear_timer(); + el.activated = true; + }; + + el.onmouseup = el.ontouchend = function(event) { + event.preventDefault(); + clear_timer(); + el.execution_timer = setTimeout(function() { + execute_callback(el.value); + }, delay); + }; + }; + this.debug = function(...args) { if (__debug) { console.log("LOG/DEBUG", ...args); // eslint-disable-line no-console } }; - this.info = (...args) => console.log("LOG/INFO", ...args); // eslint-disable-line no-console this.error = (...args) => console.error("LOG/ERROR", ...args); // eslint-disable-line no-console -- cgit v1.2.3