saiji
v0.2.0
Published
eventListener wrapper
Downloads
1
Readme
saiji
eventListener wrapper
Install
npm
npm install saiji
browser
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