{"_id":"filter-altered-clicks","_rev":"10-9b47017e32f72e631b5e93c09d8ca61b","name":"filter-altered-clicks","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","dist-tags":{"latest":"2.1.1"},"versions":{"1.0.0":{"name":"filter-altered-clicks","version":"1.0.0","keywords":["dom","events","click","middle","alt","shift","ctrl","cmd","defaultPrevented"],"author":{"url":"bfred.it","name":"Federico Brigante","email":"github@bfred.it"},"license":"MIT","_id":"filter-altered-clicks@1.0.0","maintainers":[{"name":"bfred-it","email":"npm@bfred.it"}],"homepage":"https://github.com/bfred-it/filter-altered-clicks#readme","bugs":{"url":"https://github.com/bfred-it/filter-altered-clicks/issues"},"xo":{"env":["browser"],"esnext":true},"dist":{"shasum":"1645f90dac17ede380baf7b41b81ee96ae00a658","tarball":"https://registry.npmjs.org/filter-altered-clicks/-/filter-altered-clicks-1.0.0.tgz","integrity":"sha512-4RYgY/tpQi+v6ZahEaop0Fv9Yrfmucpm4/wiH71raSSeaEC6OUWzTsM45kDmS49/pdkZTqBB76FKMqUuDyT3lg==","signatures":[{"sig":"MEUCIQD37slZFqNZp6piYekTZp0j/PLKIA5W0cDTjUczbyJJfAIgKMiwi4c7BhHMxXRLDWZae56NzuXm6xr2Obljzvhm9fo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"dist/filter-altered-clicks.common-js.js","_from":".","files":["dist"],"module":"dist/filter-altered-clicks.es-modules.js","_shasum":"1645f90dac17ede380baf7b41b81ee96ae00a658","gitHead":"f52fc05bb8dc5ab74fe2bd3812a1b4d09d10a89f","scripts":{"test":"xo && ava; npm run build","build":"npm-run-all --silent jsfix build:*","jsfix":"xo --fix","watch":"npm-run-all --parallel --silent watch:*","build:js":"bfred-npm-bundler filter-altered-clicks filterAlteredClicks","prepublish":"npm run build","watch:test":"ava --watch","watch:build":"onchange 'index.js' --initial -- npm run build -- --continue-on-error"},"_npmUser":{"name":"bfred-it","email":"npm@bfred.it"},"repository":{"url":"git+https://github.com/bfred-it/filter-altered-clicks.git","type":"git"},"_npmVersion":"3.10.8","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","directories":{},"_nodeVersion":"6.2.2","devDependencies":{"xo":"^0.16.0","ava":"^0.16.0","onchange":"^3.0.2","npm-run-all":"^3.1.0","bfred-npm-bundler":"^7.1.2"},"_npmOperationalInternal":{"tmp":"tmp/filter-altered-clicks-1.0.0.tgz_1476022180358_0.5269253747537732","host":"packages-12-west.internal.npmjs.com"}},"1.0.1":{"name":"filter-altered-clicks","version":"1.0.1","keywords":["dom","events","click","middle","alt","shift","ctrl","cmd","defaultPrevented"],"author":{"url":"bfred.it","name":"Federico Brigante","email":"github@bfred.it"},"license":"MIT","_id":"filter-altered-clicks@1.0.1","maintainers":[{"name":"bfred-it","email":"npm@bfred.it"}],"homepage":"https://github.com/bfred-it/filter-altered-clicks#readme","bugs":{"url":"https://github.com/bfred-it/filter-altered-clicks/issues"},"xo":{"env":["browser"],"esnext":true},"dist":{"shasum":"0526a43b601e79ed7d885d075465df4414415d09","tarball":"https://registry.npmjs.org/filter-altered-clicks/-/filter-altered-clicks-1.0.1.tgz","integrity":"sha512-tCjyoHHx1QxmNxAUhoQEzsYoQXg6rvf5V5YYLo5OdOVwz1vPCQ/+SPHunI7s0lyB044FebOSRBkj9uzJBVTh6g==","signatures":[{"sig":"MEQCIBmjAUD0J0IARhvOmJ0NGU1zsNgW700LPkVndTVHhgf2AiAed3ZtLgeH9DzO65mv8IYDX2uZtPsjtsRhokJZMORu9w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"dist/filter-altered-clicks.common-js.js","_from":".","files":["dist"],"module":"dist/filter-altered-clicks.es-modules.js","_shasum":"0526a43b601e79ed7d885d075465df4414415d09","gitHead":"4aba324224ef6f0d50f478f82aa57904dac80e06","scripts":{"test":"xo && ava; npm run build","build":"npm-run-all --silent jsfix build:*","jsfix":"xo --fix","watch":"npm-run-all --parallel --silent watch:*","build:js":"bfred-npm-bundler filter-altered-clicks filterAlteredClicks","prepublish":"npm run build","watch:test":"ava --watch","watch:build":"onchange 'index.js' --initial -- npm run build -- --continue-on-error"},"_npmUser":{"name":"bfred-it","email":"npm@bfred.it"},"repository":{"url":"git+https://github.com/bfred-it/filter-altered-clicks.git","type":"git"},"_npmVersion":"3.10.8","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","directories":{},"_nodeVersion":"6.2.2","devDependencies":{"xo":"^0.16.0","ava":"^0.16.0","onchange":"^3.0.2","npm-run-all":"^3.1.0","bfred-npm-bundler":"^7.1.2"},"_npmOperationalInternal":{"tmp":"tmp/filter-altered-clicks-1.0.1.tgz_1476022615588_0.4664731512311846","host":"packages-16-east.internal.npmjs.com"}},"2.0.0":{"name":"filter-altered-clicks","version":"2.0.0","keywords":["alt","click","cmd","ctrl","defaultPrevented","dom","events","middle","shift"],"author":{"url":"https://fregante.com","name":"Federico Brigante","email":"me@fregante.com"},"license":"MIT","_id":"filter-altered-clicks@2.0.0","maintainers":[{"name":"fregante","email":"opensource@bfred.it"}],"homepage":"https://github.com/fregante/filter-altered-clicks#readme","bugs":{"url":"https://github.com/fregante/filter-altered-clicks/issues"},"xo":{"env":["browser"]},"dist":{"shasum":"1830185c385ce4eeb40525000f6dcfce5460fb65","tarball":"https://registry.npmjs.org/filter-altered-clicks/-/filter-altered-clicks-2.0.0.tgz","fileCount":5,"integrity":"sha512-5HtDAiHmCfbp6oKNfKWeA1kAbCPCfAcUjgJ1vf5GYvXxABHe8uGGDZrnU3ny9fJTcemfSNgdD16w3GulGoznxQ==","signatures":[{"sig":"MEUCIQDN0aPnSRhx6AGqxOnmbn9q7ysqeB6ANZFai0Wbei1clwIgN6akhDS/4GhjqjGtgIFTxSUFiSV7OUG4zKG8xuyqKG4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5464,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj5MwbACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo9fw//TO/I9BbQt6EDE8HgvRcrFyuar6ENBp9/dmLPrQZzNcVfwo9b\r\nF34vRA48G9nj+hb9yrSAkakXtJ6SD2wMk/piu8eVkd6FhPxk0x+EAairDsYS\r\nkE+RFRYCCF1OaadQzx18CDghAmVsdz1PRjEBANT7MIMVdEMjWJadL2poP0ou\r\nx0VLtjExbMqfywGG2lhL/McvPXlm//39IIL87Mjr5e+eW8WYeD+azoOt/taQ\r\nL3yiS1EKs50WART+HMgBhK8jfNP8QzS9L3lrQNuNKrRdP2mZIYy0XQItkHkG\r\nMGg+kavLXZKeYxZAqcawVnnZCy1kQEJR/LWONTO3FToxta+wRvq5zn4396I6\r\njZNwVP0DTErlYIT4upx8JBgMc3W/nzCIgAjcdhJjWiH0vbM3nSRis48XocQd\r\n7Ymgl/l8dNPk3Put12DK95UtAqqtGRvFiT9XxY2JrQI1TW7qnq51+bDZ++ai\r\nZbXmPN3KKQdyCQdbpWANi2WJFWQ/NXRErKY/oTEb4P29sqoDZknyPCyWsofN\r\nbWWKlQrI+/e2ExtRpvqFKuxQIEoHwj2743ifle2BnkoU+A0FvmA8oPBaoz1B\r\nnpbYJUv/eO7YxDUYzdGd2w40e34SvTcKoOmJIFw3b8G/RIysJYCNeAeZZjRH\r\noQQdADSLCjhA/nACloxNPBgyY7hA4HR2CSs=\r\n=+EQq\r\n-----END PGP SIGNATURE-----\r\n"},"type":"module","types":"./index.d.ts","exports":"./index.js","funding":"https://github.com/sponsors/fregante","gitHead":"2ce73a89fc0e06dbebe07c42b9a84265d39aeab3","scripts":{"test":"xo && ava"},"_npmUser":{"name":"fregante","email":"opensource@bfred.it"},"repository":{"url":"git+https://github.com/fregante/filter-altered-clicks.git","type":"git"},"_npmVersion":"8.19.3","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","directories":{},"_nodeVersion":"18.13.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.53.1","ava":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/filter-altered-clicks_2.0.0_1675938843717_0.047093364228719015","host":"s3://npm-registry-packages"}},"2.0.1":{"name":"filter-altered-clicks","version":"2.0.1","keywords":["alt","click","cmd","ctrl","defaultPrevented","dom","events","middle","shift"],"author":{"url":"https://fregante.com","name":"Federico Brigante","email":"me@fregante.com"},"license":"MIT","_id":"filter-altered-clicks@2.0.1","maintainers":[{"name":"fregante","email":"opensource@bfred.it"}],"homepage":"https://github.com/fregante/filter-altered-clicks#readme","bugs":{"url":"https://github.com/fregante/filter-altered-clicks/issues"},"xo":{"env":["browser"]},"dist":{"shasum":"9762bd23d1b7adb732d6c8884708fbfdc5f0b0d5","tarball":"https://registry.npmjs.org/filter-altered-clicks/-/filter-altered-clicks-2.0.1.tgz","fileCount":5,"integrity":"sha512-/eguM/WumjpUls1kgLNk8T5JAdqTvI9hc8q7mOXsxIZAvxRLwttigaiJrfIuNXhREL8VrQZQKBiwFApJSbE7qA==","signatures":[{"sig":"MEQCIBQ+O2IQsTyj8o+wTSjyHJWhOwnllDoifLDH7dESB+AzAiBc182BA6nb1k66rrQmXFFexWaYXDhwR2DmBlLFv/RZ2w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5292,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj5NNEACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpzfw//ZXnzAkZ7qyGjE+s3Zncjvw+qzUirOuNq5a2vJcW1gdjirEdB\r\n13Nr6wBbrF3l8vpXN/SJUwamhaxmGybSNXMSH9cnl8u4gMCA1dke1TMAYFUP\r\nIW/erwPIWwTXHzZ3xbCCV3R8eB6SRM5clZ/b51YGGAWlQKXgoe+jzUfIbiIh\r\n9rGgPwLf4qg4heyULZ44qniv8IFZkP3lq5lOSnRXU5QU1JavVtGVR3j7QmmL\r\nSkPZFmB33IgZV2TVoWWmyQ0u83nPSBP1EosjD/r4hsG5rtTweR2iVOe/ow/Y\r\nLKG6QkYC3qH6S+d3yxO3INAXwNs4iYkohzm3itqqau9B+WkA8zmEcH9rv+H5\r\n+nPsq1GUCz8Rd5Ow0F+tkGvPtNg/cLfg/3LKybYzAKKDALWBhiZwUwOsLxgj\r\nqV1z7AOGeHFZ0PVz+ykhTBbqKGNPwto/rWN3uTtkcwVRo0gAA+RVxZGXdciu\r\nvudmnczC599w6tittFaIM0EO4ZtLJVRL842m2dW+t33Ug++izwn3i266yBoZ\r\n3UOdmnIq5ZEs3huaDhpNRLwtEul8M2UDS1tjSN7DJo0vVgTczbSk3j9qHAV7\r\nVQHg/6YIAk7Z96i16aLIOyTNo2pNVhPiAtQSsXIK1n7SR659S57+nSiUMIqW\r\nDIY3DjKnUEc17cLyWTohB+MVrinnY0/3MaA=\r\n=3C6/\r\n-----END PGP SIGNATURE-----\r\n"},"type":"module","types":"./index.d.ts","exports":"./index.js","funding":"https://github.com/sponsors/fregante","gitHead":"b3bd2ae4073e7beb6361d675a3e5d4729fa3f2c8","scripts":{"test":"xo && ava"},"_npmUser":{"name":"fregante","email":"opensource@bfred.it"},"repository":{"url":"git+https://github.com/fregante/filter-altered-clicks.git","type":"git"},"_npmVersion":"8.19.3","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","directories":{},"_nodeVersion":"18.13.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.53.1","ava":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/filter-altered-clicks_2.0.1_1675940676564_0.4898556977679207","host":"s3://npm-registry-packages"}},"2.1.0":{"name":"filter-altered-clicks","version":"2.1.0","keywords":["alt","click","cmd","ctrl","defaultPrevented","dom","events","middle","shift"],"author":{"url":"https://fregante.com","name":"Federico Brigante","email":"me@fregante.com"},"license":"MIT","_id":"filter-altered-clicks@2.1.0","maintainers":[{"name":"fregante","email":"opensource@bfred.it"}],"homepage":"https://github.com/fregante/filter-altered-clicks#readme","bugs":{"url":"https://github.com/fregante/filter-altered-clicks/issues"},"xo":{"env":["browser"]},"dist":{"shasum":"18ee18999edca1ea1332d4711cc9e60f682cf946","tarball":"https://registry.npmjs.org/filter-altered-clicks/-/filter-altered-clicks-2.1.0.tgz","fileCount":5,"integrity":"sha512-JJI5QKPB+eYDsd51OBzKiOknDTgxko6vPSEa2bEM+fSfvisQKdNQWzQUSHRsfFFkvkEqZS50WfUdCzN9JA5eag==","signatures":[{"sig":"MEQCIGqFISjGU0yqjTHOO5bIOijJd+v++c5gxr+JmRjE60jlAiB2UlGfW2E6IlN2hTZ290rqyP8IekUDPOZfSgmnHOML3w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5744},"type":"module","types":"./index.d.ts","exports":"./index.js","funding":"https://github.com/sponsors/fregante","gitHead":"1dac2cc5785cd562832c2de2f19ad87c2edd2a4d","scripts":{"test":"xo && ava"},"_npmUser":{"name":"fregante","email":"opensource@bfred.it"},"repository":{"url":"git+https://github.com/fregante/filter-altered-clicks.git","type":"git"},"_npmVersion":"10.5.2","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","directories":{},"_nodeVersion":"20.13.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.58.0","ava":"^6.1.3"},"_npmOperationalInternal":{"tmp":"tmp/filter-altered-clicks_2.1.0_1718175038609_0.9113102763398508","host":"s3://npm-registry-packages"}},"2.1.1":{"name":"filter-altered-clicks","version":"2.1.1","description":"Filter alt-click, ctrl-click, shift-click, middle click, ...","keywords":["alt","click","cmd","ctrl","defaultPrevented","dom","events","middle","shift"],"repository":{"type":"git","url":"git+https://github.com/fregante/filter-altered-clicks.git"},"funding":"https://github.com/sponsors/fregante","license":"MIT","author":{"name":"Federico Brigante","email":"me@fregante.com","url":"https://fregante.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","scripts":{"test":"xo && ava"},"xo":{"env":["browser"]},"devDependencies":{"ava":"^6.1.3","xo":"^0.58.0"},"_id":"filter-altered-clicks@2.1.1","gitHead":"2736b69cc98a65024d6167aad8716535bf53f5b6","bugs":{"url":"https://github.com/fregante/filter-altered-clicks/issues"},"homepage":"https://github.com/fregante/filter-altered-clicks#readme","_nodeVersion":"20.13.1","_npmVersion":"10.5.2","dist":{"integrity":"sha512-JlwKMFcAC6bSOAsxWM40WC7cs9nKyglLkMiR+qPRveyGEVmQ4lVDyn5V/YvOiSsy9C2BId+3f8wyuGHmBQE29g==","shasum":"747cecf65a06821b5a7a7d106839f6fa7aae779d","tarball":"https://registry.npmjs.org/filter-altered-clicks/-/filter-altered-clicks-2.1.1.tgz","fileCount":5,"unpackedSize":5805,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDT6ulMqECeYFU08u38K28+R2cA5jYKbKaGnXJw6lHZrgIgVq8C1CMQg/kjL9nQKdT3uJz4ND9kty5Y25BAkvzChRo="}]},"_npmUser":{"name":"fregante","email":"opensource@bfred.it"},"directories":{},"maintainers":[{"name":"fregante","email":"opensource@bfred.it"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/filter-altered-clicks_2.1.1_1718175262942_0.18178653780065845"},"_hasShrinkwrap":false}},"time":{"created":"2016-10-09T14:09:40.580Z","modified":"2024-06-12T06:54:23.276Z","1.0.0":"2016-10-09T14:09:40.580Z","1.0.1":"2016-10-09T14:16:57.429Z","2.0.0":"2023-02-09T10:34:03.880Z","2.0.1":"2023-02-09T11:04:36.852Z","2.1.0":"2024-06-12T06:50:38.754Z","2.1.1":"2024-06-12T06:54:23.112Z"},"maintainers":[{"name":"fregante","email":"opensource@bfred.it"}],"author":{"name":"Federico Brigante","email":"me@fregante.com","url":"https://fregante.com"},"repository":{"type":"git","url":"git+https://github.com/fregante/filter-altered-clicks.git"},"keywords":["alt","click","cmd","ctrl","defaultPrevented","dom","events","middle","shift"],"license":"MIT","homepage":"https://github.com/fregante/filter-altered-clicks#readme","bugs":{"url":"https://github.com/fregante/filter-altered-clicks/issues"},"readme":"# filter-altered-clicks [![][badge-gzip]][link-bundlephobia]\n\n[badge-gzip]: https://img.shields.io/bundlephobia/minzip/filter-altered-clicks.svg?label=gzipped\n[link-bundlephobia]: https://bundlephobia.com/result?p=filter-altered-clicks\n\n> Filter alt-click, ctrl-click, shift-click, middle click, ...\n\nMiddle-clicking on a link should open it in a new tab. SPAs hijack normal links to load them via ajax, breaking all _altered clicks_... unless they `filter-altered-clicks` 😉\n\n_Altered clicks_ are:\n\n- <kbd>ALT</kbd>-click\n- <kbd>CTRL</kbd>-click\n- <kbd>SHIFT</kbd>-click\n- <kbd>CMD</kbd>-click\n- Any clicks that aren’t left-clicks\n- Clicks that already received `preventDefault()`. [Note](#onlyphysical)\n\n## Usage\n\n`filterAlteredClicks(listener)` accepts a function and returns a function.\n\nSimplest usage:\n\n```js\nelement.addEventListener(\n\t'click',\n\tfilterAlteredClicks(event => {\n\t\tconsole.log('Unaltered click!');\n\t})\n);\n```\n\njQuery usage:\n\n```js\n$(element).on(\n\t'click',\n\tfilterAlteredClicks(event => {\n\t\tconsole.log('Unaltered click!');\n\t})\n);\n```\n\nAjax loading example, using jQuery for brevity, but it's not necessary:\n\n```js\n$('a.ajax-link').on(\n\t'click',\n\tfilterAlteredClicks(event => {\n\t\t$('#content').load(this.href);\n\t\tevent.preventDefault();\n\t})\n);\n```\n\n## Install\n\n```sh\nnpm install --save filter-altered-clicks\n```\n\n```js\nimport filterAlteredClick, {isAlteredClick} from 'filter-altered-clicks';\n```\n\n## API\n\n### `filterAlteredClicks(listener, [onlyPhysical])`\n\nReturns a [`listener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Syntax) function that is called by `addEventListener` or `jQuery.on`. Receives the `Event` as the first parameter.\n\n#### `listener`\n\nType: `function`\n\nThe same listener function you would pass to `addEventListener(type, listener)` and `.on(type, listener)`.\n\n#### `onlyPhysical`\n\nType: `boolean`, defaults to `false`\n\nOnce filtered, `listener` is normally not called if the event has already been `defaultPrevented`. Set this parameter to true to avoid this behavior.\n\nExample:\n\n```js\nelement.addEventListener(\n\t'click',\n\tfilterAlteredClicks(event => {\n\t\tconsole.log('Unaltered click!');\n\t\tconsole.log('I’m altering this click:');\n\t\tevent.preventDefault();\n\t})\n);\n\nelement.addEventListener(\n\t'click',\n\tfilterAlteredClicks(event => {\n\t\t// This will never be called because the previous one used .preventDefault\n\t})\n);\n\nelement.addEventListener(\n\t'click',\n\tfilterAlteredClicks(event => {\n\t\tconsole.log(\n\t\t\t'Unaltered click! But maybe .preventDefault was already called'\n\t\t);\n\t}, true)\n); //<-- notice the true as the second parameter of filterAlteredClicks\n```\n\nThis is called `onlyPhysical` because it refers to \"only physical alterations\", which is _altered by keyboard and not by code._\n\n### `isAlteredClick(event)`\n\nReturns true if any modifier were held while clicking, or if any button other than the main button was clicked.\n\n#### `event`\n\nType: [`MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)\n\nThe event object received in the listener function\n\n## Dependencies\n\nNone!\n\n## Related\n\n- [on-off](https://github.com/fregante/on-off/): Add and remove multiple events on multiple elements in <1KB\n\n## License\n\nMIT © [Federico Brigante](https://fregante.com)\n","readmeFilename":"readme.md"}