Clean up cycle-inputs.js

This commit is contained in:
Florian Bruhin 2018-02-09 12:14:07 +01:00
parent 8c3039abc9
commit 7caab75fa4

View File

@ -9,38 +9,38 @@
* By dive on freenode <dave@dawoodfall.net> * By dive on freenode <dave@dawoodfall.net>
*/ */
"use strict"; (function() {
var inputs = document.getElementsByTagName("input"); "use strict";
var types = /text|password|date|email|month|number|range|search|tel|time|url|week/; const inputs = document.getElementsByTagName("input");
var hidden = /hidden/; const types = /text|password|date|email|month|number|range|search|tel|time|url|week/;
var found = false; const hidden = /hidden/;
var i = 0; let found = false;
var k = 0;
function ishidden(el) { function ishidden(el) {
return hidden.test(el.attributes.value) || el.offsetParent === null; return hidden.test(el.attributes.value) || el.offsetParent === null;
}
for (i = 0; i < inputs.length; i++) {
if (inputs[i] === document.activeElement) {
for (k = i + 1; k < inputs.length; k++) {
if (!ishidden(inputs[k]) && types.test(inputs[k].type)) {
inputs[k].focus();
found = true;
break;
}
}
break;
} }
}
if (!found) { for (let i = 0; i < inputs.length; i++) {
for (i = 0; i < inputs.length; i++) { if (inputs[i] === document.activeElement) {
if (!ishidden(inputs[i]) && types.test(inputs[i].type)) { for (let k = i + 1; k < inputs.length; k++) {
inputs[i].focus(); if (!ishidden(inputs[k]) && types.test(inputs[k].type)) {
inputs[k].focus();
found = true;
break;
}
}
break; break;
} }
} }
}
if (!found) {
for (let i = 0; i < inputs.length; i++) {
if (!ishidden(inputs[i]) && types.test(inputs[i].type)) {
inputs[i].focus();
break;
}
}
}
})();
// vim: tw=0 expandtab tabstop=4 softtabstop=4 shiftwidth=4 // vim: tw=0 expandtab tabstop=4 softtabstop=4 shiftwidth=4