Source: popover.js

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

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

	this.observables = ["title", "label", "position"];
	console.log(this.observables);

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

    /**
     * This function is called when this is attached to DOM
     * @connectedCallback. 
     */
    connectedCallback() {
        console.group("Popover.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.innerHTML = `
		<a href="#" data-placement="${this.properties.position}" data-toggle="popover" title="${this.properties.title}" data-content="${this.dom.description}">${this.properties.label}</a>`

	$(document).ready(function(){
	    $('[data-toggle="popover"]').popover({html: true, position: "fixed"});
	});

	// WRAP UP AND ADD STATS
	this._finalize();

	// WRAP UP AND ADD STATS
	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("Popover.disconnectedCallback")

	/* CLEAN UP NOW */

        console.groupEnd();
    };

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

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

	// EXAMPLE ONLY. replace with observables
	switch(attr)
	{
	    case "title":
	    this.properties.title = newval;
	    break;

	    case "label":
	    this.properties.label = newval;
	    break;

	    case "position":
	    this.properties.position = newval;
	    break;
	}
	
        console.groupEnd();
    };

    /**
     * Stores DOM elements of interest for future use
     * @_fetchElements
     */
    _fetchElements() {
	console.group("Popover._fetchElements");
	
	this.dom = this.dom || [];
	this.dom.content = this.innerHTML;
	this.dom.description = this.querySelector("wc-popover-content").innerHTML;
	//this.querySelector("wc-popover-content").style("display","none");

	console.groupEnd();
    };

    /**
     * Component attributes are _fetched and defaults are set if undefined
     * @_fetchAttributes
     * @param {string} [title=NOTSET] popover title 
     * @param {string} [label=NOTSET] popover display label
     * @param {string} [position=right] popover position
     */
    _fetchAttributes() {
	console.group("Popover._fetchAttributes");
	

	this.properties = {
	    "cname"	 : "Popover",
	    "author"     : "Mel Heravi",
	    "version"    : "1.0",
	    "title"      : "NOTSET",
	    "label"      : "NOTSET",
	    "position"   : "right"
	};
	
	// FETCH TITLE
	if (this.hasAttribute("title")) {
	    this.properties.title = this.getAttribute("title");
	    console.log("title: ", this.properties.title);
	}

	if (this.hasAttribute("label")) {
	    this.properties.label = this.getAttribute("label");
	    console.log("label: ", this.properties.label);
	}

	if (this.hasAttribute("position")) {
	    this.properties.position = this.getAttribute("position");
	    console.log("position: ", this.properties.position);
	}

	console.groupEnd();
    };

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

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

	console.groupEnd();
    };

    /**
     * Destroy the instance object and artifacts
     * @_destroy
     */
    destroy() {
	console.group("Popover.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("Popover._finalize:", this.id);

	this.classList.add("wc");

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

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

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

	console.groupEnd();
	return true;
    }
}

window.customElements.define('wc-popover', Popover);