Skip to content

Commit 72b289f

Browse files
committed
combined multiple foo.on() lines to simplify listener attachment
1 parent 6391561 commit 72b289f

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/jquery.autocomplete.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,21 @@
160160
container.width(options.width);
161161
}
162162

163-
// Listen for mouse over event on suggestions list:
164-
container.on('mouseover.autocomplete', suggestionSelector, function () {
165-
that.activate($(this).data('index'));
166-
});
167-
168-
// Deselect active element when mouse leaves suggestions container:
169-
container.on('mouseout.autocomplete', function () {
170-
that.selectedIndex = -1;
171-
container.children('.' + selected).removeClass(selected);
172-
});
173-
174-
// Listen for click event on suggestions list:
175-
container.on('click.autocomplete', suggestionSelector, function () {
176-
that.select($(this).data('index'));
177-
});
163+
// Add listeners to suggestion list
164+
container
165+
// Listen for mouse over event on suggestions list:
166+
.on('mouseover.autocomplete', suggestionSelector, function () {
167+
that.activate($(this).data('index'));
168+
})
169+
// Deselect active element when mouse leaves suggestions container:
170+
.on('mouseout.autocomplete', function () {
171+
that.selectedIndex = -1;
172+
container.children('.' + selected).removeClass(selected);
173+
})
174+
// Listen for click event on suggestions list:
175+
.on('click.autocomplete', suggestionSelector, function () {
176+
that.select($(this).data('index'));
177+
});
178178

179179
that.fixPositionCapture = function () {
180180
if (that.visible) {
@@ -184,12 +184,14 @@
184184

185185
$(window).on('resize.autocomplete', that.fixPositionCapture);
186186

187-
that.el.on('keydown.autocomplete', function (e) { that.onKeyPress(e); });
188-
that.el.on('keyup.autocomplete', function (e) { that.onKeyUp(e); });
189-
that.el.on('blur.autocomplete', function () { that.onBlur(); });
190-
that.el.on('focus.autocomplete', function () { that.onFocus(); });
191-
that.el.on('change.autocomplete', function (e) { that.onKeyUp(e); });
192-
that.el.on('input.autocomplete', function (e) { that.onKeyUp(e); });
187+
// Add listeners to input field
188+
that.el
189+
.on('keydown.autocomplete', function (e) { that.onKeyPress(e); })
190+
.on('keyup.autocomplete', function (e) { that.onKeyUp(e); })
191+
.on('blur.autocomplete', function () { that.onBlur(); })
192+
.on('focus.autocomplete', function () { that.onFocus(); })
193+
.on('change.autocomplete', function (e) { that.onKeyUp(e); })
194+
.on('input.autocomplete', function (e) { that.onKeyUp(e); });
193195
},
194196

195197
onFocus: function () {

0 commit comments

Comments
 (0)