Focus order.js

From Level Access Web Labs
Revision as of 18:25, 10 December 2017 by Javila (talk | contribs) (Created page with "(function () { var nl = document.querySelectorAll("[tabindex], button, a[href], area, input, select, textarea, iframe"); var ar = [] var ar_position = 0; var positive ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

(function () {

 var nl = document.querySelectorAll("[tabindex], button, a[href], area, input, select, textarea, iframe");
 var ar = []
 var ar_position = 0;
 var positive = [];
 var positive_position = 0;
 for (var i=0; i < nl.length; i++) {
		 if (!nl[i].hasAttribute('disabled') ) {
		   if (nl[i].hasAttribute('tabindex') ) {
         if ( nl[i].getAttribute('tabindex') == 0 ) {
           ar[ar_position] = nl[i];
           ar_position++;
         }
         else if ( nl[i].getAttribute('tabindex') > 0 ) {
           positive[positive_position] = nl[i];
           positive_position++;
         }
      }
      else {

ar[ar_position] = nl[i]; ar_position++;

      }
    }
 }
 positive.sort(function(a, b) {

return parseInt(a.getAttribute('tabindex'),10) - parseInt(b.getAttribute("tabindex"),10);

 });
 for (var i=0; i < positive.length; i++) {

s = document.createElement('span'); t = document.createTextNode(i+1); s.appendChild(t); s.style.backgroundColor = 'darkblue'; s.style.color = 'white'; s.style.fontSize = "small"; positive[i].parentNode.insertBefore(s,positive[i]);

 }
 for (var i=0; i < ar.length; i++) {

s = document.createElement('span'); t = document.createTextNode(positive.length+i+1); s.appendChild(t); s.style.backgroundColor = 'darkblue'; s.style.color = 'white'; s.style.display = "inline-block"; s.style.fontSize = "small"; ar[i].parentNode.insertBefore(s,ar[i]);

 }

})();