Autocompleter.js

3rd party script for managing autocomplete functionality.

Details

AuthorHarald Kirschner <mail [at] digitarald.de>
Refactored byAaron Newton <aaron [dot] newton [at] cnet [dot] com>
LicenseMIT-style license
Version1.0rc3
Sourcehttp://digitarald.de/project/autocompleter/

Dependencies

Mootools 1.1<Class.Extras>, <Element.Event>, <Element.Selectors>, <Element.Form>, <Element.Dimensions>, Fx.Style, Ajax, Json
AutocompleterObserver.js
Summary
Autocompleter.js3rd party script for managing autocomplete functionality.
AutocompleterAll functions are part of the Autocompleter namespace.
Autocompleter.BaseBase class for the Autocompleter classes.
Properties
buildBuilds the html structure for choices and appends the events to the element.
getQueryValueReturns the user’s input to use to match against the full list.
destroyRemove the autocomplete functionality from the input.
hideChoicesHides the choices from the user.
showChoicesShows the choices to the user.
markQueryValueMarks the queried word in the given string with <span class=”autocompleter-queried”>*</span> Call this i.e.
addChoiceEventsAppends the needed event handlers for a choice-entry to the given element.
OverlayFix
Change Log$Source: /cvs/main/flatfile/html/rb/js/global/cnet.global.framework/common/3rdParty/Autocomplete/Autocompleter.js,v $ $Log: Autocompleter.js,v $ Revision 1.3 2007/06/12 20:26:52 newtona * empty log message *

Autocompleter

All functions are part of the Autocompleter namespace.

Autocompleter.Base

Base class for the Autocompleter classes.

Arguments

el(DOM element or id) element to observe.
options(object) key/value set of options.

Options

minLength(integer, default 1) Minimum length to start auto compliter
useSelection(boolean, default true) Select completed text part (works only for appended strings)
markQuery(boolean, default true) Mark queried string with <span class=”autocompleter-queried”>*</span>
inheritWidth(boolean, default true) Inherit width for the autocompleter overlay from the input field
maxChoices(integer, default 10).  Maximum of suggested fields.
injectChoice(function, optional).  Callback for injecting the list element with the arguments (itemValue, itemIndex), take a look at updateChoices for default behaviour.
onSelectEvent Function.  Fires when when an item gets selected.
onShowEvent Function.  Fires when autocompleter list shows.
onHideEvent Function.  Fires when autocompleter list hides.
customTarget(element, optional).  Allows to override the autocompleter list element with your own list element.
className(string, default ‘autocompleter-choices’).  Class name for the list element.
zIndex(integer, default 42). z-Index for the list element.
observerOptionsoptional Options Object.  For the Observer class.
fxOptionsoptional Options Object.  For the Fx.Style on the list element.
allowMulti(boolean, defaults to false) allow more than one value, seperated by a delimeter
delimeter(string) default delimter between multi values (defaults to “, “)
autotrim(boolean) trim the delimeter on blur
allowDupes(boolean, defaults to false) if multi, prevent duplicate entries
baseHref(string) the base url where the css and image assets are located (defaults to cnet’s servers you should change)

Note

If you’re not cnet, you should download these assets to your own local: http://www.cnet.com- /html- /rb- /assets- /global- /autocompleter- /Autocompleter.css http://www.cnet.com- /html- /rb- /assets- /global- /autocompleter- /spinner.gif

Then either change this script or pass in the local when you instantiate the class.

Example

This base class is not used directly (but rather its inheritants are such as Autocompleter.Ajax) so there is no example here.

Summary
Properties
buildBuilds the html structure for choices and appends the events to the element.
getQueryValueReturns the user’s input to use to match against the full list.
destroyRemove the autocomplete functionality from the input.
hideChoicesHides the choices from the user.
showChoicesShows the choices to the user.
markQueryValueMarks the queried word in the given string with <span class=”autocompleter-queried”>*</span> Call this i.e.
addChoiceEventsAppends the needed event handlers for a choice-entry to the given element.

Properties

build

Builds the html structure for choices and appends the events to the element.  Override this function to modify the html generation.

getQueryValue

Returns the user’s input to use to match against the full list.  When options.multi == true, this value is the last entered string after the last index of the delimeter.

Arguments

value(string) optional, the value to clean; defaults to this.observer.value

Examples

user input: blue
getQueryValue() returns "blue"

user input: blue, green, yellow
options.multi = true
options.delimter = ", "
getQueryValue() returns "yellow"

user input: blue, green, yellow,
options.multi = true
options.delimter = ", "
getQueryValue() returns ""

destroy

Remove the autocomplete functionality from the input.

hideChoices

Hides the choices from the user.

showChoices

Shows the choices to the user.

markQueryValue

Marks the queried word in the given string with <span class=”autocompleter-queried”>*</span> Call this i.e. from your custom parseChoices, same for addChoiceEvents

Arguments

txt(string) the string to mark

addChoiceEvents

Appends the needed event handlers for a choice-entry to the given element.

Arguments

el(DOM element or id) the element to add

OverlayFix

Private class used by <Autocompleter>basically an IframeShim.

Change Log

$Source: /cvs/main/flatfile/html/rb/js/global/cnet.global.framework/common/3rdParty/Autocomplete/Autocompleter.js,v $ $Log: Autocompleter.js,v $ Revision 1.3 2007/06/12 20:26:52 newtona * empty log message *

Revision 1.2 2007/06/07 18:43:35 newtona added CSS to autocompleter.js removed string.cnet.js dependencies from template parser and stickyWin.default.layout.js

Revision 1.1 2007/06/02 01:35:17 newtona * empty log message *

All functions are part of the Autocompleter namespace.
Base class for the Mootools Effects (Moo.Fx) library.
The Style effect; Extends Fx.Base, inherits all its properties.
An Ajax class, For all your asynchronous needs.
Simple Json parser and Stringyfier, See: http://www.json.org/
Observes formelements for changes; part of the <Autocomplete> 3rd party package.
Contains the classes for the Remote methods for Autocompleter
There are two types of elements that (sometimes) prohibit you from positioning a DOM element over them: some form elements and some flash elements.