-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from drashti1712/main-genfill
[MWPW-137345] Genfill Interactive Marquee
- Loading branch information
Showing
9 changed files
with
424 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
.genfill .desktop-only, | ||
.genfill .tablet-only, | ||
.genfill .mobile-only { | ||
-webkit-tap-highlight-color: transparent; | ||
user-select: none; | ||
display: none; | ||
} | ||
|
||
.genfill .enticement-detail, | ||
.genfill .enticement-mode, | ||
.genfill .timer { | ||
display: none; | ||
} | ||
|
||
.genfill .media a { | ||
display: none; | ||
} | ||
|
||
.enticement-arrow { | ||
display: none; | ||
width: 49px; | ||
height: 73px; | ||
position: absolute; | ||
} | ||
|
||
.enticement-text { | ||
display: none; | ||
max-width: 30ch; | ||
position: absolute; | ||
font-size: 28px; | ||
line-height: 35px; | ||
margin: 40px 0 16px -20px; | ||
top: -90px; | ||
color: var(--color-white); | ||
} | ||
|
||
.enticement-text.light { | ||
color: var(--color-black); | ||
} | ||
|
||
@media screen and (max-width: 600px) { | ||
.genfill .mobile-only a { | ||
display: none; | ||
} | ||
|
||
.genfill .media.mobile-only, | ||
.genfill .media.mobile-only a:first-of-type { | ||
display: block; | ||
} | ||
|
||
.genfill .enticement { | ||
display: none; | ||
} | ||
} | ||
|
||
@media screen and (min-width: 600px) and (max-width: 1200px) { | ||
.genfill .tablet-only a { | ||
display: none; | ||
} | ||
|
||
.genfill .tablet-only, | ||
.genfill .tablet-only a:first-of-type { | ||
display: block; | ||
} | ||
|
||
.enticement-arrow { | ||
right: 575px; | ||
top: -30px; | ||
display: block; | ||
} | ||
|
||
.enticement-text { | ||
display: block; | ||
} | ||
|
||
[dir="rtl"] .enticement-text { | ||
position: absolute; | ||
left: var(--spacing-xxs); | ||
} | ||
} | ||
|
||
@media screen and (min-width: 1200px) { | ||
.genfill .desktop-only a { | ||
display: none; | ||
} | ||
|
||
.genfill .desktop-only, | ||
.genfill .desktop-only a:first-of-type { | ||
display: block; | ||
} | ||
|
||
.enticement-arrow { | ||
right: 575px; | ||
top: -30px; | ||
display: block; | ||
} | ||
|
||
.enticement-text { | ||
display: block; | ||
} | ||
|
||
[dir="rtl"] .enticement-text { | ||
position: absolute; | ||
left: var(--spacing-xxs); | ||
} | ||
} |
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,103 @@ | ||
import { getLibs } from '../../scripts/utils.js'; | ||
import { createEnticement } from '../interactive-elements/interactive-elements.js'; | ||
import defineDeviceByScreenSize from '../../scripts/decorate.js'; | ||
|
||
function handleTransition(pics, index) { | ||
pics[index].style.display = 'none'; | ||
const nextIndex = (index + 1) % pics.length; | ||
pics[nextIndex].style.display = 'block'; | ||
return nextIndex; | ||
} | ||
|
||
function startAutocycle(interval, pics, clickConfig) { | ||
if (clickConfig.isImageClicked) return; | ||
clickConfig.autocycleInterval = setInterval(() => { | ||
clickConfig.autocycleIndex = handleTransition(pics, clickConfig.autocycleIndex); | ||
if (clickConfig.autocycleIndex === pics.length - 1) { | ||
clearInterval(clickConfig.autocycleInterval); | ||
} | ||
}, interval); | ||
} | ||
|
||
function handleClick(aTags, clickConfig) { | ||
aTags.forEach((a, i) => { | ||
a.querySelector('img').removeAttribute('loading'); | ||
a.addEventListener('click', () => { | ||
clickConfig.isImageClicked = true; | ||
if (clickConfig.autocycleInterval) clearInterval(clickConfig.autocycleInterval); | ||
handleTransition(aTags, i); | ||
}); | ||
}); | ||
} | ||
|
||
async function addEnticement(container, enticement, mode) { | ||
const svgUrl = enticement.querySelector('a').href; | ||
const enticementText = enticement.innerText; | ||
const entcmtEl = await createEnticement(`${enticementText}|${svgUrl}`, mode); | ||
entcmtEl.classList.add('enticement'); | ||
const n = container.children.length; | ||
const desktopMedia = container.querySelector('.desktop-only'); | ||
const tabletMedia = (n > 2) ? container.querySelector('.tablet-only') : null; | ||
desktopMedia.insertBefore(entcmtEl, desktopMedia.firstElementChild); | ||
tabletMedia?.insertBefore(entcmtEl.cloneNode(true), tabletMedia.firstElementChild); | ||
} | ||
|
||
async function removePTags(media, vi) { | ||
const heading = media.closest('.foreground').querySelector('h1, h2, h3, h4, h5, h6'); | ||
const hText = heading.id | ||
.split('-').map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(''); | ||
const miloLibs = getLibs(); | ||
const { createTag } = await import(`${miloLibs}/utils/utils.js`); | ||
const pics = media.querySelectorAll('picture'); | ||
pics.forEach((pic, index) => { | ||
if (pic.closest('p')) pic.closest('p').remove(); | ||
const a = createTag('a', { class: 'genfill-link' }); | ||
const img = pic.querySelector('img'); | ||
const altTxt = img.alt | ||
? `${img.alt}|Marquee|${hText}` | ||
: `Image-${vi}-${index}|Marquee|${hText}`; | ||
a.setAttribute('daa-ll', altTxt); | ||
a.appendChild(pic); | ||
media.appendChild(a); | ||
}); | ||
} | ||
|
||
export default async function decorateGenfill(el) { | ||
const clickConfig = { | ||
autocycleIndex: 0, | ||
autocycleInterval: null, | ||
isImageClicked: false, | ||
}; | ||
const interactiveContainer = el.querySelector('.interactive-container'); | ||
const allP = interactiveContainer.querySelectorAll('.media:first-child p'); | ||
const pMetadata = [...allP].filter((p) => !p.querySelector('picture')); | ||
const [enticementMode, enticement, timer = null] = [...pMetadata]; | ||
enticementMode.classList.add('enticement-mode'); | ||
enticement.classList.add('enticement-detail'); | ||
timer?.classList.add('timer'); | ||
const mode = enticementMode.innerText.includes('light') ? 'light' : 'dark'; | ||
const timerValues = timer ? timer.innerText.split('|') : null; | ||
const [intervalTime = 2000, delayTime = 1000] = (timerValues && timerValues.length > 1) | ||
? timerValues : [2000]; | ||
[enticementMode, enticement, timer].forEach((i) => i?.remove()); | ||
const viewports = ['mobile', 'tablet', 'desktop']; | ||
const mediaElements = interactiveContainer.querySelectorAll('.media'); | ||
mediaElements.forEach(async (mediaEl, index) => { | ||
await removePTags(mediaEl, index); | ||
const aTags = mediaEl.querySelectorAll('a'); | ||
handleClick(aTags, clickConfig); | ||
}); | ||
viewports.forEach((v, vi) => { | ||
const media = mediaElements[vi] | ||
? mediaElements[vi] | ||
: interactiveContainer.lastElementChild; | ||
media.classList.add(`${v}-only`); | ||
if (defineDeviceByScreenSize() === v.toUpperCase()) { | ||
setTimeout(() => { | ||
const aTags = media.querySelectorAll('a'); | ||
startAutocycle(intervalTime, aTags, clickConfig); | ||
}, delayTime); | ||
} | ||
}); | ||
addEnticement(interactiveContainer, enticement, mode); | ||
} |
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
39 changes: 39 additions & 0 deletions
39
test/blocks/interactive-marquee/interactive-marquee.test.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,39 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
|
||
document.body.innerHTML = await readFile({ path: './mocks/container.html' }); | ||
const { setLibs } = await import('../../../creativecloud/scripts/utils.js'); | ||
const { default: init } = await import('../../../creativecloud/blocks/interactive-marquee/interactive-marquee.js'); | ||
|
||
describe('interactive marquee', () => { | ||
const im = document.querySelector('.interactive-marquee'); | ||
before(async () => { | ||
setLibs('https://milo.adobe.com/libs'); | ||
await init(im); | ||
}); | ||
it('interactive marquee light variant should exist', () => { | ||
const light = im.classList.contains('light'); | ||
expect(light).to.true; | ||
}); | ||
|
||
it('has the interactive-area', () => { | ||
const container = im.querySelector('.foreground .interactive-container'); | ||
expect(container).to.exist; | ||
}); | ||
|
||
it('has a heading-xxl', () => { | ||
const heading = im.querySelector('.heading-xxl'); | ||
expect(heading).to.exist; | ||
}); | ||
|
||
it('has an icon area', () => { | ||
const iconArea = im.querySelector('.icon-area'); | ||
expect(iconArea).to.exist; | ||
}); | ||
|
||
it('should have icon text', () => { | ||
const iconText = im.querySelector('.icon-text'); | ||
expect(iconText).to.exist; | ||
expect(iconText.classList.contains('heading-xs')).to.be.true; | ||
}); | ||
}); |
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,26 @@ | ||
<div class="interactive-marquee light"> | ||
<div> | ||
<div data-valign="middle"> | ||
<picture> | ||
<img loading="lazy" alt="" src="" width="1600" height="750"> | ||
</picture> | ||
</div> | ||
</div> | ||
<div> | ||
<div data-valign="middle"> | ||
<p> | ||
<picture> | ||
<img loading="lazy" alt="" src="" width="154" height="150"> | ||
</picture>Photoshop | ||
</p> | ||
<h2 id="edit-photos-online-with-adobe-photoshop">Edit photos online with Adobe Photoshop</h2> | ||
<p>Add, remove, or expand content in images right in your browser with Photoshop on the web. Included in every Photoshop plan.</p> | ||
<p><strong><a href="https://www.adobe.com/">Free Trial</a></strong> <em><a href="http://www.adobe.com/">Explore Photoshop online</a></em></p> | ||
</div> | ||
<div data-valign="middle"> | ||
<picture> | ||
<img loading="lazy" alt="Jungle" data-title="JungleD" src="" width="1000" height="1000"> | ||
</picture> | ||
</div> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
|
||
document.body.innerHTML = await readFile({ path: './mocks/genfill.html' }); | ||
const { setLibs } = await import('../../../creativecloud/scripts/utils.js'); | ||
const { default: init } = await import('../../../creativecloud/blocks/interactive-marquee/interactive-marquee.js'); | ||
|
||
describe('genfill variant of interactive marquee', () => { | ||
const im = document.querySelector('.interactive-marquee'); | ||
before(async () => { | ||
setLibs('https://milo.adobe.com/libs'); | ||
await init(im); | ||
}); | ||
it('desktop media should exist', () => { | ||
const desktop = im.querySelector('.desktop-only'); | ||
expect(desktop).to.exist; | ||
}); | ||
it('tablet media should exist', () => { | ||
const tablet = im.querySelector('.tablet-only'); | ||
expect(tablet).to.exist; | ||
}); | ||
it('mobile media should exist', () => { | ||
const mobile = im.querySelector('.mobile-only'); | ||
expect(mobile).to.exist; | ||
}); | ||
it('should have proper enticement', () => { | ||
const ent = im.querySelector('.enticement'); | ||
expect(ent).to.exist; | ||
expect(ent.querySelector('.enticement-text')).to.exist; | ||
expect(ent.querySelector('.enticement-arrow')).to.exist; | ||
}); | ||
}); |
Oops, something went wrong.