<?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>Casey Watson &#187; Uncategorized</title>
	<atom:link href="http://casedogdesigns.com/wordpress/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://casedogdesigns.com/wordpress</link>
	<description>Outdated Thoughts</description>
	<lastBuildDate>Tue, 01 Dec 2009 22:08:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Easy Zebra Striping with Prototype</title>
		<link>http://casedogdesigns.com/wordpress/easy-zebra-striping-with-prototype/</link>
		<comments>http://casedogdesigns.com/wordpress/easy-zebra-striping-with-prototype/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 21:17:02 +0000</pubDate>
		<dc:creator>Casey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://casedogdesigns.com/wordpress/?p=31</guid>
		<description><![CDATA[While reviewing some of the JQuery tutorials, I was impressed with the ease of setting up a table with alternating row colors.
This got me thinking that it should be a relatively easy thing to achieve using the Prototype library as well. In this edition, I will give quick example of doing just that.
We&#8217;ll start by [...]]]></description>
			<content:encoded><![CDATA[<p>While reviewing some of the JQuery tutorials, I was impressed with the ease of setting up a <a href="http://docs.jquery.com/Tutorials:Zebra_Striping_Made_Easy">table with alternating row colors</a>.</p>
<p>This got me thinking that it should be a relatively easy thing to achieve using the <a href="http://www.prototypejs.org/">Prototype</a> library as well. In this edition, I will give quick example of doing just that.</p>
<p>We&#8217;ll start by using the element selector utility method (<em>$$</em>). This will return a list of the odd numbered rows in our table. We then add the <em>oddRow</em> classname to each of these matched table rows.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> stripe<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> evens <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'table.stripe tr:nth-child(odd)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>evens<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      evens.<span style="color: #006600;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        tr.<span style="color: #006600;">addClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'oddRow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Event.<span style="color: #006600;">observe</span><span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> stripe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The next step is to assign the <em>stripe</em> class to our table. Any table with this class will pick up the new behavior.</p>
<p>Last step, we need to specify the CSS to change the background color. I also threw in a directive to collapse the borders.</p>

<div class="wp_syntax"><div class="code"><pre class="css">table<span style="color: #6666ff;">.stripe</span> tbody tr<span style="color: #6666ff;">.oddRow</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #66cc66;">:</span> <span style="color: #cc00cc;">#eee</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span>
table<span style="color: #6666ff;">.stripe</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #66cc66;">:</span> <span style="color: #993333;">collapse</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Here it is in action. Though it&#8217;s a bit crude it illustrates that the rows are highlighted as intended.<br />
<script type="text/javascript"><!--
function stripe(e) {
	var evens = $$('table.stripe tr:nth-child(odd)');
	if(evens) {
		evens.each(function(tr) {
			tr.addClassName('oddRow');
		});
	}
}
Event.observe(window, 'load', stripe);
// --></script></p>
<style type="text/css"> 
table.stripe tbody tr.oddRow { background-color: #eee; } table.stripe { border-collapse: collapse; }
</style>
<table class="stripe" border="0">
<thead>
<tr>
<th>Lorem</th>
<th>Ipsum</th>
<th>Dolor</th>
<th>Sit</th>
<th>Amet</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
</tbody>
</table>
<table class="stripe" border="0">
<thead>
<tr>
<th>Lorem</th>
<th>Ipsum</th>
<th>Dolor</th>
<th>Sit</th>
<th>Amet</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
<td>Sit</td>
<td>Amet</td>
</tr>
</tbody>
</table>
<p>As always improvements, tweaks &amp; suggestions are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://casedogdesigns.com/wordpress/easy-zebra-striping-with-prototype/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
