Add dark mode

This commit is contained in:
James Musselman 2023-11-30 01:32:08 -06:00
parent bcd45d9006
commit 2588ef9729
5 changed files with 72 additions and 36 deletions

33
static/build/darkmode.js Normal file
View file

@ -0,0 +1,33 @@
// Check if user preference for dark mode is stored in a cookie
let darkModeEnabled = (document.cookie.indexOf('darkModeEnabled=true') !== -1);
// Apply dark mode based on the user's preference
function applyDarkMode() {
const theme = darkModeEnabled ? "dark" : "light";
document.documentElement.setAttribute("data-bs-theme", theme);
// Change the icon based on the theme
const icon = darkModeEnabled ? "fa-sun" : "fa-moon";
const iconElement = document.getElementById("darkModeIcon");
iconElement.classList.remove(darkModeEnabled ? "fa-moon" : "fa-sun");
iconElement.classList.add(icon);
}
// Toggle dark mode and store the preference in a cookie
function toggleDarkMode() {
darkModeEnabled = !darkModeEnabled;
const expirationDate = new Date();
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
const cookieValue = `darkModeEnabled=${darkModeEnabled}; expires=${expirationDate.toUTCString()}`;
document.cookie = cookieValue;
applyDarkMode();
}
// Add event listener to the toggle button if it exists
const darkModeButton = document.getElementById("darkModeButton");
if (darkModeButton) {
darkModeButton.addEventListener("click", toggleDarkMode);
}
// Apply dark mode on page load
applyDarkMode();

View file

@ -1,15 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en_US"> <html lang="en_US" data-bs-theme="dark">
<head> <head>
<title>Edit File</title> <title>Edit File</title>
<link rel="stylesheet" type="text/css" <link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"> href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css">
<link rel="stylesheet" type="text/css" <link rel="stylesheet" type="text/css"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"> href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script> <script>
</script> </script>
@ -65,49 +62,45 @@
onclick="formatText('heading', 'h6')">Heading 6</button></li> onclick="formatText('heading', 'h6')">Heading 6</button></li>
</ul> </ul>
</div> </div>
<button type="button" class="btn btn-light" onclick="formatText('bold')" aria-label="Bold"><i <button type="button" class="btn" onclick="formatText('bold')" aria-label="Bold"><i
class="fas fa-bold"></i></button> class="fas fa-bold"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('italic')"><i <button type="button" class="btn " onclick="formatText('italic')"><i
class="fas fa-italic"></i></button> class="fas fa-italic"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('underline')"><i <button type="button" class="btn " onclick="formatText('underline')"><i
class="fas fa-underline"></i></button> class="fas fa-underline"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('strikeThrough')"><i <button type="button" class="btn " onclick="formatText('strikeThrough')"><i
class="fas fa-strikethrough"></i></button> class="fas fa-strikethrough"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('removeFormat')"><i <button type="button" class="btn " onclick="formatText('removeFormat')"><i
class="fas fa-eraser"></i></button> class="fas fa-eraser"></i></button>
<button class="btn btn-light" onclick="addTable()"><i class="fas fa-table" <button class="btn " onclick="addTable()"><i class="fas fa-table" disabled></i></button>
disabled></i></button> <button class="btn " onclick="addVideo()"><i class="fas fa-video"></i></button>
<button class="btn btn-light" onclick="addVideo()"><i class="fas fa-video"></i></button>
<button type="button" class="btn btn-light" onclick="undo()"><i <button type="button" class="btn " onclick="undo()"><i class="fas fa-undo"></i></button>
class="fas fa-undo"></i></button> <button type="button" class="btn " onclick="redo()"><i class="fas fa-redo"></i></button>
<button type="button" class="btn btn-light" onclick="redo()"><i <button type="button" class="btn " onclick="formatText('insertUnorderedList')"><i
class="fas fa-redo"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('insertUnorderedList')"><i
class="fas fa-list-ul"></i></button> class="fas fa-list-ul"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('insertOrderedList')"><i <button type="button" class="btn " onclick="formatText('insertOrderedList')"><i
class="fas fa-list-ol"></i></button> class="fas fa-list-ol"></i></button>
<button type="button" class="btn btn-light" onclick="insertImage()"><i <button type="button" class="btn " onclick="insertImage()"><i class="fas fa-image"></i></button>
class="fas fa-image"></i></button> <button type="button" class="btn " onclick="formatText('formatBlock', '<blockquote>')"
<button type="button" class="btn btn-light" onclick="formatText('formatBlock', '<blockquote>')"
disabled><i class="fas fa-quote-right"></i></button> disabled><i class="fas fa-quote-right"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('formatBlock', '<code>')" <button type="button" class="btn " onclick="formatText('formatBlock', '<code>')" disabled><i
disabled><i class="fas fa-code"></i></button> class="fas fa-code"></i></button>
<button type="button" class="btn btn-light" onclick="formatText('insertHorizontalRule')"><i <button type="button" class="btn " onclick="formatText('insertHorizontalRule')"><i
class="fas fa-grip-lines"></i></button> class="fas fa-grip-lines"></i></button>
<button class="btn btn-light" onclick="insertLink()"><i class="fas fa-link"></i></button> <button class="btn " onclick="insertLink()"><i class="fas fa-link"></i></button>
</div> </div>
<div> <div>
<button class="btn btn-light" onclick="confirmOverwrite()"> <i class="fa fa-notes-medical"></i> <button class="btn " onclick="confirmOverwrite()"> <i class="fa fa-notes-medical"></i>
Templates</i></button> Templates</i></button>
<button class="btn btn-light" onclick="saveForm()"><i class="fas fa-save"></i></button> <button class="btn " onclick="saveForm()"><i class="fas fa-save"></i></button>
<button class="btn btn-light" onclick="confirmDeletion()"><i class="fas fa-trash"></i></button> <button class="btn " onclick="confirmDeletion()"><i class="fas fa-trash"></i></button>
</div> </div>
</div> </div>
</div> </div>
@ -203,6 +196,7 @@
}); });
} }
</script> </script>
<script src="/static/build/darkmode.js" type="text/javascript"></script>
</body> </body>

View file

@ -1,10 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en_US"> <html lang="en_US" data-bs-theme="dark">
<head> <head>
<title>Notatio</title> <title>Notatio</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/static/favicon.ico" type="image/x-icon"> <link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<!-- Font Awesome CSS for spinner --> <!-- Font Awesome CSS for spinner -->
<link rel="stylesheet" type="text/css" <link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
@ -14,7 +15,7 @@
</head> </head>
<body class="d-flex flex-column min-vh-100 "> <body class="d-flex flex-column min-vh-100 ">
<nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom p-2"> <nav class="navbar navbar-expand-lg border-bottom p-2">
<a class="navbar-brand" href="/"> <a class="navbar-brand" href="/">
<img src="/static/favicon.ico" alt="" width="24" height="24" class="d-inline-block align-text-top"> <img src="/static/favicon.ico" alt="" width="24" height="24" class="d-inline-block align-text-top">
Notatio Notatio
@ -31,6 +32,10 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#signupModal">Sign up</a> <a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#signupModal">Sign up</a>
</li> </li>
<li class="nav-item">
<button id="darkModeButton" class="btn">
<i id="darkModeIcon" class="fas fa-sun"></i>
</button>
</ul> </ul>
</div> </div>
</nav> </nav>
@ -44,7 +49,7 @@
Notatio provides a user-friendly interface combined with robust features, making it the perfect choice for Notatio provides a user-friendly interface combined with robust features, making it the perfect choice for
developers, writers, and anyone who interacts with text on a daily basis. developers, writers, and anyone who interacts with text on a daily basis.
</p> </p>
<p><strong>Notatio is alpha software! Do not use it as your daily driver!</strong></p> <p><strong>Notatio is <u>currently</u> an alpha software! Do not use it as your daily driver!</strong></p>
<h1 class="mt-4">Text Editor Comparison</h1> <h1 class="mt-4">Text Editor Comparison</h1>
<div class="table-responsive"> <div class="table-responsive">
@ -206,7 +211,7 @@
</div> </div>
</main> </main>
<footer class="footer mt-auto"> <footer class="footer mt-auto">
<div class="container d-flex justify-content-center py-3 bg-light "> <div class="container d-flex justify-content-center py-3">
<a href="https://codeberg.org/notatio/notatio#download" class="mx-2 text-muted">Download</a> <a href="https://codeberg.org/notatio/notatio#download" class="mx-2 text-muted">Download</a>
<a href="https://codeberg.org/notatio/notatio/wiki" class="mx-2 text-muted">Documentation</a> <a href="https://codeberg.org/notatio/notatio/wiki" class="mx-2 text-muted">Documentation</a>
<a href="https://codeberg.org/notatio/notatio/issues" class="mx-2 text-muted">Report Issues</a> <a href="https://codeberg.org/notatio/notatio/issues" class="mx-2 text-muted">Report Issues</a>
@ -215,6 +220,7 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="/static/build/index.js" type="text/javascript"></script> <script src="/static/build/index.js" type="text/javascript"></script>
<script src="/static/build/darkmode.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html data-bs-theme="dark">
<head> <head>
<title>List Files</title> <title>List Files</title>
@ -7,6 +7,7 @@
<link rel="icon" href="/static/favicon.ico" type="image/x-icon"> <link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="/static/build/list.js" type="text/javascript"></script> <script src="/static/build/list.js" type="text/javascript"></script>
<script src="/static/build/darkmode.js" type="text/javascript"></script>
</head> </head>
<body> <body>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en_US"> <html lang="en_US" data-bs-theme="dark">
<head> <head>
<title>Notatio | Welcome</title> <title>Notatio | Welcome</title>
@ -7,6 +7,7 @@
<link rel="stylesheet" type="text/css" href="/static/style.css"> <link rel="stylesheet" type="text/css" href="/static/style.css">
<link rel="icon" href="/static/favicon.ico" type="image/x-icon"> <link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head> </head>
<body> <body>
@ -44,6 +45,7 @@
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="/static/build/darkmode.js" type="text/javascript"></script>
</body> </body>
</html> </html>