This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal.html
95 lines (78 loc) · 4.62 KB
/
modal.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Accessible Modal Dialog</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="dialog.scss">
</head>
<body>
<div class="modal"
id="modal"
role="dialog"
aria-labelledby="modal__title"
aria-describedby="modal__description"
aria-hidden="true">
<div class="modal__content">
<h1 id="modal__title">Headline</h1>
<p id="modal__description" class="sr-only">Description goes here</p>
<nav>
<ul>
<li><a href="one.html">Link One</a></li>
<li><a href="two.html">Link Two</a></li>
<li><a href="three.html">Link Three</a></li>
</ul>
</nav>
<h1>Modal Example</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<input type="text">
<h1>Modal Example</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>otam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<h1>Modal Example</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<h1>Modal Example</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
</div>
<button class="modal__close" aria-label="Close Modal">Close Modal</button>
</div>
<div class="modal"
id="modal-2"
role="dialog"
aria-labelledby="modal-2__title"
aria-describedby="modal-2__description"
aria-hidden="true">
<div class="modal__content">
<h1 id="modal-2__title">Headline 2</h1>
<p id="modal-2__description" class="sr-only">Description goes here</p>
<h1>Modal Example 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae expedita corrupti laudantium aperiam, doloremque explicabo ipsum earum dicta saepe delectus totam vitae ipsam doloribus et obcaecati facilis eius assumenda, cumque.</p>
</div>
<button class="modal__close" aria-label="Close Modal">Close Modal</button>
</div>
<a id="open-modal"
href="#modal"
class="open-modal"
aria-label="Open Modal">Open Modal</a>
<a id="open-modal"
href="#modal-2"
class="open-modal"
aria-label="Open Modal 2">Open Modal 2</a>
<div class="modal-overlay" tabindex="-1" aria-hidden="true"></div>
<script src="modal.js"></script>
<script>
const dialogTriggers = document.querySelectorAll('.open-modal');
for (let dialogTrigger of dialogTriggers) {
let dialogOverlay = document.querySelector('.modal-overlay');
// get target id via href hash
let targetDialog = document.getElementById(dialogTrigger.hash.substr(1));
let dialog = new Dialog(targetDialog, dialogOverlay);
dialog.addEventListeners(dialogTrigger, '.modal__close');
}
</script>
</body>
</html>