nur-sery/nur_public/nur-base/navigate/main.min.js

1 line
3.1 KiB
JavaScript

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