Skip to content

Commit

Permalink
dynamicweb#86 add RTL support in swiffy-slider.js
Browse files Browse the repository at this point in the history
  • Loading branch information
heyyo-droid committed Mar 1, 2024
1 parent 84b3710 commit 00a0efb
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 24 deletions.
35 changes: 25 additions & 10 deletions dist/js/swiffy-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,30 @@ const swiffyslider = function() {
const slides = container.children;
const gapWidth = parseInt(window.getComputedStyle(container).columnGap);
const scrollStep = slides[0].offsetWidth + gapWidth;

const directionSlider = window.getComputedStyle(sliderElement, null).getPropertyValue('direction');
let directionFactor = (directionSlider == 'ltr') ? 1 : -1;

let scrollLeftPosition = next ?
container.scrollLeft + scrollStep :
container.scrollLeft - scrollStep;
container.scrollLeft + scrollStep * directionFactor :
container.scrollLeft - scrollStep * directionFactor;
if (fullpage) {
scrollLeftPosition = next ?
container.scrollLeft + container.offsetWidth :
container.scrollLeft - container.offsetWidth;
container.scrollLeft + container.offsetWidth * directionFactor :
container.scrollLeft - container.offsetWidth * directionFactor;
}
if (directionSlider == 'ltr') {
if (container.scrollLeft < 1 && !next && !noloop)
scrollLeftPosition = (container.scrollWidth - container.offsetWidth);
if (container.scrollLeft >= (container.scrollWidth - container.offsetWidth) && next && !noloop)
scrollLeftPosition = 0;
} else {
if (container.scrollLeft > -1 && !next && !noloop)
scrollLeftPosition = (container.scrollWidth - container.offsetWidth) * directionFactor;
if (container.scrollLeft <= (container.scrollWidth - container.offsetWidth) * directionFactor && next && !noloop)
scrollLeftPosition = 0;
}
if (container.scrollLeft < 1 && !next && !noloop)
scrollLeftPosition = (container.scrollWidth - container.offsetWidth);
if (container.scrollLeft >= (container.scrollWidth - container.offsetWidth) && next && !noloop)
scrollLeftPosition = 0;

container.scroll({
left: scrollLeftPosition,
behavior: nodelay ? "auto" : "smooth"
Expand All @@ -78,8 +90,11 @@ const swiffyslider = function() {
const gapWidth = parseInt(window.getComputedStyle(container).columnGap);
const scrollStep = container.children[0].offsetWidth + gapWidth;
const nodelay = sliderElement.classList.contains("slider-nav-nodelay");

const directionSlider = getComputedStyle(sliderElement, null).getPropertyValue('direction');
let directionFactor = (directionSlider == 'ltr') ? 1 : -1;
container.scroll({
left: (scrollStep * slideIndex),
left: (scrollStep * slideIndex * directionFactor),
behavior: nodelay ? "auto" : "smooth"
});
},
Expand Down Expand Up @@ -138,4 +153,4 @@ if (!document.currentScript.hasAttribute("data-noinit")) {
}
}
}
}
}
2 changes: 1 addition & 1 deletion dist/js/swiffy-slider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion dist/js/swiffy-slider.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 00a0efb

Please sign in to comment.