Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / AMD module list.md
Created May 26, 2011 15:25
List of AMD-compliant modules in the wild

A List of actively-supported, reusable, open-source, AMD-compliant modules in the wild. Let me know if you have another module to add to the list!

querySelectorAll (css3-based dom selector engine)

Promises / Deferreds

@unscriptable
unscriptable / dojoParse
Created May 16, 2011 19:56
aop-ish way to detect when dojo.parser.parse is called
define(['dojo/parser, wire/Deferred'], function (parser, Promise) {
var orig = parser.parse,
promise = new Promise();
parser.parse = function (node) {
orig.apply(parser, arguments);
promise.resolve();
};
return promise;
@unscriptable
unscriptable / another-way.js
Created May 12, 2011 20:49
AMD-compatible CommonJS Module/1.1 that can also be loaded in a script tag
// This boilerplate would allow a module to run in node.js or an
// AMD-enabled browser environment. On node.js, the syntax is:
// var Color = require("./Color").Color,
// color = new Color("#BADA55");
// In the browser, the syntax is:
// var color = new Color("#BADA55"); // window.Color is implied
(function (define) {
define(function () {
@unscriptable
unscriptable / IOC-DI.js
Created May 11, 2011 23:00
IOC/DI as an alternative to module swapping
// admittedly, dependency injection is better for non-integral dependencies.
// integral dependencies like coding constructs such as array iterators (forEach),
// type detectors (isArray, isFunction), etc are easier to work with as declared
// dependencies/modules. there are other ways to inject dependencies (e.g.
// constructor params). this is just how we're doing it.
// this example shows the injection of non-integral dependencies
define(function () {
return {
@unscriptable
unscriptable / opera script load order.txt
Created March 14, 2011 21:22
Opera doesn't fire load events in the same order as the scripts are loaded
Firefox:
script1 executes
script1 fires load event
script2 executes
script2 fires load event
script3 executes
script3 fires load event
[{"match":"/BlackBerry.+AppleWebKit\\/([\\d\\.]+)/","name":"BlackBerry","version":400,"has":{"activex":false,"activex-enabled":false,"array-es5":true,"array-every":true,"array-filter":true,"array-foreach":true,"array-indexof":true,"array-isarray":true,"array-lastindexof":true,"array-map":true,"array-reduce":true,"array-reduceright":true,"array-slice-nodelist":true,"array-some":true,"audio":true,"audio-m4a":true,"audio-mp3":true,"audio-ogg":true,"audio-wav":true,"bug-arguments-instanceof-array":false,"bug-array-concat-arguments":false,"bug-bgimagecache":true,"bug-computed-style-hidden-zero-height":false,"bug-computed-values-for-static":false,"bug-contains":false,"bug-dontenum-enumerable":false,"bug-es5-regexp":true,"bug-es5-trim":true,"bug-function-expression":false,"bug-getelementbyid-ids-names":false,"bug-getelementbyid-ignores-case":false,"bug-getelementsbyname":false,"bug-getelementsbytagname-returns-comment-nodes":false,"bug-offset-values-positioned-inside-static":false,"bug-overflow-style":false,"bug-pre
// Object Pascal separates each unit (file) into two main sections:
// interface and implementation.
// interface declares all of the publicly-facing stuff and has a
// list of dependencies (uses) implementation is the actual code
// and is private. it can have additional dependencies that the
// the interface doesn't have (and it's a good idea to keep as
// many out of the interface as possible to prevent circular
// dependencies).
module('optional name')
@unscriptable
unscriptable / tiny Promise.js
Created February 7, 2011 06:02
A minimalist implementation of a javascript promise
// (c) copyright unscriptable.com / John Hann
// License MIT
// For more robust promises, see https://github.com/briancavalier/when.js.
function Promise () {
this._thens = [];
}
Promise.prototype = {
<!-- dojo 1.x: all is well -->
<button dojotype="li.widget.Button" type="button" class="flat">Flat button</button>
<!-- dojo 1.6 html5 type and params attr -->
<button data-dojo-type="li.widget.Button" data-dojo-params="type:'button', class:'primary'">Primary button</button>
<!-- dojo 1.6 html5 type and native attrs: DOES NOT PICK UP ATTRS! -->
<button data-dojo-type="li.widget.Button" type="button" class="secondary">Secondary button</button>