infinity-forge
Version:
67 lines • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = updateProgress;
function updateProgress(translate) {
var swiper = this;
if (typeof translate === 'undefined') {
var multiplier = swiper.rtlTranslate ? -1 : 1;
// eslint-disable-next-line
translate = (swiper && swiper.translate && swiper.translate * multiplier) || 0;
}
var params = swiper.params;
var translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
var progress = swiper.progress, isBeginning = swiper.isBeginning, isEnd = swiper.isEnd, progressLoop = swiper.progressLoop;
var wasBeginning = isBeginning;
var wasEnd = isEnd;
if (translatesDiff === 0) {
progress = 0;
isBeginning = true;
isEnd = true;
}
else {
progress = (translate - swiper.minTranslate()) / translatesDiff;
var isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1;
var isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1;
isBeginning = isBeginningRounded || progress <= 0;
isEnd = isEndRounded || progress >= 1;
if (isBeginningRounded)
progress = 0;
if (isEndRounded)
progress = 1;
}
if (params.loop) {
var firstSlideIndex = swiper.getSlideIndexByData(0);
var lastSlideIndex = swiper.getSlideIndexByData(swiper.slides.length - 1);
var firstSlideTranslate = swiper.slidesGrid[firstSlideIndex];
var lastSlideTranslate = swiper.slidesGrid[lastSlideIndex];
var translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1];
var translateAbs = Math.abs(translate);
if (translateAbs >= firstSlideTranslate) {
progressLoop = (translateAbs - firstSlideTranslate) / translateMax;
}
else {
progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax;
}
if (progressLoop > 1)
progressLoop -= 1;
}
Object.assign(swiper, {
progress: progress,
progressLoop: progressLoop,
isBeginning: isBeginning,
isEnd: isEnd,
});
if (params.watchSlidesProgress || (params.centeredSlides && params.autoHeight))
swiper.updateSlidesProgress(translate);
if (isBeginning && !wasBeginning) {
swiper.emit('reachBeginning toEdge');
}
if (isEnd && !wasEnd) {
swiper.emit('reachEnd toEdge');
}
if ((wasBeginning && !isBeginning) || (wasEnd && !isEnd)) {
swiper.emit('fromEdge');
}
swiper.emit('progress', progress);
}
//# sourceMappingURL=updateProgress.js.map