dark mode in docs

This commit is contained in:
janis
2023-01-22 20:00:31 +01:00
parent 1d9b07761a
commit c87fdfcef5
11 changed files with 330 additions and 32 deletions

View File

@@ -10,7 +10,15 @@
overflow: scroll;
}
.dropdown {
display: none;
font-size: 0.8rem;
height: 100%;
background-color: rgb(27, 27, 165);
}
.navitem {
cursor: pointer;
text-decoration: none;
color: white;
padding: 5%;
@@ -19,19 +27,13 @@
font-size: 1rem;
}
.navitem:hover {
background-color: black;
}
.nav-subitem {
display: block;
text-decoration: none;
color: white;
padding: 5%;
padding-left: 25%;
font-size: 0.8rem;
width: 70%;
padding: 5%;
padding-left: 25%;
background-color: rgb(27, 27, 165);
}
.nav-subitem:hover {
background-color: rgb(43, 43, 43);
}

View File

@@ -20,6 +20,7 @@ html, body {
color: black;
display: grid;
grid-template-areas:
'menu header header header header'
'menu main main main main'
'menu main main main main'
'menu main main main main'
@@ -31,22 +32,38 @@ html, body {
'menu footer footer footer footer';
}
.darkMode {
background-color: rgb(46, 46, 46);
color: white
.logo {
width: 60%;
height: auto;
margin-left: 20%;
margin-top: 5%;
margin-bottom: 5%;
}
#nav {
grid-area: menu;
width: 90%;
min-width: 20vw;
width: 100%;
height: 100%;
overflow: scroll;
}
#docPage {
max-width: 75vw;
margin: 0;
grid-area: main;
overflow: scroll;
}
.doc-container {
width: 90%;
margin: 5%;
}
#footer {
grid-area: footer;
}
#top {
grid-area: header;
}

View File

@@ -0,0 +1,15 @@
.top-container {
background-color: rgb(223, 223, 223);
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
}
.top-wrapper {
display: flex;
width: 80%;
margin-right: 5%;
justify-content: flex-end;
}

View File

@@ -1,9 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Getting Started | impress.js - documentation</title>
<title>Getting Started - impress.js</title>
<!--I am using jquery for button animations.-->
<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script defer src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer src="/js/docs/loader.js"></script>
<link rel="stylesheet" href="/css/docs/style.css">
</head>
<body>
<div class="content">
<div id="nav"></div>
<div id="top"></div>
<div id="docPage">
<div class="doc-container">
<div class="docTitle">
<h1>Getting Started with impress.js</h1>
</div>
<p>impress.js is a JavaScript framework to create stunning presentations. Note: impress may not help you, if you have nothing interesting to say!</p>
<p>If you are new to impress and you want to learn to use it, we suggest you <a href="./gettingStarted.html" class="docs-link">start here</a>!</p>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>

View File

@@ -4,15 +4,21 @@
<title>Docs - impress.js</title>
<!--I am using jquery for button animations.-->
<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script defer src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script defer src="/js/docs/loader.js"></script>
<link rel="stylesheet" href="/css/docs/style.css">
</head>
<body>
<div class="content">
<div id="nav"></div>
<div id="top"></div>
<div id="docPage">
<div class="docTitle">
<h1>Welcome to the impress.js docs!</h1>
<div class="doc-container">
<div class="docTitle">
<h1>Welcome to the impress.js docs!</h1>
</div>
<p>impress.js is a JavaScript framework to create stunning presentations. Note: impress may not help you, if you have nothing interesting to say!</p>
<p>If you are new to impress and you want to learn to use it, we suggest you <a href="./gettingStarted.html" class="docs-link">start here</a>!</p>
</div>
</div>
<div id="footer"></div>

View File

@@ -11,11 +11,62 @@
<div class="nav-list">
<a class="navitem" id="home" href="/docs">Home</a>
<a class="navitem" id="gettingStarted" href="/docs/gettingStarted.html">Getting Started</a>
<a class="navitem" id="advanced" href="/docs/reference">API reference</a>
<a class="nav-subitem" id="advanced" href="/docs/advanced/root">Root element</a>
<a class="navitem" id="plugins" href="/docs/plugins.html">Plugins</a>
<a class="navitem" id="referenceNav" onclick="toggleList( 'reference' );">API reference</a>
<div class="dropdown" id="reference">
<a class="nav-subitem" id="root" href="/docs/reference">Home</a>
<a class="nav-subitem" id="root" href="/docs/reference/root">Root element</a>
</div>
<a class="navitem" id="pluginsNav" onclick="toggleList( 'plugins' );">Plugins</a>
<div class="dropdown" id="plugins">
<a class="nav-subitem" id="impressConsole" href="/docs/plugins/impressConsole.html">Impress Console</a>
</div>
<a class="navitem" id="contributingNav" onclick="toggleList( 'contributing' );">Contributing</a>
<div class="dropdown" id="contributing">
<a class="nav-subitem" id="contributing-gettingStarted" href="/docs/contributing/gettingStarted.html">Getting Started</a>
</div>
</div>
</div>
</div>
</body>
<script>
function highlightPath () {
};
$(document).ready(function () {
$( '.navitem' ).mouseenter( function () {
$( this ).stop();
$( this ).animate( { 'background-color': 'black' }, 100 );
} );
$( '.navitem' ).mouseleave( function () {
if ( sessionStorage.getItem( 'theme' ) == 'dark' ) {
$( this ).stop();
$( this ).animate( { 'background-color': 'rgb(12, 12, 60)' }, 100 );
} else {
$( this ).stop();
$( this ).animate( { 'background-color': 'rgb(22, 22, 117)' }, 100 );
}
} );
$( '.nav-subitem' ).mouseenter( function () {
$( this ).stop();
$( this ).animate( { 'background-color': 'rgb(43, 43, 43)' }, 100 );
} );
$( '.nav-subitem' ).mouseleave( function () {
if ( sessionStorage.getItem( 'theme' ) == 'dark' ) {
$( this ).stop();
$( this ).animate( { 'background-color': 'rgb(18, 18, 99)' }, 100 );
} else {
$( this ).stop();
$( this ).animate( { 'background-color': 'rgb(27, 27, 165)' }, 100 );
}
} );
});
function toggleList ( id ) {
$( `#${id}` ).slideToggle();
};
</script>
</html>

View File

@@ -14,7 +14,8 @@
const fs = require( 'fs' );
const path = require( 'path' );
const md2html = require( 'node-html-markdown' );
const mdhtml = require( 'markdown-it' );
const md2html = new mdhtml();
const pluginsPath = path.join( __dirname + '/../../../src/plugins' );
@@ -26,7 +27,7 @@ for ( let item in plugins ) {
if ( error ) {
parseJS( path.join( pluginsPath + '/' + plugins[item] ) );
} else {
console.log( data );
console.log( md2html.render( '' + data ) );
};
} );
}

14
website/docs/top.html Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="/css/docs/topstyle.css">
</head>
<body>
<div class="top-container">
<div class="top-wrapper">
<button onclick="toggleDarkMode();" id="darkToggle">&#9789;</button>
</div>
</div>
</body>
</html>

View File

@@ -1,3 +1,61 @@
$( document ).ready( function () {
$( '#nav' ).load( '/docs/nav.html' );
$( '#top' ).load( '/docs/top.html' );
setTimeout( setTheme, 300 );
} );
let theme = sessionStorage.getItem( 'theme' ) || getPreferredTheme();
// set theme on page load
function setTheme () {
if ( theme == 'dark' ) {
document.getElementById( 'darkToggle' ).innerHTML = '&#9788;';
$( '.content' ).css( 'background-color', 'rgb(46, 46, 46)' );
$( '.top-container' ).css( 'background-color', 'rgb(100, 100, 100)' );
$( '.content' ).css( 'color', 'white' );
$( '.nav-subitem' ).css( 'background-color', 'rgb(18, 18, 99)' );
$( '.navitem' ).css( 'background-color', 'rgb(12, 12, 60)' );
$( '.nav-container' ).css( 'background-color', 'rgb(0, 0, 100)' );
}
}
// retreive preferred theme from browser preferences if not in session storage
function getPreferredTheme () {
if ( window.matchMedia( '(prefers-colorscheme: dark)' ).matches ) {
setPreferredTheme( 'dark' );
return 'dark';
} else {
setPreferredTheme( 'light' );
return 'light';
};
}
// set theme in session storage
function setPreferredTheme ( userTheme ) {
sessionStorage.setItem( 'theme', userTheme );
theme = userTheme;
}
// change theme
function toggleDarkMode () {
if ( theme == 'light' ) {
$( '.content' ).animate( { 'background-color': 'rgb(46, 46, 46)' } );
$( '.top-container' ).animate( { 'background-color': 'rgb(100, 100, 100)' } );
$( '.nav-subitem' ).animate( { 'background-color': 'rgb(18, 18, 99)' } );
$( '.navitem' ).animate( { 'background-color': 'rgb(12, 12, 60)' } );
$( '.nav-container' ).animate( { 'background-color': 'rgb(0, 0, 100)' } );
$( '.content' ).animate( { 'color': 'white' } );
document.getElementById( 'darkToggle' ).innerHTML = '&#9788;';
setPreferredTheme( 'dark' );
} else {
$( '.content' ).animate( { 'background-color': 'white' } );
$( '.content' ).animate( { 'color': 'black' } );
$( '.nav-subitem' ).animate( { 'background-color': 'rgb(27, 27, 165)' } );
$( '.navitem' ).animate( { 'background-color': 'rgb(22, 22, 117)' } );
$( '.nav-container' ).animate( { 'background-color': 'blue' } );
$( '.top-container' ).animate( { 'background-color': 'rgb(223, 223, 223)' } );
document.getElementById( 'darkToggle' ).innerHTML = '&#9789;';
setPreferredTheme( 'light' );
}
}