Skip to content

Instantly share code, notes, and snippets.

@Skateside
Skateside / lib.object-hasown-groupby.d.ts
Last active January 26, 2024 22:58
Just thinking aloud about re-writing the Pocket Grimoire
export {}
declare global {
interface ObjectConstructor {
/**
* Checks to see if the given property is in the given object.
* @param object Object to check in.
* @param property Property to check for.
@Skateside
Skateside / breakout.css
Last active August 25, 2021 11:07
Making 100vw take up the whole width without a horizontal scrollbar or overflow:hidden
/* https://css-tricks.com/full-width-containers-limited-width-parents/#no-calc-needed */
/* "No calc() needed" now with added calc()! */
.breakout {
--main-bar: var(--scroll-bar, 0px);
--main-half-bar: calc(var(--main-bar) / 2);
width: 100vw;
width: calc(100vw - var(--main-bar));
position: relative;
left: 50%;
right: 50%;
@Skateside
Skateside / aria.js
Created September 30, 2018 12:32
Thinking aloud about a WAI-ARIA library
let types = [
[Aria.Property, [
"atomic",
]],
[Aria.ReferenceCollection, [
"controls",
]],
[Aria.State, [
"busy",
"current",
@Skateside
Skateside / polyfill.js
Created February 8, 2018 19:59
A simple polyfill for the "jQuery style methods" that have been added recently. Written in ES6 syntax
function polyfill(object, name, value) {
if (typeof object[name] !== typeof value) {
Object.defineProperty(object, name, {
value,
configurable: true,
enumerable: false,
writable: true
});
@Skateside
Skateside / unit tests.js
Last active August 2, 2017 08:14
jQuery AMCSS plugin
// $.am();
// $.addAm();
// $.removeAm();
// $.hasAm();
// $.normaliseAm() and $.normalizeAm()
// $.amHooks
// $.AM_PREFIX
describe("jQuery#am", function () {
@Skateside
Skateside / observer.js
Last active October 1, 2016 10:45
A simple, tiny and robust JavaScript observer
/**
* observer
*
* A namespace for observers. To create one, simply call the `makeObserver`
* function:
*
* var observer = makeObserver();
*
* This allows multiple observers to be run if needed. Subscribe to events
* using [[observer.on]], unsubscribe using [[observer.off]] and trigger events
@Skateside
Skateside / Access.js
Last active December 14, 2015 22:34
Getter/Setter object in JavaScript. Loosely based on the Varien_Object in Magento
/**
* access
*
* Created by calling the `Access` function.
*
* var a1 = Access();
* var a2 = new Access();
*
* Initial data can be passed, see [[access.addData]].
*
@Skateside
Skateside / jquery.imagepromise.js
Last active August 29, 2015 14:20
Convert images of a given element into promises and trigger an event when they all load.
/*
MIT license.
Copyright (c) 2015 James "Skateside" Long
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Skateside
Skateside / watch.js
Created April 21, 2015 10:04
Watch for attribute changes
/**
* watch(element, attribute, handler)
* - element (Element): Element whose attribute should be watched for changes.
* - attribute (String): Attribute to watch.
* - handler (Function): Function to execute when the attribute changes.
*
* `watch` allows DOM Nodes to have their attributes watched for changes.
* Internally, this function uses the most efficient mean possible to watch for
* the change (more in the **Configuring** section).
*
@Skateside
Skateside / createClass.js
Last active December 14, 2015 15:18
A handy function that creates a class in JavaScript
var createClass = (function () {
'use strict';
// Basic no-operation function
var noop = function () {
return;
},
// Tests to see whether or not regular expressions can be called on