use toolbox::clamp() more

This commit is contained in:
tophf 2022-01-21 20:25:03 +03:00
parent 16edf57400
commit 576511e6eb
4 changed files with 7 additions and 8 deletions

View File

@ -1,4 +1,5 @@
/* global $ $create animateElement focusAccessibility moveFocus */// dom.js /* global $ $create animateElement focusAccessibility moveFocus */// dom.js
/* global clamp */// toolbox.js
/* global t */// localization.js /* global t */// localization.js
'use strict'; 'use strict';
@ -84,10 +85,6 @@ messageBox.show = async ({
messageBox._resolve = resolve; messageBox._resolve = resolve;
}); });
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
function initOwnListeners() { function initOwnListeners() {
let listening = false; let listening = false;
let offsetX = 0; let offsetX = 0;

View File

@ -1,5 +1,5 @@
/* global $$ $ $create focusAccessibility getEventKeyName moveFocus */// dom.js /* global $$ $ $create focusAccessibility getEventKeyName moveFocus */// dom.js
/* global debounce */// toolbox.js /* global clamp debounce */// toolbox.js
/* global t */// localization.js /* global t */// localization.js
'use strict'; 'use strict';
@ -34,7 +34,7 @@
const key = isSelect ? 'selectedIndex' : 'valueAsNumber'; const key = isSelect ? 'selectedIndex' : 'valueAsNumber';
const old = el[key]; const old = el[key];
const rawVal = old + Math.sign(event.deltaY) * (el.step || 1); const rawVal = old + Math.sign(event.deltaY) * (el.step || 1);
el[key] = Math.max(el.min || 0, Math.min(el.max || el.length - 1, rawVal)); el[key] = clamp(rawVal, el.min || 0, el.max || el.length - 1);
if (el[key] !== old) { if (el[key] !== old) {
el.dispatchEvent(new Event('change', {bubbles: true})); el.dispatchEvent(new Event('change', {bubbles: true}));
} }

View File

@ -17,6 +17,7 @@
OPERA OPERA
URLS URLS
capitalize capitalize
clamp
ignoreChromeError ignoreChromeError
openURL openURL
*/// toolbox.js */// toolbox.js
@ -288,7 +289,7 @@ function enforceInputRange(element) {
if (type === 'input' && element.checkValidity()) { if (type === 'input' && element.checkValidity()) {
doNotify(); doNotify();
} else if (type === 'change' && !element.checkValidity()) { } else if (type === 'change' && !element.checkValidity()) {
element.value = Math.max(min, Math.min(max, Number(element.value))); element.value = clamp(Number(element.value), min, max);
doNotify(); doNotify();
} }
}; };

View File

@ -10,6 +10,7 @@
FIREFOX FIREFOX
URLS URLS
capitalize capitalize
clamp
getActiveTab getActiveTab
isEmptyObj isEmptyObj
*/// toolbox.js */// toolbox.js
@ -66,7 +67,7 @@ function onRuntimeMessage(msg) {
function setPopupWidth(_key, width) { function setPopupWidth(_key, width) {
document.body.style.width = document.body.style.width =
Math.max(200, Math.min(800, width)) + 'px'; clamp(width, 200, 800) + 'px';
} }
function toggleSideBorders(_key, state) { function toggleSideBorders(_key, state) {