-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
641 lines (563 loc) · 25.3 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="Description" content="tinyCalendar is a small (10.0KB, 4.5KB gZip) but very advanced jQuery date picker" />
<meta name="Keywords" content="date, date picker, calendar" />
<meta name="author" content="Peter Dematté" />
<meta http-equiv="language" content="en" />
<link rel="shortcut icon" type="image/x-icon" href="development/favicon.ico">
<link rel="icon" type="image/x-icon" href="development/favicon.ico">
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="datePicker.css">
<link rel="stylesheet" type="text/css" href="demo/demo.css">
<!-- following stylesheets are only for demos with calendar.js -->
<link rel="stylesheet" type="text/css" href="demo/month.css">
<link rel="stylesheet" type="text/css" href="demo/week.css">
<link rel="stylesheet" type="text/css" href="demo/flight.css">
<title>tiny date picker</title>
</head>
<body>
<div id="content-wrapper">
<h1>Tiny date/time picker</h1>
<p>Looking for tiny foot print, fast, scaleable, flexible and pluggable...<br>
This <strong>5KB</strong> (gZip; 12.5KB minified) small date/time picker provides a lot of hooks for developers to write calendars, agendas, booking systems, plugins, etc. (See demos below in <a href="#demo">Demo</a>). The flexibility of this tool makes integration of bootstrap or other frameworks easy.</p>
<a name="demo" id="demo" class="a-inline"></a>
<h2>Demo</h2>
<p>On all elements with className 'date':</p>
<pre>new DatePicker('.date', options);</pre> or
<pre>$('.date').datePicker(options);</pre>
<p></p>
<div class="input-toggles">
<input class="date date-1" value="2016-06-23" readonly="" />
<input class="date date-1" value="2016-06-23 11:30 PM" />
<input class="date date-1" value="2016-05-10" data-mindate="2016-05-10" data-maxdate="2017-12-31" />
<input class="date date-1" value="1969-12-28" />
<input class="date date-1" value="2016-08" />
<input class="date date-1" value="11:30 PM" />
<br><span>Range: </span>
<input class="date date-1" value="" data-from="theFlight" placeholder="YYYY-MM-DD HH:MM APM" data-timeformat="HH:MM PM" />
<input class="date date-1" value="" data-to="theFlight" placeholder="YYYY-MM-DD HH:MM APM" data-timeformat="HH:MM PM" />
<br><span>Range (name based): </span>
<input class="date date-1" value="" name="flight-from" data-from="flight-to" placeholder="YYYY-MM-DD" />
<input class="date date-1" value="" name="flight-to" data-to="flight-from" placeholder="YYYY-MM-DD" />
<br><span>Range with marked range: </span>
<input class="date date-11" value="" name="flight-from-1" data-from="flight-to-1" placeholder="YYYY-MM-DD" />
<input class="date date-11" value="" name="flight-to-1" data-to="flight-from-1" placeholder="YYYY-MM-DD" />
<div>Different month/year selector:
<input class="date date-111" value="" placeholder="YYYY-MM-DD" readonly="" data-mindate="2015-05-10" data-maxdate="2037-11-31" />
</div>
<div>Remote button and hidden input:
<input class="date" value="" placeholder="YYYY-MM-DD" readonly="" />
<input class="date" type="hidden" value="2016-06-23" />
<button class="date-2 button">datePicker</button>
</div>
<div>... and split inputs:
<input class="date-year" value="" placeholder="YYYY" readonly="" />-
<input class="date-month" value="" placeholder="MM" readonly="" />-
<input class="date-day" value="" placeholder="DD" readonly="" />
<input class="date" type="hidden" value="2016-06-23" />
<button class="date-3 button">datePicker</button>
</div>
<div>Empty time only picker:
<input class="date date-1" value="" data-type="time" placeholder="HH:MM:SS" />
</div>
<p>TIP: The values don't have to be stored in hidden variables, they can also be received and stored in local storage or javascript variables (inspect window.dates), or let an MVC framework do the job:</p>
<div>
<input class="date date-4" value="" data-date="date-1" />
<input class="date date-4" value="" data-date="date-2" />
<input class="date date-4" value="" data-date="date-3" />
</div>
<p>Simpler markup (DIV based):</p>
<div>
<input class="date date-5" value="" />
</div>
<p>Today, clear and close button. Stays open on select:</p>
<div>
<input class="date date-6" value="2016-06-23" />
</div>
</div>
<p>Find a clean demos here: <a href="./themes/white/">./themes/white/index.html</a> or <a href="./themes/naked/">./themes/naked/index.html</a></p>
<h2>Usage</h2>
<p>For the plain javascript version you need the following:</p>
<pre style="display: block; overflow: auto;">
<script type="text/javascript" src="datePicker.min.js">
<script type="text/javascript">
var myDP = new DatePicker('.date', options); // first arg. can also be ElementCollection/Array or $()
</script></pre>
<p>...or for the jQuery version:</p>
<pre style="display: block; overflow: auto;">
<script type="text/javascript" src="jqDatePicker.min.js">
<script type="text/javascript">
$('.color').datePicker(options); // that's it
</script></pre>
<p>For more information on API, callbacks, etc. see: <a class="a-inline" href="https://github.com/PitPik/tinyDatePicker">github.com/PitPik/tinyDatePicker</a></p>
<h2>calendar.js</h2>
<p>Calendar is a tiny module (1.7KB gZip; 3.57KB minified), used in datePicker.js, that can render a month or only a week. It has a lot of options and callbacks that make rendering of complex data easy. See the following demos for what can be done with Calendar:</p>
</div>
<a class="a-inline" href="https://github.com/PitPik/tinyDatePicker"><img style="position: absolute; top: 0; right: 0; border: 0;" src="development/fmog.png" alt="Fork me on GitHub"></a>
<script type="text/javascript" src="demo/events.js"></script>
<!-- <script type="text/javascript" src="datePicker.min.js"></script> -->
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript" src="datePicker.js"></script>
<script type="text/javascript">
'use strict';
// used in demos later on to merge default options with demo options...
function extend(a, b) { // extend a with properties of b not in a; simple version
for(var key in b) {
if(!a.hasOwnProperty(key)) {
a[key] = b[key];
}
}
return a;
}
/**
* returns a string used in <input> fields to mark the min date
* for one of the range demos...
*
* @return {String} String of date in format 'YYYY-MM-DD'
*/
var getTodayString = function() {
var today = new Date();
return today.getFullYear() + '-' +
((today.getMonth() + 1) + '').replace(/^(\d)$/, '0$1') + '-' +
(today.getDate() + '').replace(/^(\d)$/, '0$1');
};
/**
* The following options are for demos from datePicker
* these options render events, today icon and icons for
* the amount of events per day (excl 'disabled'), etc.
* Will be used in all other examples as well (extendet).
*/
var options = {
weekDays: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
sundayBased: false,
renderWeekNo: true,
equalHight: true,
events: events, // external data... see events.js
template: {
row: '<td class=""><span class=""{{event}} data-day=\'{"day":"{{day}}", "month":"{{month}}", "year":"{{year}}"}\'>{{day-event}}{{today}}</span></td>',
/**
* rendering events, replacing {{event}} in template.row
*/
event: function(day, date, event) {
var text = [],
uuids = [],
someExtra = '';
for (var n = 0, m = event.length; n < m; n++) {
event[n].text && text.push('- ' + event[n].text);
uuids.push(event[n]._id);
if (event[n].extra) { // extend functionality...
someExtra = event[n].extra;
}
}
text = text.join("\n");
return text ? ' title="' + text + '"' +
' data-uuids=\'[' + uuids.join(', ') + ']\'' +
(someExtra ? ' data-name="' + someExtra + '"' : '') : '';
},
/**
* rendering today; just for fun..., replacing {{today}} in template.row
*/
today: function(day, date) {
return '<span class="today-icon">+</span>';
},
/**
* rendering every day, replacing {{day-event}} in template.row
*/
day: function(day, date, event) {
var length = event.length;
for (var n = length; n--; ) { // check if it's only a 'disabled' event
if (event[n].type && event[n].type === 'disabled') { // or event[n].disabled
length--;
}
}
if (length > 1) {
return day + '<span class="count-icon">' + length + '</span>';
}
}
},
/**
* Some testings for input with no value but it should be time only picker...
* @param {[type]} element [description]
* @return {String} The value of the input field
*/
readValue: function(element) {
if (!element.value && element.getAttribute('data-type') === 'time') { // initial time if empty
return new Date().toTimeString().split(' ')[0]; // triggers default behavior
}
return element.value; // triggers default behavior
}
},
/**
* Can be used in options.renderCallback;
* Call like: funcName.call(this, container, element, toggled);
* Adds a class name options.rangeClass or 'range' to days in calender that define a range
*
* @param {Element} container The datePicker container
* @param {Element} element The current input field (or other trigger element)
* @param {Boolean} toggled Toggle indicator of datePicker (see API docu)
*/
markRangeDays = function(container, element, toggled) {
var calOptions = this.calendar.options,
value_1 = +this.currentInput.value.split(' ')[0].replace(/-/g, ''),
value_2 = this.currentPartner &&
+this.currentPartner.value.split(' ')[0].replace(/-/g, ''),
dates = container.querySelectorAll( // get all displayed days
'.' + calOptions.prevMonthClass + ', ' +
'.' + calOptions.nextMonthClass + ', ' +
'.' + calOptions.currentMonthClass),
data = '';
if (this.isOpen && toggled !== undefined && value_2) {
for (var n = 0, m = dates.length; n < m; n++) {
if (data = dates[n].getAttribute(this.options.pickerAttribute)) {
data = +data.replace(/-(\d)(?=(?:-|$))/g, '0$1').replace(/-/g, '');
if (value_1 && value_2 && value_1 !== value_2 && (
(value_1 <= data && value_2 >= data) ||
(value_1 >= data && value_2 <= data))) {
dates[n].className += ' ' + (this.options.rangeClass || 'range') +
(value_1 === data || value_2 === data ? ' range-' +
(value_1 >= data && value_2 >= data? 'begin' : 'end') : '');
}
}
}
}
},
/**
* Can be used in options.renderCallback;
* Call like: funcName.call(this, container, element, toggled);
* Renders 3 buttons to the end of datePicker with event listener for
* clearing the input, jumping to today and for closing the date picker.
* Adds 'disabled' attribute in case they can't be used (hide in CSS).
* Uses options.clearText, options.todayText and options.closeText (optional).
* Today button has an attribute data-picker="", so it works like day in calender
* where click event is picked up internaly.
*
* @param {[type]} container [description]
* @param {[type]} element [description]
* @param {[type]} toggled [description]
* @return {[type]} [description]
*/
addButtons = function(container, element, toggled) {
var _today = new Date(),
today = _today.getFullYear() + '-' + (_today.getMonth() + 1) + '-' + _today.getDate(),
date = this.date.year + '-' + +this.date.month + '-' + +this.date.day,
isFrom = element.hasAttribute(this.options.rangeStartAttribute),
isRange = this.currentPartner,
value_2 = isRange && +this.currentPartner.value.split(' ')[0].replace(/-/g, ''),
minDate = +(element.getAttribute(this.options.minDateAttribute) || this.options.minDate).replace(/-/g, ''),
maxDate = +(element.getAttribute(this.options.maxDateAttribute) || this.options.maxDate).replace(/-/g, ''),
_today = +today.replace(/-(\d)(?=(?:-|$))/g, '0$1').replace(/-/g, ''),
todayPossible = (today !== date || !element.value) && minDate <= _today && _today <= maxDate && (
isRange ? (isFrom ? !value_2 || value_2 >= _today : !value_2 || value_2 <= _today) : true);
this.isOpen && toggled !== undefined && container.insertAdjacentHTML('beforeend', // render buttons...
'<div class="dp-footer">' +
'<button class="action clear"' + (this.currentInput.value ? '' : ' disabled') +
' type="button">' + (this.options.clearText || 'clear') + '</button>' +
'<button class="action today"' + (todayPossible ? '' : ' disabled') +
' data-picker="' + today + '" type="button">' + (this.options.todayText || 'today') + '</button>' +
'<button class="action close" type="button">' + (this.options.closeText || 'close') + '</button>' +
'</div>');
this._hasListeners = this._hasListeners || (function(_this) { // ...and add event listeners (once)
container.addEventListener('click', function(e) {
var target = e.target,
className = target.className;
if (/action/.test(className)) {
if (/close/.test(className)) {
_this.toggle();
} else if (/clear/.test(className)) {
_this.currentInput.value = '';
_this.toggle(true);
}
}
});
return true; // make this._hasListeners true for next call of renderCallback
})(this);
};
// ------------------- DEMO for input.date-1 ------------------ //
// Regular example that enables all kinds of different formats
// and ranges and demonstrates the default possibilities of
// datePicker... (except extra features defined in default options)
// ------------------------------------------------------------ //
window.myDatePicker_1 = new DatePicker('.date-1', options);
// ------------------- DEMO for input.date-11 ----------------- //
// Example with marked range days.
// ------------------------------------------------------------ //
// first set input fields to a minimum date
[].map.call(document.querySelectorAll('.date-11'), function(elm, a) {
elm.setAttribute('data-mindate', getTodayString());
});
window.myDatePicker_11 = new DatePicker('.date-11', extend({
closeOnSelect: false,
renderCallback: function(container, element, toggled) {
markRangeDays.call(this, container, element, toggled);
addButtons.call(this, container, element, toggled);
return true; // triggers default behaviour
}
}, options));
// ------------------- DEMO for input.date-111 ----------------- //
// Example with different month / year selector (tables).
// This is a bit more complex as we need to render years, months,
// to install event listeners and to deal with min/max values...
// ------------------------------------------------------------ //
var hasClass = function(element, className) {
return (' ' + element.className + ' ').indexOf(' ' + className + ' ') !== -1;
},
renderMonthsYears = function(monthYear, _this) {
var isMonth = monthYear === 'dp-label-month',
year = _this.tempYear - 4, // makes current the 5th in the table
month = 1,
getData = function(n, isMonth) {
var data = isMonth ? month++ : year++;
if (isMonth) {
data = +_this.date.year >= +_this.maxDate.year && data > +_this.maxDate.month ? '' :
+_this.date.year <= +_this.minDate.year && data < +_this.minDate.month ? '' : data;
} else {
if (!_this.hasMaxYear && data >= _this.maxDate.year) {
_this.hasMaxYear = true;
}
if (!_this.hasMinYear && data <= _this.minDate.year) {
_this.hasMinYear = true;
}
data = data <= _this.maxDate.year && data >= _this.minDate.year ? data : '';
}
return isMonth ? data === '' ? data : _this.options.months[data - 1] : data;
},
dataHTML = (function() {
var html = [];
_this.hasMinYear = _this.hasMaxYear = false;
for (var n = 0, m = 4; n < m; n++) {
for (var x = 0, y = 3; x < y; x++) {
html.push(_this.options.dataHTML.
replace(/class="(.*?)"/, function($1, $2) {
return 'class="' + $2 + (
isMonth && month === +_this.date.month ? ' current this-month' :
!isMonth && year === +_this.date.year ? ' current this-year' : '') + '"';
}).
replace('{{data}}', getData(n * y + x, isMonth)).
replace('{{day}}', +_this.date.day).
replace('{{month}}', isMonth ? month - 1 : +_this.date.month).
replace('{{year}}', isMonth ? _this.date.year : year - 1 ));
}
html.push(_this.options.glueHTML);
}
html.pop(); // remove last <tr>
return html.join('');
}());
return _this.options.header.
replace('{{month}}', _this.options.months[_this.date.month - 1]).
replace('{{year}}', _this.date.year) +
_this.options.yearsMonthsHTML.replace('{{data}}', dataHTML);
};
window.myDatePicker_111 = new DatePicker('.date-111', extend({
// closeOnSelect: false,
autoFallback: false, // shows months after clicking on year
header: // HTML without selects...
'<div class="dp-title">' +
'<button class="dp-prev" type="button"{{disable-prev}}>{{prev}}</button>' +
'<button class="dp-next" type="button"{{disable-next}}>{{next}}</button>' +
'<div class="dp-label dp-label-month">{{month}}</div>' +
'<div class="dp-label dp-label-year">{{year}}</div>' +
'</div>',
yearsMonthsHTML: '<table class="cal-month month-year-picker"><tbody><tr>{{data}}</tr></tbody></table>',
dataHTML: '<td class="selector" data-year="{{year}}" data-month="{{month}}">{{data}}</td>',
glueHTML: '</tr><tr>',
renderCallback: function(container, element, toggled) {
this.isInitialized = this.isInitialized || (function(_this) { // only once
container.addEventListener('click', function(e) {
var test = e.target.className.match(/dp-label-(?:month|year)/),
prev = hasClass(e.target, _this.options.prevButtonClass),
next = prev ? false : hasClass(e.target, _this.options.nextButtonClass),
month = 0;
if (test) { // clicked on month or year label
_this.showsYears = test[0] === 'dp-label-year';
_this.tempMonth = _this.date.month;
_this.tempYear = _this.date.year;
container.innerHTML = renderMonthsYears(test[0], _this);
} else if (_this.showsYears && (prev || next)) { // clicked on arrows (prev | next)
_this.tempYear = +_this.tempYear +
(prev ? -Math.min(+_this.tempYear - +_this.minDate.year, 12) :
Math.min(+_this.maxDate.year - +_this.tempYear, 12)) + '';
month = +_this.tempMonth;
_this.date.month = ((
+_this.tempYear >= +_this.maxDate.year ? Math.min(+_this.maxDate.month, month) :
+_this.tempYear <= +_this.minDate.year ? Math.max(+_this.minDate.month, month) :
month) + '').replace(/^(\d)$/, '0$1');
container.innerHTML = renderMonthsYears('', _this);
} else { // something else was clicked
if (hasClass(e.target, 'selector') && e.target.innerHTML) {
if (_this.showsYears) {
_this.date.year = e.target.getAttribute('data-year') + '';
if (_this.options.autoFallback) {
container.innerHTML = renderMonthsYears('dp-label-month', _this);
} else {
_this.toggle(_this.date);
}
} else {
_this.date.month = (e.target.getAttribute('data-month') + '').replace(/^(\d)$/, '0$1');
_this.toggle(_this.date);
}
}
_this.showsYears = false; // revisit
}
// disable arrows
if ((_this.showsYears && _this.hasMaxYear) || (test && !_this.showsYears)) {
container.querySelector('.dp-next').disabled = true;
}
if (_this.showsYears && _this.hasMinYear || (test && !_this.showsYears)) {
container.querySelector('.dp-prev').disabled = true;
}
}, false);
return true;
})(this);
if (toggled && !this.isOpen) { // on close ... TODO: on input change
this.showsYears = false;
}
return true; // triggers default behaviour
}
}, options));
// ------------------- DEMO for input.date-2 ------------------ //
// Example for hidden input field triggered by a button and
// rendering a formatted value to a disabled input field.
// ------------------------------------------------------------ //
var getInput = function(element, hidden) {
return element.parentNode.querySelector('input' + (hidden ? '[type="hidden"]' : ''));
},
changeValueFormat = function(value) { // some dummy function...
var date = new Date(value + 'T00:00:00.000Z');
return date.toDateString();
};
window.myDatePicker_2 = new DatePicker('.date-2', extend({
/**
* Initially render all values in input fields useing converted
* values from hidden input fields.
*
* @param {ElementList} elements All elements datePicker is initialized to
*/
initCallback: function(elements) {
var input,
hiddenInput;
for (var n = elements.length; n--; ) {
input = getInput(elements[n]);
hiddenInput = getInput(elements[n], true);
input.value = changeValueFormat(hiddenInput.value);
}
},
renderCallback: function(container, element, toggled) {
return getInput(element); // triggers default behaviour on certain element
},
renderValue: function(container, element, value) {
getInput(element).value = changeValueFormat(value);
return getInput(element, true); // triggers default behaviour on certain element
},
readValue: function(element) {
var value = getInput(element, true).value;
getInput(element).value = changeValueFormat(value);
return value;
}
}, options));
// ------------------- DEMO for input.date-3 ------------------ //
// Example like the above but then year, month and day get
// rendered in seperate fields.
// ------------------------------------------------------------ //
var getInputs = function(element, hidden) {
return element.parentNode.querySelectorAll('input');
};
window.myDatePicker_3 = new DatePicker('.date-3', extend({
renderCallback: function(container, element, toggled) {
return getInputs(element)[0];
},
renderValue: function(container, element, value) {
var inputs = getInputs(element),
val = value.split('-');
inputs[3].value = value;
inputs[0].value = val[0];
inputs[1].value = val[1]; // this.options.months[+val[1] - 1];
inputs[2].value = val[2];
},
readValue: function(element) {
var value = getInputs(element)[3].value;
this.options.renderValue.call(this, undefined, element, value);
return value;
}
}, options));
// ------------------- DEMO for input.date-4 ------------------ //
// Example with data from variables.
// ------------------------------------------------------------ //
var dates = window.dates = {
'date-1': '2016-06-23',
'date-2': '2016-07-26',
'date-3': '2016-08-28'
},
dataAttr = 'data-date',
changeValueFormat_de = function(value, options) {
var parts = value.split(' ')[0].split('-'),
date = new Date(parts[0], parts[1] - 1, parts[2] || 0);
return options.weekDaysLong[date.getDay()] + ', ' + date.getDate() + '. ' +
options.months[date.getMonth()] + ' ' + date.getFullYear();
};
window.myDatePicker_4 = new DatePicker('.date-4', extend({
weekDaysLong:
['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
initCallback: function(elements) {
for (var n = elements.length; n--; ) {
elements[n].value =
changeValueFormat_de(dates[elements[n].getAttribute(dataAttr)], this.options);
}
},
renderValue: function(container, element, value) {
dates[element.getAttribute(dataAttr)] = value;
element.value = changeValueFormat_de(value, this.options);
},
readValue: function(element) {
return dates[element.getAttribute(dataAttr)];
}
}, options));
// ------------------- DEMO for input.date-5 ------------------ //
// Example with less markup.
// ------------------------------------------------------------ //
window.myDatePicker_5 = new DatePicker('.date-5', extend({
renderWeekNo: false,
equalHight: false,
datePickerClass: 'date-picker div-based',
template: {
start: function(month, year) { // rendering week days
return '{{days}}'
},
daysOfWeek: '<div class="item">{{day}}</div>',
colGlue: '',
row: '<div class="item{{day-event}}">{{day}}</div>',
end: function() {return ''},
day: function(days, date) {
if (date.getDay() === (this.options.sundayBased ? 0 : 1)) {
return ' cleared-day';
}
return ' ';
}
}
}, options));
// ------------------- DEMO for input.date-6 ------------------ //
// Example with today, clear and close button (stays open).
// ------------------------------------------------------------ //
window.myDatePicker_6 = new DatePicker('.date-6', extend({
renderWeekNo: true,
closeOnSelect: false,
clearText: '', // following are optional for different languages
todayText: '',
closeText: 'exit', // prints 'exit' in place of default 'close'
renderCallback: function(container, element, toggled) {
addButtons.call(this, container, element, toggled);
return true; // triggers default behaviour
}
}, options));
</script>
<!-- more demos on this page only useing calendar.js -->
<script type="text/javascript" src="demo/year.js"></script>
<script type="text/javascript" src="demo/month.js"></script>
<script type="text/javascript" src="demo/week.js"></script>
<script type="text/javascript" src="demo/flight.js"></script>
</body>
</html>