Skip to content

Instantly share code, notes, and snippets.

@nkajic
Last active October 16, 2021 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkajic/727ae5ff874894f96356b44eece9fd6a to your computer and use it in GitHub Desktop.
Save nkajic/727ae5ff874894f96356b44eece9fd6a to your computer and use it in GitHub Desktop.
Remove passive listeners warning p1 and p2 patch
--- lib/web/jquery/patches/jquery.js
+++ lib/web/jquery/patches/jquery.js
@@ -19,6 +19,33 @@ define([], function () {
});
}
+ /**
+ * Does not use passive listeners to improve scrolling performance
+ * https://stackoverflow.com/questions/60357083/does-not-use-passive-listeners-to-improve-scrolling-performance-lighthouse-repo
+ */
+ function removePassiveListeners(jQuery) {
+ jQuery.event.special.touchstart = {
+ setup: function( _, ns, handle ) {
+ this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
+ }
+ };
+ jQuery.event.special.touchmove = {
+ setup: function( _, ns, handle ) {
+ this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") });
+ }
+ };
+ jQuery.event.special.wheel = {
+ setup: function( _, ns, handle ){
+ this.addEventListener("wheel", handle, { passive: true });
+ }
+ };
+ jQuery.event.special.mousewheel = {
+ setup: function( _, ns, handle ){
+ this.addEventListener("mousewheel", handle, { passive: true });
+ }
+ };
+ }
+
return function ($) {
var majorVersion = $.fn.jquery.split('.')[0];
@@ -27,6 +54,7 @@ define([], function () {
}
ajaxResponsePatch($);
+ removePassiveListeners($);
return $;
};
--- lib/web/magnifier/magnify.js
+++ lib/web/magnifier/magnify.js
@@ -505,7 +505,7 @@ define([
if (!$fotoramaStage.hasClass('magnify-wheel-loaded')) {
if (fotoramaStage && fotoramaStage.addEventListener) {
if ('onwheel' in document) {
- fotoramaStage.addEventListener('wheel', onWheel);
+ fotoramaStage.addEventListener('wheel', onWheel, { passive: true });
} else if ('onmousewheel' in document) {
fotoramaStage.addEventListener('mousewheel', onWheel);
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment