Skip to content

Commit

Permalink
top menu removed jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Oct 9, 2023
1 parent 8b229ed commit e8799a4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 85 deletions.
30 changes: 0 additions & 30 deletions _dev/js/theme/components/TopMenu.js

This file was deleted.

48 changes: 0 additions & 48 deletions _dev/js/theme/components/cart/block-cart.js

This file was deleted.

46 changes: 46 additions & 0 deletions _dev/js/theme/components/useTopMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import useEvent from './event/useEvent';

const useTopMenu = (selector) => {
const { on, off } = useEvent();
const menuElement = document.querySelector(selector);
const DOM_SELECTORS = {
SUB_ELEMENTS: '.main-menu__item--top',
SUB_MENU: '.main-menu__sub',
};
const ITEM_ACTIVE = 'main-menu__item--active';


Check failure on line 12 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

More than 1 blank line not allowed
const toggleSubMenu = (e) => {
const { currentTarget } = e;
const { SUB_MENU } = DOM_SELECTORS;
const expanded = currentTarget.getAttribute('aria-expanded');
const isExpanded = expanded && expanded.toLowerCase() === 'true';
const subMenu = currentTarget.querySelector(SUB_MENU);

currentTarget.classList.toggle(ITEM_ACTIVE);

if (subMenu) {
currentTarget.setAttribute('aria-expanded', !isExpanded);

subMenu.setAttribute('aria-hidden', isExpanded);
subMenu.setAttribute('aria-expanded', !isExpanded);

Check failure on line 26 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Block must not be padded by blank lines

}
}

Check failure on line 29 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Missing semicolon

const init = () => {
debugger

Check failure on line 32 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Unexpected 'debugger' statement

Check failure on line 32 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Missing semicolon
const { SUB_ELEMENTS } = DOM_SELECTORS;

off(menuElement, 'mouseenter', SUB_ELEMENTS, toggleSubMenu);
off(menuElement, 'mouseleave', SUB_ELEMENTS, toggleSubMenu);
on(menuElement, 'mouseenter', SUB_ELEMENTS, toggleSubMenu);
on(menuElement, 'mouseleave', SUB_ELEMENTS, toggleSubMenu);
}

Check failure on line 39 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Missing semicolon

return {
init

Check failure on line 42 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Missing trailing comma
}

Check failure on line 43 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Missing semicolon
}

Check failure on line 44 in _dev/js/theme/components/useTopMenu.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

Missing semicolon

export default useTopMenu;
11 changes: 4 additions & 7 deletions _dev/js/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import EventEmitter from 'events';
import '@js/theme/core';

import '@js/theme/vendors/bootstrap/bootstrap-imports';
import 'bootstrap-touchspin';
import 'jquery-hoverintent';
import '@js/theme/components/dynamic-bootstrap-components';
import bsCustomFileInput from 'bs-custom-file-input';
import '@js/theme/components/sliders';
import '@js/theme/components/responsive';
import '@js/theme/components/customer';
import '@js/theme/components/quickview';
import '@js/theme/components/product';
import '@js/theme/components/cart/block-cart';
import useTopMenu from './components/useTopMenu';

Check failure on line 15 in _dev/js/theme/index.js

View workflow job for this annotation

GitHub Actions / Code quality - ESLint

`./components/useTopMenu` import should occur after import of `@js/theme/components/useStickyElement`
/* eslint-enable */

import prestashop from 'prestashop';
Expand All @@ -26,7 +24,6 @@ for (const i in EventEmitter.prototype) {
}
import usePasswordPolicy from '@js/theme/components/password/usePasswordPolicy';
import Form from '@js/theme/components/form';
import TopMenu from '@js/theme/components/TopMenu';
import PageLazyLoad from '@js/theme/components/Lazyload';
import PageLoader from '@js/theme/components/PageLoader';
import useStickyElement from '@js/theme/components/useStickyElement';
Expand Down Expand Up @@ -61,14 +58,14 @@ function initStickyHeader() {
}

$(() => {
const { init: initTopMenu } = useTopMenu('.js-main-menu');

initStickyHeader();
accLinksTriggerActive();
Form.init();
bsCustomFileInput.init();
const topMenu = new TopMenu('#_desktop_top_menu .js-main-menu');
usePasswordPolicy('.field-password-policy');

topMenu.init();
initTopMenu();

$('.js-select-link').on('change', ({ target }) => {
window.location.href = $(target).val();
Expand Down

0 comments on commit e8799a4

Please sign in to comment.