Skip to content

Instantly share code, notes, and snippets.

@jneurock
Last active August 29, 2015 14:05
Show Gist options
  • Save jneurock/211708cb96cbea1d7cd3 to your computer and use it in GitHub Desktop.
Save jneurock/211708cb96cbea1d7cd3 to your computer and use it in GitHub Desktop.
Add a URL property to the original event object jQuery wraps
(function($) {
// Capture the original $.Event constructor
$._Event = $.Event;
// Override the $.Event constructor (preserve the 2 arguments)
$.Event = function(src, props) {
// If the src argument is truthy, add a URL property to it
if (src) {
src.URL = window.location.href;
}
// Call the original $.Event constructor
$._Event.call(this, src, props);
};
// Make sure the new $.Event prototype matches the old one
$.Event.prototype = $._Event.prototype;
})(jQuery);
// Later on...
$('selector').on('event', function(evt) {
if (evt.originalEvent) {
// Do something with evt.originalEvent.URL
console.log(evt.originalEvent.URL);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment