forked from veg/alignment.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add patch for preventDefault to library.
- Loading branch information
1 parent
a4a4121
commit 839b645
Showing
3 changed files
with
57 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Temporary fix for a breaking change in Chrome to React | ||
* See https://github.com/facebook/react/issues/14856 | ||
*/ | ||
|
||
export default function(document) { | ||
const EVENTS_TO_MODIFY = [ | ||
"touchstart", | ||
"touchmove", | ||
"touchend", | ||
"touchcancel", | ||
"wheel" | ||
]; | ||
|
||
const originalAddEventListener = document.addEventListener.bind(); | ||
document.addEventListener = (type, listener, options, wantsUntrusted) => { | ||
let modOptions = options; | ||
if (EVENTS_TO_MODIFY.includes(type)) { | ||
if (typeof options === "boolean") { | ||
modOptions = { | ||
capture: options, | ||
passive: false | ||
}; | ||
} else if (typeof options === "object") { | ||
modOptions = { | ||
...options, | ||
passive: false | ||
}; | ||
} | ||
} | ||
|
||
return originalAddEventListener(type, listener, modOptions, wantsUntrusted); | ||
}; | ||
|
||
const originalRemoveEventListener = document.removeEventListener.bind(); | ||
document.removeEventListener = (type, listener, options) => { | ||
let modOptions = options; | ||
if (EVENTS_TO_MODIFY.includes(type)) { | ||
if (typeof options === "boolean") { | ||
modOptions = { | ||
capture: options, | ||
passive: false | ||
}; | ||
} else if (typeof options === "object") { | ||
modOptions = { | ||
...options, | ||
passive: false | ||
}; | ||
} | ||
} | ||
return originalRemoveEventListener(type, listener, modOptions); | ||
}; | ||
} |