-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharia-modal.html
More file actions
99 lines (90 loc) · 2.77 KB
/
aria-modal.html
File metadata and controls
99 lines (90 loc) · 2.77 KB
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
96
97
98
99
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Accessible Modal Dialog</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script>
$(document).ready(function(e) {
$('#trigger-modal').click(function() {
//var lastFocus = document.activeElement; wont' work on iOS
var modalOverlay = $('<div>').attr({id:"modalOverlay", id:"modalOverlay"});
$(modalOverlay).appendTo('body');
$("#trigger-modal").attr('disabled','true');
var dialog = $('<div>').attr("aria-modal", "true");
$(dialog).html('<div id="firstElement" tabindex="0"></div><h1 id="dialog-heading">Account Login</h1><div id="dialog-description"><p>Enter your Username and Password below to sign in to your account. Click the Join button to create a new account.</p></div><form><label>Username <input id="username" type="text"></label><br><label>Password <input type="password"></label></form><button id="firstButton">Sign In</button><button>Join</button><button id="lastButton" aria-label="Close Account Login Dialog">X</button><div id="lastElement" tabindex="0"></div>').appendTo('body');
$('#username').focus();
$('#lastElement').focusin(function(e) {
$('#username').focus();
});
$('#firstElement').focusin(function(e) {
$('#lastButton').focus();
});
$('body').on('keyup', function(e) {
if(e.keyCode == '27'){
$(modalOverlay).remove();
$(dialog).remove();
$("#trigger-modal").removeAttr('disabled').focus();//works on iOS
}
});
$('[aria-modal=true] button').click(function(e) {
$(modalOverlay).remove();
$(dialog).remove();
//lastFocus.focus(); not working on iOS
$("#trigger-modal").removeAttr('disabled').focus();//works on iOS
});
return false;
});
});
</script>
<style type="text/css">
*:focus {outline:3px solid blue;}
#modalOverlay {
width:100%;
height:100%;
z-index:2;
background-color:#000;
opacity:0.5;
position:fixed;
top:0;
left:0;
margin:0;
padding:0;
}
[role=dialog] {
width:50%;
margin-left:auto;
margin-right:auto;
padding: 5px;
border: thin #000 solid;
background-color:#fff;
z-index:3;
position:fixed;
top:25%;
left:25%;
}
.scroll-frame {
overflow: auto;
overflow-x: hidden;
-webkit-overflow-scrolling:touch;
height:400px;
width:100%;
}
#lastButton {
position:absolute;
top: 0px;
right: 0px;
}
</style>
</head>
<body>
<main>
<h1>Accessible Modal Dialog</h1>
<p>Coding instructions: <a href="http://w3c.github.io/aria-practices/#dialog_modal">http://w3c.github.io/aria-practices/#dialog_modal</a></p>
<h2>WAI-ARIA role=dialog</h2>
<button id="trigger-modal" aria-haspopup="dialog">Trigger modal dialog</button>
</main>
</body>
</html>