<?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>Fuel Your Coding &#187; Javascript</title>
	<atom:link href="http://fuelyourcoding.com/category/languages/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://fuelyourcoding.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Jan 2012 11:01:46 +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>10 Tools &amp; Frameworks for Responsive Design</title>
		<link>http://fuelyourcoding.com/10-tools-frameworks-for-responsive-design/</link>
		<comments>http://fuelyourcoding.com/10-tools-frameworks-for-responsive-design/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 00:33:03 +0000</pubDate>
		<dc:creator>Joel Falconer</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Languages]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=1448</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>Like webfonts, <a href="http://www.alistapart.com/articles/responsive-web-design/" target="_blank">responsive design</a> wasn’t something you heard much about until CSS3 specs started making it into popular browsers. Now, it’s the cool thing to do, and for good reason — it means one site to maintain for all devices. But it’s also a really challenging approach to web design. In this article, we look at 10 tools that’ll help you handle the challenge.</p>
<h2>320 and up</h2>
<p style="text-align: center; "><a href="http://www.stuffandnonsense.co.uk/projects/320andup/"><img class="size-full wp-image-1453 aligncenter" title="320andup" src="http://fuelyourcoding.com/files/320andup.jpg" alt="320andup" width="592" height="208" /></a></p>
<p>Most responsive designs are built with full desktop size in mind and scaled down from there. Andy and Keith Clark, the developers behind 320 and up, believe the opposite approach works best: design for the small screen, and implement the layout working upwards in size. <a href="http://www.stuffandnonsense.co.uk/projects/320andup/" target="_blank">320 and up</a> contains Media Query increments for five viewport sizes, a vertical grid, preset styles for typography and components from HTML5 Boilerplate.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">inuit.css</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">inuit.css is a HTML5 framework that uses a grid system that scales down to small screens ‘out of the box’. It’s a minimalist approach, giving you just what you need to get started without unnecessary styles, but it’s extensible and there are a range of handy plugins available for it — such as one that creates breadcrumb trails out of ordered lists.</div>
<h2>inuit.css</h2>
<p style="text-align: center; "><a href="http://csswizardry.com/inuitcss/"><img class="size-full wp-image-1456 aligncenter" title="inuitcss" src="http://fuelyourcoding.com/files/inuitcss.jpg" alt="inuitcss" width="592" height="300" /></a></p>
<p><a href="http://csswizardry.com/inuitcss/" target="_blank">inuit.css</a> is a HTML5 framework that uses a grid system that scales down to small screens ‘out of the box’. It’s a minimalist approach, giving you just what you need to get started without unnecessary styles, but it’s extensible and there are a range of handy plugins available for it — such as one that creates breadcrumb trails out of ordered lists.</p>
<h2>Skeleton</h2>
<p style="text-align: center; "><a href="http://getskeleton.com/"><img class="size-full wp-image-1457 aligncenter" title="skeleton" src="http://fuelyourcoding.com/files/skeleton.jpg" alt="skeleton" width="592" height="374" /></a></p>
<p><a href="http://getskeleton.com/" target="_blank">Skeleton</a> is a light collection of CSS and JavaScript files that make designing responsive sites based on the 960px grid easy. Skeleton includes some basic styling and typography presets to get you out of the gate quickly. This project is the brainchild of Dave Gamache, formerly of esteemed UX firm ZURB and now on Twitter’s design team.</p>
<h2>Less Framework</h2>
<p style="text-align: center; "><a href="http://lessframework.com/"><img class="size-full wp-image-1458 aligncenter" title="lessframework" src="http://fuelyourcoding.com/files/lessframework.jpg" alt="lessframework" width="592" height="351" /></a></p>
<p><a href="http://lessframework.com/" target="_blank">Less Framework</a> is a CSS starter with four layouts — default at 992px, and tablet, mobile and wide mobile sizes — based on a grid system and including a selection of typography presets. Because Less Framework is one of the most popular options, there’s a range of supporting tools such as a Rails gem, OmniGraffle stencil and Compass plugin built around Less.</p>
<h2>BluCSS</h2>
<p style="text-align: center; "><a href="http://www.designlunatic.com/projects/blucss/"><img class="size-full wp-image-1459 aligncenter" title="blucss" src="http://fuelyourcoding.com/files/blucss.jpg" alt="blucss" width="592" height="289" /></a></p>
<p><a href="http://www.designlunatic.com/projects/blucss/" target="_blank">BluCSS </a>is a CSS framework that, as usual, uses a flexible grid to facilitate responsive design. One feature that stands out is its responsive images, something many of these frameworks leave out; apply a class to your images and they’ll scale with your design. No need to include multiple files at multiple sizes, though be wary of unnecessary load on mobile devices with this approach.</p>
<h2>Mobile Boilerplate</h2>
<p style="text-align: center; "><a href="http://html5boilerplate.com/mobile"><img class="size-full wp-image-1460 aligncenter" title="mobileboilerplate" src="http://fuelyourcoding.com/files/mobileboilerplate.jpg" alt="mobileboilerplate" width="592" height="186" /></a></p>
<p>From the developers behind the famous HTML5 Boilerplate comes <a href="http://html5boilerplate.com/mobile" target="_blank">Mobile Boilerplate</a>, a responsive template that puts the focus on mobile devices, namely those running Android, iOS, Blackberry and Symbian software. Everything from viewport scaling to HTML5 offline caching to home screen icons are ready to go.</p>
<h2>Tiny Fluid Grid</h2>
<p style="text-align: center; "><a href="http://www.tinyfluidgrid.com/"><img class="size-full wp-image-1461 aligncenter" title="tinyfluidgrid" src="http://fuelyourcoding.com/files/tinyfluidgrid.jpg" alt="tinyfluidgrid" width="592" height="265" /></a></p>
<p>If you find all these CSS frameworks to be too much for your needs, <a href="http://www.tinyfluidgrid.com/" target="_blank">Tiny Fluid Grid</a> may be the alternative you’re looking for. Simply tell it how many columns your grid will need, how big you want your gutters and how wide the site will be, and this site will spit out a responsive fluid grid you can use right away.</p>
<h2>Golden Grid System</h2>
<p style="text-align: center; "><a href="http://goldengridsystem.com/"><img class="size-full wp-image-1462 aligncenter" title="goldengrid" src="http://fuelyourcoding.com/files/goldengrid.jpg" alt="goldengrid" width="592" height="217" /></a></p>
<p>The <a href="http://goldengridsystem.com/" target="_blank">Golden Grid System</a> is a 16 column grid that uses a folding method inspired by the DIN paper system to collapse down to 8 columns on tablet-size screens and 4 columns on mobile screens, making it work for designs that range from 240 to 2560 pixels wide. The GGS developers say their folding method is superior to others because the gutters are better at staying in proportion with the content, producing less of a squeezed (or sparse, depending on direction) look.</p>
<h2>1140 CSS Grid</h2>
<p style="text-align: center;"><a href="http://cssgrid.net/"><img class="size-full wp-image-1463 aligncenter" title="1140" src="http://fuelyourcoding.com/files/1140.jpg" alt="1140" width="592" height="247" /></a></p>
<p>The <a href="http://cssgrid.net/" target="_blank">1140 CSS Grid</a> takes the opposite approach of the 320 and up system. This is primarily aimed at people who really want to design for a wider 1280 pixel screen, and are sick of catering to a 1024 pixel baseline. 1140 CSS Grid allows them to do that while fluidly re-arranging to fit on smaller screens all the way down to mobile.</p>
<h2>Respond.js</h2>
<p>Even before you start working on a responsive design, you may be worried about visitors using browsers that don’t support media queries, the CSS3 feature that responsive sites depend on. With <a href="https://github.com/scottjehl/Respond" target="_blank">Respond.js</a>, this problem is easily solved; the script makes min-width and max-width work in Internet Explorer 6, 7 and 8, and should work with other browsers lacking support.</p>
<h2>Bonus: ZURB Foundation</h2>
<p><img class="aligncenter size-full wp-image-1472" title="foundation" src="http://fuelyourcoding.com/files/foundation.jpg" alt="foundation" width="592" height="412" /></p>
<p>ZURB&#8217;s <a href="http://foundation.zurb.com/">Foundation</a> is a newer entry among responsive design frameworks, and is one of the most promising, having already won over many users of other frameworks. Billed as an easy-to-use yet powerful framework for building both prototypes and production deployments that work across all kinds of devices, Foundation makes use of a flexible grid, a library of styles and elements for rapid prototyping, and professes to take the pain out of creating layouts for different formats with the same markup.</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/10-tools-frameworks-for-responsive-design/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Getting Started with jQuery Mobile &amp; Rails 3</title>
		<link>http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/</link>
		<comments>http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 13:06:15 +0000</pubDate>
		<dc:creator>Jerod Santo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery mobile]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=1341</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>

&#60;head&#62;
  &#60;title&#62;Jqmoblog&#60;/title&#62;
  &#60;link rel=&#34;stylesheet&#34; href=&#34;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&#34; /&#62;
  &#60;%= javascript_include_tag :defaults %&#62;
  &#60;script src=&#34;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&#34;&#62;&#60;/script&#62;
  &#60;%= csrf_meta_tag %&#62;
&#60;/head&#62;

Okay, everything is in place. Now we&#8217;re ready to turn this into a mobile app!
Getting Started
Before we flesh out our mobile CRUD actions, let&#8217;s get the posts index looking decent in mobile browsers. jQuery Mobile relies [...]]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>The very promising <a href="http://jquerymobile.com/">jQuery Mobile</a> project is now in its first Alpha release! What better time to give it a spin with our (err&#8230; my) <a href="http://rubyonrails.org">favorite web framework</a>?!</p>
<p>You should read jQuery Mobile&#8217;s <a href="http://jquerymobile.com/demos/1.0a1/#docs/about/intro.html">official introduction</a> section to familiarize yourself with its principles, but in a few words: you include it on the page, format your markup to conform to its requirements and reap the benefits. Yay, let&#8217;s write a (very contrived) <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> application with Rails 3 and jQuery Mobile!</p>
<h2>Setup</h2>
<p>Our application will allow us to create, read, update and delete blog posts (remember when I said it was contrived? Uhm..yah) from mobile devices. If you don&#8217;t have Rails 3 installed yet, you can get it via <a href="http://rubygems.org">RubyGems</a>:</p>
<pre class="brush: plain;">
gem install rails
</pre>
<p>Use the <tt>rails</tt> command line tool to generate a new application. We&#8217;ll call it <strong>jqmoblog</strong>.</p>
<pre class="brush: plain;">
rails new jqmoblog
# ... a bunch of files are created
cd jqmoblog
</pre>
<p>As of Rails 3.0.1 you cannot specify jQuery as the JavaScript tool of choice when you generate a Rails application, but we can easily swap it in by using the handy, dandy <a href="http://github.com/indirect/jquery-rails">jquery-rails</a> gem. Edit the <tt>Gemfile</tt> in the project&#8217;s root directory and add a dependency on the gem. Once finished your <tt>Gemfile</tt> will look something like this:</p>
<pre class="brush: ruby;">
source 'http://rubygems.org'

gem 'rails', '3.0.1'
gem 'sqlite3-ruby', :require =&gt; 'sqlite3'
gem 'jquery-rails'
</pre>
<p>Install the required gems using the <tt>bundle</tt> command line tool:</p>
<pre class="brush: plain;">
bundle install
</pre>
<p>Now we&#8217;ll use the Rails generator added by the <tt>jquery-rails</tt> gem to get all the jQuery files we need:</p>
<pre class="brush: plain;">
rails generate jquery:install
</pre>
<p>When prompted, allow it to overwrite <tt>rails.js</tt>.</p>
<p>We&#8217;re almost ready. The application skeleton is in place and jQuery has replaced the Rails default JavaScript libraries, but we&#8217;re missing the basic model, controller, and views for our application.</p>
<p>Thankfully, Rails has a generator which will create these files for us and its called the <tt>scaffold</tt> generator. We&#8217;ll keep the blog posts in our app super-simple since we&#8217;re really just using them to learn about jQuery Mobile. Each post will have a title and a body. Generate the scaffold for a Post resource like this:</p>
<pre class="brush: plain;">
rails generate scaffold Post title:string body:text
</pre>
<p>This command will provide a list of files and directories it created. There should be a model (<tt>app/models/post.rb</tt>), a controller (<tt>app/controller/posts_controller.rb</tt>), and a directory of views (<tt>app/views/posts</tt>) for our Post resource.</p>
<p>Run the database migration that was created from the <tt>scaffold</tt> command so our database has a <tt>posts</tt> table with the required columns for storing our posts:</p>
<pre class="brush: plain;">
rake db:migrate
</pre>
<p>At this point you can fire up a Rails server and the app will load up in your browser:</p>
<pre class="brush: plain;">
rails server
</pre>
<p>Point your browser to <tt>http://localhost:3000</tt> and you should see this:</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/default.png" alt="default" title="default" width="549" height="518" class="aligncenter size-full wp-image-1363" /></p>
<p>Hmm, before we get to mobilizing this application, let&#8217;s make the root url load the list of our posts instead of the default Rails index file:</p>
<pre class="brush: plain;">
rm public/index.html
</pre>
<p>Edit the <tt>config/routes.rb</tt> and set the root route like so:</p>
<pre class="brush: ruby;">
Jqmoblog::Application.routes.draw do
  resources :posts
  root :to =&gt; &quot;posts#index&quot;
end
</pre>
<p>Now load up <tt>http://localhost:3000</tt> again and you should see the empty list of posts.</p>
<p>We still need to get the jQuery Mobile files on the page. Lets use the ones hosted on <a href="http://jquery.com">jquery.com</a>. Add them to the application&#8217;s <tt>layout</tt> file so they&#8217;ll be on every page that gets served. In <tt>app/views/layouts/application.html.erb</tt>, edit the <tt>head</tt> section to look like this:</p>
<pre class="brush: xml;">
&lt;head&gt;
  &lt;title&gt;Jqmoblog&lt;/title&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&quot; /&gt;
  &lt;%= javascript_include_tag :defaults %&gt;
  &lt;script src=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&quot;&gt;&lt;/script&gt;
  &lt;%= csrf_meta_tag %&gt;
&lt;/head&gt;
</pre>
<p>Okay, everything is in place. <em>Now</em> we&#8217;re ready to turn this into a mobile app!</p>
<h2>Getting Started</h2>
<p>Before we flesh out our mobile CRUD actions, let&#8217;s get the posts index looking decent in mobile browsers. jQuery Mobile relies directly on the page&#8217;s markup to work its magic, so to invoke it we just need to change our views to conform to its conventions.</p>
<p>Each &#8220;page&#8221; in a jQuery Mobile application needs to be wrapped in a <tt>div</tt> with a <tt>data-role</tt> attribute of <tt>page</tt>. I put &#8220;page&#8221; in quotes because there can actually be many of them on a single webpage loaded from the server. In our app we&#8217;ll be loading each &#8220;page&#8221; from Rails, so we should just add this to our layout file which will wrap each of our individual views:</p>
<p><strong>Before</strong></p>
<pre class="brush: xml;">
&lt;body&gt;
  &lt;%= yield %&gt;
&lt;/body&gt;
</pre>
<p><strong>After</strong></p>
<pre class="brush: xml;">
&lt;body&gt;
  &lt;div data-role=&quot;page&quot;&gt;
    &lt;%= yield %&gt;
  &lt;/div&gt;
&lt;/body&gt;
</pre>
<p>Next edit the post&#8217;s index (<tt>index.html.erb</tt>) and change the markup to create a header and a content section which lists all the posts in the database.</p>
<p><strong>Before</strong></p>
<pre class="brush: xml;">
&lt;h1&gt;Listing posts&lt;/h1&gt;

&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Title&lt;/th&gt;
    &lt;th&gt;Body&lt;/th&gt;
    &lt;th&gt;&lt;/th&gt;
    &lt;th&gt;&lt;/th&gt;
    &lt;th&gt;&lt;/th&gt;
  &lt;/tr&gt;

&lt;% @posts.each do |post| %&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;%= post.title %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= post.body %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Show', post %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Edit', edit_post_path(post) %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Destroy', post, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;% end %&gt;
&lt;/table&gt;

&lt;br /&gt;

&lt;%= link_to 'New Post', new_post_path %&gt;
</pre>
<p><strong>After</strong></p>
<pre class="brush: xml;">
&lt;div data-role=&quot;header&quot;&gt;
  &lt;h1&gt;Listing posts&lt;/h1&gt;
&lt;/div&gt;

&lt;div data-role=&quot;content&quot;&gt;
  &lt;ul data-role=&quot;listview&quot;&gt;
    &lt;% @posts.each do |post| %&gt;
    &lt;li&gt;
      &lt;%= link_to post.title, post %&gt;
      &lt;%= link_to 'edit post', edit_post_path(post), &quot;data-icon&quot; =&gt; &quot;gear&quot; %&gt;
    &lt;/li&gt;
    &lt;% end %&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>Load up the page and it should look like this:</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/base.png" alt="base" title="base" width="472" height="615" class="aligncenter size-full wp-image-1365" /></p>
<p>Two things to note here. First, we are once again using the <tt>data-role</tt> attribute to create the header and the styled list. This is a major theme of jQuery Mobile (as of the Alpha, I&#8217;m told they <em>*might*</em> be switching to class names instead of data- attributes). Second, each list item has two links, and jQuery Mobile automatically knows that this means we want to use a <a href="http://jquerymobile.com/demos/1.0a1/#docs/lists/lists-split.html">split button list</a>. Pretty cool, huh?</p>
<p>Let&#8217;s add a button which will take us to a page where we can create new posts. Add this line to the end of the header <tt>div</tt>:</p>
<pre class="brush: xml;">
&lt;%= link_to 'Add', new_post_path, &quot;data-icon&quot; =&gt; &quot;plus&quot;, &quot;class&quot; =&gt; &quot;ui-btn-right&quot; %&gt;
</pre>
<p>Again, jQuery Mobile &#8220;just knows&#8221; that this should be a button in our header and we pass it a class and a <tt>data-icon</tt> attribute to tell it where to place it and which icon to use. We now have a button in the header which links to the new post path!</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/base-add.png" alt="base-add" title="base-add" width="472" height="615" class="aligncenter size-full wp-image-1366" /></p>
<h2>Create</h2>
<p>We&#8217;re gonna need to create posts so we can read, update and delete them, so lets handle creation first. The &#8220;Add&#8221; button on the posts index links to the <tt>new.html.erb</tt> view. It works as is and looks okay too. We&#8217;ll just tweak the markup to make it fit into the jQuery Mobile styles:</p>
<pre class="brush: xml;">
&lt;div data-role=&quot;header&quot;&gt;
  &lt;h1&gt;New Post&lt;/h1&gt;
&lt;/div&gt;

&lt;div data-role=&quot;content&quot;&gt;
  &lt;%= render 'form' %&gt;
&lt;/div&gt;
</pre>
<p>We can now add new posts using the mobile interface! Go ahead and create a few so the posts index shows a list with links to edit each post:</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/base-posts.png" alt="base-posts" title="base-posts" width="472" height="615" class="aligncenter size-full wp-image-1367" /></p>
<h2>Read</h2>
<p>People will read posts from their <tt>show.html.erb</tt> view. Again, no change to the underlying controller or model code needs to happen. Just update the view file to look like this:</p>
<pre class="brush: xml;">
&lt;div data-role=&quot;header&quot;&gt;
  &lt;h1&gt;&lt;%= @post.title %&gt;&lt;/h1&gt;
  &lt;%= link_to 'Home', posts_url, &quot;class&quot; =&gt; &quot;ui-btn-right&quot; %&gt;
&lt;/div&gt;

&lt;div data-role=&quot;content&quot;&gt;
  &lt;%= @post.body %&gt;
&lt;/div&gt;
</pre>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/post-show.png" alt="post-show" title="post-show" width="472" height="615" class="aligncenter size-full wp-image-1368" /></p>
<h2>Update</h2>
<p>When we set up the posts index we added links to the <tt>edit.html.erb</tt> view using the gear icon on the right side of the split list. Now we just need to change the markup on that view to conform to jQuery Mobile&#8217;s requirements. Have you sniffed out a pattern to this development process yet?</p>
<pre class="brush: xml;">
&lt;div data-role=&quot;header&quot;&gt;
  &lt;h1&gt;Editing Post&lt;/h1&gt;
&lt;/div&gt;

&lt;div data-role=&quot;content&quot;&gt;
  &lt;%= render 'form' %&gt;
&lt;/div&gt;
</pre>
<p>Again, it just works as expected and it will look great on many mobile devices. On to the final action, delete!</p>
<h2>Delete</h2>
<p>To facilitate deleting a post we just have to modify the delete links created by Rails&#8217; scaffold generator to fit the rest of the mobile site. I think the edit page is a good place to add a delete link, so lets add a button to the header of <tt>edit.html.erb</tt>:</p>
<pre class="brush: xml;">
&lt;%= link_to 'Delete', @post, :method =&gt; :delete, &quot;data-icon&quot; =&gt; &quot;delete&quot;, &quot;class&quot; =&gt; &quot;ui-btn-right&quot; %&gt;
</pre>
<p>The edit view is now complete, and it lets us update and delete our post.</p>
<p style="text-align: center;"><img src="http://fuelyourcoding.com/files/post-edit.png" alt="post-edit" title="post-edit" width="472" height="615" class="aligncenter size-full wp-image-1369" /></p>
<h2>Closing Up</h2>
<p>If you&#8217;ve made it this far, you&#8217;ve probably realized that working with jQuery Mobile is pretty painless and it fits in with Rails quite well. There are a bunch of other things that jQuery Mobile can do, but this should hopefully whet your appetite. Remember, the framework is still in the <strong>Alpha</strong> stage so things can and probably will change.</p>
<p>I encourage you to <a href="http://jquerymobile.com/">read more</a> about the project and get involved at an early stage so we can all benefit from a strong community!</p>
<p style="text-align: center;"><a href="http://fuelyourcoding.com/files/jqmoblog.zip">***Download the source code for the application built in this post***</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>WebKit&#8217;s JavaScript Profiler Explained</title>
		<link>http://fuelyourcoding.com/webkits-javascript-profiler-explained/</link>
		<comments>http://fuelyourcoding.com/webkits-javascript-profiler-explained/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 12:56:41 +0000</pubDate>
		<dc:creator>Jerod Santo</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Plugins / Add-Ons]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[web inspector]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=1316</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>The trend toward rich client-side web applications has brought with it a need for robust JavaScript development tools. <a href="http://getfirebug.com/">Firebug</a> lead the way in this arena, but WebKit&#8217;s <a href="http://trac.webkit.org/wiki/WebInspector">Web Inspector</a> has caught up in a big way and ships with all recent versions of Safari <strong>and</strong> Chrome.</p>
<p>One powerful tool inside Web Inspector that is likely under utilized is the <em><strong>Profiles</strong></em> pane. I write <strong>a lot</strong> of client-side JavaScript and it still took me a long time to work up the gusto to dig into this tool and get anything out of it. If you find yourself in the position I was in, hopefully this post will give you what you need to get up and running quickly.</p>
<h2>Basics</h2>
<p>The JavaScript profiler is used to find and alleviate CPU bottlenecks in your code. To use it you invoke one or more &#8220;profile&#8221; runs in which Web Inspector tracks all JavaScript executed on the page and the time taken to execute it. In the picture below you will see a single profile called &#8220;<strong>Profile 1</strong>&#8221; being displayed.</p>
<p><img src="http://fuelyourcoding.com/files/base-1.png" alt="base-1" title="base-1" width="600" height="400" class="aligncenter size-full wp-image-1320" /></p>
<p>There are two ways to run a profile:</p>
<h3>1) Manually</h3>
<p>The pane itself has a little button in the lower left-hand corner which can be used to start and stop a profile. This is the least precise of the two methods, but is sometimes good enough for one-off profiles. Click it once, go perform whatever action on the page that invokes the code you want profiled, and then click it again to stop.</p>
<h3>2) Programmatically</h3>
<p>The way I suggest you invoke profile runs is by calling into the console directly from your code. This will allow you to precisely position the start and stop of the profile for maximum signal to noise ratio. Here is how you might profile a totally contrived <tt>for</tt> loop programmatically:</p>
<pre class="brush: jscript;">
console.profile('for loop');
for (var i = 0; i &lt; 100; i++) {
  console.log('i is: ', i);
}
console.profileEnd('for loop');
</pre>
<p>After that bit of code is executed a new profile titled &#8220;for loop&#8221; will appear in the Profiles pane to be reviewed. The string argument to these functions is optional. If you don&#8217;t provide one it will simply increment &#8220;Profile [x]&#8221; like it does when run manually.</p>
<h2>The Lingo</h2>
<p>Now we know what the <em><strong>Profiles</strong></em> pane looks like and how to make it run, but its of no use unless we can derive meaning from the results. We can&#8217;t do that without understanding the terms used, so here are explanations as I understand them:</p>
<p><strong>Self</strong> &mdash; the amount of time spent directly in the corresponding function</p>
<p><strong>Total</strong> &mdash; the amount of time spent in the corresponding function and all functions called by it</p>
<p><strong>Calls</strong> &mdash; how many times the corresponding function was called</p>
<p><strong>Average</strong> &mdash; the value of the corresponding function&#8217;s <strong>Self</strong> divided by its <strong>Calls</strong></p>
<p>Of these, <strong>Self</strong> and <strong>Total</strong> are the most confusing. The key thing to know is that the profiler tracks not only the time spent in each individual function, but also the time spent in functions called by that function. This is very useful when &#8220;drilling down&#8221; on a stack of function calls because you can look to see if the <strong>Total</strong> is bigger than the <strong>Self</strong> and if it is you know the time-consuming function is nested beneath the current one. </p>
<h2>Everything&#8217;s Relative (or Absolute)</h2>
<p>By default the <strong><em>Profiles</em></strong> pane displays all information in relative times so that each function is assigned a percentage of the total time of the profile. This is helpful in some scenarios, but I find the absolute times (measured in milliseconds and seconds) much more useful most of the time. To switch the profile result to absolute times, just click the little % sign at the bottom of the pane.</p>
<p><img src="http://fuelyourcoding.com/files/absolute-time.png" alt="absolute-time" title="absolute-time" width="600" height="400" class="aligncenter size-full wp-image-1325" /></p>
<h2>Top to Bottom. Bottom to Top</h2>
<p>You can also sort the profile results using two different approaches. The default is the &#8220;Heavy&#8221; view or bottom up approach, which will more quickly float up the offending functions to the top of the heap. This is helpful to quickly identify trouble areas, but sometimes confusing because it doesn&#8217;t follow the logical structure of your code. For that, switch to the &#8220;Tree&#8221; view or top down approach. It looks like this instead:</p>
<p><img src="http://fuelyourcoding.com/files/tree-view.png" alt="tree-view" title="tree-view" width="600" height="400" class="aligncenter size-full wp-image-1327" /></p>
<h2>Focus</h2>
<p>One more feature of the <em><strong>Profiles</strong></em> pane is the ability to remove sections of the results and <strong>focus</strong> solely on the interesting bits. Do this by highlighting the interesting function and clicking the little eye icon in the lower lefthand corner. Other results will disappear and time percentages will be recalculated in the scope of the focused function.</p>
<h2>Conclusion</h2>
<p>I hope the above information explains what Web Inspector&#8217;s Profiles pane is, how to invoke it, what the results mean, and how to better organize them to increase their value. Give this power tool a try the next time you have some CPU intensive JavaScript that needs optimizing!</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/webkits-javascript-profiler-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Events: Stop (Mis)Using Return False</title>
		<link>http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/</link>
		<comments>http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 13:53:37 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[bubbling]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=1266</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>

&#60;div class=&#34;post&#34;&#62;
    &#60;h2&#62;&#60;a href=&#34;/path/to/page&#34;&#62;My Page&#60;/a&#62;&#60;/h2&#62;
    &#60;div class=&#34;content&#34;&#62;
        Teaser text...
    &#60;/div&#62;
&#60;/div&#62;
&#60;div class=&#34;post&#34;&#62;
    &#60;h2&#62;&#60;a href=&#34;/path/to/other_page&#34;&#62;My Other Page&#60;/a&#62;&#60;/h2&#62;
    &#60;div class=&#34;content&#34;&#62;
        Teaser text...
    &#60;/div&#62;
&#60;/div&#62;

Now lets say we [...]]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>Probably one of the first topics covered when you get started learning about jQuery events is the concept of canceling the browser&#8217;s default behavior. For instance, a beginner <code>click</code> tutorial may include this:</p>
<pre class="brush: jscript;">
$(&quot;a.toggle&quot;).click(function () {
    $(&quot;#mydiv&quot;).toggle();
    return false; // Prevent browser from visiting `#`
});
</pre>
<p>This function toggles the hiding and displaying of <code>#mydiv</code>, then cancels the browser&#8217;s default behavior of visiting the <code>href</code> of the anchor tag. </p>
<p>It is in these very first examples that bad habits are formed as users continue to use <code>return false;</code> whenever they want to cancel the default browser action. I am going to cover two very important topics in this article relating to the canceling of browser events:</p>
<ul>
<li>Use the right method for the job: <code>return false</code> vs. <code>preventDefault</code>, <code>stopPropagation</code>, and <code>stopImmediatePropagation</code></li>
<li>Top, bottom or somewhere in the middle: where in the event callback should you cancel default behavior?</li>
</ul>
<p><em>Note: in this article when I refer to event bubbling, I am talking about how most events will fire on the original DOM element, and then on each parent element in the DOM tree. Events do not bubble to siblings or children (When events &#8220;bubble&#8221; downward, it is called event capturing). <a href="http://www.nczonline.net/blog/2009/06/30/event-delegation-in-javascript/">Learn more about bubbling and capturing.</a></em></p>
<h2 id="use_the_right_method_for_the_job">Use the Right Method for the Job</h2>
<p>The main reason <code>return false</code> is so widely misused is because it <em>appears</em> to be doing what we want. Link callbacks no longer redirect the browser, form submit callbacks no longer submit the form, etc. So why is it so bad?</p>
<h3 id="what_return_false_is_really_doing">What <code>return false</code> is <em>really</em> doing</h3>
<p>First off, <code>return false</code> is actually doing three very separate things when you call it:</p>
<ol>
<li>event.preventDefault();</li>
<li>event.stopPropagation();</li>
<li>Stops callback execution and returns immediately when called.</li>
</ol>
<p>&#8220;Wait a minute,&#8221; you cry! I only needed to stop the default behavior! I don&#8217;t need these other two items&#8230; I think. </p>
<p>The only one of those three actions needed to cancel the default behavior is <code>preventDefault()</code>. Unless you mean to actually stop event propagation (bubbling), using <code>return false</code> will greatly increase the brittleness of your code. Lets see how this misuse plays out in a real world scenario:</p>
<p>Here is our HTML for the example:</p>
<pre class="brush: xml;">
&lt;div class=&quot;post&quot;&gt;
    &lt;h2&gt;&lt;a href=&quot;/path/to/page&quot;&gt;My Page&lt;/a&gt;&lt;/h2&gt;
    &lt;div class=&quot;content&quot;&gt;
        Teaser text...
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;post&quot;&gt;
    &lt;h2&gt;&lt;a href=&quot;/path/to/other_page&quot;&gt;My Other Page&lt;/a&gt;&lt;/h2&gt;
    &lt;div class=&quot;content&quot;&gt;
        Teaser text...
    &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Now lets say we want the actual article to load into the corresponding <code>div.content</code> when a user clicks on either title link:</p>
<pre class="brush: jscript;">
jQuery(document).ready(function ($) {
   $(&quot;div.post h2 a&quot;).click(function () {
      var a    = $(this),
          href = a.attr('href'), // Let jQuery normalize `href`,
          content  = a.parent().next();
      content.load(href + &quot; #content&quot;);
      return false; // &quot;cancel&quot; the default behavior of following the link
   });
});
</pre>
<p>All is well (currently) and our dynamic page is well under way. Down the road we decide another piece of functionality we want is to add the class <code>"active"</code> to any <code>div.post</code> that has been clicked (or when a child element has been clicked) most recently. So, we decide to add a <code>click</code> handler to them as well:</p>
<pre class="brush: jscript;">
// Inside Document Ready:
var posts = $(&quot;div.post&quot;);
posts.click(function () {
    // Remove active from all div.post
    posts.removeClass(&quot;active&quot;);
    // Add it back to this one
    $(this).addClass(&quot;active&quot;);
});
</pre>
<p>Will this work when we click a title link? NO! The reason it won&#8217;t work is because we used <code>return false</code> in the link click event instead of using what we really meant! Because <code>return false</code> really means <code>event.preventDefault(); event.stopPropagation();</code> the <code>click</code> event never bubbled up to the parent <code>div.post</code> and our new event has not been called. </p>
<p>This becomes even more of an issue when mixing normal events with <code>live</code> or <code>delegate</code> events:</p>
<pre class="brush: jscript;">
$(&quot;a&quot;).click(function () {
    // do something
    return false;
});

$(&quot;a&quot;).live(&quot;click&quot;, function () {
    // THIS WON'T FIRE
});
</pre>
<h3 id="so_what_do_you_really_want">So what DO you really want?</h3>
<h4 id="preventdefault"><code>preventDefault()</code></h4>
<p>In most situations where you would use <code>return false</code> what you <em>really</em> want is <code>e.preventDefault()</code>. Using <code>preventDefault</code> requires you allow for the event parameter to be accessed in your callback (In this example, I use <code>e</code>):</p>
<pre class="brush: jscript;">
$(&quot;a&quot;).click(function (e) {
    // e == our event data
    e.preventDefault();
});
</pre>
<p>This does everything we want without prohibiting parent elements from receiving these events as well. The fewer restrictions you place on your code the more flexible it will be to maintain. </p>
<h4 id="stoppropagation"><code>stopPropagation()</code></h4>
<p>Sometimes you just want to stop the propagation. Take the following example:</p>
<pre class="brush: xml;">
&lt;div class=&quot;post&quot;&gt;
    Normal text and then a &lt;a href=&quot;/path&quot;&gt;link&lt;/a&gt; and then more text.
&lt;/div&gt;
</pre>
<p>Now, lets pretend we want one thing to happen when you click anywhere in the <code>div</code> <strong>except</strong> on the link, and you want the user to actually be able to follow the link if they click on it. (From a usability standpoint, this is a poor example. You probably don&#8217;t want something else to happen if a user slightly misses clicking on the link!)</p>
<pre class="brush: jscript;">
$(&quot;div.post&quot;).click(function () {
   // Do the first thing;
});

$(&quot;div.post a&quot;).click(function (e) {
    // Don't cancel the browser's default action
    // and don't bubble this event!
    e.stopPropagation();
});
</pre>
<p>In this case if we had used <code>return false</code> the <code>div</code>&#8217;s click event would not have fired, but the user would also not have been directed to the correct destination either.</p>
<h4 id="stopimmediatepropagation"><code>stopImmediatePropagation()</code></h4>
<p>This method stops any further execution of an event, even to other handlers bound on the same object. All events bound to a particular item will fire in the order they were bound.  Take the following example:</p>
<pre class="brush: jscript;">
$(&quot;div a&quot;).click(function () {
   // Do something
});

$(&quot;div a&quot;).click(function (e) {
   // Do something else
   e.stopImmediatePropagation();
});

$(&quot;div a&quot;).click(function () {
   // THIS NEVER FIRES
});

$(&quot;div&quot;).click(function () {
   // THIS NEVER FIRES
});
</pre>
<p>If you think this example looks contrived, it really is. However, the situation is a very real one. As you build more abstracted code, different widgets and plugins may be adding events to the same code you are working with. This makes understanding and using <code>stopImmediatePropagation</code> worth while when you come across a situation that needs it!</p>
<h4><code>return false</code></h4>
<p>Only use <code>return false</code> when you want both <code>preventDefault()</code> and <code>stopPropagation()</code> and your code can support not canceling the default behavior until you reach the end of your callback execution. <em>I strongly encourage against using this method in any examples you may write for new jQuery developers. It promotes a poor use of event cancellation and should only be used when you are consciously deciding you need what it provides.</em>.</p>
<h2 id="top_bottom_or_somewhere_in_the_middle">Top, Bottom or Somewhere in the Middle</h2>
<p>Before, when you were (mis)using <code>return false</code>, it always had to go at the end of your function, or at least at the end of a particular line of logic where no further execution was needed. With <code>e.preventDefault</code> we have more choices. It can be called at any time during a callback function to take effect. So where should you put it?</p>
<p><strong>1. During development, it should <em>(almost) always</em> be the very first line.</strong> The last thing you want is for your form you are trying to AJAXify to actually submit to another page while you try to debug a JavaScript error in the callback. </p>
<p><strong>2. In production, if you are following progressive enhancement, put it at the bottom of the callback, or at the end of execution flow.</strong> If you are progressively enhancing a normal page, then your link <code>click</code> event or form <code>submit</code> event has the proper server side fallbacks needed for browsers that don&#8217;t support JavaScript (or don&#8217;t have support enabled). The benefit here, however, is <strong>not</strong> related to browsers with JS turned off, but rather browsers with it turned on in the situation where <em>your code throws an error</em>! Take a look at the following code:</p>
<pre class="brush: jscript;">
var data = {};
$(&quot;a&quot;).click(function (e) {
    e.preventDefault(); // cancel default behavior

    // Throws an error because `my` is undefined
    $(&quot;body&quot;).append(data.my.link); 

    // The original link doesn't work AND the &quot;cool&quot;
    // JavaScript has broken. The user is left with NOTHING!
});
</pre>
<p>Now, lets take a look at the same event with the <code>preventDefault</code> call being placed at the bottom:</p>
<pre class="brush: jscript;">
var data = {};
$(&quot;a&quot;).click(function (e) {
    // Throws an error because `my` is undefined
    $(&quot;body&quot;).append(data.my.link); 

    // This line is never reached, and your website
    // falls back to using the `href` instead of this
    // &quot;cool&quot; broken JavaScript!

    e.preventDefault(); // cancel default behavior
});
</pre>
<p>The same applies for <code>form submit</code> events as well, provided you have the proper fallback information in place. Never count on your code always working. It is far better to plan for a nice fallback than assume errors will never occur!</p>
<p><strong>3. In production, if the functionality is JavaScript only, keep the call on the first line.</strong> Remember, it doesn&#8217;t necessarily have to be the first line in the function, but it should come as early as fits with your program logic. The concept here is this: If this part of your functionality was added with JavaScript in the first place, then a fallback is not really as necessary. In this case, having it first will just ensure random <code>#</code> characters don&#8217;t appear in the URL or cause the page to jump around. Obviously, provide as much error handling as needed to ensure your users aren&#8217;t left with nothing for their efforts!</p>
<h2 id="conclusion">Conclusion</h2>
<p>I hope this article presented enough information for you to make the right choice when you cancel events. Remember to only use <code>return false</code> when you really need it, and make sure you cancel the default behavior at the right location in your callback. Always work to make your code as flexible as possible, and stop using return false!</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/feed/</wfw:commentRss>
		<slash:comments>61</slash:comments>
		</item>
		<item>
		<title>Open-Source Spotlight: Underscore.js</title>
		<link>http://fuelyourcoding.com/open-source-spotlight-underscorejs/</link>
		<comments>http://fuelyourcoding.com/open-source-spotlight-underscorejs/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 16:20:36 +0000</pubDate>
		<dc:creator>Jerod Santo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=856</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>JavaScript is a powerful language, but it lacks some of the handy utilities that developers of other languages like Ruby &amp; Python have come to know and love. <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> is your utility belt. In the author&#8217;s own words:</p>
<blockquote><p>Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It&#8217;s the tie to go along with jQuery&#8217;s tux.</p></blockquote>
<p><a href="http://documentcloud.github.com/underscore/">Underscore.js</a> provides collection functions like <tt>each</tt>, <tt>map</tt>, <tt>include</tt>, and <tt>reduce</tt>. It makes arrays more powerful by adding <tt>flatten</tt>, <tt>uniq</tt>, and <tt>intersect</tt>. It extends objects with many useful functions like <tt>keys</tt>, <tt>values</tt>, <tt>functions</tt>, <tt>isNaN</tt>, and many more.</p>
<p>A few examples to whet your appetite:</p>
<p>Using the <tt>each</tt> function to write each array value to the console:</p>
<pre class="brush: jscript;">
// object-oriented way
_(['John', 'Paul', 'George', 'Ringo']).each(function(beatle) {
    console.log(beatle);
});
// functional way
_.each(['John', 'Paul', 'George', 'Ringo'], function(beatle) {
    console.log(beatle);
});
</pre>
<p>Using the <tt>reduce</tt> method to round three numbers down and sum the results:</p>
<pre class="brush: jscript;">
_.reduce([1.5,2,3.7], 0, function(memo, num) { return memo + Math.floor(num) });
// =&gt; 6
</pre>
<p>Using the <tt>pluck</tt> method to to extract just the names from an array of objects:</p>
<pre class="brush: jscript;">
var beatles = [
  {name: 'John', dead: true},
  {name: 'Paul', dead: false},
  {name: 'Ringo', dead: false},
  {name: 'George', dead: true}
]

_.pluck(beatles, 'name');
// =&gt; [&quot;John&quot;, &quot;Paul&quot;, &quot;Ringo&quot;, &quot;George&quot;]
</pre>
<p>The library weighs in at just <strong>2.5kb</strong> once packed and gzipped, so there is little excuse not to take advantage of its offerings. There are over 60 functions included, the documentation on how to use each function is great, the source code is freely available <a href="http://github.com/documentcloud/underscore/">on GitHub</a>, and the library is completely DOM-free which means you can use it server-side as well.</p>
<p>Thanks to <a href="http://github.com/jashkenas">Jeremy Ashkenas</a> and the folks at <a href="http://www.documentcloud.org/home">DocumentCloud</a> for a great open-source library that we can all benefit from!</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/open-source-spotlight-underscorejs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin Design Patterns: Part I</title>
		<link>http://fuelyourcoding.com/jquery-plugin-design-patterns-part-i/</link>
		<comments>http://fuelyourcoding.com/jquery-plugin-design-patterns-part-i/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 18:21:06 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Plugins / Add-Ons]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=798</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>jQuery plugins come in all shapes and sizes. They perform very simple or very complex tasks depending on their intended use. When it comes time for you to design your own plugin, its really important to understand what patterns other developers use and what will best suits your needs.</p>
<p>As a side note, I have built a number of plugins for my own projects and client work that will <em>never be released</em>. The jQuery community needs to stop thinking of plugins only as releasable, open-source projects, and start thinking of them instead as a reusable pieces of code that can help optimize and <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> up a complex website. Take this little plugin as an example:</p>
<pre class="brush: jscript;">
$.fn.notice = function(){
    return this.slideDown(500).delay(4000).slideUp(500);
}
</pre>
<p>It simply abstracts the animation for displaying a notice (using jQuery 1.4). Would I ever release this on an open source site? Of course not! But it is still a fully functioning jQuery plugin that can be used over and over throughout a website.</p>
<h2>Design Pattern Series Overview</h2>
<ul>
<li>Basics &amp; Structure (this article)</li>
<li>Options &amp; Updating</li>
<li>Callbacks &amp; Custom Events</li>
<li>Misc. General Practices</li>
</ul>
<h2>Basics</h2>
<h3>Filename</h3>
<p>Every jQuery plugin sits in its own JS file, and is normally named using the following pattern:</p>
<pre class="brush: plain;">
jquery.pluginname.js
jquery.pluginname.min.js
</pre>
<p>Released plugins often also have a version number:</p>
<pre class="brush: plain;">
jquery.pluginname-1.3.js
jquery.pluginname-1.3.min.js
</pre>
<p>If you end up building a lot of plugins for your website, consider also including a namespace to keep all your files together (And of course you would combine and minify them for production, right?):</p>
<pre class="brush: plain;">
jquery.mysite.pluginname.js
jquery.mysite.pluginname.js
</pre>
<h3>Basic File Layout</h3>
<p>After any comments you choose to put at the top of your file, the very next thing you should have is a self executing anonymous function that will actually wrap your entire plugin. Say what!? Don&#8217;t worry, you have seen it before, and it looks like this:</p>
<pre class="brush: jscript;">
(function($){

   ... code here ...

})(jQuery);
</pre>
<p>This gives your plugin a private scope to work in, and also allows your plugin to be used with <code>$.noConflict</code> mode without creating a problem. By passing <tt>jQuery</tt> into the function, the <tt>$</tt> will equal jQuery <em>inside</em> the function even if <code>$</code> means something different outside your plugin.</p>
<h2>Structure</h2>
<p>There are three basic structures you will see when you look at released plugins:</p>
<h3>Contained Function</h3>
<p>In this structure, (almost) all the code to run your plugin is contained within the function used to call your plugin. This is the most common format:</p>
<pre class="brush: jscript;">
(function($){

   $.fn.myPlugin = function(){
      return this.each(function(){
         // do something
      });
   }

})(jQuery);
</pre>
<p>You <strong>should</strong> use this this structure when you are writing a simple plugin that acts once upon the jQuery result set on each execution. For complex plugins that need to maintain an adjustable state, you should consider the &#8220;Class and Function&#8221; structure.</p>
<h3>Class and Function</h3>
<p>In this structure, a class is used and an instance is created for each DOM element in the result set. You may see these objects attached in some way to the DOM elements they modify:</p>
<pre class="brush: jscript;">
(function($){
   var MyClass = function(el){
       var $el = $(el);

       // Attach the instance of this object
       // to the jQuery wrapped DOM node
       $el.data('MyClass', this);
   }

   $.fn.myPlugin = function(){
      return this.each(function(){
         (new MyClass(this));
      });
   }

})(jQuery);
</pre>
<p>You <strong>should</strong> use this structure if you need to be able to access the object later that is associated with a DOM element. It is far easier to attach a single object vs several key/value pairs using the <tt>data()</tt> method. In this approach, you can access the object by calling <tt>$('selector').data('MyClass')</tt>. This functions more like a widget and is a plugin that maintains state and can adjust its state on the fly (Learn how in the next article.).</p>
<p><em><strong>Note: </strong> Widget Factory: The next release of jQuery UI is going to see the addition of a Widget Factory that will be designed to specially assist in developing widget-like plugins. </em></p>
<h3>Extend</h3>
<p>In my opinion, this is the least idiomatic way to create a jQuery plugin. It uses the <tt>jQuery.fn.extend</tt> method instead of <tt>jQuery.fn.pluginName</tt>:</p>
<pre class="brush: jscript;">
(function($){

   $.fn.extend({
     myPlugin: function(){
      return this.each(function(){
         // do something
     },
     myOtherPlugin: function(){
      return this.each(function(){
         // do something
     }
   });

})(jQuery);
</pre>
<p>You will find this structure helpful if you need to add a <em>large number</em> of plugin methods to jQuery. I would contend, however, that if your plugin needs to add that many methods, there may be a better way to structure its implementation.</p>
<p>I feel the extend method is used more by programmers transitioning from other JS libraries. I personally find the simple <tt>$.fn.pluginName =</tt> structure to be easier to read, and more in line with what you will normally see in jQuery plugins.</p>
<h2>Up Next</h2>
<p>In the next part of this series, we will look at passing options and providing methods for updating settings and functionality after a plugin has been called.</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/jquery-plugin-design-patterns-part-i/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>jQuery Enlightenment: Book Review and Giveaway (Winners Announced!)</title>
		<link>http://fuelyourcoding.com/jquery-enlightenment-book-review-and-giveaway/</link>
		<comments>http://fuelyourcoding.com/jquery-enlightenment-book-review-and-giveaway/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 20:04:58 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Books / Magazines]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=782</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<h2>Winners Announced</h2>
<p>I was really happy to see so much participation in this giveaway! After seeing how many people entered, I was feeling really bad that only one of them would leave with a copy of the book. I talked to Cody, and he graciously provided two more free copies so we can award a total of three books! I randomly picked three winners (using <a href="http://random.org">Random.org</a>) and am happy to announce the following winners:</p>
<ul>
<li>Brad Rhine (<a href="http://truetech.org">truetech.org</a>)</li>
<li>Mila</li>
<li>Geoff Woodburn (<a href="http://woodburndesigns.com">woodburndesigns.com</a>)</li>
</ul>
<h2>Book Review</h2>
<p>Late in 2009, <a href="http://www.codylindley.com">Cody Lindley</a> published a PDF book on jQuery titled <a href="http://jqueryenlightenment.com">jQuery Enlightenment</a>. Today we are presenting our view of the book as well as offering a free copy to one lucky reader.</p>
<p><img class="alignnone size-full wp-image-792" title="jqueryen" src="http://fuelyourcoding.com/files/jqueryen.jpg" alt="jqueryen" width="600" height="300" /></p>
<h2>About The Author</h2>
<p>Cody Lindley is a core team member of the <a href="http://jquery.com">jQuery</a> project, and the original developer of the well known Thickbox plugin for jQuery. I had the pleasure of meeting and listening to Cody present at the jQuery Conference last year in Boston. He describes himself on his website:</p>
<blockquote><p>Today I am a Christian, husband, son, brother, professional Web developer, and outdoor enthusiast. I spend a majority of my time sleeping and working, but who doesn’t? In between the daily routines of the average American, I desire an existence that entails a relationship with God, my family, and nature. I would like to consider myself a bookworm (a novice theologian at best), but truth be told, I simply enjoy watching movies and playing xBox way too much. I guess I also have the luxury of pursuing my profession as a personal passion. Yes, I often work even when I am not at work.</p></blockquote>
<h2>Overview</h2>
<p>jQuery Enlightenment is a different type of book than I am used to seeing in the tech field. A list of what it is <em>not</em> might help shed light on what I mean. It is not documentation, a tutorial/walkthrough, or just conceptual material. jQuery Enlightenment is an amazingly clear montage of principals and code samples every jQuery developer needs to know grouped by topic. Cody covered topics both basic and profound throughout the pages of the book.</p>
<p>I consider myself quite adept at using jQuery, but found myself constantly amazed at the things I was learning while reading this book.  Cody says it picks up where the jQuery documentation leaves off. I can see his point, but I think this book would be a better starting place for a new jQuery developer than even reading through the jQuery API site.</p>
<h2>Pros</h2>
<h3>Code Samples</h3>
<p><img class="alignnone size-full wp-image-783" title="code" src="http://fuelyourcoding.com/files/code.jpg" alt="code" width="568" height="104" /></p>
<p>Code samples make up over 70% of the book (rough estimation). The book is not written in an editorial way at all. It is about presenting what you need to know, demonstrating it with an example, and moving on. For this reason the book is an extremely fast read and perfect for reference on a day to day basis.</p>
<p>Possibly one of the neatest features of the book itself is that (almost) every code sample provided in the book has a link to the same code on JSBin.com. JSBin is an online playground for testing and demonstrating JavaScript, HTML, and CSS technologies. jQuery Enlightenment isn&#8217;t a flat reading experience, it allows you to immediately jump in and play with the code samples until everything makes sense.</p>
<h3>Additional Notes</h3>
<p><img class="alignnone size-full wp-image-784" title="notes" src="http://fuelyourcoding.com/files/notes.jpg" alt="notes" width="568" height="104" /></p>
<p>Many of the topics are followed by a little box titled &#8216;Notes&#8217;. I am glad Cody didn&#8217;t choose some cheesy title for these boxes, but &#8216;Notes&#8217; really does not sum up what they provide. You will find many undocumented (or hard to find) tips and tricks about the finer points of jQuery in these boxes. Skip over them at your own peril!</p>
<h3>No Fluff Quality</h3>
<p>Cody doesn&#8217;t waste any time on any of the topics presented in the book. The pattern used is simple: explain, demonstrate, move on. I personally will be using this book not just for reference, but for a quick read-through every few weeks to keep my jQuery senses sharp.</p>
<h2>Cons</h2>
<p>You will be hard pressed to find something negative to say about this book, and it wasn&#8217;t until I reached the end that I had one complaint about the content. The chapter on Ajax (Chapter 11) was far too short. Perhaps this is because the documentation is very clear, but I still wanted to learn more and have more examples to glean from. Perhaps the second edition of the book (which will cover jQuery 1.4) will provide more detail on jQuery&#8217;s AJAX implementation and associated methods.</p>
<h2>Conclusion</h2>
<p>I am confident new users and seasoned users alike will find much to learn in jQuery Enlightenment. After reading the book, my only concern is that I won&#8217;t remember all of the cool things I learned while reading it!</p>
<h2>Win a FREE Copy!</h2>
<p>Next Wednesday we will be selecting a winner to receive a free copy of jQuery Enlightenment. Entering the competition is easy!</p>
<p>Head over to <a href="http://jqueryenlightenment.com">jQuery Enlightenment</a> and quickly look through table of contents. Then, leave a comment below telling us what chapter you think you would learn the most from if you were to win the book. Only comments referencing one of the actual chapters in the book will be eligible to win. <strike>We will randomly select a winner next Wednesday and announce it here on the site.</strike>. <strong>Sorry, but the contest is over!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/jquery-enlightenment-book-review-and-giveaway/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>JavaScript Can Learn: Now Teach It Tricks!</title>
		<link>http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/</link>
		<comments>http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 07:00:34 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Concepts & Training]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[extending]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=672</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>When you do a lot of development with backend technologies, it can be frustrating to then move to the front end and feel like you are using a completely different syntax. One thing I really miss is the helper methods, especially when using Ruby on Rails on the server. Little helpers like <tt>titleize()</tt> or <tt>downcase()</tt> get replaced in javascript by a custom function and <tt>toLowerCase()</tt> respectively. You don&#8217;t have to feel lost anymore! There is a way you can extend the native objects found in JavaScript to make your environment feel a little more like &#8220;home.&#8221;</p>
<p>This is accomplished by using the prototype object. Each native object in JavaScript includes a prototype object. Don&#8217;t get this confused with the PrototypeJS framework&#8230; the prototype object is a way to extend <em>all</em> objects that have inherited from the base object you extended. You can easily extend the prototype object by adding functions to it like this:</p>
<pre class="brush: jscript;">
Object.prototype.functionName = function(){

}
</pre>
<p>You can then call them directly:</p>
<pre class="brush: jscript;">
var obj = new Object();
obj.functionName();
</pre>
<p>There are a number of advanced uses of the prototype object, but this is the important thing to remember: any function added to the prototype of an object is available on any object that inherits from it. So if you extend the prototype on the Number object, all numbers will have access to the new function; if you extend the Array object, all arrays can access your custom function. You only use the <tt>prototype.functionName</tt> syntax when declaring the new function, not when calling it.</p>
<p>Enough theory, lets see some (somewhat) practical uses:</p>
<p>Do you find yourself capitalizing a lot of words in a particular JavaScript app? Just add a <tt>capitalize</tt> method to the String object.</p>
<pre class="brush: jscript;">
String.prototype.capitalize = function(){
  if(this.length == 0) return this;
  return this[0].toUpperCase() + this.substr(1);
}
</pre>
<p>Now you can capitalize any string in your application by calling <tt>"lower".capitalize()</tt> and get <tt>"Lower"</tt> in return. Since it returns a string, you could chain it with any other function you can execute on a string.</p>
<p>Do you always find yourself forgetting you can call Number(&#8221;25&#8243;) to turn a string into a number? Just add a <tt>toNumber()</tt> function to the String prototype:</p>
<pre class="brush: jscript;">
String.prototype.toNumber = function(){
  return Number(this);
}

If you need to split large JSON arrays into groups of two or three each, you could extend the Array object like this:

[js]
Array.prototype.inGroupsOf = function(num){
	var ret = [],
		length = this.length,
		groups = Math.ceil(length / num);

	for(var i = 0; i &lt; groups; i++){
		var start = i * num,
			end   = start + num;

		ret.push(this.slice(start, end))
	}
	return ret;
}
</pre>
<p>Now calling <tt>inGroupsOf(3)</tt> on any Array would return that same array split into as many parts as needed to ensure no group has more than three items in it.</p>
<p>There are a number of objects you can extend, but the ones you will use the most are <tt>String</tt>, <tt>Array</tt>, <tt>Object</tt>, <tt>Number</tt>, <tt>Date</tt>. One trouble area you might face is calling methods on numbers. The following example will fail:</p>
<pre class="brush: jscript;">
Number.prototype.to_s = function(){
  return this + &quot;&quot;;
}

25.to_s();
</pre>
<p>The prototype function is correct, but the way we called it is wrong. There are two ways to call our custom functions on numbers:</p>
<pre class="brush: jscript;">
var n = 25;
n.to_s(); // Returns &quot;25&quot;

(25).to_s(); // Also returns &quot;25&quot;
</pre>
<h2>Think Start, Not End</h2>
<p>Its important when deciding what object to extend that you focus on what object type you are starting with, not so much which type you plan on ending with. For instance, if you wanted to extend an object to easily parse Twitter date strings you would not extend the <tt>Date</tt> object. You would extend the <tt>String</tt> object, and your function would return a <tt>Date</tt> object.</p>
<h2>Load Your Extensions First</h2>
<p>It is normally a good idea to load these extensions prior to any other library, including jQuery. Anytime you extend the prototype object, the new method is instantly available to all objects of the same type or any object that has inherited from that type. However, since you want to be sure your methods are always available, you guarantee their availability by loading them first.</p>
<h2>How to Group The Extensions</h2>
<p>Naming your files <tt>Prototype.Date.js</tt> and <tt>Prototype.Array.js</tt> is an easy way to keep all your extensions in one part of your JS folder, and easy to access during development. If you follow this method, you would simply put Date.prototype methods in the <tt>Prototype.Date.js</tt> file, etc. This starts to break down when you have parallel functions. You might have a <tt>toDateFromTwitter()</tt> method on the String object and a <tt>toTwitterFromDate()</tt> method on the Date object. Putting these in separate files might not make sense. At that point, you should put both these extensions in a file named TwitterHelpers.js or something similar. Obviously use what makes sense to you and works with your flow.</p>
<h2>Don&#8217;t Bloat</h2>
<p>Just because you write 500+ awesome Array extensions in the next 2 years, does not mean you need to include them on every project. Be sure to only use this technique when it makes sense for the project and when it helps clean up your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/javascript-can-learn-now-teach-it-tricks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery Custom Events: They Will Rock Your World!</title>
		<link>http://fuelyourcoding.com/jquery-custom-events-they-will-rock-your-world/</link>
		<comments>http://fuelyourcoding.com/jquery-custom-events-they-will-rock-your-world/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 00:12:50 +0000</pubDate>
		<dc:creator>Douglas Neiner</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=418</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>

&#60;script src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&#34; type=&#34;text/javascript&#34; charset=&#34;utf-8&#34;&#62;&#60;/script&#62;
&#60;script src=&#34;js/jquery.colorblock.js&#34; type=&#34;text/javascript&#34; charset=&#34;utf-8&#34;&#62;&#60;/script&#62;
&#60;script src=&#34;js/jquery.colorobserver.js&#34; type=&#34;text/javascript&#34; charset=&#34;utf-8&#34;&#62;&#60;/script&#62;
&#60;script type=&#34;text/javascript&#34; charset=&#34;utf-8&#34;&#62;
 	$(document).ready(function(){

  	});
 &#60;/script&#62;

HTML
Copy and paste the following HTML markup into the &#60;body&#62; tag of the index.html file:

&#60;div id=&#34;color_blocks&#34;&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
  	&#60;div class=&#34;color_block&#34;&#62;&#60;/div&#62;
&#60;/div&#62;

&#60;div [...]]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>Ok, maybe they won&#8217;t exactly “Rock Your World” but they might completely change the way you look at your jQuery development. At the very least, I hope this simple technique will help you build clean, reusable and extendable front-end code.</p>
<div class="post_buttons"><a href="http://fuelyourcoding.com/files/jqueryeventssource.zip"><img class="size-full wp-image-24 alignnone" title="Download zipped archive" src="http://fuelyourcoding.com/files/download-button.gif" alt="Download zipped archive" width="229" height="68" style="margin-left: 30px" /></a><a href="http://fuelyourcoding.com/samples/jquery_custom_events/"><img class="size-full wp-image-25 alignnone" title="View the example" src="http://fuelyourcoding.com/files/example-button.gif" alt="View the example" width="229" height="68"  style="margin-left: 30px" /></a></div>
<h2>A Quick &#8216;n&#8217; Dirty Overview</h2>
<p>If you are the “just the facts” type of person, here is the 20 second overview. You can trigger custom events on any DOM object of your choosing using jQuery. Just trigger it using the following code:</p>
<pre class="brush: jscript;">
$(&quot;#myelement&quot;).trigger('fuelified');
</pre>
<p>You can subscribe to that event using either <tt>bind</tt> or <tt>live</tt> functions in jQuery:</p>
<pre class="brush: jscript;">
$(&quot;#myelement&quot;).bind('fuelified',function(e){ ... });
$(&quot;.cool_elements&quot;).live('fuelified',function(e){ ... });
</pre>
<p>You can even pass additional data about the event when triggering it and reference it on the listeners end:</p>
<pre class="brush: jscript;">
$(&quot;#myelement&quot;).trigger('fuelified',{ custom: false });
$(&quot;#myelement&quot;).bind('fuelified',function(e,data){ if(data.custom) ... });
</pre>
<p>The element the trigger has been called on, is available to listener&#8217;s callback function as the variable this.</p>
<h2>A Little Philosophy</h2>
<p>I encourage you to view your front end code in parts and pieces instead of one huge piece of front-end code. If you look at each part separately, you can build better, reusable pieces of code. You won&#8217; t have a lot of duplicated code in your web-site, and you will be able to extend what you have built later on. A rating site might have widgets that are used to take in the ratings. You may have another widget that monitors the rating widgets and tallies the scores. Making the pieces as independent as possible makes reuse and extension a breeze.</p>
<h2>A Fun Example</h2>
<p>For those who like tutorials or walkthroughs, this should be a fun demonstration of the power of jQuery custom events.</p>
<h3>Preparation</h3>
<p>To get started, <a href="http://fuelyourcoding.com/files/blankwebsitetemplate.zip">download my blank website template</a>. Then head over to <a href="http://starter.pixelgraphics.us" target="_blank">Starter for jQuery</a> and create two jQuery plugins using the following settings:</p>
<ol>
<li>Class Name: <strong>ColorBlock<br />
<span style="font-weight: normal;">Include: </span>Options, Getter </strong>(Not Comments)</li>
<li>Class Name: <strong>ColorObserver<br />
<span style="font-weight: normal;">Include: </span>Options, Getter <span style="font-weight: normal;">(Not Comments)<br />
Default Options: <strong>colorObjs|div.color_block</strong><strong> </strong></span></strong></li>
</ol>
<p>After you enter each item, click <strong>Create</strong> then <strong>Download</strong>. Save each file to the <strong>js/</strong> directory of our Blank Website Template. Then add &lt;script&gt; tags linking both files into the index.html file. Finally, put a blank jQuery document.ready block into the head, just below the scripts. When you are finished, the scripts in &lt;head&gt; area should look like this:</p>
<pre class="brush: xml;">
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/jquery.colorblock.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/jquery.colorobserver.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
 	$(document).ready(function(){

  	});
 &lt;/script&gt;
</pre>
<h3>HTML</h3>
<p>Copy and paste the following HTML markup into the &lt;body&gt; tag of the <strong>index.html</strong> file:</p>
<pre class="brush: xml;">
&lt;div id=&quot;color_blocks&quot;&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
  	&lt;div class=&quot;color_block&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id=&quot;observer-one&quot; class=&quot;observer&quot;&gt; &lt;/div&gt;
&lt;div id=&quot;observer-two&quot; class=&quot;observer&quot;&gt; &lt;/div&gt;
</pre>
<p>Normally I might delegate the creation of the div.color_block elements to a script as well, but that is not the point of this exercise!</p>
<h3>CSS</h3>
<p>Copy and paste the following CSS into the layout.css file. Basically it sets simple styling for our elements. The important part is that it sets a width and height of 50px for our .color_block elements, and floats them to the left. If you were to load <strong>index.html</strong> in a browser right now, you wouldn&#8217;t see too much.</p>
<pre>
<pre class="brush: css;">
.color_block {
	width: 50px;
	height: 50px;
	cursor: pointer;
	float: left;
	margin: 0 5px 5px 0;
}

.observer {
	clear: left;
	margin: 10px 0;
	padding: 10px;
	float: left;
	background: #eee;
	font-family: Helvetica, Arial;
}

#observer-one { border-top: solid 2px red; }
#observer-two { border-top: solid 2px blue; }</pre>
</pre>
<h3>JS</h3>
<p>The plugins you created using Starter for jQuery have added two new functions to our jQuery objects. We are going to call both of them in our &lt;head&gt; script area. Paste the following code between the opening and closing braces of the <tt>document.ready</tt> function:</p>
<pre>
<pre class="brush: jscript;">
$(&quot;.color_block&quot;).colorBlock();
$(&quot;#observer-one&quot;).colorObserver();
</pre>
</pre>
<p>The first line calls our <tt>colorBlock</tt> plugin on all the blocks. The second, calls our <tt>colorObserver</tt> method on one of our observer divs. If you load the page now, you should not get any errors, but nothing should do anything yet either.</p>
<h3>ColorBlock</h3>
<p>We want to give our ColorBlocks an array of colors. They will all start on color 1 (index position 0) and every time you click on them, they will change to the next color. To do this, we will add code to our <tt>jquery.colorblock.js</tt> file.</p>
<p><strong>Note: Most of you are probably not familiar with Starter for jQuery, or the code it puts out. I plan on writing an article about it sometime, but for this article remember these important principles. Anywhere in the plugin class itself ($.ColorBlock for example) <tt>base</tt> refers to base object. And <tt>base.el</tt> and <tt>base.$el</tt> refer to the DOM element and the jQuery wrapped DOM element the base object is connected to.</strong></p>
<p>The plugin supports override-able options. We need to use this for our plugin, so find the <tt>$.ColorBlock.defaultOptions</tt> and paste this between the curly braces:</p>
<pre>
<pre class="brush: jscript;">colors: [&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;,&quot;yellow&quot;]</pre>
</pre>
<p>Now, we need to give our object the ability to change colors. Paste the following code after the <tt>base.init</tt> function definition (but before the base.init() call. That should always come last in the plugin) :</p>
<pre>
<pre class="brush: jscript;">
base.setColor = function(new_color_index){
	if( new_color_index != base.current_color_index ){
		base.current_color_index = new_color_index;
		base.$el.css({backgroundColor: base.options.colors[base.current_color_index]});
	}
}

base.nextColor = function(){
	var new_color_index = base.current_color_index + 1;
	if ( new_color_index &gt; ( base.options.colors.length - 1 ) )
		new_color_index = 0;
	base.setColor( new_color_index );
}

base.getColor = function(){
	return base.options.colors[base.current_color_index];
}
</pre>
</pre>
<p>This gives our object three methods. A method to set the color using an arbitrary index. A method to trigger the next color in the cycle. And finally a way to retrieve which color is currently in use. Nothing so far is rocket science.</p>
<p>Finally to enable our little widget, we add two lines of code to the base.init function after the line that initializes the options.</p>
<pre>
<pre class="brush: jscript;">
base.$el.click(function(){ base.nextColor(); });
base.setColor(0);</pre>
</pre>
<p>The first line triggers base.nextColor() every time our object is clicked. And the second line just initializes our object using the first color in the array (index position 0).</p>
<p>Now, if we load index.html in our browser, you will be able to cycle through the colors on each block simply by clicking on them.</p>
<p>In our make believe world, we can be happy that we made a working jQuery plugin. YAY! However, bad news also occurs in our world, and our client requests a way to monitor which colors are currently showing. So, along comes our ColorObserver widget. </p>
<p>Already we are making educational progress, because we realize the functionality to monitor all color_blocks is <strong>not</strong> the function of the ColorBlock widget (You <strong>do</strong> realize that right?).</p>
<h3>ColorObserver</h3>
<p>Our observer needs a method to find all ColorBlocks and find out which colors are showing. The following code should do the trick. Paste the following code into the <tt>jquery.colorobserver.js</tt> file, after the <tt>base.init</tt> definition, but before the <tt>base.init();</tt> call.</p>
<pre>
<pre class="brush: jscript;">
base.discoverColors = function(){
	var colors_count = {};
	$(base.options.colorObjs).each(function(){
		var color = $(this).data('ColorBlock').getColor();

		if(!colors_count[color])
			colors_count[color] = 1;
		else
			colors_count[color] += 1;
	});

	var output = &quot;&quot;;
	$.each(colors_count, function(key,value){
		output += key + &quot;=&quot; + value + &quot;&lt;br /&gt;&quot;;
	})
	base.$el.html(output);
}</pre>
</pre>
<p>In a nutshell, this code uses the selector from our <tt>defaultOptions</tt> or an overridden option to find which objects are ColorBlocks. It then gets the color, and either adds it to the <tt>colors_count</tt> array, or increases its count by one if it already exists. It then puts together a HTML snippet, and updates its <tt>base.$el</tt> content with our snippet. (Remember that <tt>base.$el</tt> refers to the jQuery wrapped DOM element we originally tied the widget to. In this case, <tt>#observer-one</tt>)</p>
<h2>The Most Important Part</h2>
<p>Now we need to tie to two objects together. You might be tempted to hardwire some <tt>$("#observer-one").getColorObserver().discoverColors()</tt> call into your <tt>setColor</tt> function over on the ColorBlocks. It would work for sure, but it makes your code more and more dependent on each other&#8230; making future changes more likely to break your code.</p>
<p>Instead we will use custom events to solve our problem. Put the following line inside the <tt>base.setColor</tt> function on the ColorBlock, inside the <tt>if</tt> statement as the last line:</p>
<pre>
<pre class="brush: jscript;">base.$el.trigger('color_changed');</pre>
</pre>
<p>Now, any time the color changes on a single block, a &#8216;color_changed&#8217; event fires. Now, put the following two lines in the <tt>base.init</tt> function of the ColorObserver class (After the options setup code):</p>
<pre>
<pre class="brush: jscript;">
$(base.options.colorObjs).live('color_changed', function(){ base.discoverColors(); });
base.discoverColors();
</pre>
</pre>
<p>The first line binds to our custom event and tells the ColorObserver class to rediscover the visible colors. The second line is just the initial call to find out the starting state of the colors.</p>
<p>At this point our job is done, and our two widgets are correctly wired together. Load <tt>index.html</tt> up in your browser and see for yourself. Every time you change a block color, the observer knows about it and changes its data to match.</p>
<p>The best part is that you could delete the &lt;script&gt; tag that links the ColorObserver to our document, and remove the line that initializes it, and the ColorBlock&#8217;s would continue to work just fine!</p>
<h2>Even More Coolness</h2>
<p>You might not have even noticed, but even more flexibility was baked into our project. Add the following line to our &lt;head&gt; script block:</p>
<pre>
<pre class="brush: jscript;">$(&quot;#observer-two&quot;).colorObserver({colorObjs:$(&quot;.color_block:lt(3)&quot;)});</pre>
</pre>
<p>Now our second observer only observes the first 3 color blocks. We over-rode the colorObjs default selector with our own.</p>
<h2>Conclusion</h2>
<p>I hope this opens new doors to you when using jQuery for development. Its a great way of compartmentalizing and easily extending your code. If you still have trouble understanding its practicality, consider an advanced jQuery rich internet application. It could trigger events for every major interactions, and you could build a GoogleAnalyticsObserver class to listen for those actions and send them on to Google to track. </p>
<p>Let me know if this helps you out, or how you think you could use Custom jQuery Events.</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/jquery-custom-events-they-will-rock-your-world/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Steps to becoming a front-end web developer</title>
		<link>http://fuelyourcoding.com/steps-to-becoming-a-front-end-web-developer/</link>
		<comments>http://fuelyourcoding.com/steps-to-becoming-a-front-end-web-developer/#comments</comments>
		<pubDate>Mon, 18 May 2009 23:40:05 +0000</pubDate>
		<dc:creator>Gaya Kessler</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[xhtml / css]]></category>
		<category><![CDATA[become]]></category>
		<category><![CDATA[becoming]]></category>
		<category><![CDATA[front-end]]></category>
		<category><![CDATA[web developer]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=121</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>There are a few things you have to know in order to be a front-end web developer. Where to start and what to learn. This guide will take you through the steps of becoming a front-end web developer.</p>
<h2>First things first</h2>
<p>Before we start seeing stuff on the screen, we have to make something out of nothing. We start at the basics of web developing: <a href="http://en.wikipedia.org/wiki/HTML">HTML</a>. This markup language will draw shapes on the web page and display text.</p>
<p>HTML is not only very important, your whole markup will depend on it. Don&#8217;t touch CSS yet! We&#8217;ll come to that later.<br />
CSS is worthless with a bad markup supporting it.</p>
<h2>1. Learn HTML</h2>
<ol>
<li><a href="http://www.w3schools.com/html/html_intro.asp">Learn basic HTML</a></li>
<li><a href="http://www.w3schools.com/Xhtml/">Learn about xhtml and validation</a></li>
<li><a href="http://validator.w3.org/">Make valid xhtml and validate</a></li>
</ol>
<p>Learning perfect HTML will take some time but it will really pay off later. It&#8217;s way easier to prevent mistakes and track down bugs when the markup is perfect.</p>
<p>Next step is what you&#8217;ve been waiting for; applying CSS.</p>
<h2>2. Know CSS</h2>
<ol>
<li><a href="http://www.w3.org/Style/Examples/011/firstcss">How to apply CSS</a></li>
<li><a href="http://www.w3schools.com/css/css_background.asp">Know all the important aspects of styling</a></li>
<li><a href="http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/">Learn about positioning</a></li>
<li><a href="http://www.w3schools.com/css/css_dimension.asp">Get to advanced CSS</a></li>
</ol>
<p>You don&#8217;t have to be perfect at CSS. But being good at it will save a lot of time for your designer.</p>
<p>If you plan on becoming a server side programmer you are best off learning a server side language to generate HTML pages now. Take a look at <a href="http://www.php.net/">PHP</a>, <a href="http://www.asp.net/">ASP.NET</a>, <a href="http://java.sun.com/products/jsp/">JSP</a> etc. if you want to know more.</p>
<p>Now that you know good HTML and CSS it&#8217;s time to put in a little <a href="http://en.wikipedia.org/wiki/JavaScript">Javascript</a>.<br />
Don&#8217;t start by using a framework now, you first need to understand what Javascript is and what it can do to alter the layout of the web page.</p>
<h2>3. Rock Javascript!</h2>
<ol>
<li><a href="http://www.amazon.com/s/ref=nb_ss_b?url=search-alias%3Dstripbooks&amp;field-keywords=javascript&amp;x=0&amp;y=0">Read a good book about Javascript.</a></li>
<li><a href="http://net.tutsplus.com/articles/web-roundups/best-of-the-web-january/">Get to know some funny Javascript effects and concepts.</a> (There are a lot on the Internet)</li>
</ol>
<p>After I read a good book and experimented with Javascript on some projects a bit, I wanted to get everything out of Javascript by making nice effects like the other guys do. For this there are a lot of frameworks available, which also happen to make your Javascript coding a lot easier!</p>
<h2>4. Pick your framework</h2>
<p> </p>
<p>There are a few great Javascript frameworks out there. The biggest players in the game are: <a href="http://mootools.net/">MooTools</a>, <a href="http://jquery.com/">jQuery</a> and <a href="http://script.aculo.us/">script.aculo.us</a>.</p>
<p><a href="http://mootools.net/">MooTools</a> is a lightweight Javascript framework which can be used to utilize simple effects on the elements on your page. It doesn&#8217;t have a lot of fancy features, but it does the job. Good choice for beginners.</p>
<p><a href="http://jquery.com/">jQuery</a> might be the most popular one out there. Not without a reason! It&#8217;s easy to apply, it has great docs, maybe even easier to learn and does a wonderful job. Does require some plugins for extra functionality but it&#8217;s a really nice framework. Also has a large community.</p>
<p><a href="http://script.aculo.us/">script.aculo.us</a> is the mother ship of the Javascript frameworks. It&#8217;s big and weights a ton. It might be a bit slower and requires a bit more programming than its competitors, but it is powerful in what it does. The capabilities of script.aculo.us take a lot up in speed, but for that you get complete control. You can create excellent Rich Internet Applications with this framework.</p>
<p> </p>
<h2>Conclusion</h2>
<p>In just a few step you can become a front-end web developer. This might take a while and it might take some time to get used to a language, but it will pay-off in the end.<br />
There is a lot to be learned on the Internet and it is never too late to try out web development and make the web a little more exciting.</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/steps-to-becoming-a-front-end-web-developer/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Panoramic Photoviewer in Javascript</title>
		<link>http://fuelyourcoding.com/panoramic-photoviewer-in-javascript/</link>
		<comments>http://fuelyourcoding.com/panoramic-photoviewer-in-javascript/#comments</comments>
		<pubDate>Mon, 04 May 2009 12:44:20 +0000</pubDate>
		<dc:creator>Gaya Kessler</dc:creator>
				<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[panorama]]></category>
		<category><![CDATA[panoramic]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=53</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>

&#60;div class='photo' style='display: none;' id='navigate'&#62;
	&#60;div class='fixed opt1'&#62;
		&#60;!-- this is optional --!&#62;
		&#60;a href='http://gayadesign.com/post/' class='button1'&#62;

		&#60;/a&#62;
		&#60;a href='http://gayadesign.com/portfolio/' class='button2'&#62;

		&#60;/a&#62;
		&#60;a href='http://gayadesign.com/about/' class='button3'&#62;

		&#60;/a&#62;
		&#60;a href='http://gayadesign.com/partners/' class='button4'&#62;

		&#60;/a&#62;
		&#60;a href='http://gayadesign.com/contact/' class='button5'&#62;

		&#60;/a&#62;
	&#60;/div&#62;
&#60;/div&#62;

The overall container “navigate” will always be hidden prior to the actual Javascript call. I also gave the fixed div a second class. This classname will point to the options of the container; the height [...]]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>As a webdesigner you might have had this problem: “I’ve got a nice looking wide image, but I don’t want my visitors to scroll horizontally.”</p>
<p>A colleague showed me a new project he was working on. A large image appeared and I had the ability to drag and move the image around in a container. Not super efficient if you ask me, I still had to grab the image and move it around holding my mouse button. Can’t there be an easier way?</p>
<p>This article will show you my solution to the problem and maybe even a different approach on navigation.</p>
<p><img class="alignnone size-full wp-image-56" title="Panoramic Photoviewer in Javascript" src="http://fuelyourcoding.com/files/panoramicphotoviewerimg.jpg" alt="Panoramic Photoviewer in Javascript" width="606" height="132" /></p>
<div class="post_buttons"><a href="http://www.fuelyourcoding.com/scripts/photonav/jqueryphotonav.zip"><img class="size-full wp-image-24 alignnone" title="Download zipped archive" src="http://fuelyourcoding.com/files/download-button.gif" alt="Download zipped archive" width="229" height="68" /></a><a href="http://www.fuelyourcoding.com/scripts/photonav/"><img class="size-full wp-image-25 alignnone" title="View the example" src="http://fuelyourcoding.com/files/example-button.gif" alt="View the example" width="229" height="68" /></a></div>
<p>The <em>example page</em> is located here:<br />
<a href="http://fuelyourcoding.com/scripts/photonav/">http://www.fuelyourcoding.com/scripts/photonav/</a></p>
<p>And the <em>archive is downloadable</em> here:<br />
<a onclick="javascript:pageTracker._trackPageview('/scripts/photonav/jqueryphotonav.zip');" href="http://fuelyourcoding.com/scripts/photonav/jqueryphotonav.zip">http://fuelyourcoding.com/scripts/photonav/jqueryphotonav.zip</a></p>
<h2>What is it?</h2>
<p>This photo container has been adjusted to “move” with the cursor. To achieve this I used Javascript and a library called <a onclick="javascript:pageTracker._trackPageview('/outbound/article/jQuery.com');" href="http://jquery.com/">jQuery</a>.</p>
<h2>What do we have and what do we need to do?</h2>
<ol>
<li>Create a HTML layout for the picture to get in.</li>
<li>Adjust the CSS.</li>
<li>Make a call to PhotoNav in Javascript.</li>
</ol>
<h2>1. Create a HTML layout</h2>
<p>This is the easiest step. It might just as well be a copy paste of the code below. But be aware of three things.<br />
First give the overall container an id (so Javascript can grab the object).<br />
Then make sure the div with classname <em>fixed</em> gets a second classname to correspond with the CSS (I used <em>opt1</em> and <em>opt2</em>).<br />
Determine if you want to have links inside of the container, if not; you can leave the container empty.</p>
<p>Take a look at the code below:</p>
<pre class="brush: xml;">
&lt;div class='photo' style='display: none;' id='navigate'&gt;
	&lt;div class='fixed opt1'&gt;
		&lt;!-- this is optional --!&gt;
		&lt;a href='http://gayadesign.com/post/' class='button1'&gt;

		&lt;/a&gt;
		&lt;a href='http://gayadesign.com/portfolio/' class='button2'&gt;

		&lt;/a&gt;
		&lt;a href='http://gayadesign.com/about/' class='button3'&gt;

		&lt;/a&gt;
		&lt;a href='http://gayadesign.com/partners/' class='button4'&gt;

		&lt;/a&gt;
		&lt;a href='http://gayadesign.com/contact/' class='button5'&gt;

		&lt;/a&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The overall container “navigate” will always be hidden prior to the actual Javascript call. I also gave the <em>fixed</em> div a second class. This classname will point to the options of the container; the height and the background image (the actual image that needs scrolling).<br />
You can add <em>&lt;a&gt; tags</em> to the <em>fixed</em> container. I gave them all classnames so they can be positioned in the CSS. This part is optional.</p>
<p>Remember to include the jQuery library and the PhotoNav Javascript files in the header. Also include the CSS file <em>photonav.css</em>.</p>
<pre class="brush: xml;">
&lt;script src=&quot;js/jquery-1.3.2.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;js/photonavjQuery.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;link href='css/photonav.css' rel='stylesheet' type='text/css' /&gt;
</pre>
<h2>2. Adjust the CSS<br />
</h2>
<p>The top part of the CSS has to stay the way it is, do not adjust it if you don’t know what you are doing. I put a comment at the spot where you can start to edit the CSS.<br />
I’ll describe what to do at each part of the CSS.</p>
<p><strong>.photonav .photo: </strong></p>
<pre class="brush: css;">
.photonav .photo {
	width: 400px;
	margin: 10px;
	border: 1px solid gray;
}
</pre>
<p>Adjust the width of the total container. This has to be a fixed width in order for it to work in IE6. I have no idea why, but if the <em>width</em> was set to <em>100%</em>, the height was 0px. You can do <em>100%</em> in other browser with the <em>!important</em> trick.<br />
The margin and border are optional, just make it as you’d like.</p>
<p><strong>.photonav .photo .opt1:</strong></p>
<pre class="brush: css;">
.photonav .photo .opt1 {
	height: 100px;
	background-image: url();
}
</pre>
<p>This is the height of the photo container, at least, the <em>fixed</em> container. But notice the <em>.opt1</em>, it is the second classname we added to the <em>fixed</em> container in the HTML part.<br />
The background image is the image that has to be viewed inside the container.</p>
<p><em>The next part is optional and only if you want buttons inside the container.</em></p>
<p><strong>a.button*:</strong></p>
<pre class="brush: css;">
a.button1 {
	margin-left: 20px;
	margin-top: 30px;
	width: 100px;
	height: 90px;
	background-image: url();
}

a.button1:hover {
	background-image: url();
}
</pre>
<p>In order to create a menu navigation like I did on the preview page, you need to add <em>a tags</em> with different classnames. Define the pixels from the left side and the top of the container in the margin values. State the width and height of the button and the background image (if needed).<br />
To create an <em>onhover</em> effect you can add an other image in the <em>:hover</em> part.<br />
If you want a second <em>a tag</em> next to the other, subtract the <em>height </em>of the previous button from the margin-top.</p>
<h2>3. Make a call to PhotoNav in Javascript</h2>
<p>Now that you’ve got all the necessary HTML and CSS set, you can call the PhotoNav functionality. The following code can be put in a js file or in a <em>script</em> tag.</p>
<pre class="brush: jscript;">
document.getElementById('navigate').style.display = 'block';
PhotoNav.init('navigate', 758, 1412, false);
</pre>
<p>The specification is:<br />
<strong>function </strong>init(<strong>String </strong><em>id_of_container</em>, <strong>int </strong><em>width_of_container</em>, <strong>int </strong><em>width_of_panorama_picture</em>, <strong>bool</strong> <em>debugMode</em>);</p>
<p><strong>String </strong><em>id_of_container</em>:<br />
The id of the container.</p>
<p><strong>int </strong><em>width_of_container</em>:<br />
Give the width in pixels of the <em>fixed</em> container. For calculating reasons.</p>
<p><strong>int </strong><em>width_of_panorama_picture</em>:<br />
Give the width in pixels of the <span style="font-style: italic;">panoramic </span><em>picture</em>. For calculating reasons.</p>
<p><strong>bool</strong> <em>debugMode</em>:<br />
Enable debug mode. Outputting value to the HTML element with id <em>’status’</em>. (default: false)</p>
<p>If you want to enable debug mode, you have to insert the following code somewhere in your HTML:</p>
<pre class="brush: xml;">
&lt;div id='status'&gt;
	&amp;nbsp;
&lt;/div&gt;
</pre>
<h2>Conclusion</h2>
<p>Now that everything is set, you can fire the thing up! Enable the navigation on loading a page or by triggering an event in Javascript. If you have implementations of this script, post your examples in the comment section, I’d like to see them.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/panoramic-photoviewer-in-javascript/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Dos and don&#8217;ts of AJAX</title>
		<link>http://fuelyourcoding.com/dos-and-donts-of-ajax/</link>
		<comments>http://fuelyourcoding.com/dos-and-donts-of-ajax/#comments</comments>
		<pubDate>Mon, 04 May 2009 12:05:17 +0000</pubDate>
		<dc:creator>Gaya Kessler</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[backbase]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=46</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p><a onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');" href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">AJAX</a> is one the nicest concept I’ve seen in web development. The basics are simple and quite easy to use.<br />
There are a lot of <a onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');" href="http://en.wikipedia.org/wiki/List_of_Ajax_frameworks">AJAX frameworks</a> around like <a onclick="javascript:pageTracker._trackPageview('/outbound/article/jquery.com');" href="http://jquery.com/">jQuery</a>, <a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.prototypejs.org');" href="http://www.prototypejs.org/">Prototype</a> and <a onclick="javascript:pageTracker._trackPageview('/outbound/article/bdn.backbase.com');" href="http://bdn.backbase.com/">backbase</a>. These frameworks help you create an AJAX application with ease.<br />
But is AJAX really that good? No, but if you use it correctly, it is!</p>
<p>In this article I wish to share my view on AJAX and the possibilities it gives to web developers and designers, and why AJAX is wrong in several situations.</p>
<p><img class="alignnone size-full wp-image-49" title="Dos and don'ts of AJAX" src="http://fuelyourcoding.com/files/dodontsajaximg.jpg" alt="Dos and don'ts of AJAX" width="606" height="112" /></p>
<h2>Case 1: Page loading</h2>
<p>What’s up with websites and dynamically loading pages through AJAX? Isn’t it a bit strange that when you want to switch to another page, there is no real page switch?<br />
Sure, I like it when content is loaded into the website dynamically, saving me bandwidth, time and irritation. But a whole page? Isn’t that kind of missing the point?</p>
<ul>
<li>First of all: What about the back and forward buttons of your browser? No use for them if you load a whole page in AJAX.</li>
<li>Second: Funny when a user tries to copy the URL and send it to a friend. Oops, the page is loaded without the content the user expected.</li>
<li>Third: Search Engines can’t pick it up since it is not really a new page.</li>
</ul>
<p>A better way to load content through AJAX is to load only small parts of information on the page. If the users wishes to visit another page, let the browser go to another page.<br />
Loading content in a small part of the page isn’t a bad thing. If you have a container with tabbed content, it’s easy to load the content of other tabs with AJAX, not a problem.</p>
<p>Loading a whole page in AJAX is just overusing the functionality and really missing the point of web browsing.</p>
<h2>Case 2: The content manager</h2>
<p>Being able to adjust the information of your web profile on a web page with the use of AJAX is cool. Fast feedback, fast loading times and convenient. But is it really secure?<br />
I’ve seen sites where the HTTP calls to the server contained the key and value of the part they wanted to configure. Which means the record which will be adjusted is defined. This means you could also change information of other rows in the database. Why? You need to wonder what parts of the profile can be adjusted, and if it applies only to the user who is trying to configure their information, why do you need a key to tell the server which record to adjust?<br />
In PHP, for example, it only takes little effort to remember a value in a session. With this, you know which user is using the website and if you open the session in the AJAX server side pages, you can still read that session. Makes it easy to tell which record to update and doesn’t give a user the opportunity to mess around in your system.</p>
<p>If you do want to send along a key + value, which could be needed in some situations (like inserting a comment), be sure to check the given values in the server side scripts. Can’t say this enough to people, but please be sure the user that is trying to insert / update data has access to that data. This also applies to normal usage of forms, but adjusting an AJAX request is harder for most users. Still it is possible! So be on your guard.</p>
<h2>Case 3: One click update</h2>
<p>This one is something I love about AJAX. The vote buttons on sites, the follow button on Twitter, delete entry buttons and many more of those. The convenience of just clicking once without having to refresh the page is awesome. It’s so simple, yet so powerful.<br />
If you are using such a thing, keep <em>case 2</em> in mind.</p>
<h2>Case 4: Content loading</h2>
<p>One of the most important things of dynamic loading: it has to be quick. Sending a request to a server doesn’t always have to take up most of the time, but loading the response can be a real pain.<br />
Keep the response clean and small. I’ve seen examples (I’ve been guilty in the past) of people giving HTML back in the response. With this they’ll adjust the innerHTML of a container. In the worst case they’ll load a whole new page (like in <em>case 1</em>).</p>
<p>To solve this, please use <a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.php.net');" href="http://www.php.net/json_encode">JSON</a> or anything of that kind. JSON helps you convert server side variables to Javascript variables. The response the server will give are Javascript variables for Javascript to read. JSON has been implemented in PHP since version 5.2.0 and is easy to use.</p>
<p>Don’t give HTML back to your web page, but arrays of information. This helps keeping the presentation of your site and the calculation apart from each other. Do the adjusting of the DOM in Javascript.</p>
<h2>Case 5: External Services</h2>
<p>When you use external services and feeds to build a web page in server side scripting, you rely on an external service. This can also result is pages loading slower than needed. The is why AJAX is ideal for loading external services.</p>
<p>Load information from an external source after loading the page. This will prevent slow loading of the rest of the page and let’s the information just easily slip in the page when it’s ready.</p>
<h2>Conclusion</h2>
<p>I hope I’ve given my point of view on AJAX and how to use it. If you wish to discuss the things that I’ve said; please do so!</p>
<p>Share your AJAX stories with me =)</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/dos-and-donts-of-ajax/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Garagedoor effect using Javascript</title>
		<link>http://fuelyourcoding.com/garagedoor-effect-using-javascript/</link>
		<comments>http://fuelyourcoding.com/garagedoor-effect-using-javascript/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 23:35:33 +0000</pubDate>
		<dc:creator>Gaya Kessler</dc:creator>
				<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[scriptaculous]]></category>

		<guid isPermaLink="false">http://fuelyourcoding.com/?p=3</guid>
		<description><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>

&#60;script src=&#34;js/prototype.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;
&#60;script src=&#34;js/scriptaculous.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;

&#60;script src=&#34;js/garagedoor.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;
&#60;link href='css/garagedoor.css' rel='stylesheet' type='text/css' /&#62;

This will load the scripts and styles needed for the GarageDoor to work. Adjust the paths where needed.

The next thing you want to do is to create the HTML layout for the garagedoors. The following code shows the structure you need to create for your document:

&#60;div [...]]]></description>
			<content:encoded><![CDATA[<p><p><a href="http://rss.buysellads.com/click.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" target="_blank"><img src="http://rss.buysellads.com/img.php?z=1271313&k=f16d4ddc81a95a47348dcddb230bad58&a=<?php echo($a); ?>&c=<?php echo(rand()); ?>" border="0" alt="" /></a></p><p><a href="http://buysellads.com/buy/sitedetails/pubkey/f16d4ddc81a95a47348dcddb230bad58/zone/1271313" target="_blank">Advertise here via BSA</a></p></p>
<p>The GarageDoor effect &#8211; creating one has now been made easy! This tutorial explains everything you need to know on how to create the same effect yourself.</p>
<p><img class="alignnone size-full wp-image-17" title="Garagedoor effect using Javascript" src="http://fuelyourcoding.com/files/garagedoorpostimg.jpg" alt="Garagedoor effect using Javascript" width="606" height="162" /></p>
<div class="post_buttons"><a href="http://fuelyourcoding.com/scripts/garagedoor/garagedoor.zip"><img class="size-full wp-image-24 alignnone" title="Download zipped archive" src="http://fuelyourcoding.com/files/download-button.gif" alt="Download zipped archive" width="229" height="68" /></a><a href="http://fuelyourcoding.com/scripts/garagedoor/"><img class="size-full wp-image-25 alignnone" title="View the example" src="http://fuelyourcoding.com/files/example-button.gif" alt="View the example" width="229" height="68" /></a></div>
<p>An example of the GarageDoor effect in work is found here: <a href="http://fuelyourcoding.com/scripts/garagedoor/">http://www.fuelyourcoding.com/scripts/garagedoor/</a><br />
<em>Download</em> the following archive containing everything you need: <a onclick="javascript:pageTracker._trackPageview('/scripts/garagedoor/garagedoor.zip');" href="http://fuelyourcoding.com/scripts/garagedoor/garagedoor.zip">http://www.fuelyourcoding.com/scripts/garagedoor/garagedoor.zip</a></p>
<p><em>Unzip </em>the contents of the archive and upload the contents to your server, the set folders can be adjusted to your needs.</p>
<p>First we need to make the script ans style of the GarageDoor work. To make that happen, you’ll need Scriptaculous. This library enables interface effects, so you don’t have to create it yourself. So <a onclick="javascript:pageTracker._trackPageview('/outbound/article/script.aculo.us');" href="http://script.aculo.us/downloads">grab Scriptaculous</a> and upload it to your server. Make sure you also upload the <strong>prototype.js </strong>file (in the lib folder).</p>
<p>Add the following code in the <strong>&lt;head&gt;</strong> tag of your page:</p>
<pre class="brush: xml;">
&lt;script src=&quot;js/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/scriptaculous.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;js/garagedoor.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;link href='css/garagedoor.css' rel='stylesheet' type='text/css' /&gt;
</pre>
<p>This will load the scripts and styles needed for the GarageDoor to work. <em>Adjust the paths where needed.<br />
</em></p>
<p>The next thing you want to do is to create the HTML layout for the garagedoors. The following code shows the structure you need to create for your document:</p>
<pre class="brush: xml;">
&lt;div class='garagedoor' id='garagedoor'&gt;
	&lt;div title='linktofile' class='item'&gt;
		&lt;div class='underlay'&gt;
			Caption text
		&lt;/div&gt;
		&lt;img src='uritooverlayimage' class='overlay' /&gt;
		&lt;div class='mouse'&gt;&lt;img src='images/nothing.gif' /&gt;&amp;nbsp;&lt;/div&gt;
	&lt;/div&gt;
	&lt;div title='linktofile' class='item'&gt;
		&lt;div class='underlay'&gt;
			Caption text
		&lt;/div&gt;
		&lt;img src='uritooverlayimage' class='overlay' /&gt;
		&lt;div class='mouse'&gt;&lt;img src='images/nothing.gif' /&gt;&amp;nbsp;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>This contains two items that will be the garagedoor. The keywords <strong>linktofile</strong> and<strong> uritooverlayimage</strong> have to be adjusted in order to make it work. <strong>Linktofile</strong> is the URL of the page the button has to link to, might be confusing because it’s not an <em>a tag</em>, but Javascript fixes it for you.</p>
<p>The items have a default size of: <strong>100px width </strong>and <strong>80px height</strong>. <em>Create overlay images</em> according to these dimensions. In order to change the size, take a look in the <strong>garagedoor.css</strong> file and<em>adjust</em> the <strong>width</strong> and <strong>height</strong> of several elements.</p>
<p>All there is left to do is call the GarageDoor to enable the effect!</p>
<pre class="brush: xml;">
&lt;script&gt;
	GarageDoor.scrollY = -55;
	GarageDoor.scrollX = 0;
	GarageDoor.setBindings('garagedoor');
&lt;/script&gt;
</pre>
<p>The first line in the <strong>&lt;script&gt;</strong> tag sets the amount of scrolling the overlay has to do when the cursor is floating over an item. In this example the overlay has to go 55 up, which means move -55px on the Y-axis.<br />
You can also make it scroll horizontal.</p>
<p>Give the <strong>id</strong> of the <strong>garagedoor container</strong> to the <strong>setBindings</strong> method and the GarageDoor effect will be initialized! Be sure to make the call <strong>after</strong> creating the <strong>html</strong>.</p>
<p>You are now set to use the GarageDoor Effect. Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://fuelyourcoding.com/garagedoor-effect-using-javascript/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

