Tosin Sonuyi 41bc9b1ae1
DEV: make class name more unique to prevent collisions (#10)
naming a nav link "Directory" for instance collides with a core css class name
2020-08-04 22:53:27 +08:00

67 lines
1.7 KiB
HTML

<script type="text/discourse-plugin" version="0.8.20">
const customHeaderLinks = settings.Custom_header_links;
const linksPosition = (settings.links_position === "right") ? "header-buttons:before" : "home-logo:after";
if (!customHeaderLinks.length) return;
const h = require("virtual-dom").h;
const headerLinks = [];
customHeaderLinks.split("|").map(i => {
const seg = $.map(i.split(","), $.trim);
const linkText = seg[0];
const linkTitle = seg[1];
const linkHref = seg[2];
const deviceClass = `.${seg[3]}`;
const linkTarget = seg[4] === "self" ? "" : "_blank";
const keepOnScrollClass = seg[5] === "keep" ? ".keep" : "";
const linkClass = `.${linkText.trim().toLowerCase().replace(/\s/gi, '-')}-custom-header-links`;
if (!linkTarget) {
headerLinks.push(
h(
`li.headerLink${deviceClass}${keepOnScrollClass}${linkClass}`,
h(
"a",
{
title: linkTitle,
href: linkHref
},
linkText
)
)
);
} else {
headerLinks.push(
h(
`li.headerLink${deviceClass}${keepOnScrollClass}${linkClass}`,
h(
"a",
{
title: linkTitle,
href: linkHref,
target: linkTarget
},
linkText
)
)
);
}
});
api.decorateWidget(linksPosition, helper => {
return helper.h(
"ul.custom-header-links", headerLinks
);
});
api.decorateWidget("home-logo:after", helper => {
let titleVisible = helper.attrs.minimized;
if (titleVisible) {
$(".d-header").addClass("hide-menus");
} else {
$(".d-header").removeClass("hide-menus");
}
});
</script>