beautiful_scaffold 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,834 @@
1
+ /* =========================================================
2
+ * bootstrap-datepicker.js
3
+ * http://www.eyecon.ro/bootstrap-datepicker
4
+ * =========================================================
5
+ * Copyright 2012 Stefan Petre
6
+ * Improvements by Andrew Rowls
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ * ========================================================= */
20
+
21
+ !function( $ ) {
22
+
23
+ // Picker object
24
+
25
+ var Datepicker = function(element, options){
26
+ this.element = $(element);
27
+ this.language = options.language||this.element.data('date-language')||"en";
28
+ this.language = this.language in dates ? this.language : "en";
29
+ this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
30
+ this.picker = $(DPGlobal.template)
31
+ .appendTo('body')
32
+ .on({
33
+ click: $.proxy(this.click, this),
34
+ mousedown: $.proxy(this.mousedown, this)
35
+ });
36
+ this.isInput = this.element.is('input');
37
+ this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
38
+ if(this.component && this.component.length === 0)
39
+ this.component = false;
40
+
41
+ if (this.isInput) {
42
+ this.element.on({
43
+ focus: $.proxy(this.show, this),
44
+ blur: $.proxy(this._hide, this),
45
+ keyup: $.proxy(this.update, this),
46
+ keydown: $.proxy(this.keydown, this)
47
+ });
48
+ } else {
49
+ if (this.component){
50
+ // For components that are not readonly, allow keyboard nav
51
+ this.element.find('input').on({
52
+ focus: $.proxy(this.show, this),
53
+ blur: $.proxy(this._hide, this),
54
+ keyup: $.proxy(this.update, this),
55
+ keydown: $.proxy(this.keydown, this)
56
+ });
57
+
58
+ this.component.on('click', $.proxy(this.show, this));
59
+ var element = this.element.find('input');
60
+ element.on({
61
+ blur: $.proxy(this._hide, this)
62
+ })
63
+ } else {
64
+ this.element.on('click', $.proxy(this.show, this));
65
+ }
66
+ }
67
+
68
+ this.autoclose = false;
69
+ if ('autoclose' in options) {
70
+ this.autoclose = options.autoclose;
71
+ } else if ('dateAutoclose' in this.element.data()) {
72
+ this.autoclose = this.element.data('date-autoclose');
73
+ }
74
+
75
+ this.keyboardNavigation = true;
76
+ if ('keyboardNavigation' in options) {
77
+ this.keyboardNavigation = options.keyboardNavigation;
78
+ } else if ('dateKeyboardNavigation' in this.element.data()) {
79
+ this.keyboardNavigation = this.element.data('date-keyboard-navigation');
80
+ }
81
+
82
+ switch(options.startView || this.element.data('date-start-view')){
83
+ case 2:
84
+ case 'decade':
85
+ this.viewMode = this.startViewMode = 2;
86
+ break;
87
+ case 1:
88
+ case 'year':
89
+ this.viewMode = this.startViewMode = 1;
90
+ break;
91
+ case 0:
92
+ case 'month':
93
+ default:
94
+ this.viewMode = this.startViewMode = 0;
95
+ break;
96
+ }
97
+
98
+ this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
99
+ this.weekEnd = ((this.weekStart + 6) % 7);
100
+ this.startDate = -Infinity;
101
+ this.endDate = Infinity;
102
+ this.setStartDate(options.startDate||this.element.data('date-startdate'));
103
+ this.setEndDate(options.endDate||this.element.data('date-enddate'));
104
+ this.fillDow();
105
+ this.fillMonths();
106
+ this.update();
107
+ this.showMode();
108
+ };
109
+
110
+ Datepicker.prototype = {
111
+ constructor: Datepicker,
112
+
113
+ show: function(e) {
114
+ this.picker.show();
115
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
116
+ this.update();
117
+ this.place();
118
+ $(window).on('resize', $.proxy(this.place, this));
119
+ if (e ) {
120
+ e.stopPropagation();
121
+ e.preventDefault();
122
+ }
123
+ if (!this.isInput) {
124
+ $(document).on('mousedown', $.proxy(this.hide, this));
125
+ }
126
+ this.element.trigger({
127
+ type: 'show',
128
+ date: this.date
129
+ });
130
+ },
131
+
132
+ _hide: function(e){
133
+ // When going from the input to the picker, IE handles the blur/click
134
+ // events differently than other browsers, in such a way that the blur
135
+ // event triggers a hide before the click event can stop propagation.
136
+ if ($.browser.msie) {
137
+ var t = this, args = arguments;
138
+
139
+ function cancel_hide(){
140
+ clearTimeout(hide_timeout);
141
+ e.target.focus();
142
+ t.picker.off('click', cancel_hide);
143
+ }
144
+
145
+ function do_hide(){
146
+ t.hide.apply(t, args);
147
+ t.picker.off('click', cancel_hide);
148
+ }
149
+
150
+ this.picker.on('click', cancel_hide);
151
+ var hide_timeout = setTimeout(do_hide, 100);
152
+ } else {
153
+ return this.hide.apply(this, arguments);
154
+ }
155
+ },
156
+
157
+ hide: function(e){
158
+ this.picker.hide();
159
+ $(window).off('resize', this.place);
160
+ this.viewMode = this.startViewMode;
161
+ this.showMode();
162
+ if (!this.isInput) {
163
+ $(document).off('mousedown', this.hide);
164
+ }
165
+ if (e && e.currentTarget.value)
166
+ this.setValue();
167
+ this.element.trigger({
168
+ type: 'hide',
169
+ date: this.date
170
+ });
171
+ },
172
+
173
+ setValue: function() {
174
+ var formatted = DPGlobal.formatDate(this.date, this.format, this.language);
175
+ if (!this.isInput) {
176
+ if (this.component){
177
+ this.element.find('input').prop('value', formatted);
178
+ }
179
+ this.element.data('date', formatted);
180
+ } else {
181
+ this.element.prop('value', formatted);
182
+ }
183
+ },
184
+
185
+ setStartDate: function(startDate){
186
+ this.startDate = startDate||-Infinity;
187
+ if (this.startDate !== -Infinity) {
188
+ this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
189
+ }
190
+ this.update();
191
+ this.updateNavArrows();
192
+ },
193
+
194
+ setEndDate: function(endDate){
195
+ this.endDate = endDate||Infinity;
196
+ if (this.endDate !== Infinity) {
197
+ this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
198
+ }
199
+ this.update();
200
+ this.updateNavArrows();
201
+ },
202
+
203
+ place: function(){
204
+ var zIndex = parseInt(this.element.parents().filter(function() {
205
+ return $(this).css('z-index') != 'auto';
206
+ }).first().css('z-index'))+10;
207
+ var offset = this.component ? this.component.offset() : this.element.offset();
208
+ this.picker.css({
209
+ top: offset.top + this.height,
210
+ left: offset.left,
211
+ zIndex: zIndex
212
+ });
213
+ },
214
+
215
+ update: function(){
216
+ this.date = DPGlobal.parseDate(
217
+ this.isInput ? this.element.prop('value') : this.element.data('date') || this.element.find('input').prop('value'),
218
+ this.format, this.language
219
+ );
220
+ if (this.date < this.startDate) {
221
+ this.viewDate = new Date(this.startDate);
222
+ } else if (this.date > this.endDate) {
223
+ this.viewDate = new Date(this.endDate);
224
+ } else {
225
+ this.viewDate = new Date(this.date);
226
+ }
227
+ this.fill();
228
+ },
229
+
230
+ fillDow: function(){
231
+ var dowCnt = this.weekStart;
232
+ var html = '<tr>';
233
+ while (dowCnt < this.weekStart + 7) {
234
+ html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
235
+ }
236
+ html += '</tr>';
237
+ this.picker.find('.datepicker-days thead').append(html);
238
+ },
239
+
240
+ fillMonths: function(){
241
+ var html = '';
242
+ var i = 0
243
+ while (i < 12) {
244
+ html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
245
+ }
246
+ this.picker.find('.datepicker-months td').html(html);
247
+ },
248
+
249
+ fill: function() {
250
+ var d = new Date(this.viewDate),
251
+ year = d.getFullYear(),
252
+ month = d.getMonth(),
253
+ startYear = this.startDate !== -Infinity ? this.startDate.getFullYear() : -Infinity,
254
+ startMonth = this.startDate !== -Infinity ? this.startDate.getMonth() : -Infinity,
255
+ endYear = this.endDate !== Infinity ? this.endDate.getFullYear() : Infinity,
256
+ endMonth = this.endDate !== Infinity ? this.endDate.getMonth() : Infinity,
257
+ currentDate = this.date.valueOf();
258
+ this.picker.find('.datepicker-days th:eq(1)')
259
+ .text(dates[this.language].months[month]+' '+year);
260
+ this.updateNavArrows();
261
+ this.fillMonths();
262
+ var prevMonth = new Date(year, month-1, 28,0,0,0,0),
263
+ day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth()),
264
+ prevDate, dstDay = 0, date;
265
+ prevMonth.setDate(day);
266
+ prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
267
+ var nextMonth = new Date(prevMonth);
268
+ nextMonth.setDate(nextMonth.getDate() + 42);
269
+ nextMonth = nextMonth.valueOf();
270
+ var html = [];
271
+ var clsName;
272
+ while(prevMonth.valueOf() < nextMonth) {
273
+ if (prevMonth.getDay() == this.weekStart) {
274
+ html.push('<tr>');
275
+ }
276
+ clsName = '';
277
+ if (prevMonth.getFullYear() < year || (prevMonth.getFullYear() == year && prevMonth.getMonth() < month)) {
278
+ clsName += ' old';
279
+ } else if (prevMonth.getFullYear() > year || (prevMonth.getFullYear() == year && prevMonth.getMonth() > month)) {
280
+ clsName += ' new';
281
+ }
282
+ if (prevMonth.valueOf() == currentDate) {
283
+ clsName += ' active';
284
+ }
285
+ if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate) {
286
+ clsName += ' disabled';
287
+ }
288
+ date = prevMonth.getDate();
289
+ if (dstDay == -1) date++;
290
+ html.push('<td class="day'+clsName+'">'+date+ '</td>');
291
+ if (prevMonth.getDay() == this.weekEnd) {
292
+ html.push('</tr>');
293
+ }
294
+ prevDate = prevMonth.getDate();
295
+ prevMonth.setDate(prevMonth.getDate()+1);
296
+ if (prevMonth.getHours() != 0) {
297
+ // Fix for DST bug: if we are no longer at start of day, a DST jump probably happened
298
+ // We either fell back (eg, Jan 1 00:00 -> Jan 1 23:00)
299
+ // or jumped forward (eg, Jan 1 00:00 -> Jan 2 01:00)
300
+ // Unfortunately, I can think of no way to test this in the unit tests, as it depends
301
+ // on the TZ of the client system.
302
+ if (!dstDay) {
303
+ // We are not currently handling a dst day (next round will deal with it)
304
+ if (prevMonth.getDate() == prevDate)
305
+ // We must compensate for fall-back
306
+ dstDay = -1;
307
+ else
308
+ // We must compensate for a jump-ahead
309
+ dstDay = +1;
310
+ }
311
+ else {
312
+ // The last round was our dst day (hours are still non-zero)
313
+ if (dstDay == -1)
314
+ // For a fall-back, fast-forward to next midnight
315
+ prevMonth.setHours(24);
316
+ else
317
+ // For a jump-ahead, just reset to 0
318
+ prevMonth.setHours(0);
319
+ // Reset minutes, as some TZs may be off by portions of an hour
320
+ prevMonth.setMinutes(0);
321
+ dstDay = 0;
322
+ }
323
+ }
324
+ }
325
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
326
+ var currentYear = this.date.getFullYear();
327
+
328
+ var months = this.picker.find('.datepicker-months')
329
+ .find('th:eq(1)')
330
+ .text(year)
331
+ .end()
332
+ .find('span').removeClass('active');
333
+ if (currentYear == year) {
334
+ months.eq(this.date.getMonth()).addClass('active');
335
+ }
336
+ if (year < startYear || year > endYear) {
337
+ months.addClass('disabled');
338
+ }
339
+ if (year == startYear) {
340
+ months.slice(0, startMonth).addClass('disabled');
341
+ }
342
+ if (year == endYear) {
343
+ months.slice(endMonth+1).addClass('disabled');
344
+ }
345
+
346
+ html = '';
347
+ year = parseInt(year/10, 10) * 10;
348
+ var yearCont = this.picker.find('.datepicker-years')
349
+ .find('th:eq(1)')
350
+ .text(year + '-' + (year + 9))
351
+ .end()
352
+ .find('td');
353
+ year -= 1;
354
+ for (var i = -1; i < 11; i++) {
355
+ html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
356
+ year += 1;
357
+ }
358
+ yearCont.html(html);
359
+ },
360
+
361
+ updateNavArrows: function() {
362
+ var d = new Date(this.viewDate),
363
+ year = d.getFullYear(),
364
+ month = d.getMonth();
365
+ switch (this.viewMode) {
366
+ case 0:
367
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear() && month <= this.startDate.getMonth()) {
368
+ this.picker.find('.prev').css({visibility: 'hidden'});
369
+ } else {
370
+ this.picker.find('.prev').css({visibility: 'visible'});
371
+ }
372
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear() && month >= this.endDate.getMonth()) {
373
+ this.picker.find('.next').css({visibility: 'hidden'});
374
+ } else {
375
+ this.picker.find('.next').css({visibility: 'visible'});
376
+ }
377
+ break;
378
+ case 1:
379
+ case 2:
380
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear()) {
381
+ this.picker.find('.prev').css({visibility: 'hidden'});
382
+ } else {
383
+ this.picker.find('.prev').css({visibility: 'visible'});
384
+ }
385
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear()) {
386
+ this.picker.find('.next').css({visibility: 'hidden'});
387
+ } else {
388
+ this.picker.find('.next').css({visibility: 'visible'});
389
+ }
390
+ break;
391
+ }
392
+ },
393
+
394
+ click: function(e) {
395
+ e.stopPropagation();
396
+ e.preventDefault();
397
+ var target = $(e.target).closest('span, td, th');
398
+ if (target.length == 1) {
399
+ switch(target[0].nodeName.toLowerCase()) {
400
+ case 'th':
401
+ switch(target[0].className) {
402
+ case 'switch':
403
+ this.showMode(1);
404
+ break;
405
+ case 'prev':
406
+ case 'next':
407
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
408
+ switch(this.viewMode){
409
+ case 0:
410
+ this.viewDate = this.moveMonth(this.viewDate, dir);
411
+ break;
412
+ case 1:
413
+ case 2:
414
+ this.viewDate = this.moveYear(this.viewDate, dir);
415
+ break;
416
+ }
417
+ this.fill();
418
+ break;
419
+ }
420
+ break;
421
+ case 'span':
422
+ if (!target.is('.disabled')) {
423
+ this.viewDate.setDate(1);
424
+ if (target.is('.month')) {
425
+ var month = target.parent().find('span').index(target);
426
+ this.viewDate.setMonth(month);
427
+ this.element.trigger({
428
+ type: 'changeMonth',
429
+ date: this.viewDate
430
+ });
431
+ } else {
432
+ var year = parseInt(target.text(), 10)||0;
433
+ this.viewDate.setFullYear(year);
434
+ this.element.trigger({
435
+ type: 'changeYear',
436
+ date: this.viewDate
437
+ });
438
+ }
439
+ this.showMode(-1);
440
+ this.fill();
441
+ }
442
+ break;
443
+ case 'td':
444
+ if (target.is('.day') && !target.is('.disabled')){
445
+ var day = parseInt(target.text(), 10)||1;
446
+ var year = this.viewDate.getFullYear(),
447
+ month = this.viewDate.getMonth();
448
+ if (target.is('.old')) {
449
+ if (month == 0) {
450
+ month = 11;
451
+ year -= 1;
452
+ } else {
453
+ month -= 1;
454
+ }
455
+ } else if (target.is('.new')) {
456
+ if (month == 11) {
457
+ month = 0;
458
+ year += 1;
459
+ } else {
460
+ month += 1;
461
+ }
462
+ }
463
+ this.date = new Date(year, month, day,0,0,0,0);
464
+ this.viewDate = new Date(year, month, day,0,0,0,0);
465
+ this.fill();
466
+ this.setValue();
467
+ this.element.trigger({
468
+ type: 'changeDate',
469
+ date: this.date
470
+ });
471
+ var element;
472
+ if (this.isInput) {
473
+ element = this.element;
474
+ } else if (this.component){
475
+ element = this.element.find('input');
476
+ }
477
+ if (element) {
478
+ element.change();
479
+ if (this.autoclose) {
480
+ element.blur();
481
+ }
482
+ }
483
+ }
484
+ break;
485
+ }
486
+ }
487
+ },
488
+
489
+ mousedown: function(e){
490
+ e.stopPropagation();
491
+ e.preventDefault();
492
+ },
493
+
494
+ moveMonth: function(date, dir){
495
+ if (!dir) return date;
496
+ var new_date = new Date(date.valueOf()),
497
+ day = new_date.getDate(),
498
+ month = new_date.getMonth(),
499
+ mag = Math.abs(dir),
500
+ new_month, test;
501
+ dir = dir > 0 ? 1 : -1;
502
+ if (mag == 1){
503
+ test = dir == -1
504
+ // If going back one month, make sure month is not current month
505
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
506
+ ? function(){ return new_date.getMonth() == month; }
507
+ // If going forward one month, make sure month is as expected
508
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
509
+ : function(){ return new_date.getMonth() != new_month; };
510
+ new_month = month + dir;
511
+ new_date.setMonth(new_month);
512
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
513
+ if (new_month < 0 || new_month > 11)
514
+ new_month = (new_month + 12) % 12;
515
+ } else {
516
+ // For magnitudes >1, move one month at a time...
517
+ for (var i=0; i<mag; i++)
518
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
519
+ new_date = this.moveMonth(new_date, dir);
520
+ // ...then reset the day, keeping it in the new month
521
+ new_month = new_date.getMonth();
522
+ new_date.setDate(day);
523
+ test = function(){ return new_month != new_date.getMonth(); };
524
+ }
525
+ // Common date-resetting loop -- if date is beyond end of month, make it
526
+ // end of month
527
+ while (test()){
528
+ new_date.setDate(--day);
529
+ new_date.setMonth(new_month);
530
+ }
531
+ return new_date;
532
+ },
533
+
534
+ moveYear: function(date, dir){
535
+ return this.moveMonth(date, dir*12);
536
+ },
537
+
538
+ dateWithinRange: function(date){
539
+ return date >= this.startDate && date <= this.endDate;
540
+ },
541
+
542
+ keydown: function(e){
543
+ if (this.picker.is(':not(:visible)')){
544
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
545
+ this.show();
546
+ return;
547
+ }
548
+ var dateChanged = false,
549
+ dir, day, month,
550
+ newDate, newViewDate;
551
+ switch(e.keyCode){
552
+ case 27: // escape
553
+ this.hide();
554
+ e.preventDefault();
555
+ break;
556
+ case 37: // left
557
+ case 39: // right
558
+ if (!this.keyboardNavigation) break;
559
+ dir = e.keyCode == 37 ? -1 : 1;
560
+ if (e.ctrlKey){
561
+ newDate = this.moveYear(this.date, dir);
562
+ newViewDate = this.moveYear(this.viewDate, dir);
563
+ } else if (e.shiftKey){
564
+ newDate = this.moveMonth(this.date, dir);
565
+ newViewDate = this.moveMonth(this.viewDate, dir);
566
+ } else {
567
+ newDate = new Date(this.date);
568
+ newDate.setDate(this.date.getDate() + dir);
569
+ newViewDate = new Date(this.viewDate);
570
+ newViewDate.setDate(this.viewDate.getDate() + dir);
571
+ }
572
+ if (this.dateWithinRange(newDate)){
573
+ this.date = newDate;
574
+ this.viewDate = newViewDate;
575
+ this.setValue();
576
+ this.update();
577
+ e.preventDefault();
578
+ dateChanged = true;
579
+ }
580
+ break;
581
+ case 38: // up
582
+ case 40: // down
583
+ if (!this.keyboardNavigation) break;
584
+ dir = e.keyCode == 38 ? -1 : 1;
585
+ if (e.ctrlKey){
586
+ newDate = this.moveYear(this.date, dir);
587
+ newViewDate = this.moveYear(this.viewDate, dir);
588
+ } else if (e.shiftKey){
589
+ newDate = this.moveMonth(this.date, dir);
590
+ newViewDate = this.moveMonth(this.viewDate, dir);
591
+ } else {
592
+ newDate = new Date(this.date);
593
+ newDate.setDate(this.date.getDate() + dir * 7);
594
+ newViewDate = new Date(this.viewDate);
595
+ newViewDate.setDate(this.viewDate.getDate() + dir * 7);
596
+ }
597
+ if (this.dateWithinRange(newDate)){
598
+ this.date = newDate;
599
+ this.viewDate = newViewDate;
600
+ this.setValue();
601
+ this.update();
602
+ e.preventDefault();
603
+ dateChanged = true;
604
+ }
605
+ break;
606
+ case 13: // enter
607
+ this.hide();
608
+ e.preventDefault();
609
+ break;
610
+ }
611
+ if (dateChanged){
612
+ this.element.trigger({
613
+ type: 'changeDate',
614
+ date: this.date
615
+ });
616
+ var element;
617
+ if (this.isInput) {
618
+ element = this.element;
619
+ } else if (this.component){
620
+ element = this.element.find('input');
621
+ }
622
+ if (element) {
623
+ element.change();
624
+ }
625
+ }
626
+ },
627
+
628
+ showMode: function(dir) {
629
+ if (dir) {
630
+ this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
631
+ }
632
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
633
+ this.updateNavArrows();
634
+ }
635
+ };
636
+
637
+ $.fn.datepicker = function ( option ) {
638
+ var args = Array.apply(null, arguments);
639
+ args.shift();
640
+ return this.each(function () {
641
+ var $this = $(this),
642
+ data = $this.data('datepicker'),
643
+ options = typeof option == 'object' && option;
644
+ if (!data) {
645
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
646
+ }
647
+ if (typeof option == 'string' && typeof data[option] == 'function') {
648
+ data[option].apply(data, args);
649
+ }
650
+ });
651
+ };
652
+
653
+ $.fn.datepicker.defaults = {
654
+ };
655
+ $.fn.datepicker.Constructor = Datepicker;
656
+ var dates = $.fn.datepicker.dates = {
657
+ en: {
658
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
659
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
660
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
661
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
662
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
663
+ }
664
+ }
665
+
666
+ var DPGlobal = {
667
+ modes: [
668
+ {
669
+ clsName: 'days',
670
+ navFnc: 'Month',
671
+ navStep: 1
672
+ },
673
+ {
674
+ clsName: 'months',
675
+ navFnc: 'FullYear',
676
+ navStep: 1
677
+ },
678
+ {
679
+ clsName: 'years',
680
+ navFnc: 'FullYear',
681
+ navStep: 10
682
+ }],
683
+ isLeapYear: function (year) {
684
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
685
+ },
686
+ getDaysInMonth: function (year, month) {
687
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
688
+ },
689
+ validParts: /dd?|mm?|MM?|yy(?:yy)?/g,
690
+ nonpunctuation: /[^ -\/:-@\[-`{-~\t\n\r]+/g,
691
+ parseFormat: function(format){
692
+ // IE treats \0 as a string end in inputs (truncating the value),
693
+ // so it's a bad format delimiter, anyway
694
+ var separators = format.replace(this.validParts, '\0').split('\0'),
695
+ parts = format.match(this.validParts);
696
+ if (!separators || !separators.length || !parts || parts.length == 0){
697
+ throw new Error("Invalid date format.");
698
+ }
699
+ return {separators: separators, parts: parts};
700
+ },
701
+ parseDate: function(date, format, language) {
702
+ if (date instanceof Date) return date;
703
+ if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) {
704
+ var part_re = /([-+]\d+)([dmwy])/,
705
+ parts = date.match(/([-+]\d+)([dmwy])/g),
706
+ part, dir;
707
+ date = new Date();
708
+ for (var i=0; i<parts.length; i++) {
709
+ part = part_re.exec(parts[i]);
710
+ dir = parseInt(part[1]);
711
+ switch(part[2]){
712
+ case 'd':
713
+ date.setDate(date.getDate() + dir);
714
+ break;
715
+ case 'm':
716
+ date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
717
+ break;
718
+ case 'w':
719
+ date.setDate(date.getDate() + dir * 7);
720
+ break;
721
+ case 'y':
722
+ date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
723
+ break;
724
+ }
725
+ }
726
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
727
+ }
728
+ var parts = date && date.match(this.nonpunctuation) || [],
729
+ date = new Date(),
730
+ parsed = {},
731
+ setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
732
+ setters_map = {
733
+ yyyy: function(d,v){ return d.setFullYear(v); },
734
+ yy: function(d,v){ return d.setFullYear(2000+v); },
735
+ m: function(d,v){
736
+ v -= 1;
737
+ while (v<0) v += 12;
738
+ v %= 12;
739
+ d.setMonth(v);
740
+ while (d.getMonth() != v)
741
+ d.setDate(d.getDate()-1);
742
+ return d;
743
+ },
744
+ d: function(d,v){ return d.setDate(v); }
745
+ },
746
+ val, filtered, part;
747
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
748
+ setters_map['dd'] = setters_map['d'];
749
+ date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
750
+ if (parts.length == format.parts.length) {
751
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
752
+ val = parseInt(parts[i], 10);
753
+ part = format.parts[i];
754
+ if (isNaN(val)) {
755
+ switch(part) {
756
+ case 'MM':
757
+ filtered = $(dates[language].months).filter(function(){
758
+ var m = this.slice(0, parts[i].length),
759
+ p = parts[i].slice(0, m.length);
760
+ return m == p;
761
+ });
762
+ val = $.inArray(filtered[0], dates[language].months) + 1;
763
+ break;
764
+ case 'M':
765
+ filtered = $(dates[language].monthsShort).filter(function(){
766
+ var m = this.slice(0, parts[i].length),
767
+ p = parts[i].slice(0, m.length);
768
+ return m == p;
769
+ });
770
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
771
+ break;
772
+ }
773
+ }
774
+ parsed[part] = val;
775
+ }
776
+ for (var i=0, s; i<setters_order.length; i++){
777
+ s = setters_order[i];
778
+ if (s in parsed)
779
+ setters_map[s](date, parsed[s])
780
+ }
781
+ }
782
+ return date;
783
+ },
784
+ formatDate: function(date, format, language){
785
+ var val = {
786
+ d: date.getDate(),
787
+ m: date.getMonth() + 1,
788
+ M: dates[language].monthsShort[date.getMonth()],
789
+ MM: dates[language].months[date.getMonth()],
790
+ yy: date.getFullYear().toString().substring(2),
791
+ yyyy: date.getFullYear()
792
+ };
793
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
794
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
795
+ var date = [],
796
+ seps = $.extend([], format.separators);
797
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
798
+ if (seps.length)
799
+ date.push(seps.shift())
800
+ date.push(val[format.parts[i]]);
801
+ }
802
+ return date.join('');
803
+ },
804
+ headTemplate: '<thead>'+
805
+ '<tr>'+
806
+ '<th class="prev"><i class="icon-arrow-left"/></th>'+
807
+ '<th colspan="5" class="switch"></th>'+
808
+ '<th class="next"><i class="icon-arrow-right"/></th>'+
809
+ '</tr>'+
810
+ '</thead>',
811
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
812
+ };
813
+ DPGlobal.template = '<div class="datepicker dropdown-menu">'+
814
+ '<div class="datepicker-days">'+
815
+ '<table class=" table-condensed">'+
816
+ DPGlobal.headTemplate+
817
+ '<tbody></tbody>'+
818
+ '</table>'+
819
+ '</div>'+
820
+ '<div class="datepicker-months">'+
821
+ '<table class="table-condensed">'+
822
+ DPGlobal.headTemplate+
823
+ DPGlobal.contTemplate+
824
+ '</table>'+
825
+ '</div>'+
826
+ '<div class="datepicker-years">'+
827
+ '<table class="table-condensed">'+
828
+ DPGlobal.headTemplate+
829
+ DPGlobal.contTemplate+
830
+ '</table>'+
831
+ '</div>'+
832
+ '</div>';
833
+
834
+ }( window.jQuery );