Skip to content

Commit

Permalink
Refactoring after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4de committed Feb 18, 2025
1 parent 92f3e4d commit 5c99476
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { loadFragment } from '../fragment/fragment.js';

import renderAuthCombine from './renderAuthCombine.js';
import { renderAuthDropdown } from './renderAuthDropdown.js';
import { parseUrlHashTags, removeLink } from '../../scripts/hashTagParser.js';

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

parseUrlHashTags(
'nav',
(el, namespace, value) => {
if (namespace === 'display_for_') {
if (value === 'desktop_only' && !isDesktop.matches) {
removeLink(el);
}
if (value === 'mobile_only' && isDesktop.matches) {
removeLink(el);
}
}
},
);

renderAuthCombine(
navSections,
() => !isDesktop.matches && toggleMenu(nav, navSections, false),
Expand Down
5 changes: 3 additions & 2 deletions blocks/targeted-block/targeted-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ const updateTargetedBlocksVisibility = async () => {
parseUrlHashTags(
'main',
(el, namespace, value) => {
const segments = activeRules.customerSegments.map((s) => s.name.toLowerCase());
if (value.startsWith('segment')) {
const [prefix, segmentToMatch] = [...value.split('_')];
if (!activeRules.customerSegments.map((segment) => segment.name).includes(segmentToMatch)) {
const [_prefix, segment] = [...value.split('_')];
if (!segments.includes(segment.toLowerCase())) {
hideLink(el);
} else {
showLink(el);
Expand Down

0 comments on commit 5c99476

Please sign in to comment.