How to add passive event listener in flickity

I am facing one issue due to Google Light house Tool, which suggest me to add Passive Event Listner in my Flickty Java Scrip and that code which indicates me issue in following code.

function(t) {
    function e(e) {
        var i = t.event;
        return i.target = i.target || i.srcElement || e, i
    }
    var i = document.documentElement,
        n = function() {};
    **i.addEventListener ? n = function(t, e, i)** {
        t.addEventListener(e, i, !1)
    } : i.attachEvent && (n = function(t, i, n) {
        t[i + n] = n.handleEvent ? function() {
            var i = e(t);
            n.handleEvent.call(n, i)
        } : function() {
            var i = e(t);
            n.call(t, i)
        }, t.attachEvent("on" + i, t[i + n])
    });
    var o = function() {};
    i.removeEventListener ? o = function(t, e, i) {
        t.removeEventListener(e, i, !1)
    } : i.detachEvent && (o = function(t, e, i) {
        t.detachEvent("on" + e, t[e + i]);
        try {
            delete t[e + i]
        } catch (n) {
            t[e + i] = void 0
        }
    });
    var r = {
        bind: n,
        unbind: o
    };
    "function" == typeof define && define.amd ? define("eventie/eventie", r) : "object" == typeof exports ? module.exports = r : t.eventie = r
}

o how to add Passive Event Listner in above Code.

Flickty Java Script Details are as :

Flickity PACKAGED v1.1.1
Touch, responsive, flickable galleries *
Licensed GPLv3 for open source use
or Flickity Commercial License for commercial use *

Copyright 2015 Metafizzy

Is that the beautified flickty distribution code? If so, you’re not really supposed to edit it; if you want to edit the source code (and your license actually permits this), it would be much more practical to fork the github repository and build it yourself. However, the problem with either approach is that you won’t receive any further updates.

But to answer your actual question, you’ replace this line

t.addEventListener(e, i, !1)

with this line

t.addEventListener(e, i, {
  useCapture: false, // equivalent to !1 above
  passive: true      // the passive option
})

You can read a detailed description of the .addEventListener() method over at the MDN.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.