tabindex.js - jscancer - Javascript crap (relatively small)
(HTM) git clone git://git.codemadness.org/jscancer
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tabindex.js (1408B)
---
1 // automatically increment and set tabindex on enabled/writable inputs.
2 var tabindexroots = document.querySelectorAll(".tabindex-auto");
3 if (tabindexroots && tabindexroots.length) {
4 var tabels = []; // all input elements to potentially apply tabindex too.
5 var selector = "input, select, textarea" // "input, select, textarea, a";
6 for (var i = 0; i < tabindexroots.length; i++) {
7 var tabindexroot = tabindexroots[i];
8 if (tabindexroot.tagName === "TABLE") {
9 // determine max column.
10 var max = -1;
11 for (var row of tabindexroot.rows) {
12 if (max === -1 || row.cells.length > max)
13 max = row.cells.length;
14 }
15 // for tables option to increase tabindex vertically per row per cell.
16 for (var j = 0; j < max; j++) {
17 for (var row of tabindexroot.rows) {
18 if (j >= row.cells.length)
19 continue;
20 var inputs = row.cells[j].querySelectorAll(selector);
21 if (inputs && inputs.length)
22 tabels = tabels.concat(Array.from(inputs));
23 }
24 }
25 } else {
26 var els = tabindexroot.querySelectorAll(selector);
27 if (els && els.length)
28 tabels = tabels.concat(Array.from(els));
29 }
30 }
31
32 // apply tabindex.
33 var tabindexcount = 1;
34 for (var i = 0; i < tabels.length; i++) {
35 // filter elements
36 if (tabels[i].tagName == "A" ||
37 tabels[i].readOnly || tabels[i].disabled || tabels[i].hidden)
38 continue;
39 tabels[i].tabIndex = tabindexcount;
40 tabindexcount++;
41 }
42