An autocompleter using Yaps, written in FBJS to use on your Facebook Apps
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
README

README

FBJS AutoCompleter 

An autocompleter written in FBJS to use with YAPS (http://github.com/meuble/yaps)

=== Tested on browsers: 

* Mozilla Firefox 3.5
* Apple Safari 4
* Internet Explorer 6 & 7

=== Usage

To use AutoCompleter in your Facebook application, download the latest release of YAPS. Then include it in your FBML like this: 

  <script src="/path/to/yaps.js"></script>
  <script src="/path/to/autocomplete.js"></script>

Then: 

  Simple usage: 
  <script type="text/javascript">
    var ac = new AutoCompleter("input_field_id", {requestUrl: "http://your.service.url/autocompleter"});
  </script>
  
  Some options: 
  <script type="text/javascript">
    var ac = new AutoCompleter("input_field_id", {additionalParameters: {key: "value"}, containerWidth: 450, minChars: 4, requestUrl: "http://your.service.url/autocompleter"});
  </script>
  
  Just check out the code for available options.

=== Response Templating

You can format the autocompleter response using by a template paired with tokens.

Exemple: 

The goal is to display articles search results by showing a title along with a description.

Setup the following template: 

  var template = "*title* in category: *description*";
  var ac = new AutoCompleter("input_field_id", {responseTemplate: template, requestUrl: "http://your.service.url/autocompleter"});
  
Then, your service will have to cover the given tokens, the ajax response will look like:

  [
    {tokens: {title: "Cool Story Bro", description: "Something"}, id: 1, label: "Whatever you wan to display in the input field"},
    {tokens: {title: "Another Cool Story", description: "Cats"}, id: 2, label: "Can be the same as your tokens"},
    {tokens: {title: "Failing again", description: "Dogs"}, id: 3, label: "Failing - Dogs"}
  ];
  
Quick rails exemple: 

  ArticlesController < ApplicationController
  
    def autocomplete
    	stack = []
    	words = `cat /usr/share/dict/words`.grep(Regexp.new("^#{params[:word]}"))[0..10].map {|w| w.gsub("\n", "") }
    	words.each do |word|
    		stack << {:tokens => {:title => word, :description => "#{word} - random category"}, :id => word, :label => word}
    	end
      respond_to do |format|
        format.fbjs { render :json => stack }
      end
    end


=== Documentation

No doc (yet) !

=== License

AutoCompleter is licensed under the terms of the WTFPL, see http://en.wikipedia.org/wiki/WTFPL