getaddress-autocomplete-modal
Version:
GetAddress.io - Autocomplete modal plug-in
41 lines • 1.67 kB
JavaScript
import Storage from "./Storage.js";
import HistoryContainer from "./HistoryContainer.js";
export default class HistoryList {
constructor(modal, attributeValues) {
this.modal = modal;
this.attributeValues = attributeValues;
this.list = document.createElement('DIV');
this.element = this.list;
this.build = () => {
this.list.id = this.attributeValues.historyListId;
this.list.className = this.attributeValues.historyListClassName;
this.list.style.display = 'none';
this.list.setAttribute('role', 'listbox');
this.list.addEventListener('mouseenter', this.handleMouseEnter);
this.list.addEventListener('click', this.handleClick);
};
this.handleMouseEnter = () => { };
this.handleClick = () => { };
this.populate = () => {
this.clear();
const savedAddresses = Storage.list();
savedAddresses.forEach(sa => {
var container = new HistoryContainer(this.modal, this.attributeValues, sa.address, sa.id, this);
this.list.insertBefore(container.element, null);
});
if (savedAddresses.length > 0) {
this.list.style.display = 'block';
}
};
this.clear = () => {
this.list.style.display = 'none';
this.list.replaceChildren(...[]);
};
this.build();
}
destroy() {
this.list.removeEventListener('mouseenter', this.handleMouseEnter);
this.list.removeEventListener('click', this.handleClick);
}
}
//# sourceMappingURL=HistoryList.js.map