{"_id":"handle","_rev":"1646833","name":"handle","description":"Handle events on elements","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"time":{"modified":"2026-10-27T16:04:40.000Z","created":"2013-12-31T03:44:29.350Z","1.0.0":"2014-01-02T18:36:56.265Z","0.0.2":"2013-12-31T03:51:31.307Z","0.0.1":"2013-12-31T03:44:29.350Z"},"users":{},"author":{"name":"ForbesLindesay"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/handle.git"},"versions":{"1.0.0":{"name":"handle","version":"1.0.0","description":"Handle events on elements","keywords":[],"dependencies":{"promise":"~3","matches-selector":"~1.0.0"},"devDependencies":{"run-browser":"~1.1.0","tape":"~2.3.2"},"scripts":{"test":"run-browser tests/index.js"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/handle.git"},"author":{"name":"ForbesLindesay"},"license":"MIT","testling":{"files":"tests/index.js","browsers":["iexplore/9.0","iexplore/10.0","chrome/30.0","chrome/31.0","chrome/canary","firefox/10.0","firefox/15.0","firefox/20.0","firefox/21.0","firefox/22.0","firefox/23.0","firefox/24.0","firefox/25.0","firefox/nightly","opera/11.0","opera/17.0","opera/next","safari/6.0","iphone/6.0","ipad/6.0"]},"readmeFilename":"README.md","bugs":{"url":"https://github.com/ForbesLindesay/handle/issues"},"homepage":"https://github.com/ForbesLindesay/handle","_id":"handle@1.0.0","dist":{"shasum":"ce32de15629056dfda29b94d08bf57b958a4c702","tarball":"http://registry-npm.ywwl.com/handle/download/handle-1.0.0.tgz","integrity":"sha512-nYbPC28AFfygw7/ApeoRz2N62OEIP1BorBbCuLKcvX/0HpPypqw8u/o4Pj2/sKHijtD/gp5GrzYoOmwAAt40WA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDMbUpMyovnsoItOA30JJLlZFAzQgarOdXsXKx+Hkt7agIgXe/eEHxhLZQWyVXy5GJNhAsDELaChY4mt5Ll77qK2xw="}],"size":4290,"noattachment":false,"key":"/handle/-/handle-1.0.0.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"publish_time":1388687816265,"_cnpm_publish_time":1388687816265},"0.0.2":{"name":"handle","version":"0.0.2","description":"Handle events on elements","keywords":[],"dependencies":{"promise":"~3","matches-selector":"~1.0.0"},"devDependencies":{"run-browser":"~1.0.0","tape":"~2.3.2"},"scripts":{"test":"run-browser tests/index.js"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/handle.git"},"author":{"name":"ForbesLindesay"},"license":"MIT","testling":{"files":"tests/index.js","browsers":["iexplore/9.0","iexplore/10.0","chrome/30.0","chrome/31.0","chrome/canary","firefox/10.0","firefox/15.0","firefox/20.0","firefox/21.0","firefox/22.0","firefox/23.0","firefox/24.0","firefox/25.0","firefox/nightly","opera/11.0","opera/17.0","opera/next","safari/6.0","iphone/6.0","ipad/6.0"]},"readmeFilename":"README.md","bugs":{"url":"https://github.com/ForbesLindesay/handle/issues"},"homepage":"https://github.com/ForbesLindesay/handle","_id":"handle@0.0.2","dist":{"shasum":"c26ee363e7711b5b413e3857e16623ec377d50f4","tarball":"http://registry-npm.ywwl.com/handle/download/handle-0.0.2.tgz","integrity":"sha512-d79r2zROzJ9r42sUvnjj3zlxjEpZ/DHmkdqQ+ffCwNbCRfQ0Uh6rkkMLkmkYNnHlkbfX40XycuRcLi/1mC62hw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCC4o74kEAHfUjcfYFZeAPXVk80jPDft/T2fQ+J/AaecAIhAKsKQj783xAkSKhFut380ivs9x6Uumpbqal5/w1T/0YY"}],"size":4032,"noattachment":false,"key":"/handle/-/handle-0.0.2.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"directories":{},"publish_time":1388461891307,"_cnpm_publish_time":1388461891307},"0.0.1":{"name":"handle","version":"0.0.1","description":"Handle events on elements","keywords":[],"dependencies":{"promise":"~3","matches-selector":"~1.0.0"},"devDependencies":{"run-browser":"~1.0.0","tape":"~2.3.2"},"scripts":{"test":"run-browser tests/index.js"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/handle.git"},"author":{"name":"ForbesLindesay"},"license":"MIT","testling":{"files":"tests/index.js","browsers":["iexplore/9.0","iexplore/10.0","chrome/30.0","chrome/31.0","chrome/canary","firefox/10.0","firefox/15.0","firefox/20.0","firefox/21.0","firefox/22.0","firefox/23.0","firefox/24.0","firefox/25.0","firefox/nightly","opera/11.0","opera/17.0","opera/next","safari/6.0","iphone/6.0","ipad/6.0"]},"readmeFilename":"README.md","bugs":{"url":"https://github.com/ForbesLindesay/handle/issues"},"homepage":"https://github.com/ForbesLindesay/handle","_id":"handle@0.0.1","dist":{"shasum":"2da546d8225930af603351ebf5d0eb35b5af22e2","tarball":"http://registry-npm.ywwl.com/handle/download/handle-0.0.1.tgz","integrity":"sha512-+LO8DTTAtJEyZE9yju9UFM6biM5ecIwZlKWkrouS5uilw8z3S2RVb3HVIINcLmIUg8wyx9PhNHMsjlgjtwQPfQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICkIGcgpy5F79tVARjzb7nTQQ47DL2LFBnXICM7PZWN+AiEA8PzpGUXwEifmWZ6YjttTVLYAqx1eLVdnfl/SS7uwb24="}],"size":4035,"noattachment":false,"key":"/handle/-/handle-0.0.1.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"directories":{},"publish_time":1388461469350,"_cnpm_publish_time":1388461469350}},"readme":"# handle\n\nHandle events on elements\n\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/handle.png)](https://gemnasium.com/ForbesLindesay/handle)\n[![NPM version](https://badge.fury.io/js/handle.png)](http://badge.fury.io/js/handle)\n\n[![browser support](https://ci.testling.com/ForbesLindesay/handle.png)](https://ci.testling.com/ForbesLindesay/handle)\n\n## Installation\n\n    npm install handle\n\n## API\n\n### `handle(element, event, fn [, capture])`\n\nHandle `event` on `element` using `fn`.  It returns a function that can be called to stop listening.  e.g. to build `once` you could write:\n\n```js\nvar handle = require('handle');\n\nfunction once(element, event, fn, capture) {\n  var dispose = handle(element, event, function (el, event) {\n    dispose();\n    fn(el, event);\n  }, capture);\n}\n```\n\nTypical usage might look like:\n\n```js\nvar handle = require('handle');\n\nhandle(document.getElementById('my-button'), 'click', function (button, e) {\n  e.preventDefault();\n  // do something\n});\n```\n\n### `handle(elements, event, fn [, capture])`\n\nYou can handle the same event on a whole list of elements in one go.  This does not need to be an array, it just needs to have a `.length` property that is a number and have indexed values.  e.g.\n\n\n```js\nvar handle = require('handle');\n\nhandle(document.querySelector('[data-action=\"do-something\"]'), 'click', function (button, e) {\n  e.preventDefault();\n  // do something\n});\n```\n\nIt too returns a `dispose` funciton.\n\n### `handle(selector, event, fn [, capture])`\n\nThis works just like jQuery's `$(document.body).delecate(selector, event, function (e) { fn(this, e) })`.  It too returns a `dispose` function.\n\nThe advantages/disadvantages of using this method are:\n\n - It will still capture the event if the element matching selector is added to the DOM after `handle` is called.\n - It captures the event later (i.e. after those handlers that were attached directly to elements lower in the DOM chain)\n - It only binds to one element, so can have better performance, but it must check every event for a match, so can have worse performance\n\ne.g.\n\n```js\nvar handle = require('handle');\n\nhandle('[data-action=\"do-something\"]', 'click', function (button, e) {\n  e.preventDefault();\n  // do something\n});\n```\n\nIf you want to delegate from something other than `document.body` you can select a start element via the `.on` method:\n\n```js\nvar handle = require('handle').on(document.getElementById('hideable-list'));\n\nhandle('li', 'click', function (li, e) {\n  e.preventDefault();\n  li.style.visibility = 'hidden';\n});\n```\n\n### `handle.once(element|elements|selector, event [, capture])`\n\nReturn a promise that is resolved with the event args once the event is fired.  `e.preventDefault()` is also called since it must be called within the same turn to work.\n\n## Running Tests\n\nTests can be easilly run locally in the browser of your choice, and have passed if it ends with `# ok`.  They are also run on testling-ci when pushed to the repository:\n\n```\nnpm install\nnpm test\n```\n\n## License\n\n  MIT","_attachments":{},"readmeFilename":"README.md","homepage":"https://github.com/ForbesLindesay/handle","bugs":{"url":"https://github.com/ForbesLindesay/handle/issues"},"license":"MIT"}