sebastien-p / jquery.haseventlistener Goto Github PK
View Code? Open in Web Editor NEWhasEventListener is a jQuery plugin which checks if an Object or a DOM element actually has a particular/live/delegated event listener bound to it.
hasEventListener is a jQuery plugin which checks if an Object or a DOM element actually has a particular/live/delegated event listener bound to it.
Viewing the example fiddle (http://jsfiddle.net/sebastienp/eHGqB/) and changing the jQuery version to 1.7+ will show those returning false.
HasEventListener will always return true do to a IE 7 bug in the get_valid_types_first_letter method. The bug is due to IE 7's short coming of not being able to index strings like arrays. So this line:
var first_try = (/Object|(Ele|Docu)ment|Window/.exec(Object.prototype.toString.call(object)) || [""])[0][0],
needs to be this line:
var first_try = (/Object|(Ele|Docu)ment|Window/.exec(Object.prototype.toString.call(object)) || [""])[0].charAt(0),
If you wanna support IE 7.
Changed:
first_div = divs.eq(0).click(function (e) {
window.alert(e.type);
}),
To:
first_div = divs.eq(0).live('click',function (e) {
window.alert(e.type);
}),
In the JS fiddle, and it turned a 'true' to a 'false'
Me again...
The reason for the break is that in JQuery 1.8+ they moved the
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.