-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Styling focus page to similar design #23
Changes from all commits
f7f1479
7952e49
eaeb0e5
afa5f43
555c3c3
63f3641
9658004
370a46c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { | ||
sampleRUM, | ||
buildBlock, | ||
// loadHeader, | ||
// loadFooter, | ||
decorateButtons, | ||
|
@@ -9,25 +8,83 @@ import { | |
decorateBlocks, | ||
decorateTemplateAndTheme, | ||
decorateSpaceshipFocusPageH1, | ||
decorateGroups, | ||
waitForLCP, | ||
loadBlocks, | ||
loadCSS, | ||
getMetadata, | ||
} from './aem.js'; | ||
|
||
const LCP_BLOCKS = []; // add your LCP blocks to the list | ||
|
||
/** | ||
* Builds hero block and prepends to main in a new section. | ||
* @param {Element} main The container element | ||
*/ | ||
function buildHeroBlock(main) { | ||
const h1 = main.querySelector('h1'); | ||
const picture = main.querySelector('picture'); | ||
// eslint-disable-next-line no-bitwise | ||
if (h1 && picture && (h1.compareDocumentPosition(picture) & Node.DOCUMENT_POSITION_PRECEDING)) { | ||
const section = document.createElement('div'); | ||
section.append(buildBlock('hero', { elems: [picture, h1] })); | ||
main.prepend(section); | ||
function addSpeedInformation(info, containerElement) { | ||
const infoElement = document.createElement('div'); | ||
|
||
infoElement.classList.add('info'); | ||
|
||
const texts = info.split(' '); | ||
const result = `<span class="info-number">${texts[0]}</span><span class="info-text">${texts.slice(1).join(' ')}</span>`; | ||
|
||
infoElement.innerHTML = result; | ||
containerElement.appendChild(infoElement); | ||
} | ||
|
||
function addSpecifications(specs) { | ||
const specContainer = document.createElement('div'); | ||
|
||
specContainer.classList.add('spec-container'); | ||
|
||
const content = `<h2>SPECIFICATIONS</h2><div><p>Learn more about the ${document.querySelector('h1').textContent} and its technical specifications.</p></div> | ||
<table class="spec-table"><tr><th>length</th><th>width</th><th>height</th><th>weight</th></tr> | ||
<tr><td>${specs.Length}</td><td>${specs.Width}</td><td>${specs.Height}</td><td>${specs.Weight}</td></tr><table></div>`; | ||
specContainer.innerHTML = content; | ||
|
||
const parentElement = document.querySelector('body.ship-focus .default-content-wrapper'); | ||
parentElement.appendChild(specContainer); | ||
} | ||
|
||
async function prepareSpecification() { | ||
try { | ||
if (!document.body.classList.contains('ship-focus')) { | ||
return; | ||
} | ||
const specificationPath = getMetadata('specifications'); | ||
if (!specificationPath) { | ||
return; | ||
} | ||
const specificationUrl = new URL(specificationPath); | ||
const specificationsResponse = await fetch('/specifications/query-index.json'); | ||
if (!specificationsResponse.ok) { | ||
return; | ||
} | ||
const specifications = await specificationsResponse.json(); | ||
const specification = specifications.data.find((s) => s.path === specificationUrl.pathname); | ||
if (!specification) { | ||
return; | ||
} | ||
|
||
const specificationsObj = JSON.parse(specification.specifications); | ||
const infoContainer = document.createElement('div'); | ||
const titleElement = document.querySelector('h2'); | ||
|
||
if (specificationsObj.Range) { | ||
addSpeedInformation(specificationsObj.Range, infoContainer); | ||
// Temp content as it is not received from document | ||
addSpeedInformation(specificationsObj['Number of Passengers'], infoContainer); | ||
addSpeedInformation(specificationsObj.Length, infoContainer); | ||
} | ||
|
||
addSpecifications(specificationsObj); | ||
|
||
infoContainer.classList.add('info-container'); | ||
titleElement.parentNode.insertBefore(infoContainer, titleElement); | ||
|
||
// these dataset are reference and will be removed later | ||
document.body.dataset.features = specification.features; | ||
document.body.dataset.specification = specification.specifications; | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error('could not load specifications', e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add the eslint ignore here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
} | ||
} | ||
|
||
|
@@ -49,7 +106,7 @@ async function loadFonts() { | |
*/ | ||
function buildAutoBlocks(main) { | ||
try { | ||
buildHeroBlock(main); | ||
prepareSpecification(main); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error('Auto Blocking failed', error); | ||
|
@@ -68,6 +125,7 @@ export function decorateMain(main) { | |
buildAutoBlocks(main); | ||
decorateSections(main); | ||
decorateBlocks(main); | ||
decorateGroups(); | ||
decorateSpaceshipFocusPageH1(); | ||
} | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we do other viewports too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't a table restrict us quite a bit when doing a mobile version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to support mobile version in future?