Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
Created April 18, 2010 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brandonkelly/369916 to your computer and use it in GitHub Desktop.
Save brandonkelly/369916 to your computer and use it in GitHub Desktop.
/**
* tabfocus event plugin for jQuery
*
* Mimics the focus() event, except it's only
* called when focus wasn't assigned via a click
*
* -------------------------------------------
* Usage
* -------------------------------------------
*
* After including the plugin, you'll be able
* to do this:
*
* $('textarea').tabfocus(function(event){
* console.log('I was just tabbed into!');
* });
*/
$.fn.tabfocus = function(fn){
return this.each(function(){
var $this = $(this),
clicked = false;
$this.mousedown(function(){
clicked = true;
});
$this.focus(function(event){
if (! clicked) {
fn.call(this, event);
} else {
clicked = false;
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment