Skip to content

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

@zackpudil

Description

@zackpudil

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions