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

Snap-Toggle directive only OPENs? #61

Closed
iDVB opened this issue Jun 11, 2014 · 8 comments
Closed

Snap-Toggle directive only OPENs? #61

iDVB opened this issue Jun 11, 2014 · 8 comments

Comments

@iDVB
Copy link

iDVB commented Jun 11, 2014

Anyone know why I would be having CLOSE issues with my snap-toggle directive?
OPEN works just fine... and even touching anywhere on the snap-content panel will close it... just does not allow CLOSE with that very same snap-toggle button.

I thought for sure I had this working previously....

http://www.screencast.com/t/aF7UpcUY

- UPDATE -
I've not changed a thing, just noticed that if I click the toggle button and drag off it to the content area at the same time..... then it seems to work? Is it possible that the close and open events are being fired both at the same time?

http://www.screencast.com/t/FmIjV9Sr4wgs

- UPDATE 2 -
I was able to use snapRemote to console out the events and I think I was right... somehow its firing those events twice really fast, and essentially closing and opening it before it even starts closing.

http://www.screencast.com/t/knX0VZel5eD

@jtrussell
Copy link
Owner

Thanks or the screen casts - a few questions:

  • Are you using the most recent version of angular-snap (1.5.0)?
  • Do you see the same issue on the snap-toggle example plunk?
  • Do you see the same issue when fast click is not included? Or for that matter when all other js files are taken off the page?

@iDVB
Copy link
Author

iDVB commented Jun 12, 2014

Thanks.

  • was running 1.4.0. Still have issue with 1.5.0
  • removing fastclick kind of fixed the issue.
    • Button now closes drawer, however Snap still appears to fire double close events now.
  • snap-toggle example works just like it does now that I removed fastclick. However, I forked that example and added a listener to console on open and close and you can see that its still firing the close event twice in that example. http://www.screencast.com/t/ggeJZuX0B

Seems like it might be a bug? Maybe if we could get it to only fire the close event once, turning on fastclick might still work.

@jtrussell
Copy link
Owner

Thanks for checking up on that. Yeah sounds like it might be a bug. I'd
prefer to play nicely with fastclick if at all possible anyway.

I'll be happy to investigate further but am on vacation for the next few
days. I'll be happy to accept a PR especially if it's accompanied by a new
test :). If you're not in a rush though I should be able to get to it early
next week.

@iDVB
Copy link
Author

iDVB commented Jun 12, 2014

Great! Thanks. I've dive in a take a peak and PR if moons align.
Otherwise, no rush, ping the ticket when you have a chance to look at it.
Btw, thanks for this work, its a great so far.

@jtrussell
Copy link
Owner

Update and notes to self.

If the tapToClose option is true Snap.js will close an open drawer when it is tapped/clicked on mouseup rather than on click. We're currently using the click event (after mouseup) for snap-toggle. We could also use mouseup but we can't just cancel the even there or Snap.js get's stuck in drag mode.

@jtrussell
Copy link
Owner

So here's what I'm leaning towards, you can actually recreate it yourself if you want to give it a try:

app.directive('myToggle', ['$rootScope', 'snapRemote', function($rootScope, snapRemote) {
  'use strict';
  return {
    restrict: 'A',
    link: function (scope, element, attrs) {
      var snapId = attrs.snapId
        , snapSide = attrs.snapToggle || 'left';

      if(!!snapId) {
        snapId = scope.$eval(snapId);
      }

      element.bind('mousedown', function(event) {
        event.stopImmediatePropagation();
      });

      element.bind('mouseup', function(event) {
        event.stopImmediatePropagation();
      });

      element.bind('click', function() {
        snapRemote.toggle(snapSide, snapId);
        $rootScope.$digest();
      });
    }
  };
}]);

Stifling mouseup means tapToClose doesn't fight with the toggle button, we need to also stop mousedown to keep Snap.js from starting a drag when we click (since there's no more mouseup event to stop the drag).

TLDR;

Fixed toggle functionality but you won't be able to start a drag on the toggle button itself. Same would apply for a snap-close element.

jtrussell added a commit that referenced this issue Jun 19, 2014
Disable `tapToClose` feature on `snap-toggle` elements by stifling the mousedown
and mouseup events. You can override this guard with `snap-unsafe="true"`.

See #61
@jtrussell
Copy link
Owner

I'm open to other solutions but for now we'll stifle the mouseup and mousedown events on snap-toggle elements. You can turn these events back on if needed using snap-unsafe="true":

<button snap-toggle snap-unsafe="true">Toggle (w/ mousedown + mouseup)</button>

Should be considered for #34.

@iDVB
Copy link
Author

iDVB commented Jun 19, 2014

Understood. Sounds like a good solution.
I have not yet tried it but your fix may also correct another issue I saw where "opening via toggle" had a visual delay over "closing via toggle".

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