-
Notifications
You must be signed in to change notification settings - Fork 32
Add theme support #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add theme support #118
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1be1353
Add applyTheme support for overriding existing CSS variables
nielsent478 df15ed6
Update themes.js comments and remove auto-execution
nielsent478 694c545
Add theme support on the web-server
nielsent478 767e3a2
Fixed some bugs on themes.js
nielsent478 2d434ea
Add default/none option and reset logic
nielsent478 9dce01f
Fix theme objects
nielsent478 b3e337d
Update themes.js
nielsent478 ab43e71
Update themes.js
nielsent478 b420088
Update themes.js
nielsent478 3776205
Hiding the themes selection tab
nielsent478 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,73 @@ | ||
| //Applies a theme by overriding CSS variables using a JSON object | ||
| function applyTheme(theme) { | ||
| if (!theme) { //empty/null/undefined = reset | ||
| document.documentElement.removeAttribute("style"); | ||
| return; | ||
| } | ||
| //For each entry (element) inside of each theme category that is applied | ||
| for (const key in theme) { | ||
| //Apply each color variable to the root of the document | ||
| document.documentElement.style.setProperty(`--${key}`, theme[key]); | ||
| } | ||
| } | ||
|
|
||
| //Run it in console dynamically after hosted | ||
| window.applyTheme = applyTheme; | ||
|
nielsent478 marked this conversation as resolved.
|
||
|
|
||
| //Avaliable themes that can be applied | ||
| const themes = { | ||
| light: { | ||
| "editorBackgroundColour": "#8d8d8d", | ||
| //"gutterColour": "#8d8d8d", | ||
| "shadowColour": "#8d8d8d", | ||
| "editorKeyword": "#28282B", | ||
| "editorComment": "#00A36C", | ||
| "editorLineNumber": "#353935", | ||
| "editorGutterBackground": "#202020", | ||
| "editorString": "#1f1f1f" | ||
| //More can be added from the colours.css file | ||
| }, | ||
| dark: { | ||
| "editorBackgroundColour": "#1e1e1e", | ||
| //"gutterColour": "#1e1e1e", | ||
| "shadowColour": "#1e1e1e", | ||
| "editorKeyword": "#FAF9F6", | ||
| "editorComment": "#228B22", | ||
| "editorLineNumber": "#FFFFF0", | ||
| "editorGutterBackground": "#dcdcdc", | ||
| "editorString": "#fdfdfd" | ||
| }, | ||
| "professional-grey": { | ||
| "editorBackgroundColour": "#2b2b2b", | ||
| //"gutterColour": "#2b2b2b", | ||
| "shadowColour": "#2b2b2b", | ||
| "editorKeyword": "#FAF9F6", | ||
| "editorComment": "#5F8575", | ||
| "editorLineNumber": "#FFFFFF", | ||
| "editorGutterBackground": "#e0e0e0" | ||
| }, | ||
| space: { | ||
| "editorBackgroundColour": "#0d1117", | ||
| //"gutterColour": "#0d1117", | ||
| "shadowColour": "#0d1117", | ||
| "editorKeyword": "#A7C7E7", | ||
| "editorComment": "#191970", | ||
| "editorLineNumber": "#191970", | ||
| "editorGutterBackground": "#c9d1d9" | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| //Build a simple <select id="themeSelection"> | ||
| //Wait until the page Content has been loaded | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| const sel = document.getElementById("themeSelection"); | ||
| //Stop if the <select> isn’t there | ||
| if (!sel) return; | ||
| sel.add(new Option("default / none", "")); //Blank value = go back to default | ||
| //Add every theme as an option | ||
| Object.keys(themes).forEach(name => sel.add(new Option(name, name))); //Visible text, value | ||
| //Change the theme when the user picks something | ||
| sel.onchange = () => applyTheme(themes[sel.value]); | ||
| }); | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.