-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
271 lines (251 loc) · 9.54 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html>
<head>
<title>NonBlock.js</title>
<style type="text/css">
body {
font-family: Arial;
font-size: 12pt;
color: #333;
padding: 0;
margin: 30px 20px;
}
.panel {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.panel section {
margin: 10px;
padding: 10px;
box-shadow: 0px 2px 5px 1px rgba(0,0,0,0.1);
flex-grow: 1;
}
.panel section h2:first-child {
margin-top: 0;
}
.container {
position: relative;
max-width: 400px;
background-color: #CCC;
border: 1px solid #333;
border-radius: 5px;
padding: 25px;
margin: 30px 0;
}
.intheway {
background-color: #F7FF95;
color: #838200;
border: 1px solid #838200;
border-radius: 5px;
padding: 12px;
box-shadow: 0px 2px 30px 5px rgba(0,0,0,0.3);
}
.intheway.first {
position: absolute;
top: 5px;
left: 30px;
height: 100px;
width: 120px;
}
.intheway.second,
.intheway.event-forwarding-first,
.intheway.event-forwarding-second,
.intheway.pointer-events-first,
.intheway.pointer-events-second {
position: absolute;
top: 4px;
bottom: 4px;
left: 4px;
right: 4px;
height: auto;
width: auto;
}
</style>
<script type="text/javascript" src="NonBlock.js"></script>
</head>
<body>
<h1>NonBlock.js</h1>
<p>
Unobtrusive (click through) UI elements in JavaScript.
</p>
<hr />
<div class="panel">
<!-- Demos -->
<section>
<h2>Demos</h2>
<!-- First demo, with the link under it -->
<div style="position: relative;">
<div class="container first">
This is a <a href="http://google.com" target="_blank">link</a>. Here
is some text. Let's have more text. All the text in the world couldn't
save you now, Mr. Bond. Ah, but that's where you're wrong. You see, my
overalls have been equipped with several tiny lasers that will blind
you while the speaker in my straw hat blasts disco music.
</div>
<div class="nonblock intheway first">
There's a link under me. I am going to stay in the way of that
link.
</div>
</div>
<hr />
<!-- Second demo, that you can toggle -->
<div>
Try toggling nonblocking on this demo:
<button onclick="document.querySelector('.intheway.second').classList.add('nonblock')">Enable NonBlock</button>
<button onclick="document.querySelector('.intheway.second').classList.remove('nonblock')">Disable NonBlock</button>
</div>
<div class="container second">
This is a <button type="button" onclick="alert('You clicked the button.')">button</button>.
<div class="nonblock intheway second">
There's a button under me. I am going to stay in the way of that
button.
</div>
</div>
<!-- These demos only show up in PointerEvents mode -->
<div id="showOnPointerEvents" style="display: none;">
<hr />
<div>
These demos show how event simulation in "PointerEvents" mode
works.
</div>
<div>
An event listener is placed on the yellow box.
</div>
<!-- First pointer events demo -->
<h4>
class="nonblock"
</h4>
<div class="container pointer-events-first">
This is a <button type="button" onclick="alert('You clicked the button.')">button</button>.
<div class="nonblock intheway pointer-events-first">
There's a button under me. I am going to stay in the way of
that button.
</div>
</div>
<div style="display: inline-block; font-family: monospace; width: auto;">
Event log:
<div id="event-pointer-events-first" style="max-height: 250px; overflow: auto;"></div>
</div>
<!-- Second pointer events demo -->
<h4>
class="nonblock nonblock-stop-mouse-simulation"
</h4>
<div class="container pointer-events-second">
This is a <button type="button" onclick="alert('You clicked the button.')">button</button>.
<div class="nonblock nonblock-stop-mouse-simulation intheway pointer-events-second">
There's a button under me. I am going to stay in the way of
that button.
</div>
</div>
<div style="display: inline-block; font-family: monospace; width: auto;">
Event log:
<div id="event-pointer-events-second" style="max-height: 250px; overflow: auto;"></div>
(seeing no events in this demo is normal.)
</div>
<!-- Script to listen for events on the nonblocks for the pointer events demos -->
<script type="text/javascript">
function listenerDemo(demo, eventType) {
document.querySelector('.nonblock.'+demo).addEventListener(eventType, function(event){
var output = document.getElementById('event-'+demo);
output.innerHTML += '<br />'+eventType+'<br />Target: '+event.target.tagName+' class="'+event.target.className+'"<br />';
output.scrollTop = output.scrollHeight;
});
}
var events = ['mouseenter', 'mouseover', 'mouseleave', 'mouseout', 'mousemove'];
for (var i in events) {
listenerDemo('pointer-events-first', events[i]);
listenerDemo('pointer-events-second', events[i]);
}
</script>
</div>
<!-- These demos only show up in EventForwarding mode -->
<div id="showOnEventForwarding" style="display: none;">
<hr />
<div>
These demos show how event propagation in "EventForwarding" mode
works.
</div>
<div>
The container is listening for events and the yellow box is a child.
</div>
<!-- First event propagation demo -->
<h4>
class="nonblock"
</h4>
<div class="container event-forwarding-first">
This is a <button type="button" onclick="alert('You clicked the button.')">button</button>.
<div class="nonblock intheway event-forwarding-first">
There's a button under me. I am going to stay in the way of
that button.
</div>
</div>
<div style="display: inline-block; font-family: monospace; width: auto;">
Event log:
<div id="event-event-forwarding-first" style="max-height: 250px; overflow: auto;"></div>
</div>
<!-- Second event propagation demo -->
<h4>
class="nonblock nonblock-stop-propagation"
</h4>
<div class="container event-forwarding-second">
This is a <button type="button" onclick="alert('You clicked the button.')">button</button>.
<div class="nonblock nonblock-stop-propagation intheway event-forwarding-second">
There's a button under me. I am going to stay in the way of
that button.
</div>
</div>
<div style="display: inline-block; font-family: monospace; width: auto;">
Event log:
<div id="event-event-forwarding-second" style="max-height: 250px; overflow: auto;"></div>
</div>
<!-- Script to listen for events on the containers for the event propagation demos -->
<script type="text/javascript">
function listenerDemo(demo, eventType) {
document.querySelector('.container.'+demo).addEventListener(eventType, function(event){
var output = document.getElementById('event-'+demo);
output.innerHTML += '<br />'+eventType+'<br />Target: '+event.target.tagName+' class="'+event.target.className+'"<br />';
output.scrollTop = output.scrollHeight;
});
}
var events = ['mouseenter', 'mouseover', 'mouseleave', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'];
for (var i in events) {
listenerDemo('event-forwarding-first', events[i]);
listenerDemo('event-forwarding-second', events[i]);
}
</script>
</div>
</section>
<!-- Mode Selector -->
<section>
<h2>Mode</h2>
<p>
Current mode: <span id="mode"></span><br />
PointerEvents in your browser: <span id="support"></span>
</p>
<div>
Force mode:
<button type="button" onclick="forceMode('PointerEvents')">PointerEvents</button>
<button type="button" onclick="forceMode('EventForwarding')">EventForwarding</button>
</div>
<!-- Script to change the mode and update the display/toggle the mode specific demos -->
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', detectMode);
function detectMode() {
document.getElementById('mode').innerHTML = NonBlockJs.nonBlock.mode;
document.getElementById('support').innerHTML = NonBlockJs.nonBlock.pointerEventsSupport ? 'Supported' : 'Unsupported';
document.getElementById('showOnEventForwarding').style.display =
NonBlockJs.nonBlock.mode === 'EventForwarding' ? 'block' : 'none';
document.getElementById('showOnPointerEvents').style.display =
NonBlockJs.nonBlock.mode === 'PointerEvents' ? 'block' : 'none';
}
function forceMode(mode) {
NonBlockJs.nonBlock.destroy();
NonBlockJs.nonBlock = new NonBlockJs.NonBlock(document.body, mode);
detectMode();
}
</script>
</section>
</div>
</body>
</html>