|
38 | 38 | if(this.component && this.component.length === 0)
|
39 | 39 | this.component = false;
|
40 | 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 |
| - } |
| 41 | + this._attachEvents(); |
67 | 42 |
|
68 | 43 | this.autoclose = false;
|
69 | 44 | if ('autoclose' in options) {
|
|
110 | 85 | Datepicker.prototype = {
|
111 | 86 | constructor: Datepicker,
|
112 | 87 |
|
| 88 | + _events: [], |
| 89 | + _attachEvents: function(){ |
| 90 | + this._detachEvents(); |
| 91 | + if (this.isInput) { |
| 92 | + this._events = [ |
| 93 | + [this.element, { |
| 94 | + focus: $.proxy(this.show, this), |
| 95 | + blur: $.proxy(this._hide, this), |
| 96 | + keyup: $.proxy(this.update, this), |
| 97 | + keydown: $.proxy(this.keydown, this) |
| 98 | + }] |
| 99 | + ]; |
| 100 | + } |
| 101 | + else if (this.component){ |
| 102 | + this._events = [ |
| 103 | + // For components that are not readonly, allow keyboard nav |
| 104 | + [this.element.find('input'), { |
| 105 | + focus: $.proxy(this.show, this), |
| 106 | + blur: $.proxy(this._hide, this), |
| 107 | + keyup: $.proxy(this.update, this), |
| 108 | + keydown: $.proxy(this.keydown, this), |
| 109 | + }], |
| 110 | + [this.component, { |
| 111 | + click: $.proxy(this.show, this) |
| 112 | + }] |
| 113 | + ]; |
| 114 | + } |
| 115 | + else { |
| 116 | + this._events = [ |
| 117 | + [this.element, { |
| 118 | + click: $.proxy(this.show, this) |
| 119 | + }] |
| 120 | + ]; |
| 121 | + } |
| 122 | + for (var i=0, el, ev; i<this._events.length; i++){ |
| 123 | + el = this._events[i][0]; |
| 124 | + ev = this._events[i][1]; |
| 125 | + el.on(ev); |
| 126 | + } |
| 127 | + }, |
| 128 | + _detachEvents: function(){ |
| 129 | + for (var i=0, el, ev; i<this._events.length; i++){ |
| 130 | + el = this._events[i][0]; |
| 131 | + ev = this._events[i][1]; |
| 132 | + el.off(ev); |
| 133 | + } |
| 134 | + this._events = []; |
| 135 | + }, |
| 136 | + |
113 | 137 | show: function(e) {
|
114 | 138 | this.picker.show();
|
115 | 139 | this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
|
|
0 commit comments