From b153d568a093485d17a63142788ddfd462253172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 17 Aug 2016 01:52:29 -0400 Subject: [PATCH] Add a theme selector in the settings Power to the people! There is now 2 ways to set the theme: on the app config file (defaults for all users) and in the user settings. All CSS files present in the `client/themes` folder will be given as choices to the users. This is temporary (as in, temporary for a fairly long time) until we have proper theme management. --- client/index.html | 15 ++++++++++++++- client/js/lounge.js | 6 ++++++ src/server.js | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/client/index.html b/client/index.html index 74940d40..1276b99b 100644 --- a/client/index.html +++ b/client/index.html @@ -15,7 +15,7 @@ - "> + @@ -241,6 +241,19 @@ Enable colored nicknames +
+

Theme

+
+
+ + +
<% if (typeof prefetch === "undefined" || prefetch !== false) { %>

Links and URLs

diff --git a/client/js/lounge.js b/client/js/lounge.js index 2b8b0ee6..a5105f1b 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -473,6 +473,7 @@ $(function() { notifyAllMessages: false, part: true, quit: true, + theme: $("#theme").attr("href").replace(/^themes\/(.*).css$/, "$1"), // Extracts default theme name, set on the server configuration thumbnails: true, userStyles: userStyles.text(), }, JSON.parse(window.localStorage.getItem("settings"))); @@ -485,6 +486,9 @@ $(function() { settings.find("#user-specified-css-input").val(options[i]); } else if (i === "highlights") { settings.find("input[name=" + i + "]").val(options[i]); + } else if (i === "theme") { + $("#theme").attr("href", "themes/" + options[i] + ".css"); + settings.find("select[name=" + i + "]").val(options[i]); } else if (options[i]) { settings.find("input[name=" + i + "]").prop("checked", true); } @@ -516,6 +520,8 @@ $(function() { chat.toggleClass("hide-" + name, !self.prop("checked")); } else if (name === "coloredNicks") { chat.toggleClass("colored-nicks", self.prop("checked")); + } else if (name === "theme") { + $("#theme").attr("href", "themes/" + options[name] + ".css"); } else if (name === "userStyles") { $(document.head).find("#user-specified-css").html(options[name]); } else if (name === "highlights") { diff --git a/src/server.js b/src/server.js index 872e4308..4dcade40 100644 --- a/src/server.js +++ b/src/server.js @@ -122,6 +122,11 @@ function index(req, res, next) { Helper.config ); data.gitCommit = gitCommit; + data.themes = fs.readdirSync("client/themes/").filter(function(file) { + return file.endsWith(".css"); + }).map(function(css) { + return css.slice(0, -4); + }); var template = _.template(file); res.setHeader("Content-Security-Policy", "default-src *; style-src * 'unsafe-inline'; script-src 'self'; child-src 'none'; object-src 'none'; form-action 'none'; referrer no-referrer;"); res.setHeader("Content-Type", "text/html");