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 Benjamin Svobodny committed Aug 10, 2017
1 parent b98f47b commit b8099ab
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 24 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.

20 changes: 18 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,11 @@ _.prototype = {
},

open: function () {
if (this.listContainer !== 'container') {
this.setListPosition();
}
this.ul.removeAttribute("hidden");

this.isOpened = true;

if (this.autoFirst && this.index === -1) {
Expand All @@ -179,6 +185,14 @@ _.prototype = {
$.fire(this.input, "awesomplete-open");
},

setListPosition: function () {
//get the bounding of the container to set the position of the suggestion list below
var boudingRect = this.container.getBoundingClientRect()
this.ul.style.top = (boudingRect.y + boudingRect.height) + 'px';
this.ul.style.left = boudingRect.x + 'px';
this.ul.style['min-width'] = boudingRect.width + 'px';
},

destroy: function() {
//remove events from the input and its form
$.unbind(this.input, this._events.input);
Expand Down Expand Up @@ -333,6 +347,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 b8099ab

Please sign in to comment.