|
81 | 81 | var opts = this.options;
|
82 | 82 | var $element = this.element;
|
83 | 83 |
|
84 |
| - // get the multiselect instance -- instance() method no longer supported -- use data() |
| 84 | + // get the multiselect instance |
85 | 85 | this.instance = $element.data('ech-multiselect');
|
86 | 86 |
|
87 | 87 | // store header; add filter class so the close/check all/uncheck all links can be positioned correctly
|
|
93 | 93 | placeholder: opts.placeholder,
|
94 | 94 | type: "search"
|
95 | 95 | })
|
96 |
| - .css({ width: (/\d/.test(opts.width) ? opts.width + 'px' : null) }) |
97 |
| - .on({ |
| 96 | + .css({ width: (/\d/.test(opts.width) ? opts.width + 'px' : null) }); |
| 97 | + this._bindInputEvents(); |
| 98 | + // automatically reset the widget on close? |
| 99 | + if (this.options.autoReset) { |
| 100 | + $element.on('multiselectclose', $.proxy(this._reset, this)); |
| 101 | + } |
| 102 | + |
| 103 | + var $label = $(document.createElement('label')).text(opts.label).append(this.$input); |
| 104 | + this.$wrapper = $(document.createElement('div')) |
| 105 | + .addClass(filterClass) |
| 106 | + .append($label) |
| 107 | + .prependTo(this.$header); |
| 108 | + |
| 109 | + // If menu already opened, have to reset menu height since |
| 110 | + // addition of the filter input changes the header height calc. |
| 111 | + if (!!this.instance._isOpen) { |
| 112 | + this.instance._setMenuHeight(true); |
| 113 | + } |
| 114 | + |
| 115 | + // cache input values for searching |
| 116 | + this.updateCache(); |
| 117 | + |
| 118 | + // Change the normal _toggleChecked fxn behavior so that when checkAll/uncheckAll |
| 119 | + // is fired, only the currently displayed filtered inputs are checked if filter entered. |
| 120 | + var instance = this.instance; |
| 121 | + var filter = this.$input[0]; |
| 122 | + instance._oldToggleChecked = instance._toggleChecked; |
| 123 | + instance._toggleChecked = function(flag, group) { |
| 124 | + instance._oldToggleChecked(flag, group, !!filter.value); |
| 125 | + }; |
| 126 | + }, |
| 127 | + |
| 128 | + /** |
| 129 | + * Binds keyboard events to the input |
| 130 | + * This is where special behavior like ALT-R for reset is bound |
| 131 | + */ |
| 132 | + _bindInputEvents: function() { |
| 133 | + this.$input.on({ |
98 | 134 | keydown: function(e) {
|
99 | 135 | // prevent the enter key from submitting the form / closing the widget
|
100 | 136 | if(e.which === 13)
|
|
128 | 164 | }
|
129 | 165 | }
|
130 | 166 | },
|
131 |
| - input: $.proxy(debounce(this._handler, opts.debounceMS), this), |
| 167 | + input: $.proxy(debounce(this._handler, this.options.debounceMS), this), |
132 | 168 | search: $.proxy(this._handler, this)
|
133 | 169 | });
|
134 |
| - |
135 |
| - // automatically reset the widget on close? |
136 |
| - if (this.options.autoReset) |
137 |
| - $element.on('multiselectclose', $.proxy(this._reset, this)); |
138 |
| - |
139 |
| - var $label = $(document.createElement('label')).text(opts.label).append(this.$input); |
140 |
| - this.$wrapper = $(document.createElement('div')) |
141 |
| - .addClass(filterClass) |
142 |
| - .append($label) |
143 |
| - .prependTo(this.$header); |
144 |
| - |
145 |
| - // If menu already opened, have to reset menu height since |
146 |
| - // addition of the filter input changes the header height calc. |
147 |
| - if (!!this.instance._isOpen) { |
148 |
| - this.instance._setMenuHeight(true); |
149 |
| - } |
150 |
| - |
151 |
| - // cache input values for searching |
152 |
| - this.updateCache(); |
153 |
| - |
154 |
| - // Change the normal _toggleChecked fxn behavior so that when checkAll/uncheckAll |
155 |
| - // is fired, only the currently displayed filtered inputs are checked if filter entered. |
156 |
| - var instance = this.instance; |
157 |
| - var filter = this.$input[0]; |
158 |
| - instance._oldToggleChecked = instance._toggleChecked; |
159 |
| - instance._toggleChecked = function(flag, group) { |
160 |
| - instance._oldToggleChecked(flag, group, !!filter.value); |
161 |
| - }; |
162 |
| - |
163 | 170 | },
|
164 | 171 |
|
165 | 172 | /**
|
|
213 | 220 | if (term) {
|
214 | 221 | this._trigger('filter', e, filteredInputs);
|
215 | 222 | }
|
216 |
| - if (!this.instance.options.listbox) { |
| 223 | + if (!this.instance.options.listbox && this.instance._isOpen) { |
217 | 224 | this.instance._setMenuHeight(true);
|
218 | 225 | }
|
219 | 226 | return;
|
|
0 commit comments