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.

Rename javascript.

Matthew Kennedy8cd1b26a3cae
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 87205a7202..c74771bbf6 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,6 +1,6 @@
document.addEventListener('DOMContentLoaded', function () {
- const overScrollWrapper = document.querySelectorAll('[data-overscroll-wrapper]')
- overScrollWrapper.forEach(el => OverScrollKit(el))
+ const navWrapper = document.querySelectorAll('[data-nav-x-wrapper]')
+ navWrapper.forEach(el => initHorizontalNav(el))
})
const SETTINGS = {
@@ -9,101 +9,101 @@ const SETTINGS = {
navBarTravelDistance: 150
}
-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')
+function initHorizontalNav (containerEl) {
+ const navAdvanceLeft = containerEl.querySelector('.nav-x_Advancer_Left')
+ const navAdvanceRight = containerEl.querySelector('.nav-x_Advancer_Right')
+ const navContainer = containerEl.querySelector('[data-nav-x-container]')
+ const navContent = navContainer.querySelector('[data-nav-x-content]')
+ const activeNavItem = navContent.querySelector('.active')
// Trigger on DOMContentLoaded
setOverscrollIndicators()
- if (activeLink) focusActiveItem(overScrollContainer, activeLink)
+ if (activeNavItem) focusActiveItem(navContainer, activeNavItem)
window.addEventListener('resize', function () {
// Trigger on window resize
setOverscrollIndicators()
- focusActiveItem(overScrollContainer, activeLink)
+ focusActiveItem(navContainer, activeNavItem)
})
- overScrollContainer.addEventListener('scroll', function () {
+ navContainer.addEventListener('scroll', function () {
// Trigger on Side Scrolling
setOverscrollIndicators()
})
function setOverscrollIndicators () {
- overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
+ navContainer.setAttribute('data-overflowing', determineOverflow(navContent, navContainer))
}
- overScrollLeft.addEventListener('click', function () {
+ navAdvanceLeft.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') {
+ if (determineOverflow(navContent, navContainer) === 'left' || determineOverflow(navContent, navContainer) === 'both') {
// Find how far this panel has been scrolled
- const availableScrollLeft = overScrollContainer.scrollLeft
+ const availableScrollLeft = navContainer.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)`
+ navContent.style.transform = `translateX(${availableScrollLeft}px)`
} else {
- overScrollContents.style.transform = `translateX(${SETTINGS.navBarTravelDistance}px)`
+ navContent.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')
+ navContent.classList.remove('nav-x_Transition_None')
// Update our settings
SETTINGS.navBarTravelDirection = 'left'
SETTINGS.navBarTravelling = true
}
// Now update the attribute in the DOM
- overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
+ navContainer.setAttribute('data-overflowing', determineOverflow(navContent, navContainer))
})
- overScrollRight.addEventListener('click', function () {
+ navAdvanceRight.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') {
+ if (determineOverflow(navContent, navContainer) === 'right' || determineOverflow(navContent, navContainer) === 'both') {
// Get the right edge of the container and content
- const navBarRightEdge = overScrollContents.getBoundingClientRect().right
- const navBarScrollerRightEdge = overScrollContainer.getBoundingClientRect().right
+ const navBarRightEdge = navContent.getBoundingClientRect().right
+ const navBarScrollerRightEdge = navContainer.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)`
+ navContent.style.transform = `translateX(-${availableScrollRight}px)`
} else {
- overScrollContents.style.transform = `translateX(-${SETTINGS.navBarTravelDistance}px)`
+ navContent.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')
+ navContent.classList.remove('nav-x_Transition_None')
// Update our settings
SETTINGS.navBarTravelDirection = 'right'
SETTINGS.navBarTravelling = true
}
// Now update the attribute in the DOM
- overScrollContainer.setAttribute('data-overflowing', determineOverflow(overScrollContents, overScrollContainer))
+ navContainer.setAttribute('data-overflowing', determineOverflow(navContent, navContainer))
})
- overScrollContents.addEventListener('transitionend', function () {
+ navContent.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 styleOfTransform = window.getComputedStyle(navContent, 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')
+ navContent.style.transform = 'none'
+ navContent.classList.add('nav-x_Transition_None')
// Now lets set the scroll position
if (SETTINGS.navBarTravelDirection === 'left') {
- overScrollContainer.scrollLeft = overScrollContainer.scrollLeft - amount
+ navContainer.scrollLeft = navContainer.scrollLeft - amount
} else {
- overScrollContainer.scrollLeft = overScrollContainer.scrollLeft + amount
+ navContainer.scrollLeft = navContainer.scrollLeft + amount
}
SETTINGS.navBarTravelling = false
})
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 69ecbceb83..395f2b604a 100644
--- a/backend/app/assets/stylesheets/spree/backend/plugins/overscroll_indicator.scss
+++ b/backend/app/assets/stylesheets/spree/backend/plugins/overscroll_indicator.scss
@@ -1,9 +1,9 @@
-[data-overscroll-wrapper] {
+[data-nav-x-wrapper] {
position: relative;
padding: 0 11px;
}
-[data-overscroll-container] {
+[data-nav-x-container] {
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
@@ -16,7 +16,7 @@
}
}
-[data-overscroll-content] {
+[data-nav-x-content] {
float: left;
transition: transform .2s ease-in-out;
position: relative;
@@ -25,21 +25,18 @@
z-index: 200;
}
- // Bug fix for iOS jittery elastic scroll from Bootstrap 4 transaition on pills and buttons.
- // Kill transitions on items within [data-overscroll-content]
+ // Bug fix for iOS jittery elastic scroll from Bootstrap 4
+ // transaition on pills and buttons nested a tag.
& > li > a {
transition: none !important;
}
}
-
-
-
-.pn-ProductNav_Contents-no-transition {
+.nav-x_Transition_None {
transition: none;
}
-.pn-Advancer {
+.nav-x_Advancer {
appearance: none;
background: transparent;
border: 0;
@@ -59,33 +56,33 @@
&:hover {
cursor: pointer;
}
+
+ svg {
+ height: 100%;
+ fill: #bbb;
+ }
}
-.pn-Advancer_Left {
+.nav-x_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"] ~ .pn-Advancer_Left,
-[data-overflowing="left"] ~ .pn-Advancer_Left {
+[data-overflowing="both"] ~ .nav-x_Advancer_Left,
+[data-overflowing="left"] ~ .nav-x_Advancer_Left {
opacity: 1;
z-index: 300;
}
-.pn-Advancer_Right {
+.nav-x_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"] ~ .pn-Advancer_Right,
-[data-overflowing="right"] ~ .pn-Advancer_Right {
+[data-overflowing="both"] ~ .nav-x_Advancer_Right,
+[data-overflowing="right"] ~ .nav-x_Advancer_Right {
opacity: 1;
z-index: 300;
}
-
-.pn-Advancer_Icon {
- height: 100%;
- fill: #bbb;
-}
diff --git a/backend/app/views/spree/admin/shared/_content_header.html.erb b/backend/app/views/spree/admin/shared/_content_header.html.erb
index 915b6f4097..553ebb7cc6 100644
--- a/backend/app/views/spree/admin/shared/_content_header.html.erb
+++ b/backend/app/views/spree/admin/shared/_content_header.html.erb
@@ -33,19 +33,23 @@
</div>
<% if content_for?(:page_tabs) %>
- <div class="row my-2 pb-1 pt-1" data-overscroll-wrapper>
- <div data-overscroll-container>
- <ul id="spreePageTabs" class="nav nav-pills flex-nowrap" data-overscroll-content>
- <%= yield :page_tabs%>
+ <div class="row my-2 pb-1 pt-1" data-nav-x-wrapper>
+ <div data-nav-x-container>
+ <ul id="spreePageTabs" class="nav nav-pills flex-nowrap" data-nav-x-content>
+ <%= yield :page_tabs %>
</ul>
</div>
- <button id="pnAdvancerLeft" class="pn-Advancer pn-Advancer_Left" type="button" data-overscroll-button-left>
- <svg class="pn-Advancer_Icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 551 1024"><path d="M445.44 38.183L-2.53 512l447.97 473.817 85.857-81.173-409.6-433.23v81.172l409.6-433.23L445.44 38.18z" /></svg>
+ <button class="nav-x_Advancer nav-x_Advancer_Left" type="button">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 551 1024">
+ <path d="M445.44 38.183L-2.53 512l447.97 473.817 85.857-81.173-409.6-433.23v81.172l409.6-433.23L445.44 38.18z" />
+ </svg>
</button>
- <button id="pnAdvancerRight" class="pn-Advancer pn-Advancer_Right" type="button" data-overscroll-button-right>
- <svg class="pn-Advancer_Icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 551 1024"><path d="M105.56 985.817L553.53 512 105.56 38.183l-85.857 81.173 409.6 433.23v-81.172l-409.6 433.23 85.856 81.174z" /></svg>
+ <button class="nav-x_Advancer nav-x_Advancer_Right" type="button">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 551 1024">
+ <path d="M105.56 985.817L553.53 512 105.56 38.183l-85.857 81.173 409.6 433.23v-81.172l-409.6 433.23 85.856 81.174z" />
+ </svg>
</button>
</div>
<% end %>