Skip to content

Instantly share code, notes, and snippets.

@zbyte64
Last active October 23, 2015 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbyte64/b9cba91637d51355eb08 to your computer and use it in GitHub Desktop.
Save zbyte64/b9cba91637d51355eb08 to your computer and use it in GitHub Desktop.
Custom tag examples
/*
Registers the following tags (use is property):
* x-googlemap (iframe with api-key & address properties)
be sure to enable polyfill: https://github.com/WebReflection/document-register-element
*/
(function() {
var GoogleMapProto = Object.create(HTMLElement.prototype);
Object.defineProperty(GoogleMapProto, "address", {writable: true});
Object.defineProperty(GoogleMapProto, "api-key", {writable: true});
GoogleMapProto.computeSrc = function(key, address) {
return 'https://www.google.com/maps/embed/v1/place?key='+encodeURIComponent(key)+"&q="+encodeURIComponent(address);
}
GoogleMapProto.updateSrc = function() {
this.setAttribute('src', this.computeSrc(this.getAttribute('api-key'), this.getAttribute('address')));
}
GoogleMapProto.createdCallback = function() {
this.updateSrc();
}
GoogleMapProto.attributeChangedCallback = function(attrName, oldValue, newValue) {
if (attrName === 'api-key' || attrName === 'address') {
this.updateSrc();
}
}
var GoogleMap = document.registerElement('x-googlemap', {
prototype: GoogleMapProto,
extends: 'iframe'
});
console.log("registered", GoogleMap)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment