mbrevoort / jquery-facebook-multi-friend-selector

A jQuery based Alternative Facebook Multi-Friend Selector that uses the Graph API
Other
266 stars 64 forks source link

ISO New Maintainer

I'm sorry. I haven't had any time to maintain this library (sadpanda). I'm looking for a volunteer to help maintain and progress the library... because everyone's friends deserve to be selected sometimes.

Overview

This is an client side alternative to the Facebook Multi-Friend Selector that relies on jQuery. No server side component necessary which makes it really easy to adapt and use. Check out this blog post with more details and screencast. To see a demo go here. Click login and login to your facebook account and you should see the friend selector.

Much can be customized by CSS, for example if you want a stacked list type selector that's more stripped down

How to use it

This plugin is depends on the Facebook Javascript API so you have to include it:

    <script src="http://connect.facebook.net/en_US/all.js"></script>

Include the plugin javascript file and CSS

Assuming you have a container like:

    <div id="jfmfs-container"></div>

And you have included the Facebook Javascript API And you have already logged the user in. (FB.init and FB.login) You can load the friend selector in a container like this:

    $("#jfmfs-container").jfmfs();

This should fetch the current users friends and give you the interface to select friends. Then when you're ready to move on, there's a function to call that returns an array of the Facebook Ids of the selected friends.

    var friendSelector  = $("#jfmfs-container").data('jfmfs');
    var selectedFriends = friendSelector.getSelectedIds();

Options

These options can be passed into the jfmfs function with a map of options like jfmfs({key1: val, key2: val})

For example your options might look like this if you want a max of 3 friends selected, friends 11111111 and 22222222 preselected, friend 33333333 excluded from the list and to sort by friends' last name:

    {
        max_selected: 3,
        max_selected_message: "{0} of {1} sucker selected",
        friend_fields: "id,name,last_name",
        pre_selected_friends: [11111111, 22222222],
        exclude_friends: [33333333],
        sorter: function(a, b) {
            var x = a.last_name.toLowerCase();
            var y = b.last_name.toLowerCase();
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
        }
    }

Events

jfmfs.friendload.finished - triggered on the container when the list of friends is finished loading

    $("#jfmfs-container").bind("jfmfs.friendload.finished", function() { 
        alert("finished loaded!"); 
    });

jfmfs.selection.changed - triggered on the container when a selection has changed with an array of selected friends each like { id: "123", name: "John Doe"}

    $("#jfmfs-container").bind("jfmfs.selection.changed", function(e, data) { 
        console.log("changed", data);
    });                     

Changelog

Version v4

2/5/2011:

Version v3

1/28/2011:

Version v2 (yeah, not 0.0.0.2)

1/21/2011: