forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add budget-summary_content_header.js file
- Loading branch information
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
decidim-budgets/app/packs/src/decidim/budgets/budget_summary_content_header.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// This script aims to dynamically adjust the height of the .budget-summary__content element based on the heights of two of its child elements, | ||
// but only when .budget-summary__content__header is within the viewport. | ||
const isElementInViewport = (el) => { | ||
const rect = el.getBoundingClientRect(); | ||
return ( | ||
rect.top >= 0 && | ||
rect.left >= 0 && | ||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | ||
rect.right <= (window.innerWidth || document.documentElement.clientWidth) | ||
); | ||
}; | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const budgetSummaryContentHeader = document.querySelector(".budget-summary__content__header"); | ||
|
||
if (budgetSummaryContentHeader) { | ||
if (isElementInViewport(budgetSummaryContentHeader)) { | ||
const budgetSummaryContent = document.querySelector(".budget-summary__content"); | ||
const budgetSummaryProgressbox = document.querySelector(".budget-summary__progressbox"); | ||
const budgetSummaryContentHeaderDescription = document.querySelector(".budget-summary__content__header--description"); | ||
|
||
if (budgetSummaryContent) { | ||
budgetSummaryContent.style.height = `${budgetSummaryProgressbox.offsetHeight + budgetSummaryContentHeaderDescription.offsetHeight}px`; | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters