1
0
mirror of https://github.com/GenderDysphoria/GenderDysphoria.fyi.git synced 2025-11-25 12:32:42 +00:00

Initial site commit

This commit is contained in:
Jocelyn Badgley (Twipped)
2020-02-20 14:38:25 -08:00
parent 0a6bdb2544
commit 1c45fdaf33
136 changed files with 24538 additions and 146 deletions

12
js/.eslintrc Normal file
View File

@@ -0,0 +1,12 @@
{
"extends": "twipped/browser",
"env": {"es6": true, "jquery": true},
"rules": {
'indent': [ 2, 2, {
'MemberExpression': 1,
} ],
'prefer-arrow-callback': 0,
'object-shorthand': 0,
'node/no-unsupported-features/node-builtins': 0
}
}

10
js/_header.js Normal file
View File

@@ -0,0 +1,10 @@
$(function () {
let active = false;
window.addEventListener('scroll', function () {
const state = window.scrollY > 10;
if (active !== state) {
$('header').toggleClass('active', state);
active = state;
}
});
});

26
js/_lightbox.js Normal file
View File

@@ -0,0 +1,26 @@
(function ($) {
$('.lightbox, .gutter').each(function () {
$(this).magnificPopup({
delegate: 'a.lb',
type: 'image',
closeOnContentClick: false,
closeBtnInside: false,
mainClass: 'mfp-with-zoom mfp-img-mobile',
image: {
verticalFit: true,
},
gallery: {
enabled: true,
},
zoom: {
enabled: true,
duration: 300, // don't foget to change the duration also in CSS
opener: function (element) {
return element.find('img');
},
},
});
});
}(window.jQuery));

92
js/i.js Normal file
View File

@@ -0,0 +1,92 @@
(function (window, document, navigator) {
const me = document.currentScript;
const url = me.getAttribute('data-url');
const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
const vendor = navigator.vendor;
const doNotTrack = navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack;
let tid = !doNotTrack && window.localStorage.getItem('tid');
if (!tid && !doNotTrack) {
tid = Math.round(Math.random() * 1000000000);
window.localStorage.setItem('tid', tid);
}
const body = document.body;
const html = document.documentElement;
const SESSION_DATA = {
tid,
start: Date.now(),
end: null,
max_scroll: 0,
language: navigator.userLanguage || navigator.language,
href: window.location.pathname,
referrer: document.referrer,
};
// listen for all the exit events
window.addEventListener('pagehide', endSession);
window.addEventListener('beforeunload', endSession);
window.addEventListener('unload', endSession);
// for iOS when the focus leaves the tab
if (iOS) window.addEventListener('blur', endSession);
window.addEventListener('load', sendSession);
// scroll tracking
window.addEventListener('scroll', function () {
const page_height = Math.max(
body.scrollHeight,
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight,
);
const viewport_height = Math.max(html.clientHeight, window.innerHeight || 0);
const max_scroll = Math.max(SESSION_DATA.max_scroll, window.scrollY);
const viewed = max_scroll === 0 ? 0 : Math.round(((max_scroll + viewport_height) / page_height) * 100);
Object.assign(SESSION_DATA, { page_height, viewport_height, max_scroll, viewed });
});
let skip;
function endSession () {
if (skip) return;
skip = true;
SESSION_DATA.end = Date.now();
sendSession();
}
// call this function on exit
function sendSession () {
const params = new URLSearchParams(SESSION_DATA);
const data = params.toString();
// Instead, send an async request
// Except for iOS :(
const async = !iOS;
const request = new XMLHttpRequest();
request.open('GET', url + '?' + data, async); // 'false' makes the request synchronous
request.setRequestHeader('Content-Type', 'application/json');
request.send(data);
// Synchronous request cause a slight delay in UX as the browser waits for the response
// I've found it more performant to do an async call and use the following hack to keep the loop open while waiting
// Chrome doesn't care about waiting
if (!async || ~vendor.indexOf('Google')) return;
// Latency calculated from navigator.performance
const latency = data.latency || 0;
const t = Date.now() + Math.max(300, latency + 200);
while (Date.now() < t) {
// postpone the JS loop for 300ms so that the request can complete
// a hack necessary for Firefox and Safari refresh / back button
}
}
}(window, document, navigator));