-
Notifications
You must be signed in to change notification settings - Fork 438
WIP add simple dark mode #58
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,27 @@ | ||
(() => { | ||
const render = (dark, toggle) => { | ||
if (dark) { | ||
document.body.classList.add('dark-theme'); | ||
toggle.innerHTML = 'Light Mode'; | ||
} else { | ||
document.body.classList.remove('dark-theme'); | ||
toggle.innerHTML = 'Dark Mode'; | ||
} | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const toggle = document.getElementById('dark-toggle'); | ||
let prefersDarkScheme = | ||
JSON.parse(localStorage['darkMode'] || 'null') || | ||
window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
render(prefersDarkScheme, toggle); | ||
|
||
toggle.addEventListener('click', (event) => { | ||
console.log('toggling'); | ||
event.preventDefault(); | ||
prefersDarkScheme = !prefersDarkScheme; | ||
localStorage['darkMode'] = prefersDarkScheme; | ||
render(prefersDarkScheme, toggle); | ||
}); | ||
}); | ||
})(); |
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
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 |
---|---|---|
@@ -1,58 +1,71 @@ | ||
const sat = document.getElementById('docsat'); | ||
let rating = 0; | ||
let submitted = false; | ||
(() => { | ||
const sat = document.getElementById('docsat'); | ||
let rating = 0; | ||
let submitted = false; | ||
|
||
const star = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"> | ||
const star = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"> | ||
<path fill="currentColor" d="M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z" /> | ||
</svg>` | ||
const starOutline = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"> | ||
</svg>`; | ||
const starOutline = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"> | ||
<path fill="currentColor" d="M12,15.39L8.24,17.66L9.23,13.38L5.91,10.5L10.29,10.13L12,6.09L13.71,10.13L18.09,10.5L14.77,13.38L15.76,17.66M22,9.24L14.81,8.63L12,2L9.19,8.63L2,9.24L7.45,13.97L5.82,21L12,17.27L18.18,21L16.54,13.97L22,9.24Z" /> | ||
</svg>` | ||
</svg>`; | ||
|
||
select = (n) => (event) => { | ||
console.log('event', event) | ||
if (n + 1 === rating) { | ||
rating = 0 | ||
} else { | ||
rating = n + 1 | ||
} | ||
submitted = false; | ||
render(); | ||
const path = 'https://docs2-cl-default-rtdb.firebaseio.com/allratings.json'; | ||
const data = {rating,time:Date.now(),url:window.location.href}; | ||
SULX.post(path, JSON.stringify(data)); | ||
} | ||
render = () => { | ||
sat.innerHTML = ` | ||
let render; | ||
let select = (n) => (event) => { | ||
console.log('event', event); | ||
if (n + 1 === rating) { | ||
rating = 0; | ||
} else { | ||
rating = n + 1; | ||
} | ||
submitted = false; | ||
render(); | ||
const path = 'https://docs2-cl-default-rtdb.firebaseio.com/allratings.json'; | ||
const data = { rating, time: Date.now(), url: window.location.href }; | ||
SULX.post(path, JSON.stringify(data)); | ||
}; | ||
render = () => { | ||
sat.innerHTML = ` | ||
<div id="starBox"> | ||
</div> | ||
<div id="docsatFeedback" style="display:${rating && !submitted ? 'block' : 'none'};position:absolute;right:0;background-color:white;border:1px solid #CCC;padding:8px;"> | ||
<div id="docsatFeedback" style="display:${ | ||
rating && !submitted ? 'block' : 'none' | ||
};position:absolute;right:0;background-color:white;border:1px solid #CCC;padding:8px;"> | ||
Tell us more about your experience. | ||
<form id="docsatForm"> | ||
<textarea name="feedback" style="width:100%;"></textarea><br/> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</div>`; | ||
let stars = '' | ||
for (let i = 0; i < 5; i++) { | ||
let child = document.createElement('span') | ||
if (rating > i) { | ||
child.innerHTML = star; | ||
} else { | ||
child.innerHTML = starOutline; | ||
let stars = ''; | ||
for (let i = 0; i < 5; i++) { | ||
let child = document.createElement('span'); | ||
if (rating > i) { | ||
child.innerHTML = star; | ||
} else { | ||
child.innerHTML = starOutline; | ||
} | ||
child.addEventListener('click', select(i)); | ||
document.getElementById('starBox').appendChild(child); | ||
} | ||
child.addEventListener('click', select(i)) | ||
document.getElementById('starBox').appendChild(child); | ||
} | ||
|
||
document.getElementById('docsatForm').addEventListener('submit',(event) => { | ||
event.preventDefault(); | ||
|
||
submitted = true; | ||
const path = 'https://docs2-cl-default-rtdb.firebaseio.com/feedback.json'; | ||
const data = {rating,time:Date.now(),msg:event.target[0].value,url:window.location.href}; | ||
SULX.post(path, JSON.stringify(data)); | ||
render(); | ||
}); | ||
} | ||
render() | ||
document | ||
.getElementById('docsatForm') | ||
.addEventListener('submit', (event) => { | ||
event.preventDefault(); | ||
|
||
submitted = true; | ||
const path = | ||
'https://docs2-cl-default-rtdb.firebaseio.com/feedback.json'; | ||
const data = { | ||
rating, | ||
time: Date.now(), | ||
msg: event.target[0].value, | ||
url: window.location.href, | ||
}; | ||
SULX.post(path, JSON.stringify(data)); | ||
render(); | ||
}); | ||
}; | ||
render(); | ||
})(); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StephenFluin why put the toggle button at the bottom? Wouldn't it be better to put it at the top of the page ?