From be25603bd42f6c7258a430c0820f8c44efb64582 Mon Sep 17 00:00:00 2001 From: riley Date: Mon, 13 Nov 2023 13:28:22 -0500 Subject: [PATCH] still trying to style checkboxes --- luasrc/app.js | 33 +++++++++++++++++++++++++++++++-- template/header.htm | 37 ------------------------------------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/luasrc/app.js b/luasrc/app.js index 6d4a69c..76c0de5 100644 --- a/luasrc/app.js +++ b/luasrc/app.js @@ -31,5 +31,34 @@ }, false ); - })(); - \ No newline at end of file + 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() { + input.checked = checkbox.checked; + }); + observer.observe(checkbox, { attributes: true }); + }); + })(); \ No newline at end of file diff --git a/template/header.htm b/template/header.htm index 6c22f61..f2e14ba 100644 --- a/template/header.htm +++ b/template/header.htm @@ -60,43 +60,6 @@ -