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

On click event? #132

Open
phstc opened this issue Dec 23, 2015 · 6 comments
Open

On click event? #132

phstc opened this issue Dec 23, 2015 · 6 comments

Comments

@phstc
Copy link

phstc commented Dec 23, 2015

Hey,

I would like to ask you if there's a way to trigger an event on drop click, before opening a drop.

I tried this:

@drop._on @drop.target, 'click', -> console.log('click')
@drop.on 'open', -> console.log('open')

But I'm getting open before click in the console. I know what I need might seems wrong, but I need something to trigger based on the user interaction (click on the drop to open it), because I also call open programatically, and based on my current implementation it's hard to differentiate when its being opened because of a user interaction or because I @drop.open programatically.

Is there a way to do that with Drop?

Thanks

@phstc
Copy link
Author

phstc commented Dec 30, 2015

The workaround I'm using for now:

# @drop.on 'open', @openHandler
@drop.on 'close', @closeHandler

@drop.target.addEventListener('click', @somethingINeedToDoBeforeOpenHandler)
@drop.target.addEventListener('click', @openHandler)

@geekjuice
Copy link
Contributor

Are you looking for something like a beforeOpen or showOn type of handler? Basically a handler that is called before the drop is opened to check whether it should open or not? If so, we actually have #120 that I still need to review that should provide that functionality.

@phstc
Copy link
Author

phstc commented Dec 30, 2015

hi @geekjuice

Actually I'm looking for something like onClick, because it would guarantee that the drop is going to be opened due on a user interaction. open or beforeOpen does not tell if it's being opened because a user interaction or programatically via @drop.open().

@geekjuice
Copy link
Contributor

Gotcha. I think the way I thought showOn should work is:

new Drop({
  ...options,
  showOn(e) {
    if (e.type === 'click') {
      console.log('Opened via user click');
    } else {
      console.log('Probably opened programatically');
    }

    return true; // To confirm opening the drop
  }
});

This way, you can determine what type of event opened the drop and even determine if the drop should open or not.

@phstc
Copy link
Author

phstc commented Dec 30, 2015

@geekjuice hm makes sense... like changing here to pass the event along.

if (typeof this.options.showOn !== 'undefined' && !this.options.showOn(event)) {
  return;
}

Do you want me to test #120?

@geekjuice
Copy link
Contributor

Yea, if the event was passed, it should work as I described.

And I always welcome everyone to test open PRs so they can be merged sooner 👍 🍻

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