Skip to content

Commit 684bf9e

Browse files
author
Tomas Kirda
committed
Adjust suggestions width when resizing window, if width is set to auto. Fixes devbridge#92
1 parent 8d0b422 commit 684bf9e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/jquery.autocomplete.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
}
177177
};
178178

179-
$(window).on('resize', that.fixPositionCapture);
179+
$(window).on('resize.autocomplete', that.fixPositionCapture);
180180

181181
that.el.on('keydown.autocomplete', function (e) { that.onKeyPress(e); });
182182
that.el.on('keyup.autocomplete', function (e) { that.onKeyUp(e); });
@@ -242,7 +242,8 @@
242242

243243
fixPosition: function () {
244244
var that = this,
245-
offset;
245+
offset,
246+
styles;
246247

247248
// Don't adjsut position if custom container has been specified:
248249
if (that.options.appendTo !== 'body') {
@@ -251,10 +252,16 @@
251252

252253
offset = that.el.offset();
253254

254-
$(that.suggestionsContainer).css({
255+
styles = {
255256
top: (offset.top + that.el.outerHeight()) + 'px',
256257
left: offset.left + 'px'
257-
});
258+
};
259+
260+
if (that.options.width === 'auto') {
261+
styles.width = (that.el.outerWidth() - 2) + 'px';
262+
}
263+
264+
$(that.suggestionsContainer).css(styles);
258265
},
259266

260267
enableKillerFn: function () {
@@ -715,7 +722,7 @@
715722
var that = this;
716723
that.el.off('.autocomplete').removeData('autocomplete');
717724
that.disableKillerFn();
718-
$(window).off('resize', that.fixPositionCapture);
725+
$(window).off('resize.autocomplete', that.fixPositionCapture);
719726
$(that.suggestionsContainer).remove();
720727
}
721728
};

0 commit comments

Comments
 (0)