Skip to content

Commit

Permalink
Create basic example page
Browse files Browse the repository at this point in the history
- Create mockup for basic example page
- Placeholder code in basic.js for testing scrollable page
- Implement code to support common themes across pages, namely loading source content into a collapsible div with syntax highlights (thanks highlight.js)
- More style rules for the site, including buttons and controls, horizontal rule, main and aside content, smooth scroll, and source container styling
  • Loading branch information
almic committed Mar 31, 2024
1 parent 0be8487 commit a266c9d
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 1 deletion.
65 changes: 65 additions & 0 deletions docs/basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>

<head>
<style>
body {
background: #000;
color: #f0f8ff;
}
</style>
<link rel="stylesheet" href="css/page.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/basic.js"></script>

<script src="js/main.js"></script>

<!-- Code highlighting -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/night-owl.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"></script>

</head>

<body>

<div class="center page-box page-style flex-container">
<div class="flex-aside center-text">
<p><a href="index.html">Homepage</a></p>
<p class="flex-column-to-bottom"><a href="#">Scroll to top</a></p>
</div>
<div class="flex-main">
<h1 id="title" class="center-text text-glow-responsive">
Basic Sound Control
</h1>
<p class="center-text text-glow">
Playing a sound using MusicMixer.js
</p>
<hr>

<div class="flex-container flex-center flex-controls">
<button type="button">Play Music</button>
<button type="button">Stop Music</button>
<button type="button">Fade In<br>(Start)</button>
<button type="button">Fade Out<br>(Stop)</button>
</div>

<hr>
<div class="source-code-container">
<button type="button" class="collapse-button" onclick="collapse(this, 'Hide Source', 'code')">Show Source</button>
<div name="code" class="collapse-content">
<pre class="m-0"><code name="source-code" class="language-javascript">Source code!!</code></pre>
</div>
</div>
</div>
</div>

<script>
loadSourceCode('source-code', 'js/basic.js')
.catch((reason) => { console.error(reason); })
.finally(() => { hljs.highlightAll(); });
</script>

</body>

</html>
115 changes: 114 additions & 1 deletion docs/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,33 @@ h3 {
font-weight: 720;
}

div.clickable:hover {
hr {
width: 200px;
height: 1px;
border: none;
margin: 1.17rem auto;
background: linear-gradient(
to right,
rgba(0, 255, 255, 0) 0%,
rgba(0, 255, 255, 1) 45%,
rgba(0, 255, 255, 1) 55%,
rgba(0, 255, 255, 0) 100%
);
}

button {
padding: 8px;
color: inherit;
cursor: pointer;
font-size: inherit;
font-family: inherit;
border: 1px solid rgba(0, 255, 255, 0.25);
background-color: rgb(24, 48, 48);
transition: background-color 200ms ease-out;
}

button:hover {
background-color: rgb(32, 56, 56);
}

a {
Expand All @@ -62,12 +87,53 @@ a {
border-bottom: 1px solid rgba(95, 204, 255, 0);
}

div.clickable:hover {
cursor: pointer;
}

a:hover,
div.clickable:hover a {
color: #75d3ff;
border-bottom-color: rgba(117, 211, 255, 1);
}

div.flex-container {
display: flex;
}

div.flex-main {
flex-basis: 90%;
/* center back on page */
padding-right: 10%;
}

div.flex-aside {
display: flex;
flex-basis: 10%;
flex-direction: column;
/* Stick to page */
height: calc(100vh - 10rem - 2px);
position: sticky;
top: calc(5rem + 1px);
}

div.flex-center {
justify-content: center;
}

div.flex-controls {
width: 80%;
margin: 1rem auto;
}

div.flex-controls > button {
font-size: 1.17em;

flex-grow: 1;
width: 100%;
margin: 8px;
}

div.grid-box {
display: grid;
gap: 32px;
Expand Down Expand Up @@ -147,6 +213,53 @@ ul.list-blocks > li {
1;
}

.collapse-active {
border-bottom-color: rgba(0, 255, 255, 0.5);
transition: border-bottom-color 100ms ease, background-color 200ms;
}

.collapse-active::before,
.collapse-active::after {
content: '\02796';
}

.collapse-button {
width: 100%;
border: none;
display: flex;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgba(0, 255, 255, 0);
/* Change transition time to be slower during collapse, faster when opened */
transition: border-bottom-color 500ms ease, background-color 200ms ease-out;
}

.collapse-button::before,
.collapse-button::after {
content: '\02795';
flex: content;
}

.collapse-content {
max-height: 0;
overflow: hidden;
transition: max-height 250ms ease-in-out;
}

.flex-column-to-bottom {
margin-top: auto;
}

.m-0 {
margin: 0;
}

.source-code-container {
width: 60%;
margin: 0 20%;
border: 1px solid rgba(0, 255, 255, 0.5);
}

.text-glow {
text-shadow: 0 0 2px;
}
Expand Down
4 changes: 4 additions & 0 deletions docs/css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ body {
min-height: 100%;
}

html {
scroll-behavior: smooth;
}

*,
*:before,
*:after {
Expand Down
91 changes: 91 additions & 0 deletions docs/js/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Source code!!

const thing = { Yooo: 'World' };
console.log('Two lines');

// So many lines
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// What to do with my time
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// Never ending?
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// It ends!
27 changes: 27 additions & 0 deletions docs/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
async function loadSourceCode(name, path) {
const sourceCode = await (await fetch(path)).text();
const elements = document.getElementsByName(name);
elements.forEach((element) => (element.innerHTML = sourceCode));
}

function collapse(self, toggleText, name) {
self.classList.toggle('collapse-active');
if (!self.getAttribute('data-toggle-text')) {
self.setAttribute('data-toggle-text', toggleText);
}
const text = self.getAttribute('data-toggle-text');
self.setAttribute('data-toggle-text', self.innerHTML);
self.innerHTML = text;
const elements = document.getElementsByName(name);
if (!elements.length) {
console.warn(`Tried to toggle collapsible elements named ${name}, but it wasn't on the page!`);
return;
}
elements.forEach((element) => {
if (element.style.maxHeight) {
element.style.maxHeight = null;
} else {
element.style.maxHeight = element.scrollHeight + 'px';
}
});
}

0 comments on commit a266c9d

Please sign in to comment.