<?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/"
	>

<channel>
	<title>The html blog &#187; Javascript</title>
	<atom:link href="http://htmlblog.net/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://htmlblog.net</link>
	<description>The web sandbox of Asvin Balloo</description>
	<pubDate>Mon, 29 Dec 2008 12:01:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>twitree.com - see on which leaves the birds are&#8230;</title>
		<link>http://htmlblog.net/twitreecom-see-on-which-leaves-the-birds-are/</link>
		<comments>http://htmlblog.net/twitreecom-see-on-which-leaves-the-birds-are/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 12:01:02 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[twitree]]></category>

		<category><![CDATA[twitter]]></category>

		<category><![CDATA[visualization]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=81</guid>
		<description><![CDATA[I am happy to announce the launch of twitree.com. It's a twitter application which allows a twitterer to view his followers in a tree-like navigation, which can be expanded.

twitree makes extensive use of the YUI library. The following components were used :

grids css - for the layout
yahoo dom event - for DOM and event handling
connection [...]]]></description>
			<content:encoded><![CDATA[<p>I am happy to announce the launch of <a href="http://twitree.com/">twitree.com</a>. It's a <a href="http://twitter.com">twitter</a> application which allows a twitterer to view his followers in a tree-like navigation, which can be expanded.</p>
<p><a href="http://twitree.com/"><img src="http://htmlblog.net/wp-content/uploads/2008/12/twitree-300x116.jpg" alt="twitree" title="twitree" width="300" height="116" class="aligncenter size-medium wp-image-82" /></a></p>
<p><a href="http://twitree.com/">twitree</a> makes extensive use of the <a href="http://developer.yahoo.com/yui">YUI library</a>. The following components were used :</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/grids">grids css</a> - for the layout</li>
<li><a href="http://developer.yahoo.com/yui/yahoo/">yahoo</a> <a href="http://developer.yahoo.com/yui/dom/">dom</a> <a href="http://developer.yahoo.com/yui/event/">event</a> - for DOM and event handling</li>
<li><a href="http://developer.yahoo.com/yui/connection/">connection manager</a> - for AJAX requests like getting the list of followers for a user</li>
<li><a href="http://developer.yahoo.com/yui/container/">container family</a> - to display modal dialogs like prompting for a twitter username, displaying the loading panel</li>
<li><a href="http://developer.yahoo.com/yui/json/">JSON utility</a> - to parse the JSON data twitree receives from the twitter servers</li>
<li><a href="http://developer.yahoo.com/yui/cookie/">cookie utility</a> - to fetch username information from a cookie so that the user doesn't have to input his username every time</li>
<li>and finally the <a href="http://developer.yahoo.com/yui/treeview/">treeview control</a> which provides a nice tree and dynamically loads the data upon clicking on a node</li>
</ul>
<p>The application is very much in an initial phase and there are some limitations, like only 100 followers are being returned, rate limiting, etc...</p>
<p>Stay tuned for further information</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/twitreecom-see-on-which-leaves-the-birds-are/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Alternate colors to table rows with javascript (YUI)</title>
		<link>http://htmlblog.net/alternate-colors-to-table-rows-with-javascript-yui/</link>
		<comments>http://htmlblog.net/alternate-colors-to-table-rows-with-javascript-yui/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 16:49:36 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[alternate rows]]></category>

		<category><![CDATA[table]]></category>

		<category><![CDATA[yahoo]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=71</guid>
		<description><![CDATA[
This article will show you how to add alternate colors to table rows without any server side development or hard coding your scripts, thus providing good readability for your users and great flexibility for you. We will use the YUI library for that.

Demo
Download the demo
The HTML

We need to create our basic HTML file containing a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/demo/alternate/" target="_blank"><img src="http://htmlblog.net/wp-content/uploads/2008/12/colors.png" alt="" title="colors" width="411" height="323" class="aligncenter size-full wp-image-72" /></a></p>
<p>This article will show you how to add alternate colors to table rows without any server side development or hard coding your scripts, thus providing good readability for your users and great flexibility for you. We will use the <a href="http://developer.yahoo.com/yui" target="_blank">YUI library</a> for that.<br />
<span id="more-71"></span></p>
<p><a href="/demo/alternate/" target="_blank">Demo</a><br />
<a href="/demo/alternate/alternate.zip" target="_blank">Download the demo</a></p>
<p style="font-size:20px;font-weight:bold;">The HTML
<p>
We need to create our basic HTML file containing a table and adding a class name to it.</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">&lt;title&gt;</span></a></span>Alternate colors<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">&lt;table</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;alternateRows&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>First Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Second Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Third Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Fourth Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Fifth Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<p style="font-size:20px;font-weight:bold;">The Javascript</p>
<p>Next we need to include the <a href="http://developer.yahoo.com/yui" target="_blank">YUI libraries</a>, served from their <a href="http://developer.yahoo.com/yui/articles/hosting/" target="_blank">CDN</a>. We need the</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/yahoo/" target="_blank">YAHOO global object</a> which contains a number of methods that are used throughout the library</li>
<li><a href="http://developer.yahoo.com/yui/dom/" target="_blank">DOM collection</a> which provides methods that simplify common DOM-scripting tasks, including element positioning and CSS style management</li>
<li><a href="http://developer.yahoo.com/yui/event/" target="_blank">Event utility</a> for various event handling</li>
</ul>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Combo-handled YUI JS files: --&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>And also our javascript file, <a href="/demo/alternate/alternate.zip" target="_blank">alternate.js</a></p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;alternate.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>So our HTML page looks like this:</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Combo-handled YUI JS files: --&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;alternate.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">&lt;title&gt;</span></a></span>Alternate colors<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">&lt;table</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;alternateRows&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>First Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Second Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Third Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Fourth Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Fifth Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<p style="font-size:20px;font-weight:bold;">Invoking the javascript</p>
<p>To add the alternate colors to your table rows, you just have to put the following javascript code in your HTML page.</p>
<pre class="javascript">&nbsp;
	YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">'load'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		YAHOO.<span style="color: #006600;">htmlblog</span>.<span style="color: #006600;">alternateRows</span>.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'alternateRows'</span>, <span style="color: #3366CC;">'#fff'</span>, <span style="color: #3366CC;">'#ccc'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>That means that after the page has been loaded, we call the alternateRows.init function, with 3 parameters:</p>
<ul>
<li>the table class name, in our case it's "alternateRows"</li>
<li>the first color in hex, e.g #fff</li>
<li>the second color in hex, e.g #ccc</li>
</ul>
<p><br/><br />
<br/></p>
<p style="font-size:20px;font-weight:bold;">Our complete HTML page</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Combo-handled YUI JS files: --&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;alternate.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			YAHOO.util.Event.on(window, 'load', function(){
				YAHOO.htmlblog.alternateRows.init('alternateRows', '#fff', '#ccc');
			});
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">&lt;title&gt;</span></a></span>Alternate colors<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">&lt;table</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;alternateRows&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>First Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Second Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Third Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Fourth Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td&gt;</span></a></span>Fifth Row<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<p><a href="/demo/alternate/" target="_blank">Demo</a><br />
<a href="/demo/alternate/alternate.zip" target="_blank">Download the demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/alternate-colors-to-table-rows-with-javascript-yui/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bubble menu javascript or playing with YUI&#8217;s event delegation</title>
		<link>http://htmlblog.net/bubble-menu-javascript-or-playing-with-yuis-event-delegation/</link>
		<comments>http://htmlblog.net/bubble-menu-javascript-or-playing-with-yuis-event-delegation/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 15:10:41 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[event delegation]]></category>

		<category><![CDATA[menu]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=63</guid>
		<description><![CDATA[
Image courtesy of jobee59's photostream
Event delegation refers to the use of a single event listener on a parent object to listen for events happening on its children (or deeper descendants). Event delegation allows developers to be sparse in their application of event listeners while still reacting to events as they happen on highly specific targets. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm1.static.flickr.com/199/469216645_020fc74cce.jpg?v=0" alt="bubble" /><br />
Image courtesy of <a href="http://flickr.com/photos/jobee59/469216645/" target="_blank">jobee59's photostream</a></p>
<p>Event delegation refers to the use of a single event listener on a parent object to listen for events happening on its children (or deeper descendants). Event delegation allows developers to be sparse in their application of event listeners while still reacting to events as they happen on highly specific targets. This proves to be a key strategy for maintaining high performance in event-rich web projects, where the creation of hundreds of event listeners can quickly degrade performance. <a href="http://developer.yahoo.com/yui/examples/event/event-delegation.html" target="_blank">More on event delegation including examples</a>.</p>
<p>This post illustrates the use of event delegation to create a "bubble" menu, inspired by <a href="http://nettuts.com/html-css-techniques/how-to-create-a-mootools-homepage-inspired-navigation-effect-using-jquery/" target="_blank">Bedrich Rios' post on Nettuts</a>.<br />
<span id="more-63"></span><br />
<a href="/demo/bubble/" target="_blank">Demo</a><br />
<a href="/demo/bubble/bubble.zip">Download sample file</a><br />
<br/><br />
<br/></p>
<p class="headline"><strong>The HTML</strong></p>
<p>We'll need the following components from the <a href="http://developer.yahoo.com/yui" target="_blank">YUI library</a>:</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/dom/" target="_blank">yahoo-dom-event</a> - for DOM/Event handling</li>
<li><a href="http://developer.yahoo.com/yui/animation/" target="_blank">animation</a> - for sliding effects </li>
</ul>
<p>So our basic HTML page is like this:</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Combo-handled YUI JS files: --&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.6.0/build/animation/animation-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<p>Next we'll add some structural markup, a simple list, with "menu" as class name and with 5 items.</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">&lt;ul</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;menu&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span>
&nbsp;</pre>
<p>Updated HTML page:</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Combo-handled YUI JS files: --&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.6.0/build/animation/animation-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">&lt;ul</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;menu&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<p class="headline"><strong>The Javascript</strong></p>
<p>Then we just have to add the <a href="/demo/bubble/bubble.zip" target="_blank">bubble.js</a> javascript file to our page and it's done, we'll have a nice "bubble" menu.</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Combo-handled YUI JS files: --&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.6.0/build/animation/animation-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- our bubble file --&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;bubble.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">&lt;ul</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;menu&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span>Menu item 5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<p class="headline"><strong>bubble.js</strong></p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/**
*	Bubble Menu
*	@author Asvin Balloo (http://htmlblog.net)
*/</span>
bubbleMenu = <span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// private variables</span>
	<span style="color: #009900; font-style: italic;">// class name of our menu</span>
	menuClassName: <span style="color: #003366; font-weight: bold;">null</span>,
	<span style="color: #009900; font-style: italic;">// by how much we are sliding</span>
	moveToLength : <span style="color: #CC0000;">10</span>,
&nbsp;
	<span style="color: #009900; font-style: italic;">/**
	*	Init the whole process here
	*	@method init
	*	@params menuClassName {string} class name of our menus
	*/</span>
	init: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>menuClassName<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// set our class name to be used later one</span>
		bubbleMenu.<span style="color: #006600;">menuClassName</span> = menuClassName;
&nbsp;
		<span style="color: #009900; font-style: italic;">// get all the lists with the class name</span>
		<span style="color: #003366; font-weight: bold;">var</span> list = YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">getElementsByClassName</span><span style="color: #66cc66;">&#40;</span>menuClassName<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #009900; font-style: italic;">// loop through them</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i=<span style="color: #CC0000;">0</span>; i
&lt;list.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// add the onmouseover event to it, call the mouseOverHandler function</span>
			YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span>list<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>, <span style="color: #3366CC;">&quot;mouseover&quot;</span>, bubbleMenu.<span style="color: #006600;">mouseOverHandler</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #009900; font-style: italic;">// get the first child and its padding left for future reference. Useful when using onmouseout to </span>
&nbsp;
restore the <span style="color: #000066; font-weight: bold;">item</span> to original state
			<span style="color: #003366; font-weight: bold;">var</span> listItems = list<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #003366; font-weight: bold;">var</span> startingPadding = parseInt<span style="color: #66cc66;">&#40;</span>YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">getStyle</span><span style="color: #66cc66;">&#40;</span>listItems<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #3366CC;">'paddingLeft'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #009900; font-style: italic;">// add the onmouseout event, call the mouseOutHandler function</span>
			YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span>list<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>, <span style="color: #3366CC;">&quot;mouseout&quot;</span>, bubbleMenu.<span style="color: #006600;">mouseOutHandler</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">'list'</span>:list<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>, <span style="color: #3366CC;">&quot;padding&quot;</span> : 
&nbsp;
startingPadding<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>,
&nbsp;
	<span style="color: #009900; font-style: italic;">/**
	*	Mouse over handler
	*	@params e {Event} the event
	*/</span>
	mouseOverHandler: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// get the target</span>
		<span style="color: #003366; font-weight: bold;">var</span> elTarget = YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">getTarget</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #009900; font-style: italic;">// calculate the current padding left</span>
		<span style="color: #003366; font-weight: bold;">var</span> paddingLeft = parseInt<span style="color: #66cc66;">&#40;</span>YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">getStyle</span><span style="color: #66cc66;">&#40;</span>elTarget, <span style="color: #3366CC;">'paddingLeft'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #009900; font-style: italic;">// call the delegate method, with the target and the padding left value</span>
		bubbleMenu.<span style="color: #006600;">delegate</span><span style="color: #66cc66;">&#40;</span>elTarget, paddingLeft<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>,
&nbsp;
	<span style="color: #009900; font-style: italic;">/**
	*	Mouse out handler
	*	@params e {Event} the event
	*	@params o {JSON} JSON data containing the list + padding value, eg. {'list': mylist, 'padding': 10}
	*/</span>
	mouseOutHandler: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e, o<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// get the target</span>
		<span style="color: #003366; font-weight: bold;">var</span> elTarget = YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">getTarget</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #009900; font-style: italic;">// calculate the left padding, the original padding value - by how much we have padded</span>
		<span style="color: #003366; font-weight: bold;">var</span> paddingLeft = o.<span style="color: #006600;">padding</span> - bubbleMenu.<span style="color: #006600;">moveToLength</span>;
&nbsp;
		<span style="color: #009900; font-style: italic;">// call the delegate method with the target and padding value</span>
		bubbleMenu.<span style="color: #006600;">delegate</span><span style="color: #66cc66;">&#40;</span>elTarget, paddingLeft<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>,
&nbsp;
	<span style="color: #009900; font-style: italic;">/**
	*	Cool things go here, like animation
	*	@params elTarget {Target} our target
	*	@params padding {Int} by how much we are going to padd
	*/</span>
	delegate: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>elTarget, padding<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">//walk up the DOM tree looking for an &lt;li&gt; in the target's ancestry; desist when you reach the container with our class name</span>
		<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>elTarget.<span style="color: #006600;">className</span> != bubbleMenu.<span style="color: #006600;">menuClassName</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// are you an LI?</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>elTarget.<span style="color: #006600;">nodeName</span>.<span style="color: #006600;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #3366CC;">&quot;LI&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// if so then animate, set the attributes, in our case the left padding</span>
				<span style="color: #003366; font-weight: bold;">var</span> attributes = <span style="color: #66cc66;">&#123;</span> paddingLeft: <span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;to&quot;</span>: <span style="color: #66cc66;">&#91;</span>padding + bubbleMenu.<span style="color: #006600;">moveToLength</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#125;</span>;
&nbsp;
				<span style="color: #009900; font-style: italic;">// create our animation</span>
				<span style="color: #003366; font-weight: bold;">var</span> anim = <span style="color: #003366; font-weight: bold;">new</span> YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Motion</span><span style="color: #66cc66;">&#40;</span>elTarget, attributes, <span style="color: #CC0000;">0.6</span>, YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Easing</span>.<span style="color: #006600;">bounceOut</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #009900; font-style: italic;">// then animate</span>
				anim.<span style="color: #006600;">animate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000066; font-weight: bold;">break</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// it's not an li, so we keep looking and looking</span>
	            elTarget = elTarget.<span style="color: #006600;">parentNode</span>;
	        <span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// init the whole thing here</span>
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">&quot;load&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	bubbleMenu.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;menu&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>You can have unlimited (don't abuse) number of bubble menus by just adding the "menu" class to each one of them and including the bubble.js file.<br />
If you're not happy with the menu class or you found another cool class name, then you'll have to update the bubble.js file towards the end:</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// init the whole thing here</span>
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">&quot;load&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	bubbleMenu.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;mycoolclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Also you can modify by how much an item slides by modifying the moveToLength variable (default 10):</p>
<pre class="javascript">&nbsp;
&nbsp;
<span style="color: #009900; font-style: italic;">// by how much we are sliding</span>
moveToLength : <span style="color: #CC0000;">30</span>,
&nbsp;</pre>
<p>Note that the demo is using reset-fonts-grids CSS and the page has been styled with the following:</p>
<pre class="css">&nbsp;
body <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span>: <span style="color: #933;">0</span>;
	<span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #933;">0</span>;
	<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#1d1d1d</span>;
	<span style="color: #000000; font-weight: bold;">font-family</span>: <span style="color: #ff0000;">&quot;Lucida Grande&quot;</span>, Verdana, <span style="color: #993333;">sans-serif</span>;
	<span style="color: #000000; font-weight: bold;">font-size</span>: <span style="color: #933;"><span style="color: #933;">100</span>%</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.menu</span> li<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding-left</span>: <span style="color: #933;">20px</span>;
	<span style="color: #000000; font-weight: bold;">line-height</span>: <span style="color: #933;">2em</span>;
	<span style="color: #000000; font-weight: bold;">width</span>: <span style="color: #933;">150px</span>;
	<span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #cc00cc;">#<span style="color: #933;">999</span></span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#<span style="color: #933;">222</span></span>;
	<span style="color: #000000; font-weight: bold;">border</span>: <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#1a1a1a</span>;
	-moz-border-radius: <span style="color: #933;">10px</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/bubble-menu-javascript-or-playing-with-yuis-event-delegation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>8 practical tips to make your web pages faster</title>
		<link>http://htmlblog.net/8-practical-tips-to-make-your-web-pages-faster/</link>
		<comments>http://htmlblog.net/8-practical-tips-to-make-your-web-pages-faster/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 16:36:23 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[best practices]]></category>

		<category><![CDATA[fast]]></category>

		<category><![CDATA[html]]></category>

		<category><![CDATA[mod_deflate]]></category>

		<category><![CDATA[mod_expires]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[speed up]]></category>

		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=40</guid>
		<description><![CDATA[

Yahoo's Exceptional Performance team has compiled a list of 34 best practices to have faster web pages. In this post I'll show you 8 tips which helped me to get a B grade in YSlow! for web pages that I develop. Currently YSlow's web page analysis is based on 13 identified basic rules that affect [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm4.static.flickr.com/3062/2520059957_ae331ae75a.jpg?v=0" alt="" /></p>
<div style="clear:both"></div>
<p><a href="http://developer.yahoo.com/performance/rules.html" target="_blank">Yahoo's Exceptional Performance team</a> has compiled a list of <a href="http://developer.yahoo.com/performance/rules.html" target="_blank">34 best practices</a> to have faster web pages. In this post I'll show you 8 tips which helped me to get a B grade in <a href="http://developer.yahoo.com/yslow/" target="_blank">YSlow!</a> for web pages that I develop. Currently YSlow's web page analysis is based on 13 identified basic rules that affect web page performance. In decreasing order of priority they are:</p>
<ol>
<li><a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank">Make Fewer HTTP Requests</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#cdn" target="_blank">Use a Content Delivery Network</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#expires" target="_blank">Add an Expires Header</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#gzip" target="_blank">Gzip Components</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#css_top" target="_blank">Put CSS at the Top</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#js_bottom" target="_blank">Move Scripts to the Bottom</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#css_expressions" target="_blank">Avoid CSS Expressions</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#external" target="_blank">Make JavaScript and CSS External</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#dns_lookups" target="_blank">Reduce DNS Lookups</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#minify" target="_blank">Minify JavaScript</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#redirects" target="_blank">Avoid Redirects</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#js_dupes" target="_blank">Remove Duplicate Scripts</a></li>
<li><a href="http://developer.yahoo.com/performance/rules.html#etags" target="_blank">Configure ETags</a></li>
</ol>
<p>You can get more info by clicking on each item. Of course using a <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network" target="_blank">CDN</a> is not affordable by everybody, including me. This didn't prevent me to have a B grade though. I will guide you through some of the items which worked for me.<br />
<span id="more-40"></span></p>
<hr/>
<strong>Make Fewer HTTP Requests</strong><br />
If you're using the <a href="http://developer.yahoo.com" target="_blank">YUI library</a>, the good news is that recently the team graciously offered a <a href="http://developer.yahoo.com/yui/articles/hosting/" target="_blank">Combo Handler Service</a>, served from their CDN. This helps us to eliminate HTTP requests by requesting a single file. For example, to use the <a href="http://developer.yahoo.com/yui/editor/" target="_blank">Rich Text editor</a>, it needed 6 separate HTTP requests:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/container/container_core-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/menu/menu-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/element/element-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/button/button-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/editor/editor-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>Now with the Combo Handler service, it has been stripped to only 1 file:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/container/container_core-min.js&amp;2.5.2/build/menu/menu-min.js&amp;2.5.2/build/element/element-beta-min.js&amp;2.5.2/build/button/button-min.js&amp;2.5.2/build/editor/editor-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>If you're not using the YUI library or not interested in using the Combo Handler service, you can try <a href="http://code.google.com/p/minify/" target="_blank">Minify!</a><br />
<a href="http://code.google.com/p/minify/" target="_blank">Minify</a> is a <a href="http://php.net" target="_blank">PHP5</a> app that can combine multiple CSS or Javascript files, compress their contents (i.e. removal of unnecessary whitespace/comments), and serve the results with HTTP encoding (gzip/deflate) and headers that allow optimal client-side caching.</p>
<p>Another tool which can be helpful is <a href="http://shrinksafe.dojotoolkit.org/" target="_blank">Dojo Shrinksafe</a> which not only minifies your javascript code but also allows you to upload several javascript files and have them compressed in 1 single file.</p>
<p>Another way to make fewer HTTP requests is by using CSS sprites which are big images containing lots of smaller ones. An online tool which can make CSS sprites out of your smaller ones is the <a href="http://spritegen.website-performance.org/" target="_blank">CSS Sprite Generator</a>. You just have to upload your pics and it will generate your sprite together with the CSS code. More info about CSS sprites can be found on <a href="http://css-tricks.com/css-sprites-what-they-are-why-theyre-cool-and-how-to-use-them/" target="_blank">CSS Tricks</a>.</p>
<hr/>
<strong>Add an Expires Header</strong><br />
For this to work on Apache, you'll need to have <a href="http://httpd.apache.org/docs/2.0/mod/mod_expires.html" target="_blank">mod_expires</a> enabled. Then create an .htaccess file or edit your httpd.conf with the following content:</p>
<pre class="apache">&nbsp;
<span style="color: #00007f;">ExpiresActive</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">ExpiresByType</span> image/jpg <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByType</span> image/jpeg <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByType</span> image/gif <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByType</span> application/javascript <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
<span style="color: #00007f;">ExpiresByTYpe</span> text/css <span style="color: #7f007f;">&quot;access plus 2 years&quot;</span>
&nbsp;</pre>
<p>In the above listing, all images(jpg/jpeg/gif) will have an expires header 2 years in the future.</p>
<hr/>
<strong>Gzip Components</strong><br />
You must have <a href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html" target="_blank">mod_deflate</a> enabled and drop these lines in your httpd.conf file</p>
<pre class="apache">&nbsp;
SetOutputFilter DEFLATE
<span style="color: #00007f;">SetEnvIfNoCase</span> Request_URI \.<span style="color: #66cc66;">&#40;</span>?:gif|jpe?g|png<span style="color: #66cc66;">&#41;</span>$ no-gzip dont-vary
<span style="color: #00007f;">SetEnvIfNoCase</span> Request_URI \.<span style="color: #66cc66;">&#40;</span>?:exe|t?gz|zip|bz2|sit|rar<span style="color: #66cc66;">&#41;</span>$ no-gzip dont-vary
<span style="color: #00007f;">SetEnvIfNoCase</span> Request_URI \.pdf$ no-gzip dont-vary
&nbsp;</pre>
<hr/>
<strong>Put CSS at the Top</strong><br />
All CSS must be between your head tag, like that :</p>
<pre class="html4strict">&nbsp;
	<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">&lt;link</span></a> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span>=<span style="color: #ff0000;">&quot;screen&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
&nbsp;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<hr/>
<strong>Move Scripts to the Bottom</strong><br />
While the CSS are sitting at the top of your page, javascripts must be moved towards the lower part of your page, typically in the body tag. I usually put them before the closing body tag.</p>
<pre class="html4strict">&nbsp;
	<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
		<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
		...
		...
		<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;myjs.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span>
&nbsp;</pre>
<hr/>
<strong>Reduce DNS Lookups</strong><br />
I don't usually have more than 2 DNS lookups in my scripts, else YSlow will be removing some points.</p>
<hr/>
<strong>Minify JavaScript</strong><br />
As I mentioned earlier on, <a href="http://shrinksafe.dojotoolkit.org/" target="_blank">Dojo Shrinksafe</a> is an online tool which minifies your code.</p>
<p>Another great command line tool is <a href="http://www.julienlecomte.net/blog/2007/08/11/" target="_blank">Julien Lecomte YUI Compressor</a>. </p>
<p>In order to use it you must have <a href="http://java.sun.com" target="_blank">Java</a> installed (>= 1.4).</p>
<p><a href="http://www.crockford.com/" target="_blank">Douglas Crockford</a> also has something similar in <a href="http://www.crockford.com/javascript/jsmin.html" target="_blank">JSMin</a></p>
<hr/>
<strong>Configure ETags</strong><br />
Just drop this line in your httpd.conf:</p>
<pre class="apache">&nbsp;
FileETag <span style="color: #0000ff;">None</span>
&nbsp;</pre>
<p>;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/8-practical-tips-to-make-your-web-pages-faster/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pixidou - an Open Source AJAX Image Editor (PHP and YUI based)</title>
		<link>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/</link>
		<comments>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 17:42:09 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[brightness]]></category>

		<category><![CDATA[contrast]]></category>

		<category><![CDATA[crop]]></category>

		<category><![CDATA[flip]]></category>

		<category><![CDATA[free]]></category>

		<category><![CDATA[image]]></category>

		<category><![CDATA[image editor]]></category>

		<category><![CDATA[negative]]></category>

		<category><![CDATA[open source]]></category>

		<category><![CDATA[resize]]></category>

		<category><![CDATA[rotate]]></category>

		<category><![CDATA[tint]]></category>

		<category><![CDATA[upload]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=37</guid>
		<description><![CDATA[Pixidou is a new open source AJAX image editor which will allow you to :

adjust brightness
adjust contrast
cropping
flipping
negative
resizing
rotating
tint

images.

What you need to get running

PHP5.2+ installed on your webserver
GD2
a web browser

Demo
Installation
Unzip/untar the software in your web directory and that's all ;-)
Also ensure the images folder is writable by your webserver.
Have fun !!!
Download
Get it and follow it at github
All [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Pixidou </strong>is a new open source AJAX image editor which will allow you to :</p>
<ul>
<li>adjust brightness</li>
<li>adjust contrast</li>
<li>cropping</li>
<li>flipping</li>
<li>negative</li>
<li>resizing</li>
<li>rotating</li>
<li>tint</li>
</ul>
<p>images.<br />
<span id="more-37"></span><br />
<strong>What you need to get running</strong></p>
<ul>
<li>PHP5.2+ installed on your webserver</li>
<li>GD2</li>
<li>a web browser</li>
</ul>
<p><strong><a href="http://htmlblog.net/demo/pixidou">Demo</a></strong></p>
<p><strong>Installation</strong><br />
Unzip/untar the software in your web directory and that's all ;-)<br />
Also ensure the images folder is writable by your webserver.<br />
Have fun !!!</p>
<p><strong>Download</strong><br />
<a href="http://github.com/asvinb/pixidou/tree/master" target="_blank">Get it and follow it at github</a></p>
<p>All the image manipulation is <a href="http://php.net">PHP-based</a> with the help of the great <a href="http://www.verot.net/php_class_upload.htm" target="_blank">class.upload.php</a> class by Colin Verot which I highly recommend.</p>
<p>The frontend is the most interesting part, where I've use the one and only <a href="http://developer.yahoo.com/yui">YUI library</a>. Here are the component I used (served from Yahoo CDN) :</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/reset/" target="_blank">reset-fonts.css</a> -  for all resetting, style information</li>
<li>utilities - for all AJAX, animation, drag drop, event handling stuff</li>
<li><a href="http://developer.yahoo.com/yui/container/" target="_blank">container</a> - for all panels, dialogs, alerts</li>
<li><a href="http://developer.yahoo.com/yui/menu/" target="_blank">menu</a> - for the top navigation menu together with the submenus</li>
<li><a href="http://developer.yahoo.com/yui/button/" target="_blank">button</a> - provides nice buttons</li>
<li><a href="http://developer.yahoo.com/yui/slider/" target="_blank">slider</a> - for adjusting contrast and brightness</li>
<li><a href="http://developer.yahoo.com/yui/colorpicker/" target="_blank">color picker</a> - to choose the color to tint the image</li>
<li><a href="http://developer.yahoo.com/yui/resize/" target="_blank">resize</a> - to resize the image</li>
<li><a href="http://developer.yahoo.com/yui/imagecropper/" target="_blank">image cropper</a> - image cropping utility</li>
<li><a href="http://developer.yahoo.com/yui/json/" target="_blank">json</a> - to parse all JSON data returned from PHP scripts</li>
<li><a href="http://developer.yahoo.com/yui/layout/" target="_blank">layout</a> - the general layout
<li>
<li><a href="http://developer.yahoo.com/yui/tabview/" target="_blank">tabview</a> - for the about information</li>
</ul>
<p>I've not used the <a href="http://developer.yahoo.com/yui/grids/">grids.css</a> since it caused some problems while using the color picker.</p>
<p>It's only the beginning of <strong>Pixidou </strong>and I'am currently looking for some collaborators. So, if you think you can give a helping hand in any way to <strong>Pixidou</strong>, don't hesitate to contact me (asvin.balloo [@] gmail.com), I'll happily add you as a contributor to the repository on github.</p>
<p>Since it's an early version, there must be some bugs lying everywhere, don't hesitate to drop me an email.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/feed/</wfw:commentRss>
		</item>
		<item>
		<title>AJAX image cropper with YUI and PHP</title>
		<link>http://htmlblog.net/ajax-image-cropper-with-yui-and-php/</link>
		<comments>http://htmlblog.net/ajax-image-cropper-with-yui-and-php/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 11:01:55 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[crop]]></category>

		<category><![CDATA[gd]]></category>

		<category><![CDATA[image cropper]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=35</guid>
		<description><![CDATA[

This post will show you how to build an AJAX crop image tool using the image cropper control from YUI library and PHP.
Demo
Download sample file

The ImageCropper Control from the YUI library gives you an interactive interface for getting the dimensions to crop an image and using these dimensions in PHP, we can do some cropping.
The [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://htmlblog.net/wp-content/uploads/2008/10/cropper.png" alt="" title="cropper" width="500" height="270" class="alignleft size-full wp-image-36" /></p>
<div style="clear:both"></div>
<p>This post will show you how to build an AJAX crop image tool using the image cropper control from YUI library and PHP.</p>
<p><strong><a href="http://htmlblog.net/demo/cropper/" target="_blank">Demo</a></strong><br />
<strong><a href="http://htmlblog.net/demo/cropper/cropper.zip">Download sample file</a></strong><br />
<span id="more-35"></span><br />
The <a href="http://developer.yahoo.com/yui/imagecropper/">ImageCropper Control</a> from the <a href="http://developer.yahoo.com/yui/">YUI library</a> gives you an interactive interface for getting the dimensions to crop an image and using these dimensions in <a href="http://php.net">PHP</a>, we can do some cropping.</p>
<p>The script we are going to build will </p>
<ul>
<li>allow users to upload an image via AJAX</li>
<li>then allow them to select an area for cropping</li>
<li>lastly, provide a download link for the cropped image.</li>
</ul>
<p>There are 3 files we are going to use </p>
<ul>
<li>index.php - will contain the form for image upload as well as the cropping interface</li>
<li>upload.php - provides uploading functionality</li>
<li>crop.php - provides cropping functionality</li>
</ul>
<p>From a technical point of view, the flow will be like this :</p>
<ol>
<li>user uploads jpg image (index.php)</li>
<li>index.php then posts the image asynchronously to upload.php which will do the upload on the server, returning JSON data containing the image file name, its width and its height.</li>
<li>with the JSON data and innerHTML we put the image in our page</li>
<li>initialize the javascript cropping tool</li>
<li>generate a download link (crop.php)</li>
</ol>
<p><strong><br />
Let's have a look at index.php</strong><br />
The index.php is our main file where users will be able upload images and then download the cropped ones. </p>
<p>We'll need the following components from the YUI library :</p>
<ul>
<li>yahoo-dom-event.js - for DOM manipulation and Event handling</li>
<li>dragdrop - dependency for the image cropper control</li>
<li>element - dependency for the image cropper control</li>
<li>resize - dependency for the image cropper control</li>
<li>connection - for AJAX requests, in our case for image uploads via AJAX</li>
<li>json - for parsing JSON data</li>
<li>imagecropper - our most important control</li>
</ul>
<p>Of course we'll use <a href="http://developer.yahoo.com/yui/articles/hosting/">Yahoo combo handling</a> and add the js to our page along with the CSS needed for the above controls :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">&lt;link</span></a> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/resize/assets/skins/sam/resize.css&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/link.html"><span style="color: #000000; font-weight: bold;">&lt;link</span></a> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.5.2/build/imagecropper/assets/skins/sam/imagecropper.css&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- js --&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/dragdrop/dragdrop-min.js&amp;2.5.2/build/element/element-beta-min.js&amp;2.5.2/build/resize/resize-beta-min.js&amp;2.5.2/build/imagecropper/imagecropper-beta-min.js&amp;2.
5.2/build/connection/connection-min.js&amp;2.5.2/build/json/json-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>Next users must be able to upload images via AJAX, so we add a form to our page:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">&lt;form</span></a> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;upload.php&quot;</span> <span style="color: #000066;">enctype</span>=<span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;uploadForm&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;uploadForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	Image :
<span style="color: #009900;"><a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">&lt;input</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;uploadImage&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;uploadImage&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">&lt;input</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;uploadButton&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Upload&quot;</span>/<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form&gt;</span></span>
&nbsp;</pre>
<p>We have an onclick event to the upload button to fire the uploading process.</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// add listeners</span>
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'uploadButton'</span>, <span style="color: #3366CC;">'click'</span>, uploader.<span style="color: #006600;">carry</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We'll also need 2 containers :</p>
<ul>
<li>imageContainer - will contain our uploaded image</li>
<li>downloadLink - will contain the download link</li>
</ul>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;imageContainer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;downloadLink&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>Both containers will be updated via innerHTML afterwards.</p>
<p>AJAX upload<br />
For the AJAX upload, <a href="http://thecodecentral.com/2007/09/04/asynchronous-file-upload-yuis-approach">Code Central</a> </p>
<p>has an excellent tutorial which I highly recommend. I took the code sample and modified it a bit to fit my needs. Finally I came up with a nice <a href="http://json.org/">JSON object</a> called uploader which has one method, carry. The latter just posts form data to a specified URL.</p>
<pre class="javascript">&nbsp;
uploader = <span style="color: #66cc66;">&#123;</span>
	carry: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// set form</span>
		YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Connect</span>.<span style="color: #006600;">setForm</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'uploadForm'</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #009900; font-style: italic;">// upload image</span>
		YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Connect</span>.<span style="color: #006600;">asyncRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'POST'</span>, <span style="color: #3366CC;">'upload.php'</span>, <span style="color: #66cc66;">&#123;</span>
			upload: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// parse our json data</span>
				<span style="color: #003366; font-weight: bold;">var</span> jsonData = YAHOO.<span style="color: #006600;">lang</span>.<span style="color: #006600;">JSON</span>.<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">responseText</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #009900; font-style: italic;">// put image in our image container</span>
				YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'imageContainer'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">'&lt;img id=&quot;yuiImg&quot; src=&quot;'</span> + jsonData.<span style="color: #006600;">image</span> + <span style="color: #3366CC;">'&quot; width=&quot;'</span> + jsonData.<span style="color: #006600;">width</span> + <span style="color: #3366CC;">'&quot; height=&quot;'</span> + jsonData.<span style="color: #006600;">height</span> + <span style="color: #3366CC;">'&quot; alt=&quot;&quot; /&gt;'</span>;
&nbsp;
				<span style="color: #009900; font-style: italic;">// init our photoshop</span>
				photoshop.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span>jsonData.<span style="color: #006600;">image</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
				<span style="color: #009900; font-style: italic;">// get first cropped image</span>
				photoshop.<span style="color: #006600;">getCroppedImage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>When upload is complete, we get the JSON data we mentioned earlier on. For e.g :</p>
<pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;image&quot;</span> : <span style="color: #3366CC;">&quot;images/myimage.jpg&quot;</span>, <span style="color: #3366CC;">&quot;width&quot;</span> : <span style="color: #3366CC;">&quot;500&quot;</span>, <span style="color: #3366CC;">&quot;height&quot;</span> : <span style="color: #CC0000;">400</span><span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>With this data and using innerHTML we update our imageContainer div to put our image which will have yuiImg as id :</p>
<pre class="javascript">&nbsp;
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'imageContainer'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">'&lt;img id=&quot;yuiImg&quot; src=&quot;'</span> + jsonData.<span style="color: #006600;">image</span> + <span style="color: #3366CC;">'&quot; width=&quot;'</span> + jsonData.<span style="color: #006600;">width</span> + <span style="color: #3366CC;">'&quot; height=&quot;'</span> + jsonData.<span style="color: #006600;">height</span> + <span style="color: #3366CC;">'&quot; alt=&quot;&quot; /&gt;'</span>;
&nbsp;</pre>
<p>It's very important to specify the image width and height else the image cropper won't work.<br />
Next we initialize another JSON object, photoshop which we'll have a look now.</p>
<p>Our photoshop object</p>
<pre class="javascript">&nbsp;
photoshop = <span style="color: #66cc66;">&#123;</span>
	image: <span style="color: #003366; font-weight: bold;">null</span>,
	crop: <span style="color: #003366; font-weight: bold;">null</span>,
&nbsp;
	init: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// set our image</span>
		photoshop.<span style="color: #006600;">image</span> = image;
&nbsp;
		<span style="color: #009900; font-style: italic;">// our image cropper from the uploaded image</span>
		photoshop.<span style="color: #006600;">crop</span> = <span style="color: #003366; font-weight: bold;">new</span> YAHOO.<span style="color: #006600;">widget</span>.<span style="color: #006600;">ImageCropper</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'yuiImg'</span><span style="color: #66cc66;">&#41;</span>;
		photoshop.<span style="color: #006600;">crop</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'moveEvent'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// get updated coordinates</span>
			photoshop.<span style="color: #006600;">getCroppedImage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>,
&nbsp;
	getCroppedImage: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordinates = photoshop.<span style="color: #006600;">getCoordinates</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #003366; font-weight: bold;">var</span> url = <span style="color: #3366CC;">'crop.php?image='</span> + photoshop.<span style="color: #006600;">image</span> + <span style="color: #3366CC;">'&amp;cropStartX='</span> + coordinates.<span style="color: #006600;">left</span> +<span style="color: #3366CC;">'&amp;cropStartY='</span> + coordinates.<span style="color: #006600;">top</span> +<span style="color: #3366CC;">'&amp;cropWidth='</span> + coordinates.<span style="color: #006600;">width</span> +<span style="color: #3366CC;">'&amp;cropHeight='</span> + coordinates.<span style="color: #006600;">height</span>;
		YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'downloadLink'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">'&lt;a href=&quot;'</span> + url + <span style="color: #3366CC;">'&quot;&gt;download cropped image&lt;/a&gt;'</span>;		
&nbsp;
	<span style="color: #66cc66;">&#125;</span>,
&nbsp;
	getCoordinates: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> photoshop.<span style="color: #006600;">crop</span>.<span style="color: #006600;">getCropCoords</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>The init function iniatializes the YUI image cropper from the uploaded image which has yuiImg as id.</p>
<pre class="javascript">&nbsp;
photoshop.<span style="color: #006600;">crop</span> = <span style="color: #003366; font-weight: bold;">new</span> YAHOO.<span style="color: #006600;">widget</span>.<span style="color: #006600;">ImageCropper</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'yuiImg'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We also subscribe to the moveEvent for the cropper since we'll need to update the download link for the cropped image. So whenever the image cropper is moved/resized, we call the getCroppedImage function.</p>
<pre class="javascript">&nbsp;
photoshop.<span style="color: #006600;">crop</span>.<span style="color: #006600;">on</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'moveEvent'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// get updated coordinates</span>
	photoshop.<span style="color: #006600;">getCroppedImage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>The getCroppedImage function will generate the download link for the cropped image. To do image cropping in <a href="http://php.net">PHP</a> we'll need</p>
<ul>
<li>the image we want to crop</li>
<li>the X,Y coordinates</li>
<li>height and width of the to be cropped area</li>
</ul>
<p>Fortunately the YUI cropper utility has a function which will give us what we want, it's the getCropCoords() method. So, whenever the getCroppedImage function is called, we get the coordinates of the cropped area, build a URL and finally put the download link in our downloadLink container.</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// get coordinates</span>
<span style="color: #003366; font-weight: bold;">var</span> coordinates = photoshop.<span style="color: #006600;">getCoordinates</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// build our url</span>
<span style="color: #003366; font-weight: bold;">var</span> url = <span style="color: #3366CC;">'crop.php?image='</span> + photoshop.<span style="color: #006600;">image</span> + <span style="color: #3366CC;">'&amp;cropStartX='</span> + coordinates.<span style="color: #006600;">left</span> +<span style="color: #3366CC;">'&amp;cropStartY='</span> + coordinates.<span style="color: #006600;">top</span> +<span style="color: #3366CC;">'&amp;cropWidth='</span> + coordinates.<span style="color: #006600;">width</span> +<span style="color: #3366CC;">'&amp;cropHeight='</span> + coordinates.<span style="color: #006600;">height</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// put download link in our page</span>
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Dom</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'downloadLink'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">'&lt;a href=&quot;'</span> + url + <span style="color: #3366CC;">'&quot;&gt;download cropped image&lt;/a&gt;'</span>;
&nbsp;</pre>
<p>This is all we need for the index page.</p>
<p><strong>upload.php</strong></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;uploadImage&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  	<span style="color: #808080; font-style: italic;">// get file name</span>
	<span style="color: #0000ff;">$filename</span> = <a href="http://www.php.net/basename"><span style="color: #000066;">basename</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'uploadImage'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// get extension</span>
  	<span style="color: #0000ff;">$ext</span> = <a href="http://www.php.net/substr"><span style="color: #000066;">substr</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span>, <a href="http://www.php.net/strrpos"><span style="color: #000066;">strrpos</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span>, <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  	<span style="color: #808080; font-style: italic;">// check for jpg only</span>
  	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ext</span> == <span style="color: #ff0000;">&quot;jpg&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      		<span style="color: #808080; font-style: italic;">// generate unique file name</span>
  		<span style="color: #0000ff;">$newName</span> = <span style="color: #ff0000;">'images/'</span>.<a href="http://www.php.net/time"><span style="color: #000066;">time</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'.'</span>.<span style="color: #0000ff;">$ext</span>;
&nbsp;
  		<span style="color: #808080; font-style: italic;">// upload files</span>
        	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/move_uploaded_file"><span style="color: #000066;">move_uploaded_file</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'uploadImage'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'tmp_name'</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #0000ff;">$newName</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        		<span style="color: #808080; font-style: italic;">// get height and width for image uploaded</span>
        		<a href="http://www.php.net/list"><span style="color: #000066;">list</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span> = <a href="http://www.php.net/getimagesize"><span style="color: #000066;">getimagesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newName</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        		<span style="color: #808080; font-style: italic;">// return json data</span>
           		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'{&quot;image&quot; : &quot;'</span>.<span style="color: #0000ff;">$newName</span>.<span style="color: #ff0000;">'&quot;, &quot;height&quot; : &quot;'</span>.<span style="color: #0000ff;">$height</span>.<span style="color: #ff0000;">'&quot;, &quot;width&quot; : &quot;'</span>.<span style="color: #0000ff;">$width</span>.<span style="color: #ff0000;">'&quot; }'</span>;
        	<span style="color: #66cc66;">&#125;</span>
        	<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
           		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'{&quot;error&quot; : &quot;An error occurred while moving the files&quot;}'</span>;
        	<span style="color: #66cc66;">&#125;</span>
  	<span style="color: #66cc66;">&#125;</span>
  	<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
     		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'{&quot;error&quot; : &quot;Invalid image format&quot;}'</span>;
  	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>The upload.php file too is self explanatory, we check for a jpg image only, then generate an unique filename, put it in the images folder and finally build json data which we'll use for DOM manipulation. Of course the images folder must be writable by the web server.</p>
<p><strong>crop.php</strong></p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// get variables</span>
<span style="color: #0000ff;">$imgfile</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'image'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropStartX</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropStartX'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropStartY</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropStartY'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropW</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropWidth'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropH</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropHeight'</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Create two images</span>
<span style="color: #0000ff;">$origimg</span> = imagecreatefromjpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$imgfile</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$cropimg</span> = imagecreatetruecolor<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cropW</span>,<span style="color: #0000ff;">$cropH</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Get the original size</span>
<a href="http://www.php.net/list"><span style="color: #000066;">list</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span> = <a href="http://www.php.net/getimagesize"><span style="color: #000066;">getimagesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$imgfile</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Crop</span>
imagecopyresized<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cropimg</span>, <span style="color: #0000ff;">$origimg</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0000ff;">$cropStartX</span>, <span style="color: #0000ff;">$cropStartY</span>, <span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$height</span>, <span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// force download nes image</span>
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/jpeg&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Content-Disposition: attachment; filename=&quot;'</span>.<span style="color: #0000ff;">$imgfile</span>.<span style="color: #ff0000;">'&quot;'</span><span style="color: #66cc66;">&#41;</span>;
imagejpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cropimg</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// destroy the images</span>
imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cropimg</span><span style="color: #66cc66;">&#41;</span>;
imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$origimg</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Crop.php allows us to crop our uploaded image. First we get all the variables passed to us via the AJAX request,</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// get variables</span>
<span style="color: #0000ff;">$imgfile</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'image'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropStartX</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropStartX'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropStartY</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropStartY'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropW</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropWidth'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$cropH</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'cropHeight'</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;</pre>
<p>Then we create 2 images, the original one and the cropped one, and use the imagecopyresized function to generate the cropped image. We add some header information to tell the world it's an image and prompt for a save dialog.</p>
<p><strong><a href="http://htmlblog.net/demo/cropper/" target="_blank">Demo</a></strong><br />
<strong><a href="http://htmlblog.net/demo/cropper/cropper.zip">Download sample file</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/ajax-image-cropper-with-yui-and-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Show/hide containers by only adding CSS classes without writing javascript code (YUI-based)</title>
		<link>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/</link>
		<comments>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 07:37:49 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[collapse]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[div]]></category>

		<category><![CDATA[expand]]></category>

		<category><![CDATA[html]]></category>

		<category><![CDATA[selector]]></category>

		<category><![CDATA[yahoo]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=34</guid>
		<description><![CDATA[

This post will show you how to add the collapse/expand functionality in your HTML pages, perfect for FAQs by only adding two class names to your existing page and including the scripts below. Of course it's all YUI-based and also a demo of the fantastic YUI selector utility.
Demo of the toggler
Download the javascript file

What does [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm1.static.flickr.com/50/156713983_c264885895.jpg?v=0" alt="html code" /></p>
<div style="clear:both"></div>
<p>This post will show you how to add the collapse/expand functionality in your HTML pages, perfect for FAQs by only adding two class names to your existing page and including the scripts below. Of course it's all YUI-based and also a demo of the fantastic <a href="http://developer.yahoo.com/yui/selector/">YUI selector utility</a>.</p>
<p><a href="http://htmlblog.net/demo/toggler/" target="_blank"><strong>Demo of the toggler</strong></a><br />
<a href="http://htmlblog.net/demo/toggler/toggler.zip"><strong>Download the javascript file</strong></a><br />
<span id="more-34"></span><br />
<strong>What does the script do ?</strong><br />
OK, suppose you have a FAQ page where you have traditional anchor methods, i.e you click on the question and then you go to the bottom of the page to get the answer or you get redirected to another page. But now your users are complaining your site's not trendy enough and want to have the answer displayed immediately after clicking the question.</p>
<p><strong>The solution.</strong><br />
After downloading the javascript file, include it at the bottom of your page with the following HTML code:</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.5.2/build/selector/selector-beta-min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;js/toggler.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span>
&nbsp;</pre>
<p>We need to include the <a href="http://developer.yahoo.com/yui/selector/">selector utility</a> which will be used to retrieve a collection of elements that match a given CSS selector. For e.g if we want to retrieve all div nodes in HTML page having the class "foo", we can write :</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myNodes = YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Selector</span>.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div.foo'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>The selector is used in the toggler.js file.</p>
<p>After adding the scripts, now you have to add CSS classes to your containers. For example for the FAQ, for questions (or main, call it whatever you want), you add the class "htmlblog-main" and for the answers (or sub), add the "htmlblog-sub" class.</p>
<p>Before :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>1. Question<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>Answer1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>2. Question 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>Answer 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>After :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1. Question<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-sub&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Answer1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2. Question 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;htmlblog-sub&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Answer 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>If you already had a class for that container, no problem you can add the htmlblog-main or htmlblog-sub class :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;myclass htmlblog-main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1. Question<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p><strong>What next ? </strong><br />
That's all ! All your answer containers will be hidden and questions will have a [+] besides them. Pretty easy</p>
<p><strong>Am I obliged to use the htmlblog-main and html-sub classes ? And I don't want to use div tags, I want li tags.</strong><br />
Don't worry, if you don't like the class names you can put whatever you want but you'll have to edit the toggler.js file at the following lines :</p>
<pre class="javascript">&nbsp;
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">addListener</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">'load'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	YAHOO.<span style="color: #006600;">htmlblog</span>.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span>, <span style="color: #3366CC;">'htmlblog-main'</span>, <span style="color: #3366CC;">'htmlblog-sub'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>For e.g, if you're using li tags instead of divs with the "myMainClass" as main and "mySubClass" as sub, the code goes :</p>
<pre class="javascript">&nbsp;
YAHOO.<span style="color: #006600;">util</span>.<span style="color: #006600;">Event</span>.<span style="color: #006600;">addListener</span><span style="color: #66cc66;">&#40;</span>window, <span style="color: #3366CC;">'load'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	YAHOO.<span style="color: #006600;">htmlblog</span>.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span>, <span style="color: #3366CC;">'myMainClass'</span>, <span style="color: #3366CC;">'mySubClass'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p><strong>I'am getting an alert saying "Number of main and subs incorrect".</strong><br />
That means the number of main/subs are not the same. You need to have the number of the main class equals the number of the sub class.</p>
<p>I've commented the toggler.js file and you can easily change it to fit your needs.</p>
<p><a href="http://htmlblog.net/demo/toggler/" target="_blank"><strong>Demo of the toggler</strong></a><br />
<a href="http://htmlblog.net/demo/toggler/toggler.zip"><strong>Download the javascript file</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/showhide-containers-by-only-adding-css-classes-without-writing-javascript-code-yui-based/feed/</wfw:commentRss>
		</item>
		<item>
		<title>nouzil.com - a new Mauritian portal on the web (YUI-based)</title>
		<link>http://htmlblog.net/nouzilcom-a-new-mauritian-portal-on-the-web-yui-based/</link>
		<comments>http://htmlblog.net/nouzilcom-a-new-mauritian-portal-on-the-web-yui-based/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 15:25:47 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[mauritius portal]]></category>

		<category><![CDATA[nouzil]]></category>

		<category><![CDATA[nouzil.com]]></category>

		<category><![CDATA[portal]]></category>

		<category><![CDATA[servihoo]]></category>

		<category><![CDATA[servihoo.com]]></category>

		<category><![CDATA[yahoo]]></category>

		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=32</guid>
		<description><![CDATA[

I came to know the existing of a new Mauritian portal via Avinash called nouzil (which means our island in creole) and I must say at first look it reminds me of Netvibes a lot. I think the nouzil.com team picked up some bits and pieces from Netvibes.com.
Anyway, looking behind the scenes I notice that [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nouzil.com"><img src="http://htmlblog.net/wp-content/uploads/2008/09/nouzil-shot.png" alt="" title="nouzil-shot" width="500" height="271" class="aligncenter size-full wp-image-33" /></a></p>
<div style="clear:both"></div>
<p>I came to know the existing of a <a href="http://nouzil.com">new Mauritian portal</a> via <a href="http://www.noulakaz.net/weblog/2008/09/07/nouzil-a-new-mashup-for-mauritius/">Avinash</a> called <a href="http://nouzil.com">nouzil</a> (which means our island in creole) and I must say at first look it reminds me of <a href="http://www.netvibes.com">Netvibes</a> a lot. I think the <a href="http://nouzil.com">nouzil.com</a> team picked up some bits and pieces from <a href="http://www.netvibes.com">Netvibes.com</a>.<span id="more-32"></span><br />
Anyway, looking behind the scenes I notice that the new portal uses <a href="http://developer.yahoo.com/yui/">YUI </a>a lot, in fact it's all YUI-based. Had a look at the source and they are using the following <a href="http://developer.yahoo.com/yui/">YUI components</a> (with my comments) :</p>
<ul>
<li><a href="http://developer.yahoo.com/yui/">utilities</a> - for XHR requests, dragging of