--- Webpacus/root/js/webpac.js 2005/11/27 22:10:36 187 +++ Webpacus/root/js/webpac.js 2005/12/02 23:01:25 203 @@ -156,3 +156,68 @@ } return false; } + +/* + autocompleter which isn't (a suggest box) + - don't just on first option on appear + - removed fade-in/out effect + - added configurable width (content width? centered?) + - add icon which means suggest + + hopefully, this implementation won't break when I update prototype next time :-) +*/ + +Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), { + initialize: function(element, update, url, options) { + this.baseInitialize(element, update, options); + this.options.asynchronous = true; + this.options.onComplete = this.onComplete.bind(this); + this.options.defaultParams = this.options.parameters || null; + this.url = url; + this.ignoreReturn = true; + + this.options.onShow = function(element, update) { + if(!update.style.position || update.style.position=='absolute') { + update.style.position = 'absolute'; + Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight}); + } + new Element.show(update); + Logger.debug('Ajax.Suggest.onShow'); + }; + + this.options.onHide = function(element, update) { + new Element.hide(update); + Logger.debug('Ajax.Suggest.onHide'); + }; + }, + + getUpdatedChoices: function() { + entry = encodeURIComponent(this.options.paramName) + '=' + + encodeURIComponent(this.getToken()); + + this.options.parameters = this.options.callback ? + this.options.callback(this.element, entry) : entry; + + if(this.options.defaultParams) + this.options.parameters += '&' + this.options.defaultParams; + + Logger.debug('Ajax.Suggest called '+this.url); + new Ajax.Request(this.url, this.options); + }, + + onComplete: function(request) { + Logger.debug('Ajax.Suggest onComplete called'); + this.updateChoices(request.responseText); + }, + + markPrevious: function() { + if(this.index > 0) this.index-- + // else this.index = this.entryCount-1; + }, + + markNext: function() { + if(this.index < this.entryCount-1) this.index++ + // else this.index = 0; + }, + +});