Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4de committed Feb 17, 2025
1 parent fe9710f commit d6a6ca2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module.exports = {
'linebreak-style': ['error', 'unix'], // enforce unix linebreaks
'no-param-reassign': [2, { props: false }], // allow modifying properties of param
'no-use-before-define': [2, { functions: false }],
// 'no-console': [
// 'error',
// {
// allow: ['warn', 'error', 'info', 'debug'],
// },
// ],
'no-console': [
'error',
{
allow: ['warn', 'error', 'info', 'debug'],
},
],
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
},
};
4 changes: 2 additions & 2 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { renderAuthDropdown } from './renderAuthDropdown.js';

import {
isDesktop,
parseNavSections,
parseUrlHashTags,
toggleAllNavSections,
toggleMenu,
} from './menu/menu.js';
Expand Down Expand Up @@ -65,7 +65,7 @@ export default async function decorate(block) {
}
});
});
parseUrlHashTags();
parseUrlHashTags(navSections);
}

const navTools = nav.querySelector('.nav-tools');
Expand Down
26 changes: 24 additions & 2 deletions blocks/header/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,43 @@ function toggleMenu(nav, navSections, forceExpanded = null) {
}
}

/**
* Applies parsed hash tags based on conditions
*
* @param aElement
* @param hashTags
*/
function applyCondition(aElement, hashTags) {
hashTags.forEach((hashTag) => {
const { namespace, value } = { ...hashTag };

if (namespace === 'display_for_') {
if (value === 'desktop_only' && !isDesktop) {
aElement.parentNode.removeChild(aElement);
}
if (value === 'mobile_only' && isDesktop) {
aElement.parentNode.removeChild(aElement);
}
}
});
}

/**
* Parses nav fragment; disable visible elements based on hash tags
*
* @param navSections
* @returns {*}
*/
function parseUrlHashTags() {
function parseUrlHashTags(navSections) {
const aElements = navSections.querySelectorAll('li > a');

aElements.forEach((aElement) => {
const link = aElement.href;
if (link) {
const hashTags = parseHashTag(link);
console.table(`Hash tags for ${link}`, hashTags);

Check failure on line 141 in blocks/header/menu/menu.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
// liElement.parentNode.removeChild(liElement);

applyCondition(aElement, hashTags);
}
});
}
Expand Down

0 comments on commit d6a6ca2

Please sign in to comment.