My favorites | Sign in
Project Logo
                
Search
for
Updated Nov 20, 2008 by daepark
Usage  

Requires at least jquery-1.2.2.

freebaseSuggest() provides a way to attach Freebase suggestion behavior to a text input using the Freebase.com autocomplete service.

freebaseSuggest accepts an optional argument which is a dictionary that could overwrite one or more default settings as described below.

widthThis is the width of the suggestion list and the flyout in pixels. Default is 275.
softSoft suggestion. If true, DO NOT auto-select first item in the suggestion list. Otherwise, select first item. Default is true.
suggest_newTo enable a suggest new option, set text to a non-null string. This is the string displayed for the suggest new option (eg, "Create new topic"). Default is null.
flyoutTo enable flyout to show additional information for the currently highlighted item including a thumbnail and blurb. Default is true.
service_urlThis the base url to all the api services like autocomplete, blurbs and thumbnails. Default is "http://www.freebase.com".
ac_pathThe path to the autcomplete service. Default is "/api/service/search".
ac_paramA dictionary of query parameters to the autocomplete service. see http://code.google.com/p/freebase-suggest/wiki/FreebaseAPISearch
ac_qstrThis is the parameter name to be passed to the autocomplete service for the string to autocomplete on. Default is 'prefix'. The parameter value will be what the user typed in the input. see http://code.google.com/p/freebase-suggest/wiki/FreebaseAPISearch
blurb_pathThe path to the blurb service for the description to be shown in the flyout. Default is "/api/trans/blurb".
blurb_paramThe query parameters to the blurb service. Default is { maxlength: 300 }.
thumbnail_pathThe path to the thumbnail service to be shown in the flyout. Default is "/api/trans/image_thumb".
thumbnail_paramThe query paramters to the thumbnail service. Default is {}.
filterSpecify a filter function if you want to filter any of the items returned by ac_path service. The function is called with one argument representing an item from the ac_path result. The function should return TRUE to include the item or FALSE to exclude. Default is a function that returns TRUE. See fbs.filter
transformSpecify a transform function if you want to transform the default display of the suggest list item. See fbs.transform

In addition, freebaseSuggest will trigger the following events on behalf of the input it's attached to. They include:

fb-selectTriggered when something is selected from the suggestion list. The data object will contain id and name fields: { id: aString, name: aString }.
fb-select-newTriggered when the suggest_new option is selected. The data object will only contain a name field: { name: aString }.

Example 1. Attach Freebase suggestion behavior to #myInput with default options and on 'fb-select', output the selected id to the console.

$('#myInput')
     .freebaseSuggest()
     .bind('fb-select', function(e, data) { console.log('suggest: ', data.id); })

Example 2. Soft suggestion on instances of '/film/film' with a suggest new option and output the various events to the console.

var options = {
     soft: true,
     suggest_new: 'Create new Film',
     ac_param: {
         type: '/film/film',
     }
};
$('#myInput')
     .freebaseSuggest(options)
     .bind('fb-select', function(e, data) { console.log('suggest: ', data.id); })
     .bind('fb-select-new', function(e, data) { console.log('suggest new: ', data.name); });


Sign in to add a comment
Hosted by Google Code