/**
* A Footer Component - 95% UX/COE Compliant
* <BR><BR><img src=../images/footer.png width=100% style="border:1px lime dashed";>
* <BR><BR><a href="../html/footer.html">DEMO</a>
*/
class Footer extends HTMLElement {
constructor() {
console.group("Footer.constructor")
super();
console.groupEnd();
};
/**
* Set observable values here. When Changed, attributeChangedCallback is invoked
* @observedAttributes
*/
static get observedAttributes() {
console.group("Footer.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("Footer.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 = `
<div class=wc-footer-container>
<div class=wc-footer-container-inner>
<div class=container>
<div class=row>
<div class=col-md-12>
<div class='wc-footer-lhs'>
<wc-footer-logo>
<img src='/Melify/mtk/dev/tk/lib/components/w3c/assets/DTCC_pos_rgb_83X20.png' />
</wc-footer-logo>
<wc-footer-menus-lhs>
${this.dom.lmenus}
</wc-footer-menus>
</div>
<div class='wc-footer-rhs'>
<wc-footer-menus-rhs>${this.dom.rmenus}</wc-footer-menus>
<wc-footer-copyright>${this.dom.copyright}</wc-footer-copyright>
</wc-footer-menus-rhs>
</div>
</div>
</div>
</div>
</div>
</div>`
let links = this.querySelectorAll("li a");
for (let i=0; i<links.length; i++) {
let link = links[i];
link.addEventListener("click", function() {
self._onClick(link);
});
}
// 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("Footer.disconnectedCallback")
/* CLEAN UP NOW */
console.groupEnd();
};
/**
* Called with .setAttribute(...) function call
* @attributeChangedCallback
*/
attributeChangedCallback(attr, oldval, newval) {
console.group("Footer.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("Footer._fetchElements");
this.dom = this.dom || [];
this.dom.content = this.innerHTML;
this.dom.lmenus = this.querySelector("wc-footer-menus-lhs").innerHTML;
this.dom.rmenus = this.querySelector("wc-footer-menus-rhs").innerHTML;
this.dom.copyright = this.querySelector("wc-footer-copyright").innerHTML;
console.groupEnd();
};
/**
* Component attributes are _fetched and defaults are set if undefined
* @_fetchAttributes
* @param {string} [background=indianred] background color
*/
_fetchAttributes() {
console.group("Footer._fetchAttributes");
this.properties = {
"cname" : "Footer",
"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("Footer._onClick:", link);
wc.publish(this, "wc-footer", {
action: "click",
id: link.id
});
console.groupEnd();
};
/**
* Destroy the instance object and artifacts
* @_destroy
*/
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("Footer._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("Footer.test");
console.log("testing results will be printed here...");
console.groupEnd();
return true;
}
}
window.customElements.define('wc-footer', Footer);