From 4de923420a71aa76700a269eea425adfdb529148 Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Sat, 10 Jun 2023 17:20:26 -0600 Subject: [PATCH] Move clamp to function --- javascript/qrcode.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/javascript/qrcode.js b/javascript/qrcode.js index bdd59b1..f64c7b0 100644 --- a/javascript/qrcode.js +++ b/javascript/qrcode.js @@ -1,29 +1,27 @@ onUiLoaded(function() { gradioApp().querySelector("#qrcode_geo_latitude input").addEventListener("input", (event) => { let target = event.originalTarget || event.composedPath()[0]; - if (target.value < -90) { - target.value = -90; - } else if (target.value > 90) { - target.value = 90; - } else { - return; + let value = target.value; + if (value < -90 || value > 90) { + target.value = clamp(value, -90, 90) + updateInput(target); } - updateInput(target); }); gradioApp().querySelector("#qrcode_geo_longitude input").addEventListener("input", (event) => { let target = event.originalTarget || event.composedPath()[0]; - if (target.value < -180) { - target.value = -180; - } else if (target.value > 180) { - target.value = 180; - } else { - return; + let value = target.value; + if (value < -180 || value > 180) { + target.value = clamp(value, -180, 180) + updateInput(target); } - updateInput(target); }); }); +function clamp(num, min, max) { + return Math.min(Math.max(num, min), max); +}; + async function sendToControlnet(img, tab, index) { const response = await fetch(img); const blob = await response.blob();