Skip to content

Instantly share code, notes, and snippets.

@rixth
Created February 7, 2011 19:38
Show Gist options
  • Save rixth/815030 to your computer and use it in GitHub Desktop.
Save rixth/815030 to your computer and use it in GitHub Desktop.
// Cache element clicks
(function () {
var eventTypes = ['click'],
eventStack = [],
handler = function(event) {
document.getElementById('debug').innerHTML += "Caching event\n";
eventStack.push(event);
};
eventTypes.forEach(function (eventType) {
document.body.addEventListener(eventType, handler, true);
});
window.addEventListener('DOMContentLoaded', function() {
eventTypes.forEach(function (eventType) {
document.body.removeEventListener(eventType, handler, true);
});
eventStack.forEach(function (event) {
console.log('Firing', event);
event.target.dispatchEvent(event);
});
}, false);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment