Skip to content

Commit

Permalink
better handle undefined and string boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
JugglerX committed Nov 12, 2020
1 parent ca2517f commit f3e37cf
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/supporting-files/stackbit-banner.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ module.exports = `<div id="theme-bar" class="theme-bar theme-bar-fixed theme-bar
themebar.classList.remove("theme-bar-hidden");
}
let themeBarProperties = {
themeBarNewSiteLinkParams: {}
};
let themeBarProperties = {};
const demo = searchParams.get("demo");
if (demo && themeBarConfig) {
Expand All @@ -85,6 +83,9 @@ module.exports = `<div id="theme-bar" class="theme-bar theme-bar-fixed theme-bar
if (searchParams.get("themeBarNewSiteLink")) { themeBarProperties.themeBarNewSiteLink = searchParams.get("themeBarNewSiteLink") }
if (searchParams.get("themeBarNewSiteLinkParams")) {
// themeBarNewSiteLinkParams url params are merged with config values
if (!themeBarProperties.themeBarNewSiteLinkParams) {
themeBarProperties.themeBarNewSiteLinkParams = {}
}
const params = JSON.parse(searchParams.get("themeBarNewSiteLinkParams"))
for (const [key, value] of Object.entries(params)) {
themeBarProperties.themeBarNewSiteLinkParams[key] = value;
Expand All @@ -104,21 +105,17 @@ module.exports = `<div id="theme-bar" class="theme-bar theme-bar-fixed theme-bar
}
// Update fork button title or visibility
if (props.themeBarFork) {
if (props.themeBarFork === "false") {
uiThemeBarForkLink.style.display = "none";
} else {
uiThemeBarForkName.textContent = props.themeBarFork;
}
if (props.themeBarFork === "false" || props.themeBarFork === false) {
uiThemeBarForkLink.style.display = "none";
} else if (props.themeBarFork) {
uiThemeBarForkName.textContent = props.themeBarFork;
}
// Update create site button title or visibility
if (props.themeBarNewSite) {
if (props.themeBarNewSite === "false") {
uiThemeBarNewSiteLink.style.display = "none";
} else {
uiThemeBarNewSiteName.textContent = props.themeBarNewSite;
}
if (props.themeBarNewSite === "false" || props.themeBarNewSite === false) {
uiThemeBarNewSiteLink.style.display = "none";
} else if (props.themeBarNewSite) {
uiThemeBarNewSiteName.textContent = props.themeBarNewSite;
}
// Update button links and pass through extra query params
Expand All @@ -141,8 +138,10 @@ module.exports = `<div id="theme-bar" class="theme-bar theme-bar-fixed theme-bar
uiThemeBarForkLink.setAttribute("href", newForkLink.toString());
};
updateThemeBar(themeBarProperties);
sessionStorage.setItem("themeBarProperties", JSON.stringify(themeBarProperties));
if (Object.keys(themeBarProperties).length) {
updateThemeBar(themeBarProperties);
sessionStorage.setItem("themeBarProperties", JSON.stringify(themeBarProperties));
}
document.querySelector("#remove-theme-bar").addEventListener("click", function(e) {
e.preventDefault();
Expand Down

0 comments on commit f3e37cf

Please sign in to comment.