forked from adobe-rnd/aem-boilerplate-xwalk
-
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.
Merge branch 'main' of https://github.com/WWWPiramalFinanceCOM/pirama…
- Loading branch information
Showing
11 changed files
with
253 additions
and
123 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
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
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
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,53 @@ | ||
/* | ||
* Table Block | ||
* Recreate a table | ||
* https://www.hlx.live/developer/block-collection/table | ||
*/ | ||
|
||
function buildCell(rowIndex) { | ||
const cell = rowIndex ? document.createElement('td') : document.createElement('th'); | ||
if (!rowIndex) cell.setAttribute('scope', 'col'); | ||
return cell; | ||
} | ||
|
||
export function decorateTable(block) { | ||
block.classList.add('code'); | ||
block.parentElement.classList.add('code-wrapper'); | ||
const table = document.createElement('table'); | ||
const div = document.createElement('div'); | ||
const thead = document.createElement('thead'); | ||
const tbody = document.createElement('tbody'); | ||
|
||
const header = !block.classList.contains('no-header'); | ||
// if (header) table.append(thead); | ||
table.append(tbody); | ||
|
||
[...block.children].forEach((child, i) => { | ||
const row = document.createElement('tr'); | ||
// if (header && i === 0) thead.append(row); | ||
// else | ||
tbody.append(row); | ||
[...child.firstElementChild?.firstElementChild?.children]?.forEach((col) => { | ||
// [...child.children].forEach((col) => { | ||
const cell = buildCell(header ? i : i + 1); | ||
if (col.innerHTML.includes('img') && col.textContent.trim()) { | ||
col.remove(); | ||
const p = document.createElement('p'); | ||
const span = document.createElement('span'); | ||
span.append(col.textContent.trim()); | ||
p.append(col.querySelector('img')) | ||
p.append(span) | ||
cell.append(p); | ||
} else if (col.innerHTML.includes('img')) { | ||
col.remove(); | ||
cell.append(col.querySelector('img')); | ||
} else { | ||
cell.innerHTML = col.innerHTML; | ||
} | ||
row.append(cell); | ||
}); | ||
}); | ||
block.innerHTML = ''; | ||
div.append(table); | ||
block.append(div); | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.