To provide an easy way to obtain the VIAF ID of an input entity through use of the VIAF endpoint.
There are presently three widgets in this project:
- jquery.viafauto.extended.js -- Current: Use this by default (jQuery 1.9+; jQuery UI 1.10+).
- jquery.viafauto.js, the core of the current version, itself an extension of jquery.ui.autocomplete.
- jquery.viaf.autocomplete.js -- Legacy: Uses, but does not extend jquery.ui.autocomplete. This is to enable developers who, for some reason can't immediately upgrade their source to the requred jQuery and jQuery UI versions.
The only usage difference between the legacy widget and the non-legacy widget is extensibility. They both produce a "viafautox" widget. The "extended" implementation is itself a good example of the extensibility afforded by the modern jQuery widget framework.
Currently, the widgets are using the OCLC VIAF AutoSuggest API endpoint, but we may switch to using the VIAF Search endpoint as that develops better support for JSON.
To see the widget(s) in action, view the demo pages.
- jQuery 1.9+ and jQuery UI 1.10+
- jQuery 1.6.1+ and jQuery UI 1.8+ (legacy)
-
Download and include src/jquery.viafauto.js and jquery.viafauto.extended.js (optional, recommended):
See the sample implementation in extended.html.
-
For a legacy application, download and include src/jquery.viaf.autocomplete.js
See the sample implementation in legacy.html.
Either of these widgets take any option that is valid for the appropriate version of jQuery UI's Autocomplete Widget except source, which these widgets define.
There are two additional options:
- nomatch If defined, is a function that is triggered if no data is returned from the VIAF endpoint.
- noselect If defined, is a function that is triggered if the targeted element loses focus without the user having selected something.
Assumes there is a text box foo defined in the html, like:
<input type="text" id="foo"/>
Then invoke directly on the target jQuery element:
$(function() {
$("#foo").viafautox( {
select: function(event, ui){
var item = ui.item;
var message = "From First Search Box: " +item.id + " " + item.value + " (type: " + item.nametype +")";
alert(message);
},
nomatch: function(event.ui) {
var val = $(event.target).val();
alert("no match was found for " + val);
}
}
});
Released under Apache 2.0 license. See the LICENSE file.
jQuery autocomplete backed by viaf.org
Extends jQuery UI's Autocomplete Widget