Update JS

This commit is contained in:
deathrow 2023-01-19 13:24:07 -05:00
parent 5b1af73d8d
commit c136ebc3a0
No known key found for this signature in database
GPG Key ID: FF39D67A22069F73
5 changed files with 23093 additions and 0 deletions

View File

@ -20,4 +20,11 @@
<!-- Styles -->
<link rel="stylesheet" id="css-theme" href="{{ '/assets/css/main-' | append: site.theme_base | append: '.css' | prepend: site.baseurl }}">
<link rel="stylesheet" href="{{ '/assets/css/highlight/' | append: site.highlighter_theme | append: '.css' | prepend: site.baseurl }}">
<script src="/assets/js/bootstrap.min.js" defer></script>
<script src="/assets/js/jquery.min.js" defer></script>
<script src="/assets/js/d3.min.js" defer></script>
<script type="text/javascript" src="{{ '/assets/js/main.js' | prepend: site.baseurl }}" defer></script>
</head>

1758
assets/js/bootstrap.min.js vendored Normal file

File diff suppressed because it is too large Load Diff

15924
assets/js/d3.min.js vendored Normal file

File diff suppressed because it is too large Load Diff

5315
assets/js/jquery.min.js vendored Normal file

File diff suppressed because it is too large Load Diff

89
assets/js/main.js Normal file
View File

@ -0,0 +1,89 @@
let layer1, layer2, layer3, layer4;
let themeBase;
$(document).ready(() => {
layer1 = d3.select("#bg-layer1");
layer2 = d3.select("#bg-layer2");
layer3 = d3.select("#bg-layer3");
layer4 = d3.select("#bg-layer4");
themeBase = localStorage.getItem("themeBase") || document.getElementById("css-theme").getAttribute("href").match("-(light|dark).css")[1];
setTheme(themeBase);
makeStrips([layer1, layer2, layer3, layer4]);
$(document).scroll(updateBackground);
$(window).resize(updateBackground);
$("table").addClass("table table-hover");
$("img").addClass("img img-responsive");
$(".content-div > h1, .content-div > a > h1").addClass("h1-strip");
setTimeout(updateBackground, 500);
});
function drawLine(x, y, w, h, layer) {
let line = layer.append("rect")
.attr("x", x)
.attr("y", y)
.attr("width", w)
.attr("height", h)
.attr("fill", "url(#Gradient1)");
}
function updateBackground() {
// Update stripes
let contentX = ($(".content-div").offset().left);
let layer1Y = window.pageYOffset / 5;
let layer2Y = window.pageYOffset / 4;
let layer3Y = window.pageYOffset / 3;
let layer4Y = window.pageYOffset / 2;
layer1.attr("transform", `translate(${contentX}, ${-layer1Y})`);
layer2.attr("transform", `translate(${contentX}, ${-layer2Y})`);
layer3.attr("transform", `translate(${contentX}, ${-layer3Y})`);
layer4.attr("transform", `translate(${contentX}, ${-layer4Y})`);
// Update transparent overlays over h1
$(".h1-overlay").remove();
$(".h1-strip")
.filter((index, node) => $(node).isInViewport())
.map((index, node) => {
let {left, top, right, bottom, x, y, width, height} = node.getBoundingClientRect();
let style = window.getComputedStyle?getComputedStyle(node, null):node.currentStyle;
let marginTop = parseInt(style.marginTop) || 0;
let overlay = document.createElement("div");
overlay.classList.add("h1-overlay");
overlay.style.left = 0;
overlay.style.top = `${window.scrollY+top-marginTop}px`;
overlay.style.height = `${height+marginTop}px`;
document.body.appendChild(overlay);
});
}
function makeStrips(layers) {
let layerProbs = new Array(layers.length).fill(0).map((_, index) => index / layers.length);
for (let i = 10; i < 100; i *= 1.05) {
let index = Math.floor(Math.random() * layers.length);
let randomLayer = layers[index];
if (Math.random() > layerProbs[index]) {
drawLine(-i, 100, 1, 1000 * (Math.random() + 1), randomLayer);
}
}
updateBackground();
}
function toggleTheme() {
themeBase = themeBase == "light" ? "dark" : "light";
localStorage.setItem("themeBase", themeBase);
setTheme(themeBase);
}
function setTheme(themeBase) {
let oldTheme = themeBase == "light" ? "dark" : "light";
let href = document.getElementById("css-theme").getAttribute("href").replace(oldTheme, themeBase);
let css = document.getElementById("css-theme");
css.setAttribute("href", href);
}
// https://medium.com/talk-like/detecting-if-an-element-is-in-the-viewport-jquery-a6a4405a3ea2
$.fn.isInViewport = function() {
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};