1 line
2.8 KiB
JavaScript
1 line
2.8 KiB
JavaScript
(function(b){var a=":input:visible";b.resetTabindex=function(c){if(c===undefined){c=a}b(c).each(function(){b(this).attr("tabindex",0)})};b.initTabindex=function(e){if(e===undefined){e=a}var d=0;var c=b(e);c.each(function(){var f=parseInt(b(this).attr("tabindex"));if(f>d){d=f}});d+=1;c.each(function(){var f=parseInt(b(this).attr("tabindex"));if(!f){b(this).attr("tabindex",d++)}})};b.updateTabindex=function(c){if(c===undefined){b.resetTabindex(":input");b.initTabindex(a)}else{b.resetTabindex(c);b.initTabindex(c)}};b.NAVIGATE_INCLUDES=":input";b.NAVIGATE_EXCLUDES="textarea, :submit, :reset, :button";b.navigate=function(r,e,i){if(r===undefined){r=a}if(e===undefined){e=true}if(i===undefined){i=true}var d=function(t){return t!==null&&t!==undefined};var k=function(t){return b(t).val().length==0};var q=function(t){try{return d(t.selectionStart)}catch(u){}};var f=function(t){var u=b(t);return u.is(b.NAVIGATE_INCLUDES)&&!u.is(b.NAVIGATE_EXCLUDES)};var m=function(t){return t.selectionStart==t.selectionEnd};var h=function(t){var u=b(t).val().length;return u>0&&t.selectionStart==0&&t.selectionEnd==u};var p=function(t){return m(t)||h(t)};var l=function(u,t){if(u>0){var v=b("[tabindex='"+u+"']");v.focus();if(t){v.select()}}};var o=function(u,t){var v=b(u).attr("tabindex");if(v){l(parseInt(v)-1,t)}};var s=function(u,t){var v=b(u).attr("tabindex");if(v){l(parseInt(v)+1,t)}};var g=function(t){if(!q(t)){return true}else{if(p(t)){return t.selectionStart==0}else{return false}}};var j=function(t){var u=b(t).val().length;if(!q(t)){return true}else{if(p(t)){return t.selectionEnd==u}else{return false}}};var n=function(u){var t=b(u).data("ac.select");if(t){t.hide()}};if(i){b.initTabindex(r)}var c={autocomplete:false,leftKeyThenPrevinput:false,rightKeyThenNextinput:false,};b(r).keypress(function(t){if(c.autocomplete){c.autocomplete=false}else{if(t.which==8&&q(this)&&k(this)){n(this);o(this);return false}else{if(t.which==13){if(t.ctrlKey){if(b.wosubmit){b.wosubmit(this);return false}}else{if(f(this)){s(this,e);return false}}}}}}).keydown(function(u){var t=u.which;if(t==37&&g(this)&&!h(this)){c.leftKeyThenPrevinput=true;return false}else{if(t==39&&j(this)&&!h(this)){c.rightKeyThenNextinput=true;return false}}}).keyup(function(u){var t=u.which;if(c.leftKeyThenPrevinput){c.leftKeyThenPrevinput=false;n(this);o(this,e)}else{if(c.rightKeyThenNextinput){c.rightKeyThenNextinput=false;n(this);s(this,e)}else{if(t==40||(c.autocomplete&&t==38)){c.autocomplete=true}else{c.autocomplete=false}}}}).attr("autocomplete","off")};b.fn.cursorAtEOFL=function(c){if(c===undefined){c=0}return this.each(function(){var f=b(this);if(this.setSelectionRange){var g=f.val();var h=0;while(c-->=0){var d=g.search("\r?\n");if(d!=-1){var e=d;if(g.charAt(e)=="\r"){e++}e++;if(c==-1){h+=d}else{h+=e}g=g.substr(e)}else{h+=g.length;break}}this.setSelectionRange(h,h)}f.focus()})}})(jQuery); |