<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Facebook Cookbook &#187; facebook widget</title>
	<atom:link href="http://fbcookbook.ofhas.in/tag/facebook-widget/feed/" rel="self" type="application/rss+xml" />
	<link>http://fbcookbook.ofhas.in</link>
	<description>thousands of app development recipes</description>
	<lastBuildDate>Sun, 21 Mar 2010 10:38:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>friends selection custom component</title>
		<link>http://fbcookbook.ofhas.in/2009/02/06/friends-selection-custom-component/</link>
		<comments>http://fbcookbook.ofhas.in/2009/02/06/friends-selection-custom-component/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 10:10:41 +0000</pubDate>
		<dc:creator>Mahmud Ahsan</dc:creator>
				<category><![CDATA[FBML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[facebook widget]]></category>
		<category><![CDATA[friends selection custom component]]></category>

		<guid isPermaLink="false">http://fbcookbook.ofhas.in/?p=156</guid>
		<description><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
digg_url = 'http://fbcookbook.ofhas.in/2009/02/06/friends-selection-custom-component/';
digg_bgcolor = '#FFFFFF';
digg_skin = '';
digg_window = '';
digg_title = 'friends selection custom component';
digg_bodytext = '';
digg_media = 'news';
digg_topic = '';
//-->
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>
for 1 of my facebook application, i was  needed a custom friends selector. the purpose was, i&#8217;ve a page from where i&#8217;ve to select multiple friends and then i&#8217;ll submit those selected friend ids using ajax call without refreshing the page.
then i searched the documentation of fbml. in facebook component, there are 2 types of [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
digg_url = 'http://fbcookbook.ofhas.in/2009/02/06/friends-selection-custom-component/';
digg_bgcolor = '#FFFFFF';
digg_skin = '';
digg_window = '';
digg_title = 'friends selection custom component';
digg_bodytext = '';
digg_media = 'news';
digg_topic = '';
//-->
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>
<p>for 1 of my facebook application, i was  needed a custom friends selector. the purpose was, i&#8217;ve a page from where i&#8217;ve to select multiple friends and then i&#8217;ll submit those selected friend ids using ajax call without refreshing the page.</p>
<p>then i searched the documentation of fbml. in facebook component, there are 2 types of friends selector</p>
<ol>
<li><a href="http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector" target="_blank">http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector_(condensed)" target="_blank">http://wiki.developers.facebook.com/index.php/Fb:multi-friend-selector_(condensed)</a></li>
</ol>
<p><a href="http://mahmudahsan.files.wordpress.com/2008/12/face-1.png"><img class="aligncenter size-medium wp-image-298" title="face-1" src="http://mahmudahsan.files.wordpress.com/2008/12/face-1.png?w=300" alt="face-1" width="300" height="181" /></a><a href="http://mahmudahsan.files.wordpress.com/2008/12/face-2.png"><img class="aligncenter size-full wp-image-299" title="face-2" src="http://mahmudahsan.files.wordpress.com/2008/12/face-2.png" alt="face-2" width="234" height="157" /></a>but both of these are totally controlled by facebook and these components are used to send invitation or request to friends. i need a component like figure 2. the fbml code for the second component is below:</p>
<pre name="code" class="php">

&lt;fb:request-form method=”post” action=”http://yourdomain.com/submit.php” content=”Select Friends” type=”gifts” invite=”true”&gt;
&lt;div class=”clearfix” style=”padding-bottom: 10px;”&gt;
&lt;fb:multi-friend-selector condensed=”true” selected_rows=”0? style=”width: 220px;” /&gt;
&lt;/div&gt;
&lt;fb:request-form-submit /&gt;
&lt;/fb:request-form&gt;
</pre>
<p>but I was needed a component that would be fully controlled by me. so,  I developed a friends selection component and I&#8217;m sharing it. <img src='http://fbcookbook.ofhas.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-156"></span></p>
<p>here is the outlook of my component:</p>
<p><a href="http://mahmudahsan.files.wordpress.com/2008/12/custom-friends-selection-component.png"><img class="aligncenter size-full wp-image-302" title="custom-friends-selection-component" src="http://mahmudahsan.wordpress.com/files/2008/12/custom-friends-selection-component.png" alt="custom-friends-selection-component" width="281" height="248" /></a></p>
<p style="text-align:center;font-size:16px;font-family:arial;"><a href="http://ftechdb.com/mahmudahsan.wordpress.com/custom-friends-selector2.txt" target="_blank">download custom friends selector for facebook application</a></p>
<p style="text-align:left;">there are 3 parts in this code:</p>
<ol>
<li>first part is css</li>
<li>second part is javascript</li>
<li>third part is html + php</li>
</ol>
<p>so changed the file extension to .php</p>
<p>Here is the first part:</p>
<pre name="code" class="css">

&lt;style&gt;

div.scroll {
height: 160px;
width: 200px;
overflow: auto;
border: 1px solid #666;
padding: 8px;
}

#listwords{
border: 1px solid #BDBABD;
margin-top: 5px;
margin-left: 10px;
}

#listwords ul{
list-style: none;
margin-top: -3px;
cursor: pointer;
}

#listwords span{
color: olive;
text-decoration: none;
}

.itemselect{
background-color: #e2dfaf;
color: #650202;
}

.itemmouseover{
background-color: #FFEEBB;
color: BLACK;
}

.itemnormal{
color: BLACK;
font-family: arial;
font-size: 12px;
}
</pre>
<p>this is the css code for the outlook of my component. here in the top you&#8217;ll see a bold part. this is a very important code that creates scroll bar when list is overflow than it&#8217;s height.</p>
<p>now the second part and 3rd part:<br />
<code>
<pre name="code" class="javascript">

&lt;script type=”text/javascript”&gt;
//javascript part
/*————————- Friends selection —————–*/
var friendsSelectedIds =   ”; //this is string
//send this variable to php
&lt;/code&gt;&lt;/code&gt;

function toggleSelect(id){
var liBox   =   document.getElementById(’li’ + id);
var chkBox  =   document.getElementById(’chk’ + id);

liBox.toggleClassName(’itemselect’);
if (chkBox.getChecked()){
friendsSelectedIds  =   friendsSelectedIds.replace(id + ‘,’, ”);
chkBox.setChecked(false);
}
else{
chkBox.setChecked(true);
friendsSelectedIds += id + ‘,’;
}

return false;
}
/*============== END ====================*/

function sendFriendIds(){
if (friendsSelectedIds.length == 0){
new Dialog().showMessage(’Select friends’, ‘Please select friends!’);
return false;
}

//submit form using ajax call
var ajax                = new Ajax();
ajax.responseType       = Ajax.FBML;

ajax.ondone        = function(data){
//task u will do
}

ajax.onerror = function(){
new Dialog(Dialog.DIALOG_POP).showMessage(’Error’, ‘Loading error! Please try again!’, button_confirm = ‘Okay’);
}

var queryParams = {”ids” : friendsSelectedIds};
ajax.post(’http://yourdomain.com/submit.php’ , queryParams);

}
&lt;/script&gt;
</pre>
<pre name="code" class="php">

&lt;!– html Part –&gt;
&lt;form name=’ffriends’ method=”POST” action=”&quot; onsubmit=”return false”&gt;
&lt;div class=”scroll” id=”listwords”&gt;
&lt;?php $i=0; ?&gt;
&lt;ul style=’margin-left: -44px’&gt;
&lt;?php foreach($friends as $item){ ?&gt;
&lt;li id=”li&lt;?=$item[&#039;uid&#039;]?&gt;” class=’itemnormal’ onclick=”toggleSelect(&lt;?=$item[&#039;uid&#039;]?&gt;)”&gt;
&lt;input id=”chk&lt;?=$item[&#039;uid&#039;]?&gt;” type=”checkbox” /&gt; &lt;fb:name uid=”&lt;?=$item[&#039;uid&#039;]?&gt;” linked=”false” /&gt;
&lt;/li&gt;
&lt;?php } ?&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;input style=”margin-left: 10px;” class=”inputsubmit” type=”Submit” value=”Send Question” onclick=”sendFriendIds()” /&gt;
&lt;/form&gt;
</pre>
<p><span style="color:#800000;"><span style="color:#000000;">it's best that you download the code and read my description. in html part, you will see a foreach loop where friends is an array of the friends you have. i retrieve the friends using fql and assigned the result in <strong>$friends variable</strong>.  when a friend is selected, it's id is saved in </span></span><span style="color:#003366;">friendsSelectedIds variable <span style="color:#000000;">in javascript. (like </span></span><span style="color:#003366;">friendsSelectedIds=12393939,45454545, <span style="color:#000000;">)</span></span><span style="color:#800000;"> <span style="color:#000000;">a comma is added after id. </span></span></p>
<p><span style="color:#800000;"><span style="color:#000000;">when a friend is unselected its id and comma is removed from the variable. this variable is a string variable. after selecting one or more friends when user press the submit button </span></span><span style="color:#003366;"><strong>sendFriendIds() <span style="color:#000000;">method</span></strong></span><span style="color:#800000;"> <span style="color:#000000;">is called. in this method you've to redefine the ajax functionalities for your work. </span></span><span style="color:#800000;"><span style="color:#000000;">if no friend is selected a message is shown to the user.</span></span><span style="color:#800000;"><span style="color:#000000;"> remember </span></span><span style="color:#003366;"><strong>var queryParams = {"ids" : friendsSelectedIds}; <span style="color:#000000;">ids </span></strong><span style="color:#000000;">is the selected ids of friends and this will be catched from server side script. and <strong>ids </strong>containted comma separated id of friends. i think this is a very small lines of code and easily understandable for facebook application developer.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://fbcookbook.ofhas.in/2009/02/06/friends-selection-custom-component/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
