bootstrap-datepicker-rails 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  *.gem
3
+ bootstrap-datepicker
data/README.md CHANGED
@@ -58,7 +58,7 @@ $('.datepicker').datepicker()
58
58
 
59
59
  String. Default: 'mm/dd/yyyy'
60
60
 
61
- The date format, combination of d, dd, m, mm, yy, yyy.
61
+ The date format, combination of d, dd, m, mm, M, MM, yy, yyy.
62
62
 
63
63
  #### weekStart
64
64
 
@@ -78,6 +78,12 @@ String. Default: End of time
78
78
 
79
79
  The latest date that may be selected; all later dates will be disabled.
80
80
 
81
+ #### autoclose
82
+
83
+ Boolean. Default: false
84
+
85
+ Whether or not to close the datepicker immediately when a date is selected.
86
+
81
87
  ### Markup
82
88
 
83
89
  Format a component.
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
1
  #!/usr/bin/env rake
2
2
  require File.expand_path('../lib/bootstrap-datepicker-rails/version', __FILE__)
3
3
 
4
+ desc "Update assets"
5
+ task 'update' do
6
+ system("rm -rf bootstrap-datepicker")
7
+ system("git clone git://github.com/eternicode/bootstrap-datepicker.git")
8
+ system("cp bootstrap-datepicker/css/datepicker.css vendor/assets/stylesheets/bootstrap-datepicker.css")
9
+ system("cp bootstrap-datepicker/js/bootstrap-datepicker.js vendor/assets/javascripts/bootstrap-datepicker.js")
10
+ end
11
+
4
12
  desc "Build the gem"
5
13
  task "build" do
6
14
  system("gem build bootstrap-datepicker-rails.gemspec")
@@ -1,5 +1,5 @@
1
1
  module BootstrapDatepickerRails
2
2
  module Rails
3
- VERSION = "0.3"
3
+ VERSION = "0.4"
4
4
  end
5
5
  end
@@ -1,38 +1,38 @@
1
1
  /* =========================================================
2
- * bootstrap-datepicker.js
3
- * http://www.eyecon.ro/bootstrap-datepicker
4
- * =========================================================
5
- * Copyright 2012 Stefan Petre
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- * ========================================================= */
19
-
2
+ * bootstrap-datepicker.js
3
+ * http://www.eyecon.ro/bootstrap-datepicker
4
+ * =========================================================
5
+ * Copyright 2012 Stefan Petre
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================= */
19
+
20
20
  !function( $ ) {
21
-
21
+
22
22
  // Picker object
23
-
23
+
24
24
  var Datepicker = function(element, options){
25
25
  this.element = $(element);
26
26
  this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
27
27
  this.picker = $(DPGlobal.template)
28
- .appendTo('body')
29
- .on({
30
- click: $.proxy(this.click, this),
31
- mousedown: $.proxy(this.mousedown, this)
32
- });
28
+ .appendTo('body')
29
+ .on({
30
+ click: $.proxy(this.click, this),
31
+ mousedown: $.proxy(this.mousedown, this)
32
+ });
33
33
  this.isInput = this.element.is('input');
34
34
  this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
35
-
35
+
36
36
  if (this.isInput) {
37
37
  this.element.on({
38
38
  focus: $.proxy(this.show, this),
@@ -47,6 +47,13 @@
47
47
  }
48
48
  }
49
49
 
50
+ this.autoclose = false;
51
+ if ('autoclose' in options) {
52
+ this.autoclose = options.autoclose;
53
+ } else if ('dateAutoclose' in this.element.data()) {
54
+ this.autoclose = this.element.data('date-autoclose');
55
+ }
56
+
50
57
  this.viewMode = 0;
51
58
  this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
52
59
  this.weekEnd = this.weekStart == 0 ? 6 : this.weekStart - 1;
@@ -59,7 +66,7 @@
59
66
  this.update();
60
67
  this.showMode();
61
68
  };
62
-
69
+
63
70
  Datepicker.prototype = {
64
71
  constructor: Datepicker,
65
72
 
@@ -87,25 +94,25 @@
87
94
  // event triggers a hide before the click event can stop propagation.
88
95
  if ($.browser.msie) {
89
96
  var t = this, args = arguments;
90
-
97
+
91
98
  function cancel_hide(){
92
99
  clearTimeout(hide_timeout);
93
100
  e.target.focus();
94
101
  t.picker.off('click', cancel_hide);
95
102
  }
96
-
103
+
97
104
  function do_hide(){
98
105
  t.hide.apply(t, args);
99
106
  t.picker.off('click', cancel_hide);
100
107
  }
101
-
108
+
102
109
  this.picker.on('click', cancel_hide);
103
110
  var hide_timeout = setTimeout(do_hide, 100);
104
111
  } else {
105
112
  return this.hide.apply(this, arguments);
106
113
  }
107
114
  },
108
-
115
+
109
116
  hide: function(){
110
117
  this.picker.hide();
111
118
  $(window).off('resize', this.place);
@@ -120,7 +127,7 @@
120
127
  date: this.date
121
128
  });
122
129
  },
123
-
130
+
124
131
  setValue: function() {
125
132
  var formated = DPGlobal.formatDate(this.date, this.format);
126
133
  if (!this.isInput) {
@@ -132,7 +139,7 @@
132
139
  this.element.prop('value', formated);
133
140
  }
134
141
  },
135
-
142
+
136
143
  setStartDate: function(startDate){
137
144
  this.startDate = startDate||-Infinity;
138
145
  if (this.startDate !== -Infinity) {
@@ -141,7 +148,7 @@
141
148
  this.update();
142
149
  this.updateNavArrows();
143
150
  },
144
-
151
+
145
152
  setEndDate: function(endDate){
146
153
  this.endDate = endDate||Infinity;
147
154
  if (this.endDate !== Infinity) {
@@ -150,7 +157,7 @@
150
157
  this.update();
151
158
  this.updateNavArrows();
152
159
  },
153
-
160
+
154
161
  place: function(){
155
162
  var offset = this.component ? this.component.offset() : this.element.offset();
156
163
  this.picker.css({
@@ -158,7 +165,7 @@
158
165
  left: offset.left
159
166
  });
160
167
  },
161
-
168
+
162
169
  update: function(){
163
170
  this.date = DPGlobal.parseDate(
164
171
  this.isInput ? this.element.prop('value') : this.element.data('date'),
@@ -173,7 +180,7 @@
173
180
  }
174
181
  this.fill();
175
182
  },
176
-
183
+
177
184
  fillDow: function(){
178
185
  var dowCnt = this.weekStart;
179
186
  var html = '<tr>';
@@ -183,7 +190,7 @@
183
190
  html += '</tr>';
184
191
  this.picker.find('.datepicker-days thead').append(html);
185
192
  },
186
-
193
+
187
194
  fillMonths: function(){
188
195
  var html = '';
189
196
  var i = 0
@@ -192,22 +199,22 @@
192
199
  }
193
200
  this.picker.find('.datepicker-months td').html(html);
194
201
  },
195
-
202
+
196
203
  fill: function() {
197
204
  var d = new Date(this.viewDate),
198
- year = d.getFullYear(),
199
- month = d.getMonth(),
200
- startYear = this.startDate !== -Infinity ? this.startDate.getFullYear() : -Infinity,
201
- startMonth = this.startDate !== -Infinity ? this.startDate.getMonth() : -Infinity,
202
- endYear = this.endDate !== Infinity ? this.endDate.getFullYear() : Infinity,
203
- endMonth = this.endDate !== Infinity ? this.endDate.getMonth() : Infinity,
204
- currentDate = this.date.valueOf();
205
+ year = d.getFullYear(),
206
+ month = d.getMonth(),
207
+ startYear = this.startDate !== -Infinity ? this.startDate.getFullYear() : -Infinity,
208
+ startMonth = this.startDate !== -Infinity ? this.startDate.getMonth() : -Infinity,
209
+ endYear = this.endDate !== Infinity ? this.endDate.getFullYear() : Infinity,
210
+ endMonth = this.endDate !== Infinity ? this.endDate.getMonth() : Infinity,
211
+ currentDate = this.date.valueOf();
205
212
  this.picker.find('.datepicker-days th:eq(1)')
206
- .text(DPGlobal.dates.months[month]+' '+year);
213
+ .text(DPGlobal.dates.months[month]+' '+year);
207
214
  this.updateNavArrows();
208
215
  this.fillMonths();
209
216
  var prevMonth = new Date(year, month-1, 28,0,0,0,0),
210
- day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
217
+ day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
211
218
  prevMonth.setDate(day);
212
219
  prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
213
220
  var nextMonth = new Date(prevMonth);
@@ -239,12 +246,12 @@
239
246
  }
240
247
  this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
241
248
  var currentYear = this.date.getFullYear();
242
-
249
+
243
250
  var months = this.picker.find('.datepicker-months')
244
- .find('th:eq(1)')
245
- .text(year)
246
- .end()
247
- .find('span').removeClass('active');
251
+ .find('th:eq(1)')
252
+ .text(year)
253
+ .end()
254
+ .find('span').removeClass('active');
248
255
  if (currentYear == year) {
249
256
  months.eq(this.date.getMonth()).addClass('active');
250
257
  }
@@ -261,10 +268,10 @@
261
268
  html = '';
262
269
  year = parseInt(year/10, 10) * 10;
263
270
  var yearCont = this.picker.find('.datepicker-years')
264
- .find('th:eq(1)')
265
- .text(year + '-' + (year + 9))
266
- .end()
267
- .find('td');
271
+ .find('th:eq(1)')
272
+ .text(year + '-' + (year + 9))
273
+ .end()
274
+ .find('td');
268
275
  year -= 1;
269
276
  for (var i = -1; i < 11; i++) {
270
277
  html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
@@ -275,37 +282,37 @@
275
282
 
276
283
  updateNavArrows: function() {
277
284
  var d = new Date(this.viewDate),
278
- year = d.getFullYear(),
279
- month = d.getMonth();
285
+ year = d.getFullYear(),
286
+ month = d.getMonth();
280
287
  switch (this.viewMode) {
281
288
  case 0:
282
- if (this.startDate !== -Infinity && year <= this.startDate.getFullYear() && month <= this.startDate.getMonth()) {
283
- this.picker.find('.prev').css({visibility: 'hidden'});
284
- } else {
285
- this.picker.find('.prev').css({visibility: 'visible'});
286
- }
287
- if (this.endDate !== Infinity && year >= this.endDate.getFullYear() && month >= this.endDate.getMonth()) {
288
- this.picker.find('.next').css({visibility: 'hidden'});
289
- } else {
290
- this.picker.find('.next').css({visibility: 'visible'});
291
- }
292
- break;
289
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear() && month <= this.startDate.getMonth()) {
290
+ this.picker.find('.prev').css({visibility: 'hidden'});
291
+ } else {
292
+ this.picker.find('.prev').css({visibility: 'visible'});
293
+ }
294
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear() && month >= this.endDate.getMonth()) {
295
+ this.picker.find('.next').css({visibility: 'hidden'});
296
+ } else {
297
+ this.picker.find('.next').css({visibility: 'visible'});
298
+ }
299
+ break;
293
300
  case 1:
294
301
  case 2:
295
- if (this.startDate !== -Infinity && year <= this.startDate.getFullYear()) {
296
- this.picker.find('.prev').css({visibility: 'hidden'});
297
- } else {
298
- this.picker.find('.prev').css({visibility: 'visible'});
299
- }
300
- if (this.endDate !== Infinity && year >= this.endDate.getFullYear()) {
301
- this.picker.find('.next').css({visibility: 'hidden'});
302
- } else {
303
- this.picker.find('.next').css({visibility: 'visible'});
304
- }
305
- break;
302
+ if (this.startDate !== -Infinity && year <= this.startDate.getFullYear()) {
303
+ this.picker.find('.prev').css({visibility: 'hidden'});
304
+ } else {
305
+ this.picker.find('.prev').css({visibility: 'visible'});
306
+ }
307
+ if (this.endDate !== Infinity && year >= this.endDate.getFullYear()) {
308
+ this.picker.find('.next').css({visibility: 'hidden'});
309
+ } else {
310
+ this.picker.find('.next').css({visibility: 'visible'});
311
+ }
312
+ break;
306
313
  }
307
314
  },
308
-
315
+
309
316
  click: function(e) {
310
317
  e.stopPropagation();
311
318
  e.preventDefault();
@@ -313,78 +320,85 @@
313
320
  if (target.length == 1) {
314
321
  switch(target[0].nodeName.toLowerCase()) {
315
322
  case 'th':
316
- switch(target[0].className) {
317
- case 'switch':
318
- this.showMode(1);
319
- break;
320
- case 'prev':
321
- case 'next':
322
- this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
323
- this.viewDate,
324
- this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
325
- DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1)
326
- );
327
- this.fill();
323
+ switch(target[0].className) {
324
+ case 'switch':
325
+ this.showMode(1);
326
+ break;
327
+ case 'prev':
328
+ case 'next':
329
+ this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
330
+ this.viewDate,
331
+ this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
332
+ DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1)
333
+ );
334
+ this.fill();
335
+ break;
336
+ }
328
337
  break;
329
- }
330
- break;
331
338
  case 'span':
332
- if (!target.is('.disabled')) {
333
- if (target.is('.month')) {
334
- var month = target.parent().find('span').index(target);
335
- this.viewDate.setMonth(month);
336
- } else {
337
- var year = parseInt(target.text(), 10)||0;
338
- this.viewDate.setFullYear(year);
339
+ if (!target.is('.disabled')) {
340
+ if (target.is('.month')) {
341
+ var month = target.parent().find('span').index(target);
342
+ this.viewDate.setMonth(month);
343
+ } else {
344
+ var year = parseInt(target.text(), 10)||0;
345
+ this.viewDate.setFullYear(year);
346
+ }
347
+ this.showMode(-1);
348
+ this.fill();
339
349
  }
340
- this.showMode(-1);
341
- this.fill();
342
- }
343
- break;
350
+ break;
344
351
  case 'td':
345
- if (target.is('.day') && !target.is('.disabled')){
346
- var day = parseInt(target.text(), 10)||1;
347
- var year = this.viewDate.getFullYear(),
348
- month = this.viewDate.getMonth();
349
- if (target.is('.old')) {
350
- if (month == 0) {
351
- month = 11;
352
- year -= 1;
353
- } else {
354
- month -= 1;
352
+ if (target.is('.day') && !target.is('.disabled')){
353
+ var day = parseInt(target.text(), 10)||1;
354
+ var year = this.viewDate.getFullYear(),
355
+ month = this.viewDate.getMonth();
356
+ if (target.is('.old')) {
357
+ if (month == 0) {
358
+ month = 11;
359
+ year -= 1;
360
+ } else {
361
+ month -= 1;
362
+ }
363
+ } else if (target.is('.new')) {
364
+ if (month == 11) {
365
+ month = 0;
366
+ year += 1;
367
+ } else {
368
+ month += 1;
369
+ }
355
370
  }
356
- } else if (target.is('.new')) {
357
- if (month == 11) {
358
- month = 0;
359
- year += 1;
360
- } else {
361
- month += 1;
371
+ this.date = new Date(year, month, day,0,0,0,0);
372
+ this.viewDate = new Date(year, month, day,0,0,0,0);
373
+ this.fill();
374
+ this.setValue();
375
+ this.element.trigger({
376
+ type: 'changeDate',
377
+ date: this.date
378
+ });
379
+ var element;
380
+ if (this.isInput) {
381
+ element = this.element;
382
+ } else if (this.component){
383
+ element = this.element.find('input');
384
+ }
385
+ if (element) {
386
+ element.change();
387
+ if (this.autoclose) {
388
+ element.blur();
389
+ }
362
390
  }
363
391
  }
364
- this.date = new Date(year, month, day,0,0,0,0);
365
- this.viewDate = new Date(year, month, day,0,0,0,0);
366
- this.fill();
367
- this.setValue();
368
- this.element.trigger({
369
- type: 'changeDate',
370
- date: this.date
371
- });
372
- if (this.isInput) {
373
- this.element.change();
374
- } else if (this.component){
375
- this.element.find('input').change();
376
- }
377
- }
378
- break;
392
+ break;
379
393
  }
380
394
  }
381
395
  },
382
-
396
+
383
397
  mousedown: function(e){
384
398
  e.stopPropagation();
385
399
  e.preventDefault();
386
400
  },
387
-
401
+
388
402
  showMode: function(dir) {
389
403
  if (dir) {
390
404
  this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
@@ -393,14 +407,14 @@
393
407
  this.updateNavArrows();
394
408
  }
395
409
  };
396
-
410
+
397
411
  $.fn.datepicker = function ( option ) {
398
412
  var args = Array.apply(null, arguments);
399
413
  args.shift();
400
414
  return this.each(function () {
401
415
  var $this = $(this),
402
- data = $this.data('datepicker'),
403
- options = typeof option == 'object' && option;
416
+ data = $this.data('datepicker'),
417
+ options = typeof option == 'object' && option;
404
418
  if (!data) {
405
419
  $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
406
420
  }
@@ -411,116 +425,138 @@
411
425
  $.fn.datepicker.defaults = {
412
426
  };
413
427
  $.fn.datepicker.Constructor = Datepicker;
414
-
428
+
415
429
  var DPGlobal = {
416
430
  modes: [
417
- {
418
- clsName: 'days',
419
- navFnc: 'Month',
420
- navStep: 1
421
- },
422
- {
423
- clsName: 'months',
424
- navFnc: 'FullYear',
425
- navStep: 1
426
- },
427
- {
428
- clsName: 'years',
429
- navFnc: 'FullYear',
430
- navStep: 10
431
- }],
432
- dates:{
433
- days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
434
- daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
435
- daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
436
- months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
437
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
438
- },
439
- isLeapYear: function (year) {
440
- return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
431
+ {
432
+ clsName: 'days',
433
+ navFnc: 'Month',
434
+ navStep: 1
441
435
  },
442
- getDaysInMonth: function (year, month) {
443
- return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
436
+ {
437
+ clsName: 'months',
438
+ navFnc: 'FullYear',
439
+ navStep: 1
444
440
  },
445
- parseFormat: function(format){
446
- var separator = format.match(/[.\/-].*?/),
441
+ {
442
+ clsName: 'years',
443
+ navFnc: 'FullYear',
444
+ navStep: 10
445
+ }],
446
+ dates:{
447
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
448
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
449
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
450
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
451
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
452
+ },
453
+ isLeapYear: function (year) {
454
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
455
+ },
456
+ getDaysInMonth: function (year, month) {
457
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
458
+ },
459
+ parseFormat: function(format){
460
+ var separator = format.match(/[.\/ -].*?/),
447
461
  parts = format.split(/\W+/);
448
- if (!separator || !parts || parts.length == 0){
449
- throw new Error("Invalid date format.");
450
- }
451
- return {separator: separator, parts: parts};
452
- },
453
- parseDate: function(date, format) {
454
- if (date instanceof Date) return date;
455
- var parts = date.split(format.separator),
462
+ if (!separator || !parts || parts.length == 0){
463
+ throw new Error("Invalid date format.");
464
+ }
465
+ return {separator: separator, parts: parts};
466
+ },
467
+ parseDate: function(date, format) {
468
+ if (date instanceof Date) return date;
469
+ var parts = date.split(format.separator),
456
470
  date = new Date(1970, 1, 1, 0, 0, 0),
457
- val;
458
- if (parts.length == format.parts.length) {
459
- for (var i=0, cnt = format.parts.length; i < cnt; i++) {
460
- val = parseInt(parts[i], 10)||1;
461
- switch(format.parts[i]) {
462
- case 'dd':
463
- case 'd':
471
+ val, filtered;
472
+ if (parts.length == format.parts.length) {
473
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
474
+ val = parseInt(parts[i], 10)||1;
475
+ switch(format.parts[i]) {
476
+ case 'MM':
477
+ filtered = $(this.dates.months).filter(function(){
478
+ var m = this.slice(0, parts[i].length),
479
+ p = parts[i].slice(0, m.length);
480
+ return m == p;
481
+ });
482
+ val = $.inArray(filtered[0], this.dates.months) + 1;
483
+ break;
484
+ case 'M':
485
+ filtered = $(this.dates.monthsShort).filter(function(){
486
+ var m = this.slice(0, parts[i].length),
487
+ p = parts[i].slice(0, m.length);
488
+ return m == p;
489
+ });
490
+ val = $.inArray(filtered[0], this.dates.monthsShort) + 1;
491
+ break;
492
+ }
493
+ switch(format.parts[i]) {
494
+ case 'dd':
495
+ case 'd':
464
496
  date.setDate(val);
465
497
  break;
466
- case 'mm':
467
- case 'm':
498
+ case 'mm':
499
+ case 'm':
500
+ case 'MM':
501
+ case 'M':
468
502
  date.setMonth(val - 1);
469
503
  break;
470
- case 'yy':
504
+ case 'yy':
471
505
  date.setFullYear(2000 + val);
472
506
  break;
473
- case 'yyyy':
507
+ case 'yyyy':
474
508
  date.setFullYear(val);
475
509
  break;
476
- }
477
510
  }
478
511
  }
479
- return date;
480
- },
481
- formatDate: function(date, format){
482
- var val = {
483
- d: date.getDate(),
484
- m: date.getMonth() + 1,
485
- yy: date.getFullYear().toString().substring(2),
486
- yyyy: date.getFullYear()
487
- };
488
- val.dd = (val.d < 10 ? '0' : '') + val.d;
489
- val.mm = (val.m < 10 ? '0' : '') + val.m;
490
- var date = [];
491
- for (var i=0, cnt = format.parts.length; i < cnt; i++) {
492
- date.push(val[format.parts[i]]);
493
- }
494
- return date.join(format.separator);
495
- },
496
- headTemplate: '<thead>'+
497
- '<tr>'+
498
- '<th class="prev"><i class="icon-arrow-left"/></th>'+
499
- '<th colspan="5" class="switch"></th>'+
500
- '<th class="next"><i class="icon-arrow-right"/></th>'+
501
- '</tr>'+
502
- '</thead>',
503
- contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
504
- };
505
- DPGlobal.template = '<div class="datepicker dropdown-menu">'+
506
- '<div class="datepicker-days">'+
507
- '<table class=" table-condensed">'+
508
- DPGlobal.headTemplate+
509
- '<tbody></tbody>'+
510
- '</table>'+
511
- '</div>'+
512
- '<div class="datepicker-months">'+
513
- '<table class="table-condensed">'+
514
- DPGlobal.headTemplate+
515
- DPGlobal.contTemplate+
516
- '</table>'+
517
- '</div>'+
518
- '<div class="datepicker-years">'+
519
- '<table class="table-condensed">'+
520
- DPGlobal.headTemplate+
521
- DPGlobal.contTemplate+
522
- '</table>'+
523
- '</div>'+
524
- '</div>';
512
+ }
513
+ return date;
514
+ },
515
+ formatDate: function(date, format){
516
+ var val = {
517
+ d: date.getDate(),
518
+ m: date.getMonth() + 1,
519
+ M: this.dates.monthsShort[date.getMonth()],
520
+ MM: this.dates.months[date.getMonth()],
521
+ yy: date.getFullYear().toString().substring(2),
522
+ yyyy: date.getFullYear()
523
+ };
524
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
525
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
526
+ var date = [];
527
+ for (var i=0, cnt = format.parts.length; i < cnt; i++) {
528
+ date.push(val[format.parts[i]]);
529
+ }
530
+ return date.join(format.separator);
531
+ },
532
+ headTemplate: '<thead>'+
533
+ '<tr>'+
534
+ '<th class="prev"><i class="icon-arrow-left"/></th>'+
535
+ '<th colspan="5" class="switch"></th>'+
536
+ '<th class="next"><i class="icon-arrow-right"/></th>'+
537
+ '</tr>'+
538
+ '</thead>',
539
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
540
+ };
541
+ DPGlobal.template = '<div class="datepicker dropdown-menu">'+
542
+ '<div class="datepicker-days">'+
543
+ '<table class=" table-condensed">'+
544
+ DPGlobal.headTemplate+
545
+ '<tbody></tbody>'+
546
+ '</table>'+
547
+ '</div>'+
548
+ '<div class="datepicker-months">'+
549
+ '<table class="table-condensed">'+
550
+ DPGlobal.headTemplate+
551
+ DPGlobal.contTemplate+
552
+ '</table>'+
553
+ '</div>'+
554
+ '<div class="datepicker-years">'+
555
+ '<table class="table-condensed">'+
556
+ DPGlobal.headTemplate+
557
+ DPGlobal.contTemplate+
558
+ '</table>'+
559
+ '</div>'+
560
+ '</div>';
525
561
 
526
- }( window.jQuery )
562
+ }( window.jQuery )
@@ -1,89 +1,102 @@
1
1
  /*!
2
- * Datepicker for Bootstrap
3
- *
4
- * Copyright 2012 Stefan Petre
5
- * Licensed under the Apache License v2.0
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- */
2
+ * Datepicker for Bootstrap
3
+ *
4
+ * Copyright 2012 Stefan Petre
5
+ * Licensed under the Apache License v2.0
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ */
9
9
  .datepicker {
10
- top: 0;
11
- left: 0;
12
- padding: 4px;
13
- margin-top: 1px;
14
- -webkit-border-radius: 4px;
15
- -moz-border-radius: 4px;
16
- border-radius: 4px;
17
- /*.dow {
18
- border-top: 1px solid #ddd !important;
10
+ top: 0;
11
+ left: 0;
12
+ padding: 4px;
13
+ margin-top: 1px;
14
+ -webkit-border-radius: 4px;
15
+ -moz-border-radius: 4px;
16
+ border-radius: 4px;
17
+ /*.dow {
18
+ border-top: 1px solid #ddd !important;
19
19
  }*/
20
+
20
21
  }
21
22
  .datepicker:before {
22
- content: '';
23
- display: inline-block;
24
- border-left: 7px solid transparent;
25
- border-right: 7px solid transparent;
26
- border-bottom: 7px solid #ccc;
27
- border-bottom-color: rgba(0, 0, 0, 0.2);
28
- position: absolute;
29
- top: -7px;
30
- left: 6px;
23
+ content: '';
24
+ display: inline-block;
25
+ border-left: 7px solid transparent;
26
+ border-right: 7px solid transparent;
27
+ border-bottom: 7px solid #ccc;
28
+ border-bottom-color: rgba(0, 0, 0, 0.2);
29
+ position: absolute;
30
+ top: -7px;
31
+ left: 6px;
31
32
  }
32
33
  .datepicker:after {
33
- content: '';
34
- display: inline-block;
35
- border-left: 6px solid transparent;
36
- border-right: 6px solid transparent;
37
- border-bottom: 6px solid #ffffff;
38
- position: absolute;
39
- top: -6px;
40
- left: 7px;
34
+ content: '';
35
+ display: inline-block;
36
+ border-left: 6px solid transparent;
37
+ border-right: 6px solid transparent;
38
+ border-bottom: 6px solid #ffffff;
39
+ position: absolute;
40
+ top: -6px;
41
+ left: 7px;
41
42
  }
42
43
  .datepicker > div {
43
- display: none;
44
+ display: none;
44
45
  }
45
- .datepicker table {
46
- width: 100%;
47
- margin: 0;
46
+ .datepicker.days div.datepicker-days {
47
+ display: block;
48
+ }
49
+ .datepicker.months div.datepicker-months {
50
+ display: block;
51
+ }
52
+ .datepicker.years div.datepicker-years {
53
+ display: block;
48
54
  }
49
- .datepicker td, .datepicker th {
50
- text-align: center;
51
- width: 20px;
52
- height: 20px;
53
- -webkit-border-radius: 4px;
54
- -moz-border-radius: 4px;
55
- border-radius: 4px;
55
+ .datepicker table {
56
+ width: 100%;
57
+ margin: 0;
58
+ }
59
+ .datepicker td,
60
+ .datepicker th {
61
+ text-align: center;
62
+ width: 20px;
63
+ height: 20px;
64
+ -webkit-border-radius: 4px;
65
+ -moz-border-radius: 4px;
66
+ border-radius: 4px;
56
67
  }
57
68
  .datepicker td.day:hover {
58
- background: #eeeeee;
59
- cursor: pointer;
69
+ background: #eeeeee;
70
+ cursor: pointer;
60
71
  }
61
- .datepicker td.old, .datepicker td.new {
62
- color: #999999;
72
+ .datepicker td.old,
73
+ .datepicker td.new {
74
+ color: #999999;
63
75
  }
64
- .datepicker td.disabled, .datepicker td.disabled:hover {
65
- background: none;
66
- color:#999999;
67
- cursor: default;
76
+ .datepicker td.disabled,
77
+ .datepicker td.disabled:hover {
78
+ background: none;
79
+ color: #999999;
80
+ cursor: default;
68
81
  }
69
82
  .datepicker td.active,
70
83
  .datepicker td.active:hover,
71
84
  .datepicker td.active.disabled,
72
85
  .datepicker td.active.disabled:hover {
73
- background-color: #006dcc;
74
- background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
75
- background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
76
- background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
77
- background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
78
- background-image: -o-linear-gradient(top, #0088cc, #0044cc);
79
- background-image: linear-gradient(top, #0088cc, #0044cc);
80
- background-repeat: repeat-x;
81
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
82
- border-color: #0044cc #0044cc #002a80;
83
- border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
84
- filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
85
- color: #fff;
86
- text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
86
+ background-color: #006dcc;
87
+ background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
88
+ background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
89
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
90
+ background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
91
+ background-image: -o-linear-gradient(top, #0088cc, #0044cc);
92
+ background-image: linear-gradient(top, #0088cc, #0044cc);
93
+ background-repeat: repeat-x;
94
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
95
+ border-color: #0044cc #0044cc #002a80;
96
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
97
+ filter: progid:dximagetransform.microsoft.gradient(enabled=false);
98
+ color: #fff;
99
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
87
100
  }
88
101
  .datepicker td.active:hover,
89
102
  .datepicker td.active:hover:hover,
@@ -105,7 +118,7 @@
105
118
  .datepicker td.active:hover[disabled],
106
119
  .datepicker td.active.disabled[disabled],
107
120
  .datepicker td.active.disabled:hover[disabled] {
108
- background-color: #0044cc;
121
+ background-color: #0044cc;
109
122
  }
110
123
  .datepicker td.active:active,
111
124
  .datepicker td.active:hover:active,
@@ -115,46 +128,47 @@
115
128
  .datepicker td.active:hover.active,
116
129
  .datepicker td.active.disabled.active,
117
130
  .datepicker td.active.disabled:hover.active {
118
- background-color: #003399 \9;
131
+ background-color: #003399 \9;
119
132
  }
120
133
  .datepicker td span {
121
- display: block;
122
- width: 47px;
123
- height: 54px;
124
- line-height: 54px;
125
- float: left;
126
- margin: 2px;
127
- cursor: pointer;
128
- -webkit-border-radius: 4px;
129
- -moz-border-radius: 4px;
130
- border-radius: 4px;
134
+ display: block;
135
+ width: 47px;
136
+ height: 54px;
137
+ line-height: 54px;
138
+ float: left;
139
+ margin: 2px;
140
+ cursor: pointer;
141
+ -webkit-border-radius: 4px;
142
+ -moz-border-radius: 4px;
143
+ border-radius: 4px;
131
144
  }
132
145
  .datepicker td span:hover {
133
- background: #eeeeee;
146
+ background: #eeeeee;
134
147
  }
135
- .datepicker td span.disabled, .datepicker td span.disabled:hover {
136
- background:none;
137
- color: #999999;
138
- cursor: default;
148
+ .datepicker td span.disabled,
149
+ .datepicker td span.disabled:hover {
150
+ background: none;
151
+ color: #999999;
152
+ cursor: default;
139
153
  }
140
154
  .datepicker td span.active,
141
155
  .datepicker td span.active:hover,
142
156
  .datepicker td span.active.disabled,
143
157
  .datepicker td span.active.disabled:hover {
144
- background-color: #006dcc;
145
- background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
146
- background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
147
- background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
148
- background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
149
- background-image: -o-linear-gradient(top, #0088cc, #0044cc);
150
- background-image: linear-gradient(top, #0088cc, #0044cc);
151
- background-repeat: repeat-x;
152
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
153
- border-color: #0044cc #0044cc #002a80;
154
- border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
155
- filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
156
- color: #fff;
157
- text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
158
+ background-color: #006dcc;
159
+ background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
160
+ background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
161
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
162
+ background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
163
+ background-image: -o-linear-gradient(top, #0088cc, #0044cc);
164
+ background-image: linear-gradient(top, #0088cc, #0044cc);
165
+ background-repeat: repeat-x;
166
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
167
+ border-color: #0044cc #0044cc #002a80;
168
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
169
+ filter: progid:dximagetransform.microsoft.gradient(enabled=false);
170
+ color: #fff;
171
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
158
172
  }
159
173
  .datepicker td span.active:hover,
160
174
  .datepicker td span.active:hover:hover,
@@ -176,7 +190,7 @@
176
190
  .datepicker td span.active:hover[disabled],
177
191
  .datepicker td span.active.disabled[disabled],
178
192
  .datepicker td span.active.disabled:hover[disabled] {
179
- background-color: #0044cc;
193
+ background-color: #0044cc;
180
194
  }
181
195
  .datepicker td span.active:active,
182
196
  .datepicker td span.active:hover:active,
@@ -186,23 +200,24 @@
186
200
  .datepicker td span.active:hover.active,
187
201
  .datepicker td span.active.disabled.active,
188
202
  .datepicker td span.active.disabled:hover.active {
189
- background-color: #003399 \9;
203
+ background-color: #003399 \9;
190
204
  }
191
205
  .datepicker td span.old {
192
- color: #999999;
206
+ color: #999999;
193
207
  }
194
208
  .datepicker th.switch {
195
- width: 145px;
209
+ width: 145px;
196
210
  }
197
211
  .datepicker thead tr:first-child th {
198
- cursor: pointer;
212
+ cursor: pointer;
199
213
  }
200
214
  .datepicker thead tr:first-child th:hover {
201
- background: #eeeeee;
202
- }
203
- .input-append.date .add-on i, .input-prepend.date .add-on i {
204
- display: block;
205
- cursor: pointer;
206
- width: 16px;
207
- height: 16px;
208
- }
215
+ background: #eeeeee;
216
+ }
217
+ .input-append.date .add-on i,
218
+ .input-prepend.date .add-on i {
219
+ display: block;
220
+ cursor: pointer;
221
+ width: 16px;
222
+ height: 16px;
223
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-datepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-10 00:00:00.000000000 Z
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70332582805880 !ruby/object:Gem::Requirement
16
+ requirement: &70298307018260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70332582805880
24
+ version_requirements: *70298307018260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70332582808440 !ruby/object:Gem::Requirement
27
+ requirement: &70298307021480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70332582808440
35
+ version_requirements: *70298307021480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70332582487200 !ruby/object:Gem::Requirement
38
+ requirement: &70298306700540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70332582487200
46
+ version_requirements: *70298306700540
47
47
  description: A date picker for Twitter Bootstrap
48
48
  email:
49
49
  - siotopo@gmail.com
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: 65111314992475012
79
+ hash: 601702732678368938
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: 65111314992475012
88
+ hash: 601702732678368938
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.17