Skip to content

Instantly share code, notes, and snippets.

/**
* Creates a string of an element, showing the node name and all attributes.
* This is mainly useful for debugging in Internet Explorer where a DOM node
* representation isn't shown in the console.
*
* @param {Element} elem Element to stringify.
* @return {string} String representation of the element.
*/
function stringifyElem(elem) {
@Skateside
Skateside / dom.js
Created April 22, 2014 14:51
Playing with simply but highly-efficient DOM selections
var dom = {
toArray: function (nodes) {
var array = [];
if (nodes) {
array = typeof nodes.length === 'number' ?
Array.prototype.slice.call(nodes) :
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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",