REFACTOR: move widget to an ember component (#34)

This commit is contained in:
Kris
2023-08-03 12:05:58 -04:00
committed by GitHub
parent c344d0f519
commit 71c9104e48
6 changed files with 94 additions and 130 deletions
@@ -0,0 +1,25 @@
{{#if this.shouldShow}}
<ul
class="custom-header-links
{{if @scrolledTopic 'custom-header-links--hide-links'}}"
>
{{#each this.links as |link|}}
<li
class="headerLink
{{link.device}}
{{link.keepOnScrollClass}}
{{link.locale}}
{{link.linkClass}}
{{link.keepOnScroll}}"
>
<a
title={{link.anchorAttributes.title}}
href={{link.anchorAttributes.href}}
target={{link.anchorAttributes.target}}
>
{{link.linkText}}
</a>
</li>
{{/each}}
</ul>
{{/if}}
@@ -0,0 +1,45 @@
import Component from "@glimmer/component";
import { dasherize } from "@ember/string";
export default class CustomHeaderLinks extends Component {
get shouldShow() {
return settings.Custom_header_links?.length > 0;
}
get links() {
return settings.Custom_header_links.split("|").reduce((result, item) => {
let [
linkText,
linkTitle,
linkHref,
device,
target = "",
keepOnScroll,
locale,
] = item.split(",").map((s) => s.trim());
if (!linkText || (locale && document.documentElement.lang !== locale)) {
return result;
}
const linkClass = `${dasherize(linkText)}-custom-header-links`; // legacy name
const anchorAttributes = {
title: linkTitle,
href: linkHref,
target: target === "self" ? "" : "_blank",
};
result.push({
device: `headerLink--${device}`,
keepOnScroll: `headerLink--${keepOnScroll}`,
locale: `headerLink--${locale}`,
linkClass,
anchorAttributes,
linkText,
});
return result;
}, []);
}
}