Skip to content
Open
Show file tree
Hide file tree
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
68 changes: 44 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,51 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kottans practice</title>
<style>
html {
font: 20px/1.5em sans-serif;
}
a {
text-decoration: none;
}
a:hover, a:focus {
text-decoration: underline;
}
</style>
<link rel="stylesheet" href="js-dom/style.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>Online part:</p>
<ul>
<li><a href="js-dom">Sidebar navigation (DOM API)</a></li>
<li><a href="a-tiny-js-world">A Tiny JS World (pre-OOP)</a></li>
<li><a href="frogger">Frogger game (OOP)</a></li>
<li><a href="a-tiny-js-world-oop">A Tiny JS World (post-OOP)</a></li>
<li><a href="memory-pair">Memory Pair game</a></li>
<li><a href="friends-app">Friends app</a></li>
</ul>
<p>Offline part:</p>
<ul>
<li><a href="popup-no-js">Popup menu (no JS)</a></li>
</ul>
<nav id="navbar" class="navbar">
<li class="menu-item home" data-id="home">Home</li>
<li class="menu-item" data-id="popup-no-js">Popup menu</li>
<li class="menu-item" data-id="friends-app">Friends app</li>
<li class="menu-item" data-id="memory-pair">Memory Pair game</li>
<li class="menu-item" data-id="a-tiny-js-world-oop">Post-OOP</li>
<li class="menu-item" data-id="frogger">Frogger Game</li>
<li class="menu-item" data-id="a-tiny-js-world">Pre-OOP</li>
<li class="menu-item" data-id="js-dom">DOM API task</li>
</nav>
<main id="main">
<h1 id="page-title">Home</h1>
<section class="section shown" id="home">
<p>
This is my collection of projects created as a part of the Kottans frontend course 2019: <a href="http://github.com/kottans/frontend">http://github.com/kottans/frontend</a>.
</p>
</section>
<section class="section" id="popup-no-js">
<p>Recreation of Google's pop-up menu without any JS.</p>
</section>
<section class="section" id="friends-app">
<p>An application that uses the <a href="http://randomuser.me">Random User API</a> and displays user profiles, which then can be sorted and filtered.</p>
</section>
<section class="section" id="memory-pair">
<p>A simple game.</p>
</section>
<section class="section" id="a-tiny-js-world-oop">
<p>An exercise to solidify the understanding of OOP in JS.</p>
</section>
<section class="section" id="frogger">
<p>The Frogger game, built on the prototype-based OOP.</p>
</section>
<section class="section" id="a-tiny-js-world">
<p>A world of objects, where classes do not exist yet.</p>
</section>
<section class="section" id="js-dom">
<p>A page which fetches its content from JSON files. The look of it might be a bit familiar ;)</p>
</section>
<button class="btn-go" id="btn-go">Go</button>
</main>
<button id="navbar-toggle">☰</button>
<script src="script.js"></script>
</body>
</html>
32 changes: 22 additions & 10 deletions popup-no-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const navbar = document.getElementById('navbar');

/*
* Events
*/

document.getElementById('navbar-toggle').addEventListener('click', function() {
navbar.classList.toggle('shown');
});

navbar.addEventListener('click', function(event) {
// delegate clicks from <li>s to <nav>
const elem = event.target;
if (elem.nodeName != 'LI') return;

const id = elem.dataset.id;
displayData(id, elem.textContent);
navbar.classList.remove('shown');
});

document.getElementById('btn-go').addEventListener('click', function() {
window.open(currentPage);
})

/*
* Functionality
*/

let currentPage = 'home';

function displayData(id, title) {
if (id == currentPage) return;
const section = document.getElementById(id);
if (section) {
if (id == 'home') {
document.getElementById('btn-go').classList.remove('shown');
} else {
document.getElementById('btn-go').classList.add('shown');
}

document.getElementById(currentPage).classList.remove('shown');
document.getElementById(id).classList.add('shown');
document.getElementById('page-title').textContent = title;
currentPage = id;
}
}
30 changes: 30 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section {
display: none;
}

.btn-go {
all: unset;
display: none;
margin-top: 50px;
padding: 10px 25px;
border: 1px solid #fff9;
border-radius: 5px;
color: #fff;
cursor: pointer;
transition: border-color 0.25s;
}
.btn-go::after {
content: '→';
margin-left: 10px;
}
.btn-go:hover {
border-color: #fffc;
}
.btn-go:focus,
.btn-go:active {
border-color: #fff;
}

.shown {
display: block;
}