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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ _site
.jekyll-metadata
dist
node_modules
package-lock.json
63 changes: 38 additions & 25 deletions _js/main.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
var blueprint = require("./blueprint.json");
require("particles.js");
import { animator, illustrator } from "./svgbuilder";

document.addEventListener("DOMContentLoaded", () => {
let canvas = SVG("svg-container").size("90%", "90%").viewbox(0, 0, 640, 480);

particlesJS.load("particles-js", "./assets/particlesjs.json", () =>
document.getElementById("particles-js").style.animation = "show 2s forwards");
const blueprint = require('./blueprint.json');
require('particles.js');
import { animate, illustrate } from './svgbuilder';

document.addEventListener('DOMContentLoaded', () => {
const canvas = SVG('svg-container')
.size('90%', '90%')
.viewbox(0, 0, 640, 480);

particlesJS.load(
'particles-js',
'./assets/particlesjs.json',
() =>
(document.getElementById('particles-js').style.animation =
'show 2s forwards')
);

window.onpopstate = () => selectPage(canvas, window.location.hash);
selectPage(canvas, window.location.hash);
});

function selectPage(canvas, hash) {
let container = document.getElementById(hash.substring(1)) || document.getElementById("home");
let id = container.id;
if (container.classList.contains("active")) return;
const selectPage = (canvas, hash) => {
const container =
document.getElementById(hash.substring(1)) ||
document.getElementById('home');
const id = container.id;

if (container.classList.contains('active')) return;

// remove existing active classes and hide all
for (let element of document.querySelectorAll(".active")) {
element.classList.remove("active");
for (const element of document.querySelectorAll('.active')) {
element.classList.remove('active');
}
for (let element of document.querySelectorAll("#content div")) {
element.classList.add("hidden");

for (const element of document.querySelectorAll('#content div')) {
element.classList.add('hidden');
}

// add .active to the new active item and content
let content = document.getElementById(id);
content.classList.remove("hidden");
content.classList.add("active");
document.querySelector("a[href=\"#" + id + "\"]").parentElement.classList.add("active");
const content = document.getElementById(id);
content.classList.remove('hidden');
content.classList.add('active');
document
.querySelector('a[href="#' + id + '"]')
.parentElement.classList.add('active');

clearCanvas(canvas);
animator(illustrator(canvas, blueprint[content.dataset.animation]));
animate(illustrate(canvas, blueprint[content.dataset.animation]));
}

function clearCanvas(draw) {
const clearCanvas = (draw) => {
draw.each(function() {
this.removeClass("*");
this.removeClass('*');
this.off();
this.stop();
}, true);
draw.ungroup();
draw.clear();
}
};
Loading