Selector de tema de cores.

This commit is contained in:
Laegnur 2022-03-13 21:30:17 +01:00
parent 4413c0e154
commit 8fc39ad438
4 changed files with 281 additions and 44 deletions

View file

@ -90,7 +90,7 @@ function renderMenu($paxinas, $maxDepth = 0, $id = 'nav')
if($saida) if($saida)
{ {
$saida = '<ul id="' . $id . '" class="contenedor columna separado fin">' . $saida . '</ul>'; $saida = '<ul id="' . $id . '">' . $saida . '</ul>';
} }
return $saida; return $saida;

View file

@ -1,4 +1,13 @@
<?php namespace ProcessWire;?><!DOCTYPE html> <?php namespace ProcessWire;
if(!empty($_COOKIE['tema']))
{
$tema = $_COOKIE['tema'];
}
else
{
$tema = 'light.css';
}
?><!DOCTYPE html>
<html lang="<?php echo _x('en', 'HTML language code'); ?>"> <html lang="<?php echo _x('en', 'HTML language code'); ?>">
<head> <head>
<title><?php echo $titulo; ?></title> <title><?php echo $titulo; ?></title>
@ -7,15 +16,15 @@
<?php if($inicio->descripcion_sitio): ?> <?php if($inicio->descripcion_sitio): ?>
<meta name="description" content="<?php echo $configuracion['nome_sitio'] . ' ' . $configuracion['descripcion_sitio']; ?>" /> <meta name="description" content="<?php echo $configuracion['nome_sitio'] . ' ' . $configuracion['descripcion_sitio']; ?>" />
<?php endif; ?> <?php endif; ?>
<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>css/reset.css" /> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates; ?>css/reset.css" />
<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>css/fonts.css" /> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates; ?>css/fonts.css" />
<link title="Praia de Seselle" rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>css/style.css" /> <link title="Praia de Seselle" rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>css/style.css" />
<?php foreach($languages as $idioma): ?> <?php foreach($languages as $idioma): ?>
<?php if(!$page->viewable($idioma)): continue; endif; ?> <?php if(!$page->viewable($idioma)): continue; endif; ?>
<link rel="alternate" hreflang="<?php echo $inicio->getLanguageValue($idioma, 'name'); ?>" href="<?php echo $page->localHttpUrl($idioma); ?>" /> <link rel="alternate" hreflang="<?php echo $inicio->getLanguageValue($idioma, 'name'); ?>" href="<?php echo $page->localHttpUrl($idioma); ?>" />
<?php endforeach; ?> <?php endforeach; ?>
</head> </head>
<body> <body class="<?php echo $tema; ?>">
<a href="#contido" class="visually-hidden element-focusable bypass-to-main"><?php echo _x('Skip to content', 'bypass'); ?></a> <a href="#contido" class="visually-hidden element-focusable bypass-to-main"><?php echo _x('Skip to content', 'bypass'); ?></a>
<header id="cabeceira"> <header id="cabeceira">
<div class="contedor"> <div class="contedor">
@ -31,7 +40,8 @@
</div> </div>
<nav id="menu"> <nav id="menu">
<h2 class="visually-hidden"><?php echo _x('Menu', 'Navigation menu');?></h2> <h2 class="visually-hidden"><?php echo _x('Menu', 'Navigation menu');?></h2>
<ul id="idiomas" class="contenedor columna separado fin"> <div id="axustes">
<ul id="idiomas" class="contenedor columna separado fin">
<?php <?php
foreach($languages as $idioma) foreach($languages as $idioma)
{ {
@ -40,15 +50,34 @@ foreach($languages as $idioma)
continue; continue;
} }
?> ?>
<li <?php echo $idioma->id == $user->language->id ? 'class="activo"' : ''; ?>> <li <?php echo $idioma->id == $user->language->id ? 'class="activo"' : ''; ?>>
<?php <?php
$url = $page->localUrl($idioma); $url = $page->localUrl($idioma);
$hreflang = $inicio->getLanguageValue($idioma, 'name'); $hreflang = $inicio->getLanguageValue($idioma, 'name');
?> ?>
<a title="<?php echo $idioma->title; ?>" hreflang="<?php echo $hreflang;?>" href="<?php echo $url; ?>"><?php echo $hreflang; ?></a> <a title="<?php echo $idioma->title; ?>" hreflang="<?php echo $hreflang;?>" href="<?php echo $url; ?>"><?php echo $hreflang; ?></a>
</li> </li>
<?php } ?> <?php } ?>
</ul> </ul>
<div class="tema">
<label for='selector_tema'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="icono_dia" x="0px" y="0px" viewBox="0 0 35 35" style="enable-background:new 0 0 35 35;" xml:space="preserve">
<g id="sol">
<g>
<path style="fill-rule:evenodd;clip-rule:evenodd;" d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z" />
</g>
</g>
</svg>
</label>
<input class='toggle' id='selector_tema' type='checkbox'>
<label class='toggle-button' for='selector_tema'></label>
<label for='selector_tema'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="icono_noche" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<path d="M96.76,66.458c-0.853-0.852-2.15-1.064-3.23-0.534c-6.063,2.991-12.858,4.571-19.655,4.571 C62.022,70.495,50.88,65.88,42.5,57.5C29.043,44.043,25.658,23.536,34.076,6.47c0.532-1.08,0.318-2.379-0.534-3.23 c-0.851-0.852-2.15-1.064-3.23-0.534c-4.918,2.427-9.375,5.619-13.246,9.491c-9.447,9.447-14.65,22.008-14.65,35.369 c0,13.36,5.203,25.921,14.65,35.368s22.008,14.65,35.368,14.65c13.361,0,25.921-5.203,35.369-14.65 c3.872-3.871,7.064-8.328,9.491-13.246C97.826,68.608,97.611,67.309,96.76,66.458z" />
</svg>
</label>
</div>
</div>
<?php echo $menu; ?> <?php echo $menu; ?>
</nav> </nav>
</div> </div>

View file

@ -6,11 +6,6 @@
:root :root
{ {
font-size: 16px; font-size: 16px;
--color_oscuro: 189, 186, 178;
--fondo_principal: 255, 255, 255;
--fondo_oscuro: 43, 44, 38;
--sombra: 0.8;
} }
body body
@ -22,11 +17,27 @@ body
margin: 0; margin: 0;
color: var(--fondo_oscuro); color: rgb(var(--color_realce));
font-family: 'DejaVu Sans', sans-serif; font-family: 'DejaVu Sans', sans-serif;
font-size: 1rem; font-size: 1rem;
background-color: rgb(var(--fondo_principal)); background-color: rgb(var(--color_principal));
}
body.light
{
--color_principal: 255, 255, 255;
--color_realce: 43, 44, 38;
--color-pe: 43, 44, 38;
--texto_realce: 189, 186, 178;
}
body.dark
{
--color_principal: 43, 44, 38;
--color_realce: 255, 255, 255;
--color-pe: 24, 24, 18;
--texto_realce: 189, 186, 178;
} }
h1, h2, h3, h4, h5, h6 h1, h2, h3, h4, h5, h6
@ -87,14 +98,16 @@ img
header#cabeceira header#cabeceira
{ {
margin-bottom: 0.625rem; margin-bottom: 1.125rem;
padding: 0.625rem; padding: 0.625rem;
box-shadow: 0px 0 0.625rem rgb(var(--fondo_oscuro), var(--sombra)); box-shadow: 0px 16px 24px 2px rgba(0, 0, 0, 0.14),
0px 6px 30px 5px rgba(0, 0, 0, 0.12),
0px 8px 10px -5px rgba(0, 0, 0, 0.2);
} }
header#cabeceira input[type="checkbox"] header#cabeceira input#interruptor
{ {
display: block; display: block;
@ -135,7 +148,7 @@ header#cabeceira .interruptor .linna
border-radius: 0.625rem; border-radius: 0.625rem;
background: rgb(var(--fondo_oscuro)); background: rgb(var(--color_realce));
} }
header#cabeceira .interruptor .linna1 header#cabeceira .interruptor .linna1
@ -166,11 +179,11 @@ nav#menu
padding: 0; padding: 0;
border-right: 2px solid rgb(var(--fondo_oscuro)); border-right: 2px solid rgb(var(--color_realce));
color: var(--fondo_oscuro); color: rgb(var(--color_realce));
background-color: rgb(var(--fondo_principal)); background-color: rgb(var(--color_principal));
transform: translateX(-100%); transform: translateX(-100%);
transition: transform 0.5s; transition: transform 0.5s;
@ -178,7 +191,13 @@ nav#menu
nav#menu a nav#menu a
{ {
color: rgb(var(--fondo_oscuro)); color: rgb(var(--color_realce));
}
div#axustes
{
display: flex;
flex-direction: column;
} }
ul#idiomas ul#idiomas
@ -216,31 +235,31 @@ ul#idiomas li a
padding: 0.625rem; padding: 0.625rem;
border: 1px solid rgb(var(--fondo_oscuro)); border: 1px solid rgb(var(--color_realce));
text-decoration: none; text-decoration: none;
} }
ul#idiomas li.activo a ul#idiomas li.activo a
{ {
color: rgb(var(--fondo_principal)); color: rgb(var(--color_principal));
background-color: rgb(var(--fondo_oscuro)); background-color: rgb(var(--color_realce));
} }
nav#menu li a:focus nav#menu li a:focus
{ {
outline: 2px dotted rgb(var(--fondo_oscuro)); outline: 2px dotted rgb(var(--color_realce));
} }
ul#paxinas li ul#paxinas li
{ {
border-left: 0.625rem solid rgb(var(--fondo_principal)); border-left: 0.625rem solid rgb(var(--color_principal));
} }
ul#paxinas li:hover, ul#paxinas li.activo ul#paxinas li:hover, ul#paxinas li.activo
{ {
border-left: 0.625rem solid rgb(var(--fondo_oscuro)); border-left: 0.625rem solid rgb(var(--color_realce));
} }
ul#paxinas li a ul#paxinas li a
@ -252,34 +271,34 @@ ul#paxinas li a
text-decoration: none; text-decoration: none;
} }
header#cabeceira input[type="checkbox"]:checked ~ nav#menu header#cabeceira input#interruptor:checked ~ nav#menu
{ {
transform: translateX(0); transform: translateX(0);
} }
header#cabeceira input[type="checkbox"]:focus ~ .interruptor header#cabeceira input#interruptor:focus ~ .interruptor
{ {
outline: 2px dotted rgb(var(--fondo_oscuro)); outline: 2px dotted rgb(var(--color_realce));
} }
header#cabeceira input[type="checkbox"]:checked ~ .interruptor .linna1 header#cabeceira input#interruptor:checked ~ .interruptor .linna1
{ {
transform: rotate(45deg) scaleX(1.3); transform: rotate(45deg) scaleX(1.3);
} }
header#cabeceira input[type="checkbox"]:checked ~ .interruptor .linna2 header#cabeceira input#interruptor:checked ~ .interruptor .linna2
{ {
transform: scaleY(0); transform: scaleY(0);
} }
header#cabeceira input[type="checkbox"]:checked ~ .interruptor .linna3 header#cabeceira input#interruptor:checked ~ .interruptor .linna3
{ {
transform: rotate(-45deg) scaleX(1.3); transform: rotate(-45deg) scaleX(1.3);
} }
header#cabeceira input[type="checkbox"]:checked:focus ~ .interruptor header#cabeceira input#interruptor:checked:focus ~ .interruptor
{ {
outline: 2px dotted rgb(var(--fondo_oscuro)); outline: 2px dotted rgb(var(--color_realce));
} }
header#cabeceira div.contedor header#cabeceira div.contedor
@ -290,6 +309,105 @@ header#cabeceira div.contedor
justify-content: center; justify-content: center;
} }
div.tema
{
display: flex;
flex-direction: row;
justify-content: center;
margin-top: 20px;
}
.toggle
{
display: none;
}
.toggle::selection,
.toggle:after::selection,
.toggle:before::selection,
.toggle *::selection,
.toggle *:after::selection,
.toggle *:before::selection,
.toggle + .toggle-button::selection
{
background: none;
}
.toggle + .toggle-button
{
display: inline-block;
position: relative;
width: 4em;
height: 2em;
padding: 2px;
border: 2px solid rgb(var(--color_realce));
border-radius: 2em;
outline: 0;
cursor: pointer;
user-select: none;
transition: all .2s ease;
}
.toggle + .toggle-button:after,
.toggle + .toggle-button:before
{
display: block;
position: relative;
width: 50%;
height: 100%;
content: "";
}
.toggle + .toggle-button:after
{
left: 0;
border-radius: 1em;
background: rgba(var(--color_realce, 0.27));
content: "";
transition: all .2s ease;
}
.toggle + .toggle-button:before
{
display: none;
}
.toggle:checked + .toggle-button:after
{
left: 50%;
}
#icono_dia, #icono_noche
{
position: relative;
top: -3px;
width: 32px;
height: 32px;
margin: 0 7px;
cursor: pointer;
fill: rgb(var(--color_realce));
}
main#contido main#contido
{ {
flex: 1 0 auto; flex: 1 0 auto;
@ -330,9 +448,9 @@ footer#pe
padding: 1.25rem 0.625rem; padding: 1.25rem 0.625rem;
color: rgb(var(--color_oscuro)); color: rgb(var(--texto_realce));
background-color: rgb(var(--fondo_oscuro)); background-color: rgb(var(--color-pe));
} }
footer#pe p footer#pe p
@ -343,7 +461,7 @@ footer#pe p
footer#pe a footer#pe a
{ {
color: rgb(var(--color_oscuro)); color: rgb(var(--texto_realce));
} }
.contedor .contedor
@ -396,12 +514,23 @@ footer#pe a
justify-content: space-between; justify-content: space-between;
} }
header#cabeceira input[type="checkbox"], header#cabeceira input#interruptor,
header#cabeceira .interruptor header#cabeceira .interruptor
{ {
display: none; display: none;
} }
div#axustes
{
flex-direction: row;
gap: 20px;
}
div.tema
{
margin-top: 5px;
}
nav#menu nav#menu
{ {
position: initial; position: initial;

View file

@ -1 +1,80 @@
// Blank const selector_tema = document.querySelector("#selector_tema");
const preferencia_escura = window.matchMedia("(prefers-color-scheme: dark)");
function getCookie()
{
let name = "tema=";
let spli = document.cookie.split(';');
for(var j = 0; j < spli.length; j++)
{
let char = spli[j];
while (char.charAt(0) == ' ')
{
char = char.substring(1);
}
if(char.indexOf(name) == 0)
{
return char.substring(name.length, char.length);
}
}
return "";
}
function checkCookie()
{
var tema = getCookie();
if(tema != "")
{
switch(tema)
{
case 'dark':
selector_tema.checked = true;
document.body.classList.add("dark");
document.body.classList.remove("light");
break;
case 'light':
document.body.classList.add("light");
document.body.classList.remove("dark");
break;
}
document.cookie = "tema=" + tema + ";samesite=lax;path=/";
}
else
{
if(preferencia_escura.matches)
{
selector_tema.checked = true;
document.body.classList.add("dark");
document.body.classList.remove("light");
document.cookie = "tema=dark;samesite=lax;path=/";
}
}
}
checkCookie();
selector_tema.addEventListener("change", function()
{
var tema = '';
switch(selector_tema.checked)
{
case true:
tema = 'dark';
document.body.classList.add("dark");
document.body.classList.remove("light");
break;
case false:
tema = 'light';
document.body.classList.add("light");
document.body.classList.remove("dark");
break;
}
document.cookie = "tema=" + tema + ";samesite=lax;path=/";
});