Skip to content

Commit

Permalink
add possibility to use another container for suggestion items list (e…
Browse files Browse the repository at this point in the history
…xample: document.body)
  • Loading branch information
Benjamin Svobodny authored and bsvobodny committed Aug 24, 2017
1 parent b98f47b commit 92e837d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 23 deletions.
6 changes: 4 additions & 2 deletions awesomplete.base.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
display: block;
}

.awesomplete > ul {
.awesomplete > ul,
ul.awesomplete-suggestion-list {
position: absolute;
left: 0;
z-index: 1;
Expand All @@ -28,6 +29,7 @@
background: #fff;
}

.awesomplete > ul:empty {
.awesomplete > ul:empty,
ul.awesomplete-suggestion-list:empty {
display: none;
}
29 changes: 20 additions & 9 deletions awesomplete.css

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

2 changes: 1 addition & 1 deletion awesomplete.css.map

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

17 changes: 15 additions & 2 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: o.sort === false ? false : _.SORT_BYLENGTH,
item: _.ITEM,
replace: _.REPLACE
replace: _.REPLACE,
listContainer: _.CONTAINER
}, o);

this.index = -1;
Expand All @@ -42,7 +43,8 @@ var _ = function (input, o) {

this.ul = $.create("ul", {
hidden: "hidden",
inside: this.container
className: "awesomplete-suggestion-list",
inside: me.listContainer === _.CONTAINER ? me.container : me.listContainer
});

this.status = $.create("span", {
Expand Down Expand Up @@ -169,7 +171,16 @@ _.prototype = {
},

open: function () {
if (this.listContainer !== _.CONTAINER) {
// In case the suggestion list is out of the container,
// get the bounding information of the container to set the position of the suggestion list below
var boundingRect = this.container.getBoundingClientRect()
this.ul.style.top = (boundingRect.top + boundingRect.height) + "px";
this.ul.style.left = boundingRect.left + "px";
this.ul.style["min-width"] = boundingRect.width + "px";
}
this.ul.removeAttribute("hidden");

this.isOpened = true;

if (this.autoFirst && this.index === -1) {
Expand Down Expand Up @@ -333,6 +344,8 @@ _.REPLACE = function (text) {
this.input.value = text.value;
};

_.CONTAINER = "container";

_.DATA = function (item/*, input*/) { return item; };

// Private functions
Expand Down
Loading

0 comments on commit 92e837d

Please sign in to comment.