Skip to content
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

Fix dark mode slider #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 67 additions & 68 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,40 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<!-- CSS Stylesheet -->
<link id="stylesheet" rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
<link rel="stylesheet" type="text/css" href="styles/theme.css">

<script>

var url = "//unpkg.com/docsify/themes/dark.css";
var url2 = "//unpkg.com/docsify/themes/vue.css";
var stylesheet = document.getElementById("stylesheet");
var show = false;
var darkmode = localStorage.getItem('darkmode')
function setStyleSheet() {
const slider = document.querySelector(".slider");
slider.classList.add("smooth");
document.body.classList.add("darkmode");
setTimeout(function()
{
document.querySelector(".slider").classList.remove("smooth");
},500);
if (show) {
stylesheet.setAttribute('href', url2);
localStorage.setItem('darkmode', "disabled");
show = !show;
}
else {
stylesheet.setAttribute('href', url);
localStorage.setItem('darkmode', "enabled");
show = !show;
}
};


</script>
<link rel="stylesheet" type="text/css" href="styles/theme.css">

<script>

var url = "//unpkg.com/docsify/themes/dark.css";
var url2 = "//unpkg.com/docsify/themes/vue.css";
var stylesheet = document.getElementById("stylesheet");
var show = false;
var darkmode = localStorage.getItem('darkmode')
function setStyleSheet() {
const slider = document.querySelector(".slider");
slider.classList.add("smooth");
document.body.classList.add("darkmode");
setTimeout(function () {
document.querySelector(".slider").classList.remove("smooth");
}, 500);
if (show) {
stylesheet.setAttribute('href', url2);
localStorage.setItem('darkmode', "disabled");
show = !show;
}
else {
stylesheet.setAttribute('href', url);
localStorage.setItem('darkmode', "enabled");
show = !show;
}
};


</script>
</head>

<body>


<script src="//unpkg.com/docsify-edit-on-github/index.js"></script>
<div id="app"></div>
Expand All @@ -63,18 +62,17 @@

plugins: [
EditOnGithubPlugin.create('https://github.com/CircuitVerse/CircuitVerseDocs/blob/master/docs/'),
function(hook)
{

var footer = [
'<header>',
'<span><label class="switch"><input title="Toggle Dark theme" onclick="setStyleSheet();" type="checkbox" ><span class="slider round"></span></label></span>',
'</header>'
].join('');

hook.afterEach(function(html) {
return footer + html;
});
function (hook) {

var footer = [
'<header>',
'<span><label class="switch"><input title="Toggle Dark theme" onclick="setStyleSheet();" type="checkbox" ><span class="slider round"></span></label></span>',
'</header>'
].join('');

hook.afterEach(function (html) {
return footer + html;
});
},
],
loadSidebar: true,
Expand All @@ -84,41 +82,42 @@
alias: {
'/.*/_sidebar.md': '/_sidebar.md'
},
executeScript:true,
executeScript: true,
noCompileLinks: ['/#'],
auto2top: true,
pagination: {
previousText: 'Previous',
nextText: 'Next',
}
previousText: 'Previous',
nextText: 'Next',
}


}

</script>

<script src="//unpkg.com/docsify@4.7.1/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
<script src="//unpkg.com/docsify-pagination/dist/docsify-pagination.min.js"></script>
<script src="//unpkg.com/docsify-pagination/dist/docsify-pagination.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.min.js"></script>
<script type="text/javascript">


window.onload = function()
{ var darkmode = localStorage.getItem('darkmode')

if(darkmode ==="enabled"){
stylesheet.setAttribute('href', url);

window.onload = setTimeout(function () {
var darkmode = localStorage.getItem('darkmode')

if (darkmode === "enabled") {
stylesheet.setAttribute('href', url);
show = !show;
document.querySelector("input[type='checkbox']").checked = true;
console.log(document.querySelector("input[type='checkbox']"))
document.querySelector("input[type='checkbox']").checked = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I placed this console.log deliberately here. If you open up your console, switch to dark mode and refresh, sometimes you'll see the proper input, and sometimes you'll see null. This null is the source cause of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I placed this console.log deliberately here. If you open up your console, switch to dark mode and refresh, sometimes you'll see the proper input, and sometimes you'll see null. This null is the source cause of error.

@animesh-007 , here.

}
const observer = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
if(stylesheet.getAttribute("href") === url ){
document.querySelector("input[type='checkbox']").checked = url;
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (stylesheet.getAttribute("href") === url) {
document.querySelector("input[type='checkbox']").checked = true;
}
else{
document.querySelector("input[type='checkbox']").checked = url2;
else {
document.querySelector("input[type='checkbox']").checked = false;
}
});
});
Expand All @@ -127,7 +126,7 @@
observer.observe(article, {
childList: true
});
};
}, 100);
</script>
</body>

Expand All @@ -142,7 +141,7 @@
gtag('js', new Date());

gtag('config', 'UA-112678513-2');

</script>

</html>
</html>