ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
User:Zocky/AutoComplete.js - Wikipedia, the free encyclopedia

User:Zocky/AutoComplete.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

//from http://www.json.org/json.js
 
String.prototype.parseJSON = function () {
    try {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                this.replace(/"(\\.|[^"\\])*"/g, ''))) && //"
            eval('(' + this + ')');
    } catch (e) {
        return false;
    }
};
 
function ac$query(cb) 
{
  if (ac$query.arguments.length>1 && ac$x) 
  {
    var i=1;
    var url="/w/api.php?action=query&format=json";
    while (i < ac$query.arguments.length)
    {
      url=url+"&"+ac$query.arguments[i] + "=" + ac$query.arguments[i+1];
      i+=2;
    }
    ac$x.onreadystatechange=function() {
      if (ac$x.readyState==4)
        return ac$x.status==200 
        ? cb(ac$x.responseText.parseJSON()) 
        : cb(false);
    };
    ac$x.open("GET",url,true);
    ac$x.setRequestHeader('Accept','text/*');
    ac$x.send(null);
  }
  else return false;
}
 
// helper functions
function ac$$e(id)   { return document.getElementById(id); }
function ac$$c(name,id) { var el=document.createElement(name); el.id=id; return el };
function ac$$ia(node,newnode) { return node.parentNode.insertBefore(newnode,node.nextSibling); }
function ac$$uc(s) { return s.substring(0,1).toUpperCase()+s.substring(1) };
 
function ac$inputKeyDown(e)
{
  if (e.which==40 && ac$b.style.visibility=="visible")
  {
    ac$b.focus();
//    ac$b.selectedIndex=0;
//    ac$s.value=ac$b.options[0].value;
  }
  else
  {
    try {clearTimeout(ac$t)} catch (e) {};
    ac$t=setTimeout("ac$timeOut()",500)
  }
}
 
function ac$boxKeyPress(e)
{
  if (e.which==13)
  {
    ac$s.value=ac$b.options[ac$b.selectedIndex].value;
    ac$b.style.visibility="hidden";
    ac$b.selectedIndex=-1;
    ac$s.focus();
  }
  else if (e.which==27)
  {
    ac$b.style.visibility="hidden";
    ac$b.selectedIndex=-1;
    ac$s.focus();
  }
  else if (e.which)
  { 
    ac$s.value+=String.fromCharCode(e.which);
    ac$s.focus();
    ac$b.selectedIndex=-1;
    ac$s.selectionStart=ac$s.selectionEnd=ac$s.value.length;
    try {clearTimeout(ac$t)} catch (e) {};
    ac$t=setTimeout("ac$timeOut()",500)
  }
}
 
function ac$boxClick(e)
{
    ac$s.value=ac$b.options[ac$b.selectedIndex].value;
    ac$b.style.visibility="hidden";
    ac$b.selectedIndex=-1;
    ac$s.focus();
}
 
function ac$blur(e)
{
  if (e.target==ac$b)
  {
    if (ac$b.style.visibility=="hidden") ac$b.blur()  
  }
  else if (e.target!=ac$s && e.target!=document && e.target!=window)
  {
    ac$b.style.visibility="hidden";
    ac$b.selectedIndex=-1;
  }
}
 
 
 
function ac$timeOut()
{
  if (ac$s.value.length>0)
  {
    try {ac$x.abort()} catch(e){};
    cb=function(obj) 
    {
       ac$b.innerHTML='';
       for (var i in obj.query.namespaces)
       {
         try
         {
           var ns=obj.query.namespaces[i]['*'];
           ac$n[ns]=i;
           if (
             ac$s.value.toUpperCase() == ns.substring 
                                       (0,ac$s.value.length).toUpperCase()
           )
           {
             ac$b.innerHTML+='<option style="font-weight:bold">'
             + ns
             + ':</option>';
           }
         } catch(e) {}
       }
 
       for (var i in obj.query.allpages)
       {
         if (
           ac$s.value.toUpperCase() == obj.query.allpages[i].title.substring 
                                       (0,ac$s.value.length).toUpperCase()
         )
           ac$b.innerHTML+= ( 
             obj.query.allpages[i].redirect!="" 
             ? '<option>'
             : '<option style="color:silver">'
           )
           + obj.query.allpages[i].title
           + '</option>';
       }
//       ac$b.size= ac$b.options.length<8 ? ac$b.options.length : 8;
         ac$b.options.length || (ac$b.innerHTML='<option value="'+ac$s.value+'" style="color:silver">(no pages found)</option>');
       ac$b.style.visibility="visible";
    };
 
    var ns=ac$s.value.match(/^.*?(?=:)/);
    if (ns in ac$n)
    {
       var apns = ac$n[ns];
       var apfrom = ac$s.value.replace(/^.*?:/,'');
    }
    else
    {
       var apns=0;
       var apfrom=ac$s.value;
    }
 
    ac$query(cb,"list","allpages","apfrom",ac$$uc(apfrom.replace(/ /g,'_')),"aplimit","50","apnamespace",apns,"meta","siteinfo","siprop","namespaces");
  }
  else
  {
    ac$b.style.visibility="hidden";
  }
}
 
// initialization
 
var ac$s;
var ac$b;
var ac$t;
var ac$n=[];
var ac$x = window.XMLHttpRequest ? new XMLHttpRequest()
         : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")
         : false;
 
function ac$init()
{
  ac$s=ac$$e("searchInput");
  if(ac$s)
  {
    document.write('<link rel="stylesheet" type="text/css" href="'  
                 + 'http://en.wikipedia.org/w/index.php?title=User:Zocky/AutoComplete.css'
                 + '&action=raw&ctype=text/css&dontcountme=s">');
 
    ac$b=ac$$c('select','autocompletebox');
    ac$b.size=8;
    ac$b.style.visibility="hidden";
    ac$$ia(ac$s,ac$b);
 
    ac$s.setAttribute('autocomplete','off');
    ac$s.addEventListener('keydown',ac$inputKeyDown,true);
    ac$b.addEventListener('keypress',ac$boxKeyPress,true);
    ac$b.addEventListener('click',ac$boxClick,true);
    document.addEventListener('focus',ac$blur,true);
  }
}
 
addOnloadHook(ac$init);


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -