Skip to content

Instantly share code, notes, and snippets.

@Skateside
Skateside / addEventListener.js
Created July 12, 2012 21:41
I'm working on a polyfill for addEventListener. When it's complete, it will work with custom events, support removeEventListener and support the DOMContentLoaded event
// Shim to make sure that we've got the modern functions and methods that we
// need, namely [].forEach, [].map and Object.keys
(function () {
var undef, // = undefined;
isStringArray = 'a'[0] === 'a', // Used in toObject.
toString = Object.prototype.toString, // Used for class checking.
hasDontEnumBug = !{toSring: null}.propertyIsEnumerable('toString'),
@Skateside
Skateside / extend.js
Created July 29, 2012 22:06
I've been looking at Sugar and RightJS and I figured I'd start playing with my own version. I like what these things do to the language, they make it seem a lot more sensible. Ultimately this would add the ES5 and ES6 methods as well as some more new ones
// This is very similar to the standard implimentation of Object.extend but the
// important difference here is that this method will not overwrite any existing
// method of the source object. This makes it idea for updating native objects.
if (!Object.hasOwnProperty('update')) {
(function () {
'use strict';
var setProp = function (source, property, value) {
Object.defineProperty(source, property, {
@Skateside
Skateside / Basic shim.js
Created October 8, 2012 20:26
Started using mixins quite a bit so I built a few functions to make it easier.
// These shims patch methods that the SK80 micro-library uses. References to the
// ES5 spec have been included to ensure that the shims are as close to
// standards as possible.
(function () {
'use strict';
var isStringArray = 'a'[0] === 'a',
objProto = Object.prototype,
toString = objProto.toString;
@Skateside
Skateside / modular.css
Last active July 6, 2016 18:45
Having read up on SMACSS, I put together a basic starting point for all my style sheets. This is that starting point.
/* # Base rules
This style sheet attempts to show how CSS selectors can be limited to no more
than a single class (although there are exceptions). Keeping to such a
restriction helps contain the styling to a module and allows for easier
sub-classes of modules. It also enables the surgical classes (below) to work.
## Universal rules
@Skateside
Skateside / supportsSelector.js
Created November 14, 2012 10:18
CSS selector support ion a handy function
// Detects whether or not a given CSS selector is supported by the current
// browser.
//
// Takes:
// selector (String) The CSS selector to test.
// Returns:
// (Boolean) true if the selector is supported, false
// otherwise.
var supportsSelector = (function () {
@Skateside
Skateside / prototype.js
Last active October 14, 2015 01:08
Just a simpler version of SK80.create from the mixin micro library. Note to self: integrate this
/**
* Extends one object with another. The object in the first argument is
* modified.
*
* @param {Object} source Source object to extend.
* @param {Object} extra Additional properties to add to the source object.
* @return {Object} Modified source object.
*/
function extendObject(source, extra) {
@Skateside
Skateside / jsdoc.js
Last active December 17, 2015 03:49
This is a simple exploration of the Google Closure Compiler's use of JSDoc and the @type's needed to validate the code.
/*
General notes:
Curly braces around the types seem to be optional. "{number}" works the same as
"number".
*/
@Skateside
Skateside / inheritance.js
Created May 9, 2013 11:33
Playing around with simplifying inheritance in JavaScript. Not sure if this ill ever work, but worth playing with, I think.
function forin(obj, fn) {
var prop = '';
for (prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
fn.call(null, obj[prop], prop, obj);
}
@Skateside
Skateside / placeholder.js
Last active December 17, 2015 17:09
An object-oriented shim for placeholder text. This requires the jQuery library.
/*globals $, document */
/**
* A simple shim for the placeholder attribute.
*/
if (typeof (document.createElement('input')).placeholder !== 'string') {
$(function () {
'use strict';
@Skateside
Skateside / onclasschange.js
Created March 27, 2014 11:32
Nothing short of a hack, but a surprisingly useful one when you can't change the main scripts.
/**
* Add a handler to check if a class changes on a given element.
* The handler will get two arguments: the new class and the old class.
*
* @param {Element} element Element whos class changes should be watched.
* @param {Function} func Function to call when the class changes.
*/
var onclasschange = (function () {
'use strict';