-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnativedialogs.html
139 lines (114 loc) · 4.37 KB
/
nativedialogs.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<title>Simple Dialogs</title>
<link href="images/favicon.ico" rel="icon">
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.10/purify.min.js"></script>
<script type="module">
import { alert_function2, confirm_function2, prompt_function2 } from './customdialog.js';
function alert_function(e) {
alert("Alert button is doing great!");
e.preventDefault();
}
function confirm_function(e) {
const text = "Test of confirm button.";
const output = document.getElementById('output');
const answer = confirm(text);
output.innerHTML = `The value returned by the confirm method is : ${answer}`;
e.preventDefault();
}
function prompt_function(e) {
const output = document.getElementById('output');
const dirty = prompt("Test of prompt button:", "Prompt?");
const input = DOMPurify.sanitize(dirty);
if (input != null) {
output.innerHTML = `The value returned by the prompt method is : ${input}`;
}
e.preventDefault();
}
function safer_prompt_function(e) {
const output = document.getElementById('output');
const dirty = prompt("Test of safer prompt button:", "Safer prompt?");
const input = DOMPurify.sanitize(dirty);
if (dirty != null) {
output.innerHTML = `The value returned by the safer prompt method is : ${input}`;
}
else {
output.innerHTML = "User didn’t enter anything";
}
e.preventDefault();
}
document.addEventListener('DOMContentLoaded', () => {
const alert = document.getElementById('alert');
const confirm = document.getElementById('confirm');
const prompt = document.getElementById('prompt');
const safer_prompt = document.getElementById('safer_prompt');
const alert2 = document.getElementById('alert2');
const confirm2 = document.getElementById('confirm2');
const prompt2 = document.getElementById('prompt2');
alert.addEventListener('click', alert_function);
confirm.addEventListener('click', confirm_function);
prompt.addEventListener('click', prompt_function);
safer_prompt.addEventListener('click', safer_prompt_function);
alert2.addEventListener('click', alert_function2);
confirm2.addEventListener('click', confirm_function2);
prompt2.addEventListener('click', prompt_function2);
});
</script>
<template id="template1">
<div id="div1">
<dialog open>
<p>Alert pressed.</p>
<div>
<button id="ok1">OK</button>
</div>
</dialog>
</div>
</template>
<template id="template2">
<div id="div2">
<dialog open>
<p>Do you confirm?</p>
<div>
<button id="ok2">OK</button>
<button id="cancel2">Cancel</button>
</div>
</dialog>
</div>
</template>
<template id="template3">
<div id="div3">
<dialog open>
<label for="prompt_input">What is your name?</label>
<input type="text" id="prompt_input" name="prompt_input">
<div>
<button id="ok3">OK</button>
<button id="cancel3">Cancel</button>
</div>
</dialog>
</div>
</template>
</head>
<body>
<header>
<h1>Simple Dialogs</h1>
</header>
<button type="button" id="alert">Alert</button>
<button type="button" id="confirm">Confirm</button>
<button type="button" id="prompt">Prompt</button>
<button type="button" id="safer_prompt">Safer Prompt</button>
<br>
<p>Output: <output id="output"></output></p>
<hr>
<hr>
<header>
<h1>Custom Dialogs</h1>
</header>
<button type="button" id="alert2">Alert</button>
<button type="button" id="confirm2">Confirm</button>
<button type="button" id="prompt2">Prompt</button>
<br>
<p>Output: <output id="output2"></output></p>
<div id="dialog_place"></div>
</body>
</html>