Skip to content
cross-browser DOM ready module
JavaScript
Find file
Latest commit e3346c2 Oct 31, 2013 @ryanve Bump to 0.9.5

README.md

oi

cross-browser DOM ready module

$ npm install oi

Usage

Fire a function when the DOM is ready:

oi.domReady(function (oi) {
    // `this === document` in here
});

Simple cross-browser event methods:

oi.addEvent(elem, eventName, handler);
oi.removeEvent(elem, eventName, handler);

Integration

oi has a special method called .bridge() designed for integration. Integrated methods include the top-level .domReady/.addEvent/.removeEvent methods. If the receiver has an .fn object, it will also receive .fn.ready. Note that oi.domReady and oi.fn.ready are identical. The latter is provided purely for integration purposes.

oi.bridge(receiver) // integrate `oi`'s public methods into `receiver` (won't overwrite existing props)
oi.bridge(receiver, true) // integrate `oi`'s public methods into `receiver` (overwrites existing props)

The default behavior of the oi.bridge() makes it so that the receiver becomes the first arg passed to fns, like so:

receiver.domReady(function (receiver) {
    // `this === document` in here
});

jQuery-compatible receivers also get .fn.ready:

receiver(document).ready(function (receiver) {
    // `this === document` in here
});

The .domReady (and .fn.ready) methods both contain both a .remix() method that can be used for freeform integration. Use this if you want to create a new version of the ready function which sends multiple custom args. The .remix() method returns a new version of itself:

receiver.domReady = oi.domReady.remix(customArg0, customArg1 /*, ...*/);

See advanced #integration notes in the source.

MIT License

Copyright (C) 2012 by Ryan Van Etten

Something went wrong with that request. Please try again.