Skip to content

Instantly share code, notes, and snippets.

View ryanw3b3r's full-sized avatar
💪
Having a very productive day

Ryan W ryanw3b3r

💪
Having a very productive day
View GitHub Profile
@ryanw3b3r
ryanw3b3r / preload.js
Created May 14, 2024 21:43
Preload images in pure Javascript
const preload = src => new Promise(function(resolve, reject) {
const img = new Image();
img.onload = function() {
resolve(img);
}
img.onerror = reject;
img.src = src;
});
const preloadAll = sources =>
@ryanw3b3r
ryanw3b3r / ModalFocusTrap.vue
Created August 17, 2023 13:04
Trap TAB and Shift+TAB in modal or any other element. Just wrap it in this component.
<script lang="ts" setup>
import { type Ref, onMounted, ref } from 'vue'
const selectors = 'a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled])'
const wrapper: Ref<HTMLElement | undefined> = ref()
const focusableEls: Ref<Array<HTMLElement>> = ref([])
const firstFocusableEl: Ref<HTMLElement | undefined> = ref()
const lastFocusableEl: Ref<HTMLElement | undefined> = ref()
function handleBackwardMove(event: KeyboardEvent): void {