Source: card.js

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

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

	let observables = ["width", "height"];
	console.log(observables);

        console.groupEnd();
        return observables;
    };

    /**
     * This function is called when this is attached to DOM
     * @connectedCallback. 
     */
    connectedCallback() {
        console.group("Card.connectedCallback")
	
	let self = this;
	
	// ADD MTK CLASS
	this.classList.add("wc");

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

	// FETCH ALL ATTRIBUTES
	this._fetchAttributes();

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

	/* CLEAN UP NOW */

        console.groupEnd();
    };

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

	/* CLEAN UP NOW */

        console.groupEnd();
    };

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

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

	switch(attr)
	{
	    case "width":
	    this.properties.width = newval;
	    this.setAttribute("style", "width:" + this.properties.width);
	    this.style.width = this.properties.width;
	    break;

	    case "height":
	    this.properties.height = newval;
	    this.setAttribute("style", "height:" + this.properties.height);
	    this.style.height = this.properties.height;
	    break;
	}
	
        console.groupEnd();
    };

    /**
     * Stores DOM elements of interest for future use
     * @_fetchElements
     */
    _fetchElements() {
	console.group("Card._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} author component owner
     * @param {string} version Latest version of this component
     * @param {string} [height=100%] body height
     * @param {string} [width=100%] panel width
     */
    _fetchAttributes() {
	console.group("Card._fetchAttributes");
	
	this.properties = this.properties || [];

	this.properties = {
	    "cname"   : "Card",
	    "author"  : "Mel Heravi",
	    "version" : "1.0",
	    "user"    : "Mel",
	    "width"   : "100%",
	    "height"  : "100%"
	};

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

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

	console.groupEnd();
    };

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

	delete this;

	this.parentNode.removeChild(this);

	console.groupEnd();
    };

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

	// ADD ANALYTICS HERE	this.classList.add("wc");


	wc.getStats(this, this.properties.cname, this.properties.version);
	
	console.groupEnd();
    };

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

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

	console.groupEnd();
	return true;
    }
}

window.customElements.define('wc-card', Card);