Skip to content

Instantly share code, notes, and snippets.

@jakubpolak
Last active April 3, 2016 09:10
Show Gist options
  • Select an option

  • Save jakubpolak/3930135 to your computer and use it in GitHub Desktop.

Select an option

Save jakubpolak/3930135 to your computer and use it in GitHub Desktop.
jQuery has event.
(function($) {
$.fn.hasEvent = function(A, F, E) {
var L = 0;
var T = typeof A;
var V = false;
E = E ? E : this;
A = (T == 'string') ? $.trim(A) : A;
if(T == 'function') F = A, A = null;
if(F == E) delete(F);
var S = E.data('events');
for (e in S) if (S.hasOwnProperty(e)) L++;
if(L < 1) return V = false;
if(A && !F) {
return V = S.hasOwnProperty(A);
} else
if(A && S.hasOwnProperty(A) && F) {
$.each(S[A], function(i, r) {
if(V == false && r.handler == F) V = true;
});
return V;
} else
if(!A && F) {
$.each(S, function(i, s) {
if(V == false) {$.each(s, function(k, r) {
if(V == false && r.handler == F) V = true;
});}
});
}
return V;
}
$.extend($, {hasEvent: $.fn.hasEvent});
}) (jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment