bootstrap-datepicker-rails 1.0.0.7 → 1.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19104dfe3f94c50ba9fbd11789fbf7212bd1db27
4
- data.tar.gz: 6e77b100cd5d0b9762e24917a3f0aebb74c8bd67
3
+ metadata.gz: 0707cb1b033e6f2dd26120672932d15b3fb14766
4
+ data.tar.gz: 5b7c2e83f55c220e3cd031ae4394e9e790596d7b
5
5
  SHA512:
6
- metadata.gz: 8714d1d79e78e68fb349779aaa3e69a3221db879eac25e340df87aae8251a92758856d417ab3a1adf9f32717f45eec7d68ccf36a989c60cfc9f1b5f14d9fcddc
7
- data.tar.gz: 32529e4389a5b4ebe7e46336b27030a22470d0dd974858f1d0cc9fb57d22902f794542409a00571c2e1f9fecf0d2a0dfe0741bbfc4b04747baf87decf214a760
6
+ metadata.gz: 7d4a34001568bdc7a377f48f385832330de7c3a74a7aaadc13bc4b0d4f5a891576f8eb38de81445f5e82801f4deb5977c7ebd0ed2e2f44e8be125118f18dbdd9
7
+ data.tar.gz: c21f9e0a107770101feebeb8fa5cf92b5bcc52fd959ae37c7298f082543ab90dced005499900de35063a2d6cf126eb2a1edab065975695671436db81c90fca4c
@@ -1,5 +1,5 @@
1
1
  module BootstrapDatepickerRails
2
2
  module Rails
3
- VERSION = "1.0.0.7"
3
+ VERSION = "1.1.0.1"
4
4
  end
5
5
  end
@@ -33,12 +33,9 @@
33
33
  var Datepicker = function(element, options) {
34
34
  var that = this;
35
35
 
36
+ this._process_options(options);
37
+
36
38
  this.element = $(element);
37
- this.language = options.language||this.element.data('date-language')||"en";
38
- this.language = this.language in dates ? this.language : this.language.split('-')[0]; //Check if "de-DE" style date is available, if not language should fallback to 2 letter code eg "de"
39
- this.language = this.language in dates ? this.language : "en";
40
- this.isRTL = dates[this.language].rtl||false;
41
- this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
42
39
  this.isInline = false;
43
40
  this.isInput = this.element.is('input');
44
41
  this.component = this.element.is('.date') ? this.element.find('.add-on, .btn') : false;
@@ -46,13 +43,6 @@
46
43
  if(this.component && this.component.length === 0)
47
44
  this.component = false;
48
45
 
49
- this.forceParse = true;
50
- if ('forceParse' in options) {
51
- this.forceParse = options.forceParse;
52
- } else if ('dateForceParse' in this.element.data()) {
53
- this.forceParse = this.element.data('date-force-parse');
54
- }
55
-
56
46
  this.picker = $(DPGlobal.template);
57
47
  this._buildEvents();
58
48
  this._attachEvents();
@@ -62,65 +52,17 @@
62
52
  } else {
63
53
  this.picker.addClass('datepicker-dropdown dropdown-menu');
64
54
  }
65
- if (this.isRTL){
55
+
56
+ if (this.o.rtl){
66
57
  this.picker.addClass('datepicker-rtl');
67
58
  this.picker.find('.prev i, .next i')
68
59
  .toggleClass('icon-arrow-left icon-arrow-right');
69
60
  }
70
61
 
71
- this.autoclose = false;
72
- if ('autoclose' in options) {
73
- this.autoclose = options.autoclose;
74
- } else if ('dateAutoclose' in this.element.data()) {
75
- this.autoclose = this.element.data('date-autoclose');
76
- }
77
-
78
- this.keyboardNavigation = true;
79
- if ('keyboardNavigation' in options) {
80
- this.keyboardNavigation = options.keyboardNavigation;
81
- } else if ('dateKeyboardNavigation' in this.element.data()) {
82
- this.keyboardNavigation = this.element.data('date-keyboard-navigation');
83
- }
84
62
 
85
- this.viewMode = this.startViewMode = 0;
86
- switch(options.startView || this.element.data('date-start-view')){
87
- case 2:
88
- case 'decade':
89
- this.viewMode = this.startViewMode = 2;
90
- break;
91
- case 1:
92
- case 'year':
93
- this.viewMode = this.startViewMode = 1;
94
- break;
95
- }
63
+ this.viewMode = this.o.startView;
96
64
 
97
- this.minViewMode = options.minViewMode||this.element.data('date-min-view-mode')||0;
98
- if (typeof this.minViewMode === 'string') {
99
- switch (this.minViewMode) {
100
- case 'months':
101
- this.minViewMode = 1;
102
- break;
103
- case 'years':
104
- this.minViewMode = 2;
105
- break;
106
- default:
107
- this.minViewMode = 0;
108
- break;
109
- }
110
- }
111
-
112
- this.viewMode = this.startViewMode = Math.max(this.startViewMode, this.minViewMode);
113
-
114
- this.todayBtn = (options.todayBtn||this.element.data('date-today-btn')||false);
115
- this.todayHighlight = (options.todayHighlight||this.element.data('date-today-highlight')||false);
116
-
117
- this.calendarWeeks = false;
118
- if ('calendarWeeks' in options) {
119
- this.calendarWeeks = options.calendarWeeks;
120
- } else if ('dateCalendarWeeks' in this.element.data()) {
121
- this.calendarWeeks = this.element.data('date-calendar-weeks');
122
- }
123
- if (this.calendarWeeks)
65
+ if (this.o.calendarWeeks)
124
66
  this.picker.find('tfoot th.today')
125
67
  .attr('colspan', function(i, val){
126
68
  return parseInt(val) + 1;
@@ -128,18 +70,12 @@
128
70
 
129
71
  this._allow_update = false;
130
72
 
131
- this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
132
- this.weekEnd = ((this.weekStart + 6) % 7);
133
- this.startDate = -Infinity;
134
- this.endDate = Infinity;
135
- this.daysOfWeekDisabled = [];
136
- this.beforeShowDay = options.beforeShowDay || $.noop;
137
- this.setStartDate(options.startDate||this.element.data('date-startdate'));
138
- this.setEndDate(options.endDate||this.element.data('date-enddate'));
139
- this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
73
+ this.setStartDate(this.o.startDate);
74
+ this.setEndDate(this.o.endDate);
75
+ this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled);
76
+
140
77
  this.fillDow();
141
78
  this.fillMonths();
142
- this.setRange(options.range);
143
79
 
144
80
  this._allow_update = true;
145
81
 
@@ -154,6 +90,68 @@
154
90
  Datepicker.prototype = {
155
91
  constructor: Datepicker,
156
92
 
93
+ _process_options: function(opts){
94
+ // Store raw options for reference
95
+ this._o = $.extend({}, this._o, opts);
96
+ // Processed options
97
+ var o = this.o = $.extend({}, this._o);
98
+
99
+ // Check if "de-DE" style date is available, if not language should
100
+ // fallback to 2 letter code eg "de"
101
+ var lang = o.language;
102
+ if (!dates[lang]) {
103
+ lang = lang.split('-')[0];
104
+ if (!dates[lang])
105
+ lang = $.fn.datepicker.defaults.language;
106
+ }
107
+ o.language = lang;
108
+
109
+ switch(o.startView){
110
+ case 2:
111
+ case 'decade':
112
+ o.startView = 2;
113
+ break;
114
+ case 1:
115
+ case 'year':
116
+ o.startView = 1;
117
+ break;
118
+ default:
119
+ o.startView = 0;
120
+ }
121
+
122
+ switch (o.minViewMode) {
123
+ case 1:
124
+ case 'months':
125
+ o.minViewMode = 1;
126
+ break;
127
+ case 2:
128
+ case 'years':
129
+ o.minViewMode = 2;
130
+ break;
131
+ default:
132
+ o.minViewMode = 0;
133
+ }
134
+
135
+ o.startView = Math.max(o.startView, o.minViewMode);
136
+
137
+ o.weekStart %= 7;
138
+ o.weekEnd = ((o.weekStart + 6) % 7);
139
+
140
+ var format = DPGlobal.parseFormat(o.format)
141
+ if (o.startDate !== -Infinity) {
142
+ o.startDate = DPGlobal.parseDate(o.startDate, format, o.language);
143
+ }
144
+ if (o.endDate !== Infinity) {
145
+ o.endDate = DPGlobal.parseDate(o.endDate, format, o.language);
146
+ }
147
+
148
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled||[];
149
+ if (!$.isArray(o.daysOfWeekDisabled))
150
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled.split(/[,\s]*/);
151
+ o.daysOfWeekDisabled = $.map(o.daysOfWeekDisabled, function (d) {
152
+ return parseInt(d, 10);
153
+ });
154
+ },
157
155
  _events: [],
158
156
  _secondaryEvents: [],
159
157
  _applyEvents: function(evs){
@@ -214,7 +212,12 @@
214
212
  [$(document), {
215
213
  mousedown: $.proxy(function (e) {
216
214
  // Clicked outside the datepicker, hide it
217
- if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
215
+ if (!(
216
+ this.element.is(e.target) ||
217
+ this.element.find(e.target).size() ||
218
+ this.picker.is(e.target) ||
219
+ this.picker.find(e.target).size()
220
+ )) {
218
221
  this.hide();
219
222
  }
220
223
  }, this)
@@ -236,16 +239,14 @@
236
239
  this._unapplyEvents(this._secondaryEvents);
237
240
  },
238
241
  _trigger: function(event, altdate){
239
- var date = altdate || this.date;
240
- date = new Date(date.getTime() + (date.getTimezoneOffset()*60000));
242
+ var date = altdate || this.date,
243
+ local_date = new Date(date.getTime() + (date.getTimezoneOffset()*60000));
241
244
 
242
245
  this.element.trigger({
243
246
  type: event,
244
- date: date,
247
+ date: local_date,
245
248
  format: $.proxy(function(altformat){
246
- var format = this.format;
247
- if (altformat)
248
- format = DPGlobal.parseFormat(altformat);
249
+ var format = altformat || this.o.format;
249
250
  return DPGlobal.formatDate(date, format, this.language);
250
251
  }, this)
251
252
  });
@@ -269,11 +270,11 @@
269
270
  if (!this.picker.is(':visible')) return;
270
271
  this.picker.hide().detach();
271
272
  this._detachSecondaryEvents();
272
- this.viewMode = this.startViewMode;
273
+ this.viewMode = this.o.startView;
273
274
  this.showMode();
274
275
 
275
276
  if (
276
- this.forceParse &&
277
+ this.o.forceParse &&
277
278
  (
278
279
  this.isInput && this.element.val() ||
279
280
  this.hasInput && this.element.find('input').val()
@@ -325,36 +326,24 @@
325
326
 
326
327
  getFormattedDate: function(format) {
327
328
  if (format === undefined)
328
- format = this.format;
329
- return DPGlobal.formatDate(this.date, format, this.language);
329
+ format = this.o.format;
330
+ return DPGlobal.formatDate(this.date, format, this.o.language);
330
331
  },
331
332
 
332
333
  setStartDate: function(startDate){
333
- this.startDate = startDate||-Infinity;
334
- if (this.startDate !== -Infinity) {
335
- this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
336
- }
334
+ this._process_options({startDate: startDate});
337
335
  this.update();
338
336
  this.updateNavArrows();
339
337
  },
340
338
 
341
339
  setEndDate: function(endDate){
342
- this.endDate = endDate||Infinity;
343
- if (this.endDate !== Infinity) {
344
- this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
345
- }
340
+ this._process_options({endDate: endDate});
346
341
  this.update();
347
342
  this.updateNavArrows();
348
343
  },
349
344
 
350
345
  setDaysOfWeekDisabled: function(daysOfWeekDisabled){
351
- this.daysOfWeekDisabled = daysOfWeekDisabled||[];
352
- if (!$.isArray(this.daysOfWeekDisabled)) {
353
- this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
354
- }
355
- this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) {
356
- return parseInt(d, 10);
357
- });
346
+ this._process_options({daysOfWeekDisabled: daysOfWeekDisabled});
358
347
  this.update();
359
348
  this.updateNavArrows();
360
349
  },
@@ -386,14 +375,14 @@
386
375
  delete this.element.data().date;
387
376
  }
388
377
 
389
- this.date = DPGlobal.parseDate(date, this.format, this.language);
378
+ this.date = DPGlobal.parseDate(date, this.o.format, this.o.language);
390
379
 
391
380
  if(fromArgs) this.setValue();
392
381
 
393
- if (this.date < this.startDate) {
394
- this.viewDate = new Date(this.startDate);
395
- } else if (this.date > this.endDate) {
396
- this.viewDate = new Date(this.endDate);
382
+ if (this.date < this.o.startDate) {
383
+ this.viewDate = new Date(this.o.startDate);
384
+ } else if (this.date > this.o.endDate) {
385
+ this.viewDate = new Date(this.o.endDate);
397
386
  } else {
398
387
  this.viewDate = new Date(this.date);
399
388
  }
@@ -401,15 +390,15 @@
401
390
  },
402
391
 
403
392
  fillDow: function(){
404
- var dowCnt = this.weekStart,
393
+ var dowCnt = this.o.weekStart,
405
394
  html = '<tr>';
406
- if(this.calendarWeeks){
395
+ if(this.o.calendarWeeks){
407
396
  var cell = '<th class="cw">&nbsp;</th>';
408
397
  html += cell;
409
398
  this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
410
399
  }
411
- while (dowCnt < this.weekStart + 7) {
412
- html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
400
+ while (dowCnt < this.o.weekStart + 7) {
401
+ html += '<th class="dow">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>';
413
402
  }
414
403
  html += '</tr>';
415
404
  this.picker.find('.datepicker-days thead').append(html);
@@ -419,7 +408,7 @@
419
408
  var html = '',
420
409
  i = 0;
421
410
  while (i < 12) {
422
- html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
411
+ html += '<span class="month">'+dates[this.o.language].monthsShort[i++]+'</span>';
423
412
  }
424
413
  this.picker.find('.datepicker-months td').html(html);
425
414
  },
@@ -444,7 +433,7 @@
444
433
  cls.push('new');
445
434
  }
446
435
  // Compare internal UTC date with local today, not UTC today
447
- if (this.todayHighlight &&
436
+ if (this.o.todayHighlight &&
448
437
  date.getUTCFullYear() == today.getFullYear() &&
449
438
  date.getUTCMonth() == today.getMonth() &&
450
439
  date.getUTCDate() == today.getDate()) {
@@ -453,8 +442,8 @@
453
442
  if (currentDate && date.valueOf() == currentDate) {
454
443
  cls.push('active');
455
444
  }
456
- if (date.valueOf() < this.startDate || date.valueOf() > this.endDate ||
457
- $.inArray(date.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
445
+ if (date.valueOf() < this.o.startDate || date.valueOf() > this.o.endDate ||
446
+ $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1) {
458
447
  cls.push('disabled');
459
448
  }
460
449
  if (this.range){
@@ -472,37 +461,40 @@
472
461
  var d = new Date(this.viewDate),
473
462
  year = d.getUTCFullYear(),
474
463
  month = d.getUTCMonth(),
475
- startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
476
- startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
477
- endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
478
- endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
464
+ startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
465
+ startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity,
466
+ endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity,
467
+ endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
479
468
  currentDate = this.date && this.date.valueOf(),
480
469
  tooltip;
481
470
  this.picker.find('.datepicker-days thead th.datepicker-switch')
482
- .text(dates[this.language].months[month]+' '+year);
471
+ .text(dates[this.o.language].months[month]+' '+year);
483
472
  this.picker.find('tfoot th.today')
484
- .text(dates[this.language].today)
485
- .toggle(this.todayBtn !== false);
473
+ .text(dates[this.o.language].today)
474
+ .toggle(this.o.todayBtn !== false);
475
+ this.picker.find('tfoot th.clear')
476
+ .text(dates[this.o.language].clear)
477
+ .toggle(this.o.clearBtn !== false);
486
478
  this.updateNavArrows();
487
479
  this.fillMonths();
488
480
  var prevMonth = UTCDate(year, month-1, 28,0,0,0,0),
489
481
  day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
490
482
  prevMonth.setUTCDate(day);
491
- prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
483
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.o.weekStart + 7)%7);
492
484
  var nextMonth = new Date(prevMonth);
493
485
  nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
494
486
  nextMonth = nextMonth.valueOf();
495
487
  var html = [];
496
488
  var clsName;
497
489
  while(prevMonth.valueOf() < nextMonth) {
498
- if (prevMonth.getUTCDay() == this.weekStart) {
490
+ if (prevMonth.getUTCDay() == this.o.weekStart) {
499
491
  html.push('<tr>');
500
- if(this.calendarWeeks){
492
+ if(this.o.calendarWeeks){
501
493
  // ISO 8601: First week contains first thursday.
502
494
  // ISO also states week starts on Monday, but we can be more abstract here.
503
495
  var
504
496
  // Start of current week: based on weekstart/current date
505
- ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
497
+ ws = new Date(+prevMonth + (this.o.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
506
498
  // Thursday of this week
507
499
  th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
508
500
  // First Thursday of year, year from thursday
@@ -516,7 +508,7 @@
516
508
  clsName = this.getClassNames(prevMonth);
517
509
  clsName.push('day');
518
510
 
519
- var before = this.beforeShowDay(prevMonth);
511
+ var before = this.o.beforeShowDay(prevMonth);
520
512
  if (before === undefined)
521
513
  before = {};
522
514
  else if (typeof(before) === 'boolean')
@@ -532,7 +524,7 @@
532
524
 
533
525
  clsName = $.unique(clsName);
534
526
  html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
535
- if (prevMonth.getUTCDay() == this.weekEnd) {
527
+ if (prevMonth.getUTCDay() == this.o.weekEnd) {
536
528
  html.push('</tr>');
537
529
  }
538
530
  prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
@@ -567,7 +559,7 @@
567
559
  .find('td');
568
560
  year -= 1;
569
561
  for (var i = -1; i < 11; i++) {
570
- html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
562
+ html += '<span class="year'+(i == -1 ? ' old' : i == 10 ? ' new' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
571
563
  year += 1;
572
564
  }
573
565
  yearCont.html(html);
@@ -581,12 +573,12 @@
581
573
  month = d.getUTCMonth();
582
574
  switch (this.viewMode) {
583
575
  case 0:
584
- if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
576
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() && month <= this.o.startDate.getUTCMonth()) {
585
577
  this.picker.find('.prev').css({visibility: 'hidden'});
586
578
  } else {
587
579
  this.picker.find('.prev').css({visibility: 'visible'});
588
580
  }
589
- if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
581
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() && month >= this.o.endDate.getUTCMonth()) {
590
582
  this.picker.find('.next').css({visibility: 'hidden'});
591
583
  } else {
592
584
  this.picker.find('.next').css({visibility: 'visible'});
@@ -594,12 +586,12 @@
594
586
  break;
595
587
  case 1:
596
588
  case 2:
597
- if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
589
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()) {
598
590
  this.picker.find('.prev').css({visibility: 'hidden'});
599
591
  } else {
600
592
  this.picker.find('.prev').css({visibility: 'visible'});
601
593
  }
602
- if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
594
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()) {
603
595
  this.picker.find('.next').css({visibility: 'hidden'});
604
596
  } else {
605
597
  this.picker.find('.next').css({visibility: 'visible'});
@@ -637,9 +629,18 @@
637
629
  date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
638
630
 
639
631
  this.showMode(-2);
640
- var which = this.todayBtn == 'linked' ? null : 'view';
632
+ var which = this.o.todayBtn == 'linked' ? null : 'view';
641
633
  this._setDate(date, which);
642
634
  break;
635
+ case 'clear':
636
+ if (this.isInput)
637
+ this.element.val("");
638
+ else
639
+ this.element.find('input').val("");
640
+ this.update();
641
+ if (this.o.autoclose)
642
+ this.hide();
643
+ break;
643
644
  }
644
645
  break;
645
646
  case 'span':
@@ -651,7 +652,7 @@
651
652
  var year = this.viewDate.getUTCFullYear();
652
653
  this.viewDate.setUTCMonth(month);
653
654
  this._trigger('changeMonth', this.viewDate);
654
- if ( this.minViewMode == 1 ) {
655
+ if (this.o.minViewMode === 1) {
655
656
  this._setDate(UTCDate(year, month, day,0,0,0,0));
656
657
  }
657
658
  } else {
@@ -660,7 +661,7 @@
660
661
  var month = 0;
661
662
  this.viewDate.setUTCFullYear(year);
662
663
  this._trigger('changeYear', this.viewDate);
663
- if ( this.minViewMode == 2 ) {
664
+ if (this.o.minViewMode === 2) {
664
665
  this._setDate(UTCDate(year, month, day,0,0,0,0));
665
666
  }
666
667
  }
@@ -697,9 +698,9 @@
697
698
 
698
699
  _setDate: function(date, which){
699
700
  if (!which || which == 'date')
700
- this.date = date;
701
+ this.date = new Date(date);
701
702
  if (!which || which == 'view')
702
- this.viewDate = date;
703
+ this.viewDate = new Date(date);
703
704
  this.fill();
704
705
  this.setValue();
705
706
  this._trigger('changeDate');
@@ -711,7 +712,7 @@
711
712
  }
712
713
  if (element) {
713
714
  element.change();
714
- if (this.autoclose && (!which || which == 'date')) {
715
+ if (this.o.autoclose && (!which || which == 'date')) {
715
716
  this.hide();
716
717
  }
717
718
  }
@@ -762,7 +763,7 @@
762
763
  },
763
764
 
764
765
  dateWithinRange: function(date){
765
- return date >= this.startDate && date <= this.endDate;
766
+ return date >= this.o.startDate && date <= this.o.endDate;
766
767
  },
767
768
 
768
769
  keydown: function(e){
@@ -781,7 +782,7 @@
781
782
  break;
782
783
  case 37: // left
783
784
  case 39: // right
784
- if (!this.keyboardNavigation) break;
785
+ if (!this.o.keyboardNavigation) break;
785
786
  dir = e.keyCode == 37 ? -1 : 1;
786
787
  if (e.ctrlKey){
787
788
  newDate = this.moveYear(this.date, dir);
@@ -806,7 +807,7 @@
806
807
  break;
807
808
  case 38: // up
808
809
  case 40: // down
809
- if (!this.keyboardNavigation) break;
810
+ if (!this.o.keyboardNavigation) break;
810
811
  dir = e.keyCode == 38 ? -1 : 1;
811
812
  if (e.ctrlKey){
812
813
  newDate = this.moveYear(this.date, dir);
@@ -853,7 +854,7 @@
853
854
 
854
855
  showMode: function(dir) {
855
856
  if (dir) {
856
- this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
857
+ this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir));
857
858
  }
858
859
  /*
859
860
  vitalets: fixing bug of very special conditions:
@@ -895,7 +896,7 @@
895
896
  },
896
897
  dateUpdated: function(e){
897
898
  var dp = $(e.target).data('datepicker'),
898
- new_date = e.date,
899
+ new_date = dp.getUTCDate(),
899
900
  i = $.inArray(e.target, this.inputs),
900
901
  l = this.inputs.length;
901
902
  if (i == -1) return;
@@ -920,33 +921,101 @@
920
921
  }
921
922
  };
922
923
 
924
+ function opts_from_el(el, prefix){
925
+ // Derive options from element data-attrs
926
+ var data = $(el).data(),
927
+ out = {}, inkey,
928
+ replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])'),
929
+ prefix = new RegExp('^' + prefix.toLowerCase());
930
+ for (var key in data)
931
+ if (prefix.test(key)){
932
+ inkey = key.replace(replace, function(_,a){ return a.toLowerCase(); });
933
+ out[inkey] = data[key];
934
+ }
935
+ return out;
936
+ }
937
+
938
+ function opts_from_locale(lang){
939
+ // Derive options from locale plugins
940
+ var out = {};
941
+ // Check if "de-DE" style date is available, if not language should
942
+ // fallback to 2 letter code eg "de"
943
+ if (!dates[lang]) {
944
+ lang = lang.split('-')[0]
945
+ if (!dates[lang])
946
+ return;
947
+ }
948
+ var d = dates[lang];
949
+ $.each($.fn.datepicker.locale_opts, function(i,k){
950
+ if (k in d)
951
+ out[k] = d[k];
952
+ });
953
+ return out;
954
+ }
955
+
923
956
  var old = $.fn.datepicker;
924
957
  $.fn.datepicker = function ( option ) {
925
958
  var args = Array.apply(null, arguments);
926
959
  args.shift();
927
- return this.each(function () {
960
+ var internal_return,
961
+ this_return;
962
+ this.each(function () {
928
963
  var $this = $(this),
929
964
  data = $this.data('datepicker'),
930
965
  options = typeof option == 'object' && option;
931
966
  if (!data) {
932
- if ($this.is('.input-daterange') || options.inputs){
933
- var opts = {
934
- inputs: options.inputs || $this.find('input').toArray()
967
+ var elopts = opts_from_el(this, 'date'),
968
+ // Preliminary otions
969
+ xopts = $.extend({}, $.fn.datepicker.defaults, elopts, options),
970
+ locopts = opts_from_locale(xopts.language),
971
+ // Options priority: js args, data-attrs, locales, defaults
972
+ opts = $.extend({}, $.fn.datepicker.defaults, locopts, elopts, options);
973
+ if ($this.is('.input-daterange') || opts.inputs){
974
+ var ropts = {
975
+ inputs: opts.inputs || $this.find('input').toArray()
935
976
  };
936
- $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, $.fn.datepicker.defaults,options))));
977
+ $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, ropts))));
937
978
  }
938
979
  else{
939
- $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
980
+ $this.data('datepicker', (data = new Datepicker(this, opts)));
940
981
  }
941
982
  }
942
983
  if (typeof option == 'string' && typeof data[option] == 'function') {
943
- data[option].apply(data, args);
984
+ internal_return = data[option].apply(data, args);
985
+ if (internal_return !== undefined)
986
+ return false;
944
987
  }
945
988
  });
989
+ if (internal_return !== undefined)
990
+ return internal_return;
991
+ else
992
+ return this;
946
993
  };
947
994
 
948
995
  $.fn.datepicker.defaults = {
996
+ autoclose: false,
997
+ beforeShowDay: $.noop,
998
+ calendarWeeks: false,
999
+ clearBtn: false,
1000
+ daysOfWeekDisabled: [],
1001
+ endDate: Infinity,
1002
+ forceParse: true,
1003
+ format: 'mm/dd/yyyy',
1004
+ keyboardNavigation: true,
1005
+ language: 'en',
1006
+ minViewMode: 0,
1007
+ rtl: false,
1008
+ startDate: -Infinity,
1009
+ startView: 0,
1010
+ todayBtn: false,
1011
+ todayHighlight: false,
1012
+ weekStart: 0
949
1013
  };
1014
+ $.fn.datepicker.locale_opts = [
1015
+ 'format',
1016
+ 'rtl',
1017
+ 'weekStart'
1018
+ ];
950
1019
  $.fn.datepicker.Constructor = Datepicker;
951
1020
  var dates = $.fn.datepicker.dates = {
952
1021
  en: {
@@ -955,7 +1024,8 @@
955
1024
  daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
956
1025
  months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
957
1026
  monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
958
- today: "Today"
1027
+ today: "Today",
1028
+ clear: "Clear"
959
1029
  }
960
1030
  };
961
1031
 
@@ -996,6 +1066,8 @@
996
1066
  },
997
1067
  parseDate: function(date, format, language) {
998
1068
  if (date instanceof Date) return date;
1069
+ if (typeof format === 'string')
1070
+ format = DPGlobal.parseFormat(format);
999
1071
  if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)) {
1000
1072
  var part_re = /([\-+]\d+)([dmwy])/,
1001
1073
  parts = date.match(/([\-+]\d+)([dmwy])/g),
@@ -1086,6 +1158,8 @@
1086
1158
  return date;
1087
1159
  },
1088
1160
  formatDate: function(date, format, language){
1161
+ if (typeof format === 'string')
1162
+ format = DPGlobal.parseFormat(format);
1089
1163
  var val = {
1090
1164
  d: date.getUTCDate(),
1091
1165
  D: dates[language].daysShort[date.getUTCDay()],
@@ -1100,7 +1174,7 @@
1100
1174
  val.mm = (val.m < 10 ? '0' : '') + val.m;
1101
1175
  var date = [],
1102
1176
  seps = $.extend([], format.separators);
1103
- for (var i=0, cnt = format.parts.length; i < cnt; i++) {
1177
+ for (var i=0, cnt = format.parts.length; i <= cnt; i++) {
1104
1178
  if (seps.length)
1105
1179
  date.push(seps.shift());
1106
1180
  date.push(val[format.parts[i]]);
@@ -1115,7 +1189,7 @@
1115
1189
  '</tr>'+
1116
1190
  '</thead>',
1117
1191
  contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1118
- footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
1192
+ footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr><tr><th colspan="7" class="clear"></th></tr></tfoot>'
1119
1193
  };
1120
1194
  DPGlobal.template = '<div class="datepicker">'+
1121
1195
  '<div class="datepicker-days">'+
@@ -111,7 +111,7 @@
111
111
  border-color: #fdf59a #fdf59a #fbed50;
112
112
  border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
113
113
  filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
114
- color: #000 !important;
114
+ color: #000;
115
115
  }
116
116
  .datepicker table tr td.today:hover,
117
117
  .datepicker table tr td.today:hover:hover,
@@ -145,6 +145,12 @@
145
145
  .datepicker table tr td.today.disabled:hover.active {
146
146
  background-color: #fbf069 \9;
147
147
  }
148
+ .datepicker table tr td.today:hover:hover {
149
+ color: #000;
150
+ }
151
+ .datepicker table tr td.today.active:hover {
152
+ color: #fff;
153
+ }
148
154
  .datepicker table tr td.range,
149
155
  .datepicker table tr td.range:hover,
150
156
  .datepicker table tr td.range.disabled,
@@ -380,18 +386,19 @@
380
386
  .datepicker table tr td span.active.disabled:hover.active {
381
387
  background-color: #003399 \9;
382
388
  }
383
- .datepicker table tr td span.old {
389
+ .datepicker table tr td span.old,
390
+ .datepicker table tr td span.new {
384
391
  color: #999999;
385
392
  }
386
393
  .datepicker th.datepicker-switch {
387
394
  width: 145px;
388
395
  }
389
396
  .datepicker thead tr:first-child th,
390
- .datepicker tfoot tr:first-child th {
397
+ .datepicker tfoot tr th {
391
398
  cursor: pointer;
392
399
  }
393
400
  .datepicker thead tr:first-child th:hover,
394
- .datepicker tfoot tr:first-child th:hover {
401
+ .datepicker tfoot tr th:hover {
395
402
  background: #eeeeee;
396
403
  }
397
404
  .datepicker .cw {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-datepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.7
4
+ version: 1.1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gonzalo Rodríguez-Baltanás Díaz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-14 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties