Skip to content

Commit 195ad46

Browse files
author
Harris
committed
Fix 771 only resize if menu open
1 parent 1d16799 commit 195ad46

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

src/jquery.multiselect.filter.js

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
var opts = this.options;
8282
var $element = this.element;
8383

84-
// get the multiselect instance -- instance() method no longer supported -- use data()
84+
// get the multiselect instance
8585
this.instance = $element.data('ech-multiselect');
8686

8787
// store header; add filter class so the close/check all/uncheck all links can be positioned correctly
@@ -93,8 +93,44 @@
9393
placeholder: opts.placeholder,
9494
type: "search"
9595
})
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({
98134
keydown: function(e) {
99135
// prevent the enter key from submitting the form / closing the widget
100136
if(e.which === 13)
@@ -128,38 +164,9 @@
128164
}
129165
}
130166
},
131-
input: $.proxy(debounce(this._handler, opts.debounceMS), this),
167+
input: $.proxy(debounce(this._handler, this.options.debounceMS), this),
132168
search: $.proxy(this._handler, this)
133169
});
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-
163170
},
164171

165172
/**
@@ -213,7 +220,7 @@
213220
if (term) {
214221
this._trigger('filter', e, filteredInputs);
215222
}
216-
if (!this.instance.options.listbox) {
223+
if (!this.instance.options.listbox && this.instance._isOpen) {
217224
this.instance._setMenuHeight(true);
218225
}
219226
return;

0 commit comments

Comments
 (0)