forked from jockmac22/foundation_calendar_date_time_picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
653 lines (533 loc) · 21.7 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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<html>
<head>
<title>Calendar: A date and time picker for the Foundation CSS Framework</title>
<!-- Make sure you have the foundation base, and icons (v3) CSS -->
<link rel="stylesheet" type="text/css" href="foundation/foundation.css" />
<link rel="stylesheet" type="text/css" href="foundation-icon-fonts-3/foundation-icons.css" />
<!-- Add the foundation calendar CSS -->
<link rel="stylesheet" type="text/css" href="foundation_calendar.css" />
<!-- Make sure you have jQuery, date.js loading properly -->
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript" src="foundation/foundation.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$(document).foundation();
});
</script>
<script type="text/javascript" src="js/date.js" ></script>
<!-- Add the foundation calendar Javascript -->
<script type="text/javascript" src="foundation_calendar.js" ></script>
<script type="text/javascript" src="helpers/date-helpers.js" ></script>
<script type="text/javascript" src="helpers/string-helpers.js" ></script>
<style type="text/css">
label {
margin-top: 20px;
}
code {
font-size: 14px;
}
.row {
margin-bottom: 20px;
}
.header {
border-bottom: 1px solid #333;
}
dl dt {
display: inline-block;
width: 18%;
margin-right: 1%;
vertical-align: top;
}
dl dd {
display: inline-block;
width: 79%;
vertical-align: top;
}
</style>
</head>
<body>
<div class="fixed">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1><a href="#"><i class="fi-calendar"></i> Calendar</a></h1>
</li>
</ul>
<section class="top-bar-section">
<!-- Left Nav Section -->
<ul class="left">
<li class="has-dropdown">
<a href="#basicsetup">Basic Setup</a>
<ul class="dropdown">
<li><a href="#datetime">Date & Time</a></li>
<li><a href="#date">Date</a></li>
<li><a href="#time">Time</a></li>
</ul>
</li>
<li class="has-dropdown">
<a href="#displayformats">Display Formats</a>
<ul class="dropdown">
<li><a href="#dateformat">Date Format</a></li>
<li><a href="#timeformat">Time Format</a></li>
</ul>
</li>
<li class="has-dropdown">
<a href="#values">Values</a>
<ul class="dropdown">
<li><a href="#intialvalue">Initial Value</a></li>
<li><a href="#valueformat">Value Format</a></li>
<li><a href="#utcoffset">UTC Offset</a></li>
</ul>
</li>
<li class="has-dropdown">
<a href="#fixeddisplays">Fixed Displays</a>
<ul class="dropdown">
<li><a href="#fixedcalendar">Fixed Calendar</a></li>
</ul>
</li>
<li class="has-dropdown">
<a href="#events">Events</a>
<ul class="dropdown">
<li><a href="#events">monthChange</a></li>
<li><a href="#events">monthPrev</a></li>
<li><a href="#events">monthNext</a></li>
<li><a href="#events">dateChange</a></li>
<li><a href="#events">timeChange</a></li>
</ul>
</li>
<li class="has-dropdown">
<a href="#customizebehaviors">Customize Behaviors</a>
<ul class="dropdown">
<li><a href="#dateisclickable">dateIsClickable</a></li>
<li><a href="#buildothermonthdayui">buildOtherMonthDayUI</a></li>
<li><a href="#builddayui">buildDayUI</a></li>
</ul>
</li>
</ul>
</section>
</nav>
</div>
<a name="basicsetup"></a>
<div class="row">
<div class="small-12 columns">
<h1><i class="fi-calendar"></i> Calendar <small class="show-for-large-only" style="margin-top:20px;">A date and time picker for the Foundation CSS framework</small></h1>
<p class="hide-for-large-only">A date and time picker for the Foundation CSS framework</p>
</div>
</div>
<a name="datetime"></a>
<div class="row">
<div class="small-12 columns">
<h3 class="header" data-magellan-destination="basicsetup">Basic Setup</h3>
</div>
</div>
<a name="date"></a>
<div class="row">
<div class="medium-12 large-8 columns">
<h3>Date & Time</h3>
<p>The calendar is setup through unobtrusive javascript. All you have to do is add a parameter to the input field, and voila, you have a date/time picker:</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time />
</code>
</div>
</div>
<a name="time"></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-2">
<h3>Date Only</h3>
<p>The calendar is setup through unobtrusive javascript. All you have to do is add a parameter to the input field, and voila, you have a date/time picker:</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date />
</code>
</div>
</div>
<a name="displayformats"></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-4">
<h3>Time Only</h3>
<p>The calendar is setup through unobtrusive javascript. All you have to do is add a parameter to the input field, and voila, you have a date/time picker:</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-time />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-time />
</code>
</div>
</div>
<a name="dateformat"></a>
<div class="row">
<div class="small-12 columns">
<a name="displayformats"></a>
<h3 class="header" data-magellan-destination="displayformats">Display Formats</h3>
<p>The display format strings are based on a modified set of the Ruby 'strftime' formatting conventions. <a href="http://apidock.com/ruby/DateTime/strftime" target="_blank">Here's a list of the formatting options.</a></p>
<p>Display formats are provided to each instance by providing the input with <strong>data-date-format</strong> and <strong>data-time-format</strong> parameters, respectively.</p>
</div>
</div>
<a name="timeformat"></a>
<div class="row">
<div class="medium-12 large-8 columns">
<h3>Date Format</h3>
<p>The date format for the display can be specified using the <strong>data-date-format</strong> parameter. Like so:</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time data-date-format="%m/%d/%Y" />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time data-date-format="%m/%d/%Y" />
</code>
</div>
</div>
<a name="values"></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-4">
<h3>Time Format</h3>
<p>The date format for the display can be specified using the <strong>data-time-format</strong> parameter. Like so:</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time data-time-format="%H:%M:%S" />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time data-time-format="%H:%M:%S" />
</code>
</div>
</div>
<a name="initialvalue"></a>
<div class="row">
<div class="small-12 columns">
<h2 class="header">Values</h2>
<p>You can fully manage the values that are set and generated by the UI as well. This will allow you to provide a value, modify it, and return to the system in a format that is appropriate.</p>
</div>
</div>
<a name="valueformat"></a>
<div class="row">
<div class="medium-12 large-8 columns">
<h3>Initial Value</h3>
<p>You can set the initial value for the field, using the standard input <strong>value</strong> parameter. The value should be provided in a format that Javascript can parse, the suggested format is <strong>YYYY-MM-DD HH:MM:SS</strong>. Like so:</a></p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time value="1977-07-06 14:32:01" />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time value="1977-07-06 14:32:01" />
</code>
</div>
</div>
<a name="allownullblank"></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-2">
<h3>Value Format</h3>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time data-value-format="%Y/%m/%d %H:%M:%S" />
<button class="small radius" style="margin-top: 10px;" onClick="alert(jQuery(this).parent().find('input').val());return false;" >Show the value</button>
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time data-value-format="%Y-%m-%dT%H:%M:%S" />
</code>
</div>
</div>
<a name="utcoffset"></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-4">
<h3>Allow Null/Blank Values</h3>
<p>All of the implementations so far, require a value to exist, or a default value is implied. This doesn't allow you to remove a value should you want to inject a null value for a field.</p>
<p>To allow a field to be set to null, all you need to do is set the <strong>data-nullable</strong> parameter in the input field. This will provide a button that will clear the field. Like so:</p>
<div class="row" style="margin-bottom: 10px;">
<div class="small-12 medium-8 large-12 columns medium-centered">
<label>Initial value: 1977-07-06 14:32:01</label>
<input type="text" data-date-time data-nullable value="1977-07-06 14:32:01" />
</div>
</div>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<label>Initial value: null</label>
<input type="text" data-date-time data-nullable />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time data-nullable value="1977-07-06 14:32:01" />
<input type="text" data-date-time data-nullable />
</code>
</div>
</div>
<a name="fixeddisplays"></a>
<div class="row">
<div class="medium-12 large-8 columns">
<h3>UTC Offset</h3>
<p>Assuming that the current time is UTC, you can assign an offset value so that the display will update accordingly. In the current example, the current UTC time is <script>document.write(new Date().format("%H:%M:%S"));</script>. Our offset is set to -7 hours (US Mountain Time), so the displayed time is minus 7 hours.</p>
<p>If you change the time, and then click the "Show the value" button, you will see that the stored value is actually in the calculated UTC time.</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time data-utc-offset="-7" />
<button class="small radius" style="margin-top: 10px;" onClick="alert(jQuery(this).parent().find('input').val());return false;" >Show the value</button>
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time data-utc-offset="-7" />
</code>
<br />
<br />
<p>If you assign a UTC offset, and a value to the field, it will assume that provided value is UTC, and perform the calculations from there.</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input type="text" data-date-time data-utc-offset="-7" value="1977-07-06 21:32:01" />
<button class="small radius" style="margin-top: 10px;" onClick="alert(jQuery(this).parent().find('input').val());return false;" >Show the value</button>
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date-time data-utc-offset="-7" value="1977-07-06 21:32:01" />
</code>
</div>
</div>
<a name="fixedcalendar"></a>
<div class="row">
<div class="small-12 columns">
<h2 class="header">Fixed Displays</h2>
<p>If you want the calendar or time picker to display as the UI itself, then you can append the data-fixed parameter to the input.</p>
</div>
</div>
<a name="events"></a>
<div class="row">
<div class="medium-12 large-8 columns">
<h3>Fixed Calendar</h3>
<p>The calendar can be used as the UI element by specifying the fixed-calendar parameter in the input field:</p>
<div class="row">
<div class="small-12 medium-6 large-6 columns">
<input type="text" data-date data-fixed />
</div>
</div>
<label>Code:</label>
<code>
<input type="text" data-date data-fixed />
</code>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<h2 class="header">Events</h2>
<p>If you want to trigger your own custom javascript when the date/time pickers are manipulated you can bind events to the date input to respond accordingly.</p>
<p>The date/time picker below is wired up to respond to the following events:</p>
<h5>Date Events</h5>
<dl>
<dt>monthChange</dt>
<dd>Triggered when a month is changed to previous or next</dd>
<dt>monthPrev</dt>
<dd>Triggered when the previous month is selected</dd>
<dt>monthNext</dt>
<dd>Triggered when the next month is selected</dd>
<dt>dateChange</dt>
<dd>Triggered when the specific date is changed</dd>
</dl>
<h5>Time Events</h5>
<dl>
<dt>timeChange</dt>
<dd>Triggered when the time is changed.</dd>
</dl>
<a name="customizebehaviors"></a>
<p>Here's the code that implements the date/time picker (Check the console for output)</p>
<code>
<input id="eventCalendar" type="text" data-date-time />
</code>
<input id="eventCalendar" type="text" data-date-time />
<p>We can wire up the events with code similar to the following implementation:</p>
<code>
<pre>
$(document).ready(function() {
$('#eventCalendar').bind('monthChange', function(evt, opts) {
console.info('monthChange triggered');
console.info(opts);
});
});
</pre>
</code>
<script type="text/javascript">
$(document).ready(function(evt) {
var eventCal = $('#eventCalendar');
eventCal.bind('monthChange', function(evt, opts) {
console.info('monthChange triggered');
console.info(opts);
});
eventCal.bind('monthPrev', function(evt, opts) {
console.info('monthPrev triggered');
console.info(opts);
});
eventCal.bind('monthNext', function(evt, opts) {
console.info('monthNext triggered');
console.info(opts);
});
eventCal.bind('dateChange', function(evt, opts) {
console.info('dateChange triggered');
console.info(opts);
});
eventCal.bind('timeChange', function(evt, opts) {
console.info('timeChange triggered');
console.info(opts);
});
});
</script>
</div>
</div>
<a name="dateisclickable"></a>
<div class="row">
<div class="small-12 columns">
<h2 class="header">Customized Behaviors</h2>
<p>If you want to customize how the calendar is drawn, you can bind behaviors to several of the build cycle steps.</p>
<p>Every behavior has a default method for handling its output, however if you bind to a behavior you can override the response and generate a highly customized interface for the Calendar UI. (<strong>NOTE:</strong> This currently only applies to the date picker UI, time picker behaviors haven't been implemented yet.)</p>
<p>The behaviors each have a stack of methods that are called in the order they are bound. Each call receives the options for the current calendar, any additional options that may need to be specified, and the response from the previous call.</p>
<p>Each bound behavior can build off of the response from the previous call, or generate a completely new response based your needs. Binding a behavior looks something like this:</p>
<pre><code>
<script type="text/javascript">
$('#someCalendarInput').fdcp('bindBehavior', 'someBehavior', function(opts, addl_opts, response) {
...
return someResponse;
});
</script>
</code></pre>
<p>This code will bind the behavior 'someBehavior' to the calendar that was build around the input with id 'someCalendarInput', and add the specified function to the stack for that behavior.</p>
<p>The function call accepts three arguments:</p>
<dl>
<dt>opts</dt>
<dd>The options for the specified calendar implementation</dd>
<dt>addl_opts</dt>
<dd>Any additional options that may need to be specified for the identified behavior</dd>
<dt>response</dt>
<dd>The response from the previous call in the behavior stack, this is initialized as null</dd>
</dl>
<p>The function should return a response value in accordance with the behavior being bound to</p>
</div>
</div>
<a name="buildothermonthdayui"></a>
<div class="row">
<div class="medium-12 large-8 columns">
<h3>dateIsClickable</h3>
<p>This behavior allows you to modify whether or not an individual day in the week is presented as clickable or not.</p>
<p>The example code below makes all weekend days not clickable</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input id="behaviorExample1" type="text" data-date-time data-fixed />
</div>
</div>
<label>Code:</label>
<pre><code>
<script type="text/javascript">
$('#behaviorExample1').fcdp('bindBehavior', 'dateIsClickable', function(opts, addl_opts, response) {
// Check to see if we are rendering the dateIsClickable calendar input
return !addl_opts.is_weekend;
});
</script>
</code></pre>
<script type="text/javascript">
$('#behaviorExample1').fcdp('bindBehavior', 'dateIsClickable', function(opts, addl_opts, response) {
// Check to see if we are rendering the dateIsClickable calendar input
return !addl_opts.is_weekend;
});
</script>
</div>
</div>
<a name="builddayui"></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-2">
<h3>buildOtherMonthDayUI</h3>
<p>This behaviors allows you to modify how days from the previous or following months are rendered to the the display.</p>
<p>The example code below displays all of the days from the previous and next month without their numbers.</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input id="behaviorExample2" type="text" data-date-time data-fixed />
</div>
</div>
<label>Code:</label>
<pre><code>
<script type="text/javascript">
$('#behaviorExample2').fcdp('bindBehavior', 'buildOtherMonthDayUI', function(opts, addl_opts, response) {
var clazz = "day other-month" + (addl_opts.is_weekend ? " weekend" : "");
return $('<div class="' + clazz + '"></div>');
});
</script>
</code></pre>
<script type="text/javascript">
$('#behaviorExample2').fcdp('bindBehavior', 'buildOtherMonthDayUI', function(opts, addl_opts, response) {
var clazz = "day other-month" + (addl_opts.is_weekend ? " weekend" : "");
return $('<div class="' + clazz + '"></div>');
});
</script>
</div>
</div>
<a name=""></a>
<div class="row">
<div class="medium-12 large-8 columns large-offset-4">
<h3>buildDayUI</h3>
<code>$.fcdp.functions.buildDayUI = function(opts, day_opts) { ... }</code><br /><br />
<dl>
<dt>opts</dt>
<dd>The list of options set for the given calendar object.</dd>
<dt>day_opts</dt>
<dd>This list of options set for the current day in the calendar build cycle. If you output the contents of this object to the console, you will see the values provided.</dd>
<dt><i>returns</i></dt>
<dd>A string or jQuery selector containing the HTML content to be rendered.</dd>
</dl>
<p>This method allows you to modify how days from the current month are rendered to the the display.</p>
<p>The example code below replaces the numbers for Wednesday with a star icon.</p>
<div class="row">
<div class="small-12 medium-8 large-12 columns medium-centered">
<input id="behaviorExample3" type="text" data-date-time data-fixed />
</div>
</div>
<script type="text/javascript">
$('#behaviorExample3').fcdp('bindBehavior', 'buildDayUI', function(opts, addl_opts, response) {
var clazz = "day" + (addl_opts.is_weekend ? " weekend" : "") + (addl_opts.is_current ? " current" : "");
var day_content = (addl_opts.weekday_num == 3 ? '<i class="fi-star"></i>' : addl_opts.day_number);
var response = false;
if (addl_opts.is_clickable) {
response = '<a href="#' + addl_opts.day_number + '" class="' + clazz + '" data-date="' + addl_opts.date.format() + '">' + day_content + '</a>';
} else {
response = '<span class="' + clazz + '" data-date="' + addl_opts.date.format() + '">' + day_content + '</span>';
}
return response;
});
</script>
<label>Code:</label>
<pre><code>
<code>
<script type="text/javascript">
$('#behaviorExample3').fcdp('bindBehavior', 'buildDayUI', function(opts, addl_opts, response) {
var clazz = "day" + (addl_opts.is_weekend ? " weekend" : "") + (addl_opts.is_current ? " current" : "");
var day_content = (addl_opts.weekday_num == 3 ? '<i class="fi-star"></i>' : addl_opts.day_number);
var response = false;
if (addl_opts.is_clickable) {
response = '<a href="#' + addl_opts.day_number + '" class="' + clazz + '" data-date="' + addl_opts.date.format() + '">' + day_content + '</a>';
} else {
response = '<span class="' + clazz + '" data-date="' + addl_opts.date.format() + '">' + day_content + '</span>';
}
return response;
});
</script>
</code></pre>
</div>
</div>
</body>
</head>