1 | ;
|
2 | /**
|
3 | * Copyright (c) 2017, Philip Walton <philip@philipwalton.com>
|
4 | */
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | /**
|
7 | * Gets all attributes of an element as a plain JavaScriot object.
|
8 | * @param {Element} element The element whose attributes to get.
|
9 | * @return {!Object} An object whose keys are the attribute keys and whose
|
10 | * values are the attribute values. If no attributes exist, an empty
|
11 | * object is returned.
|
12 | */
|
13 | function getAttributes(element) {
|
14 | var attrs = {};
|
15 | // Validate input.
|
16 | if (!(element && element.nodeType === 1))
|
17 | return attrs;
|
18 | // Return an empty object if there are no attributes.
|
19 | var map = element.attributes;
|
20 | if (map.length === 0)
|
21 | return {};
|
22 | for (var i = 0, attr = void 0; (attr = map[i]); i++) {
|
23 | attrs[attr.name] = attr.value;
|
24 | }
|
25 | return attrs;
|
26 | }
|
27 | exports.getAttributes = getAttributes;
|
28 | //# sourceMappingURL=get-attributes.js.map |
\ | No newline at end of file |