Skip to content
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

Gallery fixes #272

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions blocks/gallery/gallery.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@
margin: 0 5px;
}

.gallery-wrapper .gallery.block .byline.no-author .publication::before {
display: none;
}

.gallery-wrapper .gallery.block .byline .sharing {
display: flex;
flex-grow: 1;
Expand Down Expand Up @@ -207,6 +203,7 @@

.gallery-wrapper .gallery.block .carousel > div {
width: 100%;
position: relative;
}

.gallery-wrapper .gallery.block .carousel > div h3 {
Expand Down Expand Up @@ -269,6 +266,17 @@
padding-left: 28px;
}

.gallery-wrapper .gallery.block .carousel .next-up-wrapper span {
text-transform: uppercase;
font-size: 12px;
font-style: normal;
font-weight: 700;
line-height: 16px;
letter-spacing: .3em;
text-align: left;
margin-bottom: 8px;
}

.gallery-wrapper .gallery.block .carousel .next.has-label span {
display: inline ;
text-transform: uppercase;
Expand Down Expand Up @@ -313,3 +321,33 @@
padding-left: 20px;
line-height: 19px;
}

.gallery-wrapper .gallery.block .carousel .next-up-wrapper {
position: absolute;
top: 50%;
right: 0;
width: 288px;
padding: 14px 20px;
cursor: pointer;
text-align: left;
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23FFF' d='M4.689 0L3.335 1.354 9.968 8l-6.633 6.644L4.689 16l7.976-7.99-.01-.01.01-.011z'/%3E%3C/svg%3E")
#151517;
background-position: center right 38px;
background-repeat: no-repeat;
background-size: 27px;
border-left: 3px solid #ed3e49;
color: #fff;
font-family: var(--font-gotham);
transform: translateY(-50%);
}

.gallery-wrapper .gallery.block .carousel .next-up-wrapper:hover {
color: #fff;
}

.gallery-wrapper .gallery.block .carousel .next-up-wrapper h4 {
margin: 0;
width: 180px;
line-height: 21px;
}

33 changes: 29 additions & 4 deletions blocks/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import {
buildBlock, decorateBlock, getMetadata, loadBlocks,
} from '../../scripts/lib-franklin.js';

const generateNextUpInfo = ({ title, path }) => {
const nextUpWrapper = document.createElement('a');
nextUpWrapper.className = 'next-up-wrapper';
nextUpWrapper.href = path;
nextUpWrapper.innerHTML = `<span>Next up</span><h4>${title}</h4>`;
return nextUpWrapper;
};

let latestGalleries = [];

fetch('/gallery-query-index.json?sheet=play&limit=2').then((response) => response.json()).then((data) => {
latestGalleries = data.data;
});

const gdPlusArticle = getMetadata('gdplus').length > 0;
const rubric = getMetadata('rubric');
const author = getMetadata('author');
Expand Down Expand Up @@ -45,6 +59,7 @@ const HTML_TEMPLATE = `
<slot></slot>
<slot name="share"></slot>
</div>
<!-- TODO add recommendations based on what the user has already seen. -->
</article>
<div class="container-aside">
<!-- ADVERTISEMENT HERE -->
Expand All @@ -57,9 +72,19 @@ const HTML_TEMPLATE = `
* Add carousel interactions
* @param {Element} carousel The carousel element
*/
function addEventListeners(carousel) {
function addEventListeners(carousel, carouselItemsLength) {
// Slide to the sibling item
const slide = (item, sibling) => {
if (sibling === 'next' && [...item.parentElement.children].indexOf(item) === (carouselItemsLength - 1)) {
if (latestGalleries.length) {
if (window.location.pathname === latestGalleries[0].path) {
item.firstElementChild.append(generateNextUpInfo(latestGalleries[1]));
} else {
item.firstElementChild.append(generateNextUpInfo(latestGalleries[0]));
}
}
return;
}
carousel.classList.add('is-transitioning');
item.hidden = true;
item[`${sibling}ElementSibling`].hidden = false;
Expand Down Expand Up @@ -172,14 +197,14 @@ export default async function decorate(block) {
</svg>
</button>
` : ''}
${index !== carouselItemsLength - 1 ? `

<button class="next ${isFirst ? 'has-label' : ''}">
${isFirst ? '<span>View the Gallery</span>' : ''}
<svg viewBox="0 0 16 16">
<path fill="#FFF" d="M4.689 0L3.335 1.354 9.968 8l-6.633 6.644L4.689 16l7.976-7.99-.01-.01.01-.011z"/>
</svg>
</button>
` : ''}

<div class="count">${index + 1}/${carouselItemsLength}</div>
`);

Expand All @@ -198,7 +223,7 @@ export default async function decorate(block) {
}
});

addEventListeners(carousel);
addEventListeners(carousel, carouselItemsLength);

// Update block with rendered template
block.innerHTML = '';
Expand Down