showoff icon indicating copy to clipboard operation
showoff copied to clipboard

Custom events are fired twice

Open donv opened this issue 10 years ago • 2 comments

Hi!

Given the slides below, the string "event" is logged twice. The event should only be fired once, right?

This happens for at least "show" and "next". Tested on OS X Safari.

!SLIDE

First slide

!SLIDE a_very_unique_class
# Second
    @@@ java
    public class MyClass {
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
    }

<script>
  $(".a_very_unique_class").bind("showoff:show", function (event) {
    console.log("event");
  });
</script>


!SLIDE
# Third

donv avatar Mar 16 '15 09:03 donv

I'm not entirely certain what is happening here, but the root of the problem is that the $(".a_very_unique_class") selector is returning an array of two identical objects. I'll keep working on it, but for now, a decent mitigation is to stop event propagation in your event handler:

  $(".a_very_unique_class").bind("showoff:show", function (event) {
    console.log("event");
    event.stopPropagation();
  });

binford2k avatar Mar 23 '15 20:03 binford2k

Hi @binford2k !

Thanks for looking at this, and for the workaround.

donv avatar Mar 24 '15 08:03 donv