1(function( $ ){
2 $.fn.enterAsTab = function( options ) {
3 var settings = $.extend( {
4 'allowSubmit': false
5 }, options);
6 this.find('input, select').live("keypress", {localSettings: settings}, function(event) {
7 if (settings.allowSubmit) {
8 var type = $(this).attr("type");
9 if (type == "submit") {
10 return true;
11 }
12 }
13 if (event.keyCode == 13 ) {
14 var inputs = $(this).parents("form").eq(0).find(":input:visible:not(disabled):not([readonly])");
15 var idx = inputs.index(this);
16 if (idx == inputs.length - 1) {
17 idx = -1;
18 } else {
19 inputs[idx + 1].focus(); // handles submit buttons
20 }
21 try {
22 inputs[idx + 1].select();
23 }
24 catch(err) {
25 // handle objects not offering select
26 }
27 return false;
28 }
29});
30 return this;
31};
32})( jQuery );