(function(window) { 'use strict'; var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { var buttons = document.createDocumentFragment(); [].forEach.call(this.querySelectorAll('button'), (button) => { buttons.appendChild(button); }); var shadowRoot = this.createShadowRoot(); shadowRoot.innerHTML = `
`; var $id = shadowRoot.getElementById.bind(shadowRoot); this.els = { container: $id('container'), content: $id('content'), heading: $id('heading'), message: $id('message'), menu: $id('menu') }; this.els.menu.appendChild(buttons); this.els.menu.addEventListener('click', (evt) => { var button = evt.target.closest('button[data-action]'); if (button) { this.dispatchEvent(new CustomEvent('action', { detail: button.dataset.action })); } }); this.els.heading.textContent = this.getAttribute('heading'); this.els.message.textContent = this.getAttribute('message'); this.els.heading.dataset.l10nId = this.getAttribute('heading-l10n-id'); this.els.message.dataset.l10nId = this.getAttribute('message-l10n-id'); this.onDOMRetranslated = () => { document.l10n.translateFragment(shadowRoot); }; }; proto.attachedCallback = function() { document.addEventListener('DOMRetranslated', this.onDOMRetranslated); this.onDOMRetranslated(); }; proto.detachedCallback = function() { document.removeEventListener('DOMRetranslated', this.onDOMRetranslated); }; proto.attributeChangedCallback = function(attr, oldVal, newVal) { switch (attr) { case 'heading': this.els.heading.textContent = newVal; break; case 'message': this.els.message.textContent = newVal; break; case 'heading-l10n-id': this.els.heading.dataset.l10nId = newVal; this.onDOMRetranslated(); break; case 'message-l10n-id': this.els.message.dataset.l10nId = newVal; this.onDOMRetranslated(); break; } }; proto.addActionButton = function(title, action, className = '') { var button = document.createElement('button'); button.type = 'button'; button.textContent = title; button.dataset.action = action; button.className = className; this.els.menu.appendChild(button); }; proto.removeActionButton = function(action) { var buttons = this.els.menu.querySelectorAll(`[data-action="${action}"]`); [].forEach.call(buttons, button => this.els.menu.removeChild(button)); }; ['heading', 'message'].forEach((prop) => { Object.defineProperty(proto, prop, { get: function() { return this.getAttribute(prop); }, set: function(value) { this.setAttribute(prop, value || ''); } }); }); try { window.MusicOverlay = document.registerElement('music-overlay', { prototype: proto }); } catch (e) { if (e.name !== 'NotSupportedError') { throw e; } } })(window);