2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-25 14:17:45 +00:00

Add inner container, so that styling can be more flexible.

This commit is contained in:
Tomas Kirda 2013-06-27 17:05:37 -05:00
parent 6a9c2caaf7
commit 96714d286e

View File

@ -93,6 +93,7 @@
that.onChange = null; that.onChange = null;
that.isLocal = false; that.isLocal = false;
that.suggestionsContainer = null; that.suggestionsContainer = null;
that.innerContainer = null;
that.options = $.extend({}, defaults, options); that.options = $.extend({}, defaults, options);
that.classes = { that.classes = {
selected: 'autocomplete-selected', selected: 'autocomplete-selected',
@ -126,7 +127,8 @@
suggestionSelector = '.' + that.classes.suggestion, suggestionSelector = '.' + that.classes.suggestion,
selected = that.classes.selected, selected = that.classes.selected,
options = that.options, options = that.options,
container; container,
innerContainer;
// Remove autocomplete attribute to prevent native suggestions: // Remove autocomplete attribute to prevent native suggestions:
that.element.setAttribute('autocomplete', 'off'); that.element.setAttribute('autocomplete', 'off');
@ -138,12 +140,13 @@
} }
}; };
that.suggestionsContainer = Autocomplete.utils.createNode('<div class="' + options.containerClass + '" style="position: absolute; display: none;"></div>'); that.suggestionsContainer = Autocomplete.utils.createNode('<div class="' + options.containerClass + '" style="position: absolute; display: none;"><div class="autocomplete-inner"></div></div>');
container = $(that.suggestionsContainer); container = $(that.suggestionsContainer);
container.appendTo(options.appendTo); container.appendTo(options.appendTo);
that.innerContainer = $('.autocomplete-inner', container);
// Only set width if it was provided: // Only set width if it was provided:
if (options.width !== 'auto') { if (options.width !== 'auto') {
container.width(options.width); container.width(options.width);
@ -473,6 +476,7 @@
className = that.classes.suggestion, className = that.classes.suggestion,
classSelected = that.classes.selected, classSelected = that.classes.selected,
container = $(that.suggestionsContainer), container = $(that.suggestionsContainer),
innerContainer = that.innerContainer,
html = '', html = '',
width; width;
@ -490,13 +494,14 @@
container.width(width > 0 ? width : 300); container.width(width > 0 ? width : 300);
} }
container.html(html).show(); innerContainer.html(html);
container.show();
that.visible = true; that.visible = true;
// Select first value by default: // Select first value by default:
if (that.options.autoSelectFirst) { if (that.options.autoSelectFirst) {
that.selectedIndex = 0; that.selectedIndex = 0;
container.children().first().addClass(classSelected); innerContainer.children().first().addClass(classSelected);
} }
that.findBestHint(); that.findBestHint();