Comparing version 1.0.2 to 1.0.3
# Changelog | ||
## 1.0.3 | ||
- Further improvements to caching. | ||
## 1.0.2 | ||
@@ -4,0 +8,0 @@ |
57
index.js
module.exports = function(el) { | ||
// Node cache must be refreshed on every check, in case | ||
// the content of the element has changed | ||
var nodeCache = {}; | ||
var nodeCacheIndex = 1; | ||
function isHidden(node) { | ||
if (node === document.documentElement) { | ||
return false; | ||
} | ||
if (node.tabbableCacheIndex) { | ||
return nodeCache[node.tabbableCacheIndex]; | ||
} | ||
var result = false; | ||
var style = window.getComputedStyle(node); | ||
if (style.visibility === 'hidden' || style.display === 'none') { | ||
result = true; | ||
} else if (node.parentNode) { | ||
result = isHidden(node.parentNode); | ||
} | ||
node.tabbableCacheIndex = nodeCacheIndex; | ||
nodeCache[node.tabbableCacheIndex] = result; | ||
nodeCacheIndex++; | ||
return result; | ||
} | ||
var basicTabbables = []; | ||
var orderedTabbables = []; | ||
var isHidden = createIsHidden(); | ||
@@ -71,1 +44,29 @@ var candidates = el.querySelectorAll('input, select, a[href], textarea, button, [tabindex]'); | ||
} | ||
function createIsHidden() { | ||
// Node cache must be refreshed on every check, in case | ||
// the content of the element has changed | ||
var nodeCache = []; | ||
return function isHidden(node) { | ||
if (node === document.documentElement) return false; | ||
var cached = nodeCache.find(function(item) { | ||
return item[0] === node; | ||
}); | ||
if (cached) return cached[1]; | ||
var result = false; | ||
var style = window.getComputedStyle(node); | ||
if (style.visibility === 'hidden' || style.display === 'none') { | ||
result = true; | ||
} else if (node.parentNode) { | ||
result = isHidden(node.parentNode); | ||
} | ||
nodeCache.push([node, result]); | ||
return result; | ||
} | ||
} |
{ | ||
"name": "tabbable", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Returns an array of all tabbable DOM nodes within a containing node.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6596
57