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
3 changes: 1 addition & 2 deletions pointercrate-core-pages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl PageConfiguration {
.meta("og:type", "website")
.meta("referrer", "strict-origin-when-cross-origin")
.meta("viewport", "initial-scale=1, maximum-scale=1")
.script("https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js")
.script("https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js")
.script("/static/core/js/modules/anim.js")
.script("/static/core/js/ui.js")
.script("/static/core/js/nav.js")
.script("/static/core/js/misc.js")
Expand Down
159 changes: 82 additions & 77 deletions pointercrate-core-pages/static/js/misc.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
function forceRatio(element, wRatio, hRatio) {
var target = $(element);
var width = target.width();
var width = element.offsetWidth;
var calculatedHeight = (width * hRatio) / wRatio;
if (Math.abs(target.height() - calculatedHeight) > 20) {
target.height((target.width() * hRatio) / wRatio);
if (Math.abs(element.offsetHeight - calculatedHeight) > 20) {
element.style.height = ((element.offsetWidth * hRatio) / wRatio) + "px";
}
}

$(window).on("load resize", function () {
function initMisc() {
// back to top things

var scrollers = $(".js-scroll");
var scrollTarget = $("html, body");
var scrollers = document.querySelectorAll(".js-scroll");

scrollers.each((i, elem) => {
var src = $(elem);
scrollers.forEach(function (elem) {
if (elem.dataset.miscBound) return;
elem.dataset.miscBound = "true";

src.click(() => {
var dest = src.data("destination");
var destination = $("#" + dest);
elem.addEventListener("click", function () {
var dest = elem.dataset.destination;
var destination = dest ? document.getElementById(dest) : null;

if (src.data("reveal")) destination.fadeIn(1000);
if (elem.dataset.reveal && destination) fadeIn(destination, 1000);

if (dest !== undefined)
scrollTarget.animate({ scrollTop: destination.offset().top - 60 }, 400);
else scrollTarget.animate({ scrollTop: 0 }, 400);
if (destination) {
var destinationTop = destination.getBoundingClientRect().top + window.scrollY;
window.scrollTo({ top: destinationTop - 60, behavior: "smooth" });
} else {
window.scrollTo({ top: 0, behavior: "smooth" });
}
});
});

// sometimes animating scrolltop causes things to get stuck. This fixes it.

$(window).bind("mousewheel touchmove touchstart", function () {
$("html, body").stop();
});

// Closable panels

for (let x of document.querySelectorAll(".plus.cross")) {
let parent = x.parentNode;
for (var x of document.querySelectorAll(".plus.cross")) {
if (x.dataset.closableBound) continue;
x.dataset.closableBound = "true";

var parent = x.parentNode;

while (parent !== null && parent.classList !== null) {
if (parent.classList.contains("closable")) {
x.addEventListener("click", () => $(parent).fadeOut(1000));
x.addEventListener("click", function () {
fadeOut(parent, 1000);
});
break;
}
parent = parent.parentNode;
}
}

// Animation stuff when scrolling
var toAnimate = $(".js-scroll-anim");
var wnd = $(window);

wnd.on("scroll resize", checkAnimations);
toAnimate.each((i, elem) => {
var obj = $(elem);
var toAnimate = document.querySelectorAll(".js-scroll-anim");

if (obj.data("js-shown") !== undefined) return;
window.addEventListener("scroll", checkAnimations);
window.addEventListener("resize", checkAnimations);
toAnimate.forEach(function (elem) {
if (elem.dataset.jsShown !== undefined) return;

var observer = new MutationObserver(checkAnimations);
var conf = {
Expand All @@ -68,55 +67,60 @@ $(window).on("load resize", function () {
};
observer.observe(elem.parentElement, conf);

obj.data("js-shown", true);
elem.dataset.jsShown = "true";
});

checkAnimations();

function checkAnimations() {
var viewportBottom = wnd.scrollTop() + wnd.innerHeight();
var viewportBottom = window.scrollY + window.innerHeight;

toAnimate.each((i, elem) => {
var obj = $(elem);
var objBottom = obj.offset().top;
toAnimate.forEach(function (elem) {
var objBottom = elem.offsetTop;

if (objBottom <= viewportBottom && !obj.data("js-shown")) {
switch (obj.data("anim")) {
if (objBottom <= viewportBottom && elem.dataset.jsShown !== "true") {
switch (elem.dataset.anim) {
default:
case "fade":
obj.stop().fadeTo(500, 1);
stopAnimation(elem);
fadeTo(elem, 500, 1);
break;
}
obj.data("js-shown", true);
} else if (objBottom > viewportBottom && obj.data("js-shown")) {
switch (obj.data("anim")) {
elem.dataset.jsShown = "true";
} else if (objBottom > viewportBottom && elem.dataset.jsShown === "true") {
switch (elem.dataset.anim) {
default:
case "fade":
obj.stop().fadeTo(500, 0);
stopAnimation(elem);
fadeTo(elem, 500, 0);
break;
}
obj.data("js-shown", false);
elem.dataset.jsShown = "false";
}
});
}

$(".js-collapse").each(function (i, elem) {
var collapse = $(elem);
var content = collapse.find(".js-collapse-content");
var arrow = collapse.find(".arrow");

arrow.parent().click(function () {
if (!collapse.hasClass("js-sliding")) {
collapse.addClass("js-sliding");
if (collapse.hasClass("active")) {
content.slideUp(250, () => {
collapse.removeClass("active");
collapse.removeClass("js-sliding");
document.querySelectorAll(".js-collapse").forEach(function (elem) {
if (elem.dataset.collapseBound) return;
elem.dataset.collapseBound = "true";

var content = elem.querySelector(".js-collapse-content");
var arrow = elem.querySelector(".arrow");

if (!arrow || !arrow.parentElement) return;

arrow.parentElement.addEventListener("click", function () {
if (!elem.classList.contains("js-sliding")) {
elem.classList.add("js-sliding");
if (elem.classList.contains("active")) {
slideUp(content, 250, function () {
elem.classList.remove("active");
elem.classList.remove("js-sliding");
});
} else {
content.slideDown(250, () => {
collapse.addClass("active");
collapse.removeClass("js-sliding");
slideDown(content, 250, function () {
elem.classList.add("active");
elem.classList.remove("js-sliding");
});
}
}
Expand All @@ -125,28 +129,29 @@ $(window).on("load resize", function () {

// ratio things

$(".ratio-16-9").each(function () {
forceRatio(this, 16, 9);
if (this.tagName == "IFRAME") this.onload = () => forceRatio(this, 16, 9);
document.querySelectorAll(".ratio-16-9").forEach(function (elem) {
forceRatio(elem, 16, 9);
if (elem.tagName === "IFRAME") elem.onload = function () { forceRatio(elem, 16, 9); };
});
$(".ratio-4-3").each(function () {
forceRatio(this, 4, 3);
if (this.tagName == "IFRAME") this.onload = () => forceRatio(this, 4, 3);
document.querySelectorAll(".ratio-4-3").forEach(function (elem) {
forceRatio(elem, 4, 3);
if (elem.tagName === "IFRAME") elem.onload = function () { forceRatio(elem, 4, 3); };
});

$(".js-delay-css").each((i, elem) => {
var elem = $(elem);
var attr = elem.data("property");
var value = elem.data("property-value");
document.querySelectorAll(".js-delay-css").forEach(function (elem) {
var attr = elem.dataset.property;
var value = elem.dataset.propertyValue;

if (elem.css(attr) != value) elem.css(attr, value);
if (getComputedStyle(elem).getPropertyValue(attr) != value) elem.style.setProperty(attr, value);
});

$(".js-delay-attr").each((i, elem) => {
var elem = $(elem);
var attr = elem.data("attr");
var value = elem.data("attr-value");
document.querySelectorAll(".js-delay-attr").forEach(function (elem) {
var attr = elem.dataset.attr;
var value = elem.dataset.attrValue;

if (elem.attr(attr) != value) elem.attr(attr, value);
if (elem.getAttribute(attr) != value) elem.setAttribute(attr, value);
});
});
}

window.addEventListener("load", initMisc);
window.addEventListener("resize", initMisc);
83 changes: 83 additions & 0 deletions pointercrate-core-pages/static/js/modules/anim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// quick replacements for jquery fade/slide animations

function fadeIn(element, duration, callback) {
if (!element) return;
var computed = getComputedStyle(element);
if (computed.display === "none") {
element.style.opacity = "0";
element.style.display = "block";
}
element.offsetHeight;
element.style.transition = "opacity " + duration + "ms ease";
element.style.opacity = "1";
if (callback) setTimeout(callback, duration);
}

function fadeOut(element, duration, callback) {
if (!element) return;
var computed = getComputedStyle(element);
if (computed.display === "none") {
if (callback) callback();
return;
}
element.style.transition = "opacity " + duration + "ms ease";
element.style.opacity = "0";
setTimeout(function () {
element.style.display = "none";
if (callback) callback();
}, duration);
}

function fadeTo(element, duration, opacity, callback) {
if (!element) return;
var computed = getComputedStyle(element);
if (computed.display === "none" && opacity > 0) {
element.style.opacity = "0";
element.style.display = "block";
}
element.offsetHeight;
element.style.transition = "opacity " + duration + "ms ease";
element.style.opacity = opacity.toString();
if (callback) setTimeout(callback, duration);
}

function slideDown(element, duration, callback) {
if (!element) return;
var computed = getComputedStyle(element);
if (computed.display === "none") {
element.style.maxHeight = "0";
element.style.overflow = "hidden";
element.style.display = "block";
}
var targetHeight = element.scrollHeight + "px";
element.offsetHeight;
element.style.transition = "max-height " + duration + "ms cubic-bezier(0.45, 0.05, 0.55, 0.95)";
element.style.maxHeight = targetHeight;
if (callback) setTimeout(callback, duration);
}

function slideUp(element, duration, callback) {
if (!element) return;
var computed = getComputedStyle(element);
if (computed.display === "none") {
if (callback) callback();
return;
}
element.style.transition = "max-height " + duration + "ms cubic-bezier(0.45, 0.05, 0.55, 0.95)";
element.style.maxHeight = "0";
element.style.overflow = "hidden";
setTimeout(function () {
element.style.display = "none";
if (callback) callback();
}, duration);
}

function stopAnimation(element) {
if (!element) return;
var style = getComputedStyle(element);
var opacity = style.opacity;
var maxHeight = style.maxHeight;
element.style.transition = "";
element.style.opacity = opacity;
element.style.maxHeight = maxHeight;
}
Loading