Skip to content
Snippets Groups Projects
Commit 8660b7ad authored by Ere Maijala's avatar Ere Maijala
Browse files

Switched to trigger() for the selection event so that it can be bound to with...

Switched to trigger() for the selection event so that it can be bound to with the bind() function and the initialization function doesn't need to be modified.
Moved the autocomplete window to the form so that the bounding rect is not needed thus avoiding positioning problems e.g. when window is scrolled while suggestions are loading.
Align suggestions when window is resized.
Set the initial content with .html().
Use the greater of input width and form width for the maximum autocomplete list width instead of the arbitrary * 2 width.
parent c543d8d6
Branches
Tags
No related merge requests found
...@@ -18,9 +18,7 @@ ...@@ -18,9 +18,7 @@
function populate(value, input, eventType) { function populate(value, input, eventType) {
input.val(value); input.val(value);
hide(); hide();
if (typeof options.onselection !== 'undefined') { input.trigger('autocomplete:select', {value: value, eventType: eventType});
options.onselection(value, input, eventType);
}
} }
function createList(data, input) { function createList(data, input) {
...@@ -96,13 +94,13 @@ ...@@ -96,13 +94,13 @@
} }
function align(input, element) { function align(input, element) {
var offset = input[0].getBoundingClientRect(); var position = input.position();
element.css({ element.css({
position: 'absolute', position: 'absolute',
top: offset.top + offset.height, top: position.top + input.outerHeight(),
left: offset.left, left: position.left,
maxWidth: offset.width * 2, minWidth: input.width() / 2,
minWidth: offset.width, maxWidth: Math.max(input.width(), input.closest('form').width()),
zIndex: 50 zIndex: 50
}); });
} }
...@@ -111,9 +109,12 @@ ...@@ -111,9 +109,12 @@
if (typeof element === 'undefined') { if (typeof element === 'undefined') {
element = $('<div/>') element = $('<div/>')
.addClass('autocomplete-results hidden') .addClass('autocomplete-results hidden')
.text('<i class="item loading">'+options.loadingString+'</i>'); .html('<i class="item loading">'+options.loadingString+'</i>');
align(input, element); align(input, element);
$('body').append(element); input.closest('form').append(element);
$(window).resize(function() {
align(input, element);
});
} }
input.data('selected', -1); input.data('selected', -1);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment