2020-07-15 11:41:59 +01:00
|
|
|
import 'css!./emby-collapse';
|
2020-07-24 10:43:03 +02:00
|
|
|
import 'webcomponents';
|
2020-07-15 11:41:59 +01:00
|
|
|
import 'emby-button';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
/* eslint-disable indent */
|
|
|
|
|
|
|
|
const EmbyButtonPrototype = Object.create(HTMLDivElement.prototype);
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function slideDownToShow(button, elem) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
elem.classList.remove('hide');
|
|
|
|
elem.classList.add('expanded');
|
|
|
|
elem.style.height = 'auto';
|
2020-07-15 11:41:59 +01:00
|
|
|
const height = elem.offsetHeight + 'px';
|
2019-01-10 15:39:37 +03:00
|
|
|
elem.style.height = '0';
|
|
|
|
|
|
|
|
// trigger reflow
|
2020-07-15 11:41:59 +01:00
|
|
|
const newHeight = elem.offsetHeight;
|
2019-01-10 15:39:37 +03:00
|
|
|
elem.style.height = height;
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
if (elem.classList.contains('expanded')) {
|
|
|
|
elem.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
elem.classList.add('hide');
|
|
|
|
}
|
|
|
|
elem.style.height = 'auto';
|
|
|
|
}, 300);
|
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const icon = button.querySelector('.material-icons');
|
2019-01-10 15:39:37 +03:00
|
|
|
//icon.innerHTML = 'expand_less';
|
|
|
|
icon.classList.add('emby-collapse-expandIconExpanded');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function slideUpToHide(button, elem) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
elem.style.height = elem.offsetHeight + 'px';
|
|
|
|
// trigger reflow
|
2020-07-15 11:41:59 +01:00
|
|
|
const newHeight = elem.offsetHeight;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
elem.classList.remove('expanded');
|
|
|
|
elem.style.height = '0';
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
if (elem.classList.contains('expanded')) {
|
|
|
|
elem.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
elem.classList.add('hide');
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const icon = button.querySelector('.material-icons');
|
2019-01-10 15:39:37 +03:00
|
|
|
//icon.innerHTML = 'expand_more';
|
|
|
|
icon.classList.remove('emby-collapse-expandIconExpanded');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onButtonClick(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const button = this;
|
|
|
|
const collapseContent = button.parentNode.querySelector('.collapseContent');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (collapseContent.expanded) {
|
|
|
|
collapseContent.expanded = false;
|
|
|
|
slideUpToHide(button, collapseContent);
|
|
|
|
} else {
|
|
|
|
collapseContent.expanded = true;
|
|
|
|
slideDownToShow(button, collapseContent);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
EmbyButtonPrototype.attachedCallback = function () {
|
|
|
|
|
|
|
|
if (this.classList.contains('emby-collapse')) {
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
this.classList.add('emby-collapse');
|
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const collapseContent = this.querySelector('.collapseContent');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (collapseContent) {
|
|
|
|
collapseContent.classList.add('hide');
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const title = this.getAttribute('title');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const html = '<button is="emby-button" type="button" on-click="toggleExpand" id="expandButton" class="emby-collapsible-button iconRight"><h3 class="emby-collapsible-title" title="' + title + '">' + title + '</h3><span class="material-icons emby-collapse-expandIcon expand_more"></span></button>';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
this.insertAdjacentHTML('afterbegin', html);
|
|
|
|
|
2020-07-15 11:41:59 +01:00
|
|
|
const button = this.querySelector('.emby-collapsible-button');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
button.addEventListener('click', onButtonClick);
|
|
|
|
|
|
|
|
if (this.getAttribute('data-expanded') === 'true') {
|
|
|
|
onButtonClick.call(button);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.registerElement('emby-collapse', {
|
2018-10-23 01:05:09 +03:00
|
|
|
prototype: EmbyButtonPrototype,
|
2019-01-10 15:39:37 +03:00
|
|
|
extends: 'div'
|
|
|
|
});
|
2020-07-15 11:41:59 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|