From aa6066dfd5b737128325d22265f894102f8c741e Mon Sep 17 00:00:00 2001 From: Xaekai Date: Fri, 8 Jul 2016 04:31:32 -0700 Subject: [PATCH] Reduce the number of places the default theme is hardcoded from 6 to 1. --- package.json | 2 +- templates/head.pug | 7 ++++++- www/js/data.js | 6 +++--- www/js/theme.js | 7 ++++--- www/js/util.js | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 35bdb760..73fff5df 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.18.3", + "version": "3.18.4", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/templates/head.pug b/templates/head.pug index f537b15e..57d047aa 100644 --- a/templates/head.pug +++ b/templates/head.pug @@ -1,3 +1,5 @@ +- var DEFAULT_THEME = "/css/themes/slate.css"; + mixin head() meta(charset="utf-8") meta(name="viewport", content="width=device-width, initial-scale=1.0") @@ -7,7 +9,10 @@ mixin head() title= siteTitle link(href="/css/sticky-footer-navbar.css", rel="stylesheet") link(href="/css/cytube.css", rel="stylesheet") - link(id="usertheme", href="/css/themes/slate.css", rel="stylesheet") + link(id="usertheme", href=DEFAULT_THEME, rel="stylesheet") + + script(type="text/javascript"). + var DEFAULT_THEME = '#{DEFAULT_THEME}'; script(src="/js/theme.js") //[if lt IE 9] diff --git a/www/js/data.js b/www/js/data.js index 1d348208..440b0b38 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -97,7 +97,7 @@ function getOrDefault(k, def) { } var USEROPTS = { - theme : getOrDefault("theme", "/css/themes/slate.css"), + theme : getOrDefault("theme", DEFAULT_THEME), // Set in head template layout : getOrDefault("layout", "fluid"), synch : getOrDefault("synch", true), hidevid : getOrDefault("hidevid", false), @@ -204,9 +204,9 @@ function eraseCookie(name) { (function () { var localVersion = parseFloat(getOpt("version")); if (isNaN(localVersion)) { - USEROPTS.theme = "/css/themes/slate.css"; + USEROPTS.theme = DEFAULT_THEME; USEROPTS.layout = "fluid"; - setOpt("theme", "/css/themes/slate.css"); + setOpt("theme", DEFAULT_THEME); setOpt("layout", "fluid"); setOpt("version", CL_VERSION); } diff --git a/www/js/theme.js b/www/js/theme.js index 0d1e38be..e0690124 100644 --- a/www/js/theme.js +++ b/www/js/theme.js @@ -3,7 +3,8 @@ return s.trim(); }); - var theme = "/css/themes/slate.css"; + // Set in the head template. + var theme = DEFAULT_THEME; for (var i = 0; i < c.length; i++) { if (c[i].indexOf("cytube-theme=") === 0) { theme = c[i].split("=")[1]; @@ -15,8 +16,8 @@ return; } - if (theme !== "/css/themes/slate.css") { - console.log("THEME COOKIE:", theme); + if (theme !== DEFAULT_THEME) { + console.info("THEME COOKIE:", theme); var cur = document.getElementById("usertheme"); cur.parentNode.removeChild(cur); var css = document.createElement("link"); diff --git a/www/js/util.js b/www/js/util.js index f767515b..d2564c40 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -696,7 +696,7 @@ function applyOpts() { var old = $("#usertheme").attr("id", "usertheme_old"); var theme = USEROPTS.theme; if (theme === "default") { - theme = "/css/themes/slate.css"; + theme = DEFAULT_THEME; } $("").attr("rel", "stylesheet") .attr("type", "text/css")