Skip to content

Commit

Permalink
Allow the user to specify a custom autocomplete tag LeaVerou#16981
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoko committed Oct 7, 2016
1 parent 8185a3c commit 7322999
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var _ = function (input, o) {
filter: _.FILTER_CONTAINS,
sort: _.SORT_BYLENGTH,
item: _.ITEM,
replace: _.REPLACE
replace: _.REPLACE,
ul: undefined
}, o);

this.index = -1;
Expand All @@ -40,7 +41,8 @@ var _ = function (input, o) {
around: input
});

this.ul = $.create("ul", {
// Prevent unnecessary dom manipulation
this.ul = this.ul || $.create("ul", {
hidden: "hidden",
inside: this.container
});
Expand Down Expand Up @@ -301,8 +303,8 @@ _.DATA = function (item/*, input*/) { return item; };

function Suggestion(data) {
var o = Array.isArray(data)
? { label: data[0], value: data[1] }
: typeof data === "object" && "label" in data && "value" in data ? data : { label: data, value: data };
? { label: data[0], value: data[1] }
: typeof data === "object" && "label" in data && "value" in data ? data : { label: data, value: data };

this.label = o.label || o.value;
this.value = o.value;
Expand All @@ -317,7 +319,7 @@ Suggestion.prototype.toString = Suggestion.prototype.valueOf = function () {
function configure(instance, properties, o) {
for (var i in properties) {
var initial = properties[i],
attrValue = instance.input.getAttribute("data-" + i.toLowerCase());
attrValue = instance.input.getAttribute("data-" + i.toLowerCase());

if (typeof initial === "number") {
instance[i] = parseInt(attrValue);
Expand Down
2 changes: 1 addition & 1 deletion awesomplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7322999

Please sign in to comment.