Created
April 18, 2010 00:17
-
-
Save brandonkelly/369916 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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