Skip to content

Commit

Permalink
Update Theme-Customs
Browse files Browse the repository at this point in the history
Signed-off-by: Diego Andrés <diegoandres_cortes@outlook.com>
  • Loading branch information
DiegoAndresCortes committed Aug 10, 2024
1 parent 614692c commit 12f9bc4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
5 changes: 2 additions & 3 deletions languages/ThemeCustoms/main.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,9 @@
$txt['st_site_color_desc'] = 'Indicates a suggested color that user agents (browser) should use to customize the display of the page or of the surrounding user interface. <em class="smalltext">Default is #567c8f</em>';

// Color Variants
$txt['st_default_variant_desc'] = 'If the user selection is disabled, this will be the default and locked mode. Admins can still change their preference.<br><strong>This does not affect the default values for the users, for that you can use the Member Options section.</strong>';
$txt['st_color'] = 'Color Settings';
$txt['st_color_variants'] = 'Theme Color Variants';
$txt['st_color_variants_javascript'] = 'Use JavaScript to change the color';
$txt['st_color_variants_javascript_desc'] = 'This will change the variant of the theme using JavaScript and auto-update for the profile.';
$txt['variant_pick'] = 'Select Color Variant';
$txt['variant_default'] = 'Default';
$txt['variant_red'] = 'Red';
Expand All @@ -257,7 +256,7 @@
$txt['st_theme_mode'] = 'Theme Mode';
$txt['st_theme_mode_select'] = 'Select Theme Mode';
$txt['st_theme_mode_default'] = 'Default Theme Mode';
$txt['st_theme_mode_default_desc'] = 'If user selection is disabled, this will be the default and locked mode. Admins can still change their preference.';
$txt['st_theme_mode_default_desc'] = 'If user selection is disabled, this will be the default and locked mode. Admins can still change their preference.<br><strong>This does not affect the default values for the users, for that you can use the Member Options section.</strong>';
$txt['st_enable_mode_selection'] = 'Enable user mode selection';
$txt['st_dark_mode'] = 'Dark Mode';
$txt['st_light_mode'] = 'Light Mode';
Expand Down
2 changes: 1 addition & 1 deletion scripts/custom/variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let localVariant = localStorage.getItem('st_theme_variant');
let toggleVariant = document.querySelectorAll('.theme-variant-toggle');

if (!smf_member_id && localVariant !== null) {
document.documentElement.dataset.mode = localVariant;
document.documentElement.dataset.variant = localVariant;
}

function switchVariant(variant) {
Expand Down
4 changes: 2 additions & 2 deletions themecustoms/Color/DarkMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function init() : void
$this->selection();

// No need to load if the setting is disabled and default mode is light
if (!empty($context['theme_can_change_mode']) || $settings['st_theme_mode_default'] !== 'light') {
if (!empty($context['theme_can_change_mode']) || (!empty($settings['st_theme_mode_default']) && $settings['st_theme_mode_default'] !== 'light')) {
// Load the css
$this->css();

Expand Down Expand Up @@ -115,7 +115,7 @@ private function css()
global $settings, $context;

// Add the HTML data attribute for color mode
$settings['themecustoms_html_attributes']['data']['mode'] = 'data-mode="' . $context['theme_colormode'] . '"';
$settings['themecustoms_html']['attributes'][] = 'data-mode="' . $context['theme_colormode'] . '"';

// Load the dark CSS
loadCSSFile('custom/dark.css', ['order_pos' => $this->order, 'attributes' => (isset($context['theme_colormode']) && $context['theme_colormode'] == 'system' ? ['media' => '(prefers-color-scheme: dark)'] : [])], 'smf_darkmode');
Expand Down
9 changes: 6 additions & 3 deletions themecustoms/Color/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function init() : void
$this->selection();

// No need to load if the setting is disabled and the default variant is selected
if (!empty($context['theme_can_change_variants']) || $settings['default_variant'] !== 'default') {
if (!empty($context['theme_can_change_variants']) || (!empty($settings['default_variant']) && $settings['default_variant'] !== 'default')) {
// Load the css
$this->css();

Expand Down Expand Up @@ -127,7 +127,7 @@ private function css() : void
global $context, $settings;

// Add the HTML data attribute for color variant
$settings['themecustoms_html_attributes']['data']['variant'] = 'data-variant="' . $context['theme_variant'] . '"';
$settings['themecustoms_html']['attributes'][] = 'data-variant="' . $context['theme_variant'] . '"';

// Add the CSS file for the variants
loadCSSFile('custom/variants.css', ['order_pos' => $this->order], 'smf_variants');
Expand Down Expand Up @@ -223,6 +223,9 @@ public function options() : void
{
global $context, $txt, $settings;

if (!empty($context['current_action']) && $context['current_action'] == 'admin' && isset($_REQUEST['th']) && !empty($_REQUEST['th']) && $_REQUEST['th'] != Config::$current->id)
return;

// Insert the theme options
$context['theme_options'] = array_merge(
[
Expand Down Expand Up @@ -257,7 +260,7 @@ public function settings(array &$theme_settings, array &$settings_types) : void
'section_title' => $txt['theme_variants'],
'id' => 'default_variant',
'label' => $txt['theme_variants_default'],
'description' => '<img src="' . $settings['images_url'] . '/thumbnail' . (!empty($settings['default_variant']) && $settings['default_variant'] !== 'default' ? '_' . $settings['default_variant'] : '') . '.png" id="variant_preview" class="theme_thumbnail" alt="">',
'description' => $txt['st_default_variant_desc'] . '<br><br><img src="' . $settings['images_url'] . '/thumbnail' . (!empty($settings['default_variant']) && $settings['default_variant'] !== 'default' ? '_' . $settings['default_variant'] : '') . '.png" id="variant_preview" class="theme_thumbnail" alt="">',
'options' => $this->selectVariants,
'type' => 'list',
'theme_type' => 'color',
Expand Down
6 changes: 3 additions & 3 deletions themecustoms/Theme/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ public function buffer(string $buffer) : string
}

/**
* Add the global data attributes
* Add the global html attributes
*/
public function htmlAttributes() : void
{
global $settings, $context;

// Data attributes
$settings['themecustoms_html_attributes_data'] = (!empty($settings['themecustoms_html_attributes']['data']) && is_array($settings['themecustoms_html_attributes']['data']) ? ' ' . implode(' ', $settings['themecustoms_html_attributes']['data']) : '');
// HTML Attributes
$settings['themecustoms_html_attributes'] = (!empty($settings['themecustoms_html']['attributes']) && is_array($settings['themecustoms_html']['attributes']) ? ' ' . implode(' ', $settings['themecustoms_html']['attributes']) : '');

// Disable the info center?
if (isset($settings['st_disable_info_center']) && !empty($settings['st_disable_info_center']) && !empty($context['info_center']))
Expand Down

0 comments on commit 12f9bc4

Please sign in to comment.