2018-07-06 07:18:51 +02:00
|
|
|
class DomHelper {
|
|
|
|
static isVisible(element) {
|
|
|
|
return element.offsetParent !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static openNewTab(url) {
|
|
|
|
let win = window.open("");
|
|
|
|
win.opener = null;
|
|
|
|
win.location = url;
|
|
|
|
win.focus();
|
|
|
|
}
|
|
|
|
|
2020-10-17 00:44:03 +02:00
|
|
|
static scrollPageTo(element, evenIfOnScreen) {
|
2018-07-06 07:18:51 +02:00
|
|
|
let windowScrollPosition = window.pageYOffset;
|
|
|
|
let windowHeight = document.documentElement.clientHeight;
|
|
|
|
let viewportPosition = windowScrollPosition + windowHeight;
|
|
|
|
let itemBottomPosition = element.offsetTop + element.offsetHeight;
|
|
|
|
|
2020-10-17 00:44:03 +02:00
|
|
|
if (evenIfOnScreen || viewportPosition - itemBottomPosition < 0 || viewportPosition - element.offsetTop > windowHeight) {
|
2018-07-06 07:18:51 +02:00
|
|
|
window.scrollTo(0, element.offsetTop - 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getVisibleElements(selector) {
|
|
|
|
let elements = document.querySelectorAll(selector);
|
|
|
|
let result = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < elements.length; i++) {
|
|
|
|
if (this.isVisible(elements[i])) {
|
|
|
|
result.push(elements[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-07-11 05:41:27 +02:00
|
|
|
static hasPassiveEventListenerOption() {
|
|
|
|
var passiveSupported = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var options = Object.defineProperty({}, "passive", {
|
|
|
|
get: function() {
|
|
|
|
passiveSupported = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener("test", options, options);
|
|
|
|
window.removeEventListener("test", options, options);
|
|
|
|
} catch(err) {
|
|
|
|
passiveSupported = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return passiveSupported;
|
|
|
|
}
|
2018-07-06 07:18:51 +02:00
|
|
|
}
|