jellyfish-web/src/elements/emby-radio/emby-radio.js

84 lines
2.4 KiB
JavaScript
Raw Normal View History

import layoutManager from 'layoutManager';
import 'css!./emby-radio';
import 'registerElement';
/* eslint-disable indent */
2020-07-11 11:23:28 +01:00
let EmbyRadioPrototype = Object.create(HTMLInputElement.prototype);
2018-10-23 01:05:09 +03:00
function onKeyDown(e) {
// Don't submit form on enter
2020-03-11 22:19:26 +03:00
// Real (non-emulator) Tizen does nothing on Space
if (e.keyCode === 13 || e.keyCode === 32) {
e.preventDefault();
2020-03-11 15:04:29 +03:00
if (!this.checked) {
this.checked = true;
this.dispatchEvent(new CustomEvent('change', {
bubbles: true
}));
}
return false;
}
2018-10-23 01:05:09 +03:00
}
EmbyRadioPrototype.attachedCallback = function () {
2020-07-11 11:23:28 +01:00
const showFocus = !layoutManager.mobile;
if (this.getAttribute('data-radio') === 'true') {
return;
2018-10-23 01:05:09 +03:00
}
this.setAttribute('data-radio', 'true');
this.classList.add('mdl-radio__button');
2020-07-11 11:23:28 +01:00
let labelElement = this.parentNode;
//labelElement.classList.add('"mdl-radio mdl-js-radio mdl-js-ripple-effect');
labelElement.classList.add('mdl-radio');
labelElement.classList.add('mdl-js-radio');
labelElement.classList.add('mdl-js-ripple-effect');
2020-03-12 20:45:27 +03:00
if (showFocus) {
labelElement.classList.add('show-focus');
}
2020-07-11 11:23:28 +01:00
let labelTextElement = labelElement.querySelector('span');
labelTextElement.classList.add('radioButtonLabel');
labelTextElement.classList.add('mdl-radio__label');
2020-07-11 11:23:28 +01:00
let html = '';
2020-03-12 12:34:50 +03:00
html += '<div class="mdl-radio__circles">';
html += '<svg>';
html += '<defs>';
html += '<clipPath id="cutoff">';
html += '<circle cx="50%" cy="50%" r="50%" />';
html += '</clipPath>';
html += '</defs>';
html += '<circle class="mdl-radio__outer-circle" cx="50%" cy="50%" r="50%" fill="none" stroke="currentcolor" stroke-width="0.26em" clip-path="url(#cutoff)" />';
html += '<circle class="mdl-radio__inner-circle" cx="50%" cy="50%" r="25%" fill="currentcolor" />';
html += '</svg>';
2020-03-12 20:45:27 +03:00
if (showFocus) {
html += '<div class="mdl-radio__focus-circle"></div>';
}
2020-03-12 12:34:50 +03:00
html += '</div>';
this.insertAdjacentHTML('afterend', html);
this.addEventListener('keydown', onKeyDown);
};
document.registerElement('emby-radio', {
2018-10-23 01:05:09 +03:00
prototype: EmbyRadioPrototype,
extends: 'input'
});
/* eslint-enable indent */