Skip to content

Commit

Permalink
Add: reverted unwanted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Patel07 committed Feb 4, 2024
1 parent bfac516 commit 7405b99
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 115 deletions.
66 changes: 0 additions & 66 deletions src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,69 +70,3 @@ tr.solved {
.table {
--bs-table-bg: rgba(0, 0, 0, 0) !important;
}

/*toggle switch styling*/
:root {
font: 700 16px/1 Verdana;
}

.switch {
position: relative;
display: inline-block;
width: 4.5em;
height: 2.125em;
}

.slider {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 2.125em;
background-color: #fff;
cursor: pointer;
transition: .4s;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 10px;
}

.slider::before {
content: "";
position: absolute;
height: 1.625em;
width: 1.625em;
left: 0.425em;
bottom: 0.25em;
border-radius: 50%;
background: #9c7dd2;
transition: .4s;
z-index: 2;
}

.control:checked + .switch .slider {
background: var(--bs-light-purple);
}

.control:checked + .switch .slider::before {
transform: translateX(calc(4.5em - 2.5em));
background: #fff;
}

.sun,
.moon {
height: 20px;
width: 20px;
z-index: 1000;
}


/*navbar formating overridding over bootstrap*/
@media (min-width: 992px) {
.navbar-expand-lg .navbar-nav {
flex-direction: row;
align-items: center;
}
}
58 changes: 27 additions & 31 deletions src/main/resources/static/theme-toggle.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
(function () {
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')

function updateToggle (darkMode) {
const checkbox = document.querySelector(".theme-toggle input[type='checkbox']")
if (checkbox) {
checkbox.checked = darkMode
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
let initialTheme
if (localStorage.getItem('darkmode-pref-set') === 'true') {
initialTheme = localStorage.getItem('darkMode') === 'true'
} else {
initialTheme = darkModeMediaQuery.matches
}

document.body.classList.toggle('dark-mode', darkMode)
localStorage.setItem('darkMode', darkMode)
localStorage.setItem('darkmode-pref-set', 'true')
}
function updateToggle (darkMode) {
document.querySelector(".theme-toggle input[type=radio][value='dark']").checked = darkMode
document.querySelector(".theme-toggle input[type=radio][value='light']").checked = !darkMode

document.body.classList.toggle('dark-mode', darkMode)
localStorage.setItem('darkMode', darkMode)
localStorage.setItem('darkmode-pref-set', 'true')
}

// Listen for system theme changes
darkModeMediaQuery.addEventListener('change', (e) => {
updateToggle(e.matches)
})
darkModeMediaQuery.addEventListener('change', (e) => {
const darkModeOn = e.matches
updateToggle(darkModeOn)
})

// Set up event listener and initial theme on page load
window.addEventListener('load', function () {
const checkbox = document.querySelector(".theme-toggle input[type='checkbox']")
if (checkbox) {
checkbox.addEventListener('change', function () {
updateToggle(checkbox.checked)
})
window.addEventListener('load', function () {
const radios = document.querySelectorAll('.theme-toggle input[type=radio]')
radios.forEach((radio) => {
radio.addEventListener('change', function (e) {
updateToggle(e.target.value === 'dark')
})
})

// Initialize theme based on user preference or system preference
let initialTheme
if (localStorage.getItem('darkmode-pref-set') === 'true') {
initialTheme = localStorage.getItem('darkMode') === 'true'
} else {
initialTheme = darkModeMediaQuery.matches
}
updateToggle(initialTheme)
}
})
updateToggle(initialTheme)
})
})()
27 changes: 9 additions & 18 deletions src/main/resources/templates/fragments/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,16 @@
<a class="dropdown-item" href="/about">About</a>
</ul>
</li>
<div class="theme-toggle navbar-text navbar-nav ms-3">
<input type="checkbox" id='theme-toggle-checkbox' class='control visually-hidden'>
<label for='theme-toggle-checkbox' class="switch">
<span class="slider round" th:attr="data-cy='dark-mode-checkbox'">
<svg class="sun" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="25" height="25" viewBox="0,0,256,256" style="fill:#000000;">
<g fill="#ffffff" fill-rule="nonzero" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal">
<g transform="scale(10.66667,10.66667)">
<path d="M11,0v3h2v-3zM4.22266,2.80859l-1.41406,1.41406l2.12109,2.12109l1.41406,-1.41406zM19.77734,2.80859l-2.12109,2.12109l1.41406,1.41406l2.12109,-2.12109zM12,5c-3.85415,0 -7,3.14585 -7,7c0,3.85415 3.14585,7 7,7c3.85415,0 7,-3.14585 7,-7c0,-3.85415 -3.14585,-7 -7,-7zM12,7c2.77327,0 5,2.22673 5,5c0,2.77327 -2.22673,5 -5,5c-2.77327,0 -5,-2.22673 -5,-5c0,-2.77327 2.22673,-5 5,-5zM0,11v2h3v-2zM21,11v2h3v-2zM4.92969,17.65625l-2.12109,2.12109l1.41406,1.41406l2.12109,-2.12109zM19.07031,17.65625l-1.41406,1.41406l2.12109,2.12109l1.41406,-1.41406zM11,21v3h2v-3z"></path>
</g>
</g>
</svg>
<svg class="moon" x="0px" y="0px" width="25" height="25" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill="#9c7dd2" d="M13 6V3M18.5 12V7M14.5 4.5H11.5M21 9.5H16M15.5548 16.8151C16.7829 16.8151 17.9493 16.5506 19 16.0754C17.6867 18.9794 14.7642 21 11.3698 21C6.74731 21 3 17.2527 3 12.6302C3 9.23576 5.02061 6.31331 7.92462 5C7.44944 6.05072 7.18492 7.21708 7.18492 8.44523C7.18492 13.0678 ..."></path>
</svg>
</span>
<div class="theme-toggle navbar-text">
<label>
<span class="visually-hidden">Light</span>
<input type="radio" value="light" name="theme">
<span class="checkmark" th:attr="data-cy='light-mode-radio'">☀️</span>
</label>
</div>


<label>
<span class="visually-hidden">Dark</span>
<input type="radio" value="dark" name="theme">
<span class="checkmark" th:attr="data-cy='dark-mode-radio'">🌜</span>
</ul>
<a th:if="${ctf_enabled != null && ctf_enabled == true}" class="nav-link disabled me-2" href="#"
tabindex="-1" aria-disabled="true" style="color:white">In CTF-mode</a>
Expand Down

0 comments on commit 7405b99

Please sign in to comment.