forked from say2joe/jquery.disable-autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.disable.autocomplete.min.js
1 lines (1 loc) · 1.06 KB
/
jquery.disable.autocomplete.min.js
1
(function(e){function t(){function u(e){var t=e.which;var u=r.val();var a=n.val();var f=this.selectionStart;var l=String.fromCharCode(t);var c=this.selectionEnd-f;var h=s.test(e.keyCode);var p=o.test(t);var d=i.test(l);var v=u.split("");var m=a.split("");if(e.type==="keydown"){if(p){if(c){m.splice(f,c)}else if(t===46){m.splice(f,1)}else{m.splice(--f,1)}n.val(m.join(""))}return true}else if(e.type==="keypress"){if(d){m.splice(f,c,l);v.splice(f,c,"*");f++}else{return p||h}}else{return false}u=v.join("");a=m.join("");n.val(a);r.val(u);this.setSelectionRange(f,f);return false}var t=e(this).attr("autocomplete","off");if(typeof this.selectionStart==="undefined"){return true}var n=t.clone().attr("type","hidden");var r=t.clone();var i=/^[\ \w\`\~\!\@\#\$\%\^\&\*\(\)\-\=\+\/\?\.\>\,\<\'\"\;\:\\\|\]\}\[\{]$/;var s=/^(37|39)$/;var o=/^(8|46)$/;r.attr({type:"text",name:""}).on("keypress keydown paste",u);t.before(n,r).remove();t=null}e.fn.extend({disableAutocomplete:function(){var e=/text|password/i;return this.each(function(){if(e.test(this.type)){t.call(this)}})}})})(jQuery)