Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve over-scroll in IOS

Matthew Kennedydc08c7cd3649
diff --git a/backend/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6 b/backend/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6
index dbfc608964..87205a7202 100644
--- a/backend/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6
+++ b/backend/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6
@@ -1,117 +1,113 @@
+document.addEventListener('DOMContentLoaded', function () {
+ const overScrollWrapper = document.querySelectorAll('[data-overscroll-wrapper]')
+ overScrollWrapper.forEach(el => OverScrollKit(el))
+})
+
const SETTINGS = {
navBarTravelling: false,
navBarTravelDirection: '',
navBarTravelDistance: 150
}
-document.addEventListener('DOMContentLoaded', function () {
- const overScrollWrapper = document.querySelectorAll('[data-overscroll-wrapper]')
+function OverScrollKit (containerEl) {
+ const overScrollLeft = containerEl.querySelector('[data-overscroll-button-left]')
+ const overScrollRight = containerEl.querySelector('[data-overscroll-button-right]')
+ const overScrollContainer = containerEl.querySelector('[data-overscroll-container]')
+ const overScrollContents = overScrollContainer.querySelector('[data-overscroll-content]')
+ const activeLink = overScrollContents.querySelector('.active')
- overScrollWrapper.forEach(el => setupOverScrollKit(el))
+ // Trigger on DOMContentLoaded
+ setOverscrollIndicators()
- function setupOverScrollKit (containerEl) {
- const overScrollLeft = containerEl.querySelector('[data-overscroll-button-left]')
- const overScrollRight = containerEl.querySelector('[data-overscroll-button-right]')
- const overScrollContainer = containerEl.querySelector('[data-overscroll-container]')
- const overScrollContents = overScrollContainer.querySelector('[data-overscroll-content]')
- const activeLink = overScrollContents.querySelector('.active')
+ if (activeLink) focusActiveItem(overScrollContainer, activeLink)
- // Trigger on DOMContentLoaded
+ window.addEventListener('resize', function () {
+ // Trigger on window resize
setOverscrollIndicators()
-
focusActiveItem(overScrollContainer, activeLink)
+ })
- window.addEventListener('resize', function () {
- // Trigger on window resize
- setOverscrollIndicators()
- focusActiveItem(overScrollContainer, activeLink)
- })
-
- overScrollContainer.addEventListener('scroll', function () {
- // Trigger on Side Scrolling
- setOverscrollIndicators()
- })
+ overScrollContainer.addEventListener('scroll', function () {
+ // Trigger on Side Scrolling
+ setOverscrollIndicators()
+ })
- function setOverscrollIndicators () {
- overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
- }
+ function setOverscrollIndicators () {
+ overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
+ }
- overScrollLeft.addEventListener('click', function () {
- // If in the middle of a move return
- if (SETTINGS.navBarTravelling === true) return
-
- // If we have content overflowing both sides or on the left
- if (determineOverflow(overScrollContents, overScrollContainer) === 'left' || determineOverflow(overScrollContents, overScrollContainer) === 'both') {
- // Find how far this panel has been scrolled
- const availableScrollLeft = overScrollContainer.scrollLeft
- // If the space available is less than two lots of our desired distance, just move the whole amount
- // otherwise, move by the amount in the settings
- if (availableScrollLeft < SETTINGS.navBarTravelDistance * 2) {
- overScrollContents.style.transform = `translateX(${availableScrollLeft}px)`
- } else {
- overScrollContents.style.transform = `translateX(${SETTINGS.navBarTravelDistance}px)`
- }
- // We do want a transition (this is set in CSS) when moving so remove the class that would prevent that
- overScrollContents.classList.remove('pn-ProductNav_Contents-no-transition')
- // Update our settings
- SETTINGS.navBarTravelDirection = 'left'
- SETTINGS.navBarTravelling = true
+ overScrollLeft.addEventListener('click', function () {
+ // If in the middle of a move return
+ if (SETTINGS.navBarTravelling === true) return
+
+ // If we have content overflowing both sides or on the left
+ if (determineOverflow(overScrollContents, overScrollContainer) === 'left' || determineOverflow(overScrollContents, overScrollContainer) === 'both') {
+ // Find how far this panel has been scrolled
+ const availableScrollLeft = overScrollContainer.scrollLeft
+ // If the space available is less than two lots of our desired distance, just move the whole amount
+ // otherwise, move by the amount in the settings
+ if (availableScrollLeft < SETTINGS.navBarTravelDistance * 2) {
+ overScrollContents.style.transform = `translateX(${availableScrollLeft}px)`
+ } else {
+ overScrollContents.style.transform = `translateX(${SETTINGS.navBarTravelDistance}px)`
}
- // Now update the attribute in the DOM
- overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
- })
-
- overScrollRight.addEventListener('click', function () {
- // If in the middle of a move return
- if (SETTINGS.navBarTravelling === true) return
-
- // If we have content overflowing both sides or on the right
- if (determineOverflow(overScrollContents, overScrollContainer) === 'right' || determineOverflow(overScrollContents, overScrollContainer) === 'both') {
- // Get the right edge of the container and content
- const navBarRightEdge = overScrollContents.getBoundingClientRect().right
- const navBarScrollerRightEdge = overScrollContainer.getBoundingClientRect().right
- // Now we know how much space we have available to scroll
- const availableScrollRight = Math.floor(navBarRightEdge - navBarScrollerRightEdge)
- // If the space available is less than two lots of our desired distance, just move the whole amount
- // otherwise, move by the amount in the settings
- if (availableScrollRight < SETTINGS.navBarTravelDistance * 2) {
- overScrollContents.style.transform = `translateX(-${availableScrollRight}px)`
- } else {
- overScrollContents.style.transform = `translateX(-${SETTINGS.navBarTravelDistance}px)`
- }
- // We do want a transition (this is set in CSS) when moving so remove the class that would prevent that
- overScrollContents.classList.remove('pn-ProductNav_Contents-no-transition')
- // Update our settings
- SETTINGS.navBarTravelDirection = 'right'
- SETTINGS.navBarTravelling = true
+ // We do want a transition (this is set in CSS) when moving so remove the class that would prevent that
+ overScrollContents.classList.remove('pn-ProductNav_Contents-no-transition')
+ // Update our settings
+ SETTINGS.navBarTravelDirection = 'left'
+ SETTINGS.navBarTravelling = true
+ }
+ // Now update the attribute in the DOM
+ overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
+ })
+
+ overScrollRight.addEventListener('click', function () {
+ // If in the middle of a move return
+ if (SETTINGS.navBarTravelling === true) return
+
+ // If we have content overflowing both sides or on the right
+ if (determineOverflow(overScrollContents, overScrollContainer) === 'right' || determineOverflow(overScrollContents, overScrollContainer) === 'both') {
+ // Get the right edge of the container and content
+ const navBarRightEdge = overScrollContents.getBoundingClientRect().right
+ const navBarScrollerRightEdge = overScrollContainer.getBoundingClientRect().right
+ // Now we know how much space we have available to scroll
+ const availableScrollRight = Math.floor(navBarRightEdge - navBarScrollerRightEdge)
+ // If the space available is less than two lots of our desired distance, just move the whole amount
+ // otherwise, move by the amount in the settings
+ if (availableScrollRight < SETTINGS.navBarTravelDistance * 2) {
+ overScrollContents.style.transform = `translateX(-${availableScrollRight}px)`
+ } else {
+ overScrollContents.style.transform = `translateX(-${SETTINGS.navBarTravelDistance}px)`
}
- // Now update the attribute in the DOM
- overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
- })
-
- overScrollContents.addEventListener(
- 'transitionend',
- function () {
- // get the value of the transform, apply that to the current scroll position (so get the scroll pos first) and then remove the transform
- const styleOfTransform = window.getComputedStyle(overScrollContents, null)
- const tr = styleOfTransform.getPropertyValue('transform') || styleOfTransform.getPropertyValue('transform')
- // If there is no transition we want to default to 0 and not null
- const amount = Math.abs(parseInt(tr.split(',')[4]) || 0)
-
- overScrollContents.style.transform = 'none'
- overScrollContents.classList.add('pn-ProductNav_Contents-no-transition')
- // Now lets set the scroll position
- if (SETTINGS.navBarTravelDirection === 'left') {
- overScrollContainer.scrollLeft = overScrollContainer.scrollLeft - amount
- } else {
- overScrollContainer.scrollLeft = overScrollContainer.scrollLeft + amount
- }
- SETTINGS.navBarTravelling = false
- },
- false
- )
- }
-})
+ // We do want a transition (this is set in CSS) when moving so remove the class that would prevent that
+ overScrollContents.classList.remove('pn-ProductNav_Contents-no-transition')
+ // Update our settings
+ SETTINGS.navBarTravelDirection = 'right'
+ SETTINGS.navBarTravelling = true
+ }
+ // Now update the attribute in the DOM
+ overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
+ })
+
+ overScrollContents.addEventListener('transitionend', function () {
+ // get the value of the transform, apply that to the current scroll position (so get the scroll pos first) and then remove the transform
+ const styleOfTransform = window.getComputedStyle(overScrollContents, null)
+ const tr = styleOfTransform.getPropertyValue('transform') || styleOfTransform.getPropertyValue('transform')
+ // If there is no transition we want to default to 0 and not null
+
+ const amount = Math.abs(parseInt(tr.split(',')[4]) || 0)
+
+ overScrollContents.style.transform = 'none'
+ overScrollContents.classList.add('pn-ProductNav_Contents-no-transition')
+ // Now lets set the scroll position
+ if (SETTINGS.navBarTravelDirection === 'left') {
+ overScrollContainer.scrollLeft = overScrollContainer.scrollLeft - amount
+ } else {
+ overScrollContainer.scrollLeft = overScrollContainer.scrollLeft + amount
+ }
+ SETTINGS.navBarTravelling = false
+ })
+}
// Set active link into view
function focusActiveItem (containerEl, activeEl) {
diff --git a/backend/app/assets/stylesheets/spree/backend/plugins/overscroll_indicator.scss b/backend/app/assets/stylesheets/spree/backend/plugins/overscroll_indicator.scss
index 9180a3ce6d..3c242dabc1 100644
--- a/backend/app/assets/stylesheets/spree/backend/plugins/overscroll_indicator.scss
+++ b/backend/app/assets/stylesheets/spree/backend/plugins/overscroll_indicator.scss
@@ -14,21 +14,34 @@
&::-webkit-scrollbar {
display: none;
}
+}
- .pn-ProductNav_Contents {
- float: left;
- transition: transform .2s ease-in-out;
- }
+[data-overscroll-content] {
+ float: left;
+ transition: transform .2s ease-in-out;
+ position: relative;
- .pn-ProductNav_Contents-no-transition {
- transition: none;
+ & > * {
+ z-index: 200;
}
}
+.pn-ProductNav_Contents-no-transition {
+ transition: none;
+}
+
.pn-Advancer {
appearance: none;
background: transparent;
border: 0;
+ position: absolute;
+ padding: 5px;
+ height: 100%;
+ top: 0;
+ bottom: 0;
+ opacity: 0;
+ z-index: 100;
+ transition: all .3s;
&:focus {
outline: 0;
@@ -37,37 +50,30 @@
&:hover {
cursor: pointer;
}
-
- position: absolute;
- padding: 5px;
- height: 100%;
- top: 0;
- bottom: 0;
- opacity: 0;
- transition: opacity .3s;
- z-index: -1;
}
.pn-Advancer_Left {
border-right: 2px solid rgba(128, 128, 128, 0.56);
background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(255,255,255,1) 65%, rgba(255,255,255,0.8533788515406162) 100%);
left: -1px;
- [data-overflowing="both"] ~ &,
- [data-overflowing="left"] ~ & {
- opacity: 1;
- z-index: 5;
- }
+}
+
+[data-overflowing="both"] ~ .pn-Advancer_Left,
+[data-overflowing="left"] ~ .pn-Advancer_Left {
+ opacity: 1;
+ z-index: 300;
}
.pn-Advancer_Right {
border-left: 2px solid rgba(128, 128, 128, 0.56);
background: linear-gradient(90deg, rgba(255,255,255,0.850577731092437) 0%, rgba(255,255,255,1) 35%, rgba(255,255,255,1) 100%);
right: -1px;
- [data-overflowing="both"] ~ &,
- [data-overflowing="right"] ~ & {
- opacity: 1;
- z-index: 5;
- }
+}
+
+[data-overflowing="both"] ~ .pn-Advancer_Right,
+[data-overflowing="right"] ~ .pn-Advancer_Right {
+ opacity: 1;
+ z-index: 300;
}
.pn-Advancer_Icon {