<?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>redirect_to :hack &#187; Javascript</title>
	<atom:link href="http://blog.coderubik.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.coderubik.com</link>
	<description>Thoughts on Ruby on Rails and Web development</description>
	<lastBuildDate>Thu, 25 Mar 2010 17:19:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Javascript inside a Facebook profile tab</title>
		<link>http://blog.coderubik.com/2010/03/javascript-inside-a-facebook-profile-tab/</link>
		<comments>http://blog.coderubik.com/2010/03/javascript-inside-a-facebook-profile-tab/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 17:06:38 +0000</pubDate>
		<dc:creator>Pierre Olivier Martel</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://modelix.net/?p=158</guid>
		<description><![CDATA[Developing a Facebook application that runs in a profile tab can be a real pain in the neck. As stated on the Facebook developer wiki, one of the many constrains developing a Facebook tab forbids the use of external javascript files. This means you have to inline your javascript in a script tag in order [...]]]></description>
			<content:encoded><![CDATA[<p>Developing a Facebook application that runs in a profile tab can be a real pain in the neck. As stated on the <a href="http://wiki.developers.facebook.com/index.php/Tabbed_Profile">Facebook developer wiki</a>, one of the many constrains developing a Facebook tab forbids the use of external javascript files. This means you have to inline your javascript in a <code>script</code> tag in order to be processed by the Facebook <span class="caps">FBML </span>parser.</p>

<p>This is a real problem if you have javascript files for your Facebook application and wish to keep your code <span class="caps">DRY.</span> Here is the solution I came up with using Ruby on Rails and Facebooker :</p>



<pre class="prettyprint rb"><code># ApplicationController.rb
helper_method :request_is_facebook_tab? # Make the facebooker method available in views and helpers

# Application.fbml.erb
&lt;%= render :partial =&gt; 'facebook/fb_js' %&gt;

# _fb_js.fbml.erb
&lt;% if request_is_facebook_tab? %&gt;
  &lt;%= javascript_tag output_js_files_content(&quot;Utility.js&quot;, &quot;FBjqRY.min.js&quot;, &quot;application-fb.js&quot;) %&gt;
&lt;% else %&gt;
  &lt;%= javascript_include_tag &quot;Utility.js&quot;, &quot;FBjqRY.min.js&quot;, &quot;application-fb.js&quot; %&gt;
&lt;% end %&gt;

# facebook_helper.rb
def output_js_files_content(*files)
    output = files.collect { |f| IO.read(File.join(RAILS_ROOT, 'public', 'javascripts', f)) }
    output.join(&quot;\n&quot;)
end
</code></pre>



<p>This code will detect wether or not the facebook application is running inside a profile tab. If so, instead of generating an external javascript tag, an helper method is called to dump all the content of javascript files inside a <code>script</code> tag.<br />
  <br />
This solution lets keep your javascript where it belongs (inside .js files) and keep your code <span class="caps">DRY </span>when dealing with profile tabs limitation.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.coderubik.com/2010/03/javascript-inside-a-facebook-profile-tab/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Alternate background colors with jQuery</title>
		<link>http://blog.coderubik.com/2008/09/alternate-background-colors-with-jquery/</link>
		<comments>http://blog.coderubik.com/2008/09/alternate-background-colors-with-jquery/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 04:09:00 +0000</pubDate>
		<dc:creator>Pierre Olivier Martel</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://modelix.net/?p=7</guid>
		<description><![CDATA[I did a little javascript function with jQuery this morning to alternate DOM elements background colors . The function takes in parameters an array of jQuery elements and an array of hexadecimal colors and changes the background color of each element with the next color in the array. // Alternates the background colors of the [...]]]></description>
			<content:encoded><![CDATA[<p>I did a little javascript function with jQuery this morning to alternate <span class="caps">DOM </span>elements background colors . The function takes in parameters an array of jQuery elements and an array of hexadecimal colors and changes the background color of each element with the next color in the array.<br /></p>

<pre class="prettyprint">// Alternates the background colors of the elements passed in parameters
// elems  - Array of jQuery DOM objects
// colors - Array of hexadecimal colors
function alternateBgColor(elems, colors) {
  elems.each( function(index){
    var colorIndex = index % colors.length;
    $(this).css('background-color', colors[colorIndex]);
  });
}</pre>

<p><br />It&#8217;s only a three lines function but the cool thing about it is that you can alternate through as many colors as you need. I&#8217;m only using two for now but this could come useful at some point! I like how everything javascript just got easier with jQuery.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.coderubik.com/2008/09/alternate-background-colors-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->