collapsible.js: Minor performance improvements

(cherry picked from commit 917e68d68d3865c6972992c622a1ce229d5176ac)
This commit is contained in:
Johannes Meyer 2022-07-25 11:23:43 +02:00
parent 0cd2887fca
commit db6864170c

View File

@ -154,7 +154,7 @@
return; return;
} else if (typeof collapsible.dataset.noPersistence !== 'undefined') { } else if (typeof collapsible.dataset.noPersistence !== 'undefined') {
if (collapsible.matches('.collapsed')) { if (collapsible.classList.contains('collapsed')) {
_this.expand(collapsible); _this.expand(collapsible);
} else { } else {
_this.collapse(collapsible, _this.calculateCollapsedHeight(collapsible)); _this.collapse(collapsible, _this.calculateCollapsedHeight(collapsible));
@ -253,9 +253,9 @@
return ''; return '';
} }
if (collapsible.matches('table')) { if (collapsible.tagName === 'TABLE') {
return '> tbody > tr'; return '> tbody > tr';
} else if (collapsible.matches('ul, ol')) { } else if (collapsible.tagName === 'UL' || collapsible.tagName === 'OL') {
return '> li:not(.collapsible-control)'; return '> li:not(.collapsible-control)';
} }
@ -279,19 +279,23 @@
var visibleRows = Number(collapsible.dataset.visibleRows); var visibleRows = Number(collapsible.dataset.visibleRows);
if (isNaN(visibleRows)) { if (isNaN(visibleRows)) {
visibleRows = this.defaultVisibleRows; visibleRows = this.defaultVisibleRows;
} else if (visibleRows === 0) {
return true;
} }
return $(rowSelector, collapsible).length > visibleRows * 2; return $(rowSelector, collapsible).length > visibleRows * 2;
} else { } else {
var actualHeight = collapsible.scrollHeight - parseFloat(
window.getComputedStyle(collapsible).getPropertyValue('padding-top')
);
var maxHeight = Number(collapsible.dataset.visibleHeight); var maxHeight = Number(collapsible.dataset.visibleHeight);
if (isNaN(maxHeight)) { if (isNaN(maxHeight)) {
maxHeight = this.defaultVisibleHeight; maxHeight = this.defaultVisibleHeight;
} else if (maxHeight === 0) {
return true;
} }
var actualHeight = collapsible.scrollHeight - parseFloat(
window.getComputedStyle(collapsible).getPropertyValue('padding-top')
);
return actualHeight >= maxHeight * 2; return actualHeight >= maxHeight * 2;
} }
}; };