Skip to content

Commit 5c99476

Browse files
committed
Refactoring after merge
1 parent 92f3e4d commit 5c99476

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

blocks/header/header.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { loadFragment } from '../fragment/fragment.js';
1111

1212
import renderAuthCombine from './renderAuthCombine.js';
1313
import { renderAuthDropdown } from './renderAuthDropdown.js';
14+
import { parseUrlHashTags, removeLink } from '../../scripts/hashTagParser.js';
1415

1516
// media query match that indicates mobile/tablet width
1617
const isDesktop = window.matchMedia('(min-width: 900px)');
@@ -326,6 +327,20 @@ export default async function decorate(block) {
326327
navWrapper.append(nav);
327328
block.append(navWrapper);
328329

330+
parseUrlHashTags(
331+
'nav',
332+
(el, namespace, value) => {
333+
if (namespace === 'display_for_') {
334+
if (value === 'desktop_only' && !isDesktop.matches) {
335+
removeLink(el);
336+
}
337+
if (value === 'mobile_only' && isDesktop.matches) {
338+
removeLink(el);
339+
}
340+
}
341+
},
342+
);
343+
329344
renderAuthCombine(
330345
navSections,
331346
() => !isDesktop.matches && toggleMenu(nav, navSections, false),

blocks/targeted-block/targeted-block.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ const updateTargetedBlocksVisibility = async () => {
6666
parseUrlHashTags(
6767
'main',
6868
(el, namespace, value) => {
69+
const segments = activeRules.customerSegments.map((s) => s.name.toLowerCase());
6970
if (value.startsWith('segment')) {
70-
const [prefix, segmentToMatch] = [...value.split('_')];
71-
if (!activeRules.customerSegments.map((segment) => segment.name).includes(segmentToMatch)) {
71+
const [_prefix, segment] = [...value.split('_')];
72+
if (!segments.includes(segment.toLowerCase())) {
7273
hideLink(el);
7374
} else {
7475
showLink(el);

0 commit comments

Comments
 (0)