-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog - Copy.html
98 lines (89 loc) · 2.7 KB
/
dialog - Copy.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
96
97
98
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>모달 대화상자 샘플</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 role="dialog">').attr({"aria-labelledby":"dialog-heading", "aria-modal":"true"});
$(dialog).html('<div id="firstElement" tabindex="0"></div><h1 id="dialog-heading" tabindex="-1">사용자 로그인</h1><div id="dialog-description" tabindex="-1"><p>아래 로그인 정보를 입력하세요.</p></div><form><label>아이디 <input id="username" type="text"></label><br><label>비밀번호 <input type="password"></label></form><button id="firstButton">로그인</button><button>회원가입</button><button id="lastButton" aria-label="로그인 화면 닫기">X</button><div id="lastElement" tabindex="0"></div>').appendTo('body');
$('#dialog-heading').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
}
});
$('[role=dialog] 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>접근성이 적용된 모달 대화상자</h1>
<p>대화상자 시뮬레이션 페이지입니다.</p>
<button id="trigger-modal" aria-haspopup="dialog">계정 로그인</button>
</main>
</body>
</html>