Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Check what other JS libraries get when DOM click events are fired
- */
- document.addEventListener('click', function(event){
- console.group('Click Listener');
- console.log('event',event);
- console.log('target',event.target);
- console.groupEnd();
- });
- /*
- Captures DOM click events and dispatches a new event with original event.target
- */
- document.addEventListener('click', function(event){
- console.group('DOM Click Dispatcher');
- /*
- Only handling events we dispatch manually
- This is to prevent a infite loop
- */
- console.log('event.dispatchedManually',event.dispatchedManually);
- if (typeof event.dispatchedManually !== 'undefined') return;
- /*
- Retrieving the original target element
- https://www.polymer-project.org/1.0/docs/devguide/events#retargeting
- */
- event = Polymer.dom(event);
- var target = event.path[0];
- console.log('Polymer event',event);
- console.log('Original Target',target);
- /*
- Dispatching a 'click' event on the original target
- so other JS libraries that rely on original event.target can work
- https://stackoverflow.com/questions/2705583/how-to-simulate-a-click-with-javascript#answer-2706236
- */
- var simulate = document.createEvent('Events');
- simulate.initEvent('click', true, false);
- simulate.dispatchedManually = true;
- console.log('Dispatching',simulate,'for',target);
- target.dispatchEvent(simulate);
- console.groupEnd();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement