Coder Social home page Coder Social logo

jquery-facebook-multi-friend-selector's Introduction

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

  • max_selected: int (optional)- max number of items that can be selected

  • labels: object with i18n labels for translations. If you pass this, you need to define all of the labels.

      labels: {
      	selected: "Selected",
      	filter_default: "Start typing a name",
      	filter_title: "Find Friends:",
      	all: "All",
      	max_selected_message: "{0} of {1} selected"
      	// message to display showing how many items are already selected like: "{0} of {1} chosen"
      }
    
  • friend_fields: a comma separated list of fields to return in case you need additional fields for sorting. However you should always at least specify: "id,name",

  • sorter: a function reference that will be called to do the sorting. It takes two arguments which are the two friend objects to be compared and returns "truthy if the first should come before the second. The default is:

      function(a, b) {
      	var x = a.name.toLowerCase();
      	var y = b.name.toLowerCase();
      	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
      }
    
  • pre_selected_friends: an array of ids of friends to preselect once loaded like: pre_selected_friends: [1014025367]

  • exclude_friends: an array of ids of friends to exclude from the list like: exclude_friends: [33333333]

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:

  • Fixed issue with images not loading when list is filtered

  • Added i18n label object option to override default text

  • Fixed bug when there was only one row of friends

  • Added minified version [5.37KB (2.06KB gzipped)]

Version v3

1/28/2011:

  • Added customizable sorter option (see details in options section)

  • Added pre_selected_friends option (see details in options section)

  • Added exclude_friends option (see details in options section)

Version v2 (yeah, not 0.0.0.2)

1/21/2011:

  • Added some performance optimizations especially with a large number of friends

  • Custom events for notification when friends are loaded or selections change

  • Progressive image loading when scrolling including the usage of Ben Alman's awesome throttle/debounce library for smoother scrolling

jquery-facebook-multi-friend-selector's People

Contributors

mbrevoort avatar slexaxton avatar yuri-korzun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-facebook-multi-friend-selector's Issues

Preload friend images - feature request.

It would be great if the plugin would allow to preload images or at least have the functionality to start loading images before being displayed.

This would allow background loading and would improve user experience.

I18n support

Hi,

currently some labels are hard-coded in the JS file ("Start typing a name" etc.). There should be a way to localize all strings, maybe using the options object which is passed to the jfmfs() call.

Hover classes not working in Chrome

I found a bug with Chrome v10.0.648.205 on OSX 10.6 where the friend selector does not show the hover classes on friend elements in the list. I fixed this by doing the following:

elem.find(".jfmfs-friend:not(.selected)").live(
'hover', function (ev) {
if (ev.type == 'mouseover' || ev.type == 'mouseenter') {
$(this).addClass("hover");
}
if (ev.type == 'mouseout' || ev.type == 'mouseleave') {
$(this).removeClass("hover");
}
});

Server side friends data

Hello,

Great job on this tool. I really like the look at feel of the plugin. In my app, I already use the Koala gem and because I get 'offline_access' I can get the list of friends even if the user is not currently logged in into Facebook. Is there an easy way of replacing the call to Facebook with a json object representation of the id and name of friends?

Thank you,

Example Fails with Login Failed Notice

Hello,
I tried uploading the example file to my server, only changing the app id to my app id. When I load the page and attempt to execute the script by clicking on the login link, the script throws a failure notice, stating that the login failed. I was already logged in to facebook at the time.

I tried inserting the code to initialize an app from here, and then the getLoginStatus code from here, finally switching out the login code in the example with the sample code from here.

The rest of the code is exactly the same from your example, and when I ran it, it appeared to work. I'm a complete noob to a lot of this stuff, but I'm guessing the facebook is actively deprecating all the stuff which doesn't use the new Oauth system?

Thanks for sharing the plugin, finding it made my week!

.

.

album selector

Sorry! not issue, just request.

Why not improve "Album Selector" feature?

$('#jfmps-container').jfmps({
noAlbumImagesText: 'You have no images in this album.',
noAlbumsText: 'You do not have any albums.',
submitCallback: function(jsonData){ alert(jsonData); },
imageSubmitButton: $('#jfmps-submit-button'),
maxPhotosSelected: 1,
numAlbumColumns: 4,
numPhotosColumns: 6,
albumSelectorMode: true, // <============ ALBUM SELECTOR FEATURE
debug: true
});

Feeding user ids, rather than getting all friends

Would it be possible to add an option, that accepts ids of users and displays only those users, rather than all friends of a user? That would be extremely useful for me. I know, that I can simply exclude all the users but the ones I want, but that seems like an overkill for me.

Support multiple jfmfs on a page

Original title: too many ids in generated html

All divs generated by jfmfs have ids, like: jfmfs-friend-selector, jfmfs-inner-header, jfmfs-friend-container, etc. This is pretty inconvenient, since I have two of those selectors on a single page, so a conflict is inevitable. How about changing them to classes?

Centering Friends within the friend container

I removed the width attribute from the #jfmfs-friend-container to let the container expand to the parent div's size but now the friend icons are left justified. This produces a large white spaces from the right side of the container. I tried to play around with the float attribute with no avail - any suggestions how I would be able to fix this?

CSS cuts off bottom of friends container

Great plugin!

One issue that I've noticed: the bottom of the friends container in an iframe canvas app gets cut off. The vertical scrollbar is there but the last row of people cannot be scrolled to. The canvas iframe has been resized with FB's javascript so I don't think it's that.

avoid text selection of friends

I noticed in the screen cast text being selected. At least in Firefox/Webkit browsers you can add these rules

-webkit-user-select:none;
-moz-user-select:none;

to prevent the inadvertent text selection...

Is there a method to reset the filter?

I am using the friend selector to select friends one at a time (cannot select multiple in this case, as they are for different categories) I show and hide the friend selector as required, however I would like to reset the filter if the user has types anyhing and previously filtered the list, is there way to reset this filter?

Add show()/hide() methods

It would be nice if there were additional public methods to show and hide the selector. Currently this has to be done by adding and removing the container-element...

Get names as well as ID's?

When running getSelectedIds() you only get the ID's. Is it possible to somehow get the names as well?

Not usable with lots of friends

I created a fork to fix a couple of problems, check it out at amirshim/jquery-facebook-multi-friend-selector@ad81497

Here's a summary...

When there are lots of friends, the browser gets bogged down with having to do 1000's of secure http requests... for each photo, it has to get the real photo url. it might also prevent caching on some browsers. Fixed it by doing a FQL query to get all the actual photos along with the names/ids of your friends.

Even with the fixes, rendering is still slow, but manageable. For 5000 friends, it takes 20 seconds or so, probably because of the float left. Maybe this could be fixed by using absolute positioning. (?)

Could also load the images as needed... i.e. only when they are displayed... something like http://developer.yahoo.com/yui/3/imageloader/

Also you should disable default behavior for clicking on all/selected buttons... in case developers are using hash for ajax.

I had some problems with live(), so I switched them to delegate(). Probably didn't need to, but I think it also makes it more readable... sorry.

test user friends of test users don't show up

When I'm logged in as a test user (say A) who has test user friends (say B and C), they don't show up in the selector. It looks like this is in the code that calls for friends:

$("#jfmfs-container").jfmfs({
friend_fields: "id,name,last_name",
...

this in turn makes a FB.api call like "https://graph.facebook.com/me/friends?fields=id,name,last_name&access_token=..."
Usually this returns a data object with an array of objects [{ "id": "123456", "name": "Bob Smith", "last_name": "Smith" }, {..},]
but for test users you get: [{ "id": "123456"}, {..},]

I am not sure why this is. Maybe Facebook does not allow names because they might somehow pollute the real user namespace? If this is not an error, maybe generating stub names might make sense for test users so that they can still be selected and the show can go on. That's what I'm thinking of doing. If I have a good patch, I'll pull request.
Thoughts welcome,

Callback after data is loaded

Hey Mike, thanks a ton for writing this. I'm using it to great effect. I was wondering if you'd mind slipping in a callback function I could supply in the options once a user's friends are returned. There are folks out there with ~1000 friends, or slow connections, and I'd like to be able to display a loading message while their friends are being pulled.

Last user selection.

Hi.

I found problem in your demo page. I filtered my friends for seeing for example 4 friends. And then try to select 4 friends in your control. Can't select the any 4 person. Is it bug?

Thanks.

Still maintained?

Hi Mike,

is this repository still maintained? If not, could you put a notice at the top of the Readme, if possible with the offer to add other committers to take over?

Robin

Max 15 limit

Is the max limit of 15 friends to select there because of a limitation from Facebook? or is it something I can adjust without an issue?

Static watermark text for friend-search textbox

Used your plugin for a German website, and I need to translate most of the labels in German language. Most of the settings are changed from just defining in settings, but one label (settings.labels.filter_default) is static in code at line number 248 & 254. I need to replace the static text "Start typing a name" with the "settings.labels.filter_default" variable and now watermark text working fine for German language. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.