Let's say you want a build a page like
Say a Date Picker..
window.$j = jQuery.noConflict();
.search .datepicker
{
background:green;
}
.widget-clock .datepicker
{
background:yellow;
}
If you can write a tag like
and a date picker will be generated for you
Or this
My Project
Home</link>
About</link>
Contact</link>
And a Bootstrap Inverse Navbar will be scaffolded
This is already present in our browser
Check : Inspecting Elements
Web Components === Write your own HTML tags & behaviours
Are built using 4 key pieces
$("template img") or document.querySelectorAll("template img")
)
Encapsulate HTML will be stored here
This will appear in uppercase!!
<script>
// the element on page
var textShadow = document.querySelector('#uppercase-ele')
.createShadowRoot();
var template = document.querySelector('#uppercase');
textShadow.appendChild(template.content.toUpperCase());
</script>
THIS WILL APPEAR IN UPPERCASE
TagName(HTML Templates + Shadow DOM) = Custom Elements
Capitalize Me
This would look more Semantic-ish
Capitalize Me
registerElement()
to create a new element-
(dash)var customButton = document.registerElement('custom-button', {
prototype: Object.create(HTMLButtonElement.prototype),
extends: 'button'
});
createdCallback
-- Custom Element createdattachedCallback
-- Custom Element Attached to DOMdetachedCallback
-- Custom Element Removed from DOMattributeChangedCallback
-- Custom Element Added or Updated or Removedvar obj = {
createdCallback: function(){
var shadow = this.createShadowRoot();
var template = document.querySelector('#message');
shadow.appendChild(template.content);
},
attachedCallback : function(){
console.log("attached Callback");
},
detachedCallback : function(){
console.log("detached Callback");
},
attributeChangedCallback : function(attrName, oldVal, newVal){
console.log("attrname : "+attrname+" :: oldval : "+oldVal+" :: newval : "+newVal)
}
}
var customPrototype = Object.create(HTMLElement.prototype, obj);
var upperCase = document.registerElement('upper-case', {prototype: customPrototype});