jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/emby-checkbox/emby-checkbox.js
2016-06-11 11:55:39 -04:00

45 lines
1.4 KiB
JavaScript

define(['css!./emby-checkbox', 'registerElement'], function () {
var EmbyCheckboxPrototype = Object.create(HTMLInputElement.prototype);
function onKeyDown(e) {
// Don't submit form on enter
if (e.keyCode == 13) {
e.preventDefault();
this.checked = !this.checked;
return false;
}
}
EmbyCheckboxPrototype.attachedCallback = function () {
if (this.getAttribute('data-embycheckbox') == 'true') {
return;
}
this.setAttribute('data-embycheckbox', 'true');
this.classList.add('mdl-checkbox__input');
var labelElement = this.parentNode;
//labelElement.classList.add('mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-js-ripple-effect--ignore-events');
labelElement.classList.add('mdl-checkbox');
labelElement.classList.add('mdl-js-checkbox');
labelElement.classList.add('mdl-js-ripple-effect');
var labelTextElement = labelElement.querySelector('span');
labelElement.insertAdjacentHTML('beforeend', '<span class="mdl-checkbox__focus-helper"></span><span class="checkboxOutline"><span class="mdl-checkbox__tick-outline"></span></span>');
labelTextElement.classList.add('checkboxLabel');
this.addEventListener('keydown', onKeyDown);
};
document.registerElement('emby-checkbox', {
prototype: EmbyCheckboxPrototype,
extends: 'input'
});
});