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
This commit is contained in:
161
f_scripts/shared/swiper/components-shared/update-swiper.js
Normal file
161
f_scripts/shared/swiper/components-shared/update-swiper.js
Normal file
@@ -0,0 +1,161 @@
|
||||
import { isObject, extend } from './utils.js';
|
||||
function updateSwiper({
|
||||
swiper,
|
||||
slides,
|
||||
passedParams,
|
||||
changedParams,
|
||||
nextEl,
|
||||
prevEl,
|
||||
scrollbarEl,
|
||||
paginationEl
|
||||
}) {
|
||||
const updateParams = changedParams.filter(key => key !== 'children' && key !== 'direction' && key !== 'wrapperClass');
|
||||
const {
|
||||
params: currentParams,
|
||||
pagination,
|
||||
navigation,
|
||||
scrollbar,
|
||||
virtual,
|
||||
thumbs
|
||||
} = swiper;
|
||||
let needThumbsInit;
|
||||
let needControllerInit;
|
||||
let needPaginationInit;
|
||||
let needScrollbarInit;
|
||||
let needNavigationInit;
|
||||
let loopNeedDestroy;
|
||||
let loopNeedEnable;
|
||||
let loopNeedReloop;
|
||||
if (changedParams.includes('thumbs') && passedParams.thumbs && passedParams.thumbs.swiper && currentParams.thumbs && !currentParams.thumbs.swiper) {
|
||||
needThumbsInit = true;
|
||||
}
|
||||
if (changedParams.includes('controller') && passedParams.controller && passedParams.controller.control && currentParams.controller && !currentParams.controller.control) {
|
||||
needControllerInit = true;
|
||||
}
|
||||
if (changedParams.includes('pagination') && passedParams.pagination && (passedParams.pagination.el || paginationEl) && (currentParams.pagination || currentParams.pagination === false) && pagination && !pagination.el) {
|
||||
needPaginationInit = true;
|
||||
}
|
||||
if (changedParams.includes('scrollbar') && passedParams.scrollbar && (passedParams.scrollbar.el || scrollbarEl) && (currentParams.scrollbar || currentParams.scrollbar === false) && scrollbar && !scrollbar.el) {
|
||||
needScrollbarInit = true;
|
||||
}
|
||||
if (changedParams.includes('navigation') && passedParams.navigation && (passedParams.navigation.prevEl || prevEl) && (passedParams.navigation.nextEl || nextEl) && (currentParams.navigation || currentParams.navigation === false) && navigation && !navigation.prevEl && !navigation.nextEl) {
|
||||
needNavigationInit = true;
|
||||
}
|
||||
const destroyModule = mod => {
|
||||
if (!swiper[mod]) return;
|
||||
swiper[mod].destroy();
|
||||
if (mod === 'navigation') {
|
||||
if (swiper.isElement) {
|
||||
swiper[mod].prevEl.remove();
|
||||
swiper[mod].nextEl.remove();
|
||||
}
|
||||
currentParams[mod].prevEl = undefined;
|
||||
currentParams[mod].nextEl = undefined;
|
||||
swiper[mod].prevEl = undefined;
|
||||
swiper[mod].nextEl = undefined;
|
||||
} else {
|
||||
if (swiper.isElement) {
|
||||
swiper[mod].el.remove();
|
||||
}
|
||||
currentParams[mod].el = undefined;
|
||||
swiper[mod].el = undefined;
|
||||
}
|
||||
};
|
||||
if (changedParams.includes('loop') && swiper.isElement) {
|
||||
if (currentParams.loop && !passedParams.loop) {
|
||||
loopNeedDestroy = true;
|
||||
} else if (!currentParams.loop && passedParams.loop) {
|
||||
loopNeedEnable = true;
|
||||
} else {
|
||||
loopNeedReloop = true;
|
||||
}
|
||||
}
|
||||
updateParams.forEach(key => {
|
||||
if (isObject(currentParams[key]) && isObject(passedParams[key])) {
|
||||
extend(currentParams[key], passedParams[key]);
|
||||
} else {
|
||||
const newValue = passedParams[key];
|
||||
if ((newValue === true || newValue === false) && (key === 'navigation' || key === 'pagination' || key === 'scrollbar')) {
|
||||
if (newValue === false) {
|
||||
destroyModule(key);
|
||||
}
|
||||
} else {
|
||||
currentParams[key] = passedParams[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
if (updateParams.includes('controller') && !needControllerInit && swiper.controller && swiper.controller.control && currentParams.controller && currentParams.controller.control) {
|
||||
swiper.controller.control = currentParams.controller.control;
|
||||
}
|
||||
if (changedParams.includes('children') && slides && virtual && currentParams.virtual.enabled) {
|
||||
virtual.slides = slides;
|
||||
virtual.update(true);
|
||||
}
|
||||
if (changedParams.includes('children') && slides && currentParams.loop) {
|
||||
loopNeedReloop = true;
|
||||
}
|
||||
if (needThumbsInit) {
|
||||
const initialized = thumbs.init();
|
||||
if (initialized) thumbs.update(true);
|
||||
}
|
||||
if (needControllerInit) {
|
||||
swiper.controller.control = currentParams.controller.control;
|
||||
}
|
||||
if (needPaginationInit) {
|
||||
if (swiper.isElement && (!paginationEl || typeof paginationEl === 'string')) {
|
||||
paginationEl = document.createElement('div');
|
||||
paginationEl.classList.add('swiper-pagination');
|
||||
swiper.el.shadowEl.appendChild(paginationEl);
|
||||
}
|
||||
if (paginationEl) currentParams.pagination.el = paginationEl;
|
||||
pagination.init();
|
||||
pagination.render();
|
||||
pagination.update();
|
||||
}
|
||||
if (needScrollbarInit) {
|
||||
if (swiper.isElement && (!scrollbarEl || typeof scrollbarEl === 'string')) {
|
||||
scrollbarEl = document.createElement('div');
|
||||
scrollbarEl.classList.add('swiper-scrollbar');
|
||||
swiper.el.shadowEl.appendChild(scrollbarEl);
|
||||
}
|
||||
if (scrollbarEl) currentParams.scrollbar.el = scrollbarEl;
|
||||
scrollbar.init();
|
||||
scrollbar.updateSize();
|
||||
scrollbar.setTranslate();
|
||||
}
|
||||
if (needNavigationInit) {
|
||||
if (swiper.isElement) {
|
||||
if (!nextEl || typeof nextEl === 'string') {
|
||||
nextEl = document.createElement('div');
|
||||
nextEl.classList.add('swiper-button-next');
|
||||
swiper.el.shadowEl.appendChild(nextEl);
|
||||
}
|
||||
if (!prevEl || typeof prevEl === 'string') {
|
||||
prevEl = document.createElement('div');
|
||||
prevEl.classList.add('swiper-button-prev');
|
||||
swiper.el.shadowEl.appendChild(prevEl);
|
||||
}
|
||||
}
|
||||
if (nextEl) currentParams.navigation.nextEl = nextEl;
|
||||
if (prevEl) currentParams.navigation.prevEl = prevEl;
|
||||
navigation.init();
|
||||
navigation.update();
|
||||
}
|
||||
if (changedParams.includes('allowSlideNext')) {
|
||||
swiper.allowSlideNext = passedParams.allowSlideNext;
|
||||
}
|
||||
if (changedParams.includes('allowSlidePrev')) {
|
||||
swiper.allowSlidePrev = passedParams.allowSlidePrev;
|
||||
}
|
||||
if (changedParams.includes('direction')) {
|
||||
swiper.changeDirection(passedParams.direction, false);
|
||||
}
|
||||
if (loopNeedDestroy || loopNeedReloop) {
|
||||
swiper.loopDestroy();
|
||||
}
|
||||
if (loopNeedEnable || loopNeedReloop) {
|
||||
swiper.loopCreate();
|
||||
}
|
||||
swiper.update();
|
||||
}
|
||||
export { updateSwiper };
|
||||
Reference in New Issue
Block a user