Class Index | File Index

Classes


Namespace callbacks


Defined in: jquery.better-autocomplete.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
These callbacks are supposed to be overridden by you when you need customization of the default behavior.
Method Summary
Method Attributes Method Name and Description
 
afterHide($results)
Executed after the suggestion list has been hidden.
 
afterShow($results)
Executed after the suggestion list has been shown.
 
beginFetching($input)
Called when remote fetching begins.
 
canonicalQuery(rawQuery, caseSensitive)
To ease up on server load, treat similar strings the same.
 
constructURL(path, query)
Construct the remote fetching URL.
 
fetchRemoteData(url, completeCallback, timeout, crossOrigin)
Fetch remote result data and return it using completeCallback when fetching is finished.
 
Called when fetching is finished.
 
getGroup(result)
From a given result object, return it's group name (if any).
 
highlight(result, $input, trigger)
Gets fired when the a result is highlighted.
 
insertSuggestionList($results, $input)
Insert the results list into the DOM and position it properly.
 
Process remote fetched data by extracting an array of result objects from it.
 
queryLocalResults(query, resource, caseSensitive)
Retrieve local results from the local resource by providing a query string.
 
select(result, $input)
Gets fired when the user selects a result by clicking or using the keyboard to select an element.
 
themeResult(result)
Given a result object, theme it to HTML.
Namespace Detail
callbacks
These callbacks are supposed to be overridden by you when you need customization of the default behavior. When you are overriding a callback function, it is a good idea to copy the source code from the default callback function, as a skeleton.
Method Detail
afterHide($results)
Executed after the suggestion list has been hidden.
Parameters:
{Object} $results
The suggestion list UL element, wrapped in jQuery.

Default behavior: Does nothing.

afterShow($results)
Executed after the suggestion list has been shown.
Parameters:
{Object} $results
The suggestion list UL element, wrapped in jQuery.

Default behavior: Does nothing.

beginFetching($input)
Called when remote fetching begins.

Default behavior: Adds the CSS class "fetching" to the input field, for styling purposes.
Parameters:
{Object} $input
The input DOM element, wrapped in jQuery.

{String} canonicalQuery(rawQuery, caseSensitive)
To ease up on server load, treat similar strings the same.

Default behavior: Trims the query from leading and trailing whitespace.
Parameters:
{String} rawQuery
The user's raw input.
{Boolean} caseSensitive
Case sensitive. Will convert to lowercase if false.
Returns:
{String} The canonical query associated with this string.

{String} constructURL(path, query)
Construct the remote fetching URL.

Default behavior: Adds "?q=" or "&q=" to the path. The query string is URL encoded.
Parameters:
{String} path
The path given in the jQuery.betterAutocomplete constructor.
{String} query
The raw query string. Remember to URL encode this to prevent illegal character errors.
Returns:
{String} The URL, ready for fetching.

fetchRemoteData(url, completeCallback, timeout, crossOrigin)
Fetch remote result data and return it using completeCallback when fetching is finished. Must be asynchronous in order to not freeze the Better Autocomplete instance.

Default behavior: Fetches JSON data from the url, using the jQuery.ajax() method. Errors are ignored.
Parameters:
{String} url
The URL to fetch data from.
{Function} completeCallback
This function must be called, even if an error occurs. It takes zero or one parameter: the data that was fetched.
{Number} timeout
The preferred timeout for the request. This callback should respect the timeout.
{Boolean} crossOrigin
True if a cross origin request should be performed.

finishFetching($input)
Called when fetching is finished. All active requests must finish before this function is called.

Default behavior: Removes the "fetching" class.
Parameters:
{Object} $input
The input DOM element, wrapped in jQuery.

{String} getGroup(result)
From a given result object, return it's group name (if any). Used for grouping results together.

Default behavior: If the result has a "group" property defined, return it.
Parameters:
{Object} result
The result object.
Returns:
{String} The group name, may contain HTML. If no group, don't return anything.

highlight(result, $input, trigger)
Gets fired when the a result is highlighted. This may happen either automatically or by user action.

Default behavior: Does nothing.
Parameters:
{Object} result
The result object that was selected.
{Object} $input
The input DOM element, wrapped in jQuery.
{String} trigger
The event which triggered the highlighting. Must be one of the following:
  • "mouse": A mouseover event triggered the highlighting.
  • "key": The user pressed an arrow key to navigate amongst the results.
  • "auto": If options.autoHighlight is set, an automatic highlight of the first result will occur each time a new result set is rendered.

insertSuggestionList($results, $input)
Insert the results list into the DOM and position it properly.

Default behavior: Inserts suggestion list directly after the input element and sets an absolute position using jQuery.position() for determining left/top values. Also adds a nice looking box-shadow to the list.
Parameters:
{Object} $results
The UL list element to insert, wrapped in jQuery.
{Object} $input
The text input element, wrapped in jQuery.

{Array[Object]} processRemoteData(data)
Process remote fetched data by extracting an array of result objects from it. This callback is useful if the fetched data is not the plain results array, but a more complicated object which does contain results.

Default behavior: If the data is defined and is an array, return it. Otherwise return an empty array.
Parameters:
{mixed} data
The raw data recieved from the server. Can be undefined.
Returns:
{Array[Object]} A flat array containing result objects. May be an empty array.

{Array[Object]} queryLocalResults(query, resource, caseSensitive)
Retrieve local results from the local resource by providing a query string.

Default behavior: Automatically handles arrays, if the data inside each element is either a plain string or a result object. If it is a result object, it will match the query string against the title and description property. Search is not case sensitive.
Parameters:
{String} query
The query string, unescaped. May contain any UTF-8 character. If case insensitive, it already is lowercased.
{Object} resource
The resource provided in the jQuery.betterAutocomplete init constructor.
{Boolean} caseSensitive
From options.caseSensitive, the searching should be case sensitive.
Returns:
{Array[Object]} A flat array containing pure result objects. May be an empty array.

select(result, $input)
Gets fired when the user selects a result by clicking or using the keyboard to select an element.

Default behavior: Inserts the result's title into the input field.
Parameters:
{Object} result
The result object that was selected.
{Object} $input
The input DOM element, wrapped in jQuery.

{String} themeResult(result)
Given a result object, theme it to HTML.

Default behavior: Wraps result.title in an h4 tag, and result.description in a p tag. Note that no sanitization of malicious scripts is done here. Whatever is within the title/description is just printed out. May contain HTML.
Parameters:
{Object} result
The result object that should be rendered.
Returns:
{String} HTML output, will be wrapped in a list element.

Documentation generated by JsDoc Toolkit 2.4.0 on Thu Apr 26 2012 05:09:57 GMT+0200 (CEST)