Changing themes should work without JavaScript now.

This commit is contained in:
Azareal 2019-10-27 18:58:35 +10:00
parent 1189967f2b
commit 7b09a3aff5
3 changed files with 8 additions and 6 deletions

View File

@ -851,12 +851,12 @@ function mainInit(){
});
$("#themeSelectorSelect").change(function(){
console.log("Changing the theme to " + this.options[this.selectedIndex].getAttribute("val"));
console.log("Changing the theme to " + this.options[this.selectedIndex].getAttribute("value"));
$.ajax({
url: this.form.getAttribute("action") + "?s=" + me.User.S,
type: "POST",
dataType: "json",
data: { "newTheme": this.options[this.selectedIndex].getAttribute("val"), js: "1" },
data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 },
error: ajaxError,
success: function (data, status, xhr) {
console.log("Theme successfully switched");

View File

@ -8,6 +8,7 @@ import (
"strconv"
"strings"
"time"
//"fmt"
c "github.com/Azareal/Gosora/common"
"github.com/Azareal/Gosora/common/phrases"
@ -85,7 +86,8 @@ func ChangeTheme(w http.ResponseWriter, r *http.Request, user c.User) c.RouteErr
//headerLite, _ := SimpleUserCheck(w, r, &user)
// TODO: Rename js to something else, just in case we rewrite the JS side in WebAssembly?
js := r.PostFormValue("js") == "1"
newTheme := c.SanitiseSingleLine(r.PostFormValue("newTheme"))
newTheme := c.SanitiseSingleLine(r.PostFormValue("theme"))
//fmt.Printf("newTheme: %+v\n", newTheme)
theme, ok := c.Themes[newTheme]
if !ok || theme.HideFromThemes {

View File

@ -12,8 +12,8 @@
{{if .CurrentUser.IsAdmin}}<div title="start to before tmpl" class="elapsed">{{.Header.Elapsed1}}</div><div title="start to footer" class="elapsed">{{elapsed .Header.StartedAt}}</div>{{end}}
<form action="/theme/" method="post">
<div id="themeSelector">
<select id="themeSelectorSelect" name="themeSelector" aria-label="{{lang "footer_theme_selector_aria"}}">{{range .Header.Themes}}{{if not .HideFromThemes}}
<option val="{{.Name}}"{{if eq $.Header.Theme.Name .Name}} selected{{end}}>{{.FriendlyName}}</option>
<select id="themeSelectorSelect" name="theme" aria-label="{{lang "footer_theme_selector_aria"}}">{{range .Header.Themes}}{{if not .HideFromThemes}}
<option value="{{.Name}}"{{if eq $.Header.Theme.Name .Name}} selected{{end}}>{{.FriendlyName}}</option>
{{end}}{{end}}</select>
<noscript><input type="submit" /></noscript>
</div>