6 Commits

Author SHA1 Message Date
felex67 fb9449ba46 mouse event fix 2026-07-12 03:59:21 +05:00
felex67 0b61352d7e comments reformatted 2026-07-12 02:53:52 +05:00
felex67 f861fec8e0 Minimal version finished 2026-06-23 03:25:47 +05:00
felex67 846a79b5a0 finished 2026-06-22 03:31:52 +05:00
felex67 c0ea3a1e23 1. aria-current added in button
2. set(): fixed name -> theme in for(){}
2026-06-20 11:38:25 +05:00
felex67 33729bc897 Minified version added 2026-06-20 03:50:42 +05:00
7 changed files with 177 additions and 3276 deletions
-2864
View File
File diff suppressed because it is too large Load Diff
-21
View File
@@ -1,21 +0,0 @@
<div id="btn-toggle" role="button" aria-label="toggle color scheme. current: system" tabindex="0">
<svg width="100%" height="100%" viewBox="0 0 135.46666 135.46667" version="1.1" id="button-toggle-theme-svg" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<path id="path1" style="opacity:inherit;fill:currentColor;fill-opacity:1;stroke:#171717;stroke-width:0" d="M 67.777258,12.777515 A 55,55 0 0 0 12.777515,67.777258 55,55 0 0 0 67.777258,122.77752 55,55 0 0 0 122.77752,67.777258 55,55 0 0 0 67.777258,12.777515 Z m -0.128157,4.95577 V 117.73338 A 50,50 0 0 1 17.733285,67.733333 50,50 0 0 1 67.649101,17.733285 Z"/></svg>
</div>
<script type="text/JavaScript">
const dummy = document.getElementById('btn-dummy');
const btn = document.getElementById('btn-toggle');
const btnText = document.getElementById('btn-text');
const themes = [{n: 'system', i: 'Sys'}, {n: 'light', i:'☀️'}, {n: 'dark', i: '🌙'}];
let index = 0;
function keydown(e) {
if (e.key == ' ' || e.key == 'Enter') {
btn.setAttribute('aria-label', 'toggle color scheme. current: ' + (themes[index = (index + 1) % themes.length].n));
btnText.innerHTML = themes[index].i;
dummy.focus();
btn.focus();
}
};
btn.addEventListener('keydown', keydown);
</script>
+7 -9
View File
@@ -52,14 +52,6 @@
--text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); --text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
--font-family: 'Arial', sans-serif; --font-family: 'Arial', sans-serif;
} }
.flxd-tm-color-scheme-old-terminal {
--bg-color: #222;
--text-color: #9d9;
--accent-color: #40a9ff;
--border-color: #444;
--text-shadow: 0px 0px 10px rgba(255, 255, 0, 0.9);
--font-family: Monospace;
}
body { body {
margin: auto; margin: auto;
@@ -108,5 +100,11 @@ a:hover, a:focus {
filter: drop-shadow(var(--text-shadow)); filter: drop-shadow(var(--text-shadow));
cursor: pointer; cursor: pointer;
background-color: rgba(150, 150, 150, 0.3); background-color: rgba(150, 150, 150, 0.3);
opacity: 0.6; transform:rotate(-360deg);
transition:transform 2s ease;
}
#flxd-tm-btn-toggle:hover, #flxd-tm-btn-toggle:focus {
transform:rotate(360deg);
transition:transform 2s ease;
} }
+1 -1
View File
@@ -1,2 +1,2 @@
<link rel="stylesheet" href="css/felexdev-themes.css"> <link rel="stylesheet" href="css/felexdev-themes.css">
<script src="js/felexdev-theme-manager.js"></script> <script src="js/felexdev-theme-manager-minified.js"></script>
+8
View File
@@ -0,0 +1,8 @@
/**
* @file felexdev-theme-manager.js
* @description Минимальная версия
* @version 0.0.1
* @author felex67 (admin@felexdev.ru)
* @license Apache2.0
*/
class ThemeManager {static #c={bid:'btn-toggle',btid:0,gpfx:'flxd-tm',tpfx:'color-scheme',svg:'<svg width="100%" height="100%" viewBox="0 0 135.46666 135.46667"version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"><path id="path1" style="opacity:100%;fill:currentColor;fill-opacity:1;stroke:#171717;stroke-width:0" d="M 67.777258,12.777515 A 55,55 0 0 0 12.777515,67.777258 55,55 0 0 0 67.777258,122.77752 55,55 0 0 0 122.77752,67.777258 55,55 0 0 0 67.777258,12.777515 Z m -0.128157,4.95577 V 117.73338 A 50,50 0 0 1 17.733285,67.733333 50,50 0 0 1 67.649101,17.733285 Z"/></svg>',mrqd:window.matchMedia('(prefers-color-scheme: dark)'),rqdh:null};static #cl=document.documentElement.classList;static #b=document.createElement('div');static #i=0;static #t=[];static toggle=()=>{this.#s((this.#i+1)%this.#t.length);};static #bclk=(e)=>{if(e.type==='click'||e.key==='Enter'||e.key===' ')this.#s((this.#i+1)%2)};static #stch=(e)=>{if(e.matches!=this.#i)this.#s(e.matches+0);};static{let c=this.#c;let b=this.#b;c.gpfx=c.gpfx+'-';c.tpfx=`${c.gpfx}${c.tpfx}-`;b.id=c.bid=c.gpfx+c.bid;b.tabIndex=c.btid;b.innerHTML=c.svg;b.setAttribute('aria-label', 'toggle color scheme');b.addEventListener('click',this.#bclk);b.addEventListener('keydown',this.#bclk);c.rqdh=c.mrqd.addEventListener('change',this.#stch);};static #at=(n)=>{this.#t.push({n:n,s:this.#c.tpfx+n});};static #s(i){if(i==this.#i)return;let m=this;m.#cl.replace(m.#t[m.#i].s,m.#t[i].s);m.#sv(m.#i=i);m.#b.setAttribute('aria-current',m.#t[i].n);};static #sv=(()=>{let s=()=>{console.error(this.#c.gpfx+'#sv: Невозможно сохранить тему, хранилище недоступно.');};try{this.#i=parseInt(localStorage.getItem(this.#c.tpfx))||0;s=()=>{try{localStorage.setItem(this.#c.tpfx,this.#i);}catch(e){console.error(e);}};}catch(e){console.error(this.#c.gpfx+'#sv-IIFE: localStorage не доступен.');}return s;})();static{let i=this.#i;let t=this.#t;this.#at('light');this.#at('dark');if(i>=t.length||i<0){console.error(`${this.#c.gpfx}bottom-static: В хранилище сохранён не валидный индекс '${i}'. Сброс на системную тему`);this.#i=this.#c.mrqd.matches+0;}this.#cl.add(t[i].s);this.#b.setAttribute('aria-current',t[i].n);};static set=(name)=>{let i=-1;for(let j=0;j<this.#t.length;j++){if(this.#t[j].n===name){i=j;break;}}if(i==-1){throw new Error(`Темы '${name}' не существует!.`);}this.#s(i);};static #_=()=>{window.removeEventListener('DOMContentLoaded',this.#_);document.body.appendChild(this.#b);};static {if(!document.body)window.addEventListener('DOMContentLoaded',this.#_);};};
File diff suppressed because one or more lines are too long
+1 -2
View File
@@ -1,11 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ru-RU" dir="ltr"> <html lang="ru-RU" dir="ltr">
<head> <head>
<meta name="generator" content="Hugo 0.147.9">
<script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<title>Подопытный</title> <title>Подопытный</title>
<link rel="stylesheet" href="css/felexdev-themes.css"> <link rel="stylesheet" href="css/felexdev-themes.css">
<script src="js/felexdev-theme-manager.js"></script> <script src="js/felexdev-theme-manager.js"></script>
</head> </head>