-
Notifications
You must be signed in to change notification settings - Fork 85
/
index.html
503 lines (418 loc) · 18.8 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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Datepair.js – Demos and Documentation</title>
<meta name="description" content="A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar." />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.jonthornton.com/jquery-timepicker/jquery.timepicker.js"></script>
<link rel="stylesheet" type="text/css" href="https://www.jonthornton.com/jquery-timepicker/jquery.timepicker.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.standalone.css" />
<script src="lib/pikaday.js"></script>
<link rel="stylesheet" type="text/css" href="lib/pikaday.css" />
<script src="lib/jquery.ptTimeSelect.js"></script>
<link rel="stylesheet" type="text/css" href="lib/jquery.ptTimeSelect.css" />
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
<script src="lib/moment.min.js"></script>
<script src="lib/site.js"></script>
<link rel="stylesheet" type="text/css" href="lib/site.css" />
<script src="dist/datepair.js"></script>
<script src="dist/jquery.datepair.js"></script>
</head>
<body>
<header>
<h1><a href="https://github.com/jonthornton/jquery-datepair">Datepair.js</a></h1>
<p>
A javascript plugin for intelligently selecting date and time ranges<br />
inspired by Google Calendar. <br />
</p>
<ul id="header-links">
<li><a href="https://github.com/jonthornton/jquery-datepair#datepair-plugin-for-jquery">Documentation</a></li>
<li><a href="https://github.com/jonthornton/jquery-datepair">Source code on GitHub</a></li>
<li><a href="https://github.com/jonthornton/jquery-datepair/zipball/master">Download (zip)</a></li>
<li><a href="https://github.com/jonthornton/jquery-datepair/issues?state=open">Help</a></li>
</ul>
</header>
<section>
<p>Use this plugin to link date and time inputs when you need to select ranges. <br />No dependencies, with optional support for jQuery/Zepto.</p>
</section>
<section id="examples">
<article>
<div class="demo">
<h2>Basic Example</h2>
<p>Datepair.js doesn't include any date or time picker widgets, but it's preconfigured to work with <a href="https://github.com/jonthornton/jquery-timepicker">jquery-timepicker</a> and <a href="https://github.com/eternicode/bootstrap-datepicker">Bootstrap Datepicker</a>. Include input widgets as you normally would, and then use Datepair.js to link them.</p>
<p id="basicExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
</div>
<pre class="code" data-language="javascript">
<p id="basicExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
<!-- include input widgets; this is independent of Datepair.js -->
<link rel="stylesheet" type="text/css" href="jquery.timepicker.css" />
<link rel="stylesheet" type="text/css" href="bootstrap-datepicker.css" />
<script type="text/javascript" src="bootstrap-datepicker.js"></script>
<script type="text/javascript" src="jquery.timepicker.js"></script>
<script type="text/javascript" src="datepair.js"></script>
<script>
// initialize input widgets first
$('#basicExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#basicExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
// initialize datepair
var basicExampleEl = document.getElementById('basicExample');
var datepair = new Datepair(basicExampleEl);
</script>
</pre>
<script>
$('#basicExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#basicExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
var basicExampleEl = document.getElementById('basicExample');
var datepair = new Datepair(basicExampleEl);
</script>
</article>
<article>
<div class="demo">
<h2>jQuery Example</h2>
<p>Include the optional jquery.datepicker.js file to interact with Datepair.js with a jQuery interface.</p>
<p id="jqueryExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
</div>
<pre class="code" data-language="javascript">
<p id="jqueryExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
<script type="text/javascript" src="datepair.js"></script>
<script type="text/javascript" src="jquery.datepair.js"></script>
<script>
// initialize input widgets first
$('#jqueryExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#jqueryExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
// initialize datepair
$('#jqueryExample').datepair();
</script>
</pre>
<script>
$('#jqueryExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#jqueryExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
$('#jqueryExample').datepair();
</script>
</article>
<article>
<div class="demo">
<h2>Date-only Example</h2>
<p>You can use datepair with just dates, or just times.</p>
<p id="dateOnlyExample">
<input type="text" class="date start" /> to
<input type="text" class="date end" />
</p>
<p id="timeOnlyExample">
<input type="text" class="time start" /> to
<input type="text" class="time end" />
</p>
</div>
<pre class="code" data-language="javascript">
// HTML not shown for brevity
$('#timeOnlyExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
var timeOnlyExampleEl = document.getElementById('timeOnlyExample');
var timeOnlyDatepair = new Datepair(timeOnlyExampleEl);
$('#dateOnlyExample .date').datepicker({
'format': 'yyyy-m-d',
'autoclose': true
});
var dateOnlyExampleEl = document.getElementById('dateOnlyExample');
var dateOnlyDatepair = new Datepair(dateOnlyExampleEl);
</pre>
<script>
$('#timeOnlyExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
var timeOnlyExampleEl = document.getElementById('timeOnlyExample');
var timeOnlyDatepair = new Datepair(timeOnlyExampleEl);
$('#dateOnlyExample .date').datepicker({
'format': 'yyyy-m-d',
'autoclose': true
});
var dateOnlyExampleEl = document.getElementById('dateOnlyExample');
var dateOnlyDatepair = new Datepair(dateOnlyExampleEl);
</script>
</article>
<article>
<div class="demo">
<h2>Default Delta Example</h2>
<p>Datepair can automatically set the other input when a first value is selected.</p>
<p id="defaultDeltaExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
</div>
<pre class="code" data-language="javascript">
// HTML not shown for brevity
var defaultDeltaExampleEl = document.getElementById('defaultDeltaExample');
var defaultDeltaDatepair = new Datepair(defaultDeltaExampleEl, {
'defaultDateDelta': 1, // days
'defaultTimeDelta': 7200000 // milliseconds
});
</pre>
<script>
$('#defaultDeltaExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#defaultDeltaExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
var defaultDeltaExampleEl = document.getElementById('defaultDeltaExample');
var defaultDeltaDatepair = new Datepair(defaultDeltaExampleEl, {
'defaultDateDelta': 1,
'defaultTimeDelta': 7200000
});
</script>
</article>
<article>
<div class="demo">
<h2>Alternate UI Widgets Example</h2>
<p>jquery-datepair is widget agnostic and can work with any date and time pickers. Here's an example with <a href="http://pttimeselect.sourceforge.net/example/index.html">jQuery.ptTimeSelect</a> and <a href="https://github.com/dbushell/Pikaday">Pikaday</a>.</p>
<p id="alternateUiWidgetsExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to<br />
<input type="text" class="date end" />
<input type="text" class="time end" />
</p>
</div>
<pre class="code" data-language="javascript">
<p id="alternateUiWidgetsExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to<br />
<input type="text" class="date end" />
<input type="text" class="time end" />
</p>
<script type="text/javascript" src="pikaday.js"></script>
<script type="text/javascript" src="jquery.ptTimeSelect.js"></script>
<script type="text/javascript" src="moment.js"></script>
<script>
// initialize input widgets
// ptTimeSelect doesn't trigger change event by default
$('#alternateUiWidgetsExample .time').ptTimeSelect({
'onClose': function($self) {
$self.trigger('change');
}
});
$('#alternateUiWidgetsExample .date').pikaday();
var TIMEFORMAT = 'h:mm a';
var alternateUiWidgetsExampleEl = document.getElementById('alternateUiWidgetsExample');
var alternateWidgetsDatepair = new Datepair(alternateUiWidgetsExampleEl, {
parseTime: function(input){
// use moment.js to parse time
var m = moment(input.value, TIMEFORMAT);
return m.toDate();
},
updateTime: function(input, dateObj){
var m = moment(dateObj);
input.value = m.format(TIMEFORMAT);
},
parseDate: function(input){
var picker = $(input).data('pikaday');
return picker.getDate();
},
updateDate: function(input, dateObj){
var picker = $(input).data('pikaday');
return picker.setDate(dateObj);
}
});
</script>
</pre>
<script>
// initialize input widgets
// ptTimeSelect doesn't trigger change event by default
$('#alternateUiWidgetsExample .time').ptTimeSelect({
'onClose': function($self) {
$self.trigger('change');
}
});
$('#alternateUiWidgetsExample .date').pikaday();
var TIMEFORMAT = 'h:mm a';
var alternateUiWidgetsExampleEl = document.getElementById('alternateUiWidgetsExample');
var alternateWidgetsDatepair = new Datepair(alternateUiWidgetsExampleEl, {
parseTime: function(input){
// use moment.js to parse time
var m = moment(input.value, TIMEFORMAT);
return m.toDate();
},
updateTime: function(input, dateObj){
var m = moment(dateObj);
input.value = m.format(TIMEFORMAT);
},
parseDate: function(input){
var picker = $(input).data('pikaday');
return picker.getDate();
},
updateDate: function(input, dateObj){
var picker = $(input).data('pikaday');
return picker.setDate(dateObj);
}
});
</script>
</article>
<article>
<div class="demo">
<h2>Events Example</h2>
<p>Datepair fires several events to indicate the status of the inputs.</p>
<p id="eventsExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
<p id="eventsExampleStatus"></p>
</div>
<pre class="code" data-language="javascript">
// HTML not shown for brevity
// initialize input widgets first
$('#eventsExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#eventsExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
var eventsExampleEl = document.getElementById('eventsExample');
var eventsExampleDatepair = new Datepair(eventsExampleEl);
// some sample handlers
$('#eventsExample').on('rangeSelected', function(){
$('#eventsExampleStatus').text('Valid range selected');
}).on('rangeIncomplete', function(){
$('#eventsExampleStatus').text('Incomplete range');
}).on('rangeError', function(){
$('#eventsExampleStatus').text('Invalid range');
});
</pre>
<script>
$('#eventsExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#eventsExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
var eventsExampleEl = document.getElementById('eventsExample');
var eventsExampleDatepair = new Datepair(eventsExampleEl);
$('#eventsExample').on('rangeSelected', function(){
$('#eventsExampleStatus').text('Valid range selected');
}).on('rangeIncomplete', function(){
$('#eventsExampleStatus').text('Incomplete range');
}).on('rangeError', function(){
$('#eventsExampleStatus').text('Invalid range');
});
</script>
</article>
<article>
<div class="demo">
<h2>Anchor Example</h2>
<p>Datepair defaults to move the end time/date based on changes to the start time/date. This can be changed to the end inputs, or disabled completely.</p>
<p>Anchor:
<select id="anchorSelect">
<option value="start">Start</option>
<option value="end">End</option>
<option value="">Null</option>
</select>
</p>
<p id="anchorExample">
<input type="text" class="date start" />
<input type="text" class="time start" /> to
<input type="text" class="time end" />
<input type="text" class="date end" />
</p>
</div>
<pre class="code" data-language="javascript">
var anchorExampleEl = document.getElementById('anchorExample');
var anchorDatepair = new Datepair(anchorExampleEl, {
anchor: $('#anchorSelect').val()
});
$('#anchorSelect').on('change', function(){
anchorDatepair.option('anchor', $('#anchorSelect').val());
});
</pre>
<script>
$('#anchorExample .time').timepicker({
'showDuration': true,
'timeFormat': 'g:ia'
});
$('#anchorExample .date').datepicker({
'format': 'm/d/yyyy',
'autoclose': true
});
var anchorExampleEl = document.getElementById('anchorExample');
var anchorDatepair = new Datepair(anchorExampleEl, {
anchor: $('#anchorSelect').val()
});
$('#anchorSelect').on('change', function(){
anchorDatepair.option('anchor', $('#anchorSelect').val());
});
</script>
</article>
</section>
<section>
<h2>Need Help?</h2>
<p>Check <a href="https://github.com/jonthornton/jquery-datepair#datepair-plugin-for-jquery">the documenation</a> or <a href="https://github.com/jonthornton/jquery-datepair/issues?state=open">submit an issue</a> on GitHub.</p>
</section>
<footer>
<p>© 2014 <a href="https://jonthornton.com">Jon Thornton</a></p>
</footer>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-15605525-4', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>