const template = document.createElement('template'); template.innerHTML = `

TITLE

DESCRIPTION

` class AudioPlayer extends HTMLElement { constructor() { super(); this._shadowRoot = this.attachShadow({ 'mode': 'open' }); this._shadowRoot.appendChild(template.content.cloneNode(true)); this.$audioPlayer = this._shadowRoot.querySelector('#audioPlayerContainer'); } static get observedAttributes() { return ['audio', 'cover', 'cover_alt']; } attributeChangedCallback(name, oldVal, newVal) { if (oldVal != newVal) { this[name] = newVal; this.render(); } } render() { this.cover ? this.$audioPlayer.querySelector('img').src = this.cover : null; this.cover_alt ? this.$audioPlayer.querySelector('img').alt = this.cover_alt : null; this.audio ? this.$audioPlayer.querySelector('audio source').src = this.audio : null; } } window.customElements.define('audio-player', AudioPlayer);