Permalink
Browse files

Added custom sort options, prevented selectable text

  • Loading branch information...
1 parent fb9d531 commit a29214b3e32e54b9353007defc5845a710c6c709 @mbrevoort committed Jan 29, 2011
View
@@ -47,8 +47,29 @@ 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
-max_selected_message: String (optional, but required if max_selected specified) - message to display showing how many items are already selected like: "{0} of {1} chosen"}
+* max_selected: int (optional)- max number of items that can be selected
+* max_selected_message: String (optional, but required if max_selected specified) - 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));
+ }
+
+For example your options might look like this if you want a max of 3 friends selected and to sort by friends' last name:
+
+ {
+ max_selected: 3,
+ max_selected_message: "{0} of {1} sucker selected",
+ friend_fields: "id,name,last_name",
+ 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
------
View
@@ -47,7 +47,19 @@
function init() {
FB.api('/me', function(response) {
$("#username").html("<img src='https://graph.facebook.com/" + response.id + "/picture'/><div>" + response.name + "</div>");
- $("#jfmfs-container").jfmfs({ max_selected: 15, max_selected_message: "{0} of {1} selected"});
+
+
+
+ $("#jfmfs-container").jfmfs({
+ max_selected: 15,
+ max_selected_message: "{0} of {1} selected",
+ friend_fields: "id,name,last_name",
+ sorter: function(a, b) {
+ var x = a.last_name.toLowerCase();
+ var y = b.last_name.toLowerCase();
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ }
+ });
$("#jfmfs-container").bind("jfmfs.friendload.finished", function() {
console.log("finished loading!");
});
@@ -34,6 +34,8 @@ limitations under the License.
border: 1px solid #FFFFFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
+ -webkit-user-select:none;
+ -moz-user-select:none;
}
.jfmfs-friend img {
@@ -34,6 +34,8 @@ limitations under the License.
border: 1px solid #FFFFFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
+ -webkit-user-select:none;
+ -moz-user-select:none;
}
.jfmfs-friend img {
@@ -26,7 +26,13 @@
var settings = $.extend({
max_selected: -1,
- max_selected_message: "{0} of {1} selected"
+ max_selected_message: "{0} of {1} selected",
+ friend_fields: "id,name",
+ sorter: function(a, b) {
+ var x = a.name.toLowerCase();
+ var y = b.name.toLowerCase();
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ }
}, options || {});
var lastSelected; // used when shift-click is performed to know where to start from to select multiple elements
@@ -50,12 +56,8 @@
container = $("#jfmfs-friend-selector"),
all_friends;
- FB.api('/me/friends?fields=id,name', function(response) {
- var sortedFriendData = response.data.sort(function(a, b) {
- var x = a.name.toLowerCase();
- var y = b.name.toLowerCase();
- return ((x < y) ? -1 : ((x > y) ? 1 : 0));
- });
+ FB.api('/me/friends?fields=' + settings.friend_fields, function(response) {
+ var sortedFriendData = response.data.sort(settings.sorter);
var buffer = [];
@@ -174,14 +176,16 @@
});
// filter by selected, hide all non-selected
- $("#jfmfs-filter-selected").click(function() {
+ $("#jfmfs-filter-selected").click(function(event) {
+ event.preventDefault();
all_friends.not(".selected").addClass("hide-non-selected");
$(".filter-link").removeClass("selected");
$(this).addClass("selected");
});
// remove filter, show all
- $("#jfmfs-filter-all").click(function() {
+ $("#jfmfs-filter-all").click(function(event) {
+ event.preventDefault();
all_friends.removeClass("hide-non-selected");
$(".filter-link").removeClass("selected");
$(this).addClass("selected");

0 comments on commit a29214b

Please sign in to comment.