mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
refactor: Move condition out of loop
This commit is contained in:
parent
ebaa5026d9
commit
08cbc5aa8f
1 changed files with 24 additions and 18 deletions
|
@ -898,33 +898,39 @@ function toggleLineClamp(clampTarget, e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderOverview(page, item) {
|
function renderOverview(page, item) {
|
||||||
for (const overviewElemnt of page.querySelectorAll('.overview')) {
|
const overviewElements = page.querySelectorAll('.overview');
|
||||||
|
|
||||||
|
if (overviewElements.length > 0) {
|
||||||
const overview = item.Overview || '';
|
const overview = item.Overview || '';
|
||||||
|
|
||||||
if (overview) {
|
if (overview) {
|
||||||
overviewElemnt.innerHTML = overview;
|
for (const overviewElemnt of overviewElements) {
|
||||||
overviewElemnt.classList.remove('hide');
|
overviewElemnt.innerHTML = overview;
|
||||||
overviewElemnt.classList.add('detail-clamp-text');
|
overviewElemnt.classList.remove('hide');
|
||||||
|
overviewElemnt.classList.add('detail-clamp-text');
|
||||||
|
|
||||||
// Grab the sibling element to control the expand state
|
// Grab the sibling element to control the expand state
|
||||||
const expandButton = overviewElemnt.parentElement.querySelector('.overview-expand');
|
const expandButton = overviewElemnt.parentElement.querySelector('.overview-expand');
|
||||||
|
|
||||||
// Detect if we have overflow of text. Based on this StackOverflow answer
|
// Detect if we have overflow of text. Based on this StackOverflow answer
|
||||||
// https://stackoverflow.com/a/35157976
|
// https://stackoverflow.com/a/35157976
|
||||||
if (Math.abs(overviewElemnt.scrollHeight - overviewElemnt.offsetHeight) > 2) {
|
if (Math.abs(overviewElemnt.scrollHeight - overviewElemnt.offsetHeight) > 2) {
|
||||||
expandButton.classList.remove('hide');
|
expandButton.classList.remove('hide');
|
||||||
} else {
|
} else {
|
||||||
expandButton.classList.add('hide');
|
expandButton.classList.add('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
expandButton.addEventListener('click', toggleLineClamp.bind(null, overviewElemnt));
|
expandButton.addEventListener('click', toggleLineClamp.bind(null, overviewElemnt));
|
||||||
|
|
||||||
for (const anchor of overviewElemnt.querySelectorAll('a')) {
|
for (const anchor of overviewElemnt.querySelectorAll('a')) {
|
||||||
anchor.setAttribute('target', '_blank');
|
anchor.setAttribute('target', '_blank');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
overviewElemnt.innerHTML = '';
|
for (const overviewElemnt of overviewElements) {
|
||||||
overviewElemnt.classList.add('hide');
|
overviewElemnt.innerHTML = '';
|
||||||
|
overviewElemnt.classList.add('hide');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue