From e9bdb2de06045c14e7e46cd75f02ee16849414a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Mon, 9 Oct 2023 23:16:10 +0200 Subject: [PATCH] customer account jquery removed --- _dev/js/theme/components/customer.js | 18 ---------- _dev/js/theme/components/customer/index.js | 34 +++++++++++++++++++ _dev/js/theme/components/header/index.js | 21 ++++++++++++ .../components/{ => header}/useTopMenu.js | 2 +- _dev/js/theme/components/useStickyElement.js | 9 +++-- _dev/js/theme/index.js | 31 ++--------------- 6 files changed, 65 insertions(+), 50 deletions(-) delete mode 100644 _dev/js/theme/components/customer.js create mode 100644 _dev/js/theme/components/customer/index.js create mode 100644 _dev/js/theme/components/header/index.js rename _dev/js/theme/components/{ => header}/useTopMenu.js (96%) diff --git a/_dev/js/theme/components/customer.js b/_dev/js/theme/components/customer.js deleted file mode 100644 index 5009226a..00000000 --- a/_dev/js/theme/components/customer.js +++ /dev/null @@ -1,18 +0,0 @@ -import $ from 'jquery'; - -function initRmaItemSelector() { - $(`${prestashop.selectors.order.returnForm} table thead input[type=checkbox]`).on('click', ({ currentTarget }) => { - const checked = $(currentTarget).prop('checked'); - $(`${prestashop.selectors.order.returnForm} table tbody input[type=checkbox]`).each((_, checkbox) => { - $(checkbox).prop('checked', checked); - }); - }); -} - -function setupCustomerScripts() { - if ($('body#order-detail')) { - initRmaItemSelector(); - } -} - -$(document).ready(setupCustomerScripts); diff --git a/_dev/js/theme/components/customer/index.js b/_dev/js/theme/components/customer/index.js new file mode 100644 index 00000000..9f1aa423 --- /dev/null +++ b/_dev/js/theme/components/customer/index.js @@ -0,0 +1,34 @@ +import DOMReady from "../../utils/DOMReady"; +import $ from "jquery"; + +const initCustomerLinksTriggerActive = () => { + const url = window.location.pathname; + const customerLinks = document.querySelectorAll('.js-customer-links a'); + + customerLinks.forEach((el) => { + if (el.getAttribute('href').indexOf(url) !== -1) { + el.classList.add('active'); + } + }); +} + +const initRmaForm = () => { + const returnForm = document.querySelector(prestashop.selectors.order.returnForm); + + if (!returnForm) { + return; + } + + returnForm.querySelector('thead input[type=checkbox]').addEventListener('click', ({ currentTarget }) => { + const checked = currentTarget.checked; + returnForm.querySelectorAll('tbody input[type=checkbox]').forEach((checkbox) => { + checkbox.checked = checked; + }); + }); +} + + +DOMReady(() => { + initCustomerLinksTriggerActive(); + initRmaForm(); +}) diff --git a/_dev/js/theme/components/header/index.js b/_dev/js/theme/components/header/index.js new file mode 100644 index 00000000..90b34e45 --- /dev/null +++ b/_dev/js/theme/components/header/index.js @@ -0,0 +1,21 @@ +import DOMReady from "../../utils/DOMReady"; +import useTopMenu from './useTopMenu'; +import useStickyElement from "../useStickyElement"; + +const initStickyHeader = () => { + const header = document.querySelector('.js-header-top'); + const headerWrapper = document.querySelector('.js-header-top-wrapper'); + + if (header && headerWrapper) { + const { init } = useStickyElement(header, headerWrapper); + + init(); + } +} + +DOMReady(() => { + const { init: initTopMenu } = useTopMenu('.js-main-menu'); + + initTopMenu(); + initStickyHeader(); +}); diff --git a/_dev/js/theme/components/useTopMenu.js b/_dev/js/theme/components/header/useTopMenu.js similarity index 96% rename from _dev/js/theme/components/useTopMenu.js rename to _dev/js/theme/components/header/useTopMenu.js index da512c3d..e8556369 100644 --- a/_dev/js/theme/components/useTopMenu.js +++ b/_dev/js/theme/components/header/useTopMenu.js @@ -1,4 +1,4 @@ -import useEvent from './event/useEvent'; +import useEvent from '../event/useEvent'; const useTopMenu = (selector) => { const { on, off } = useEvent(); diff --git a/_dev/js/theme/components/useStickyElement.js b/_dev/js/theme/components/useStickyElement.js index 19059948..dd7ef80a 100644 --- a/_dev/js/theme/components/useStickyElement.js +++ b/_dev/js/theme/components/useStickyElement.js @@ -1,4 +1,4 @@ -import debounce from '@js/theme/utils/debounce'; +import debounce from '../utils/debounce'; /** * Returns sticky element data @@ -65,11 +65,14 @@ export default (element, stickyWrapper, options = {}) => { } }; - window.addEventListener('scroll', debounce(handleSticky, debounceTime)); - handleSticky(); + const init = () => { + window.addEventListener('scroll', debounce(handleSticky, debounceTime)); + handleSticky(); + } return { getExtraOffsetTop, getIsSticky, + init, }; }; diff --git a/_dev/js/theme/index.js b/_dev/js/theme/index.js index db2653f4..c546b29e 100644 --- a/_dev/js/theme/index.js +++ b/_dev/js/theme/index.js @@ -2,18 +2,18 @@ import $ from 'jquery'; import EventEmitter from 'events'; -import '@js/theme/core'; +import './core/index'; import './vendors/bootstrap/bootstrap-imports'; import './components/dynamic-bootstrap-components'; import bsCustomFileInput from 'bs-custom-file-input'; +import './components/header/index'; +import './components/customer/index'; import './components/sliders'; import './components/responsive'; -import './components/customer'; import './components/quickview'; import './components/product'; import prestashop from 'prestashop'; -import useTopMenu from './components/useTopMenu'; /* eslint-enable */ /* eslint-disable */ @@ -25,7 +25,6 @@ import usePasswordPolicy from './components/password/usePasswordPolicy'; import Form from './components/form'; import PageLazyLoad from './components/Lazyload'; import PageLoader from './components/PageLoader'; -import useStickyElement from './components/useStickyElement'; import httpRequestErrorHandler from './handler/error/httpRequestErrorHandler'; prestashop.pageLazyLoad = new PageLazyLoad({ @@ -36,35 +35,11 @@ prestashop.pageLoader = new PageLoader(); prestashop.on('handleError', httpRequestErrorHandler); -function accLinksTriggerActive() { - const url = window.location.pathname; - $('.js-customer-links a').each((i, el) => { - const $el = $(el); - - if ($el.attr('href').indexOf(url) !== -1) { - $el.addClass('active'); - } - }); -} - -function initStickyHeader() { - const header = document.querySelector('.js-header-top'); - const headerWrapper = document.querySelector('.js-header-top-wrapper'); - - if (header && headerWrapper) { - useStickyElement(header, headerWrapper); - } -} $(() => { - const { init: initTopMenu } = useTopMenu('.js-main-menu'); - - initStickyHeader(); - accLinksTriggerActive(); Form.init(); bsCustomFileInput.init(); usePasswordPolicy('.field-password-policy'); - initTopMenu(); $('.js-select-link').on('change', ({ target }) => { window.location.href = $(target).val();