From 8a501c075f3c28089ea9622e700ffce3ef70ac0a Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 9 Oct 2017 14:04:59 +0000 Subject: [PATCH] Persist selected theme in dropdown --- dist/js/sb-admin-2.js | 8 ++++---- includes/themes.php | 24 ++++++++++++++++++++---- index.php | 5 +++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/dist/js/sb-admin-2.js b/dist/js/sb-admin-2.js index 3bbc30da..ce024e24 100755 --- a/dist/js/sb-admin-2.js +++ b/dist/js/sb-admin-2.js @@ -6,7 +6,7 @@ $(function() { }); function set_theme(theme) { - $('link[title="main"]').attr('href', theme); + $('link[title="main"]').attr('href', 'dist/css/' + theme); // persist selected theme in cookie setCookie('theme',theme,90); @@ -20,9 +20,9 @@ function setCookie(cname, cvalue, exdays) { } var themes = { - "default": "dist/css/custom.css", - "hackernews" : "dist/css/hackernews.css", - "terminal" : "dist/css/terminal.css", + "default": "custom.css", + "hackernews" : "hackernews.css", + "terminal" : "terminal.css", } //Loads the correct sidebar on window load, diff --git a/includes/themes.php b/includes/themes.php index 0b502341..44af3511 100644 --- a/includes/themes.php +++ b/includes/themes.php @@ -5,6 +5,22 @@ */ function DisplayThemeConfig(){ + $cselected = ''; + $hselected = ''; + $tselected = ''; + + switch( $_COOKIE['theme'] ) { + case "custom.css": + $cselected = "selected"; + break; + case "hackernews.css": + $hselected = "selected"; + break; + case "terminal.css": + $tselected = "selected"; + break; + } + ?>
@@ -20,10 +36,10 @@ function DisplayThemeConfig(){
- Select a Theme + + +
diff --git a/index.php b/index.php index f11a2956..5ed8a06b 100755 --- a/index.php +++ b/index.php @@ -66,10 +66,11 @@ if (empty($_SESSION['csrf_token'])) { $csrf_token = $_SESSION['csrf_token']; if(!isset($_COOKIE['theme'])) { - $theme_url = "dist/css/custom.css"; + $theme = "custom.css"; } else { - $theme_url = $_COOKIE['theme']; + $theme = $_COOKIE['theme']; } +$theme_url = 'dist/css/' . $theme; ?>