UNPKG

osmos

Version:

OSMOS - Symbiosys

35 lines (27 loc) 849 B
import {bindable} from 'aurelia-framework'; export class OsCollapseCustomElement { @bindable targetId; @bindable accordion; osCollapse(targetId) { var target = document.getElementById(targetId); if(target.classList.contains('in')) { target.classList.remove('in'); target.style.height = 0; } else { var height = 0; var children = target.children; if(this.accordion) { var accordions = document.querySelectorAll('.' + this.accordion); Array.from(accordions).forEach((accordion) => { accordion.style.height = height + 'px'; accordion.classList.remove('in'); }); } target.classList.add('in'); Array.from(children).forEach((c) => { height += parseInt(c.clientHeight); }); target.style.height = height + 'px'; } } }