-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactors folder structure and adds share function
- Loading branch information
1 parent
b8cf0ed
commit 1b43521
Showing
5 changed files
with
77 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { AceEditor } from "./editor.js"; | ||
const toggleBtn = document.getElementsByClassName("toggle-theme")[0]; | ||
|
||
window.addEventListener("load", () => { | ||
let theme = localStorage.getItem("theme"); | ||
if (theme === "dark") { | ||
toggleTheme("dark"); | ||
} | ||
}); | ||
|
||
toggleBtn.addEventListener("click", function () { | ||
let currTheme = localStorage.getItem("theme"); | ||
if (currTheme === "dark") toggleTheme("light"); | ||
else toggleTheme("dark"); | ||
}); | ||
|
||
export function applyThemeToEditors() { | ||
const theme = localStorage.getItem("theme"); | ||
const exprEditor = new AceEditor( | ||
localStorage.getItem(localStorageModeKey) ?? "cel" | ||
); | ||
const editorsInputEl = document.querySelectorAll( | ||
".editor__input.data__input" | ||
); | ||
|
||
if (theme === "dark") { | ||
exprEditor.editor.setTheme("ace/theme/tomorrow_night"); | ||
editorsInputEl.forEach((editor) => { | ||
new AceEditor(editor.id).editor.setTheme("ace/theme/tomorrow_night"); | ||
}); | ||
} else { | ||
exprEditor.editor.setTheme("ace/theme/clouds"); | ||
editorsInputEl.forEach((editor) => { | ||
new AceEditor(editor.id); | ||
}); | ||
} | ||
} | ||
|
||
function toggleTheme(theme) { | ||
let toggleIcon = document.getElementsByClassName("toggle-theme__icon")[0]; | ||
let celLogo = document.getElementsByClassName("cel-logo")[0]; | ||
let copyIcon = document.querySelectorAll(".editor-copy-icon"); | ||
|
||
if (theme === "dark") { | ||
document.body.classList.add("dark"); | ||
toggleIcon.src = "./assets/img/moon.svg"; | ||
celLogo.src = "./assets/img/logo-dark.svg"; | ||
copyIcon[0].src = "./assets/img/copy-dark.svg"; | ||
copyIcon[1].src = "./assets/img/copy-dark.svg"; | ||
} else { | ||
document.body.classList.remove("dark"); | ||
toggleIcon.src = "./assets/img/sun.svg"; | ||
celLogo.src = "./assets/img/logo.svg"; | ||
copyIcon[0].src = "./assets/img/copy.svg"; | ||
copyIcon[1].src = "./assets/img/copy.svg"; | ||
} | ||
localStorage.setItem("theme", theme); | ||
applyThemeToEditors(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters