Skip to content

Commit

Permalink
vanilla.js pageloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Oct 9, 2023
1 parent e9bdb2d commit 63680e2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
17 changes: 0 additions & 17 deletions _dev/js/theme/components/PageLoader.js

This file was deleted.

1 change: 0 additions & 1 deletion _dev/js/theme/components/customer/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import DOMReady from "../../utils/DOMReady";

Check failure on line 1 in _dev/js/theme/components/customer/index.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Strings must use singlequote
import $ from "jquery";

const initCustomerLinksTriggerActive = () => {
const url = window.location.pathname;
Expand Down
40 changes: 40 additions & 0 deletions _dev/js/theme/components/usePageLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* A utility module for managing the page loader state.
*
* @return {showLoader, hideLoader}
* @example
* const pageLoader = usePageLoader();
* pageLoader.showLoader(); // Display the page loader
* pageLoader.hideLoader(); // Hide the page loader
*/
const usePageLoader = () => {
const body = document.body;

Check failure on line 11 in _dev/js/theme/components/usePageLoader.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Use object destructuring
const ACTIVE_CLASS = 'page-loader-active';

/**
* Show the page loader.
*
* @method showLoader
* @returns {void}
*/
const showLoader = () => {
body.classList.add(ACTIVE_CLASS);
};

/**
* Hide the page loader.
*
* @method hideLoader
* @returns {void}
*/
const hideLoader = () => {
body.classList.remove(ACTIVE_CLASS);
};

return {
showLoader,
hideLoader,
};
};

export default usePageLoader;
4 changes: 2 additions & 2 deletions _dev/js/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ for (const i in EventEmitter.prototype) {
import usePasswordPolicy from './components/password/usePasswordPolicy';
import Form from './components/form';
import PageLazyLoad from './components/Lazyload';
import PageLoader from './components/PageLoader';
import httpRequestErrorHandler from './handler/error/httpRequestErrorHandler';
import usePageLoader from "./components/usePageLoader";

prestashop.pageLazyLoad = new PageLazyLoad({
selector: '.lazyload',
});

prestashop.pageLoader = new PageLoader();
prestashop.pageLoader = usePageLoader();

prestashop.on('handleError', httpRequestErrorHandler);

Expand Down

0 comments on commit 63680e2

Please sign in to comment.