Skip to content

Commit d6a6ca2

Browse files
committed
Refactoring
1 parent fe9710f commit d6a6ca2

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

.eslintrc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ module.exports = {
1515
'linebreak-style': ['error', 'unix'], // enforce unix linebreaks
1616
'no-param-reassign': [2, { props: false }], // allow modifying properties of param
1717
'no-use-before-define': [2, { functions: false }],
18-
// 'no-console': [
19-
// 'error',
20-
// {
21-
// allow: ['warn', 'error', 'info', 'debug'],
22-
// },
23-
// ],
18+
'no-console': [
19+
'error',
20+
{
21+
allow: ['warn', 'error', 'info', 'debug'],
22+
},
23+
],
2424
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
2525
},
2626
};

blocks/header/header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { renderAuthDropdown } from './renderAuthDropdown.js';
1414

1515
import {
1616
isDesktop,
17-
parseNavSections,
17+
parseUrlHashTags,
1818
toggleAllNavSections,
1919
toggleMenu,
2020
} from './menu/menu.js';
@@ -65,7 +65,7 @@ export default async function decorate(block) {
6565
}
6666
});
6767
});
68-
parseUrlHashTags();
68+
parseUrlHashTags(navSections);
6969
}
7070

7171
const navTools = nav.querySelector('.nav-tools');

blocks/header/menu/menu.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,43 @@ function toggleMenu(nav, navSections, forceExpanded = null) {
104104
}
105105
}
106106

107+
/**
108+
* Applies parsed hash tags based on conditions
109+
*
110+
* @param aElement
111+
* @param hashTags
112+
*/
113+
function applyCondition(aElement, hashTags) {
114+
hashTags.forEach((hashTag) => {
115+
const { namespace, value } = { ...hashTag };
116+
117+
if (namespace === 'display_for_') {
118+
if (value === 'desktop_only' && !isDesktop) {
119+
aElement.parentNode.removeChild(aElement);
120+
}
121+
if (value === 'mobile_only' && isDesktop) {
122+
aElement.parentNode.removeChild(aElement);
123+
}
124+
}
125+
});
126+
}
127+
107128
/**
108129
* Parses nav fragment; disable visible elements based on hash tags
109130
*
110131
* @param navSections
111132
* @returns {*}
112133
*/
113-
function parseUrlHashTags() {
134+
function parseUrlHashTags(navSections) {
114135
const aElements = navSections.querySelectorAll('li > a');
115136

116137
aElements.forEach((aElement) => {
117138
const link = aElement.href;
118139
if (link) {
119140
const hashTags = parseHashTag(link);
120141
console.table(`Hash tags for ${link}`, hashTags);
121-
// liElement.parentNode.removeChild(liElement);
142+
143+
applyCondition(aElement, hashTags);
122144
}
123145
});
124146
}

0 commit comments

Comments
 (0)