skrollr-menu icon indicating copy to clipboard operation
skrollr-menu copied to clipboard

Ignore events handled by other listeners

Open stianlik opened this issue 10 years ago • 8 comments

Avoid scrolling if link is used by a third-party. E.g. if I use Twitter Bootstrap with the carousel-component in to show images, I do not want my page to start scrolling when users click next/prev.

Related to https://github.com/Prinzhorn/skrollr/pull/474

stianlik avatar Apr 04 '14 09:04 stianlik

You should just stopPropagation then. There are valid cases where you prevented the default, but still want skrollr-menu.

Prinzhorn avatar Apr 05 '14 12:04 Prinzhorn

Good point, however, this may be a problem if you are using third-party code (in my case http://getbootstrap.com/javascript/#carousel) that call event.preventDefault() for handled events. I guess one could add an event listener that gets triggered between the carousel and skrollr-menu, but that does not seem ideal.

Would it be acceptable if I made it configurable? I.e.

skrollr.menu.init({
    ignoreDefaultPrevented: true | false
})

or a more general version

skrollr.menu.init({
    handleClick: function(event) {
        if (/* I want this event to be handled by skrollr-menu */) {
            return true;
        }
        return false;
    }
})

stianlik avatar Apr 05 '14 13:04 stianlik

We should probably handle this in some way or another, but can't you just use a button element? I don't know why the bootstrap docs use links there. It's not best practice, because it's not what links are made for. You can just use data-target instead of href on any non-a element for all Bootstrap JavaScript plugins.

Prinzhorn avatar Apr 05 '14 14:04 Prinzhorn

I hadn't thought of that, using a button will solve the issue for my current project, thanks for the tip. I guess most cases can solved be this way. Although, I still think it will be useful to support defaultPrevented in some way, it is not critical.

stianlik avatar Apr 05 '14 14:04 stianlik

I would love this so much right about now :D

meza avatar Jul 02 '14 11:07 meza

I would love this so much right about now :D

What is your use case? There is probably a workaround.

Prinzhorn avatar Jul 02 '14 12:07 Prinzhorn

<a href="mailto:.." and <a href="tel:..."

Also, it seems to disregard target="_blank" with the mailto link, which is pretty annoying :(

meza avatar Jul 02 '14 12:07 meza

<a href="mailto:.." and <a href="tel:..."

they should both be ignored by skrollr-menu completely (https://github.com/Prinzhorn/skrollr-menu/blob/master/src/skrollr.menu.js#L71). If not, please create a demo on jsbin.com

Prinzhorn avatar Jul 02 '14 12:07 Prinzhorn