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

Unbinding specific events not working #149

Closed
JohnKis opened this issue Jan 5, 2015 · 7 comments
Closed

Unbinding specific events not working #149

JohnKis opened this issue Jan 5, 2015 · 7 comments

Comments

@JohnKis
Copy link

JohnKis commented Jan 5, 2015

First of all, thanks for all your handwork on interact.js. It's a great library to work with.

Today I've noticed that unbinding events isn't working. When I call .off('drop') on an interactable, the event listener will still be active. I've tried to debug it and found that events.remove() (in line 413) expects an element as opposed to an interactable (which .off() passes through), hence it'll bail out in line 421 as 'target' will be undefined.

@taye taye closed this as completed in daed1ee Jan 6, 2015
@taye
Copy link
Owner

taye commented Jan 6, 2015

Thanks for raising this issue. I've released a new version which fixes it.

@JohnKis
Copy link
Author

JohnKis commented Jan 6, 2015

Thanks for your quick response.

Something's still wrong, though. Removing an action event listener is still not working.
The following code should bind an event listener to 'drop' and then unbind it. However the listener will still be called after unbinding.

interact(el)
    .dropzone(true)
    .on('drop',function(){
        alert('drop');
    });

interact(el)
    .dropzone(false)
    .off('drop',function(){
        alert('drop');
    });

Logging this._iEvents in :4802 shows that the event listener has been successfully removed, but it will still be called.

@taye
Copy link
Owner

taye commented Jan 6, 2015

That's because those functions are two different objects. If you do add and remove the events like this instead, then it should work:

function dropListener (event){
    alert('drop');
}

interact(el)
    .dropzone(true)
    .on('drop', dropListener);

interact(el)
    .dropzone(false)
    .off('drop', dropListener);

@JohnKis
Copy link
Author

JohnKis commented Jan 6, 2015

Sorry, that's how I'm using it. I just got it wrong in the example. Logging out this._iEvents clearly shows that the listener has been removed, however it'll be fired again somehow after removal.

@taye
Copy link
Owner

taye commented Jan 6, 2015

Maybe you added the event by including it in the dropzone options.

interact(el).dropzone({
  ondrop: dropListener
});

In that case, you would have to do:

interact(el).ondrop = null;

@JohnKis
Copy link
Author

JohnKis commented Jan 6, 2015

I haven't used it that way, but I tried your suggestion and it worked fine.

Thanks very much for your help!

@taye
Copy link
Owner

taye commented Jan 6, 2015

You're welcome :)

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