Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the amount of magic numbers in JS code in Gallery #9078

Open
agr opened this issue Mar 28, 2022 · 0 comments
Open

Reduce the amount of magic numbers in JS code in Gallery #9078

agr opened this issue Mar 28, 2022 · 0 comments

Comments

@agr
Copy link
Contributor

agr commented Mar 28, 2022

Gallery JS code is ridden with magic numbers:

return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);

var isInteract = (code === 13 /*enter*/ || code === 32 /*space*/) && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;

(code >= 48 && code <= 57 // numbers 0-9
|| code >= 64 && code <= 90 // letters a-z
|| code >= 96 && code <= 111 // numpad
|| code >= 186 && code <= 192 // ; = , - . / `
|| code >= 219 && code <= 222) // [\ ] '

if ((e.keyCode >= 46 && e.keyCode <= 90) //delete, 0-9, a-z
|| (e.keyCode >= 96 && e.keyCode <= 111) //numpad
|| (e.keyCode >= 186) //punctuation
|| (e.keyCode == 8)) //backspace

etc.

For better code readability it would be nice to provide nice names at least for some of them (key codes, for example). Some attempts to do it seems to have been done in the past, we need to extend it:

var _autocompleteTimeout = 0;
var _autocompleteDelay = 100; // time to wait between keypresses before starting autocomplete requests
var _resultsCache = {};
var _maxResults = 9;
var _lastIndex = 0;
var _keyCodes = {
tab: 9,
esc: 27,
upArrow: 38,
downArrow: 40
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant