bootstrap-datepicker-rails 0.6.17 → 0.6.18

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.
@@ -1,5 +1,5 @@
1
1
  module BootstrapDatepickerRails
2
2
  module Rails
3
- VERSION = "0.6.17"
3
+ VERSION = "0.6.18"
4
4
  end
5
5
  end
@@ -26,7 +26,9 @@
26
26
 
27
27
  // Picker object
28
28
 
29
- var Datepicker = function(element, options){
29
+ var Datepicker = function(element, options) {
30
+ var that = this;
31
+
30
32
  this.element = $(element);
31
33
  this.language = options.language||this.element.data('date-language')||"en";
32
34
  this.language = this.language in dates ? this.language : "en";
@@ -34,54 +36,55 @@
34
36
  this.picker = $(DPGlobal.template)
35
37
  .appendTo('body')
36
38
  .on({
37
- click: $.proxy(this.click, this),
38
- mousedown: $.proxy(this.mousedown, this)
39
+ click: $.proxy(this.click, this)
39
40
  });
40
41
  this.isInput = this.element.is('input');
41
42
  this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
43
+ this.hasInput = this.component && this.element.find('input').length;
42
44
  if(this.component && this.component.length === 0)
43
45
  this.component = false;
44
46
 
45
47
  if (this.isInput) {
46
48
  this.element.on({
47
49
  focus: $.proxy(this.show, this),
48
- blur: $.proxy(this._hide, this),
49
50
  keyup: $.proxy(this.update, this),
50
51
  keydown: $.proxy(this.keydown, this)
51
52
  });
52
53
  } else {
53
- if (this.component){
54
+ if (this.component && this.hasInput){
54
55
  // For components that are not readonly, allow keyboard nav
55
56
  this.element.find('input').on({
56
57
  focus: $.proxy(this.show, this),
57
- blur: $.proxy(this._hide, this),
58
58
  keyup: $.proxy(this.update, this),
59
59
  keydown: $.proxy(this.keydown, this)
60
60
  });
61
61
 
62
62
  this.component.on('click', $.proxy(this.show, this));
63
- var element = this.element.find('input');
64
- element.on({
65
- blur: $.proxy(this._hide, this)
66
- })
67
63
  } else {
68
64
  this.element.on('click', $.proxy(this.show, this));
69
65
  }
70
66
  }
71
67
 
68
+ $(document).on('mousedown', function (e) {
69
+ // Clicked outside the datepicker, hide it
70
+ if ($(e.target).closest('.datepicker').length == 0) {
71
+ that.hide();
72
+ }
73
+ });
74
+
72
75
  this.autoclose = false;
73
76
  if ('autoclose' in options) {
74
77
  this.autoclose = options.autoclose;
75
78
  } else if ('dateAutoclose' in this.element.data()) {
76
79
  this.autoclose = this.element.data('date-autoclose');
77
80
  }
78
-
79
- this.keyboardNavigation = true;
80
- if ('keyboardNavigation' in options) {
81
- this.keyboardNavigation = options.keyboardNavigation;
82
- } else if ('dateKeyboardNavigation' in this.element.data()) {
83
- this.keyboardNavigation = this.element.data('date-keyboard-navigation');
84
- }
81
+
82
+ this.keyboardNavigation = true;
83
+ if ('keyboardNavigation' in options) {
84
+ this.keyboardNavigation = options.keyboardNavigation;
85
+ } else if ('dateKeyboardNavigation' in this.element.data()) {
86
+ this.keyboardNavigation = this.element.data('date-keyboard-navigation');
87
+ }
85
88
 
86
89
  switch(options.startView || this.element.data('date-start-view')){
87
90
  case 2:
@@ -124,40 +127,12 @@
124
127
  e.stopPropagation();
125
128
  e.preventDefault();
126
129
  }
127
- if (!this.isInput) {
128
- $(document).on('mousedown', $.proxy(this.hide, this));
129
- }
130
130
  this.element.trigger({
131
131
  type: 'show',
132
132
  date: this.date
133
133
  });
134
134
  },
135
135
 
136
- _hide: function(e){
137
- // When going from the input to the picker, IE handles the blur/click
138
- // events differently than other browsers, in such a way that the blur
139
- // event triggers a hide before the click event can stop propagation.
140
- if ($.browser.msie) {
141
- var t = this, args = arguments;
142
-
143
- function cancel_hide(){
144
- clearTimeout(hide_timeout);
145
- e.target.focus();
146
- t.picker.off('click', cancel_hide);
147
- }
148
-
149
- function do_hide(){
150
- t.hide.apply(t, args);
151
- t.picker.off('click', cancel_hide);
152
- }
153
-
154
- this.picker.on('click', cancel_hide);
155
- var hide_timeout = setTimeout(do_hide, 100);
156
- } else {
157
- return this.hide.apply(this, arguments);
158
- }
159
- },
160
-
161
136
  hide: function(e){
162
137
  this.picker.hide();
163
138
  $(window).off('resize', this.place);
@@ -206,8 +181,8 @@
206
181
 
207
182
  place: function(){
208
183
  var zIndex = parseInt(this.element.parents().filter(function() {
209
- return $(this).css('z-index') != 'auto';
210
- }).first().css('z-index'))+10;
184
+ return $(this).css('z-index') != 'auto';
185
+ }).first().css('z-index'))+10;
211
186
  var offset = this.component ? this.component.offset() : this.element.offset();
212
187
  this.picker.css({
213
188
  top: offset.top + this.height,
@@ -449,7 +424,7 @@
449
424
  if (element) {
450
425
  element.change();
451
426
  if (this.autoclose) {
452
- element.blur();
427
+ this.hide();
453
428
  }
454
429
  }
455
430
  }
@@ -458,11 +433,6 @@
458
433
  }
459
434
  },
460
435
 
461
- mousedown: function(e){
462
- e.stopPropagation();
463
- e.preventDefault();
464
- },
465
-
466
436
  moveMonth: function(date, dir){
467
437
  if (!dir) return date;
468
438
  var new_date = new Date(date.valueOf()),
@@ -527,7 +497,7 @@
527
497
  break;
528
498
  case 37: // left
529
499
  case 39: // right
530
- if (!this.keyboardNavigation) break;
500
+ if (!this.keyboardNavigation) break;
531
501
  dir = e.keyCode == 37 ? -1 : 1;
532
502
  if (e.ctrlKey){
533
503
  newDate = this.moveYear(this.date, dir);
@@ -552,7 +522,7 @@
552
522
  break;
553
523
  case 38: // up
554
524
  case 40: // down
555
- if (!this.keyboardNavigation) break;
525
+ if (!this.keyboardNavigation) break;
556
526
  dir = e.keyCode == 38 ? -1 : 1;
557
527
  if (e.ctrlKey){
558
528
  newDate = this.moveYear(this.date, dir);
@@ -579,6 +549,9 @@
579
549
  this.hide();
580
550
  e.preventDefault();
581
551
  break;
552
+ case 9: // tab
553
+ this.hide();
554
+ break;
582
555
  }
583
556
  if (dateChanged){
584
557
  this.element.trigger({
@@ -54,7 +54,6 @@
54
54
  display: block;
55
55
  }
56
56
  .datepicker table {
57
- width: 100%;
58
57
  margin: 0;
59
58
  }
60
59
  .datepicker td,
@@ -133,11 +132,11 @@
133
132
  }
134
133
  .datepicker td span {
135
134
  display: block;
136
- width: 47px;
135
+ width: 23%;
137
136
  height: 54px;
138
137
  line-height: 54px;
139
138
  float: left;
140
- margin: 2px;
139
+ margin: 1%;
141
140
  cursor: pointer;
142
141
  -webkit-border-radius: 4px;
143
142
  -moz-border-radius: 4px;
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.6.17
4
+ version: 0.6.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: 2859334882354847738
121
+ hash: -2750079544658003183
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements:
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: 2859334882354847738
130
+ hash: -2750079544658003183
131
131
  requirements: []
132
132
  rubyforge_project:
133
133
  rubygems_version: 1.8.24