-
Notifications
You must be signed in to change notification settings - Fork 1
/
redips-autocomplete-min.js
13 lines (13 loc) · 2.72 KB
/
redips-autocomplete-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
Copyright (c) 2008-2020, www.redips.net All rights reserved.
Code licensed under the BSD License: http://www.redips.net/license/
http://www.redips.net/javascript/autocomplete/
Version 1.3.0
Mar 25, 2020.
*/
var REDIPS=REDIPS||{};
REDIPS.autocomplete=function(){var a,b,c,d=null,g=!1;var h=function(){b.style.visibility="visible"};var f=function(){g?g=!1:(null!==d&&clearTimeout(d),b.style.visibility="hidden")};var k=function(){g=!0;b.getElementsByTagName("select")[0].focus()};var m=function(a){c.value=a.options[a.selectedIndex].text;b.style.visibility="hidden";c.focus()};var n=function(){null!==d&&clearTimeout(d);d=setTimeout(function(){var l=0,d=0,e=c;if(0===c.value.length)f();else{do d+=e.offsetLeft,l+=e.offsetTop,e=e.offsetParent;
while(e);b.style.top=l+c.offsetHeight+"px";b.style.left=d+"px";b.style.width=c.offsetWidth+"px";a.open("GET",REDIPS.autocomplete.url+c.value+"&fname="+c.name,!0);a.onreadystatechange=function(){if(a.readyState===XMLHttpRequest.DONE)if(200===a.status){var c='<select multiple ondblclick="REDIPS.autocomplete.selected(this)" onkeydown = "REDIPS.autocomplete.keydown(this, event)" onblur = "REDIPS.autocomplete.hide()" onclick = "window.event.cancelBubble = true" style = "width:100%; height:100%">'+a.responseText;
b.innerHTML=c+"</select>";h()}else b.innerHTML="Error: ["+a.status+"] "+a.statusText};a.setRequestHeader("X-Requested-With","XMLHttpRequest");a.send(null)}},REDIPS.autocomplete.delay)};return{delay:500,url:"redips-autocomplete.php?query=",height:120,init:function(){var c=document.getElementsByTagName("body")[0];b=document.createElement("div");b.setAttribute("id","redips-autocomplete");b.onmouseover=REDIPS.autocomplete.focus;b.style.cssText="position:absolute;visibility:hidden;background-color:white;z-index:999;height:"+
REDIPS.autocomplete.height+"px";c.appendChild(b);a=new XMLHttpRequest;REDIPS.event.add(document,"click",REDIPS.autocomplete.hide)},show:h,hide:f,focus:k,keydown:function(a,b){if("INPUT"===a.nodeName)switch(c=a,b.keyCode||window.event.keyCode){case 9:case 13:case 16:case 17:case 18:case 19:case 20:break;case 33:case 34:case 35:case 36:case 37:case 38:case 39:break;case 45:case 145:break;case 112:case 113:case 114:case 115:case 116:case 117:break;case 118:case 119:case 120:case 121:case 122:case 123:break;
case 27:f();break;case 40:k();break;case 8:case 46:n();break;default:n()}else switch(b.keyCode||window.event.keyCode){case 27:case 8:f();c.focus();break;case 9:case 13:m(a)}},selected:m}}();REDIPS.event||(REDIPS.event=function(){return{add:function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent?a.attachEvent("on"+b,c):a["on"+b]=c},remove:function(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent?a.detachEvent("on"+b,c):a["on"+b]=null}}}());