-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
382 lines (356 loc) · 11.6 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.shiftcheckbox.js"></script>
<script type="text/javascript" src="//google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<script type="text/javascript">
function setInfoText(text) {
$('#demo1-link').text(text);
if (console && console.log) console.log(text);
}
$(function() {
$('#demo1 div.checkbox').shiftcheckbox({
// Options accept selectors, jQuery objects, or DOM
// elements.
checkboxSelector : ':checkbox',
selectAll : $('#demo1 .all'),
ignoreClick : 'a',
// The onChange function will be called whenever the
// plugin changes the state of a checkbox.
onChange : function(checked) {
setInfoText(
'Changed checkbox ' + $(this).attr('id')
+ ' to ' + checked + ' programmatically');
}
});
// If you also want to handle the user clicking on a
// checkbox, use the jQuery .change() event.
$('#demo1 :checkbox').change(function() {
setInfoText(
'Clicked checkbox ' + $(this).attr('id')
+ ', checked=' + this.checked);
});
$('#demo2 :checkbox').shiftcheckbox();
$('#demo3 .row').shiftcheckbox({
checkboxSelector : ':checkbox',
selectAll : '#demo3 .all'
});
$('.demo a:not(.toggle-code)').click(function() {
setInfoText('Clicked link: ' + $(this).attr('href')
+ ' at ' + new Date());
if ($(this).hasClass('block-click')) {
return false;
}
});
$('.toggle-code').click(function() {
var $pre = $(this).parent().next('pre');
if ($pre.is(':visible')) {
$pre.hide();
$(this).text('show');
} else {
$pre.show();
$(this).text('hide');
}
return false;
});
});
</script>
<style type="text/css">
body {
padding-bottom: 4em;
}
p {
margin-bottom: 1em;
max-width: 850px;
}
h2 {
margin: 1em 0;
}
#demo1 .all, #demo2 .all {
margin-bottom: .75em;
}
.all:hover, .checkbox:hover, div.row:hover {
background: #eee;
}
code, pre {
background: #eee;
border: 1px solid #aaa !important;
}
code {
padding: 1px 3px;
}
pre {
max-width: 550px;
padding: 6px !important;
margin: 25px 15px;
}
label, span.label {
padding: 0 8px;
margin: 0 4px;
}
label {
font-weight: bold;
}
label:hover {
background: #999;
color: white;
}
#demo1-link {
font-style: italic;
color: #999;
}
</style>
</head>
<body>
<h1>ShiftCheckbox jQuery plugin</h1>
<p>
This jQuery plugin can perform the following checkbox-related functions:
<ul>
<li>
Shift+click to select/deselect ranges of checkboxes, like in GMail
</li>
<li>
Handling the events of one or more "Select all" checkboxes
</li>
<li>
Passing clicks from a "row" element that contains a checkbox to the
checkbox itself
</li>
</ul>
A couple demos of the plugin's functionality are below.
</p>
<p>
<a href="https://github.com/nylen/shiftcheckbox">
Click here to browse the plugin source on GitHub.
</a>
</p>
<p>
<a href="jquery.shiftcheckbox.js">Click here to download the plugin.</a>
</p>
<h2>Demo 1 - All features in use</h2>
<div class="demo" id="demo1">
<p>
Click (or Shift+click) on any part of a row to select the corresponding
checkbox. The rows are the <code>div.checkbox</code> elements, and the
presence of the <code>checkboxSelector</code> option tells the plugin
that it should handle click events on the rows and pass them to the
checkboxes.
</p>
<p>
Because the <code>ignoreClick</code> option is set,
clicking on one of the links inside the rows will
not toggle the associated checkboxes.
</p>
<p>
Code (<a class="toggle-code" href="#">hide</a>):
<pre class="prettyprint">$('#demo1 div.checkbox').shiftcheckbox({
// Options accept selectors, jQuery objects, or DOM
// elements.
checkboxSelector : ':checkbox',
selectAll : $('#demo1 .all'),
ignoreClick : 'a',
// The onChange function will be called whenever the
// plugin changes the state of a checkbox.
onChange : function(checked) {
setInfoText(
'Changed checkbox ' + $(this).attr('id')
+ ' to ' + checked + ' programmatically');
}
});
// If you also want to handle the user clicking on a
// checkbox, use the jQuery .change() event.
$('#demo1 :checkbox').change(function() {
setInfoText(
'Clicked checkbox ' + $(this).attr('id')
+ ', checked=' + this.checked);
});
</pre>
To disable the plugin:
<pre class="prettyprint">$('#demo1 div.checkbox, #demo1 .all').off('.shiftcheckbox');</pre>
</p>
<p id="demo1-link">Nothing interesting has happened yet</p>
<div class="all">
<input type="checkbox" id="all-1" />
<label for="all-1">Select all</label>
<label for="none">This is another label</label>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-1" />
<label for="cb-1-1">Demo 1 checkbox 1 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-2" />
<label for="cb-1-2">Demo 1 checkbox 2 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-3" />
<label for="cb-1-3">Demo 1 checkbox 3 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-4" />
<label for="cb-1-4">Demo 1 checkbox 4 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-5" />
<label for="cb-1-5">Demo 1 checkbox 5 label</label>
<a href="#test-5">test - this is a link within a row</a>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-6" />
<label for="cb-1-6">Demo 1 checkbox 6 label</label>
<a href="#test-6">test - this is a link within a row</a>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-7" />
<label for="cb-1-7">Demo 1 checkbox 7 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-8" />
<label for="cb-1-8">Demo 1 checkbox 8 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-9" />
<label for="cb-1-9">Demo 1 checkbox 9 label</label>
<span>test - this is some other text</span>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-10" />
<label for="cb-1-10">Demo 1 checkbox 10 label</label>
<label for="null">Another label</label>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-11" />
<label for="cb-1-11">Demo 1 checkbox 11 label</label>
<label for="whatever">Another label</label>
</div>
<div class="checkbox">
<input type="checkbox" id="cb-1-12" />
<label for="cb-1-12">Demo 1 checkbox 12 label</label>
<label for="null">Another label</label>
</div>
</div>
<h2>Demo 2 - Basic functionality</h2>
<div class="demo" id="demo2">
<p>
For this demo, only the checkboxes pick up the Shift+click events and
not the labels attached to them. For usability purposes, it is better
to wrap both the label and the checkbox in a row element and specify
the <code>checkboxSelector</code> option like the first demo does.
</p>
<p>
Code:
<pre class="prettyprint">$('#demo2 :checkbox').shiftcheckbox();
</pre>
To disable the plugin:
<pre class="prettyprint">$('#demo2 :checkbox').off('.shiftcheckbox');</pre>
</p>
<div>
<input type="checkbox" id="cb-2-1" />
<label for="cb-2-1">Demo 2 checkbox 1 label</label>
</div>
<div>
<input type="checkbox" id="cb-2-2" />
<label for="cb-2-2">Demo 2 checkbox 2 label</label>
</div>
<div>
<input type="checkbox" id="cb-2-3" />
<label for="cb-2-3">Demo 2 checkbox 3 label</label>
</div>
<div>
<input type="checkbox" id="cb-2-4" />
<span class="label">Demo 2 checkbox 4 text (not a label)</span>
</div>
<div>
<input type="checkbox" id="cb-2-5" />
<span class="label">Demo 2 checkbox 5 text (not a label)</span>
</div>
<div>
<input type="checkbox" id="cb-2-6" />
<label for="cb-2-6">Demo 2 checkbox 6 label</label>
</div>
<div>
<input type="checkbox" id="cb-2-7" />
<label for="cb-2-7">Demo 2 checkbox 7 label</label>
</div>
<div>
<input type="checkbox" id="cb-2-8" />
<label for="cb-2-8">Demo 2 checkbox 8 label</label>
</div>
<div>
<input type="checkbox" id="cb-2-9" />
<label for="cb-2-9">Demo 2 checkbox 9 label</label>
</div>
</div>
<h2>Demo 3 - Special cases</h2>
<div class="demo" id="demo3">
<p>
This demo tests a couple of special cases: labels that contain the
checkboxes they point to (whether or not they are row elements) and
select-all checkboxes and links inside and outside of row elements.
</p>
<p>
Code:
<pre class="prettyprint">$('#demo3 .row').shiftcheckbox({
checkboxSelector : ':checkbox',
selectAll : '#demo3 .all'
});
</pre>
To disable the plugin:
<pre class="prettyprint">$('#demo3 .row, #demo3 .all').off('.shiftcheckbox');</pre>
</p>
<input type="checkbox" class="all" />
<a class="all block-click" href="#demo3-all1">Select all 1</a>
<div class="row all">
<input type="checkbox" />
<a class="all block-click" href="#demo3-all2">Select all 2</a>
</div>
<div class="row">
<input type="checkbox" class="all" />
<a class="all block-click" href="#demo3-all3">Select all 3</a>
</div>
<div>
<label class="row" for="cb-3-1">
<input type="checkbox" id="cb-3-1" />
Demo 3 checkbox 1 label
</label>
</div>
<div>
<label class="row" for="cb-3-2">
<input type="checkbox" id="cb-3-2" />
Demo 3 checkbox 2 label
</label>
</div>
<div>
<label class="row" for="cb-3-3">
<input type="checkbox" id="cb-3-3" />
Demo 3 checkbox 3 label
</label>
</div>
<div class="row">
<label for="cb-3-4">
<input type="checkbox" id="cb-3-4" />
Demo 3 checkbox 4 label
</label>
</div>
<div class="row">
<label for="cb-3-5">
<input type="checkbox" id="cb-3-5" />
Demo 3 checkbox 5 label
</label>
</div>
<div class="row">
<label for="cb-3-6">
<input type="checkbox" id="cb-3-6" />
Demo 3 checkbox 6 label
</label>
</div>
</div>
</body>
</html>