bling dot js
Because you want the $ of jQuery without the jQuery.
You may be interested in bling.js if you get tired of the [].slice.call( document.querySelectorAll('.foo'), function(){ …
rodeo. It does this:
// forEach over the qSA result, directly.
document.querySelectorAll('input').forEach(el => /* ... */);
// on() rather than addEventListener()
document.body.on('dblclick', evt => /* ... */);
// classic $ + on()
$('p').on('click', el => /* ... */);
It doesn't do anything else. This is not a jQuery equivalent.
on()
works on elements, document
, window
, and results from querySelector
& querySelectorAll
.$
is qSA so if you're grabbing a single element you'll have to [0]
it.Node.prototype.on = EventTarget.prototype.addEventListener
is awesome. It works in Chrome/FF but not yet in IE/Safari.dispatchEvent
& removeEventListener
. I'm OK with that./* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) {
this.forEach(function (elem, i) {
elem.on(name, fn);
});
}