Allow customizing theme for embeds

This commit is contained in:
2021-11-28 15:58:04 +01:00
parent 90519b0f81
commit c8f220c36e
2 changed files with 77 additions and 29 deletions

View File

@@ -29,15 +29,26 @@ let update_file = () => {
} }
} }
let style = ""
let set_style = s => {
style = s
embed_iframe()
}
let embed_iframe = () => { let embed_iframe = () => {
tab = "iframe" tab = "iframe"
let style_part = ""
if (style) {
style_part = "&style="+style
}
let url let url
if (list.id === "") { if (list.id === "") {
// Not a list, use file ID // Not a list, use file ID
url = domain_url()+"/u/"+file.id+"?embed" url = domain_url()+"/u/"+file.id+"?embed"+style_part
} else { } else {
url = domain_url()+"/l/"+list.id+"?embed"+window.location.hash url = domain_url()+"/l/"+list.id+"?embed"+style_part+window.location.hash
} }
embed_html = `<iframe ` + embed_html = `<iframe ` +
@@ -120,6 +131,41 @@ const example = () => {
</button> </button>
{/if} {/if}
</div> </div>
{#if tab === "iframe"}
<h3>Appearance</h3>
<p>
You can change the pixeldrain theme for your embedded file. Try the
available themes <a href="/appearance">here</a>.
</p>
<div class="center">
<button class:button_highlight={style===""} on:click={() => {set_style("")}}>
Default
</button>
<button class:button_highlight={style==="classic"} on:click={() => {set_style("classic")}}>
Classic
</button>
<button class:button_highlight={style==="solarized_dark"} on:click={() => {set_style("solarized_dark")}}>
Solarized
</button>
<button class:button_highlight={style==="maroon"} on:click={() => {set_style("maroon")}}>
Maroon
</button>
<button class:button_highlight={style==="hacker"} on:click={() => {set_style("hacker")}}>
Hacker
</button>
<button class:button_highlight={style==="canta"} on:click={() => {set_style("canta")}}>
Canta
</button>
<button class:button_highlight={style==="arc"} on:click={() => {set_style("arc")}}>
Arc
</button>
<button class:button_highlight={style==="deepsea"} on:click={() => {set_style("deepsea")}}>
Deep sea
</button>
</div>
{/if}
<h3>Code</h3> <h3>Code</h3>
<p> <p>
Put this code in your website to embed the file. Put this code in your website to embed the file.

View File

@@ -5,39 +5,41 @@ import (
"net/http" "net/http"
) )
func userStyle(r *http.Request) (style pixeldrainStyleSheet) { func userStyle(r *http.Request) pixeldrainStyleSheet {
var selectedStyle pixeldrainStyleSheet // Get the chosen style from the URL
var style = r.URL.Query().Get("style")
if cookie, err := r.Cookie("style"); err != nil { // If the URL style was empty use the cookie value
selectedStyle = defaultPixeldrainStyle if style == "" {
} else { if cookie, err := r.Cookie("style"); err == nil {
switch cookie.Value { style = cookie.Value
}
}
switch style {
case "classic": case "classic":
selectedStyle = pixeldrainClassicStyle return pixeldrainClassicStyle
case "solarized_dark": case "solarized_dark":
selectedStyle = solarizedDarkStyle return solarizedDarkStyle
case "sunny": case "sunny":
selectedStyle = sunnyPixeldrainStyle return sunnyPixeldrainStyle
case "maroon": case "maroon":
selectedStyle = maroonStyle return maroonStyle
case "hacker": case "hacker":
selectedStyle = hackerStyle return hackerStyle
case "canta": case "canta":
selectedStyle = cantaPixeldrainStyle return cantaPixeldrainStyle
case "arc": case "arc":
selectedStyle = arcPixeldrainStyle return arcPixeldrainStyle
case "deepsea": case "deepsea":
selectedStyle = deepseaPixeldrainStyle return deepseaPixeldrainStyle
case "default": case "default":
fallthrough // use default case fallthrough // use default case
default: default:
selectedStyle = defaultPixeldrainStyle return defaultPixeldrainStyle
} }
} }
return selectedStyle
}
type pixeldrainStyleSheet struct { type pixeldrainStyleSheet struct {
TextColor hsl TextColor hsl
InputColor hsl // Buttons, text fields InputColor hsl // Buttons, text fields