4c4 < * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, JArn Zaefferer --- > * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, J+Ýrn Zaefferer 10c10 < * Revision: $Id: jquery.autocomplete.js 3917 2007-11-24 18:47:22Z joern.zaefferer $ --- > * Revision: $Id: jquery.autocomplete.js 3909 2007-11-23 15:11:17Z joern.zaefferer $ 152c152 < max: options && !options.scroll ? 10 : 150 --- > max: options && !options.scroll ? 10 : 100 202a203 > var lastAjaxCall = {query:""}; // HLS - for options.listIsSorted 262c263,264 < select.hide(); --- > // HLS - added ESC input when suggest box is hidden > select.visible()?select.hide():(this.value = ""); 356,357c358 < if (!options.matchCase) < currentValue = currentValue.toLowerCase(); --- > if (!options.matchCase) currentValue = currentValue.toLowerCase(); 428c429,431 < function request(term, success, failure) { --- > //------------------------------------------- > // HLS - duplicate of autocompleter "class" > function matchSubset(s, sub) { 430,431c433,444 < term = term.toLowerCase(); < var data = cache.load(term); --- > s = s.toLowerCase(); > var i = s.indexOf(sub); > if (i == -1) return false; > return i == 0 || options.matchContains; > }; > //------------------------------------------- > > // HLS - reorganized the code for better exit reading > function request(term, success, failure) { > > if (!options.matchCase) term = term.toLowerCase(); > 432a446 > var data = cache.load(term); 434a449,452 > lastAjaxCall.query = lastWord(term); // HLS > return true; // HLS > } > 436c454,469 < } else if( (typeof options.url == "string") && (options.url.length > 0) ){ --- > if( (typeof options.url == "string") && (options.url.length > 0) ){ > > //------------------------------------- > // HLS - skip ajax if failure is a quaranteed with > // a sorted RPC resultant data set. > //------------------------------------- > if (options.listIsSorted && > lastAjaxCall.query && (lastAjaxCall.query != "")) { > if (matchSubset(lastWord(term),lastAjaxCall.query)) { > //console.log("- LAC: Skip AJAX!"); > stopLoading(); > return true; > } > } > //------------------------------------- > //console.log("- ajax. term=",lastWord(term)); 443,453c476,495 < $.ajax({ < // try to leverage ajaxQueue plugin to abort previous requests < mode: "abort", < // limit abortion to this input < port: "autocomplete" + input.name, < dataType: options.dataType, < url: options.url, < data: $.extend({ < q: lastWord(term), < limit: options.max < }, extraParams), --- > //------------------------------------- > // HLS > //------------------------------------- > var furl = options.url; > var fdata = $.extend({q: lastWord(term), limit: options.max}, > extraParams); > if (options.formatUrl) { > furl = options.formatUrl(furl, fdata); > if (furl != options.url) fdata = {}; > } > if (options.formatUrlData) { > fdata = options.formatUrlData(fdata); > } > > lastAjaxCall.query = lastWord(term); > > var xhrOpts = { > url: furl, > data: fdata, > error: function(){ stopLoading(); }, 455c497,498 < var parsed = options.parse && options.parse(data) || parse(data); --- > var parsed = options.parse && > options.parse(data) || parse(data); 457a501,507 > }, > mode: "abort", // leverage ajaxQueue plugin > port: "autocomplete" + input.name // limit abortion > > }; > if (options.dataType) { > xhrOpts.dataType = options.dataType; 459,461c509,513 < }); < } else { < failure(term); --- > //------------------------------------- > > // call ajax! > $.ajax(xhrOpts); > return true; // HLS 462a515,517 > > failure(term); > return false; // HLS 491a547,548 > overClass: "ac_over", // HLS > listIsSorted: true, // HLS reduces forward lookups 502c559 < formatItem: function(row) { return row[0]; }, --- > formatItem: function(value) { return value[0]; }, // HLS - return value[0] 513a571 > scrollLimit: 0, // HLS overrides scrollHeight 555,556c613 < // if rawValue is a string, make an array otherwise just reference the array < rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue; --- > // if row is a string, make an array otherwise just reference the array 655c712 < ACTIVE: "ac_over" --- > ACTIVE: options.overClass //HLS - was "ac_over" 716c773 < function moveSelect(step) { --- > function moveSelect_OLD(step) { 726c783,784 < list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight()); --- > var ofs = offset + activeItem[0].offsetHeight - list.innerHeight(); > list.scrollTop(ofs); 733c791,876 < function movePosition(step) { --- > //------------------------------------ > // HLS > //------------------------------------ > > function boxScrollTop(v) > // - move to the top of scroll > { > // set it > if (typeof v == "number") { > element[0].scrollTop = v; > return v; > } > // read it > return element[0].scrollTop; > } > > function boxScrollBy(pixels) > // - scroll by +/- pixel amount > { > element[0].scrollTop += pixels; > return element[0].scrollTop; > } > > function boxCurrentItem(i, onoff) > // - unselect current or select new position > { > if (onoff) { > return listItems.slice(i,i+1).addClass(CLASSES.ACTIVE); > } > return listItems.slice(i,i+1).removeClass(CLASSES.ACTIVE); > } > > function boxCalcPixelJump(a1, a2) > { > var top1 = $(listItems[a1]).offset().top; > var top2 = $(listItems[a2]).offset().top; > return top2-top1; > } > > function boxCalcScrollLimit(hLimit) > // - return number of items within hLimit > { > if (hLimit > 0) { > var h = 0; > for (var i=0; i < listItems.length; i++) { > h += listItems[i].clientHeight; > if (h >= hLimit) return i+1; > } > } > return 0; > } > > function moveSelect(step) > // - move scroll cursor +/- steps > { > var lastActive = active; > boxCurrentItem(active, false); > if (step > 0) { > active += step; > if (active >= listItems.size()) { > active = listItems.size() - 1; > } else { > var h = (active+1)*listItems[active].offsetHeight; > if (h >= element[0].offsetHeight) { > var pixels = boxCalcPixelJump(lastActive, active); > boxScrollBy(pixels); > } > } > } else { > active += step; > if (active < 0) { > active = 0; > } else { > var h = active*listItems[active].offsetHeight; > if ( h < element[0].scrollTop) { > var pixels = boxCalcPixelJump(active,lastActive) > boxScrollBy(-1*pixels); > } > } > } > boxCurrentItem(active, true); > }; > > function movePosition(step) > // HLS - decrepated > { 741a885,886 > //------------------------------------ > 767c912,915 < list.bgiframe(); --- > // HLS > //list.bgiframe(); > try { list.bgiframe(); } catch(e) { } > // 815,830c964,983 < list.scrollTop(0); < list.css({ < maxHeight: options.scrollHeight, < overflow: 'auto' < }); < < if($.browser.msie && typeof document.body.style.maxHeight === "undefined") { < var listHeight = 0; < listItems.each(function() { < listHeight += this.offsetHeight; < }); < var scrollbarsVisible = listHeight > options.scrollHeight; < list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight ); < if (!scrollbarsVisible) { < // IE doesn't recalculate width when scrollbar disappears < listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) ); --- > > //------------------------------------------ > // HLS - Calc the height of the box. This is > // assuming fixed row sizes. The logic > // here is to only use the scrollLimit > // if defined, otherwise use the > // scrollHeight (backward compatibility) > //------------------------------------------ > > var bs = {"overflow-y": "auto"}; > var hs = "auto"; > var rh = listItems[0].clientHeight; > if ($.browser.msie) rh = listItems[0].offsetHeight; > > if (options.scrollLimit > 0) { > if (listItems.size() > options.scrollLimit) > hs = options.scrollLimit*rh; > } else { > var n = boxCalcScrollLimit(options.scrollHeight); > if (n>0) hs = n*rh; 831a985,989 > > if ($.browser.msie) { > bs.height = hs; > } else { > bs.maxHeight = hs; 833a992,994 > element.css(bs); > boxScrollTop(0); > //------------------------------------------