Skip to content
Snippets Groups Projects
Commit 7a27debb authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Autocomplete updates, including PR533.

parent 26778c01
Branches
Tags
No related merge requests found
/** /**
* vufind.typeahead.js 0.6 * vufind.typeahead.js 0.8
* ~ @crhallberg * ~ @crhallberg
*/ */
(function ( $ ) { (function ( $ ) {
...@@ -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) {
...@@ -58,7 +56,7 @@ ...@@ -58,7 +56,7 @@
} }
$.fn.autocomplete.element.html(shell); $.fn.autocomplete.element.html(shell);
$.fn.autocomplete.element.find('.item').mousedown(function() { $.fn.autocomplete.element.find('.item').mousedown(function() {
populate($(this).attr('data-value'), input, {mouse: true}) populate($(this).attr('data-value'), input, {mouse: true});
}); });
align(input, $.fn.autocomplete.element); align(input, $.fn.autocomplete.element);
} }
...@@ -99,10 +97,10 @@ ...@@ -99,10 +97,10 @@
var offset = input[0].getBoundingClientRect(); var offset = input[0].getBoundingClientRect();
element.css({ element.css({
position: 'absolute', position: 'absolute',
top: offset.top + offset.height, top: offset.top + offset.height + document.body.scrollTop,
left: offset.left, left: offset.left,
maxWidth: offset.width * 2,
minWidth: offset.width, minWidth: offset.width,
maxWidth: 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); $('body').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