Skip to content

Commit

Permalink
container function to generate container element
Browse files Browse the repository at this point in the history
addresses a use case where container element cannot reuse input element parent
because input parent clips container content

also solves LeaVerou#17086
  • Loading branch information
Natalia Kowalczyk committed May 27, 2018
1 parent f1440f2 commit 33f9ec6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var _ = function (input, o) {
data: _.DATA,
filter: _.FILTER_CONTAINS,
sort: o.sort === false ? false : _.SORT_BYLENGTH,
container: _.CONTAINER,
item: _.ITEM,
replace: _.REPLACE
}, o);
Expand All @@ -40,10 +41,7 @@ var _ = function (input, o) {

// Create necessary elements

this.container = $.create("div", {
className: "awesomplete",
around: input
});
this.container = this.container(input);

this.ul = $.create("ul", {
hidden: "hidden",
Expand Down Expand Up @@ -351,6 +349,13 @@ _.SORT_BYLENGTH = function (a, b) {
return a < b? -1 : 1;
};

_.CONTAINER = function (input) {
return $.create("div", {
className: "awesomplete",
around: input
});
}

_.ITEM = function (text, input, item_id) {
var html = input.trim() === "" ? text : text.replace(RegExp($.regExpEscape(input.trim()), "gi"), "<mark>$&</mark>");
return $.create("li", {
Expand Down
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ <h1>Extend</h1>
<td>Sort function (will be passed directly to <code>Array.prototype.sort()</code>) to sort the items after they have been filtered and before they are truncated and converted to HTML elements. If value is <code>false</code>, sorting will be disabled.</td>
<td>Sorted by length first, order second.</td>
</tr>
<tr>
<td><code>container</code></td>
<td>Controls how list container element generated.</td>
<td>Function that takes one parameter, the user’s input and returns an element.</td>
<td>Generates <code>&lt;div></code> with class <code>awesomplete</code></td>
</tr>
<tr>
<td><code>item</code></td>
<td>Controls how list items are generated.</td>
Expand Down

0 comments on commit 33f9ec6

Please sign in to comment.