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,37 +5,39 @@ 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
case "classic":
selectedStyle = pixeldrainClassicStyle
case "solarized_dark":
selectedStyle = solarizedDarkStyle
case "sunny":
selectedStyle = sunnyPixeldrainStyle
case "maroon":
selectedStyle = maroonStyle
case "hacker":
selectedStyle = hackerStyle
case "canta":
selectedStyle = cantaPixeldrainStyle
case "arc":
selectedStyle = arcPixeldrainStyle
case "deepsea":
selectedStyle = deepseaPixeldrainStyle
case "default":
fallthrough // use default case
default:
selectedStyle = defaultPixeldrainStyle
} }
} }
return selectedStyle switch style {
case "classic":
return pixeldrainClassicStyle
case "solarized_dark":
return solarizedDarkStyle
case "sunny":
return sunnyPixeldrainStyle
case "maroon":
return maroonStyle
case "hacker":
return hackerStyle
case "canta":
return cantaPixeldrainStyle
case "arc":
return arcPixeldrainStyle
case "deepsea":
return deepseaPixeldrainStyle
case "default":
fallthrough // use default case
default:
return defaultPixeldrainStyle
}
} }
type pixeldrainStyleSheet struct { type pixeldrainStyleSheet struct {