Class: AbstractAutocompleteAdapter

(abstract) AbstractAutocompleteAdapter(updateCallback, searchBoxSelector)

Adapter that handles ordinary URL lookup (as specified in AbstractLookupAdapter) and autocomplete searches. Autocomplete searches rely on the remote-ac package written by Danqing Liu.

The autocomplete class (AC global) must exist before this code is run. We communicate with the widget using callbacks, prefixed with _, which are bound to it.

Constructor

(abstract) new AbstractAutocompleteAdapter(updateCallback, searchBoxSelector)

Parameters:
Name Type Description
updateCallback function

Callback to run after a row has been selected.

searchBoxSelector String

jQuery selector for input we're adding the autocomplete widget to.

Source:

Extends

Members

ac :AC

After AbstractAutocompleteAdapter#setupAutocomplete is run, holds a reference to the autocomplete widget used by this instance.

Type:
  • AC
Source:

acCSSPrefix :String

CSS prefix for the autocomplete widget.

Type:
  • String
Source:

acDelay :Number

Delay in milliseconds before performing a search.

Type:
  • Number
Source:

acPrimaryTextKey :String

Key (into the row objects retrieved via the request handler) that determines which value is used as the main text in the autocomplete widget.

'label' corresponds to what the main application expects, but if you want to show something different than what gets passed to the application, you may want to change it.

Type:
  • String
Source:

acSecondaryTextKey :String

Default row key for the optional secondary, smaller text shown in the autocomplete widget below each result.

Type:
  • String
Source:

sourceID :String

Canonical identifier for this source. Lower-case string, no whitespace.

Type:
  • String
Overrides:
Source:

supportedPattern :RegExp

RegExp for URLs this adapter can handle.

Type:
  • RegExp
Overrides:
Source:

Methods

_renderNoResultsHandler()

Render "No search results" text row at the bottom with default styles.

This:
Source:

(abstract) _renderRowHandler(row)

Callback for rendering a row within the autocomplete widget, overriding default rendering.

This:
Parameters:
Name Type Description
row Object

The row object to render

Source:

(abstract) _requestHandler(query)

Callback for fetching row data.

This:
Parameters:
Name Type Description
query String

The characters entered by the user

Source:

_selectRowHandler(row, event)

Pass along row data we can handle to the main application. Will also query lib.reviews itself (through the native adapter) for the URL, so we can give preferential treatment to an existing native record for the review subject.

This:
Parameters:
Name Type Description
row Object

row data object. All properties except "url" are only used for display purposes, since the server performs its own lookup on the URL.

Properties
Name Type Attributes Description
url String

the URL for this review subject

label String

the main name shown for this review subject

subtitle String <optional>

shown as secondary title for the subject

description String <optional>

shown as short description below label and subtitle

event Event

the click or keyboard event which triggered this row selection.

Source:

ask(url) → {Boolean}

Does this adapter support the given URL? By default, performs a simple regex check.

Parameters:
Name Type Description
url String

the URL to test

Overrides:
Source:
Returns:

true if supported

Type
Boolean

disableSpinner()

Hide activity indicator in the input widget. Must be called in handler code via this.adapter.

Source:

enableSpinner()

Show activity indicator in the input widget. Must be called in handler code via this.adapter.

Source:

getSourceID() → {String}

Return the canonical source identifier for this adapter

Overrides:
Source:
Returns:
Type
String

(abstract) lookup(_url) → {Promise}

Perform a lookup for a given URL.

Parameters:
Name Type Description
_url String

the URL to perform lookup for

Overrides:
Source:
Returns:

promise that resolves with a result object of the form LookupResult on success, and rejects with an error on failure

Type
Promise

removeAutocomplete()

Remove the autocomplete widget including all its event listeners.

Source:

runAutocomplete()

Run the autocomplete widget on the current input.

Source:

setupAutocomplete()

Initialize the autocomplete widget. You can add additional callbacks / custom properties in the inherited class; just remember to call super.setupAutocomplete() first.

Source: