2018-06-24 14:54:36 +08:00
|
|
|
<script type="text/discourse-plugin" version="0.8.20">
|
2019-05-04 22:14:27 +08:00
|
|
|
const customHeaderLinks = settings.Custom_header_links;
|
2018-06-24 14:54:36 +08:00
|
|
|
|
2019-05-04 22:14:27 +08:00
|
|
|
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, '-')}`;
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2018-06-24 14:54:36 +08:00
|
|
|
|
|
|
|
api.decorateWidget("header-buttons:before", helper => {
|
|
|
|
return helper.h(
|
2019-05-04 22:14:27 +08:00
|
|
|
"ul.custom-header-links", headerLinks
|
2018-06-24 14:54:36 +08:00
|
|
|
);
|
|
|
|
});
|
2018-12-08 13:13:54 +08:00
|
|
|
|
2019-05-04 22:14:27 +08:00
|
|
|
api.decorateWidget("home-logo:after", helper => {
|
|
|
|
let titleVisible = helper.attrs.minimized;
|
|
|
|
if (titleVisible) {
|
|
|
|
$(".d-header").addClass("hide-menus");
|
|
|
|
} else {
|
|
|
|
$(".d-header").removeClass("hide-menus");
|
|
|
|
}
|
|
|
|
});
|
2018-06-24 14:54:36 +08:00
|
|
|
</script>
|