jQuery.hasEventListener icon indicating copy to clipboard operation
jQuery.hasEventListener copied to clipboard

hasEventListner will not work in JQuery 1.8+ (possible fix for that)

Open zackpudil opened this issue 13 years ago • 4 comments

Me again...

The reason for the break is that in JQuery 1.8+ they moved the $.data("events") to $._data('events") as to not mess with someones data-events tag.

I made a quick fix to this by adding a null colace in the get_events_data method on the return line to use
javascript $["_"+DATA](element, EVENTS) if javascript $[DATA](element, EVENTS) doesn't return anything.

compatibility.get_events_data = ($.now && !$.sub) ? function (element) { // 1.4.3 and 1.4.4

        // Workaround for '$({}).bind("event", handler).data("events"); // undefined' bug (on "window" too) !
        var element_type = get_valid_types_first_letter(element),
            data = $[DATA](element, ((element_type = (element_type === "W") || (element_type === "O"))) ? "__" + EVENTS + "__" : EVENTS);

        return ((data && element_type) ? (data || {})[EVENTS] : data);

    } : function (element) {

        return $[DATA](element, EVENTS) || $["_"+DATA](element, EVENTS);

    };

With this change the path we're using $("~selector").hasEventListner('event.namespace') works great.

Thanks,

Zack

zackpudil avatar Sep 12 '12 21:09 zackpudil

I think that jQuery 1.8 has been out for long enough now that it would make sense to make this change in the plugin and simply say it requires jQuery 1.8 (the older version could still be provided).

Zack, do you think maybe you could fork the repo, make these changes, and then do a pull request?

Sebastien, it would be good to hear from you so we know that the pull request might be accepted if Zack or I goes to the trouble.

Thanks for the helpful plugin.

mbrowne avatar Jan 03 '13 22:01 mbrowne

I'm so sorry, notifications stopped working as expected at some point or something and this is actually the first time I read your comments, 9 months later...

I started to work on a fix a few months ago but sadly hadn't enough time to finish it. So here is what I'm going to do :

  • Write some real unit tests
  • Take a look at this PR
  • Release this new version, finally!

sebastien-p avatar Oct 14 '13 08:10 sebastien-p

yet a year later... ;p

bbrala avatar Sep 23 '14 08:09 bbrala

I know :( Now I have a full time job and I write a book so I don't have much time left for maintaining jQuery plugins (which I do not use anymore - I mean jQuery).

The version-3 branch has tests for $.getEventsData, $.hasEventListener and $('*:hasEventListener()'). $.fn.hasEventListener should work too. The only feature really missing is live/delegated events support.

Also, feel free to contribute if you can.

sebastien-p avatar Sep 23 '14 11:09 sebastien-p