1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-03 19:56:22 -07:00

Use stylesheet cookie if set

This commit is contained in:
user.email 2018-12-01 16:41:17 -08:00
parent 77b109770a
commit 8021743c82
8 changed files with 48 additions and 26 deletions

View file

@ -371,6 +371,7 @@ input.config-text {
} }
.lightbox-footer { .lightbox-footer {
background-color: #CDCDCD;
bottom: 5%; bottom: 5%;
clear: both; clear: both;
left: 16px; left: 16px;

View file

@ -181,7 +181,6 @@ function showMessage(msg) {
lightbox_css_added = true; lightbox_css_added = true;
} }
$jq(document.body).prepend("<div class=\"lightbox-bg\"></div><div class=\"lightbox-msg\">"+msg+"<br /><button class=\"lightbox-msg-ok\" style=\"float: right; margin-top:8px;\">OK</button></div>"); $jq(document.body).prepend("<div class=\"lightbox-bg\"></div><div class=\"lightbox-msg\">"+msg+"<br /><button class=\"lightbox-msg-ok\" style=\"float: right; margin-top:8px;\">OK</button></div>");
console.log($jq(".lightbox-msg").width());
var centeroffset = parseInt($jq(".lightbox-msg").css("transform-origin").replace("px",""),10)+$jq(".lightbox-msg").width()/2 var centeroffset = parseInt($jq(".lightbox-msg").css("transform-origin").replace("px",""),10)+$jq(".lightbox-msg").width()/2
$jq(".lightbox-msg").css({ $jq(".lightbox-msg").css({
@ -342,7 +341,7 @@ function isFrontPage() {
} }
function setCookie(name,value) { function setCookie(name,value) {
document.cookie = name + "=" + escape(value) document.cookie = name + "=" + escape(value) + ";path=" + webroot;
} }
function getCookie(name) { function getCookie(name) {
@ -406,15 +405,15 @@ var Setting = function(id, text, type, defaultVal, callback, options) {
this.text = text; this.text = text;
this.type = type; // text, textarea, checkbox, select this.type = type; // text, textarea, checkbox, select
this.defaultVal = defaultVal; this.defaultVal = defaultVal;
if(this.getCookie() === undefined) this.setCookie(this.defaultVal); if(!this.getCookie()) this.setCookie(this.defaultVal);
if(this.type == "select") this.options = options; if(this.type == "select") this.options = options;
if(!callback) this.callback = function() {}; if(!callback) this.callback = function() {};
else this.callback = callback; else this.callback = callback;
} }
Setting.prototype.onSave == function(newVal) { Setting.prototype.save = function(newVal) {
this.callback();
setCookie(this.id, newVal); setCookie(this.id, newVal);
this.callback();
} }
Setting.prototype.getCookie = function() { Setting.prototype.getCookie = function() {
@ -449,6 +448,7 @@ Setting.prototype.renderHTML = function() {
if(this.getCookie() == this.options[o].val) html += "selected=\"" + this.getCookie() + "\""; if(this.getCookie() == this.options[o].val) html += "selected=\"" + this.getCookie() + "\"";
html += ">" + this.options[o].text + "</option>"; html += ">" + this.options[o].text + "</option>";
} }
html += "</select>";
break; break;
case "textarea": case "textarea":
html = "<textarea id=\"" + this.id + "\" name=\"" + this.id + "\">" + this.getCookie() + "</textarea>"; html = "<textarea id=\"" + this.id + "\" name=\"" + this.id + "\">" + this.getCookie() + "</textarea>";
@ -461,11 +461,12 @@ Setting.prototype.renderHTML = function() {
} }
function initSettings() { function initSettings() {
var settings_html = "<table width=\"100%\"><colgroup><col span=\"1\" width=\"50%\"><col span=\"1\" width=\"50%\"></colgroup>"; var settings_html = "<div id=\"settings-container\" style=\"overflow:auto\"><table width=\"100%\"><colgroup><col span=\"1\" width=\"50%\"><col span=\"1\" width=\"50%\"></colgroup>";
settings.push( settings.push(
new Setting("style", "Style", "select", "pipes.css", function() { new Setting("style", "Style", "select", defaultStyle, function() {
console.log(this.getCookie());
document.getElementById("theme").setAttribute("href", webroot + "css/" + this.getCookie());
}, []), }, []),
new Setting("pintopbar", "Pin top bar", "checkbox", true), new Setting("pintopbar", "Pin top bar", "checkbox", true),
new Setting("enableposthover", "Preview post on hover", "checkbox", true), new Setting("enableposthover", "Preview post on hover", "checkbox", true),
@ -481,26 +482,37 @@ function initSettings() {
settings_html += "<tr><td><b>" + setting.text + ":</b></td><td>" + setting.renderHTML() + "</td></tr>"; settings_html += "<tr><td><b>" + setting.text + ":</b></td><td>" + setting.renderHTML() + "</td></tr>";
} }
settings_html += "</table><div class=\"lightbox-footer\"><hr /><button id=\"save-settings-button\">Save Settings</button></div>"; settings_html += "</table></div><div class=\"lightbox-footer\"><hr /><button id=\"save-settings-button\">Save Settings</button></div>";
settings_menu = new TopBarButton("Settings",function(){ settings_menu = new TopBarButton("Settings",function(){
showLightBox("Settings",settings_html,null) showLightBox("Settings",settings_html,null)
$jq("button#save-settings-button").click(function() { $jq("button#save-settings-button").click(function() {
for(var s = 0; s < settings.length; s++) { for(var s = 0; s < settings.length; s++) {
var val = settings[s].getVal(); var val = settings[s].getVal();
if(val !== undefined) settings[s].setCookie(val); settings[s].save(val);
} }
}); });
}); });
} }
$jq(document).ready(function() { $jq(document).ready(function() {
var style = getCookie("style");
if(style === undefined) style = defaultStyle;
var themeElem = document.getElementById("theme");
if(themeElem) themeElem.setAttribute("href", webroot + "css/" + style);
board = location.pathname.substring(1,location.pathname.indexOf("/",1)) board = location.pathname.substring(1,location.pathname.indexOf("/",1))
current_staff = getStaff() current_staff = getStaff()
initCookies(); initCookies();
topbar = $jq("div#topbar"); topbar = $jq("div#topbar");
if(getCookie("pintopbar") == "false") {
topbar.css({
"position": "absolute",
"top": "0px",
"padding-left": "0px",
"padding-right": "0px",
});
}
initSettings(); initSettings();
watched_threads_btn = new TopBarButton("WT",function() {}); watched_threads_btn = new TopBarButton("WT",function() {});

View file

@ -31,6 +31,7 @@
} }
.lightbox-footer { .lightbox-footer {
background-color:#CDCDCD;
bottom:5%; bottom:5%;
clear:both; clear:both;
left:16px; left:16px;

View file

@ -2,11 +2,12 @@
<html> <html>
<head> <head>
<title>Banned</title> <title>Banned</title>
<link rel="shortcut icon" href="/favicon.png"> <link rel="shortcut icon" href="{{.config.SiteWebfolder}}favicon.png">
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/global.css" /> <link rel="stylesheet" href="{{.config.SiteWebfolder}}css/global.css" />
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/{{$.config.DefaultStyle}}" /> <link id="theme" rel="stylesheet" href="{{.config.SiteWebfolder}}css/{{.config.DefaultStyle}}" />
<script type="text/javascript"> <script type="text/javascript">
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}]; var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
var defaultStyle = "{{.config.DefaultStyle}}";
var webroot = "{{.config.SiteWebfolder}}" var webroot = "{{.config.SiteWebfolder}}"
</script> </script>
<script type="text/javascript" src="/javascript/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="/javascript/jquery-3.3.1.min.js"></script>

View file

@ -7,14 +7,15 @@
<script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}]; var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
var defaultStyle = "{{.config.DefaultStyle}}";
var webroot = "{{.config.SiteWebfolder}}" var webroot = "{{.config.SiteWebfolder}}"
</script> </script>
<script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/gochan.js"></script> <script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/gochan.js"></script>
<script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/manage.js"></script> <script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/manage.js"></script>
<link rel="stylesheet" href="/css/global.css" /> <link rel="stylesheet" href="{{.config.SiteWebfolder}}css/global.css" />
<link rel="stylesheet" href="/css/{{.config.DefaultStyle}}" /> <link id="theme" rel="stylesheet" href="{{.config.SiteWebfolder}}css/{{.config.DefaultStyle}}" />
<link rel="shortcut icon" href="/favicon.png"> <link rel="shortcut icon" href="{{.config.SiteWebfolder}}favicon.png">
</head> </head>
<body> <body>
<div id="topbar">{{range $i, $board := .boards}} <div id="topbar">{{range $i, $board := .boards}}

View file

@ -13,6 +13,7 @@
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}]; var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
var defaultStyle = "{{$.config.DefaultStyle}}";
var webroot = "{{$.config.SiteWebfolder}}"; var webroot = "{{$.config.SiteWebfolder}}";
var thread_type = "thread"; var thread_type = "thread";
@ -22,9 +23,9 @@
</script> </script>
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/gochan.js"></script> <script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/gochan.js"></script>
<script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/manage.js"></script> <script type="text/javascript" src="{{$.config.SiteWebfolder}}javascript/manage.js"></script>
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/global.css" /> <link rel="stylesheet" href="{{.config.SiteWebfolder}}css/global.css" />
<link rel="stylesheet" href="{{$.config.SiteWebfolder}}css/{{$.config.DefaultStyle}}" /> <link id="theme" rel="stylesheet" href="{{.config.SiteWebfolder}}css/{{.config.DefaultStyle}}" />
<link rel="shortcut icon" href="{{$.config.SiteWebfolder}}favicon.png" /> <link rel="shortcut icon" href="{{.config.SiteWebfolder}}favicon.png">
</head> </head>
<body> <body>
<div id="topbar"> <div id="topbar">

View file

@ -1,9 +1,10 @@
<title>Gochan Manage page</title> <title>Gochan Manage page</title>
<link rel="stylesheet" href="{{.SiteWebfolder}}css/global.css" /> <link rel="stylesheet" href="{{.SiteWebfolder}}css/global.css" />
<link rel="stylesheet" href="{{$.SiteWebfolder}}css/{{.DefaultStyle}}" /> <link id="theme" rel="stylesheet" href="{{.SiteWebfolder}}css/{{.DefaultStyle}}" />
<link rel="shortcut icon" href="{{.SiteWebfolder}}favicon.png" /> <link rel="shortcut icon" href="{{.SiteWebfolder}}favicon.png" />
<script type="text/javascript"> <script type="text/javascript">
var styles = [{{range $ii, $style := .Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}]; var styles = [{{range $ii, $style := .Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
var defaultStyle = "{{.DefaultStyle}}";
var webroot = "{{.SiteWebfolder}}" var webroot = "{{.SiteWebfolder}}"
</script> </script>
<script type="text/javascript" src="{{.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="{{.SiteWebfolder}}javascript/jquery-3.3.1.min.js"></script>

View file

@ -7,14 +7,18 @@
<script type="text/javascript" src="/javascript/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="/javascript/jquery-3.3.1.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}]; var styles = [{{range $ii, $style := .config.Styles}}{{if gt $ii 0}}, {{end}}{Name: "{{$style.Name}}", Filename: "{{$style.Filename}}"}{{end}}];
var defaultStyle = "{{.config.DefaultStyle}}";
var webroot = "{{$.config.SiteWebfolder}}"; var webroot = "{{$.config.SiteWebfolder}}";
</script> </script>
<script type="text/javascript" src="/javascript/gochan.js"></script> <script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/gochan.js"></script>
<script type="text/javascript" src="/javascript/manage.js"></script> <script type="text/javascript" src="{{.config.SiteWebfolder}}javascript/manage.js"></script>
<link rel="stylesheet" href="/css/global/img.css" /> <link rel="stylesheet" href="{{.config.SiteWebfolder}}css/global/img.css" />
{{range $_, $style := .config.Styles}} {{range $_, $style := .config.Styles}}
<link rel="stylesheet" href="/css/{{$style.Filename}}" />{{end}} <link rel="stylesheet" href="{{.config.SiteWebfolder}}css/{{$style.Filename}}" />{{end}}
<link rel="shortcut icon" href="/favicon.png" /> <link rel="shortcut icon" href="{{.config.SiteWebfolder}}favicon.png" />
<link rel="stylesheet" href="{{.config.SiteWebfolder}}css/global.css" />
<link id="theme" rel="stylesheet" href="{{.config.SiteWebfolder}}css/{{.config.DefaultStyle}}" />
<link rel="shortcut icon" href="{{.config.SiteWebfolder}}favicon.png">
</head> </head>
<body> <body>
<header> <header>