<?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</title>
	<atom:link href="http://htmlblog.net/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>9 tips to validate your XHTML code</title>
		<link>http://htmlblog.net/9-tips-to-validate-your-xhtml-code/</link>
		<comments>http://htmlblog.net/9-tips-to-validate-your-xhtml-code/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 15:29:14 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[Web]]></category>

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

		<category><![CDATA[embed flash]]></category>

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

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

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

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

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

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

What is validation ?
According to the W3c, Validation is a process of checking your documents against a formal Standard, such as those published by the World Wide Web Consortium (W3C)  for HTML and XML-derived Web document types, or by the WapForum for WML, etc. It serves a similar purpose to spell checking and proofreading [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm3.static.flickr.com/2297/2131136676_7e5c0544e7.jpg?v=0" alt="HTML Code" /></p>
<div style="clear:both"></div>
<p><strong>What is validation ?</strong><br />
According to the <a href="http://validator.w3.org/docs/why.html" target="_blank">W3c</a>, Validation is a process of checking your documents against a formal Standard, such as those published by the <a href="http://www.w3.org/" target="_blank">World Wide Web Consortium (W3C)</a>  for HTML and XML-derived Web document types, or by the WapForum for WML, etc. It serves a similar purpose to spell checking and proofreading for grammar and syntax, but is much more precise and reliable than any of those processes because it is dealing with precisely-specified machine languages, not with nebulously-defined human natural language.</p>
<hr/>
<p><strong>Why taking the trouble to validate your XHTML ?</strong></p>
<ul>
<li>Properly written XHTML code will render better, render on more browsers, and render faster than XHTML with errors. It's also more easily adapted to print and alternative browsing devices like mobile phones and handheld computers.</li>
<li>Properly written XHTML code is more likely to be "future-proof" (backward compatible with future standards and future web browsers).</li>
<li>Browsers are becoming more standards compliant, and it is becoming increasingly necessary and important to write valid and standards compliant XHTML code</li>
<li>Poorly written XHTML can greatly reduce the amount of traffic your web site receives from search engines.</li>
<li>Write XHTML code right the first time and write it once.</li>
<li>You don't want to look foolish among your friends while not knowing the rules, uh?</li>
</ul>
<p><span id="more-41"></span></p>
<hr/>
<p><strong>Tip 1: Specify a DOCTYPE and namespace</strong><br />
Include a <a href="http://en.wikipedia.org/wiki/Document_Type_Declaration" target="_blank">DOCTYPE</a> at the top of your page and specify the <a href="http://en.wikipedia.org/wiki/XML_Namespace" target="_blank">namespace</a></p>
<p>For XHTML1.0 Strict</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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</span></a> xmlns=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;</pre>
<p>For XHTML1.0 Transitional</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</span></a> xmlns=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;</pre>
<p>For XHTML1.0 Frameset</p>
<pre class="html4strict">&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Frameset//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.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</span></a> xmlns=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;</pre>
<hr/>
<p><strong>Tip 2: Specify the character encoding</strong></p>
<pre class="html4strict">&nbsp;
<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>
&nbsp;</pre>
<hr />
<p><strong>Tip 3: Avoid using deprecated tags and attributes.</strong><br />
Deprecated tags :</p>
<ul>
<li>applet</li>
<li>basefont</li>
<li>center</li>
<li>dir</li>
<li>font</li>
<li>isindex</li>
<li>menu</li>
<li>s</li>
<li>strike</li>
<li>u</li>
</ul>
<p>Deprecated attributes and tags in which they are deprecated :</p>
<ul>
<li>align (caption, img, input, object, legend, table, hr, div, h1, h2, h3, h4, h5, h6, p)</li>
<li>alink, link, vlink (body)</li>
<li>background (body)</li>
<li>bgcolor (table, tr, td, th, body)</li>
<li>border (img, object)</li>
<li>clear (br)</li>
<li>compact (dl, ol, ul)</li>
<li>height (td, th)</li>
<li>hspace (img, object)</li>
<li>language (script)</li>
<li>name (img, a, applet, form, frame, iframe, map)</li>
<li>noshade (hr)</li>
<li>nowrap (td, th)</li>
<li>size (hr)</li>
<li>start (ol)</li>
<li>target (a)</li>
<li>text (body)</li>
<li>type (li, ol, ul)</li>
<li>value (li)</li>
<li>version (html)</li>
<li>vspace (img, object)</li>
<li>width (hr, td, th, pre)</li>
</ul>
<hr />
<p><strong>Tip 4: All tags in lowercase</strong><br />
All tags and attribute names must be in lower case and attribute values must be between double quotes ("), i.e</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>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">&lt;Img</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;test.jpg&quot;</span> <span style="color: #000066;">ID</span>=myimage <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">'logo'</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>is incorrect while correct version goes like this:</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>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;test.jpg&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myimage&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;logo&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>
<hr/>
<p><strong>Tip 5: XHTML must be well-formed</strong><br />
All opening tags must have closing ones, or if the tag is empty, like br tag, it must have a closing slash. For e.g</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>
&nbsp;
this is a paragraph
&nbsp;
	<span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/hr.html"><span style="color: #000000; font-weight: bold;">&lt;hr&gt;</span></a></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;images.jpg&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;my company&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>is invalid. The correct code:</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>
&nbsp;
this is a paragraph
&nbsp;
&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/hr.html"><span style="color: #000000; font-weight: bold;">&lt;hr</span></a> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;images.jpg&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;my company&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>Also, tags must be properly nested can can't overlap. An example of bad nesting is</p>
<pre class="html4strict">&nbsp;
&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><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>this is a paragraph<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span>
&nbsp;
&nbsp;</pre>
<p>It should be like this in order to validate:</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>
&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>this is a paragraph<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<hr/>
<p><strong>Tip 6: Images must always have alt attribute</strong><br />
According to the W3C recommendations, the "alt" attribute specifies an alternate text for user agents that cannot display images. Including the alt attribute will not only validate your code but also improve your search engine rankings. In Google's webmaster guidelines, they advise the use of alternative text for images since they can't see the images. Instead they rely on the alt attribute.</p>
<p>Correct code :</p>
<pre class="html4strict">&nbsp;
	<span style="color: #009900;"><a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">&lt;img</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;images/logo.jpg&quot;</span> <span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;My Company&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;</pre>
<hr/>
<p><strong>Tip 7: Surround your javascript between CDATA tags</strong><br />
If you're not using external javascript files, to prevent the validator from spitting errors from your javascript code, </p>
<p>simply surround them within CDATA tags, like this:</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: #000000; font-weight: bold;">&gt;</span></span>
/* <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span>!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span> */
var myfunction = function<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>;
/* <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</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>
<hr/>
<p><strong>Tip 8 : Encode HTML character entities</strong></p>
<pre class="html4strict">&nbsp;
	<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- incorrect --&gt;</span></span>
	my brother <span style="color: #ddbb00;">&amp; me</span>
&nbsp;
<span style="color: #ddbb00;">	&lt;!-- correct --&gt;</span>
<span style="color: #ddbb00;">	my brother &amp;amp;</span> me
&nbsp;</pre>
<hr/>
<p><strong>Tip 9: Correct way to embed flash movies</strong><br />
Code which won't validate</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/object.html"><span style="color: #000000; font-weight: bold;">&lt;object</span></a> <span style="color: #000066;">classid</span>=<span style="color: #ff0000;">&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;</span> <span style="color: #000066;">codebase</span>=<span style="color: #ff0000;">&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/param.html"><span style="color: #000000; font-weight: bold;">&lt;param</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;music/sound.swf&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/param.html"><span style="color: #000000; font-weight: bold;">&lt;param</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;quality&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;high&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;">&lt;embed <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;music/sound.swf&quot;</span> quality=<span style="color: #ff0000;">&quot;high&quot;</span> pluginspage=<span style="color: #ff0000;">&quot;http://www.macromedia.com/go/getflashplayer&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span>/embed&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object&gt;</span></span>
&nbsp;</pre>
<p>Correct way to embed flash movies</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/object.html"><span style="color: #000000; font-weight: bold;">&lt;object</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;music/sound.swf&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/param.html"><span style="color: #000000; font-weight: bold;">&lt;param</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;music/sound.swf&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/param.html"><span style="color: #000000; font-weight: bold;">&lt;param</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;quality&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;high&quot;</span>/<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object&gt;</span></span>
&nbsp;</pre>
<p>Or if you want you can use <a href="http://code.google.com/p/swfobject/" target="_blank">swfobject</a> which offers optimized Flash Player embed methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/9-tips-to-validate-your-xhtml-code/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>10 code snippets for PHP developers</title>
		<link>http://htmlblog.net/10-code-snippets-for-php-developers/</link>
		<comments>http://htmlblog.net/10-code-snippets-for-php-developers/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 16:48:31 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[email check]]></category>

		<category><![CDATA[get ip address]]></category>

		<category><![CDATA[list files directory]]></category>

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

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

		<category><![CDATA[password generator]]></category>

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

		<category><![CDATA[send mail]]></category>

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

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

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

		<guid isPermaLink="false">http://htmlblog.net/?p=38</guid>
		<description><![CDATA[I've compiled a small list of some useful code snippets which might help you when writing your PHP scripts...

Email address check
Checks for a valid email address using the php-email-address-validation class.
Source and docs: http://code.google.com/p/php-email-address-validation/
&#160;
include&#40;'EmailAddressValidator.php'&#41;;
&#160;
$validator = new EmailAddressValidator;
if &#40;$validator-&#62;check_email_address&#40;'test@example.org'&#41;&#41; &#123;
    // Email address is technically valid
&#125;
else &#123;
    // Email not valid
&#125;
&#160;

Random [...]]]></description>
			<content:encoded><![CDATA[<p>I've compiled a small list of some useful code snippets which might help you when writing your PHP scripts...<br />
<span id="more-38"></span><br />
<strong>Email address check</strong><br />
Checks for a valid email address using the <a href="http://code.google.com/p/php-email-address-validation/" target="_blank">php-email-address-validation</a> class.<br />
Source and docs: <a href="http://code.google.com/p/php-email-address-validation/" target="_blank">http://code.google.com/p/php-email-address-validation/</a></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'EmailAddressValidator.php'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$validator</span> = <span style="color: #000000; font-weight: bold;">new</span> EmailAddressValidator;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$validator</span>-&gt;<span style="color: #006600;">check_email_address</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'test@example.org'</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;">// Email address is technically valid</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// Email not valid</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<hr />
<p><strong>Random password generator</strong><br />
PHP password generator is a complete, working random password generation function for PHP. It allows the developer to customize the password: set its length and strength. Just include this function anywhere in your code and then use it.<br />
Source : <a href="http://www.webtoolkit.info/php-random-password-generator.html" target="_blank">http://www.webtoolkit.info/php-random-password-generator.html</a></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> generatePassword<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$length</span>=<span style="color: #cc66cc;">9</span>, <span style="color: #0000ff;">$strength</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$vowels</span> = <span style="color: #ff0000;">'aeuy'</span>;
    <span style="color: #0000ff;">$consonants</span> = <span style="color: #ff0000;">'bdghjmnpqrstvz'</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$strength</span> &amp; <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$consonants</span> .= <span style="color: #ff0000;">'BDGHJLMNPQRSTVWXZ'</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$strength</span> &amp; <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$vowels</span> .= <span style="color: #ff0000;">&quot;AEUY&quot;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$strength</span> &amp; <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$consonants</span> .= <span style="color: #ff0000;">'23456789'</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$strength</span> &amp; <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$consonants</span> .= <span style="color: #ff0000;">'@#$%'</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$password</span> = <span style="color: #ff0000;">''</span>;
    <span style="color: #0000ff;">$alt</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: #cc66cc;">2</span>;
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span> &lt; <span style="color: #0000ff;">$length</span>; <span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$alt</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$password</span> .= <span style="color: #0000ff;">$consonants</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/rand"><span style="color: #000066;">rand</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> % <a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$consonants</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
            <span style="color: #0000ff;">$alt</span> = <span style="color: #cc66cc;">0</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$password</span> .= <span style="color: #0000ff;">$vowels</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/rand"><span style="color: #000066;">rand</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> % <a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$vowels</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
            <span style="color: #0000ff;">$alt</span> = <span style="color: #cc66cc;">1</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$password</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<hr />
<p><strong>Get IP address</strong><br />
Returns the real IP address of a visitor, even when connecting via a proxy.<br />
Source : <a href="http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html" target="_blank">http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html</a></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getRealIpAddr<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<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;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_CLIENT_IP'</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;">//check ip from share internet</span>
		<span style="color: #0000ff;">$ip</span> = <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_CLIENT_IP'</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">elseif</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;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_X_FORWARDED_FOR'</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;">//to check ip is pass from proxy</span>
		<span style="color: #0000ff;">$ip</span> = <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$ip</span> = <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'REMOTE_ADDR'</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$ip</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<hr />
<p><strong>XSL transformation</strong><br />
PHP5 version<br />
Source : <a href="http://www.tonymarston.net/php-mysql/xsl.html" target="_blank">http://www.tonymarston.net/php-mysql/xsl.html</a></p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$xp</span> = <span style="color: #000000; font-weight: bold;">new</span> XsltProcessor<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// create a DOM document and load the XSL stylesheet</span>
<span style="color: #0000ff;">$xsl</span> = <span style="color: #000000; font-weight: bold;">new</span> DomDocument;
<span style="color: #0000ff;">$xsl</span>-&gt;<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'something.xsl'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// import the XSL styelsheet into the XSLT process</span>
<span style="color: #0000ff;">$xp</span>-&gt;<span style="color: #006600;">importStylesheet</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xsl</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// create a DOM document and load the XML datat</span>
<span style="color: #0000ff;">$xml_doc</span> = <span style="color: #000000; font-weight: bold;">new</span> DomDocument;
<span style="color: #0000ff;">$xml_doc</span>-&gt;<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'something.xml'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// transform the XML into HTML using the XSL file</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$html</span> = <span style="color: #0000ff;">$xp</span>-&gt;<span style="color: #006600;">transformToXML</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xml_doc</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$html</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/trigger_error"><span style="color: #000066;">trigger_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'XSL transformation failed.'</span>, <span style="color: #000000; font-weight: bold;">E_USER_ERROR</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// if</span>
&nbsp;</pre>
<p>PHP4 version</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> xml2html<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xmldata</span>, <span style="color: #0000ff;">$xsl</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
   <span style="color: #808080; font-style: italic;">/* $xmldata -&gt; your XML */</span>
   <span style="color: #808080; font-style: italic;">/* $xsl -&gt; XSLT file */</span>
&nbsp;
   <span style="color: #0000ff;">$arguments</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/_xml'</span> =&gt; <span style="color: #0000ff;">$xmldata</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #0000ff;">$xsltproc</span> = xslt_create<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
   xslt_set_encoding<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xsltproc</span>, <span style="color: #ff0000;">'ISO-8859-1'</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #0000ff;">$html</span> = xslt_process<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xsltproc</span>, <span style="color: #0000ff;">$xmldata</span>, <span style="color: #0000ff;">$xsl</span>, <span style="color: #000000; font-weight: bold;">NULL</span>, <span style="color: #0000ff;">$arguments</span><span style="color: #66cc66;">&#41;</span>;
&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;">$html</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
       <a href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'XSLT processing error: '</span>. xslt_error<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xsltproc</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
   xslt_free<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$xsltproc</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$html</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> xml2html<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'myxmml.xml'</span>, <span style="color: #ff0000;">'myxsl.xsl'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<hr />
<p><strong>Force downloading of a file</strong><br />
Forces a user to download a file, for e.g you have an image but you want the user to download it instead of displaying it in his browser.</p>
<pre class="php">&nbsp;
<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: application/octet-stream&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// displays progress bar when downloading (credits to Felix ;-))</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-Length: &quot;</span> . <a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'myImage.jpg'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// file name of download file</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;myImage.jpg&quot;'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// reads the file on the server</span>
<a href="http://www.php.net/readfile"><span style="color: #000066;">readfile</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'myImage.jpg'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<hr />
<p><strong>String encoding to prevent harmful code</strong><br />
Web applications face any number of threats; one of them is cross-site scripting and related injection attacks. The <a href="http://phed.org/reform-encoding-library/">Reform library</a> attempts to provide a solid set of functions for encoding output for the most common context targets in web applications (e.g. HTML, XML, JavaScript, etc)<br />
Source : <a href="http://phed.org/reform-encoding-library/" target="_blank">http://phed.org/reform-encoding-library/</a></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Reform.php'</span><span style="color: #66cc66;">&#41;</span>;
Reform::<span style="color: #006600;">HtmlEncode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a potentially harmful string'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<hr />
<p><strong>Sending mail</strong><br />
Using PHPMailer<br />
<a href="http://phpmailer.codeworxtech.com/" target="_blank">PHPMailer</a> a powerful email transport class with a big features and small footprint that is simple to use and integrate into your own software.<br />
Source : <a href="http://phpmailer.codeworxtech.com/" target="_blank">http://phpmailer.codeworxtech.com/</a></p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;class.phpmailer.php&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$mail</span> = <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">From</span> = <span style="color: #ff0000;">'noreply@htmlblog.net'</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">FromName</span> = <span style="color: #ff0000;">'HTML Blog'</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Host</span> = <span style="color: #ff0000;">'smtp.site.com'</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Mailer</span> = <span style="color: #ff0000;">'smtp'</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Subject</span> = <span style="color: #ff0000;">'My Subject'</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">IsHTML</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$body</span> = <span style="color: #ff0000;">'Hello&lt;br/&gt;How are you ?'</span>;
<span style="color: #0000ff;">$textBody</span> = <span style="color: #ff0000;">'Hello, how are you ?'</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Body</span> = <span style="color: #0000ff;">$body</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">AltBody</span> = <span style="color: #0000ff;">$textBody</span>;
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">AddAddress</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'asvin [@] gmail.com'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'There has been a mail error !'</span>;
&nbsp;</pre>
<p>Using <a href="http://swiftmailer.org/" target="_blank">Swift Mailer</a><br />
<a href="http://swiftmailer.org/" target="_blank">Swift Mailer</a> is an alternative to PHPMailer and is a fully OOP library for sending e-mails from PHP websites and applications.<br />
Source : <a href="http://swiftmailer.org/" target="_blank">http://swiftmailer.org/</a></p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// include classes</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">&quot;lib/Swift.php&quot;</span>;
<span style="color: #b1b100;">require_once</span> <span style="color: #ff0000;">&quot;lib/Swift/Connection/SMTP.php&quot;</span>;
&nbsp;
<span style="color: #0000ff;">$swift</span> =&amp; <span style="color: #000000; font-weight: bold;">new</span> Swift<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Swift_Connection_SMTP<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;smtp.site.com&quot;</span>, <span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$message</span> =&amp; <span style="color: #000000; font-weight: bold;">new</span> Swift_Message<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;My Subject&quot;</span>, <span style="color: #ff0000;">&quot;Hello&lt;br/&gt;How are you ?&quot;</span>, <span style="color: #ff0000;">&quot;text/html&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$swift</span>-&gt;<span style="color: #006600;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$message</span>, <span style="color: #ff0000;">&quot;asvin [@] gmail.com&quot;</span>, <span style="color: #ff0000;">&quot;noreply@htmlblog.net&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</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;Message sent&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;">'There has been a mail error !'</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//It's polite to do this when you're finished</span>
<span style="color: #0000ff;">$swift</span>-&gt;<span style="color: #006600;">disconnect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<hr />
<p><strong>Uploading of files</strong><br />
Using <a href="http://www.verot.net/php_class_upload.htm" target="_blank">class.upload.php</a> from Colin Verot<br />
Source : <a href="http://www.verot.net/php_class_upload.htm" target="_blank">http://www.verot.net/php_class_upload.htm</a></p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$uploadedImage</span> = <span style="color: #000000; font-weight: bold;">new</span> Upload<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;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$uploadedImage</span>-&gt;<span style="color: #006600;">uploaded</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$uploadedImage</span>-&gt;<span style="color: #006600;">Process</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'myuploads'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$uploadedImage</span>-&gt;<span style="color: #006600;">processed</span><span style="color: #66cc66;">&#41;</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;">'file has been uploaded'</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<hr />
<p><strong>List files in directory</strong><br />
List all files in a directory and return an array.<br />
Source : <a href="http://www.laughing-buddha.net/jon/php/dirlist/" target="_blank">http://www.laughing-buddha.net/jon/php/dirlist/</a></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> dirList <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$directory</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// create an array to hold directory list</span>
    <span style="color: #0000ff;">$results</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">// create a handler for the directory</span>
    <span style="color: #0000ff;">$handler</span> = <a href="http://www.php.net/opendir"><span style="color: #000066;">opendir</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$directory</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">// keep going until all files in directory have been read</span>
    <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span> = <a href="http://www.php.net/readdir"><span style="color: #000066;">readdir</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handler</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;">// if $file isn't this directory or its parent,</span>
        <span style="color: #808080; font-style: italic;">// add it to the results array</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span> != <span style="color: #ff0000;">'.'</span> &amp;&amp; <span style="color: #0000ff;">$file</span> != <span style="color: #ff0000;">'..'</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #0000ff;">$results</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$file</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">// tidy up: close the handler</span>
    <a href="http://www.php.net/closedir"><span style="color: #000066;">closedir</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$handler</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">// done!</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$results</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<hr />
<p><strong>Querying RDBMS with MDB2 (for e.g <a href="http://mysql.com" target="_blank">MySQL</a>)</strong><br />
<a href="http://pear.php.net/package/MDB2" target="_blank">PEAR MDB2</a> provides a common API for all supported RDBMS.</p>
<p>Source : <a href="http://pear.php.net/package/MDB2" target="_blank">http://pear.php.net/package/MDB2</a></p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// include MDB2 class</span>
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'MDB2.php'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// connection info</span>
<span style="color: #0000ff;">$db</span> =&amp; MDB2::<span style="color: #006600;">factory</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mysql://username:password@host/database'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// set fetch mode</span>
<span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">setFetchMode</span><span style="color: #66cc66;">&#40;</span>MDB2_FETCHMODE_ASSOC<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// querying data</span>
<span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">'SELECT id,label FROM myTable'</span>;
<span style="color: #0000ff;">$result</span> = <span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">queryAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// inserting data</span>
<span style="color: #808080; font-style: italic;">// prepare statement</span>
<span style="color: #0000ff;">$statement</span> = <span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'INSERT INTO mytable(id,label) VALUES(?,?)'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// our data</span>
<span style="color: #0000ff;">$sqlData</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$id</span>, <span style="color: #0000ff;">$label</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// execute</span>
<span style="color: #0000ff;">$statement</span>-&gt;<span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sqlData</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$statement</span>-&gt;<span style="color: #006600;">free</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// disconnect from db</span>
<span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">disconnect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/10-code-snippets-for-php-developers/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-