#variant_switch button:active

For support and discussion related to templates and themes in phpBB 3.3.
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

@cabot
Your method works indeed! But to avoid making mistakes. The idea is to keep the CSS in this method?

Code: Select all

.html_Crimson a {color: Crimson;}
etc. ...
.html_Crimson .button-secondary:focus, .html_Crimson .button-secondary:hover, .html_Crimson .button:focus .icon, .html_Crimson .button:hover .icon {color: Crimson;}
etc.
etc.
It's all about the choice selection right?

Code: Select all

					{% if S_USER_LOGGED_IN and not S_IS_BOT %}
<li class="rightside" data-skip-responsive="true">
			<div class="dropdown-container">
			<a href="#" class="dropdown-trigger" role="menuitem" title="kleurenpallet">
				<i class="icon fa-paint-brush fa-fw" aria-hidden="true"></i>
			</a>
				<div class="dropdown">
					<div class="pointer"><div class="pointer-inner"></div></div>
					<div class="dropdown-contents" role="menu">
						  <div id="variant_switch" class="navbar-header" role="contentinfo">
{% set colors = ['default', 'Crimson', 'PaleVioletRed', 'MediumOrchid', 'BlueViolet', 'SlateBlue', 'RoyalBlue', 'DodgerBlue', 'DarkTurquoise', 'DarkCyan', 'LimeGreen', 'YellowGreen', 'Gold', 'Orange', 'Coral', 'Gray'] %}
 
{% for color in colors %}
<button id="html_{{ color }}" onClick="change_variant(this.id)" title="{{ color }}"></button>
{% endfor %}
					</div>
				</div>
			</div>
		</li>
	</ul>
{% endif %}
User avatar
cabot
Jr. Style Validator
Posts: 1201
Joined: Sat Jan 07, 2012 4:16 pm

Re: #variant_switch button:active

Post by cabot »

You can iterate over the array in the head to get the colours and simplify the style sheet as much as possible by using a single CSS variable.
Here's a suggestion.

overall_header/head:

Code: Select all

<script>if (localStorage.prosilverColors) document.documentElement.setAttribute("data-color", localStorage.prosilverColors);</script>

{% DEFINE COLORS = ['default', 'Crimson', 'PaleVioletRed', 'MediumOrchid', 'BlueViolet', 'SlateBlue', 'RoyalBlue', 'DodgerBlue', 'DarkTurquoise', 'DarkCyan', 'LimeGreen', 'YellowGreen', 'Gold', 'Orange', 'Coral', 'Gray'] %}
<style>
{% for color in definition.COLORS %}
	{% if color != 'default' %}
	[data-color="{{ color }}"] { --primary-color: {{ color }}; }
	.switch-{{ color }} { background-color: {{ color }}; }
	{% endif %}
{% endfor %}
Dropdown in any file:

Code: Select all

{% if S_USER_LOGGED_IN and not S_IS_BOT %}
<li class="rightside" data-skip-responsive="true">
	<div class="dropdown-container">
		<a href="#" class="dropdown-trigger" role="menuitem" title="{{ lang('COLOUR_SWATCH') }}">
			<i class="icon fa-paint-brush fa-fw" aria-hidden="true"></i><span class="sr-only">{{ lang('COLOUR_SWATCH') }}</span>
		</a>
		<div class="dropdown">
			<div class="pointer"><div class="pointer-inner"></div></div>
			<div class="dropdown-contents" role="menu">
				<div id="variant_switch" class="navbar-header" role="contentinfo">
					{% for color in definition.COLORS %}
					<button class="switch-{{ color }}" data-colorselect="{{ color }}" title="{{ color }}"><span class="sr-only">{{ color }}</span></button>
					{% endfor %}
				</div>
			</div>
		</div>
	</div>
</li>
{% endif %}
JS either in overall_footer or in a custom .js file:

Code: Select all

const colorButtons = $("[data-colorselect]");

function setColor(color) {
	if (color === "default") {
		$("html").removeAttr("data-color");
		localStorage.removeItem("prosilverColors");
	} else {
		$("html").attr("data-color", color);
		localStorage.setItem("prosilverColors", color);
	}
	updateActiveColor(color);
}

function updateActiveColor(currentColor) {
	colorButtons.each(function () {
		$(this).toggleClass("activecolor", $(this).data("colorselect") === currentColor);
	});
}

const savedColor = localStorage.getItem("prosilverColors") || "default";
setColor(savedColor);

colorButtons.on("click", function () {
	const selectedColor = $(this).data("colorselect");
	setColor(selectedColor);
});
The full CSS based on what you've posted:

Code: Select all

a,
.button-secondary:focus,
.button-secondary:hover,
.button:focus .icon,
.button:hover .icon,
a.button1,
a.button2,
input.button1,
input.button2,
input.button3,
.pagination li.active span,
.tabs .activetab > a,
.tabs .activetab > a:hover {
	color: var(--primary-color, #105289);
}

html,
body,
.badge-messages {
	background-color: var(--primary-color, #105289);
}

.quick-icon .qi-line {
	border-top: 2px solid var(--primary-color, #105289);
}

#variant_switch {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
}

#variant_switch button {
	display: inline-block;
	width: 20px;
	height: 20px;
	margin: 0.5em;
	border: 0;
	border-radius: 3px;
}

.switch-default { background-color: #105289; }

#variant_switch button:hover,
#variant_switch button:focus {
	opacity: 0.5;
}

#variant_switch .activecolor {
	outline: thick double var(--primary-color, #105289);
}
From now on, all you have to do is add or remove a color in the array and the rest will follow automatically (don't remove ‘default’).
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

Super cool! Works like a charm :D

And for my darker variant/switch of the style I have adjusted the below so that you can choose the color separately

Code: Select all

localStorage.removeItem("prosilver_darkColors");
Thank you all very much! It was an educational day!
User avatar
Gumboots
Registered User
Posts: 985
Joined: Fri Oct 11, 2019 1:59 am

Re: #variant_switch button:active

Post by Gumboots »

I like the array for situations when you have stacks of buttons. It will help keep things a bit saner. OTOH, if you only have a few it's just more logic to process, and you have to render all the markup anyway, so you're not gaining anything in terms of performance. You're actually incurring a sight loss, and least in theory (although nobody is likely to notice in practice). The crossover point at which an array becomes worthwhile is largely personal preference.

If you do want to use an array for large numbers of buttons I would make two suggestions:
  1. Put each entry on a new line.
  2. Order them alphabetically.
This will make changes easier, if you ever want to change anything. Less head scratching involved.

Code: Select all

{% DEFINE COLORS = [
	'default',
	'BlueViolet',
	'Coral',
	'Crimson',
	'DarkCyan',
	'DarkTurquoise',
	'DodgerBlue',
	'Gold',
	'Gray',
	'LimeGreen',
	'MediumOrchid',
	'Orange',
	'PaleVioletRed',
	'RoyalBlue',
	'SlateBlue',
	'YellowGreen'
	]
%}
And don't forget any commas, or you will kill your whole site. :D
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Gumboots
Registered User
Posts: 985
Joined: Fri Oct 11, 2019 1:59 am

Re: #variant_switch button:active

Post by Gumboots »

Couple of suggestions...
cabot wrote: Mon Apr 14, 2025 5:29 pmDropdown in any file:

Code: Select all

{% if S_USER_LOGGED_IN and not S_IS_BOT %}
<li class="rightside" data-skip-responsive="true">
	<div class="dropdown-container">
		<a href="#" class="dropdown-trigger" role="menuitem" title="{{ lang('COLOUR_SWATCH') }}">
			<i class="icon fa-paint-brush fa-fw" aria-hidden="true"></i><span class="sr-only">{{ lang('COLOUR_SWATCH') }}</span>
		</a>
		<div class="dropdown">
			<div class="pointer"><div class="pointer-inner"></div></div>
			<div class="dropdown-contents" role="menu">
				<div id="variant_switch" class="navbar-header" role="contentinfo">
					{% for color in definition.COLORS %}
					<button class="switch-{{ color }}" data-colorselect="{{ color }}" title="{{ color }}"><span class="sr-only">{{ color }}</span></button>
					{% endfor %}
				</div>
			</div>
		</div>
	</div>
</li>
{% endif %}
1/ Offhand I can't see any reason to deny the colour changer to guests, and in fact I often use it myself on my own stuff when I'm not logged in. I'd suggest only hiding it from bots, if you want to hide it at all, but I'm not sure that is even necessary.

2/ Get rid of the title attribute here:

Code: Select all

<button class="switch-{{ color }}" data-colorselect="{{ color }}" title="{{ color }}">
Reasons being:
  1. Sighted users don't need it.
  2. It's useless on touch screen anyway.
  3. Unsighted users won't care, and in any case they have the sr-only span to tell them. Screen reader handling of the title attribute is inconsistent, and users are not going to want to hear "MediumOrchid MediumOrchid" if they happen to be using a reader that does read out the title attribute.
Quite honestly, the title attribute is usually more trouble than it is worth, for anyone.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
cabot
Jr. Style Validator
Posts: 1201
Joined: Sat Jan 07, 2012 4:16 pm

Re: #variant_switch button:active

Post by cabot »

1/ It's bennybernaer's choice and I respect it as such. ;)

2/ As far as I'm concerned, I like to have the information on hovering over an icon when it's not labelled.
What's more, the two screen readers I use (NVDA and VoiceOver) ignore the title attribute by default, so the label is not repeated twice. But of course this depends on the user's settings.

On the other hand, in the context of A11Y, there shouldn't be a contentinfo lanmark there (but I've only just noticed it ^^), and the prosilver dropdown doesn't meet accessibility criteria.
Anyway, I'm not going to dwell on general accessibility in this thread to avoid polluting it unnecessarily.

As I said recently in another thread, prosilver in general doesn't meet these criteria (which are evolving), but I don't want to blame anyone because the code is a bit dated and there's already been a lot of effort in this area. And I think it's up to us, the users, to open tickets and make the corresponding PRs to support the developers who are already doing a great deal. Let's not forget that this is open source software and that, in essence, everyone can participate in its development.
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

@Gumboots

Hiding from guests is a deliberate choice.

Given the sensitive content of my forum, you will only see a login screen as a guest when you visit the forum.
https://ana4life.nl/
User avatar
cabot
Jr. Style Validator
Posts: 1201
Joined: Sat Jan 07, 2012 4:16 pm

Re: #variant_switch button:active

Post by cabot »

bennybernaer wrote: Mon Apr 14, 2025 6:37 pm And for my darker variant/switch of the style I have adjusted the below so that you can choose the color separately
Don't forget to also change the key name in the condition:

Code: Select all

<script>if (localStorage.prosilverColors) document.documentElement.setAttribute("data-color", localStorage.prosilver_darkColors);</script>
prosilverColors should be prosilver_darkColors :)
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

cabot wrote: Tue Apr 15, 2025 10:35 am Don't forget to also change the key name in the condition:

Code: Select all

<script>if (localStorage.prosilverColors) document.documentElement.setAttribute("data-color", localStorage.prosilver_darkColors);</script>
prosilverColors should be prosilver_darkColors :)
I see it! Completely overseen. It's good now! :)
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

In my footer I have an image.

To make it really excellent, it would be nice if the image changes (relative to the color). Is it possible to add this to the css?

Code: Select all

#variant_switch {
	default.png
        Crimson.png
        etc.
}

Code: Select all

			<div class="socialinks">
				<ul>
					<li>
						<a type="application/rss+xml" href="/feed?sid=04c5960a339db2024bd4e9497169ab52">
							<i class="icon fp-feed" title="Feed - ana4life"></i>
						</a>
					</li>
					<li>
						<a href="https://www.instagram.com/ana4life_nl/" title="Instagram">
							<i class="icon fp-instagram"></i>
						</a>
					</li>
					<li>
						<a href="https://twitter.com/ana4life_nl" title="X">
							<i class="icon fp-twitter"></i>
						</a>
					</li>
				</ul>
				    <br><img src="{T_THEME_PATH}/images/default.png" title="Meer dan 15 jaar ervaring"/>
			</div>
User avatar
Gumboots
Registered User
Posts: 985
Joined: Fri Oct 11, 2019 1:59 am

Re: #variant_switch button:active

Post by Gumboots »

That's as easy as changing colours. Instead of changing a colour code you just change the image url. The easiest way would be to set up a div with the image called as a background image. Then you don't have to worry about more template edits and can do it all in your CSS.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

Gumboots wrote: Sat Apr 19, 2025 8:13 pm That's as easy as changing colours. Instead of changing a colour code you just change the image url. The easiest way would be to set up a div with the image called as a background image. Then you don't have to worry about more template edits and can do it all in your CSS.
Do you mean something like this? But how do I assign this per chosen color?

Code: Select all

			<div class="variant_switch"><img src="{T_THEME_PATH}/images/default.png" title="Meer dan 15 jaar ervaring"/></div>

Code: Select all

.variant_switch {
	background-image: url ("./images/default.png");
	background-image: url ("./images/crimson.png");
	etc.
}  
User avatar
Gumboots
Registered User
Posts: 985
Joined: Fri Oct 11, 2019 1:59 am

Re: #variant_switch button:active

Post by Gumboots »

Same way as you do colours: use a parent tag with the colour ID or class assigned to make CSS declarations.

First, set it as a background image, not an inline image.

Code: Select all

<div class="variant_switch"></div>
Define the size you want the div to have.

Code: Select all

.variant_switch {width: whatever; height: whatever_else;}
You may want to use aspect ratio there, depending on exactly what you are aiming for.

Then if you are assigning a colour class on the root/html tag, use that for your descendant declarations.

Code: Select all

.html_Crimson .variant_switch {background-image: whatever;}
Live example:

Code: Select all

#var_hdlgre .headerbar .inner	{
	background: url(banners/hdlgre2.webp) 66% 0;
}
#var_hdlblu .headerbar .inner {
	background: url(banners/hdlblu2.webp) 66% 0;
}
#var_hdlsla .headerbar .inner {
	background: url(banners/hdlsla2.webp) 50% 0;
}
#var_hdlora .headerbar .inner {
	background: url(banners/hdlora2.webp) 10% 0;
}
#var_hdlmur .headerbar .inner	{
	background: url(banners/hdlmur2.webp) 77% 0;
}
From here: https://hawkdawg.com/forums/index.php
Don't worry about the background-position numbers there. Those are just so the banners position themselves well relative to the logo on phones. Not your problem for this use case.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
bennybernaer
Registered User
Posts: 768
Joined: Tue Mar 22, 2011 9:53 pm

Re: #variant_switch button:active

Post by bennybernaer »

I have implemented your changes in my test forum but something seems to go wrong. I don't see any image in my footer. Is it also the intention that the div <div class="variant_switch"></div> remains empty?

Code: Select all

.html_PaleVioletRed .variant_switch {background-image: url("./images/footer/PaleVioletRed.png");} 
etc.
Just to be clear you know that I use the changes from Cabot for my colors?

viewtopic.php?p=16061662#p16061662
User avatar
Gumboots
Registered User
Posts: 985
Joined: Fri Oct 11, 2019 1:59 am

Re: #variant_switch button:active

Post by Gumboots »

You have the html_default class in your markup for the html tag. Presumably that gets replaced by a class that matches your selected variant when you use the variant switcher (I can't tell for sure because I don't have access). So, you use that class to pick which image you want to display. It's a simple descendant selector, like any other you are using. If it's not working then the selector is wrong, or the path to the image is wrong, or you have not set a size on the div (which is necessary, because without content it will collapse to zero height if no size is set).
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦

Return to “[3.3.x] Styles Support & Discussion”