Skip to content

Commit

Permalink
Merge pull request #2838 from entreprise7pro/parseint-breakpoints-num…
Browse files Browse the repository at this point in the history
…bers-not-strings-pull-request

breakpoints source code fix, see issue #2789
  • Loading branch information
nolimits4web committed Oct 18, 2018
2 parents a7066aa + 095d60b commit adea312
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/core/breakpoints/setBreakpoint.js
Expand Up @@ -10,6 +10,24 @@ export default function () {
// Set breakpoint for window width and update parameters
const breakpoint = swiper.getBreakpoint(breakpoints);
if (breakpoint && swiper.currentBreakpoint !== breakpoint) {
// Unless 'auto', these values must be integers, we must do math operations, not string concatenations.
if (breakpoint in breakpoints && typeof breakpoints[breakpoint].slidesPerView !== 'undefined') {
// If it's 'auto' cannot make it an integer but we can make it lowercase.
if (breakpoints[breakpoint].slidesPerView === 'auto' || breakpoints[breakpoint].slidesPerView === 'AUTO') {
breakpoints[breakpoint].slidesPerView = breakpoints[breakpoint].slidesPerView.toLowerCase();
} else {
// Force slidesPerView to an integer using parseInt(x, 10) (base 10).
breakpoints[breakpoint].slidesPerView = parseInt(breakpoints[breakpoint].slidesPerView, 10);
}
}
if (breakpoint in breakpoints && typeof breakpoints[breakpoint].spaceBetween !== 'undefined') {
// Force spaceBetween to an integer using parseInt(x, 10) (base 10).
breakpoints[breakpoint].spaceBetween = parseInt(breakpoints[breakpoint].spaceBetween, 10);
}
if (breakpoint in breakpoints && typeof breakpoints[breakpoint].slidesPerGroup !== 'undefined') {
// Force slidesPerGroup to an integer using parseInt(x, 10) (base 10).
breakpoints[breakpoint].slidesPerGroup = parseInt(breakpoints[breakpoint].slidesPerGroup, 10);
}
const breakPointsParams = breakpoint in breakpoints ? breakpoints[breakpoint] : swiper.originalParams;
const needsReLoop = params.loop && (breakPointsParams.slidesPerView !== params.slidesPerView);

Expand All @@ -23,6 +41,18 @@ export default function () {

swiper.currentBreakpoint = breakpoint;

if (typeof breakPointsParams.slidesPerGroup !== 'undefined') {
// Use the breakpoint slidesPerGroup, otherwise we'd get the default desktop setting.
swiper.params.slidesPerGroup = breakPointsParams.slidesPerGroup;
}
if (typeof breakPointsParams.slidesPerView !== 'undefined') {
// Use the breakpoint slidesPerView, otherwise we'd get the default desktop setting.
swiper.params.slidesPerView = breakPointsParams.slidesPerView;
}
if (typeof breakPointsParams.spaceBetween !== 'undefined') {
// Use the breakpoint spaceBetween, otherwise we'd get the default desktop setting.
swiper.params.spaceBetween = breakPointsParams.spaceBetween;
}
if (needsReLoop && initialized) {
swiper.loopDestroy();
swiper.loopCreate();
Expand Down

0 comments on commit adea312

Please sign in to comment.