(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.autoComplete = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i' + item.replace(re, "$1") + ''; }, onSelect: function(e, term, item){} }; for (var k in options) { if (options.hasOwnProperty(k)) o[k] = options[k]; } // init var elems = typeof o.selector == 'object' ? [o.selector] : document.querySelectorAll(o.selector); for (var i=0; i 0) that.sc.scrollTop = selTop + that.sc.suggestionHeight + scrTop - that.sc.maxHeight; else if (selTop < 0) that.sc.scrollTop = selTop + scrTop; } } } addEvent(window, 'resize', that.updateSC); document.body.appendChild(that.sc); live('autocomplete-suggestion', 'mouseleave', function(e){ var sel = that.sc.querySelector('.autocomplete-suggestion.selected'); if (sel) setTimeout(function(){ sel.className = sel.className.replace('selected', ''); }, 20); }, that.sc); live('autocomplete-suggestion', 'mouseover', function(e){ var sel = that.sc.querySelector('.autocomplete-suggestion.selected'); if (sel) sel.className = sel.className.replace('selected', ''); this.className += ' selected'; }, that.sc); live('autocomplete-suggestion', 'mouseup', function(e){ if (hasClass(this, 'autocomplete-suggestion')) { // else outside click var v = this.getAttribute('data-val'); that.value = v; o.onSelect(e, v, this); that.focus(); that.sc.style.display = 'none'; } }, that.sc); that.blurHandler = function(){ try { var over_sb = document.querySelector('.autocomplete-suggestions:hover'); } catch(e){ var over_sb = 0; } if (!over_sb) { that.last_val = that.value; that.sc.style.display = 'none'; } else that.focus(); }; addEvent(that, 'blur', that.blurHandler); that.focusHandler = function(){ that.last_val = '\n'; triggerEvent(that, 'keyup'); }; if (!o.minChars) addEvent(that, 'focus', that.focusHandler); var suggest = function(data){ var val = that.value; that.cache[val] = data; if (data.length && val.length >= o.minChars) { var s = ''; for (var i=0;i= o.minChars) { if (val != that.last_val) { that.last_val = val; clearTimeout(that.timer); if (o.cache) { if (val in that.cache) { suggest(that.cache[val]); return; } // no requests if previous suggestions were empty for (var i=1; i