Login   Register  
PHP Classes
elePHPant
Icontem

File: media/jquery/jquery.autocomplete.min.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Peter He  >  File Picker  >  media/jquery/jquery.autocomplete.min.js  >  Download  
File: media/jquery/jquery.autocomplete.min.js
Role: Auxiliary script
Content type: text/plain
Description: Plugin of jQuery
Class: File Picker
Let the user browse and pick server side files
Author: By
Last change: Update and rename
Date: 2008-10-02 19:15
Size: 6,382 bytes
 

Contents

Class file image Download
jQuery.autocomplete=function(D,S){var N=this;var W=$(D).attr("autocomplete","off");if(S.inputClass){W.addClass(S.inputClass)}var O=document.createElement("div");var H=$(O);H.hide().addClass(S.resultsClass).css("position","absolute");if(S.width>0){H.css("width",S.width)}$("body").append(O);D.autocompleter=N;var f=null;var V="";var g=-1;var I={};var Y=false;var J=false;var A=null;function K(){I={};I.data={};I.length=0}K();if(S.data!=null){var Q="",n={},L=[];if(typeof S.url!="string"){S.cacheLength=1}for(var l=0;l<S.data.length;l++){L=((typeof S.data[l]=="string")?[S.data[l]]:S.data[l]);if(L[0].length>0){Q=L[0].substring(0,1).toLowerCase();if(!n[Q]){n[Q]=[]}n[Q].push(L)}}for(var j in n){S.cacheLength++;E(j,n[j])}}W.keydown(function(i){A=i.keyCode;switch(i.keyCode){case 38:i.preventDefault();b(-1);break;case 40:i.preventDefault();b(1);break;case 9:case 13:if(d()){W.get(0).blur();i.preventDefault()}break;default:g=-1;if(f){clearTimeout(f)}f=setTimeout(function(){R()},S.delay);break}}).focus(function(){J=true}).blur(function(){J=false;C()});T();function R(){if(A==46||(A>8&&A<32)){return H.hide()}var i=W.val();if(i==V){return }V=i;if(i.length>=S.minChars){W.addClass(S.loadingClass);a(i)}else{W.removeClass(S.loadingClass);H.hide()}}function b(k){var i=$("li",O);if(!i){return }g+=k;if(g<0){g=0}else{if(g>=i.size()){g=i.size()-1}}i.removeClass("ac_over");$(i[g]).addClass("ac_over")}function d(){var i=$("li.ac_over",O)[0];if(!i){var k=$("li",O);if(S.selectOnly){if(k.length==1){i=k[0]}}else{if(S.selectFirst){i=k[0]}}}if(i){P(i);return true}else{return false}}function P(i){if(!i){i=document.createElement("li");i.extra=[];i.selectValue=""}var k=$.trim(i.selectValue?i.selectValue:i.innerHTML);D.lastSelected=k;V=k;H.html("");W.val(k);T();if(S.onItemSelect){setTimeout(function(){S.onItemSelect(i)},1)}}function B(p,k){var o=W.get(0);if(o.createTextRange){var i=o.createTextRange();i.collapse(true);i.moveStart("character",p);i.moveEnd("character",k);i.select()}else{if(o.setSelectionRange){o.setSelectionRange(p,k)}else{if(o.selectionStart){o.selectionStart=p;o.selectionEnd=k}}}o.focus()}function U(i){if(A!=8){W.val(W.val()+i.substring(V.length));B(V.length,i.length)}}function c(){var k=X(D);var i=(S.width>0)?S.width:W.width();H.css({width:parseInt(i)+"px",top:(k.y+D.offsetHeight)+"px",left:k.x+"px"}).show()}function C(){if(f){clearTimeout(f)}f=setTimeout(T,200)}function T(){if(f){clearTimeout(f)}W.removeClass(S.loadingClass);if(H.is(":visible")){H.hide()}if(S.mustMatch){var i=W.val();if(i!=D.lastSelected){P(null)}}}function G(k,i){if(i){W.removeClass(S.loadingClass);O.innerHTML="";if(!J||i.length==0){return T()}if($.browser.msie){H.append(document.createElement("iframe"))}O.appendChild(h(i));if(S.autoFill&&(W.val().toLowerCase()==k.toLowerCase())){U(i[0][0])}c()}else{T()}}function F(q){if(!q){return null}var k=[];var p=q.split(S.lineSeparator);for(var o=0;o<p.length;o++){var r=$.trim(p[o]);if(r){k[k.length]=r.split(S.cellSeparator)}}return k}function h(t){var s=document.createElement("ul");var q=t.length;if((S.maxItemsToShow>0)&&(S.maxItemsToShow<q)){q=S.maxItemsToShow}for(var r=0;r<q;r++){var u=t[r];if(!u){continue}var o=document.createElement("li");if(S.formatItem){o.innerHTML=S.formatItem(u,r,q);o.selectValue=u[0]}else{o.innerHTML=u[0];o.selectValue=u[0]}var k=null;if(u.length>1){k=[];for(var p=1;p<u.length;p++){k[k.length]=u[p]}}o.extra=k;s.appendChild(o);$(o).hover(function(){$("li",s).removeClass("ac_over");$(this).addClass("ac_over");g=$("li",s).indexOf($(this).get(0))},function(){$(this).removeClass("ac_over")}).click(function(i){i.preventDefault();i.stopPropagation();P(this)})}return s}function a(k){if(!S.matchCase){k=k.toLowerCase()}var i=S.cacheLength?m(k):null;if(i){G(k,i)}else{if((typeof S.url=="string")&&(S.url.length>0)){$.get(M(k),function(o){o=F(o);E(k,o);G(k,o)})}else{W.removeClass(S.loadingClass)}}}function M(p){var k=S.url+"?q="+encodeURI(p);for(var o in S.extraParams){k+="&"+o+"="+encodeURI(S.extraParams[o])}return k}function m(u){if(!u){return null}if(I.data[u]){return I.data[u]}if(S.matchSubset){for(var s=u.length-1;s>=S.minChars;s--){var o=u.substr(0,s);var v=I.data[o];if(v){var t=[];for(var p=0;p<v.length;p++){var k=v[p];var r=k[0];if(Z(r,u)){t[t.length]=k}}return t}}}return null}function Z(p,o){if(!S.matchCase){p=p.toLowerCase()}var k=p.indexOf(o);if(k==-1){return false}return k==0||S.matchContains}this.flushCache=function(){K()};this.setExtraParams=function(i){S.extraParams=i};this.findValue=function(){var k=W.val();if(!S.matchCase){k=k.toLowerCase()}var i=S.cacheLength?m(k):null;if(i){e(k,i)}else{if((typeof S.url=="string")&&(S.url.length>0)){$.get(M(k),function(o){o=F(o);E(k,o);e(k,o)})}else{e(k,null)}}};function e(u,t){if(t){W.removeClass(S.loadingClass)}var r=(t)?t.length:0;var o=null;for(var s=0;s<r;s++){var v=t[s];if(v[0].toLowerCase()==u.toLowerCase()){o=document.createElement("li");if(S.formatItem){o.innerHTML=S.formatItem(v,s,r);o.selectValue=v[0]}else{o.innerHTML=v[0];o.selectValue=v[0]}var k=null;if(v.length>1){k=[];for(var p=1;p<v.length;p++){k[k.length]=v[p]}}o.extra=k}}if(S.onFindValue){setTimeout(function(){S.onFindValue(o)},1)}}function E(k,i){if(!i||!k||!S.cacheLength){return }if(!I.length||I.length>S.cacheLength){K();I.length++}else{if(!I[k]){I.length++}}I.data[k]=i}function X(k){var o=k.offsetLeft||0;var i=k.offsetTop||0;while(k=k.offsetParent){o+=k.offsetLeft;i+=k.offsetTop}return{x:o,y:i}}};jQuery.fn.autocomplete=function(B,A,C){A=A||{};A.url=B;A.data=((typeof C=="object")&&(C.constructor==Array))?C:null;A.inputClass=A.inputClass||"ac_input";A.resultsClass=A.resultsClass||"ac_results";A.lineSeparator=A.lineSeparator||"\n";A.cellSeparator=A.cellSeparator||"|";A.minChars=A.minChars||1;A.delay=A.delay||400;A.matchCase=A.matchCase||0;A.matchSubset=A.matchSubset||1;A.matchContains=A.matchContains||0;A.cacheLength=A.cacheLength||1;A.mustMatch=A.mustMatch||0;A.extraParams=A.extraParams||{};A.loadingClass=A.loadingClass||"ac_loading";A.selectFirst=A.selectFirst||false;A.selectOnly=A.selectOnly||false;A.maxItemsToShow=A.maxItemsToShow||-1;A.autoFill=A.autoFill||false;A.width=parseInt(A.width,10)||0;this.each(function(){var D=this;new jQuery.autocomplete(D,A)});return this};jQuery.fn.autocompleteArray=function(B,A){return this.autocomplete(null,A,B)};jQuery.fn.indexOf=function(B){for(var A=0;A<this.length;A++){if(this[A]==B){return A}}return -1};