1 | import { requestAnimationTimeout, cancelAnimationTimeout } from '../../utils/requestAnimationTimeout';
|
2 | var mountedInstances = [];
|
3 | var originalBodyPointerEvents = null;
|
4 | var disablePointerEventsTimeoutId = null;
|
5 |
|
6 | function enablePointerEventsIfDisabled() {
|
7 | if (disablePointerEventsTimeoutId) {
|
8 | disablePointerEventsTimeoutId = null;
|
9 |
|
10 | if (document.body && originalBodyPointerEvents != null) {
|
11 | document.body.style.pointerEvents = originalBodyPointerEvents;
|
12 | }
|
13 |
|
14 | originalBodyPointerEvents = null;
|
15 | }
|
16 | }
|
17 |
|
18 | function enablePointerEventsAfterDelayCallback() {
|
19 | enablePointerEventsIfDisabled();
|
20 | mountedInstances.forEach(function (instance) {
|
21 | return instance.__resetIsScrolling();
|
22 | });
|
23 | }
|
24 |
|
25 | function enablePointerEventsAfterDelay() {
|
26 | if (disablePointerEventsTimeoutId) {
|
27 | cancelAnimationTimeout(disablePointerEventsTimeoutId);
|
28 | }
|
29 |
|
30 | var maximumTimeout = 0;
|
31 | mountedInstances.forEach(function (instance) {
|
32 | maximumTimeout = Math.max(maximumTimeout, instance.props.scrollingResetTimeInterval);
|
33 | });
|
34 | disablePointerEventsTimeoutId = requestAnimationTimeout(enablePointerEventsAfterDelayCallback, maximumTimeout);
|
35 | }
|
36 |
|
37 | function onScrollWindow(event) {
|
38 | if (event.currentTarget === window && originalBodyPointerEvents == null && document.body) {
|
39 | originalBodyPointerEvents = document.body.style.pointerEvents;
|
40 | document.body.style.pointerEvents = 'none';
|
41 | }
|
42 |
|
43 | enablePointerEventsAfterDelay();
|
44 | mountedInstances.forEach(function (instance) {
|
45 | if (instance.props.scrollElement === event.currentTarget) {
|
46 | instance.__handleWindowScrollEvent();
|
47 | }
|
48 | });
|
49 | }
|
50 |
|
51 | export function registerScrollListener(component, element) {
|
52 | if (!mountedInstances.some(function (instance) {
|
53 | return instance.props.scrollElement === element;
|
54 | })) {
|
55 | element.addEventListener('scroll', onScrollWindow);
|
56 | }
|
57 |
|
58 | mountedInstances.push(component);
|
59 | }
|
60 | export function unregisterScrollListener(component, element) {
|
61 | mountedInstances = mountedInstances.filter(function (instance) {
|
62 | return instance !== component;
|
63 | });
|
64 |
|
65 | if (!mountedInstances.length) {
|
66 | element.removeEventListener('scroll', onScrollWindow);
|
67 |
|
68 | if (disablePointerEventsTimeoutId) {
|
69 | cancelAnimationTimeout(disablePointerEventsTimeoutId);
|
70 | enablePointerEventsIfDisabled();
|
71 | }
|
72 | }
|
73 | }
|
74 | import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js"; |
\ | No newline at end of file |