-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ce77fa6
commit b477e0d
Showing
11 changed files
with
64 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* global axe */ | ||
|
||
/** | ||
* Return the list of attributes of a node. | ||
* @method getNodeAttributes | ||
* @memberof axe.utils | ||
* @param {Element} node | ||
* @returns {NamedNodeMap} | ||
*/ | ||
axe.utils.getNodeAttributes = function getNodeAttributes(node) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
if (node.attributes instanceof window.NamedNodeMap) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
return node.attributes; | ||
} | ||
|
||
// if the attributes property is not of type NamedNodeMap then the DOM | ||
// has been clobbered. E.g. <form><input name="attributes"></form>. | ||
// We can clone the node to isolate it and then return the attributes | ||
return node.cloneNode(false).attributes; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe('axe.utils.getNodeAttributes', function() { | ||
'use strict'; | ||
|
||
it('should return the list of attributes', function() { | ||
var node = document.createElement('div'); | ||
node.setAttribute('class', 'foo bar'); | ||
var actual = axe.utils.getNodeAttributes(node); | ||
assert.isTrue(actual instanceof window.NamedNodeMap); | ||
assert.equal(actual.length, 1); | ||
assert.equal(actual[0].name, 'class'); | ||
}); | ||
|
||
it('should return the list of attributes when the DOM is clobbered', function() { | ||
var node = document.createElement('form'); | ||
node.setAttribute('id', '123'); | ||
node.innerHTML = '<select name="attributes"></select>'; | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
assert.isFalse(node.attributes instanceof window.NamedNodeMap); | ||
|
||
var actual = axe.utils.getNodeAttributes(node); | ||
assert.isTrue(actual instanceof window.NamedNodeMap); | ||
assert.equal(actual.length, 1); | ||
assert.equal(actual[0].name, 'id'); | ||
}); | ||
}); |