Constructor
new WikidataAutocompleteAdapter()
See AbstractAutocompleteAdapter for parameter documentation, not shown here due to jsdoc bug.
Extends
Members
ac :AC
After AbstractAutocompleteAdapter#setupAutocomplete is run, holds a reference to the autocomplete widget used by this instance.
Type:
- AC
- Overrides:
- Source:
acCSSPrefix :String
CSS prefix for the autocomplete widget.
Type:
- String
- Overrides:
- Source:
acDelay :Number
We override the default; Wikidata can take more of a beating than some other sites. :)
Type:
- Number
- Overrides:
- Source:
acPrimaryTextKey :String
We override the default, because we may display different text (stored in this field) than what we pass along to the application (stored in the label field). The display text may include a parenthetical component that highlights a match against an alias, rather than the primary label.
Type:
- String
- Overrides:
- Source:
acSecondaryTextKey :String
Default row key for the optional secondary, smaller text shown in the autocomplete widget below each result.
Type:
- String
- Overrides:
- Source:
displayResults :Number
Type:
- Number
- Source:
- See:
excludedItemClasses :Array.<String>
Items with these classes are typically not going to be the target of reviews.
Type:
- Array.<String>
fetchResults :Number
Because we exclude certain item classes (e.g., disambiguation pages), we fetch a larger number of results than we may need, since we may eliminate some of them. The ratio configured here has proven to strike a good balance where few queries result in zero "good" results.
Type:
- Number
nativeToWikidata :Object
How do lib.reviews language code translate to Wikidata language codes? lib.reviews language code are used as keys, Wikidata codes as values.
Since Wikidata supports a superset of languages and most language code are identical, we only enumerate exceptions.
Type:
- Object
queryServiceTimeout :Number
Timeout for query service validation requests in milliseconds
Type:
- Number
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
_extractRowHandler(item, queryString) → {Object}
Transform a result from the Wikidata item into a row that can be rendered by the autocomplete widget.
This:
Parameters:
Name | Type | Description |
---|---|---|
item |
Object | a query result returned by the SPARQL query service (member of |
queryString |
String | the original (unescaped) query string is used for highlighting the match in a composite title that includes both the label and the alias against which the query matched |
Returns:
plain object that only contains the data we can use inside the
application, plus a derived title
property for rendering this row in
the autocomplete widget.
- Type
- Object
_renderNavHandler(spec)
Render next/previous navigation within the autocomplete widget.
This:
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
spec |
Object | Navigation settings Properties
|
_renderNoResultsHandler()
Render "No search results" text row at the bottom with default styles.
This:
- Overrides:
- 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 |
- Overrides:
- Source:
_requestHandler(query, offsetopt)
Send an autocomplete request to the Wikidata query service and render the result using the autocomplete widget.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
query |
String | the query string |
|
offset |
Number |
<optional> |
the offset from which to continue a previous query. |
- Overrides:
- 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
|
||||||||||||||||||||
event |
Event | the click or keyboard event which triggered this row selection. |
- Overrides:
- 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.
- Overrides:
- Source:
enableSpinner()
Show activity indicator in the input widget. Must be called in handler code via this.adapter.
- Overrides:
- Source:
getSourceID() → {String}
Return the canonical source identifier for this adapter
- Overrides:
- Source:
Returns:
- Type
- String
lookup(url) → {Promise}
Look up a single item in Wikidata given its URL. Uses the MediaWiki API.
Parameters:
Name | Type | Description |
---|---|---|
url |
String | the URL to look up |
- Overrides:
- Source:
Returns:
resolves to a LookupResult if successful, rejects with error if not.
- Type
- Promise
removeAutocomplete()
Remove the autocomplete widget including all its event listeners.
- Overrides:
- Source:
runAutocomplete()
Run the autocomplete widget on the current input.
- Overrides:
- Source:
setupAutocomplete()
Initialize the autocomplete widget. You can add additional callbacks /
custom properties in the inherited class; just remember to call
super.setupAutocomplete()
first.