Search code examples
jqueryeventsgesturehammer.js

Hammer.js event undefined


After updating Hammer to v2 it (maybe not so surprisingly) stopped working. Just can't figure out how I can fix it.

The problem arises at my website which you can visit here: www.tooi.org. If you scroll down to WORK, click one of the projects and then try to click (tap) or swipe. I get the following error in Chrome developer tools:

Uncaught TypeError: undefined is not a function

This is the code that triggers handleHammer after a gesture:

new Hammer(element[0], {
    dragLockToAxis: true,
    dragMinDistance: 0
}).on('tap drag swipe release', handleHammer(event));

after this, handleHammer will check every case (gesture):

function handleHammer(event) {
    // disable browser scrolling
    event.preventDefault();

    switch(event.type) {
        case 'tap':
            (etc.)

and points to hammer.js:2358 where it says the following:

2356    var i = 0;
2357    while (i < handlers.length) {
2358        handlers[i](data);
2359        i++;
2360    }

I hope somebody can help me :) Thanks


Solution

  • Pass argument as function.

    new Hammer(element[0], {
        dragLockToAxis: true,
        dragMinDistance: 0
    }).on('tap drag swipe release', function(){handleHammer(event)});