Choices/src/scripts/components/list.js

38 lines
712 B
JavaScript
Raw Normal View History

2017-08-29 13:56:54 +02:00
export default class List {
2018-05-21 18:01:03 +02:00
constructor({ element }) {
Object.assign(this, { element });
2017-08-29 13:56:54 +02:00
this.scrollPos = this.element.scrollTop;
this.height = this.element.offsetHeight;
this.hasChildren = !!this.element.children;
}
/**
* Clear List contents
*/
clear() {
this.element.innerHTML = '';
}
/**
* Scroll to passed position on Y axis
*/
2017-10-11 10:39:31 +02:00
scrollTo(scrollPos = 0) {
2017-08-29 13:56:54 +02:00
this.element.scrollTop = scrollPos;
}
/**
* Append node to element
*/
append(node) {
this.element.appendChild(node);
}
/**
* Find element that matches passed selector
* @return {HTMLElement}
*/
getChild(selector) {
return this.element.querySelector(selector);
}
}