Source: stepper.js

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

        console.groupEnd();
    };
    
    /**
     * Set observable values here. When Changed, attributeChangedCallback is invoked
     * @observedAttributes
     */
    static get observedAttributes() {
        console.group("Stepper.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("Stepper.connectedCallback")
	
	let self = this;

	// MAKE SURE OUR COMPONENT HAS GLOBAL CLASS
	this.classList.add("wc");

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

	// FETCH ALL ATTRIBUTES
	this._fetchAttributes();

	this.innerHTML = this.dom.content;

	let links = this.querySelectorAll("wc-step");

	for (let i=0; i<links.length; i++) {
	    let link = links[i]

	    // IT IS A LINK, PUBLISH CALLBACKS
	    if (link.classList.contains("is-link")) {
		var image = new Image();image.src = "/Melify/mtk/dev/tk/lib/components/w3c/assets/stepper/SP_1.png";
		link.parentNode.insertBefore(image, link.nextSibling);
		
		link.addEventListener("click", function() {
		    self._onClick(link);
		});
	    };
	    
	    if (link.classList.contains("is-next")) {
		var image = new Image();image.src = "/Melify/mtk/dev/tk/lib/components/w3c/assets/stepper/SP_3.png";
		link.parentNode.insertBefore(image, link.nextSibling);
	    };
	    
	    if (link.classList.contains("is-current")) {
		var image = new Image();image.src = "/Melify/mtk/dev/tk/lib/components/w3c/assets/stepper/SP_2.png";
		link.parentNode.insertBefore(image, link.nextSibling);
	    };
	}

	// 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("Stepper.disconnectedCallback")

	/* CLEAN UP NOW */

        console.groupEnd();
    };

    /**
     * Called with .setAttribute(...) function call
     * @attributeChangedCallback
     */
    attributeChangedCallback(attr, oldval, newval) {
        console.group("Stepper.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("Stepper._fetchElements");
	
	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("Stepper._fetchAttributes");
	
	this.dom = this.dom || [];

	this.properties = {
	    "cname"      : "Stepper",
	    "author"     : "Mel Heravi",
	    "version"    : "1.0",
	    "background" : "indianred"
	};

	// EXAMPLE ONLY. replace with attributes
	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(link) {
	console.group("Stepper._onClick", link);

	//PUBLISH TO THE EVENT
	wc.publish(this, "wc-stepper", {
	    link: link,
	    action: "click"
	});

	console.groupEnd();
    };

    /**
     * Destroy the instance object and artifacts
     * @_destroy
     * @param {object} link step user clicked on
     */
    destroy() {
	console.group("Message.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("Stepper._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("Stepper.test");

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

	console.groupEnd();
	return true;
    }
}

window.customElements.define('wc-stepper', Stepper);