Skip to content

Instantly share code, notes, and snippets.

View mvsde's full-sized avatar
🏳️‍⚧️
Protect trans kids!

Fynn Becker mvsde

🏳️‍⚧️
Protect trans kids!
View GitHub Profile
@mvsde
mvsde / event-bus.js
Last active June 30, 2021 07:52
Subscribe / Publish pattern
/**
* Use Mitt instead: https://github.com/developit/mitt
*/
const EventBus = {
topics: {},
subscribe: function (topic, listener) {
// Create topic if not yet created
if (!this.topics[topic]) {
@mvsde
mvsde / sr-only.css
Last active January 7, 2020 15:39
Hide element visually but keep it in accessibility tree
/**
* Visually hides elements but keeps them accessible for screen readers and
* keyboard users.
*
* Source:
* https://allyjs.io/tutorials/hiding-elements.html#2017-edition-of-visuallyhidden
*/
.sr-only:not(:focus):not(:active) {
position: absolute;
@mvsde
mvsde / fluid-type.scss
Last active July 3, 2023 00:31
Fluid typography Sass mixin
// Modern browsers have support for the CSS clamp function:
// https://developer.mozilla.org/en-US/docs/Web/CSS/clamp()
// Source: https://css-tricks.com/snippets/css/fluid-typography/
@mixin fluid-type($min-font-size, $max-font-size, $min-vw: $breakpoint-min, $max-vw: $breakpoint-max) {
$u1: unit($min-vw);
$u2: unit($max-vw);
$u3: unit($min-font-size);
$u4: unit($max-font-size);
@mvsde
mvsde / add-event-listener-once.js
Last active June 30, 2021 07:55
JavaScript Collapse
/**
* Modern browsers support the `once` option for event listeners:
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters
*/
module.exports = function(target, type, callback) {
let eventWrapper = function(event) {
target.removeEventListener(type, eventWrapper);
callback(event);
};
@mvsde
mvsde / svg-url.scss
Last active May 15, 2017 18:22
Cross-browser inline SVG function
// SVG URL
//
// Generate an escaped SVG for data URIs.
//
// Usage:
// .selector {
// background-image: svg-url('<svg>…</svg>');
// }
//
// Source: