source: trip-planner-front/node_modules/@angular/cdk/esm2015/a11y/aria-describer/aria-reference.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/** IDs are delimited by an empty space, as per the spec. */
9const ID_DELIMITER = ' ';
10/**
11 * Adds the given ID to the specified ARIA attribute on an element.
12 * Used for attributes such as aria-labelledby, aria-owns, etc.
13 */
14export function addAriaReferencedId(el, attr, id) {
15 const ids = getAriaReferenceIds(el, attr);
16 if (ids.some(existingId => existingId.trim() == id.trim())) {
17 return;
18 }
19 ids.push(id.trim());
20 el.setAttribute(attr, ids.join(ID_DELIMITER));
21}
22/**
23 * Removes the given ID from the specified ARIA attribute on an element.
24 * Used for attributes such as aria-labelledby, aria-owns, etc.
25 */
26export function removeAriaReferencedId(el, attr, id) {
27 const ids = getAriaReferenceIds(el, attr);
28 const filteredIds = ids.filter(val => val != id.trim());
29 if (filteredIds.length) {
30 el.setAttribute(attr, filteredIds.join(ID_DELIMITER));
31 }
32 else {
33 el.removeAttribute(attr);
34 }
35}
36/**
37 * Gets the list of IDs referenced by the given ARIA attribute on an element.
38 * Used for attributes such as aria-labelledby, aria-owns, etc.
39 */
40export function getAriaReferenceIds(el, attr) {
41 // Get string array of all individual ids (whitespace delimited) in the attribute value
42 return (el.getAttribute(attr) || '').match(/\S+/g) || [];
43}
44//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJpYS1yZWZlcmVuY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL2ExMXkvYXJpYS1kZXNjcmliZXIvYXJpYS1yZWZlcmVuY2UudHMiXSwibmFtZXMiOltdLCJt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