-
Notifications
You must be signed in to change notification settings - Fork 2
/
DynamicallyAddExternalIcon.html
65 lines (57 loc) · 2.08 KB
/
DynamicallyAddExternalIcon.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!--
Codepen sample: https://codepen.io/geospatialem/pen/OJoRgXq
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamically Add External Links</title>
<script type="module" src="https://js.arcgis.com/calcite-components/1.0.7/calcite.esm.js"></script>
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/1.0.7/calcite.css">
<style>
calcite-link {
display: flex;
margin: 1rem;
}
calcite-button[target="_blank"]::after,
calcite-link[target="_blank"]::after {
content: " (opens in new tab)";
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
</style>
</head>
<body>
<!-- Icon not added -->
<calcite-link href="https://developers.arcgis.com">ArcGIS Developers</calcite-link>
<!-- Icon added on-the-fly when target is set to blank -->
<calcite-link href="https://developers.arcgis.com/calcite-design-system" target="_blank">Calcite Design
System</calcite-link>
<script>
(async () => {
await customElements.whenDefined("calcite-link");
const calLink = document.querySelectorAll("calcite-link");
for (let i = 0; i < calLink.length; i++) {
if (calLink[i].target === "_blank" && !calLink[i].iconEnd) {
calLink[i].iconEnd = "launch";
}
}
await customElements.whenDefined("calcite-button");
const calBtn = document.querySelectorAll("calcite-button");
for (let i = 0; i < calBtn.length; i++) {
if (calBtn[i].target === "_blank" && !calBtn[i].iconEnd) {
calBtn[i].iconEnd = "launch";
}
}
})();
</script>
</body>
</html>