forked from sunstar-engineering/sunstar-engineering
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ritwik Srivastava
authored and
Ritwik Srivastava
committed
Sep 21, 2023
1 parent
f91c0bf
commit 380adf6
Showing
1 changed file
with
35 additions
and
35 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import { wrapImgsInLinks } from '../../scripts/scripts.js'; | ||
|
||
export default function decorate(block) { | ||
const cols = [...block.firstElementChild.children]; | ||
block.classList.add(`columns-small-${cols.length}-cols`); | ||
const textOnlyColBlock = !block.querySelector('picture'); | ||
const cols = [...block.firstElementChild.children]; | ||
block.classList.add(`columns-small-${cols.length}-cols`); | ||
const textOnlyColBlock = !block.querySelector('picture'); | ||
|
||
// setup image columns | ||
[...block.children].forEach((row) => { | ||
[...row.children].forEach((col) => { | ||
wrapImgsInLinks(col); | ||
if (!textOnlyColBlock) { | ||
const pics = col.querySelectorAll('picture'); | ||
if (pics.length) { | ||
const picWrapper = pics[0].closest('div'); | ||
if (picWrapper && picWrapper.children.length === pics.length) { | ||
// pictures (either wrapped in achors, or otherwise) | ||
// are only content in the column | ||
picWrapper.classList.add('columns-small-img-col'); | ||
} | ||
} | ||
} | ||
}); | ||
// setup image columns | ||
[...block.children].forEach((row) => { | ||
[...row.children].forEach((col) => { | ||
wrapImgsInLinks(col); | ||
if (!textOnlyColBlock) { | ||
const pics = col.querySelectorAll('picture'); | ||
if (pics.length) { | ||
const picWrapper = pics[0].closest('div'); | ||
if (picWrapper && picWrapper.children.length === pics.length) { | ||
// pictures (either wrapped in achors, or otherwise) | ||
// are only content in the column | ||
picWrapper.classList.add('columns-small-img-col'); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
// decorate columns-small with description content | ||
[...block.children].forEach((row) => { | ||
const cells = row.querySelectorAll('div:not(.columns-small-img-col)'); | ||
if (cells.length) { | ||
[...cells].forEach((content) => { | ||
content.classList.add('description'); | ||
const contentWrapper = document.createElement('div'); | ||
contentWrapper.classList.add('description-wrapper'); | ||
const contentParent = content.parentElement; | ||
contentParent.insertBefore(contentWrapper, content); | ||
contentWrapper.appendChild(content); | ||
if (textOnlyColBlock) { | ||
content.classList.add('text-only'); | ||
} | ||
}); | ||
} | ||
}); | ||
[...block.children].forEach((row) => { | ||
const cells = row.querySelectorAll('div:not(.columns-small-img-col)'); | ||
if (cells.length) { | ||
[...cells].forEach((content) => { | ||
content.classList.add('description'); | ||
const contentWrapper = document.createElement('div'); | ||
contentWrapper.classList.add('description-wrapper'); | ||
const contentParent = content.parentElement; | ||
contentParent.insertBefore(contentWrapper, content); | ||
contentWrapper.appendChild(content); | ||
if (textOnlyColBlock) { | ||
content.classList.add('text-only'); | ||
} | ||
}); | ||
} | ||
}); | ||
} |