Skip to content

Commit 85be7bc

Browse files
author
Jakub Freisler
committed
Added original addEventListener method under addEventListener._original property.
Added proper info about what's above in README.md.
1 parent e976d22 commit 85be7bc

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ Well, that's true, partly. First of all specification says that you shouldn't ev
7979

8080
Unfortunately, no. Since they are not actual errors there is no way to catch them and (more importantly) there is no way to distinguish whether you're inside of the passive listener context to know when not to call/override preventDefault method. Now, we look at the regarding issue in WHATWG repo whatwg/dom#587.
8181

82+
## Is there a possibility to bring default addEventListener method back for chosen elements/globally (e.g. for time of running some of the code)?
83+
84+
Yes, original addEventListener is available under `_original` property of our's addEventListener's implementation (so - `element.addEventListener._original`). Having that in mind, you can bring it back for however you want, e.g.:
85+
```javascript
86+
element.addEventListener = element.addEventListener._original;
87+
```
88+
8289
# Resources
8390

8491
* About passive event listeners https://medium.com/@devlucky/about-passive-event-listeners-224ff620e68c

__tests__/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ describe('passive events are supported', () => {
7979
capture: false
8080
});
8181
});
82+
83+
it('should original implementation be visible under addEventListener._original property', () => {
84+
expect(spy.addEventListener).toEqual(init.addEventListener);
85+
});
8286
});
8387

8488
describe('passive events are not supported', () => {

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const overwriteAddEvent = (superMethod) => {
3434

3535
superMethod.call(this, type, listener, options);
3636
};
37+
38+
EventTarget.prototype.addEventListener._original = superMethod;
3739
};
3840

3941
const supportsPassive = eventListenerOptionsSupported();

0 commit comments

Comments
 (0)