Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme js code refactoring #304

Merged
merged 9 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion _dev/css/theme/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
@import "search/index";
@import "page-loader/index";
@import "links-list/index";
@import "lazyload/index";
@import "alert-toast/index";
1 change: 0 additions & 1 deletion _dev/css/theme/components/lazyload/_index.scss

This file was deleted.

5 changes: 0 additions & 5 deletions _dev/css/theme/components/lazyload/_lazyload.scss

This file was deleted.

2 changes: 1 addition & 1 deletion _dev/js/checkout.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@js/checkout/index';
import './checkout/index';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import useEvent from '../../components/event/useEvent';
import { on } from '../../../utils/event/eventHandler';
import editAddressHandler from './handler/address/editAddressHandler';
import changeAddressHandler from './handler/address/changeAddressHandler';
import changeDeliveryMethodHandler from './handler/delivery/changeDeliveryMethodHandler';
Expand All @@ -12,8 +12,6 @@ import confirmOrderHandler from './handler/payment/confirmOrderHandler';
import checkoutFormSubmitHandler from './handler/process/checkoutFormSubmitHandler';
import checkoutStepChangeHandler from './handler/process/checkoutStepChangeHandler';

const { on } = useEvent();

/**
* Checkout controller.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import { getAllSiblingsBeforeElement, getAllSiblingsAfterElement } from '../../../utils/DOMSelectorsHelper';
import { getAllSiblingsBeforeElement, getAllSiblingsAfterElement } from '../../../../utils/DOM/DOMSelectorsHelper';

/**
* A utility function to control checkout steps in Prestashop.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import prestashop from 'prestashop';
import useToggleDisplay from '../../../../components/display/useToggleDisplay';
import useToggleDisplay from '../../../../../utils/display/useToggleDisplay';
import switchEditAddressButtonColor from '../../utils/switchEditAddressButtonColor';
import getEditAddress from '../../utils/getEditAddress';
import switchConfirmAddressesButtonState from '../../utils/switchConfirmAddressesButtonState';
import { isElementVisible, each } from '../../../../utils/DOMHelpers';
import { isElementVisible, each } from '../../../../../utils/DOM/DOMHelpers';

/**
* Handles the change event for address selection in the Prestashop checkout process.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import prestashop from 'prestashop';
import useToggleDisplay from '../../../../components/display/useToggleDisplay';
import useToggleDisplay from '../../../../../utils/display/useToggleDisplay';
import switchConfirmAddressesButtonState from '../../utils/switchConfirmAddressesButtonState';
import switchEditAddressButtonColor from '../../utils/switchEditAddressButtonColor';
import { isElementVisible } from '../../../../utils/DOMHelpers';
import { isElementVisible } from '../../../../../utils/DOM/DOMHelpers';
import getEditAddress from '../../utils/getEditAddress';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import prestashop from 'prestashop';
import { formSerializeArray, fromSerializeObject } from '../../../../utils/formSerialize';
import { formSerializeArray, fromSerializeObject } from '../../../../../utils/form/formSerialize';
import selectDeliveryMethodRequest from '../../request/selectDeliveryMethodRequest';
import parseToHtml from '../../../../utils/parseToHtml';
import refreshCheckoutPage from '../../utils/refreshCheckoutPage';
import { each } from '../../../../utils/DOMHelpers';
import { each, parseToHtml } from '../../../../../utils/DOM/DOMHelpers';

/**
* Handles the change of delivery method in the Prestashop checkout process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getSelectedPaymentOption from '../../utils/getSelectedPaymentOption';
import canProceedOrder from '../../utils/canProceedOrder';
import checkCartStillOrderableRequest from '../../request/checkCartStillOrderableRequest';
import toggleOrderConfirmationButtonState from '../../utils/toggleOrderConfirmationButtonState';
import { each } from '../../../../utils/DOMHelpers';
import { each } from '../../../../../utils/DOM/DOMHelpers';

const showNativeFormErrors = () => {
const { termsCheckboxSelector } = prestashop.selectors.checkout;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import prestashop from 'prestashop';
import useToggleDisplay from '../../../../components/display/useToggleDisplay';
import useToggleDisplay from '../../../../../utils/display/useToggleDisplay';
import canProceedOrder from '../../utils/canProceedOrder';
import toggleOrderConfirmationButtonState from '../../utils/toggleOrderConfirmationButtonState';
import { each } from '../../../../utils/DOMHelpers';
import { each } from '../../../../../utils/DOM/DOMHelpers';

const { toggle } = useToggleDisplay();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import collapseAllPaymentOptions from '../../utils/collapseAllPaymentOptions';
import getSelectedPaymentOption from '../../utils/getSelectedPaymentOption';
import useToggleDisplay from '../../../../components/display/useToggleDisplay';
import useToggleDisplay from '../../../../../utils/display/useToggleDisplay';
import canProceedOrder from '../../utils/canProceedOrder';
import toggleOrderConfirmationButtonState from '../../utils/toggleOrderConfirmationButtonState';
import { each } from '../../../../utils/DOMHelpers';
import { each } from '../../../../../utils/DOM/DOMHelpers';

const { show } = useToggleDisplay();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import { each } from '../../../../utils/DOMHelpers';
import { each } from '../../../../../utils/DOM/DOMHelpers';

/**
* Handles the submission of the checkout form, disables submit buttons, and emits a 'submitCheckoutForm' event.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import DOMReady from '../../utils/DOMReady';
import { DOMReady } from '../../../utils/DOM/DOMHelpers';

import checkoutController from './checkoutController';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import useDefaultHttpRequest from '../../../components/http/useDefaultHttpRequest';
import useDefaultHttpRequest from '../../../../utils/http/useDefaultHttpRequest';

/**
* Represents the server response from a check cart still orderable request.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useDefaultHttpRequest from '../../../components/http/useDefaultHttpRequest';
import useDefaultHttpRequest from '../../../../utils/http/useDefaultHttpRequest';

/**
* Represents the server response from a select delivery method request.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import { each } from '../../../utils/DOMHelpers';
import { each } from '../../../../utils/DOM/DOMHelpers';

/**
* Checks if all conditions are accepted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prestashop from 'prestashop';
import { each } from '../../../utils/DOMHelpers';
import useToggleDisplay from '../../../components/display/useToggleDisplay';
import { each } from '../../../../utils/DOM/DOMHelpers';
import useToggleDisplay from '../../../../utils/display/useToggleDisplay';

/**
* Collapses all payment options' additional information blocks and options forms.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { each } from '../../../utils/DOMHelpers';
import { each } from '../../../../utils/DOM/DOMHelpers';

/**
* Switches the state of the confirm addresses button.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { each } from '../../../utils/DOMHelpers';
import { each } from '../../../../utils/DOM/DOMHelpers';

/**
* Changes the color of the edit button for the wrong address.
Expand Down
11 changes: 4 additions & 7 deletions _dev/js/checkout/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import prestashop from 'prestashop';
import useEvent from '../theme/components/event/useEvent';
import parseToHtml from '../theme/utils/parseToHtml';
import useHttpRequest from '../theme/components/http/useHttpRequest';
import { each } from '../theme/utils/DOMHelpers';
import DOMReady from '../theme/utils/DOMReady';

const { on } = useEvent();
import { on } from '../utils/event/eventHandler';
import { parseToHtml, each, DOMReady } from '../utils/DOM/DOMHelpers';
import useHttpRequest from '../utils/http/useHttpRequest';
import './core/checkout/index';

function setUpCheckout() {
const clickTermLinkHandler = async (event) => {
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/listing.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@js/listing/index';
import './listing/index';
4 changes: 1 addition & 3 deletions _dev/js/listing/components/filters/Filters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prestashop from 'prestashop';
import FiltersRangeSliders from './FiltersRangeSliders';
import useEvent from '../../../theme/components/event/useEvent';
import { on } from '../../../utils/event/eventHandler';

class Filters {
constructor() {
Expand All @@ -11,8 +11,6 @@ class Filters {
}

setEvents() {
const { on } = useEvent();

prestashop.on('updatedProductList', () => {
prestashop.pageLoader.hideLoader();
this.rangeSliders.init();
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/listing/components/filters/FiltersRangeSliders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RangeSlider from './RangeSlider';
import { each } from '../../../theme/utils/DOMHelpers';
import { each } from '../../../utils/DOM/DOMHelpers';

class FiltersRangeSliders {
static init() {
Expand Down
3 changes: 1 addition & 2 deletions _dev/js/listing/components/filters/RangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import prestashop from 'prestashop';
import noUiSlider from 'nouislider';
import wNumb from 'wnumb';
import FiltersUrlHandler from './FiltersUrlHandler';
import useEvent from '../../../theme/components/event/useEvent';
import { on, off } from '../../../utils/event/eventHandler';

class RangeSlider {
constructor(element) {
Expand Down Expand Up @@ -92,7 +92,6 @@ class RangeSlider {
}

setEvents() {
const { on, off } = useEvent();
this.sliderHandler.off('set', this.constructor.handlerSliderSet);
this.sliderHandler.on('set', this.constructor.handlerSliderSet);
this.sliderHandler.off('update', this.handlerSliderUpdate);
Expand Down
6 changes: 2 additions & 4 deletions _dev/js/listing/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import prestashop from 'prestashop';
import Filters from '@js/listing/components/filters/Filters';
import parseToHtml from '../theme/utils/parseToHtml';
import { each } from '../theme/utils/DOMHelpers';
import DOMReady from '../theme/utils/DOMReady';
import Filters from './components/filters/Filters';
import { each, parseToHtml, DOMReady } from '../utils/DOM/DOMHelpers';

function updateProductListDOM(data) {
each(prestashop.selectors.listing.searchFilters, (el) => {
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/product.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@js/product/index';
import './product/index';
2 changes: 1 addition & 1 deletion _dev/js/product/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ProductGallery from './components/ProductGallery';
import DOMReady from '../theme/utils/DOMReady';
import { DOMReady } from '../utils/DOM/DOMHelpers';

DOMReady(() => {
const gallery = new ProductGallery();
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/theme.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@js/theme/index';
import './theme/index';
21 changes: 0 additions & 21 deletions _dev/js/theme/components/Lazyload.js

This file was deleted.

2 changes: 1 addition & 1 deletion _dev/js/theme/components/customer/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DOMReady from '../../utils/DOMReady';
import { DOMReady } from '../../../utils/DOM/DOMHelpers';

const initCustomerLinksTriggerActive = () => {
const url = window.location.pathname;
Expand Down
4 changes: 2 additions & 2 deletions _dev/js/theme/components/dynamic-bootstrap-components.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DOMReady from '../utils/DOMReady';
import useBootstrapComponentDynamicImport from '../utils/dynamicImports/useBootstrapComponentDynamicImport';
import { DOMReady } from '../../utils/DOM/DOMHelpers';
import useBootstrapComponentDynamicImport from '../../utils/dynamicImports/useBootstrapComponentDynamicImport';

DOMReady(() => {
const { init: initDynamicImportForModal } = useBootstrapComponentDynamicImport(
Expand Down
59 changes: 0 additions & 59 deletions _dev/js/theme/components/event/useEvent.js

This file was deleted.

2 changes: 1 addition & 1 deletion _dev/js/theme/components/header/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DOMReady from '../../utils/DOMReady';
import { DOMReady } from '../../../utils/DOM/DOMHelpers';
import useTopMenu from './useTopMenu';
import useStickyElement from '../useStickyElement';

Expand Down
3 changes: 1 addition & 2 deletions _dev/js/theme/components/header/useTopMenu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import useEvent from '../event/useEvent';
import { on, off } from '../../../utils/event/eventHandler';

const useTopMenu = (selector) => {
const { on, off } = useEvent();
const menuElement = document.querySelector(selector);
const DOM_SELECTORS = {
SUB_ELEMENTS: '.main-menu__item--top',
Expand Down
4 changes: 1 addition & 3 deletions _dev/js/theme/components/product.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import prestashop from 'prestashop';
import useCustomQuantityInput from './useCustomQuantityInput';
import { each } from '../utils/DOMHelpers';
import parseToHtml from '../utils/parseToHtml';
import DOMReady from '../utils/DOMReady';
import { each, parseToHtml, DOMReady } from '../../utils/DOM/DOMHelpers';
import productEventContextSelector from '../core/product/utils/productEventContextSelector';

DOMReady(() => {
Expand Down
3 changes: 1 addition & 2 deletions _dev/js/theme/components/quickview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import prestashop from 'prestashop';
import DOMReady from '../utils/DOMReady';
import parseToHtml from '../utils/parseToHtml';
import { DOMReady, parseToHtml } from '../../utils/DOM/DOMHelpers';

/**
* Handle open quick view
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/theme/components/responsive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import DOMReady from '../utils/DOMReady';
import { DOMReady } from '../../utils/DOM/DOMHelpers';

function isMobile() {
return prestashop.responsive.current_width < prestashop.responsive.min_width;
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/theme/components/sliders/PageSlider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiperSlider from '@js/theme/components/sliders/SwiperSlider';
import SwiperSlider from './SwiperSlider';

class PageSlider {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion _dev/js/theme/components/sliders/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import prestashop from 'prestashop';
import DOMReady from '../../utils/DOMReady';
import { DOMReady } from '../../../utils/DOM/DOMHelpers';
import PageSlider from './PageSlider';
import SwiperSlider from './SwiperSlider';

Expand Down
Loading