summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2021-10-18 08:46:53 +0300
committerMaxim Devaev <[email protected]>2021-10-18 08:46:53 +0300
commite2873032eedb341a9a21686ad216ee87bf114f4d (patch)
tree4e887affa7f20f276f4f756d3ec0a48f117ebf53 /web
parentb4ca93dac1585b63e316287d66cecfbc8e00590c (diff)
slider setValue/getValue
Diffstat (limited to 'web')
-rw-r--r--web/share/js/kvm/mouse.js8
-rw-r--r--web/share/js/kvm/stream.js13
-rw-r--r--web/share/js/tools.js15
3 files changed, 22 insertions, 14 deletions
diff --git a/web/share/js/kvm/mouse.js b/web/share/js/kvm/mouse.js
index 7fc58905..7b50cf27 100644
--- a/web/share/js/kvm/mouse.js
+++ b/web/share/js/kvm/mouse.js
@@ -66,12 +66,12 @@ export function Mouse(__getResolution, __recordWsEvent) {
let rate_slider = $("hid-mouse-rate-slider");
tools.slider.setParams(rate_slider, 10, 100, 10, 100);
rate_slider.oninput = rate_slider.onchange = __updateRate;
- rate_slider.value = tools.storage.get("hid.mouse.rate", 100);
+ tools.slider.setValue(rate_slider, tools.storage.get("hid.mouse.rate", 100));
let sens_slider = $("hid-mouse-sens-slider");
tools.slider.setParams(sens_slider, 0.1, 1.9, 0.1, 1);
sens_slider.oninput = sens_slider.onchange = __updateRelativeSens;
- sens_slider.value = tools.storage.get("hid.mouse.sens", 1.0);
+ tools.slider.setValue(sens_slider, tools.storage.get("hid.mouse.sens", 1.0));
__updateRelativeSens();
tools.storage.bindSimpleSwitch($("hid-mouse-squash-switch"), "hid.mouse.squash", true);
@@ -111,7 +111,7 @@ export function Mouse(__getResolution, __recordWsEvent) {
};
var __updateRate = function() {
- let rate = parseInt($("hid-mouse-rate-slider").value);
+ let rate = tools.slider.getValue($("hid-mouse-rate-slider"));
$("hid-mouse-rate-value").innerHTML = rate;
tools.storage.set("hid.mouse.rate", rate);
if (__timer) {
@@ -121,7 +121,7 @@ export function Mouse(__getResolution, __recordWsEvent) {
};
var __updateRelativeSens = function() {
- __relative_sens = parseFloat($("hid-mouse-sens-slider").value);
+ __relative_sens = tools.slider.getValue($("hid-mouse-sens-slider"));
$("hid-mouse-sens-value").innerHTML = __relative_sens.toFixed(1);
tools.storage.set("hid.mouse.sens", __relative_sens);
};
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js
index 9aa77545..15a62194 100644
--- a/web/share/js/kvm/stream.js
+++ b/web/share/js/kvm/stream.js
@@ -508,17 +508,17 @@ export function Streamer() {
if (state.streamer) {
tools.el.setEnabled($("stream-quality-slider"), true);
- __setIfChanged($("stream-quality-slider"), state.streamer.encoder.quality, __updateQualityValue);
+ tools.slider.setValue($("stream-quality-slider"), state.streamer.encoder.quality, __updateQualityValue);
if (state.features.h264 && __janus_enabled) {
__setMinMax($("stream-h264-bitrate-slider"), state.limits.h264_bitrate);
tools.el.setEnabled($("stream-h264-bitrate-slider"), true);
- __setIfChanged($("stream-h264-bitrate-slider"), state.streamer.h264.bitrate, __updateH264BitrateValue);
+ tools.slider.setValue($("stream-h264-bitrate-slider"), state.streamer.h264.bitrate, __updateH264BitrateValue);
}
__setMinMax($("stream-desired-fps-slider"), state.limits.desired_fps);
tools.el.setEnabled($("stream-desired-fps-slider"), true);
- __setIfChanged($("stream-desired-fps-slider"), state.streamer.source.desired_fps, __updateDesiredFpsValue);
+ tools.slider.setValue($("stream-desired-fps-slider"), state.streamer.source.desired_fps, __updateDesiredFpsValue);
let resolution_str = __makeStringResolution(state.streamer.source.resolution);
if (__makeStringResolution(__resolution) !== resolution_str) {
@@ -597,13 +597,6 @@ export function Streamer() {
el.max = limits.max;
};
- var __setIfChanged = function(el, value, callback) {
- if (el.value !== value) {
- el.value = value;
- callback(value);
- }
- };
-
var __updateQualityValue = function(value) {
$("stream-quality-value").innerHTML = `${value}%`;
};
diff --git a/web/share/js/tools.js b/web/share/js/tools.js
index e0b350d5..26685cb4 100644
--- a/web/share/js/tools.js
+++ b/web/share/js/tools.js
@@ -162,6 +162,21 @@ export var tools = new function() {
el.step = step;
el.value = value;
},
+ "setValue": function(el, value, callback=null) {
+ if (el.value != value) {
+ el.value = value;
+ if (callback) {
+ callback(value);
+ }
+ }
+ },
+ "getValue": function(el) {
+ if (el.step % 1 === 0) {
+ return parseInt(el.value);
+ } else {
+ return parseFloat(el.value);
+ }
+ },
};
};