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.

Fix odd even CSS selector.

Matthew Kennedy979b762a7809
diff --git a/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6 b/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6
index b5ffe65e87..f77cb1d32f 100644
--- a/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6
+++ b/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6
@@ -4,16 +4,45 @@ document.addEventListener('turbolinks:load', function() {
if (!featurePageContent) return
- const halfWidthElements = featurePageContent.querySelectorAll('.cms_half_section')
+ const halfWidthElements = featurePageContent.querySelectorAll('.cms_full_section')
halfWidthElements.forEach(function(elem) {
- if (elem.nextElementSibling && !elem.nextElementSibling.classList.contains('cms_half_section')) {
- if (elem.previousElementSibling && elem.previousElementSibling.classList.contains('cms_half_section')) return
+ if (elem.previousElementSibling && elem.previousElementSibling.classList.contains('cms_half_section')) {
+ const siblings = getSiblings(elem);
- const el = document.createElement('aside');
- el.classList.add('col-6', 'cms_half_section', 'd-none')
-
- elem.insertAdjacentElement('afterend', el);
+ if (!isEven(siblings.length)) { insertPlaceHolder(elem) }
}
})
+
+ function insertPlaceHolder(elem) {
+ const el = document.createElement('aside');
+ el.classList.add('col-6', 'cms_half_section', 'd-none')
+
+ elem.insertAdjacentElement('beforebegin', el);
+ }
+
+ function isEven(value) {
+ if (value % 2 === 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function getSiblings(elem) {
+ // Setup siblings array and get the first sibling
+ const siblings = [];
+ let sibling = elem.parentNode.firstChild;
+
+ // Loop through each sibling and push to the array
+ while (sibling) {
+ if (sibling === elem) break
+
+ if (sibling.nodeType === 1 && sibling !== elem && !sibling.classList.contains('cms_full_section')) {
+ siblings.push(sibling);
+ }
+ sibling = sibling.nextElementSibling;
+ }
+ return siblings;
+ };
})
diff --git a/frontend/app/helpers/spree/cms_pages_helper.rb b/frontend/app/helpers/spree/cms_pages_helper.rb
index 794623a67f..16077b7b05 100644
--- a/frontend/app/helpers/spree/cms_pages_helper.rb
+++ b/frontend/app/helpers/spree/cms_pages_helper.rb
@@ -13,7 +13,7 @@ module Spree
css_width = 'col-6 cms_half_section'
when 'Full'
element = 'div'
- css_width = 'col-12'
+ css_width = 'col-12 cms_full_section'
else
element = 'div'
css_width = ''
diff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb
index 8283703800..587304a065 100644
--- a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb
@@ -1,5 +1,5 @@
-<div class="col-12">
- <div class="full-width">
+<div class="<%= width %>">
+ <div class="<%= boundary %>">
<div data-product-carousel-taxon-id='<%= section.linked_resource.permalink %>' class="my-3"></div>
</div>
</div>