jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/emby-collapse/emby-collapse.js

92 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-07-02 11:05:40 -07:00
define(['browser', 'css!./emby-collapse', 'registerElement'], function (browser) {
var EmbyButtonPrototype = Object.create(HTMLDivElement.prototype);
function slideDownToShow(button, elem) {
elem.classList.remove('hide');
elem.classList.add('expanded');
elem.style.height = 'auto';
var height = elem.offsetHeight + 'px';
elem.style.height = '0';
elem.offsetHeight;
elem.style.height = height;
setTimeout(function () {
if (elem.classList.contains('expanded')) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
2016-07-04 15:53:15 -07:00
elem.style.height = 'auto';
2016-07-02 11:05:40 -07:00
}, 300);
var icon = button.querySelector('i');
//icon.innerHTML = 'expand_less';
icon.classList.add('expanded');
}
function slideUpToHide(button, elem) {
2016-07-04 15:53:15 -07:00
elem.style.height = elem.offsetHeight + 'px';
elem.offsetHeight;
2016-07-02 11:05:40 -07: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);
var icon = button.querySelector('i');
//icon.innerHTML = 'expand_more';
icon.classList.remove('expanded');
}
function onButtonClick(e) {
var collapseContent = this.parentNode.querySelector('.collapseContent');
2016-07-02 19:47:39 -07:00
if (collapseContent.expanded) {
collapseContent.expanded = false;
2016-07-02 11:05:40 -07:00
slideUpToHide(this, collapseContent);
} else {
2016-07-02 19:47:39 -07:00
collapseContent.expanded = true;
2016-07-02 11:05:40 -07:00
slideDownToShow(this, collapseContent);
}
}
EmbyButtonPrototype.attachedCallback = function () {
if (this.getAttribute('data-embycollapse') == 'true') {
return;
}
this.setAttribute('data-embycollapse', 'true');
var collapseContent = this.querySelector('.collapseContent');
if (collapseContent) {
collapseContent.classList.add('hide');
}
var title = this.getAttribute('title');
2016-07-03 16:21:45 -07:00
var html = '<button is="emby-button" type="button" on-click="toggleExpand" id="expandButton" class="emby-collapsible-button iconRight">\
2016-07-02 11:05:40 -07:00
<h3 class="emby-collapsible-title" title="' + title + '">' + title + '</h3>\
2016-07-03 16:21:45 -07:00
<i class="md-icon emby-collapse-expandIcon">expand_more</i>\
2016-07-02 11:05:40 -07:00
</button>';
this.insertAdjacentHTML('afterbegin', html);
this.querySelector('.emby-collapsible-button').addEventListener('click', onButtonClick);
};
document.registerElement('emby-collapse', {
prototype: EmbyButtonPrototype,
extends: 'div'
});
});