Source: tooltip.js

/**
 * A Tooltip Component - 90% UX/COE Compliant
 * <BR><BR><img src=../images/tooltip.png width=50% style="border:1px lime dashed";>
 * <BR><BR><a href="../html/tooltip.html">DEMO</a>
 */
class Tooltip extends HTMLElement {
    constructor() {
        console.group("Tooltip.constructor")
	
        super();

        console.groupEnd();
    };
    
    /**
     * Set observable values here. When Changed, attributeChangedCallback is invoked
     * @observedAttributes
     */
    static get observedAttributes() {
        console.group("Tooltip.observedAttributes");

	this.observables = ["background"];
	console.log(this.observables);

        console.groupEnd();
        return this.observables;
    };

    /**
     * This function is called when this is attached to DOM
     * @connectedCallback. 
     */
    connectedCallback() {
        console.group("Tooltip.connectedCallback")
	
	let self = this;

	// FETCH ALL INTERESTING ELEMENTS
	this._fetchElements();

	// FETCH ALL ATTRIBUTES
	this._fetchAttributes();

	// REPLACE CONTENT IF NECESSARY WITH NEW STUFF
	this.innerHTML = this.dom.content;

	this._finalize();

	// SHOW IT NOW (NO FLICKERS) 
	this.style.visibility = "visible";

        console.groupEnd();
    };

    /**
     * Invoked When component is removed. Usually with a .remove() function call
     * @disconnectedCallback
     */
    disconnectedCallback() {
        console.group("Tooltip.disconnectedCallback")

	/* CLEAN UP NOW */

        console.groupEnd();
    };

    /**
     * Called with .setAttribute(...) function call
     * @attributeChangedCallback
     */
    attributeChangedCallback(attr, oldval, newval) {
        console.group("Tooltip.attributeChangedCallback:", attr, oldval, newval);

	this.properties = this.properties || [];

	// EXAMPLE ONLY. replace with observables
	switch(attr)
	{
	    case "background":
	    this.properties.background = newval;
	    this.style.background = this.properties.background;
	    break;
	}
	
        console.groupEnd();
    };

    /**
     * Stores DOM elements of interest for future use
     * @_fetchElements
     */
    _fetchElements() {
	console.group("Tooltip._fetchElements");
	
	this.dom = this.dom || [];
	this.dom.content = this.innerHTML;

	console.groupEnd();
    };

    /**
     * Component attributes are _fetched and defaults are set if undefined
     * @_fetchAttributes
     * @param {string} [background=indianred] background color
     */
    _fetchAttributes() {
	console.group("Tooltip._fetchAttributes");
	
	this.properties = {
	    "cname"	 : "Tooltip",
	    "author"     : "Mel Heravi",
	    "version"    : "1.0",
	    "background" : "indianred"
	};
	
	// FETCH BACKGROUND
	if (this.hasAttribute("background")) {
	    this.properties.background = this.getAttribute("background");
	    console.log("background: ", this.properties.background);
	}

	console.groupEnd();
    };

    /**
     * A sample callback usage function - see connectedCallback()
     * @_onClick
     */
    _onClick() {
	console.group("Tooltip._onClick:", this.id);

	wc.publish(this, "wc-tooltip", {
	    action: "click",
	    id: this.id
	});

	console.groupEnd();
    };

    /**
     * Destroy the instance object and artifacts
     * @_destroy
     */
    destroy() {
	console.group("Tooltip.destroy:", this.id);

	// FREE POINTER
	delete this;

	// REMOVE ITEM FROM DOM
	this.parentNode.removeChild(this);

	console.groupEnd();
    };

    /**
     * SAVE DATA FOR ANALYTICS
     * @__finalize
     */
    _finalize() {
	console.group("Tooltip._finalize:", this.id);

	// ADD ANALYTICS HERE
	wc.getStats(this, this.properties.cname, this.properties.version);
	
	console.groupEnd();
    };

    /**
     * FOR TESTING PURPOSES
     * @test
     */
    static test() {
	console.group("Tooltip.test");

	console.log("testing results will be printed here...");

	console.groupEnd();
	return true;
    }
}

window.customElements.define('wc-tooltip', Tooltip);