{"_id":"@abradley2/url-change-event","_rev":"2-3f279fe348efba57b5f0bc309a40b658","name":"@abradley2/url-change-event","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@abradley2/url-change-event","version":"1.0.0","description":"Intercepts link clicks and url changes then fires an event","main":"index.js","scripts":{"build":"browserify ./index.js -s urlChangeEvent -o ./dist/urlChangeEvent.js","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/abradley2/url-change-event.git"},"author":{"name":"Tony Bradley"},"license":"MIT","bugs":{"url":"https://github.com/abradley2/url-change-event/issues"},"homepage":"https://github.com/abradley2/url-change-event#readme","devDependencies":{"browserify":"^16.2.3","eslint":"^5.10.0","eslint-config-standard":"^12.0.0","eslint-plugin-import":"^2.14.0","eslint-plugin-node":"^8.0.0","eslint-plugin-promise":"^4.0.1","eslint-plugin-standard":"^4.0.0"},"gitHead":"59ee0e49c3f7c3933c7e44fdd4758583bac166e9","_id":"@abradley2/url-change-event@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"abradley2","email":"antbradley91@gmail.com"},"dist":{"integrity":"sha512-82WkdLQBah8pzNdOqFnMyvy06mcQrD6OGA26IBFKNWc5eu0smvctftTAYv9PpEYNymqxDsykiGf7ETleYaYhxw==","shasum":"2fb0b4ebe9615cdcf259ca74525ce0f9c72c86f0","tarball":"https://registry.npmjs.org/@abradley2/url-change-event/-/url-change-event-1.0.0.tgz","fileCount":7,"unpackedSize":8047,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcFpBjCRA9TVsSAnZWagAAU2AP/1thRE6oBZ4OI3cKUAgz\nd5Bcu9CkMZ7i1V26PZYOzFNMoZA8a770IdmUWMOa62IIhPEM16/27Xa9jTOJ\ny+NDdEfPqm/5R2WSvgOgv1JmKTHFL8x3bhAK50De9ZdkaVcmAS8zvL1Nh7mU\nHqt72+PxDO1F8XcbjywgJEj9oL8M/BeGgli/b5IaO+0IRa7/L6YWZaHBHUcD\nT7jXSh5f2RJ5emLYEiIlrjy8TGwTcIx3mCz1oZHxaZzKG3zTnyP9R8dzgHLA\nrLfULeyrRkWW8zSenrvFOa+PkIkbeqXsnoTQWzoH/Tk3xZxWbj+Nr4rYQov0\nKxLNvrljBNcnUStpc8h0CcktOev7K0h14+l9Z9fwvi/AqnkcbyKojfxVsau9\nzgQND2IyK+uBqcAsDvA9xOznRYkspDw8ElQw3U9KZ0SnqOhWQPzNriGctGXM\n5dGPfTKrjgDQEChHEPjYJUQisUFtJviQ/N1XvRAWXjDKbvpx6tAjAvLMOEeV\niA1XDYmVkCMp8rLVocL8ffUj8qD29xJJkjlo1B0NOERvrH8mAOkGjqHeya+1\nkrJ1bC0NcuXxtUogP3qIBUS3CcVysJtxY3Vom3k+ap+Z2wEW2IrvsNlM0G4i\nEIEy8xRSl4wzXEpIWu1jzxCxrB/NG8sLxOwlR8+VMp/Mn92vQ4WkazMyn9sl\nsnD1\r\n=uznB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDZJk76hTLGnndU9lSq957u+UVkQFjbDaiVsGLOjOAYsQIgBhEXkF8XROUlW0aaw4v699/6UmwYL0PndSwMQQ2eksw="}]},"maintainers":[{"name":"abradley2","email":"antbradley91@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/url-change-event_1.0.0_1544982626859_0.1825064391711526"},"_hasShrinkwrap":false},"1.0.1":{"name":"@abradley2/url-change-event","version":"1.0.1","description":"Intercepts link clicks and url changes then fires an event","main":"index.js","scripts":{"build":"browserify ./index.js -s urlChangeEvent -o ./dist/urlChangeEvent.js","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/abradley2/url-change-event.git"},"author":{"name":"Tony Bradley"},"license":"MIT","bugs":{"url":"https://github.com/abradley2/url-change-event/issues"},"homepage":"https://github.com/abradley2/url-change-event#readme","devDependencies":{"browserify":"^16.2.3","eslint":"^5.10.0","eslint-config-standard":"^12.0.0","eslint-plugin-import":"^2.14.0","eslint-plugin-node":"^8.0.0","eslint-plugin-promise":"^4.0.1","eslint-plugin-standard":"^4.0.0"},"gitHead":"3109ea5b9172230621224128c87e4e95db120e8d","_id":"@abradley2/url-change-event@1.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.11.0","_npmUser":{"name":"abradley2","email":"antbradley91@gmail.com"},"dist":{"integrity":"sha512-/IbHg5QUWmqKavo4PXfqMxOeKXqEIMbsCo/RXVkYZqj2tvih8iFeg/IReU96UulwtWEohNFopb8THK1J3V0ktw==","shasum":"979ad65fc0b8acd1884cf7203b5880aacaf2382c","tarball":"https://registry.npmjs.org/@abradley2/url-change-event/-/url-change-event-1.0.1.tgz","fileCount":7,"unpackedSize":8056,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcFsF1CRA9TVsSAnZWagAATEEP/1DP7++/DzB0jIy63rq2\n5zgrxHGHOeMKGRLg8kapYQwLzi9zJOG7rUJePNcEZMfeecIHZhCsVIwQ+tEe\no/X/B5aIuH3zIUJMrAho+M0v4bL7T6Rr0YSofMSGg9iKwW39txqs0bktuDHd\nxWfnEjNdhmn47a3CxiNif7GWInldMzqxndNQLjeV0ahT6AXfSaQ5VT7Nbz/M\nhuggncVqtjXrLabU/BsbO2u3w16BH2lZiv++EtCu3QEdkD7Wcl8G4de444E+\np9oZFy/wtx24q7ItQkM3UeImV0Oour3RkvTe0gepJOUMElQ2IuOr65qsK5s+\nXFAsC0Q29TPm3JlgwwwsjNsJdF/8qLJOeeUCvxcOpjXE80C8E68byywOZ7Zs\nyTjOGVnTBqRAwwE/sR3+F8bTwGmtFJLSTCfBlkYhYN1t6SHGUfO0zaYTPATS\n/HzVt8AZGdMU/Zg5gQ4x4BAmgnURqyGaHO3jrNcy/n+CTTBs8ai6l1Ns4aJm\nJR+GWO8TyPxkjUy1zPKDU0c5pAdOWpXCr0mwmAVfi9X4o1LZiS7hRcKQbw20\nh7U3PZ1nTZjJfAEYX3pXRA2ZWdHB0GVLYHmEDbv6WKKNnaX3H6ccGO+nnVFu\nuhLge4eE3XOrQ9EvQAXEo/pKAWccFOdC3WZofglA9R6IlYPC3wJfjS118kGH\nGMbO\r\n=Z37o\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGfIMPr3jS1GGv6KbVcY7QsPqT5FQ0th7NHEOtSq2ebVAiBz9T5/ihZ0NtvuK45JOZHiHgKWzNr0swfykffl7CwzDg=="}]},"maintainers":[{"name":"abradley2","email":"antbradley91@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/url-change-event_1.0.1_1544995188461_0.017594569671667504"},"_hasShrinkwrap":false}},"time":{"created":"2018-12-16T17:50:26.692Z","1.0.0":"2018-12-16T17:50:27.018Z","modified":"2022-04-04T11:01:38.408Z","1.0.1":"2018-12-16T21:19:48.644Z"},"maintainers":[{"name":"abradley2","email":"antbradley91@gmail.com"}],"description":"Intercepts link clicks and url changes then fires an event","homepage":"https://github.com/abradley2/url-change-event#readme","repository":{"type":"git","url":"git+https://github.com/abradley2/url-change-event.git"},"author":{"name":"Tony Bradley"},"bugs":{"url":"https://github.com/abradley2/url-change-event/issues"},"license":"MIT","readme":"# Url Change Event\n\n```\nconst initialize = require('@abradley2/url-change-event')\n```\n\nConvenience module for intercepting all link clicks on the body of the document that\nhave either `data-link=\"replaceState\"` or `data-link=\"pushState\"` attributes, calling\nthe corresponding `history` method, and then firing a `urlchange` event on the window\nwhen the location of the document has changed in this way.\n\nThis makes it very simple to support routing in single page applications.\n\n### Usage\n\n```\nconst initialize = require('@abradley2/url-change-event')\n\n// initialize the listeners and interceptors. Returns a function\n// that will unsubscribe these listeners.\nconst stopListening = initialize()\n\n// you can now listen to the \"urlchange\" event on the window\nwindow.addEventListener('urlchange', (event) => {\n  // you can handle this however. The location on the document is passed for convenience\n\n  return document.location === event.detail // true\n})\n```\n\nA link that triggers replaceState should look similar to this:\n```\n<a href=\"/path/in/application#someAnchor\" data-link=\"replaceState\"> Go somewhere! </a>\n```\n\nA link that triggers pushState should look similar to this:\n```\n<a href=\"/push/some/state?query=true\" data-link=\"pushState\"> Go somewhere! </a>\n```\n\nThe `data-link` attribute is important. If the value is either `pushState` or `replaceState`,\nthen `preventDefault` will be called and the event triggered. If not, then nothing happens.\n\n### Popstate events\n\nIn addition to navigation via page links, the `urlchange` event is also fired for the `popstate`\nevent, so there's no need to manually subscribe to that as well.\n\n### State\n\nThe initialization function for this helper method takes on optional argument:\na function which recieves the element of the link clicked as it's first argument,\nand then returns whatever data is desired to be passed as the `state` argument in the\nsubsequent history change.\n\n```\nconst initialize = require('@abradley2/url-change-event')\n\ninitialize(function getStateFromElement(el) {\n  // this can be anything really. It is passed as the `stateObj` to the history method\n  // (the first argument to either history.replaceState or history.pushState)\n  return {\n    data: el.getAttribute('data-link-state')\n  }\n})\n```\n\n### Title\n\nTo have the title of the document change in response to a link being clicked, via the\nsecond argument to the invoked history method, just set the `data-title` attribute to the\ndesired document title on any associated `data-link` element.\n\n### License\n\nMIT\n","readmeFilename":"README.md"}