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

Product Media Layout updates #937

Merged
merged 25 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8245a5b
Initial work
LucasLacerdaUX Nov 9, 2021
846eb7a
Update 21 translation files
translation-platform[bot] Dec 7, 2021
451b0c7
Update 13 translation files
translation-platform[bot] Dec 7, 2021
920e766
Update 2 translation files
translation-platform[bot] Dec 7, 2021
d2288a5
Address reviewer comments and add new layout type.
LucasLacerdaUX Dec 7, 2021
f8f4e28
Update 5 translation files
translation-platform[bot] Dec 8, 2021
36150a5
Update 3 translation files
translation-platform[bot] Dec 8, 2021
df687d7
Fixes for a11y and bugs.
LucasLacerdaUX Dec 8, 2021
ec1bff4
Update 1 translation file
translation-platform[bot] Dec 9, 2021
abbd348
Update 1 translation file
translation-platform[bot] Dec 10, 2021
edaee32
Update 15 translation files
translation-platform[bot] Dec 10, 2021
4cc8234
Update 5 translation files
translation-platform[bot] Dec 13, 2021
61a0dd2
Fix bugs with arrows
LucasLacerdaUX Dec 13, 2021
09a2d7b
Address reviewer comments
LucasLacerdaUX Dec 14, 2021
5011e20
Fix focus on Safari
LucasLacerdaUX Dec 14, 2021
56a370e
Resolve conflicts
LucasLacerdaUX Dec 14, 2021
73bd504
Fix label on slideshow buttons
LucasLacerdaUX Dec 15, 2021
95bc6c0
Media sizes update
LucasLacerdaUX Dec 15, 2021
7a4cdfd
More reviewer comments. Thanks Ludo :D
LucasLacerdaUX Dec 15, 2021
6ee8ba0
Update thumbnail sizing
LucasLacerdaUX Dec 15, 2021
704c010
Add description to snippet
LucasLacerdaUX Dec 15, 2021
8d8f2c2
Fix arrows... again
LucasLacerdaUX Dec 16, 2021
3290a46
Fix featured product
LucasLacerdaUX Dec 16, 2021
3a162d9
Check for slider before adding role=presentation
LucasLacerdaUX Dec 16, 2021
dcf41e5
Remove margin bottom
LucasLacerdaUX Dec 16, 2021
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
4 changes: 4 additions & 0 deletions assets/component-product-model.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
visibility: hidden;
}

.shopify-design-mode .product__xr-button[data-shopify-xr-hidden] {
display: none;
}

@media screen and (max-width: 749px) {
slider-component .product__xr-button {
display: none;
Expand Down
18 changes: 18 additions & 0 deletions assets/component-slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ slider-component {
}
}

@media screen and (min-width: 750px) {
.slider.slider--tablet-up {
position: relative;
flex-wrap: inherit;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-behavior: smooth;
scroll-padding-left: 1rem;
-webkit-overflow-scrolling: touch;
margin-bottom: 1rem;
}

.slider.slider--tablet-up .slider__slide {
margin-bottom: 0;
padding-bottom: 0;
}
}

@media screen and (max-width: 989px) {
.slider.slider--tablet {
position: relative;
Expand Down
56 changes: 32 additions & 24 deletions assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,15 @@ class DeferredMedia extends HTMLElement {
poster.addEventListener('click', this.loadContent.bind(this));
}

loadContent() {
loadContent(focus = true) {
window.pauseAllMedia();
if (!this.getAttribute('loaded')) {
const content = document.createElement('div');
content.appendChild(this.querySelector('template').content.firstElementChild.cloneNode(true));

this.setAttribute('loaded', true);
this.appendChild(content.querySelector('video, model-viewer, iframe')).focus();
const deferredElement = this.appendChild(content.querySelector('video, model-viewer, iframe'));
if (focus) deferredElement.focus();
}
}
}
Expand All @@ -505,7 +506,7 @@ class SliderComponent extends HTMLElement {
this.sliderItems = this.querySelectorAll('[id^="Slide-"]');
this.enableSliderLooping = false;
this.currentPageElement = this.querySelector('.slider-counter--current');
this.pageTotal = this.querySelector('.slider-counter--total');
this.pageTotalElement = this.querySelector('.slider-counter--total');
this.prevButton = this.querySelector('button[name="previous"]');
this.nextButton = this.querySelector('button[name="next"]');

Expand All @@ -529,32 +530,51 @@ class SliderComponent extends HTMLElement {
this.update();
}

resetPages() {
this.sliderItems = this.slider.querySelectorAll('li');
this.initPages();
}

update() {
const previousPage = this.currentPage;
this.currentPage = Math.round(this.slider.scrollLeft / this.sliderLastItem.clientWidth) + 1;

if (!this.currentPageElement || !this.pageTotal) return;
if (this.currentPageElement && this.pageTotalElement) {
this.currentPageElement.textContent = this.currentPage;
this.pageTotalElement.textContent = this.totalPages;
}

this.currentPageElement.textContent = this.currentPage;
this.pageTotal.textContent = this.totalPages;
if (this.currentPage != previousPage) {
this.dispatchEvent(new CustomEvent('slideChanged', { detail: {
currentPage: this.currentPage,
currentElement: this.sliderItemsToShow[this.currentPage - 1]
}}));
}

if (this.enableSliderLooping) return;

if (this.currentPage === 1) {
if (this.isSlideVisible(this.sliderItemsToShow[0])) {
this.prevButton.setAttribute('disabled', 'disabled');
} else {
this.prevButton.removeAttribute('disabled');
}

if (this.currentPage === this.totalPages) {
if (this.isSlideVisible(this.sliderLastItem)) {
this.nextButton.setAttribute('disabled', 'disabled');
} else {
this.nextButton.removeAttribute('disabled');
}
}

isSlideVisible(element, offset = 0) {
const lastVisibleSlide = this.slider.clientWidth + this.slider.scrollLeft - offset;
return element.offsetLeft < lastVisibleSlide && element.offsetLeft > this.slider.scrollLeft;
}

onButtonClick(event) {
event.preventDefault();
this.slideScrollPosition = event.currentTarget.name === 'next' ? this.slider.scrollLeft + this.sliderLastItem.clientWidth : this.slider.scrollLeft - this.sliderLastItem.clientWidth;
const step = event.currentTarget.dataset.step || 1;
this.slideScrollPosition = event.currentTarget.name === 'next' ? this.slider.scrollLeft + (step * this.sliderLastItem.clientWidth) : this.slider.scrollLeft - (step * this.sliderLastItem.clientWidth);
this.slider.scrollTo({
left: this.slideScrollPosition
});
Expand Down Expand Up @@ -742,25 +762,13 @@ class VariantSelects extends HTMLElement {
updateMedia() {
if (!this.currentVariant) return;
if (!this.currentVariant.featured_media) return;
const newMedia = document.querySelector(
`[data-media-id="${this.dataset.section}-${this.currentVariant.featured_media.id}"]`
);

if (!newMedia) return;
const mediaGallery = document.getElementById(`MediaGallery-${this.dataset.section}`);
mediaGallery.setActiveMedia(`${this.dataset.section}-${this.currentVariant.featured_media.id}`, true);

const modalContent = document.querySelector(`#ProductModal-${this.dataset.section} .product-media-modal__content`);
const newMediaModal = modalContent.querySelector( `[data-media-id="${this.currentVariant.featured_media.id}"]`);
const parent = newMedia.parentElement;
if (parent.firstChild == newMedia) return;
modalContent.prepend(newMediaModal);
parent.prepend(newMedia);
this.stickyHeader = this.stickyHeader || document.querySelector('sticky-header');
if(this.stickyHeader) {
this.stickyHeader.dispatchEvent(new Event('preventHeaderReveal'));
}
window.setTimeout(() => {
parent.scrollLeft = 0;
parent.querySelector('li.product__media-item').scrollIntoView({behavior: 'smooth'});
});
}

updateURL() {
Expand Down
5 changes: 1 addition & 4 deletions assets/product-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ window.ProductModel = {
},
};

window.addEventListener('DOMContentLoaded', () => {
if (Shopify.designMode) {
document.querySelectorAll("[data-shopify-xr-hidden]").forEach(element => element.classList.add('hidden'));
}
window.addEventListener('DOMContentLoaded', () => {
if (window.ProductModel) window.ProductModel.loadShopifyXR();
});
Loading