Skip to content

Commit 9771b79

Browse files
committed
Render fulfillment container only when applicable
Why these changes are being introduced: The fulfillment link container currently renders as an empty div when no links are available. This pollutes the DOM and affects spacing. Relevant ticket(s): - [USE-611](https://mitlibraries.atlassian.net/browse/USE-611) How this addresses that need: This removes the parent div if no fulfillment links are present. Side effects of this change: None.
1 parent 55cf25a commit 9771b79

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

app/javascript/controllers/content_loader_controller.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ export default class extends Controller {
1212
.then(response => response.text())
1313
.then(html => {
1414
const parentElement = this.element.parentElement;
15-
// Replace the entire element with the fetched HTML
16-
this.element.outerHTML = html;
17-
// Hide primo links if libkey link is present
18-
if (parentElement.querySelector('.libkey-link')) {
19-
const resultGet = parentElement.closest('.result-get');
20-
if (resultGet) {
21-
const primoLinks = resultGet.querySelectorAll('.primo-link');
22-
// removing instead of hiding to avoid layout issues when selecting which link to highlight
23-
primoLinks.forEach(link => link.remove());
15+
// Strip HTML comments and trim whitespace
16+
const cleanedHtml = html.replace(/<!--[\s\S]*?-->/g, '').trim();
17+
// Replace the entire element with the fetched HTML, or remove if empty
18+
if (cleanedHtml) {
19+
this.element.outerHTML = cleanedHtml;
20+
// Hide primo links if libkey link is present
21+
if (parentElement.querySelector('.libkey-link')) {
22+
const resultGet = parentElement.closest('.result-get');
23+
if (resultGet) {
24+
const primoLinks = resultGet.querySelectorAll('.primo-link');
25+
// removing instead of hiding to avoid layout issues when selecting which link to highlight
26+
primoLinks.forEach(link => link.remove());
27+
}
2428
}
29+
} else {
30+
// Remove result-get container (no fulfillment links)
31+
parentElement.remove();
2532
}
2633
})
2734
}

0 commit comments

Comments
 (0)