Skip to content

Commit

Permalink
Implemented Actual Dark Mode Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bijju089 committed Nov 20, 2024
1 parent a55911a commit 7bfcbe7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 44 deletions.
27 changes: 27 additions & 0 deletions custom/templates/Aurora/aurora/addons.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,30 @@
})
</script>
{/if}

<!--- DarkMode Addon --->
<script>
{if $THEMESWITCHER eq '1'}
function toggleDarkLightMode() {
if (document.getElementById("darkmode-toggle").checked) {
document.body.classList.add('dark');
document.cookie = "darkMode=1; path=/; max-age=31536000";
} else {
document.body.classList.remove('dark');
document.cookie = "darkMode=0; path=/; max-age=31536000";
}
}
{/if}
window.addEventListener('load', function () {
const darkModeCookie = document.cookie.split('; ').find(row => row.startsWith('darkMode='));
const darkMode = darkModeCookie ? darkModeCookie.split('=')[1] : '{$DARKMODE}';
if (darkMode === '1') {
document.body.classList.add('dark');
document.getElementById("darkmode-toggle").checked = true;
} else {
document.body.classList.remove('dark');
document.getElementById("darkmode-toggle").checked = false;
}
});
</script>
31 changes: 8 additions & 23 deletions custom/templates/Aurora/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@
{if $PAGE_LOAD_TIME}
<span class="item" id="page_load"></span>
{/if}
{if $THEMESWITCHER eq '1' }
<span class="item" id="darkmode">
<input type="checkbox" class="darkmode-toggle" id="darkmode-toggle" onclick="toggleDarkLightMode()">
<label for="darkmode-toggle" class="darkmode-toggle-label">
<i class="fas fa-moon"></i>
<i class="fas fa-sun"></i>
<div class="darkmode-ball"></div>
</label>

<script type="text/javascript">
if (document.body.classList.contains('dark')) {
document.getElementById("darkmode-toggle").checked = true;
} else {
document.getElementById("darkmode-toggle").checked = false;
}
</script>
<input type="checkbox" class="darkmode-toggle" id="darkmode-toggle" onclick="toggleDarkLightMode()">
<label for="darkmode-toggle" class="darkmode-toggle-label">
<i class="fas fa-moon"></i>
<i class="fas fa-sun"></i>
<div class="darkmode-ball"></div>
</label>
</span>
{/if}
{if isset($AUTO_LANGUAGE)}
<a class="item" href="javascript:" onclick="toggleAutoLanguage()" id="auto-language"></a>
{/if}
Expand Down Expand Up @@ -174,15 +168,6 @@ document.getElementById("dslink").addEventListener("click", function() {
}
</script>
<script type="text/javascript">
function toggleDarkLightMode() {
$.post("{$DARK_LIGHT_MODE_ACTION}", { token: "{$DARK_LIGHT_MODE_TOKEN}" })
.done(function () {
window.location.reload();
});
return false;
}
{if isset($AUTO_LANGUAGE)}
const autoLanguage = document.getElementById('auto-language');
const autoLanguageValue = $.cookie('auto_language') ?? 'true';
Expand Down
2 changes: 1 addition & 1 deletion custom/templates/Aurora/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ value="{$PAGE_KEYWORDS}"}{else}{assign var="PAGEKEYWORDS" value=" "}{/if}
{/if}
</head>

<body{if $AURORA_DARK_MODE} class="dark" {/if} id="page-{if is_numeric($smarty.const.PAGE)}{$TITLE}{else}{$smarty.const.PAGE}{/if}">
<body id="page-{if is_numeric($smarty.const.PAGE)}{$TITLE}{else}{$smarty.const.PAGE}{/if}">
12 changes: 1 addition & 11 deletions custom/templates/Aurora/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Aurora_Template extends TemplateBase {
public function __construct($cache, $smarty, $language, $user, $pages) {
$template = [
'name' => 'Aurora',
'version' => '1.1',
'version' => '2.0',
'nl_version' => '2.1.2',
'author' => '<a href="https://bijjuxd.me/" target="_blank">BijjuXD</a> | <a href="https://cxstudios.org/" target="_blank">cxSTUDIOS</a>',
];
Expand All @@ -55,16 +55,6 @@ public function __construct($cache, $smarty, $language, $user, $pages) {
$smarty->assign('FORUM_SPAM_WARNING_TITLE', $language->get('general', 'warning'));

$cache->setCache('template_settings');
$smartyDarkMode = false;


if (defined('DARK_MODE') && DARK_MODE == '1') {
$smartyDarkMode = true;
}

$smarty->assign([
'AURORA_DARK_MODE' => $smartyDarkMode
]);

$this->_template = $template;
$this->_language = $language;
Expand Down
16 changes: 9 additions & 7 deletions custom/templates/Aurora/template_settings/class/AuroraUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
/*
* Aurora Template
* @license MIT
* Made by cxSTUDIOS | BijjuXD
*/

class AuroraUtil
Expand Down Expand Up @@ -107,21 +107,21 @@ public static function initialise()
'minecraftPort' => 25565,
'shadowEffects' => 0,
'cardt' => 'Portfolio',
'cardw' => 'https://cxstudios.org/exampleproject',
'cardw' => 'https://cxstudios.in/exampleproject',
'card1t' => 'My Project',
'card1w' => 'https://cxstudios.org/exampleproject',
'card1w' => 'https://cxstudios.in/exampleproject',
'card1v' => 'https://i.imgur.com/nvWYgJY.png',
'card1h' => 'https://i.imgur.com/9nZfJ0c.png',
'card2t' => 'My Project',
'card2w' => 'https://cxstudios.org/exampleproject',
'card2w' => 'https://cxstudios.in/exampleproject',
'card2v' => 'https://i.imgur.com/nvWYgJY.png',
'card2h' => 'https://i.imgur.com/9nZfJ0c.png',
'card3t' => 'My Project',
'card3w' => 'https://cxstudios.org/exampleproject',
'card3w' => 'https://cxstudios.in/exampleproject',
'card3v' => 'https://i.imgur.com/nvWYgJY.png',
'card3h' => 'https://i.imgur.com/9nZfJ0c.png',
'card4t' => 'My Project',
'card4w' => 'https://cxstudios.org/exampleproject',
'card4w' => 'https://cxstudios.in/exampleproject',
'card4v' => 'https://i.imgur.com/nvWYgJY.png',
'card4h' => 'https://i.imgur.com/9nZfJ0c.png',
'button1t' => 'Home',
Expand Down Expand Up @@ -158,7 +158,9 @@ public static function initialise()
'preloaderText' => 'Loading...',
'preloaderColor' => 'red',
'preloaderSpeed' => 'normal',
'preloaderStyle' => 'normal'
'preloaderStyle' => 'normal',
'darkMode' => 0,
'themeSwitcher' => 1
];

foreach ($settings_data as $key => $value) {
Expand Down
11 changes: 9 additions & 2 deletions custom/templates/Aurora/template_settings/page/theme.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
<div class="form-group">
<label for="inputDarkMode">{$DARKMODE_LABEL}</label>
<select name="darkMode" class="form-control" id="inputDarkMode">
<option value="0" {if $DARK_MODE_VALUE eq '0' } selected{/if}>{$DISABLED}</option>
<option value="1" {if $DARK_MODE_VALUE eq '1' } selected{/if}>{$ENABLED}</option>
<option value="0" {if $DARKMODE eq '0' } selected{/if}>{$DISABLED}</option>
<option value="1" {if $DARKMODE eq '1' } selected{/if}>{$ENABLED}</option>
</select>
</div>
<div class="form-group">
<label for="inputThemeSwitcher">{$THEMESWITCHER_LABEL}</label>
<select name="themeSwitcher" class="form-control" id="inputthemeSwitcher">
<option value="0" {if $THEMESWITCHER eq '0' } selected{/if}>{$DISABLED}</option>
<option value="1" {if $THEMESWITCHER eq '1' } selected{/if}>{$ENABLED}</option>
</select>
</div>
<div class="form-group">
Expand Down

0 comments on commit 7bfcbe7

Please sign in to comment.