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(){ $("#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({ $.ajax({
url: this.form.getAttribute("action") + "?s=" + me.User.S, url: this.form.getAttribute("action") + "?s=" + me.User.S,
type: "POST", type: "POST",
dataType: "json", dataType: "json",
data: { "newTheme": this.options[this.selectedIndex].getAttribute("val"), js: "1" }, data: { "theme": this.options[this.selectedIndex].getAttribute("value"), js: 1 },
error: ajaxError, error: ajaxError,
success: function (data, status, xhr) { success: function (data, status, xhr) {
console.log("Theme successfully switched"); console.log("Theme successfully switched");

View File

@ -8,6 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
//"fmt"
c "github.com/Azareal/Gosora/common" c "github.com/Azareal/Gosora/common"
"github.com/Azareal/Gosora/common/phrases" "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) //headerLite, _ := SimpleUserCheck(w, r, &user)
// TODO: Rename js to something else, just in case we rewrite the JS side in WebAssembly? // TODO: Rename js to something else, just in case we rewrite the JS side in WebAssembly?
js := r.PostFormValue("js") == "1" 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] theme, ok := c.Themes[newTheme]
if !ok || theme.HideFromThemes { 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}} {{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"> <form action="/theme/" method="post">
<div id="themeSelector"> <div id="themeSelector">
<select id="themeSelectorSelect" name="themeSelector" aria-label="{{lang "footer_theme_selector_aria"}}">{{range .Header.Themes}}{{if not .HideFromThemes}} <select id="themeSelectorSelect" name="theme" 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> <option value="{{.Name}}"{{if eq $.Header.Theme.Name .Name}} selected{{end}}>{{.FriendlyName}}</option>
{{end}}{{end}}</select> {{end}}{{end}}</select>
<noscript><input type="submit" /></noscript> <noscript><input type="submit" /></noscript>
</div> </div>
@ -26,4 +26,4 @@
</div> </div>
</div> </div>
</body> </body>
</html> </html>