HEX
Server: Apache
System: Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux
User: ws67301310 (67301310)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /homepages/4/d4297730999/htdocs/wordpress/wp-content/plugins/fasthosts-journey/js/parts/overlay.js
export default class Overlay {

    constructor() {
        this.parent = document.body
        this.id = 'fasthosts-journey-overlay'
        this.add()

        this.registerClickEvent()
        this.onClick = []
    }

    getHtmlElement() {
        return document.body.querySelector('#' + this.id)
    }

    registerClickEvent() {
        this.getHtmlElement().addEventListener('click', (e) => {
            if (e.target === this.getHtmlElement()) {
                this.onClick.forEach((fn) => {
                    fn()
                })
            }
        })
    }

    add() {
        let el = document.createElement('DIV')
        el.id = this.id
        this.parent.prepend(el)
    }

    setBackground(color){
        this.getHtmlElement().style.backgroundColor = color;
    }

    hide() {
        this.getHtmlElement().style.display = 'none'
    }
}