<?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>maSnun&#039;s logs &#187; javascript</title>
	<atom:link href="http://masnun.com/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://masnun.com/blog</link>
	<description>Personal Blog of maSnun</description>
	<lastBuildDate>Sat, 24 Jul 2010 04:33:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Working with the Google Chart (Visualization) JavaScript APIs</title>
		<link>http://masnun.com/blog/2010/05/01/working-with-the-google-chart-visualization-javascript-apis/</link>
		<comments>http://masnun.com/blog/2010/05/01/working-with-the-google-chart-visualization-javascript-apis/#comments</comments>
		<pubDate>Sat, 01 May 2010 16:02:42 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=933</guid>
		<description><![CDATA[For a current project at my workplace I need a good charting solution. I need a pie chart for now, on which people can actually click and interact. I found a few tools and went for the Google Visualization APIs. &#8230; <a href="http://masnun.com/blog/2010/05/01/working-with-the-google-chart-visualization-javascript-apis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a current project at my workplace I need a good charting solution. I need a pie chart for now, on which people can actually click and interact. I found a few tools and went for the Google Visualization APIs. The APIs are a set of JS libraries which let you build quick charts and graphics out of data tables. I started trying the sample codes on the Google Ajax playground and quickly understood which way to go to get things right. First I must make it clear that, I&#8217;m no Javascript pro. I have coded with jQuery a few times before and I have no real experience with JS until today. It is just today I spent a good amount of time with the Facebook JS APIs. Who knows if it&#8217;s the brilliant documentation at the Google Code or my fast learning ability, it took me just one hour to learn the Visualization APIs and cook something up from scratch.</p>
<p>Here&#8217;s the source code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">google.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visualization&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;packages&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;piechart&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
google.<span style="color: #660066;">setOnLoadCallback</span><span style="color: #009900;">&#40;</span>drawChart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> drawChart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	table <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">DataTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;string&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;Languages&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;Hours worked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">addRows</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;PHP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;Python&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;JS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	targetDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'chart'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	chart <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">PieChart</span><span style="color: #009900;">&#40;</span>targetDiv<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	chart.<span style="color: #660066;">draw</span><span style="color: #009900;">&#40;</span>table<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>width<span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">240</span><span style="color: #339933;">,</span> is3D<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Languges Worked With (in hours)'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">events</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>chart<span style="color: #339933;">,</span> <span style="color: #3366CC;">'select'</span><span style="color: #339933;">,</span> selectionHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> selectionHandler<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			selectedData <span style="color: #339933;">=</span> chart.<span style="color: #660066;">getSelection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			row <span style="color: #339933;">=</span> selectedData<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">row</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> table.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span>row<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			time <span style="color: #339933;">=</span> table.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span>row<span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			resultDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'res'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			resultDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Selected Language: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; / Working Hours: &quot;</span> <span style="color: #339933;">+</span> time <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It&#8217;s very simple and easy. First we include the root javascript from: http://google.com/jsapi and then put the above codes in a script tag inside head.</p>
<p>We use the google loader to load the visualization package and then use it to build a PieChart. When the loading is done, the setOnLoadCallback() method invokes another function to proceed with further execution. We packed our main code inside a drawChart() function and set it as the callback.</p>
<p>To assemble the data, we first need a DataTable. A data table is an object with virtual columns and rows. First, we need to define the columns. We do that by calling the addColumn() method. The first parameter is the data type and the second one is the name. In our example, we added two columns.</p>
<p>Next, we call the addRows() passing an integer as the only parameter. This method creates &#8220;filler&#8221; or empty sets for putting data into.</p>
<p>Then, we use the setValue() call to insert/update data. The first parameter is the row number counted from 0. The second one is the index of column. Remember the sequence of the column definitions? Yes, follow that sequence. The first column is the index 0. The 3rd parameter is the actual value for that row and column.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">table.<span style="color: #660066;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;meaow&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>The above call will insert the string &#8220;meaow&#8221; into the second column of the 3rd row. It&#8217;s easy! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
PS: Please be aware of the data type of the column while inserting/updating data.</p>
<p>Now that we have a DataTable at our disposal, all we need to do is feed this data to a PieChart and draw it up. First, we created a new div with the id &#8220;chart&#8221;. This div will be holding the chart. Then we call the PieChart constructor with this div element. Then we call the draw() method of the chart object to paint it on the screen. The first parameter is the datatable and the second one is an object (dictionary/associative array like) defining the look and feel of the charts.</p>
<p>That draws the chart alright. But I need to let the users interact with the chart. So, I added a Listener to listen to any &#8220;select&#8221; events and call the handler function back. We get a event object but for select events, they don&#8217;t have any properties. That is they don&#8217;t tell you what the user clicked. You have to get the data by calling the getSelection() method of the chart. The returned object will have &#8220;row&#8221; and &#8220;column&#8221; values. For PieChart, alone the row value does the job. We get the row index. Then call the getValue() method of the data table to get the value of a certain column in a row. In this case, I just iterated over both columns. Built a text string out of the data and dynamically updated a div with that! </p>
<p>It&#8217;s pretty simple. It&#8217;s powerful and user friendly as well.</p>
<p>PS: I really liked the Google Ajax Playground. I am gonna play a lot in there from now on <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I just realized I&#8217;m becoming a good coder as well. I wrote the above codes without any pretty printer or code formatter. It looks well indented to me <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/05/01/working-with-the-google-chart-visualization-javascript-apis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using The Facebook Graph API with js-sdk : An explanatory Tutorial</title>
		<link>http://masnun.com/blog/2010/05/01/using-the-facebook-graph-api-with-js-sdk-an-explanatory-tutorial/</link>
		<comments>http://masnun.com/blog/2010/05/01/using-the-facebook-graph-api-with-js-sdk-an-explanatory-tutorial/#comments</comments>
		<pubDate>Sat, 01 May 2010 11:06:52 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=916</guid>
		<description><![CDATA[The facebook Graph API has a nice Javascript SDK to build applications using JS. The most important benefit is that with JS you could tightly integrate the Facebook Graph API with your web application. Integration is quite easy. First we &#8230; <a href="http://masnun.com/blog/2010/05/01/using-the-facebook-graph-api-with-js-sdk-an-explanatory-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The facebook Graph API has a nice Javascript SDK to build applications using JS. The most important benefit is that with JS you could tightly integrate the Facebook Graph API with your web application.</p>
<p>Integration is quite easy. First we add a fbAsyncInit object to the window object for asynchronous initiating. The following code snippet was borrowed from the official docs and then slightly modified:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
            window.<span style="color: #660066;">fbAsyncInit</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                FB.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>appId<span style="color: #339933;">:</span> appId<span style="color: #339933;">,</span> <span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> cookie<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> xfbml<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009966; font-style: italic;">/* All the events registered */</span>
                FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'auth.login'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #006600; font-style: italic;">// do something with response</span>
                    login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'auth.logout'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #006600; font-style: italic;">// do something with response</span>
                    logout<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                FB.<span style="color: #660066;">getLoginStatus</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">session</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #006600; font-style: italic;">// logged in and connected user, someone you know</span>
                        login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                e.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
                e.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">protocol</span> <span style="color: #339933;">+</span>
                    <span style="color: #3366CC;">'//connect.facebook.net/en_US/all.js'</span><span style="color: #339933;">;</span>
                e.<span style="color: #660066;">async</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fb-root'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #003366; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>
&nbsp;
           <span style="color: #003366; font-weight: bold;">function</span> logout<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'logout'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Thanks to the elegance of Javascript, we called the newly constructed object immediately after initiating, with a callback that loaded the JS sdk on our page. We registered the auth.login, auth.logout events and for initially looking for any logged in user, we made the getLoginStatus()  call. In fact this code snippet initiates the facebook access on the page. Registering the events to our custom functions, we just made sure that, we know when something important happens. While iniating, if the user is already logged in, the login() function gets called  because of the getLoginStatus() call. Later, after initiating, if the user logs in or logs out, the auth.login and auth.logout events get fired. Our registered handlers will be called in those cases.</p>
<p>To make things easy for the end user, you can use a fb:login-button tag from FBML. I believe Facebook app developers are already aware of that. Still, I was just reminding that you can still use those tags <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  A login button is going to help you. Because, it&#8217;s mandatory that you call the FB.login() on an user event (like button click) because most browsers won&#8217;t allow opening a popup on a non-user event.</p>
<p>Now the user is logged in and authorized the apps, you can start customizing your contents for the user. You can always check for available users by calling the FB.getSession() function. It returns null if no user is available, otherwise, it returns a session object with access_token, app key and secret and most importantly the user uid.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">session <span style="color: #339933;">=</span> FB.<span style="color: #660066;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>session.<span style="color: #660066;">uid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'no user logged in'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can use the dir() function on the session object to explore it on the Firebug console. </p>
<p>Now, you can make calls to the Graph API using the normal path pattern:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">FB.<span style="color: #660066;">api</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/me/photos&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">link</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The above code will alert() the user&#8217;s latest photo URI. Well, make sure that the applicaton has permissions to make the calls.</p>
<p>You can even mix up with the legacy API by passing an object with a &#8220;method&#8221; parameter pointing to the method name and related args. You can build the Facbook UIs using the FB.ui() call. Have a look how we use legacy API and UI to build a nifty sharing dialog box.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> share <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
   method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'stream.share'</span><span style="color: #339933;">,</span>
   u<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://masnun.com/'</span>
 <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
 FB.<span style="color: #660066;">ui</span><span style="color: #009900;">&#40;</span>share<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here, instead of alert()ing the response, we logged it to the console <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>In this way, you can interact with the user the way you want. It&#8217;s plain and simple. So, start digging now and have fun.</p>
<p>The Offcial js-sdk docs can be found here: <a href="http://developers.facebook.com/docs/reference/javascript/">http://developers.facebook.com/docs/reference/javascript/</a></p>
<p>Happy developing! Happy Facebooking! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/05/01/using-the-facebook-graph-api-with-js-sdk-an-explanatory-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JSDB: A JavaScript Interpreter</title>
		<link>http://masnun.com/blog/2009/12/05/jsdb-a-javascript-interpreter/</link>
		<comments>http://masnun.com/blog/2009/12/05/jsdb-a-javascript-interpreter/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 11:23:51 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=738</guid>
		<description><![CDATA[Recently I have taken keen interest in JavaScript, mainly because to handle jQuery better. I have always found JS very cool but never had the time to dig deeper into the language. In this EID vacation at KU, I had &#8230; <a href="http://masnun.com/blog/2009/12/05/jsdb-a-javascript-interpreter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I have taken keen interest in JavaScript, mainly because to handle jQuery better. I have always found JS very cool but never had the time to dig deeper into the language. In this EID vacation at KU, I had plenty of leisure times even after my tasks at Leevio and the free lance jobs. I started passing time with JS and found something really cool that I didn&#8217;t know so far.</p>
<p>JavaScript is a programming language. Yeah, just like the interpreted languages like Python, PHP and Ruby, JS is another good old programming language. My ignorance, I never knew this! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  I have always thought that JavaScript is merely a client side scripting language that works with web browsers only <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>My perceptions started changing few months ago when I saw some server side applications of JavaScript coding. Lately, a few days back I saw the node.js projects which is quite similar to the Twisted project implemented in Python. I started wondering how JS is being interpreted on the server side. Google answered me <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  There are JavaScript interpreters for even shell scripting <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I first tried the interpreters from Mozilla but unfortunately couldn&#8217;t make them work on my machine. So, I switched to JSDB <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  The interpreter is available free for download at: <a href="http://www.jsdb.org/">http://www.jsdb.org/</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>They say on their homepage:</p>
<blockquote><p>JSDB is JavaScript for databases, a scripting language for data-driven, network-centric programming on Windows, Mac, Linux, and SunOS. JSDB works with databases, XML, the web, and email. It is free and open-source. Use it as a JavaScript shell, to run CGI programs, or as a web server. </p></blockquote>
<p>Yeah, I indeed use it as a JavaScript Shell <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Here is the <a href="http://www.jsdb.org/reference.html">Documentation</a> of what JSDB has inside. I have made a PDF print out of the page for offline reading!</p>
<p>I really find the tool interesting because I am writing small throw away programs those are not really that much useful but the development curve is contributing to my JS skills <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/12/05/jsdb-a-javascript-interpreter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Updated AIR APP</title>
		<link>http://masnun.com/blog/2009/11/30/updated-air-app/</link>
		<comments>http://masnun.com/blog/2009/11/30/updated-air-app/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 15:02:06 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://masnun.com/2009/11/30/updated-air-app/</guid>
		<description><![CDATA[I have updated the AIR app with a better GUI and advanced features. Download App: http://masnun.googlecode.com/files/maSnun-AIR.air Download Source: http://masnun.googlecode.com/files/maSnun_AIR_Source.zip I have added a few more JavaScript files for better interactions]]></description>
			<content:encoded><![CDATA[<p>I have updated the AIR app with a better GUI and advanced features.</p>
<p><b>Download App: </b> <a href="http://masnun.googlecode.com/files/maSnun-AIR.air">http://masnun.googlecode.com/files/maSnun-AIR.air</a><br/><br />
<b>Download Source:</b> <a href="http://masnun.googlecode.com/files/maSnun_AIR_Source.zip">http://masnun.googlecode.com/files/maSnun_AIR_Source.zip</a><br/><br/></p>
<p>I have added a few more JavaScript files for better interactions <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/11/30/updated-air-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First AIR App</title>
		<link>http://masnun.com/blog/2009/11/30/my-first-air-app/</link>
		<comments>http://masnun.com/blog/2009/11/30/my-first-air-app/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 11:25:53 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=728</guid>
		<description><![CDATA[I have been looking forward to trying the Adobe AIR platform for desktop GUI development for a long time. Recently I started learning more on JavaScript, jQuery and CSS. So I decided to try out the AIR SDK for javascript &#8230; <a href="http://masnun.com/blog/2009/11/30/my-first-air-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been looking forward to trying the Adobe AIR platform for desktop GUI development for a long time. Recently I started learning more on JavaScript, jQuery and CSS. So I decided to try out the AIR SDK for javascript engineers. I must agree that AIR is simply great. The platform is strong and powerful while the development curve is very low <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I read just one article and it helped understand the basics. Later I had some issues regarding the packaging system but managed to hack through <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>First, I downloaded the Adobe AIR runtime and Adobe AIR SDK for Linux since I am on Ubuntu 9.04. I installed the runtime environment for testing the final product. The SDK has built in tools for testing and debugging the apps. I extracted the SDK into my home folder and then added the &#8220;bin&#8221; directory of the SDK to the system path by editing the &#8220;/etc/environment&#8221; file.</p>
<p>I then created a directory for the air application named &#8220;myair&#8221;. Inside that directory, I created an application descriptor named &#8220;myair.xml&#8221;. Here&#8217;s the source code for the file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/application/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.example.masnun-air<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maSnun-AIR<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>300<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>600<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;icon<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image16x16<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>icons/AIRApp_16.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/image16x16<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image32x32<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>icons/AIRApp_32.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/image32x32<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image48x48<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>icons/AIRApp_48.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/image48x48<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image128x128<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>icons/AIRApp_128.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/image128x128<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/icon<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This descriptor file holds all the basic information regarding the application. I created three more directories under the application directory:</p>
<p>&#8211; icons: for the icons described in the descriptor<br />
&#8211; js: for the javascript files (mainly jQuery)<br />
&#8211; build: for building the final product (packaging)</p>
<p>Then I went on building the initial and only view of the application. It&#8217;s nothing but a very simple html file. Here&#8217;s the source of the &#8220;index.html&#8221; file:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--
Author: maSnun
URL: http://masnun.com
Email: masnun@gmail.com
--&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;maSnun's AIR Demo&lt;/title&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
        &lt;script type=&quot;text/JavaScript&quot;
        src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/JavaScript&quot;&gt;
            $(document).ready(function() { masnun(); });
&nbsp;
            function masnun() {
&nbsp;
                i = 0;
                $(&quot;p&quot;).prepend(&quot;&amp;#187;&quot;)
                total = $(&quot;p&quot;).length - 1;
                $(&quot;#hide&quot;).click(function (e) {
                    if(i &gt; total) {
                        alert(&quot;No more paragraphs to hide!&quot;);
                        e.preventDefault();
                    } else {
                        e.preventDefault();
                        $(&quot;p:eq(&quot;+i+&quot;)&quot;).hide(&quot;slow&quot;);
                        i = i + 1;
                    }
                });
&nbsp;
&nbsp;
                $(&quot;#show&quot;).click(function (e) {
                    e.preventDefault();
                    $(&quot;p&quot;).show(&quot;slow&quot;);
                    i = 0;
                });
&nbsp;
&nbsp;
                $(&quot;p&quot;).hover(function () {
                    $(this).addClass(&quot;hover&quot;);
                }, function () {
                    $(this).removeClass(&quot;hover&quot;);
                });
&nbsp;
                $(&quot;p&quot;).click(function() {
                    alert(&quot;You clicked a menu item :D&quot;);
                });
&nbsp;
&nbsp;
            }
        &lt;/script&gt;
        &lt;style type=&quot;text/css&quot;&gt;
            body { font-size:18px; background:black; color:white;  border: dashed 3px fuchsia;
            margin:5pt;}
            p { color:red; margin:5px; cursor:pointer; }
            p.hover { background: blue; color: white; }
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body &gt;
        &lt;div style=&quot;margin: 10pt; color:lime;&quot;&gt;
        &lt;font size=&quot;2&quot;&gt; Welcome to the demo AIR app! Clicking the &quot;Hide&quot; option
        hides the menu items one by one. Clicking the &quot;Reset&quot; option brings
        all the hidden items back. Clicking a menu item shows a dialog box :D&lt;/font&gt;
            &lt;/div&gt;
        &lt;div align=&quot;center&quot;  &gt;
            &lt;a href=&quot;&quot; id=&quot;hide&quot; style=&quot;color:orange;&quot;&gt;Hide&lt;/a&gt; || &lt;a href=&quot;&quot; id=&quot;show&quot; style=&quot;color:orange;&quot;&gt;Reset&lt;/a&gt;  &lt;br/&gt;&lt;br/&gt;
        &lt;/div&gt;
        &lt;div align=&quot;left&quot; style=&quot;color:white;&quot;&gt;
            &lt;p&gt; Menu Item 1&lt;/p&gt;
            &lt;p&gt; Menu Item 2&lt;/p&gt;
            &lt;p&gt; Menu Item 3&lt;/p&gt;
            &lt;p&gt; Menu Item 4&lt;/p&gt;
            &lt;p&gt; Menu Item 5&lt;/p&gt;
            &lt;p&gt; Menu Item 6&lt;/p&gt;
            &lt;p&gt; Menu Item 7&lt;/p&gt;
            &lt;p&gt; Menu Item 8&lt;/p&gt;
            &lt;p&gt; Menu Item 9&lt;/p&gt;
        &lt;/div&gt;
&nbsp;
        &lt;div style=&quot;margin: 10pt; color:yellow;&quot;&gt;
        &lt;font size=&quot;2&quot;&gt; &lt;b&gt;Created by:&lt;/b&gt; maSnun&lt;/font&gt;
            &lt;/div&gt;
&nbsp;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>If you are familiar with HTML, CSS and jQuery, the code will be self explanatory for you.</p>
<p>Thats completes the development cycle. I tested the application by typing the following commands on my terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> myair
adl myair.xml</pre></div></div>

<p>And it worked! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Now for packaging, I first created a selfsigned certificate:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adt <span style="color: #660033;">-certificate</span> <span style="color: #660033;">-cn</span> SelfSign <span style="color: #660033;">-ou</span> Dev <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;Example&quot;</span> <span style="color: #660033;">-c</span> US <span style="color: #000000;">2048</span>-RSA cert.px masnun</pre></div></div>

<p>Then packaged the application using the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adt <span style="color: #660033;">-package</span> <span style="color: #660033;">-storetype</span> pkcs12 <span style="color: #660033;">-keystore</span> cert.pfx build<span style="color: #000000; font-weight: bold;">/</span>maSnun-AIR.air myair.xml index.html icons<span style="color: #000000; font-weight: bold;">/*</span>.png js<span style="color: #000000; font-weight: bold;">/*</span>.<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>It packaged the application and created an air archive for me. I tested it and it installed, worked and uninstalled fine on my machine.</p>
<p><b>Download the App: </b> <a href="http://masnun.googlecode.com/files/maSnun-AIR.air">http://masnun.googlecode.com/files/maSnun-AIR.air</a></p>
<p>Have fun! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/11/30/my-first-air-app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery with PHP</title>
		<link>http://masnun.com/blog/2009/11/29/jquery-with-php/</link>
		<comments>http://masnun.com/blog/2009/11/29/jquery-with-php/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 17:34:28 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=724</guid>
		<description><![CDATA[I am learning jQuery these days and here&#8217;s the source code of a php script that uses jQuery on the client side. I have mainly demonstrated jQuery here. PHP has been used to manipulate desired number of paragraphs quickly You &#8230; <a href="http://masnun.com/blog/2009/11/29/jquery-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am learning jQuery these days and here&#8217;s the source code of a php script that uses jQuery on the client side.</p>
<p>I have mainly demonstrated jQuery here. PHP has been used to manipulate desired number of paragraphs quickly <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>You get a number of paragraphs. Hovering over them changes their style. Clicking the &#8220;Hide&#8221; link hides the paragraphs one by one. <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;jQuery with PHP&lt;/title&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
        &lt;script type=&quot;text/JavaScript&quot;
        src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/JavaScript&quot;&gt;
            $(document).ready(function() { masnun(); });
&nbsp;
            function masnun() {
&nbsp;
                i = 0;
                total = $(&quot;p&quot;).length - 1;
                $(&quot;a&quot;).click(function (e) {
                    if(i &gt; total) {
                        alert(&quot;No more paragraphs to hide!&quot;);
                        e.preventDefault();
                    } else {
                        e.preventDefault();
                        $(&quot;p:eq(&quot;+i+&quot;)&quot;).hide(&quot;slow&quot;);
                        i = i + 1;
                    }
                });
                $(&quot;p&quot;).hover(function () {
                    $(this).addClass(&quot;hover&quot;);
                }, function () {
                    $(this).removeClass(&quot;hover&quot;);
                });
&nbsp;
&nbsp;
            }
        &lt;/script&gt;
        &lt;style&gt;
            p { color:black; margin:5px; cursor:pointer; }
            p.hover { background:black; color: white; }
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
&nbsp;
        &lt;a href=&quot;&quot;&gt;Hide&lt;/a&gt; &lt;br/&gt;&lt;br/&gt;
&nbsp;
&nbsp;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt; Paragraph number: <span style="color: #006699; font-weight: bold;">{$i}</span> &lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/11/29/jquery-with-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>My Free Lancing Experience &#8211; 2</title>
		<link>http://masnun.com/blog/2009/08/26/my-free-lancing-experience-2/</link>
		<comments>http://masnun.com/blog/2009/08/26/my-free-lancing-experience-2/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 17:40:21 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[free lancing]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=429</guid>
		<description><![CDATA[Here I come up with the second post of the series and my recent free lance programming experience. This project was also from Eric Willis who happily chose me for another of his projects. This time I developed http://crowdminz.com . &#8230; <a href="http://masnun.com/blog/2009/08/26/my-free-lancing-experience-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here I come up with the second post of the series and my recent free lance programming experience.</p>
<p>This project was also from Eric Willis who happily chose me for another of his projects. This time I developed <a href="http://crowdminz.com">http://crowdminz.com</a> . It&#8217;a a live web crawler that crawls the www in real time.</p>
<p>As you will notice, the first page has the &#8220;web&#8221; category pre-selected. And there are three columns showing results from &#8212; twitter, digg and friendfeed. You might be surprised to know that search box uses no forms. It just happened that I coded the php portion while the site layout was coded by a third party coder. When I tried to put a form into the right place, the page broke. I then put a single input box and used javascript to make it behave like a html form. When you click the search button, the value of the search box is collected by javascript and the window.location.href is assigned a new value that necessarily contains a new URI with query string. To make it behave like a real form, I had to filter key presses and make sure that the search is performed even when the user pressed the Enter button after typing something in the box.</p>
<p>I used the twitter, digg and friendfeed RSS search results to gather data from them. I used SimpleXML with php to parse the data and form the results. For video, I had to use Youtube and Flickr for image results.</p>
<p>It was a $50 project and I completed it in almost 6 working hours. I took time to dig into the HTML layouts where I lost track every now and then. Finally it was done and I did enjoy coding the javascript portion.</p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2009/08/26/my-free-lancing-experience-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
