Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
jQuery VIAF autocomplete backed by viaf.org
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
images
js
src
.gitignore
LICENSE
README.md
TODO.txt

README.md

jquery-viaf-autocomplete

Goals

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.

Demo

To see the widget(s) in action, view the demo pages.

Requirements

  • jQuery 1.9+ and jQuery UI 1.10+
  • jQuery 1.6.1+ and jQuery UI 1.8+ (legacy)

Usage

Download the source:

  • 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.

Options

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.

Sample Usage

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);
       } 
   }
});

License

Released under Apache 2.0 license. See the LICENSE file.

VIAF Documentation

jQuery autocomplete backed by viaf.org

OCLC VIAF API Documentation

Using the API

Request Types

Response Details

SRU Explain page

Sample Viaf Links

Callback http://viaf.org/viaf/AutoSuggest?query=james&callback=myCallBack
Wildcard (only at end) http://viaf.org/viaf/AutoSuggest?query=jam%25&callback=samplecallback
Name Only http://www.viaf.org/viaf/search?query=local.personalNames+%3D+%22james%22&recordSchema=http://viaf.org%2FVIAFCluster&maximumRecords=100&startRecord=1&resultSetTTL=300&recordPacking=xml&recordXPath=&sortKeys=

jQuery links

Extends jQuery UI's Autocomplete Widget

Something went wrong with that request. Please try again.