Created
July 29, 2009 12:11
-
-
Save padolsey/158090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var special = jQuery.event.special, | |
uid1 = 'D' + (+new Date()), | |
uid2 = 'D' + (+new Date() + 1); | |
jQuery.event.special.focus = { | |
setup: function() { | |
var _self = this, | |
handler = function(e) { | |
e = jQuery.event.fix(e); | |
e.type = 'focus'; | |
if (_self === document) { | |
jQuery.event.handle.call(_self, e); | |
} | |
}; | |
jQuery(this).data(uid1, handler); | |
if (_self === document) { | |
/* Must be live() */ | |
if (_self.addEventListener) { | |
_self.addEventListener('focus', handler, true); | |
} else { | |
_self.attachEvent('onfocusin', handler); | |
} | |
} else { | |
return false; | |
} | |
}, | |
teardown: function() { | |
var handler = jQuery(this).data(uid1); | |
if (this === document) { | |
if (this.removeEventListener) { | |
this.removeEventListener('focus', handler, true); | |
} else { | |
this.detachEvent('onfocusin', handler); | |
} | |
} | |
} | |
}; | |
jQuery.event.special.blur = { | |
setup: function() { | |
var _self = this, | |
handler = function(e) { | |
e = jQuery.event.fix(e); | |
e.type = 'blur'; | |
if (_self === document) { | |
jQuery.event.handle.call(_self, e); | |
} | |
}; | |
jQuery(this).data(uid2, handler); | |
if (_self === document) { | |
/* Must be live() */ | |
if (_self.addEventListener) { | |
_self.addEventListener('blur', handler, true); | |
} else { | |
_self.attachEvent('onfocusout', handler); | |
} | |
} else { | |
return false; | |
} | |
}, | |
teardown: function() { | |
var handler = jQuery(this).data(uid2); | |
if (this === document) { | |
if (this.removeEventListener) { | |
this.removeEventListener('blur', handler, true); | |
} else { | |
this.detachEvent('onfocusout', handler); | |
} | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment