index.js 860 Bytes
Newer Older
xhw committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
function checkOverflow() {
	const swiper = this;
	const {
		isLocked: wasLocked,
		params
	} = swiper;
	const {
		slidesOffsetBefore
	} = params;

	if (slidesOffsetBefore) {
		const lastSlideIndex = swiper.slides.length - 1;
		const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] +
			slidesOffsetBefore * 2;
		swiper.isLocked = swiper.size > lastSlideRightEdge;
	} else {
		swiper.isLocked = swiper.snapGrid.length === 1;
	}

	if (params.allowSlideNext === true) {
		swiper.allowSlideNext = !swiper.isLocked;
	}

	if (params.allowSlidePrev === true) {
		swiper.allowSlidePrev = !swiper.isLocked;
	}

	if (wasLocked && wasLocked !== swiper.isLocked) {
		swiper.isEnd = false;
	}

	if (wasLocked !== swiper.isLocked) {
		swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
	}
}

export default {
	checkOverflow
};