This repository has been archived by the owner on Sep 14, 2021. It is now read-only.
/
demo.html
228 lines (203 loc) · 5.35 KB
/
demo.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
---
layout: example
title: demo
---
<style scoped="scoped">
form input, form textarea, form select, form button
{
display: block;
}
input, textarea, select
{
min-width: 20em;
}
input[type=radio], input[type=checkbox]
{
min-width: 2em;
}
input[type=radio], input[type=checkbox]
{
display: inline;
}
kbd
{
border-width: 2px;
border-style: outset;
padding: 1px;
background-color: #eee;
}
.border
{
padding: 0.3em;
border: 1px dotted #999;
}
</style>
<p>
Sometimes it can be useful to programatically emulate/simulate the effect of pressing
the <kbd>tab</kbd> key. Examples include <a href="https://github.com/joelpurra/skipontab">
using <kbd>tab</kbd> to skip over less used form fields</a>, another to <a href="https://github.com/joelpurra/plusastab">
use the <kbd>+</kbd> on the keypad as a new tab key</a>.
</p>
<p>
This demo allows comparing EmulateTab to the browser you are using. Try to <kbd>tab</kbd>
and <kbd>shift</kbd>-<kbd>tab</kbd> through the fields. Then start the emulated
tabbing that runs on a timer.
</p>
<p>
Note that using the <em>mouse</em> to click on a button, checkbox or radio button
may cause the browser to <em>unfocus</em> (blur) the current selection. Since there
is no selected element, tabbing would then restart at the top of the page.
</p>
<fieldset>
<legend>Demo controls</legend>
<button id="enable-auto-navigation" type="button" autofocus="autofocus">
Enable auto navigation</button>
<button id="disable-auto-navigation" type="button">
Disable auto navigation</button>
<label>
<input id="auto-navigation-reverse" type="checkbox" />
Reverse</label>
<label>
<input id="auto-navigation-interval" type="number" min="0" max="2000" step="10" />
Interval</label>
</fieldset>
<form>
<fieldset>
<legend>A bunch of random form elements for demo purposes</legend>
<input type="text" value="Textbox" />
<textarea>Textarea</textarea>
<a href="http://joelpurra.se/">Joel Purra</a>
<input type="submit" value="Input type submit" />
<ol>
<li>
<label>
<input type="checkbox" />
Checkbox</label></li>
<li>
<label>
<input type="checkbox" />
Another textbox</label></li>
</ol>
<select>
<option>Drop down with two options</option>
<option>Another option</option>
</select>
<a>Anchors without <code>href</code> are always skipped by the browser</a>
<div class="border">
<button type="submit">
Inside container</button>
<div class="border">
<button type="submit">
Inside subcontainer to container</button>
</div>
<button type="submit">
Inside container</button>
</div>
<select multiple="multiple">
<option>First</option>
<option>Second</option>
<option>Third</option>
</select>
<fieldset>
<legend>First part of radio group 1</legend>
<label>
<input type="radio" name="radiogroup1" />
First</label>
<label>
<input type="radio" name="radiogroup1" />
Second</label>
<label>
<input type="radio" name="radiogroup1" />
Third</label>
</fieldset>
<input type="text" value="Textbox" />
<fieldset>
<legend>Second part of radio group 1</legend>
<label>
<input type="radio" name="radiogroup1" />
Fourth</label>
<label>
<input type="radio" name="radiogroup1" />
Fifth</label>
<label>
<input type="radio" name="radiogroup1" />
Sixth</label>
</fieldset>
<input type="text" value="Textbox" />
<fieldset>
<legend>Radio group 2 mixed with the third part of radio group 1</legend>
<label>
<input type="radio" name="radiogroup2" />
First</label>
<label>
<input type="radio" name="radiogroup1" />
Seventh</label>
<label>
<input type="radio" name="radiogroup2" />
Third</label>
</fieldset>
<button id="click-to-add-checkbox" type="button">
Click to add checkbox after button</button>
<p>
Tabbing past here will usually put focus in the address bar of the browser, but
the emulation will put focus at the top of the page. The emulation is not overriding
default behavior, it is extending it. Also, javascript cannot control focus of the
browser address
</p>
</fieldset>
</form>
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../dist/emulatetab.joelpurra.js"></script>
<script>
//<![CDATA[
var
intervalId,
defaultInterval = 500;
$("#auto-navigation-interval")
.val(defaultInterval);
$("form")
.submit(simulateSubmitting);
$("#enable-auto-navigation")
.click(enableAutoNavigation);
$("#disable-auto-navigation")
.click(disableAutoNavigation);
$("#click-to-add-checkbox")
.click(addCheckboxAfter);
function autoNavigate()
{
var reverse = $("#auto-navigation-reverse").is(":checked");
$.emulateTab(reverse ? -1 : +1);
}
function enableAutoNavigation()
{
disableAutoNavigation();
var interval = parseInt($("#auto-navigation-interval").val());
if (!$.isNumeric(interval))
{
interval = defaultInterval;
}
intervalId = setInterval(autoNavigate, interval);
}
function disableAutoNavigation()
{
clearInterval(intervalId);
}
function addCheckboxAfter(event)
{
var $target = $(event.target);
var $checkbox = $('<input />')
.attr("type", "checkbox");
$checkbox.insertAfter($target);
$target.focus();
}
function simulateSubmitting(event)
{
event.preventDefault();
if (confirm("Simulating that the form has been submitted.\n\nWould you like to reload the page?"))
{
location.reload();
}
return false;
}
//]]>
</script>