diff --git a/js/dlg/message-box.js b/js/dlg/message-box.js index f7008d77..d3be66b0 100644 --- a/js/dlg/message-box.js +++ b/js/dlg/message-box.js @@ -1,4 +1,5 @@ /* global $ $create animateElement focusAccessibility moveFocus */// dom.js +/* global clamp */// toolbox.js /* global t */// localization.js 'use strict'; @@ -84,10 +85,6 @@ messageBox.show = async ({ messageBox._resolve = resolve; }); - function clamp(value, min, max) { - return Math.min(Math.max(value, min), max); - } - function initOwnListeners() { let listening = false; let offsetX = 0; diff --git a/js/dom-on-load.js b/js/dom-on-load.js index 05e63b9a..f3f9db34 100644 --- a/js/dom-on-load.js +++ b/js/dom-on-load.js @@ -1,5 +1,5 @@ /* global $$ $ $create focusAccessibility getEventKeyName moveFocus */// dom.js -/* global debounce */// toolbox.js +/* global clamp debounce */// toolbox.js /* global t */// localization.js 'use strict'; @@ -34,7 +34,7 @@ const key = isSelect ? 'selectedIndex' : 'valueAsNumber'; const old = el[key]; 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) { el.dispatchEvent(new Event('change', {bubbles: true})); } diff --git a/options/options.js b/options/options.js index fbaa7f12..1590fa32 100644 --- a/options/options.js +++ b/options/options.js @@ -17,6 +17,7 @@ OPERA URLS capitalize + clamp ignoreChromeError openURL */// toolbox.js @@ -288,7 +289,7 @@ function enforceInputRange(element) { if (type === 'input' && element.checkValidity()) { doNotify(); } 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(); } }; diff --git a/popup/popup.js b/popup/popup.js index 6e028e3f..6c6f4e95 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -10,6 +10,7 @@ FIREFOX URLS capitalize + clamp getActiveTab isEmptyObj */// toolbox.js @@ -66,7 +67,7 @@ function onRuntimeMessage(msg) { function setPopupWidth(_key, width) { document.body.style.width = - Math.max(200, Math.min(800, width)) + 'px'; + clamp(width, 200, 800) + 'px'; } function toggleSideBorders(_key, state) {