-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialog-requestclose-method.html
More file actions
100 lines (86 loc) · 2.31 KB
/
Copy pathdialog-requestclose-method.html
File metadata and controls
100 lines (86 loc) · 2.31 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
100
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>デモ:dialog要素をJavaScriptで開閉する(各種イベントチェック)</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>デモ:dialog要素をJavaScriptで開閉する(各種イベントチェック)</h1>
<div class="toolbar">
<button class="open-button">
ダイアログを開く
</button>
</div>
<dialog id="modal-dialog">
<p>ダイアログです。</p>
<button class="request-close-button" value="hello-world">
閉じるリクエスト
</button>
<button class="close-button">
閉じる
</button>
</dialog>
<h2>ログ</h2>
<pre id="log"></pre>
<footer>
<p><a href="./">トップに戻る</a></p>
</footer>
<script>
const dialog = document.querySelector('#modal-dialog');
const openButton = document.querySelector('.open-button');
const requestCloseButton = document.querySelector('.request-close-button');
const closeButton = document.querySelector('.close-button');
openButton.addEventListener('click', () => {
dialog.showModal();
});
requestCloseButton.addEventListener('click', () => {
dialog.requestClose(requestCloseButton.value);
});
closeButton.addEventListener('click', () => {
dialog.close();
});
function logEvent(event) {
const logElement = document.getElementById('log');
const groupTitle = `${event.target.tagName} ${event.type} event`;
console.group(groupTitle);
console.dir(event);
console.groupEnd();
const logEntry = `
${groupTitle}:
{
type: "${event.type}",
target: ${event.target.tagName},
currentTarget: ${event.currentTarget.tagName},
cancelable: ${event.cancelable}
}`;
logElement.textContent += logEntry + '\n';
}
dialog.addEventListener('close', (event) => {
logEvent(event);
});
dialog.addEventListener('cancel', (event) => {
logEvent(event);
});
dialog.addEventListener('command', (event) => {
logEvent(event);
});
if ('CloseWatcher' in window) {
const watcher = new CloseWatcher();
watcher.addEventListener('close', (event) => {
logEvent(event);
});
watcher.addEventListener('cancel', (event) => {
logEvent(event);
});
}
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') {
logEvent(event);
}
});
</script>
<script src="hide-footer-inside-iframe.js"></script>
</body>
</html>