Mootools Facebook Search

When it comes to social web, facebook is clearly a reference, packed with outstanding features. Among them, their famous autocompletion search input, allowing you to quickly find a particular friend. Another one that I like is when you want to send a message, it is really easy to select the friends you want to send it to. It is now being used by hotmail as well.

There's a Mootools script for this already, developped by Guillermo Rauch, and that I use for several projects, but I didn't find any script performing an autocompletion search like the facebook one.

From the Guillermo Rauch's script, and thanks to the help of Josh Moont from Inspire, we modified the code to obtain a solution based on the same search meachnism, but with a different output, resulting in the mootools facebook search plugin. I hope you will enjoy it.

Source and © Jeremy DESVAUX .
  • Previous Resource
  • Download
  • Next Resource

Demonstration

  • Type a name

How to setup

The First thing to do if you want to use that plugin is to include the different files, (The Mootools library, textboxlist.js and fansearch.js).
There's also a basic stylesheet to render the results properly.
  1. /** Mootools inclusion **/
  2. <script type="text/javascript" src="Path_to/Mootools.js"></script>
  3. /** Textboxlist inclusion **/</h3>
  4. <script type="text/javascript" src="Path_to/textboxlist.js"></script>
  5. /** Fansearch inclusion **/</h3>
  6. <script type="text/javascript" src="Path_to/fansearch.js"></script>
  7. /** Additional Style **/
  8. <link href="Path_to/style.css" rel="stylesheet" type="text/css"/>
The purpose of that plugin is to dynamically search among a predefined set of data so now that we have included the files, we need to create those data under the form of a JSON array.
This can be done in a separate page of your choice. In our case, we'll call it fcbksearchfeed.
Every piece of information needs to have 3 things: a caption (the name that will be displayed as text), a value (the id of that information), and a picture path (to display the image).
for example:
  1.  
  2. [
  3. {
  4. "caption": "Sylvia Molloy",
  5. "value": "1",
  6. "picture": "lib/fcbksrch/imgs/imgtest (1).jpg"
  7. },
  8. {
  9. "caption": "Manuel Mujica Lainez",
  10. "value": "2",
  11. "picture": "lib/fcbksrch/imgs/imgtest (2).jpg"
  12. }
  13. ]
  14.  
Now that the files are included and the data set is ready, we create the form with the search input as follows:
  1. <form id="fcbksrchform">
  2. <ul>
  3. <li id="facebook-list" class="input-text">
  4. <input type="text" value="" id="facebook-demo" name="facebook-demo"/>
  5. <div id="facebook-auto">
  6. <div class="default">Type a name</div>
  7. <ul class="feed"> </ul>
  8. </div>
  9. </li>
  10. </ul>
  11. </form>
This leads us to our last part. At this point, we have all our separated files ready, we then need to register them all with the fansearch script to make it working.
So you need to open the fansearch.js file and specify the following options:
  • JSONUrl: Url of the json page from where to fetch the data. (in our case /fcbksrchfeed)
  • GOTOUrl: Url you want to go to when the user clicks on of the list elements. (Or when he presses enter).
  • UserInput: Id and Name of the input where the user types, here the facebook-demo input.
  • ResContainer: Id and Name of the results container, where all the results will appear (here the facebook-auto div).
All done! If you need any extra information do not hesitate to ask. Hope this will help.

Why not share this here:

  • Tweet this
  • Buy the author a coffee
  • Bump this
  • Digg this
  • Post this on Del.icio.us
  • Post this on StumbleUpon
  • Post this on Reddit
  • Post this on Technorati
  • Post this on Google
  • Post this on Facebook
  • Email this to a friend

You may also like:

  • jQuery FancyBox Plugin
  • A guide to Ajax Interactions with jQuery
  • How to make SEO friendly urls
  • jQuery ThickBox Plugin
  • jQuery library
  • Creating a simple image gallery with PHP & jQuery

Leave a Comment

Posted Comments

jdmweb
No comments have been posted so far. Be the first!
From jdmweb at 19:06 29/07/10 { Reply }