Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gester detection handler clarification? #545

Closed
Novicaine opened this issue Apr 30, 2014 · 3 comments
Closed

Gester detection handler clarification? #545

Novicaine opened this issue Apr 30, 2014 · 3 comments

Comments

@Novicaine
Copy link

This isn't an issue, more of a question on how to implement a new gesture handler. If this isn't appropriate, please delete, and I apologize.

In detection.js, there is this code:

        // call Hammer.gesture handlers
        Utils.each(this.gestures, function triggerGesture(gesture) {
            // only when the instance options have enabled this gesture
            if(!this.stopped && inst.enabled && instOptions[gesture.name]) {
                // if a handler returns false, we stop with the detection
                if(gesture.handler.call(gesture, eventData, inst) === false) {
                    this.stopDetect();
                    return false;
                }
            }
        }, this);

Where the comments say:

  // if a handler returns false, we stop with the detection

But I don't see how any of the provided handlers return anything, either true or false. Or does the call only return false if there is no handler?

For example, here is the handler for swipe.js ... it doesn't explicitly return anything, it just returns. I'm not very comfortable with the function prototype call and closure, so maybe it is obvious to others.

Hammer.gestures.Swipe = {
    name: 'swipe',
    index: 40,
    defaults: {
/* < SNIPPED  > */
    },

    handler: function swipeGesture(ev, inst) {
        if(ev.eventType == EVENT_RELEASE) {
            var touches = ev.touches.length,
                options = inst.options;

            // max touches
            if(touches < options.swipeMinTouches ||
                touches > options.swipeMaxTouches) {
                return;
            }

            // when the distance we moved is too small we skip this gesture
            // or we can be already in dragging
            if(ev.velocityX > options.swipeVelocityX ||
                ev.velocityY > options.swipeVelocityY) {
                // trigger swipe events
                inst.trigger(this.name, ev);
                inst.trigger(this.name + ev.direction, ev);
            }
        }
    }
};

Thanks!!

@jtangelder
Copy link
Member

I guess this is kind of deprecated code, that could be removed. It does exactly the same as calling stopDetect(). Currently it isn't used anywhere in the default gestures like you said.

@Novicaine
Copy link
Author

Ok, that’s what I thought, but since I’m not 100% sure with java and closure, I wanted to make sure I wasn’t misreading the code.
Thanks for following up!

-John Slagel

From: Jorik Tangelder [mailto:notifications@github.com]
Sent: Thursday, May 01, 2014 1:32 PM
To: EightMedia/hammer.js
Cc: John Slagel
Subject: Re: [hammer.js] Gester detection handler clarification? (#545)

I guess this is kind of deprecated code, that could be removed. It does exactly the same as calling stopDetect(). Currently it isn't used anywhere in the default gestures like you said.


Reply to this email directly or view it on GitHubhttps://github.com//issues/545#issuecomment-41940503.

@jtangelder
Copy link
Member

No problem! Good luck, i'm curious, what kind of gesture are you creating?

7f027da

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants