2018-07-05 22:18:51 -07:00
|
|
|
class DomHelper {
|
|
|
|
static isVisible(element) {
|
|
|
|
return element.offsetParent !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static openNewTab(url) {
|
2024-03-20 23:59:37 +01:00
|
|
|
const win = window.open("");
|
2018-07-05 22:18:51 -07:00
|
|
|
win.opener = null;
|
|
|
|
win.location = url;
|
|
|
|
win.focus();
|
|
|
|
}
|
|
|
|
|
2020-10-16 17:44:03 -05:00
|
|
|
static scrollPageTo(element, evenIfOnScreen) {
|
2024-03-20 23:59:37 +01:00
|
|
|
const windowScrollPosition = window.pageYOffset;
|
|
|
|
const windowHeight = document.documentElement.clientHeight;
|
|
|
|
const viewportPosition = windowScrollPosition + windowHeight;
|
|
|
|
const itemBottomPosition = element.offsetTop + element.offsetHeight;
|
2018-07-05 22:18:51 -07:00
|
|
|
|
2020-10-16 17:44:03 -05:00
|
|
|
if (evenIfOnScreen || viewportPosition - itemBottomPosition < 0 || viewportPosition - element.offsetTop > windowHeight) {
|
2018-07-05 22:18:51 -07:00
|
|
|
window.scrollTo(0, element.offsetTop - 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getVisibleElements(selector) {
|
2024-03-11 00:20:55 +01:00
|
|
|
const elements = document.querySelectorAll(selector);
|
|
|
|
return [...elements].filter((element) => this.isVisible(element));
|
2018-07-05 22:18:51 -07:00
|
|
|
}
|
|
|
|
}
|