Skip to content

Instantly share code, notes, and snippets.

Avatar

Kamcio dziku86

View GitHub Profile
@dziku86
dziku86 / app.js
Created January 19, 2023 18:09 — forked from prof3ssorSt3v3/app.js
Code from video about using Promise.finally and Spinners
View app.js
function delay(time = 500) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time);
});
}
let spinner = document.querySelector('.spinner');
spinner.classList.add('active');
fetch('./books.json')
View getAllFocusableElements.js
const getAllFocusableElements = (parent) => Array.from(parent.querySelectorAll('*')).filter(elm => elm.tabIndex > -1).sort((a,b) => a.tabIndex > b.tabIndex ? 1 : a.tabIndex < b.tabIndex ? -1 : 0);
@dziku86
dziku86 / formProgress.js
Created February 21, 2021 22:15 — forked from adactio/formProgress.js
Show a progress bar with every form that has a method of POST. Particularly nice if there's a file upload involved.
View formProgress.js
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
'use strict';
if (!win.XMLHttpRequest || !win.FormData || !win.addEventListener || !doc.querySelectorAll) {
// doesn't cut the mustard.
return;
}
function hijaxForm (formElement) {
var progressBar;
@dziku86
dziku86 / functional-utils.js
Created February 20, 2021 21:37 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
View functional-utils.js
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@dziku86
dziku86 / scriptloader.js
Last active February 20, 2021 21:57 — forked from itsjavi/scriptloader.js
JS ScriptLoader using ES6 Promises
View scriptloader.js
function ScriptLoader () {
const loader = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = !0
script.addEventListener('load', resolve(script), !1)
script.addEventListener('error', reject(script), !1)
body.appendChild(script)
})
this.load = url => loader(url)
@dziku86
dziku86 / darkthemeswitcher-inline.js
Last active December 8, 2020 14:57 — forked from frontdevops/darkthemeswitcher-inline.js
Simple Dark Theme Bookmarklet for web pages
View darkthemeswitcher-inline.js
javascript:(d=>{var css=`html{background:#fefefe;filter:invert(100%)}*{background:inherit}img:not([src*=".svg"]),video{filter:invert(100%)}`,style,id='dark-theme-snippet',ee=d.getElementById(id);if(null !=ee)ee.parentNode.removeChild(ee);else{style=d.createElement('style');style.id=id;style.styleSheet?style.styleSheet.cssText=css:style.appendChild(d.createTextNode(css));d.head.appendChild(style)}})(document)
View contains.js
const handleClick = e => {
if (!modalEl.contains(e.target)) modalEl.hidden = !0
}