From 75d2fe544266ec61b898cda16e5d49a3970f8c39 Mon Sep 17 00:00:00 2001 From: riley Date: Mon, 13 Nov 2023 14:06:59 -0500 Subject: [PATCH] still trying to style checkboxes --- luasrc/app.js | 133 ++++++++++++++++++++++++------------------- luasrc/gaya/gaya.css | 14 ++--- template/header.htm | 16 ------ 3 files changed, 81 insertions(+), 82 deletions(-) diff --git a/luasrc/app.js b/luasrc/app.js index 76c0de5..8ee7e3b 100644 --- a/luasrc/app.js +++ b/luasrc/app.js @@ -1,64 +1,79 @@ (function () { - // your page initialization code here - // the DOM will be available here - - const toggler = document.querySelector(".toggler"); - console.log(toggler); - toggler.addEventListener( - "click", - function (e) { - const element = document.querySelector(".navbar"); - element.classList.toggle("active"); - }, - false - ); - - const isDark = localStorage.getItem("isDark"); - if (isDark == 1) { + // your page initialization code here + // the DOM will be available here + + const toggler = document.querySelector(".toggler"); + console.log(toggler); + toggler.addEventListener( + "click", + function (e) { + const element = document.querySelector(".navbar"); + element.classList.toggle("active"); + }, + false + ); + + const isDark = localStorage.getItem("isDark"); + if (isDark == 1) { + const element = document.querySelector("body"); + element.classList.add("dark"); + } + const themetoggler = document.querySelector(".themetoggler"); + themetoggler.addEventListener( + "click", + function (e) { + e.preventDefault(); const element = document.querySelector("body"); - element.classList.add("dark"); - } - const themetoggler = document.querySelector(".themetoggler"); - themetoggler.addEventListener( - "click", - function (e) { - e.preventDefault(); - const element = document.querySelector("body"); - element.classList.toggle("dark"); + element.classList.toggle("dark"); + + const isDark = localStorage.getItem("isDark"); + localStorage.setItem("isDark", isDark == 1 ? 0 : 1); + }, + false + ); + + document.addEventListener("DOMContentLoaded", function() { + // Move all your code here - const isDark = localStorage.getItem("isDark"); - localStorage.setItem("isDark", isDark == 1 ? 0 : 1); - }, - false - ); - var checkboxes = document.querySelectorAll('.cbi-checkbox input[type="checkbox"]'); - - checkboxes.forEach(function(checkbox) { - var switchElement = document.createElement('label'); - switchElement.className = 'switch'; - - var input = document.createElement('input'); - input.type = 'checkbox'; - input.checked = checkbox.checked; - switchElement.appendChild(input); - - var slider = document.createElement('span'); - slider.className = 'slider'; - switchElement.appendChild(slider); - - // Add the switch to the div wrapping the checkbox - checkbox.parentNode.insertBefore(switchElement, checkbox); - - // Hide the original checkbox - checkbox.style.display = 'none'; - - input.addEventListener('change', function() { - checkbox.checked = this.checked; - }); - - var observer = new MutationObserver(function() { + var mutationObserver = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + var checkboxes = document.querySelectorAll('.cbi-checkbox input[type="checkbox"]'); + + checkboxes.forEach(function(checkbox) { + // Check if toggle switch is already created + if (!checkbox.nextSibling || checkbox.nextSibling.className !== 'switch') { + var switchElement = document.createElement('label'); + switchElement.className = 'switch'; + + var input = document.createElement('input'); + input.type = 'checkbox'; input.checked = checkbox.checked; + switchElement.appendChild(input); + + var slider = document.createElement('span'); + slider.className = 'slider'; + switchElement.appendChild(slider); + + // Add the switch to the div wrapping the checkbox + checkbox.parentNode.insertBefore(switchElement, checkbox); + + // Hide the original checkbox + checkbox.style.display = 'none'; + + input.addEventListener('change', function() { + checkbox.checked = this.checked; + }); + + var observer = new MutationObserver(function() { + input.checked = checkbox.checked; + }); + observer.observe(checkbox, { attributes: true }); + } }); - observer.observe(checkbox, { attributes: true }); - }); - })(); \ No newline at end of file + }); + }); + + mutationObserver.observe(document.documentElement, { childList: true, subtree: true }); + }); + +})(); // Make sure to include this closing partz \ No newline at end of file diff --git a/luasrc/gaya/gaya.css b/luasrc/gaya/gaya.css index 16a4374..a574ea9 100644 --- a/luasrc/gaya/gaya.css +++ b/luasrc/gaya/gaya.css @@ -3029,7 +3029,7 @@ strong { } /* The switch - the box around the slider */ -.switch { +.cbi-checkbox .switch { position: relative; display: inline-block; width: 60px; @@ -3037,14 +3037,14 @@ strong { } /* Hide default HTML checkbox */ -.switch input { +.cbi-checkbox .switch input { opacity: 0; width: 0; height: 0; } /* The slider */ -.slider { +.cbi-checkbox .switch .slider { position: absolute; cursor: pointer; top: 0; @@ -3055,7 +3055,7 @@ strong { transition: .4s; } -.slider:before { +.cbi-checkbox .switch .slider:before { position: absolute; content: ""; height: 26px; @@ -3066,14 +3066,14 @@ strong { transition: .4s; } -input:checked + .slider { +.cbi-checkbox .switch input:checked + .slider { background-color: #2196F3; } -input:focus + .slider { +.cbi-checkbox .switch input:focus + .slider { box-shadow: 0 0 1px #2196F3; } -input:checked + .slider:before { +.cbi-checkbox .switch input:checked + .slider:before { transform: translateX(26px); } \ No newline at end of file diff --git a/template/header.htm b/template/header.htm index f2e14ba..8ef39a2 100644 --- a/template/header.htm +++ b/template/header.htm @@ -60,22 +60,6 @@ -