0.2.0 • Published 8 years ago

saiji v0.2.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

saiji npm version Build Status

eventListener wrapper

Sauce Test Status

Install

npm

npm install saiji

browser

download here

Usage

on

addEventListener

// HTMLElement
var button = document.getElementById("button");
saiji(button).on("click", function() {
    // something
});

// HTMLCollection
var buttons = document.getElementsByTagName("button");
saiji(buttons).on("click", function() {
    // something
});

once

var count = 0;
var button = document.getElementById("button");
saiji(button).once("click", function() {
    count++;
});
button.click();
button.click();
assert.strictEqual(count, 1);

off

var button = document.getElementById("button");
saiji(button).on("click", function() {
    count++;
});
button.click();
// off
saiji(button).off("click", function() {
    count++;
})
button.click();
assert.strictEqual(count, 1);

Use instance

var button = document.getElementById("button");
var instance = saiji(button).on("click", function() {
    count++;
});
button.click();
// off
instance.off();
button.click();
assert.strictEqual(count, 1);

DOMContentLoaded

If document.readyState is complete, DOMContentLoaded is executed immediately

License

MIT