Skip to content

Instantly share code, notes, and snippets.

@chapuzzo
Forked from paulirish/bling.js
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save chapuzzo/7b25e8f0d4fa0a0ac0b4 to your computer and use it in GitHub Desktop.

Select an option

Save chapuzzo/7b25e8f0d4fa0a0ac0b4 to your computer and use it in GitHub Desktop.
// blinggggggggggg
Window.prototype.$ = document.querySelectorAll.bind(document)
Node.prototype.on = function (name, fn) {
this.addEventListener(name, fn)
}
// NodeList needs all Array goodies
NodeList.prototype.__proto__ = Array.prototype
// NodeList needs EventTarget goodies but iterated
NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) {
this.forEach(function (elem, i) {
elem.on(name, fn)
})
} // todo: dispatchEvent & removeEventListener
// We should be able to forEach on the qSA result.
document.querySelectorAll('input').forEach(function (el) {
el.readOnly = true
})
// addEventListhistakestoolongtotype. on() method
document.body.on('dblclick', function (e) {
console.log('double clicked the body')
})
// classic Bling + on()
$('p').on('click', function (e) {
p.hidden = true
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment