Skip to content

Commit

Permalink
updated loader with promise
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebLuster committed Nov 21, 2024
1 parent cf31b12 commit a557bb3
Showing 1 changed file with 98 additions and 45 deletions.
143 changes: 98 additions & 45 deletions stories/assets/js/loader.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import { langSwitch } from './lang-switcher';
import { lightboxGallery } from './lightbox-gallery';
import { modal } from './modal';
import { tabs } from './tabs';
import { accordion } from './accordion';
import { sidebarNav, sidebarMenu } from './sidebar';
import { select } from './select';
import { expandSearch } from './expand-search';
import { navigationInitialize } from './navigation';
import { statsHover } from './stats';
import { swiper } from './swiper';
import { parallaxEffect } from './parallax';

const loader = () => {
// Select all elements with the attribute data-undpds and convert to an array
Expand All @@ -20,79 +8,144 @@ const loader = () => {
undpdsElements.forEach(element => {
// Get the value of data-undpds attribute
const undpdsValue = $(element).attr('data-undpds');

// Use switch statement to check the value and call appropriate functions
switch (undpdsValue) {
case 'data-undpds-tab':
tabs();
console.log('tabs');
Promise.try(() => import('./tabs'))
.then(tabs => tabs.tabs())
.catch(error => console.error('Error loading tabs:', error));
break;

case 'data-undpds-expand-search':
expandSearch($(element));
console.log('expandSearch');
Promise.try(() => import('./expand-search'))
.then(expandSearch => expandSearch.expandSearch($(element)))
.catch(error => console.error('Error loading expandSearch:', error));
break;

case 'data-undpds-select':
select();
console.log('select');
Promise.try(() => import('./select'))
.then(select => select.select())
.catch(error => console.error('Error loading select:', error));
break;

case 'data-undpds-sidebar':
sidebarNav();
sidebarMenu();
console.log('sidebar');
Promise.try(() => import('./sidebar'))
.then(sidebarNav => {
sidebarNav.sidebarNav();
sidebarNav.sidebarMenu();
})
.catch(error => console.error('Error loading sidebarNav:', error));
break;

case 'data-undpds-navigation':
navigationInitialize();
console.log('navigation');
Promise.try(() => import('./navigation'))
.then(navigationInitialize => navigationInitialize.navigationInitialize())
.catch(error => console.error('Error loading navigationInitialize:', error));
break;

case 'data-undpds-accordion':
accordion();
console.log('accordion');
Promise.try(() => import('./accordion'))
.then(accordion => accordion.accordion())
.catch(error => console.error('Error loading accordion:', error));
break;

case 'data-undpds-lightbox-gallery':
lightboxGallery();
console.log('lightboxGallery');
Promise.try(() => import('./lightbox-gallery'))
.then(lightboxGallery => lightboxGallery.lightboxGallery())
.catch(error => console.error('Error loading lightboxGallery:', error));
break;

case 'data-undpds-language-switcher':
langSwitch();
console.log('langSwitch');
Promise.try(() => import('./lang-switcher'))
.then(langSwitch => langSwitch.langSwitch())
.catch(error => console.error('Error loading langSwitch:', error));
break;

case 'data-undpds-modal':
modal();
console.log('modal');
Promise.try(() => import('./modal'))
.then(modal => modal.modal())
.catch(error => console.error('Error loading modal:', error));
break;

case 'data-undpds-stats-hover':
statsHover();
console.log('statsHover');
Promise.try(() => import('./stats'))
.then(statsHover => statsHover.statsHover())
.catch(error => console.error('Error loading statsHover:', error));
break;

case 'data-undpds-swiper':
swiper('.parallax__content');
parallaxEffect('.parallax-card', ['.parallax-cardimage', '.parallax-cardcontent'], 'top center', 'bottom+=85 center', 'vertical', 'desktop', 'percent');
console.log('swiper');
Promise.try(() => Promise.all([import('./swiper'), import('./parallax')]))
.then(([swiper, parallaxEffect]) => {
swiper.swiper('.parallax__content');
parallaxEffect.parallaxEffect(
'.parallax-card',
['.parallax-cardimage', '.parallax-cardcontent'],
'top center',
'bottom+=85 center',
'vertical',
'desktop',
'percent'
);
})
.catch(error => console.error('Error loading swiper or parallaxEffect:', error));
break;

case 'data-undpds-fit-text':
fitText('.stats-card.medium', {desktop: 110, mobile: 80});
Promise.try(() => import('./fitText'))
.then(fitText => fitText.fitText('.stats-card.medium', { desktop: 110, mobile: 80 }))
.catch(error => console.error('Error loading fitText:', error));
break;

case 'data-undpds-swiper-fixed-carousel':
swiper('.fixed-carousel', '.fixed-carousel__button-wrap');
Promise.try(() => import('./swiper'))
.then(swiperCarousel => swiperCarousel.swiper('.fixed-carousel', '.fixed-carousel__button-wrap'))
.catch(error => console.error('Error loading swiperCarousel:', error));
break;

case 'data-undpds-swiper-fluid-carousel':
swiper('.fluid-carousel', '.slide-content');
Promise.try(() => import('./swiper'))
.then(swiperFluidCarousel => swiperFluidCarousel.swiper('.fluid-carousel', '.slide-content'))
.catch(error => console.error('Error loading swiperFluidCarousel:', error));
break;

case 'data-undpds-swiper-image-carousel':
swiper('.image-carousel', '.slider-slide');
Promise.try(() => import('./swiper'))
.then(swiperImageCarousel => swiperImageCarousel.swiper('.image-carousel', '.slider-slide'))
.catch(error => console.error('Error loading swiperImageCarousel:', error));
break;

case 'data-undpds-parralax-effect-images':
parallaxEffect('.parallax-gallery-images', '.column', 'top center', 'bottom+=15% center', 'vertical', 'all');
Promise.try(() => import('./parallax'))
.then(parallaxEffectImages => parallaxEffectImages.parallaxEffect(
'.parallax-gallery-images',
'.column',
'top center',
'bottom+=15% center',
'vertical',
'all'
))
.catch(error => console.error('Error loading parallaxEffectImages:', error));
break;

case 'data-undpds-expand-to-size-homepage-hero-full':
expandToSize('.homepage-hero-full');
Promise.try(() => import('./animation'))
.then(expandToSize => expandToSize.expandToSize('.homepage-hero-full'))
.catch(error => console.error('Error loading expandToSize:', error));
break;

case 'data-undpds-expand-to-size-page-hero-full':
expandToSize('.pagehero-fulll');
Promise.try(() => import('./animation'))
.then(expandToSizePageHero => expandToSizePageHero.expandToSize('.pagehero-full'))
.catch(error => console.error('Error loading expandToSizePageHero:', error));
break;

case 'data-undpds-swiper-page-hero-cards':
swiper('.pagehero-cards-items')
Promise.try(() => import('./swiper'))
.then(swiperPageHeroCards => swiperPageHeroCards.swiper('.pagehero-cards-items'))
.catch(error => console.error('Error loading swiperPageHeroCards:', error));
break;

default:
console.warn(`No function defined for ${undpdsValue}`);
}
Expand Down

0 comments on commit a557bb3

Please sign in to comment.