bootstrap-rails-engine 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,757 @@
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
+ switch(options.startView){
76
+ case 2:
77
+ case 'decade':
78
+ this.viewMode = this.startViewMode = 2;
79
+ break;
80
+ case 1:
81
+ case 'year':
82
+ this.viewMode = this.startViewMode = 1;
83
+ break;
84
+ case 0:
85
+ case 'month':
86
+ default:
87
+ this.viewMode = this.startViewMode = 0;
88
+ break;
89
+ }
90
+
91
+ this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
92
+ this.weekEnd = ((this.weekStart + 6) % 7);
93
+ this.startDate = -Infinity;
94
+ this.endDate = Infinity;
95
+ this.setStartDate(options.startDate||this.element.data('date-startdate'));
96
+ this.setEndDate(options.endDate||this.element.data('date-enddate'));
97
+ this.fillDow();
98
+ this.fillMonths();
99
+ this.update();
100
+ this.showMode();
101
+ };
102
+
103
+ Datepicker.prototype = {
104
+ constructor: Datepicker,
105
+
106
+ show: function(e) {
107
+ this.picker.show();
108
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
109
+ this.place();
110
+ $(window).on('resize', $.proxy(this.place, this));
111
+ if (e ) {
112
+ e.stopPropagation();
113
+ e.preventDefault();
114
+ }
115
+ if (!this.isInput) {
116
+ $(document).on('mousedown', $.proxy(this.hide, this));
117
+ }
118
+ this.element.trigger({
119
+ type: 'show',
120
+ date: this.date
121
+ });
122
+ },
123
+
124
+ _hide: function(e){
125
+ // When going from the input to the picker, IE handles the blur/click
126
+ // events differently than other browsers, in such a way that the blur
127
+ // event triggers a hide before the click event can stop propagation.
128
+ if ($.browser.msie) {
129
+ var t = this, args = arguments;
130
+
131
+ function cancel_hide(){
132
+ clearTimeout(hide_timeout);
133
+ e.target.focus();
134
+ t.picker.off('click', cancel_hide);
135
+ }
136
+
137
+ function do_hide(){
138
+ t.hide.apply(t, args);
139
+ t.picker.off('click', cancel_hide);
140
+ }
141
+
142
+ this.picker.on('click', cancel_hide);
143
+ var hide_timeout = setTimeout(do_hide, 100);
144
+ } else {
145
+ return this.hide.apply(this, arguments);
146
+ }
147
+ },
148
+
149
+ hide: function(e){
150
+ this.picker.hide();
151
+ $(window).off('resize', this.place);
152
+ this.viewMode = this.startViewMode;
153
+ this.showMode();
154
+ if (!this.isInput) {
155
+ $(document).off('mousedown', this.hide);
156
+ }
157
+ if (e && e.currentTarget.value)
158
+ this.setValue();
159
+ this.element.trigger({
160
+ type: 'hide',
161
+ date: this.date
162
+ });
163
+ },
164
+
165
+ setValue: function() {
166
+ var formated = DPGlobal.formatDate(this.date, this.format, this.language);
167
+ if (!this.isInput) {
168
+ if (this.component){
169
+ this.element.find('input').prop('value', formated);
170
+ }
171
+ this.element.data('date', formated);
172
+ } else {
173
+ this.element.prop('value', formated);
174
+ }
175
+ },
176
+
177
+ setStartDate: function(startDate){
178
+ this.startDate = startDate||-Infinity;
179
+ if (this.startDate !== -Infinity) {
180
+ this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
181
+ }
182
+ this.update();
183
+ this.updateNavArrows();
184
+ },
185
+
186
+ setEndDate: function(endDate){
187
+ this.endDate = endDate||Infinity;
188
+ if (this.endDate !== Infinity) {
189
+ this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
190
+ }
191
+ this.update();
192
+ this.updateNavArrows();
193
+ },
194
+
195
+ place: function(){
196
+ var offset = this.component ? this.component.offset() : this.element.offset();
197
+ this.picker.css({
198
+ top: offset.top + this.height,
199
+ left: offset.left
200
+ });
201
+ },
202
+
203
+ update: function(){
204
+ this.date = DPGlobal.parseDate(
205
+ this.isInput ? this.element.prop('value') : this.element.data('date') || this.element.find('input').prop('value'),
206
+ this.format, this.language
207
+ );
208
+ if (this.date < this.startDate) {
209
+ this.viewDate = new Date(this.startDate);
210
+ } else if (this.date > this.endDate) {
211
+ this.viewDate = new Date(this.endDate);
212
+ } else {
213
+ this.viewDate = new Date(this.date);
214
+ }
215
+ this.fill();
216
+ },
217
+
218
+ fillDow: function(){
219
+ var dowCnt = this.weekStart;
220
+ var html = '<tr>';
221
+ while (dowCnt < this.weekStart + 7) {
222
+ html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
223
+ }
224
+ html += '</tr>';
225
+ this.picker.find('.datepicker-days thead').append(html);
226
+ },
227
+
228
+ fillMonths: function(){
229
+ var html = '';
230
+ var i = 0
231
+ while (i < 12) {
232
+ html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
233
+ }
234
+ this.picker.find('.datepicker-months td').html(html);
235
+ },
236
+
237
+ fill: function() {
238
+ var d = new Date(this.viewDate),
239
+ year = d.getFullYear(),
240
+ month = d.getMonth(),
241
+ startYear = this.startDate !== -Infinity ? this.startDate.getFullYear() : -Infinity,
242
+ startMonth = this.startDate !== -Infinity ? this.startDate.getMonth() : -Infinity,
243
+ endYear = this.endDate !== Infinity ? this.endDate.getFullYear() : Infinity,
244
+ endMonth = this.endDate !== Infinity ? this.endDate.getMonth() : Infinity,
245
+ currentDate = this.date.valueOf();
246
+ this.picker.find('.datepicker-days th:eq(1)')
247
+ .text(dates[this.language].months[month]+' '+year);
248
+ this.updateNavArrows();
249
+ this.fillMonths();
250
+ var prevMonth = new Date(year, month-1, 28,0,0,0,0),
251
+ day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
252
+ prevMonth.setDate(day);
253
+ prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
254
+ var nextMonth = new Date(prevMonth);
255
+ nextMonth.setDate(nextMonth.getDate() + 42);
256
+ nextMonth = nextMonth.valueOf();
257
+ html = [];
258
+ var clsName;
259
+ while(prevMonth.valueOf() < nextMonth) {
260
+ if (prevMonth.getDay() == this.weekStart) {
261
+ html.push('<tr>');
262
+ }
263
+ clsName = '';
264
+ if (prevMonth.getFullYear() < year || (prevMonth.getFullYear() == year && prevMonth.getMonth() < month)) {
265
+ clsName += ' old';
266
+ } else if (prevMonth.getFullYear() > year || (prevMonth.getFullYear() == year && prevMonth.getMonth() > month)) {
267
+ clsName += ' new';
268
+ }
269
+ if (prevMonth.valueOf() == currentDate) {
270
+ clsName += ' active';
271
+ }
272
+ if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate) {
273
+ clsName += ' disabled';
274
+ }
275
+ html.push('<td class="day'+clsName+'">'+prevMonth.getDate() + '</td>');
276
+ if (prevMonth.getDay() == this.weekEnd) {
277
+ html.push('</tr>');
278
+ }
279
+ prevMonth.setDate(prevMonth.getDate()+1);
280
+ }
281
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
282
+ var currentYear = this.date.getFullYear();
283
+
284
+ var months = this.picker.find('.datepicker-months')
285
+ .find('th:eq(1)')
286
+ .text(year)
287
+ .end()
288
+ .find('span').removeClass('active');
289
+ if (currentYear == year) {
290
+ months.eq(this.date.getMonth()).addClass('active');
291
+ }
292
+ if (year < startYear || year > endYear) {
293
+ months.addClass('disabled');
294
+ }
295
+ if (year == startYear) {
296
+ months.slice(0, startMonth).addClass('disabled');
297
+ }
298
+ if (year == endYear) {
299
+ months.slice(endMonth+1).addClass('disabled');
300
+ }
301
+
302
+ html = '';
303
+ year = parseInt(year/10, 10) * 10;
304
+ var yearCont = this.picker.find('.datepicker-years')
305
+ .find('th:eq(1)')
306
+ .text(year + '-' + (year + 9))
307
+ .end()
308
+ .find('td');
309
+ year -= 1;
310
+ for (var i = -1; i < 11; i++) {
311
+ html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
312
+ year += 1;
313
+ }
314
+ yearCont.html(html);
315
+ },
316
+
317
+ updateNavArrows: function() {
318
+ var d = new Date(this.viewDate),
319
+ year = d.getFullYear(),
320
+ month = d.getMonth();
321
+ switch (this.viewMode) {
322
+ case 0:
323
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear() && month <= this.startDate.getMonth()) {
324
+ this.picker.find('.prev').css({visibility: 'hidden'});
325
+ } else {
326
+ this.picker.find('.prev').css({visibility: 'visible'});
327
+ }
328
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear() && month >= this.endDate.getMonth()) {
329
+ this.picker.find('.next').css({visibility: 'hidden'});
330
+ } else {
331
+ this.picker.find('.next').css({visibility: 'visible'});
332
+ }
333
+ break;
334
+ case 1:
335
+ case 2:
336
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear()) {
337
+ this.picker.find('.prev').css({visibility: 'hidden'});
338
+ } else {
339
+ this.picker.find('.prev').css({visibility: 'visible'});
340
+ }
341
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear()) {
342
+ this.picker.find('.next').css({visibility: 'hidden'});
343
+ } else {
344
+ this.picker.find('.next').css({visibility: 'visible'});
345
+ }
346
+ break;
347
+ }
348
+ },
349
+
350
+ click: function(e) {
351
+ e.stopPropagation();
352
+ e.preventDefault();
353
+ var target = $(e.target).closest('span, td, th');
354
+ if (target.length == 1) {
355
+ switch(target[0].nodeName.toLowerCase()) {
356
+ case 'th':
357
+ switch(target[0].className) {
358
+ case 'switch':
359
+ this.showMode(1);
360
+ break;
361
+ case 'prev':
362
+ case 'next':
363
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
364
+ switch(this.viewMode){
365
+ case 0:
366
+ this.viewDate = this.moveMonth(this.viewDate, dir);
367
+ break;
368
+ case 1:
369
+ case 2:
370
+ this.viewDate = this.moveYear(this.viewDate, dir);
371
+ break;
372
+ }
373
+ this.fill();
374
+ break;
375
+ }
376
+ break;
377
+ case 'span':
378
+ if (!target.is('.disabled')) {
379
+ this.viewDate.setDate(1);
380
+ if (target.is('.month')) {
381
+ var month = target.parent().find('span').index(target);
382
+ this.viewDate.setMonth(month);
383
+ } else {
384
+ var year = parseInt(target.text(), 10)||0;
385
+ this.viewDate.setFullYear(year);
386
+ }
387
+ this.showMode(-1);
388
+ this.fill();
389
+ }
390
+ break;
391
+ case 'td':
392
+ if (target.is('.day') && !target.is('.disabled')){
393
+ var day = parseInt(target.text(), 10)||1;
394
+ var year = this.viewDate.getFullYear(),
395
+ month = this.viewDate.getMonth();
396
+ if (target.is('.old')) {
397
+ if (month == 0) {
398
+ month = 11;
399
+ year -= 1;
400
+ } else {
401
+ month -= 1;
402
+ }
403
+ } else if (target.is('.new')) {
404
+ if (month == 11) {
405
+ month = 0;
406
+ year += 1;
407
+ } else {
408
+ month += 1;
409
+ }
410
+ }
411
+ this.date = new Date(year, month, day,0,0,0,0);
412
+ this.viewDate = new Date(year, month, day,0,0,0,0);
413
+ this.fill();
414
+ this.setValue();
415
+ this.element.trigger({
416
+ type: 'changeDate',
417
+ date: this.date
418
+ });
419
+ var element;
420
+ if (this.isInput) {
421
+ element = this.element;
422
+ } else if (this.component){
423
+ element = this.element.find('input');
424
+ }
425
+ if (element) {
426
+ element.change();
427
+ if (this.autoclose) {
428
+ element.blur();
429
+ }
430
+ }
431
+ }
432
+ break;
433
+ }
434
+ }
435
+ },
436
+
437
+ mousedown: function(e){
438
+ e.stopPropagation();
439
+ e.preventDefault();
440
+ },
441
+
442
+ moveMonth: function(date, dir){
443
+ if (!dir) return date;
444
+ var new_date = new Date(date.valueOf()),
445
+ day = new_date.getDate(),
446
+ month = new_date.getMonth(),
447
+ mag = Math.abs(dir),
448
+ new_month, test;
449
+ dir = dir > 0 ? 1 : -1;
450
+ if (mag == 1){
451
+ test = dir == -1
452
+ // If going back one month, make sure month is not current month
453
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
454
+ ? function(){ return new_date.getMonth() == month; }
455
+ // If going forward one month, make sure month is as expected
456
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
457
+ : function(){ return new_date.getMonth() != new_month; };
458
+ new_month = month + dir;
459
+ new_date.setMonth(new_month);
460
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
461
+ if (new_month < 0 || new_month > 11)
462
+ new_month = (new_month + 12) % 12;
463
+ } else {
464
+ // For magnitudes >1, move one month at a time...
465
+ for (var i=0; i<mag; i++)
466
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
467
+ new_date = this.moveMonth(new_date, dir);
468
+ // ...then reset the day, keeping it in the new month
469
+ new_month = new_date.getMonth();
470
+ new_date.setDate(day);
471
+ test = function(){ return new_month != new_date.getMonth(); };
472
+ }
473
+ // Common date-resetting loop -- if date is beyond end of month, make it
474
+ // end of month
475
+ while (test()){
476
+ new_date.setDate(--day);
477
+ new_date.setMonth(new_month);
478
+ }
479
+ return new_date;
480
+ },
481
+
482
+ moveYear: function(date, dir){
483
+ return this.moveMonth(date, dir*12);
484
+ },
485
+
486
+ keydown: function(e){
487
+ if (this.picker.is(':not(:visible)')){
488
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
489
+ this.show();
490
+ return;
491
+ }
492
+ var dateChanged = false,
493
+ dir, day, month;
494
+ switch(e.keyCode){
495
+ case 27: // escape
496
+ this.hide();
497
+ e.preventDefault();
498
+ break;
499
+ case 37: // left
500
+ case 39: // right
501
+ dir = e.keyCode == 37 ? -1 : 1;
502
+ if (e.ctrlKey){
503
+ this.date = this.moveYear(this.date, dir);
504
+ this.viewDate = this.moveYear(this.viewDate, dir);
505
+ } else if (e.shiftKey){
506
+ this.date = this.moveMonth(this.date, dir);
507
+ this.viewDate = this.moveMonth(this.viewDate, dir);
508
+ } else {
509
+ this.date.setDate(this.date.getDate() + dir);
510
+ this.viewDate.setDate(this.viewDate.getDate() + dir);
511
+ }
512
+ this.setValue();
513
+ this.update();
514
+ e.preventDefault();
515
+ dateChanged = true;
516
+ break;
517
+ case 38: // up
518
+ case 40: // down
519
+ dir = e.keyCode == 38 ? -1 : 1;
520
+ if (e.ctrlKey){
521
+ this.date = this.moveYear(this.date, dir);
522
+ this.viewDate = this.moveYear(this.viewDate, dir);
523
+ } else if (e.shiftKey){
524
+ this.date = this.moveMonth(this.date, dir);
525
+ this.viewDate = this.moveMonth(this.viewDate, dir);
526
+ } else {
527
+ this.date.setDate(this.date.getDate() + dir * 7);
528
+ this.viewDate.setDate(this.viewDate.getDate() + dir * 7);
529
+ }
530
+ this.setValue();
531
+ this.update();
532
+ e.preventDefault();
533
+ dateChanged = true;
534
+ break;
535
+ case 13: // enter
536
+ this.hide();
537
+ e.preventDefault();
538
+ break;
539
+ }
540
+ if (dateChanged){
541
+ this.element.trigger({
542
+ type: 'changeDate',
543
+ date: this.date
544
+ });
545
+ var element;
546
+ if (this.isInput) {
547
+ element = this.element;
548
+ } else if (this.component){
549
+ element = this.element.find('input');
550
+ }
551
+ if (element) {
552
+ element.change();
553
+ }
554
+ }
555
+ },
556
+
557
+ showMode: function(dir) {
558
+ if (dir) {
559
+ this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
560
+ }
561
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
562
+ this.updateNavArrows();
563
+ }
564
+ };
565
+
566
+ $.fn.datepicker = function ( option ) {
567
+ var args = Array.apply(null, arguments);
568
+ args.shift();
569
+ return this.each(function () {
570
+ var $this = $(this),
571
+ data = $this.data('datepicker'),
572
+ options = typeof option == 'object' && option;
573
+ if (!data) {
574
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
575
+ }
576
+ if (typeof option == 'string') data[option].apply(data, args);
577
+ });
578
+ };
579
+
580
+ $.fn.datepicker.defaults = {
581
+ };
582
+ $.fn.datepicker.Constructor = Datepicker;
583
+ var dates = $.fn.datepicker.dates = {
584
+ en: {
585
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
586
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
587
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
588
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
589
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
590
+ }
591
+ }
592
+
593
+ var DPGlobal = {
594
+ modes: [
595
+ {
596
+ clsName: 'days',
597
+ navFnc: 'Month',
598
+ navStep: 1
599
+ },
600
+ {
601
+ clsName: 'months',
602
+ navFnc: 'FullYear',
603
+ navStep: 1
604
+ },
605
+ {
606
+ clsName: 'years',
607
+ navFnc: 'FullYear',
608
+ navStep: 10
609
+ }],
610
+ isLeapYear: function (year) {
611
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
612
+ },
613
+ getDaysInMonth: function (year, month) {
614
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
615
+ },
616
+ validParts: /dd?|mm?|MM?|yy(?:yy)?/g,
617
+ nonpunctuation: /[^ -\/:-@\[-`{-~\t\n\r]+/g,
618
+ parseFormat: function(format){
619
+ // IE treats \0 as a string end in inputs (truncating the value),
620
+ // so it's a bad format delimiter, anyway
621
+ var separators = format.replace(this.validParts, '\0').split('\0'),
622
+ parts = format.match(this.validParts);
623
+ if (!separators || !separators.length || !parts || parts.length == 0){
624
+ throw new Error("Invalid date format.");
625
+ }
626
+ return {separators: separators, parts: parts};
627
+ },
628
+ parseDate: function(date, format, language) {
629
+ if (date instanceof Date) return date;
630
+ if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) {
631
+ var part_re = /([-+]\d+)([dmwy])/,
632
+ parts = date.match(/([-+]\d+)([dmwy])/g),
633
+ part, dir;
634
+ date = new Date();
635
+ for (var i=0; i<parts.length; i++) {
636
+ part = part_re.exec(parts[i]);
637
+ dir = parseInt(part[1]);
638
+ switch(part[2]){
639
+ case 'd':
640
+ date.setDate(date.getDate() + dir);
641
+ break;
642
+ case 'm':
643
+ date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
644
+ break;
645
+ case 'w':
646
+ date.setDate(date.getDate() + dir * 7);
647
+ break;
648
+ case 'y':
649
+ date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
650
+ break;
651
+ }
652
+ }
653
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
654
+ }
655
+ var parts = date ? date.match(this.nonpunctuation) : [],
656
+ date = new Date(),
657
+ parsed = {},
658
+ setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
659
+ setters_map = {
660
+ yyyy: function(d,v){ return d.setFullYear(v); },
661
+ yy: function(d,v){ return d.setFullYear(2000+v); },
662
+ m: function(d,v){
663
+ v -= 1;
664
+ d.setMonth(v);
665
+ while (d.getMonth() != v)
666
+ d.setDate(d.getDate()-1);
667
+ return d;
668
+ },
669
+ d: function(d,v){ return d.setDate(v); }
670
+ },
671
+ val, filtered, part;
672
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
673
+ setters_map['dd'] = setters_map['d'];
674
+ date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
675
+ if (parts.length == format.parts.length) {
676
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
677
+ val = parseInt(parts[i], 10)||1;
678
+ part = format.parts[i];
679
+ switch(part) {
680
+ case 'MM':
681
+ filtered = $(dates[language].months).filter(function(){
682
+ var m = this.slice(0, parts[i].length),
683
+ p = parts[i].slice(0, m.length);
684
+ return m == p;
685
+ });
686
+ val = $.inArray(filtered[0], dates[language].months) + 1;
687
+ break;
688
+ case 'M':
689
+ filtered = $(dates[language].monthsShort).filter(function(){
690
+ var m = this.slice(0, parts[i].length),
691
+ p = parts[i].slice(0, m.length);
692
+ return m == p;
693
+ });
694
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
695
+ break;
696
+ }
697
+ parsed[part] = val;
698
+ }
699
+ for (var i=0, s; i<setters_order.length; i++){
700
+ s = setters_order[i];
701
+ if (s in parsed)
702
+ setters_map[s](date, parsed[s])
703
+ }
704
+ }
705
+ return date;
706
+ },
707
+ formatDate: function(date, format, language){
708
+ var val = {
709
+ d: date.getDate(),
710
+ m: date.getMonth() + 1,
711
+ M: dates[language].monthsShort[date.getMonth()],
712
+ MM: dates[language].months[date.getMonth()],
713
+ yy: date.getFullYear().toString().substring(2),
714
+ yyyy: date.getFullYear()
715
+ };
716
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
717
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
718
+ var date = [],
719
+ seps = $.extend([], format.separators);
720
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
721
+ if (seps.length)
722
+ date.push(seps.shift())
723
+ date.push(val[format.parts[i]]);
724
+ }
725
+ return date.join('');
726
+ },
727
+ headTemplate: '<thead>'+
728
+ '<tr>'+
729
+ '<th class="prev"><i class="icon-arrow-left"/></th>'+
730
+ '<th colspan="5" class="switch"></th>'+
731
+ '<th class="next"><i class="icon-arrow-right"/></th>'+
732
+ '</tr>'+
733
+ '</thead>',
734
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
735
+ };
736
+ DPGlobal.template = '<div class="datepicker dropdown-menu">'+
737
+ '<div class="datepicker-days">'+
738
+ '<table class=" table-condensed">'+
739
+ DPGlobal.headTemplate+
740
+ '<tbody></tbody>'+
741
+ '</table>'+
742
+ '</div>'+
743
+ '<div class="datepicker-months">'+
744
+ '<table class="table-condensed">'+
745
+ DPGlobal.headTemplate+
746
+ DPGlobal.contTemplate+
747
+ '</table>'+
748
+ '</div>'+
749
+ '<div class="datepicker-years">'+
750
+ '<table class="table-condensed">'+
751
+ DPGlobal.headTemplate+
752
+ DPGlobal.contTemplate+
753
+ '</table>'+
754
+ '</div>'+
755
+ '</div>';
756
+
757
+ }( window.jQuery )