Files
easystream-main/f_scripts/shared/swiper/modules/grid/grid.js
SamiAhmed7777 0b7e2d0a5b feat: Add comprehensive documentation suite and reorganize project structure
- Created complete documentation in docs/ directory
- Added PROJECT_OVERVIEW.md with feature highlights and getting started guide
- Added ARCHITECTURE.md with system design and technical details
- Added SECURITY.md with comprehensive security implementation guide
- Added DEVELOPMENT.md with development workflows and best practices
- Added DEPLOYMENT.md with production deployment instructions
- Added API.md with complete REST API documentation
- Added CONTRIBUTING.md with contribution guidelines
- Added CHANGELOG.md with version history and migration notes
- Reorganized all documentation files into docs/ directory for better organization
- Updated README.md with proper documentation links and quick navigation
- Enhanced project structure with professional documentation standards
2025-10-21 00:39:45 -07:00

98 lines
3.1 KiB
JavaScript

export default function Grid({
swiper,
extendParams
}) {
extendParams({
grid: {
rows: 1,
fill: 'column'
}
});
let slidesNumberEvenToRows;
let slidesPerRow;
let numFullColumns;
const initSlides = slidesLength => {
const {
slidesPerView
} = swiper.params;
const {
rows,
fill
} = swiper.params.grid;
slidesPerRow = slidesNumberEvenToRows / rows;
numFullColumns = Math.floor(slidesLength / rows);
if (Math.floor(slidesLength / rows) === slidesLength / rows) {
slidesNumberEvenToRows = slidesLength;
} else {
slidesNumberEvenToRows = Math.ceil(slidesLength / rows) * rows;
}
if (slidesPerView !== 'auto' && fill === 'row') {
slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, slidesPerView * rows);
}
};
const updateSlide = (i, slide, slidesLength, getDirectionLabel) => {
const {
slidesPerGroup,
spaceBetween
} = swiper.params;
const {
rows,
fill
} = swiper.params.grid;
// Set slides order
let newSlideOrderIndex;
let column;
let row;
if (fill === 'row' && slidesPerGroup > 1) {
const groupIndex = Math.floor(i / (slidesPerGroup * rows));
const slideIndexInGroup = i - rows * slidesPerGroup * groupIndex;
const columnsInGroup = groupIndex === 0 ? slidesPerGroup : Math.min(Math.ceil((slidesLength - groupIndex * rows * slidesPerGroup) / rows), slidesPerGroup);
row = Math.floor(slideIndexInGroup / columnsInGroup);
column = slideIndexInGroup - row * columnsInGroup + groupIndex * slidesPerGroup;
newSlideOrderIndex = column + row * slidesNumberEvenToRows / rows;
slide.style.order = newSlideOrderIndex;
} else if (fill === 'column') {
column = Math.floor(i / rows);
row = i - column * rows;
if (column > numFullColumns || column === numFullColumns && row === rows - 1) {
row += 1;
if (row >= rows) {
row = 0;
column += 1;
}
}
} else {
row = Math.floor(i / slidesPerRow);
column = i - row * slidesPerRow;
}
slide.style[getDirectionLabel('margin-top')] = row !== 0 ? spaceBetween && `${spaceBetween}px` : '';
};
const updateWrapperSize = (slideSize, snapGrid, getDirectionLabel) => {
const {
spaceBetween,
centeredSlides,
roundLengths
} = swiper.params;
const {
rows
} = swiper.params.grid;
swiper.virtualSize = (slideSize + spaceBetween) * slidesNumberEvenToRows;
swiper.virtualSize = Math.ceil(swiper.virtualSize / rows) - spaceBetween;
swiper.wrapperEl.style[getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
if (centeredSlides) {
const newSlidesGrid = [];
for (let i = 0; i < snapGrid.length; i += 1) {
let slidesGridItem = snapGrid[i];
if (roundLengths) slidesGridItem = Math.floor(slidesGridItem);
if (snapGrid[i] < swiper.virtualSize + snapGrid[0]) newSlidesGrid.push(slidesGridItem);
}
snapGrid.splice(0, snapGrid.length);
snapGrid.push(...newSlidesGrid);
}
};
swiper.grid = {
initSlides,
updateSlide,
updateWrapperSize
};
}