From 2d3bcb7b7233860f37cff31b2dbe124e545cff6d Mon Sep 17 00:00:00 2001 From: abourtnik Date: Thu, 7 Nov 2024 13:51:16 +0100 Subject: [PATCH] Add autoplay checkbox --- resources/js/app.js | 28 ++++++-- resources/sass/swith.scss | 16 ++--- .../views/layouts/menus/account.blade.php | 6 +- .../layouts/menus/sidebars/front.blade.php | 72 +++++++++++++------ resources/views/videos/show.blade.php | 9 ++- 5 files changed, 91 insertions(+), 40 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index 90b6abb3..51b51584 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -90,21 +90,39 @@ ajaxButtons.map(element => element.addEventListener('click', async e => { // THEME -const switchers = [...document.getElementsByClassName('theme-switcher')]; +const themesSwitchers = [...document.getElementsByClassName('theme-switcher')]; const theme = localStorage.getItem("theme"); if (theme && theme === 'dark') { - if (switchers) { - switchers.forEach(switcher => switcher.checked = true) + if (themesSwitchers) { + themesSwitchers.forEach(switcher => switcher.checked = true) } document.documentElement.setAttribute('data-bs-theme', 'dark') } -switchers.forEach(switcher => { +themesSwitchers.forEach(switcher => { switcher.addEventListener('change', e => { const theme = e.currentTarget.checked ? 'dark' : 'light'; document.documentElement.setAttribute('data-bs-theme', theme) localStorage.setItem("theme", theme); - switchers.filter(switcher => switcher.id !== e.currentTarget.id).forEach(switcher => switcher.checked = e.currentTarget.checked) + themesSwitchers.filter(switcher => switcher.id !== e.currentTarget.id).forEach(switcher => switcher.checked = e.currentTarget.checked) + }) +}) + +// AUTOPLAY + +const autoplaySwitchers = [...document.getElementsByClassName('autoplay-switcher')]; + +const autoplay = JSON.parse(localStorage.getItem("autoplay-video") || true); +if (autoplay) { + if (autoplaySwitchers) { + autoplaySwitchers.forEach(switcher => switcher.checked = true) + } +} + +autoplaySwitchers.forEach(switcher => { + switcher.addEventListener('change', e => { + localStorage.setItem("autoplay-video", e.currentTarget.checked); + autoplaySwitchers.filter(switcher => switcher.id !== e.currentTarget.id).forEach(switcher => switcher.checked = e.currentTarget.checked) }) }) diff --git a/resources/sass/swith.scss b/resources/sass/swith.scss index b34c887f..7c15729b 100644 --- a/resources/sass/swith.scss +++ b/resources/sass/swith.scss @@ -1,4 +1,4 @@ -.theme-switch { +.input-switch { input { position: absolute; top: 0; @@ -48,28 +48,28 @@ opacity: 1; transition: .3s; } - .icon-moon { + .icon-on { color: #d4dcff; } } -.theme-switch input:checked+label .switch::before { +.input-switch input:checked+label .switch::before { transform: translateX(31px); background: #5396e7 !important; } -.theme-switch input:checked+label .switch { - background: #0f1224 !important; +.input-switch input:checked+label .switch { + background: var(--bs-primary-bg-subtle) !important } -.theme-switch input:not(:checked)+label .icon-moon { +.input-switch input:not(:checked)+label .icon-on { opacity: 0; } -.theme-switch input:checked+label .icon-sun { +.input-switch input:checked+label .icon-off { opacity: 0; } -.theme-switch input:checked+label .icon { +.input-switch input:checked+label .icon { transform: translateX(31px); } diff --git a/resources/views/layouts/menus/account.blade.php b/resources/views/layouts/menus/account.blade.php index db65e3d3..ef357206 100644 --- a/resources/views/layouts/menus/account.blade.php +++ b/resources/views/layouts/menus/account.blade.php @@ -56,14 +56,14 @@ @endforeach -
+