<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>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>
	<lastBuildDate>Thu, 30 Apr 2009 19:25:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing your first Greasemonkey script &#8211; adding menus to Facebook&#8217;s top menu</title>
		<link>http://htmlblog.net/writing-your-first-greasemonkey-script-adding-menus-to-facebooks-top-menu/</link>
		<comments>http://htmlblog.net/writing-your-first-greasemonkey-script-adding-menus-to-facebooks-top-menu/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 19:25:50 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[greasemonkey]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=120</guid>
		<description><![CDATA[This post will show you how to write a basic Greasemonkey script that will add two more menu items to Facebook's friends top menu as shown below.

These 2 menu items are :

"Recently Updated" - show all your friends with recent updates
"Status Updates" - show the latest status updates of your friends

About Greasemonkey
Greasemonkey is a Firefox [...]]]></description>
			<content:encoded><![CDATA[<p>This post will show you how to write a basic <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> script that will add two more menu items to Facebook's friends top menu as shown below.</p>
<p><img src="http://htmlblog.net/wp-content/uploads/2009/04/facebook.png" alt="facebook" title="facebook" width="357" height="135" class="aligncenter size-full wp-image-123" /></p>
<p>These 2 menu items are :</p>
<ul>
<li>"Recently Updated" - show all your friends with recent updates</li>
<li>"Status Updates" - show the latest status updates of your friends</li>
</ul>
<h3 class="post-title">About <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a></h3>
<p><a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> is a <a href="http://www.mozilla.com/firefox/" target="_blank">Firefox</a> extension that allows you to write scripts that alter the web pages you visit. You can</p>
<ul>
<li>use it to make a web site more readable or more usable</li>
<li>fix rendering bugs that the site owner can't be bothered to fix themselves. </li>
<li>alter pages so they work better with assistive technologies that speak a web page out loud or convert it to Braille</li>
<li>even automatically retrieve data from other sites to make two sites more interconnected.</li>
</ul>
<p><a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> by itself does none of these things. In fact, after you install it, you won't notice any change at all... until you start installing what are called “user scripts”. A user script is just a chunk of javascript code, with some additional information that tells <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> where and when it should be run. Each user script can target a specific page, a specific site, or a group of sites.</p>
<h3 class="post-title">Install <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> addon for Firefox</h3>
<p>Go to <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> addon page, click on the "Add to Firefox" button and follow the instructions. After restarting Firefox, you will notice a monkey's head sitting at the bottom right its status bar.<br />
If you right click on the monkey's head and choose "Manage User Scripts" from the resulting menu, you will notice there isn't any script which is quite normal since we have not installed any ;-).</p>
<h3 class="post-title">Creating your first <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> script.</h3>
<p>For a <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> to be recognized, it must end with <strong>.user.js</strong>, so let us create an empty file and save it as <strong>myfirstscript.user.js</strong><br />
Fire up your favourite text editor and open your newly created file.</p>
<h3 class="post-title"><a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> script metadata</h3>
<p>All user scripts has a meta data section which tells <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a> about the script itself, where it came from, and when to run it. For example, our script :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// ==UserScript==</span>
<span style="color: #009900; font-style: italic;">// @name          My First GM script</span>
<span style="color: #009900; font-style: italic;">// @namespace     http://htmlblog.net</span>
<span style="color: #009900; font-style: italic;">// @description   basic Greasemonkey script</span>
<span style="color: #009900; font-style: italic;">// @include       http://www.facebook.com/</span>
<span style="color: #009900; font-style: italic;">// ==/UserScript==</span>
&nbsp;</pre>
<p>You can find <a href="http://diveintogreasemonkey.org/helloworld/metadata.html" target="_blank">more information about the metadata here</a>. </p>
<p>Remember we want our script available only for <a href="http://www.facebook.com" target="_blank">Facebook</a> pages, that is why we use <strong>@include http://www.facebook.com</strong></p>
<h3 class="post-title">Show me some code.</h3>
<p>Alright, to add our own menus, we need to get the parent element holding the drop down menu. After inspecting Facebook's source code, we can rapidly come to the conclusion that the parent element's id is "fb_menu_friends_dropdown". So the current Facebook code looks like that :</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_dropdown hidden_elem&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;fb_menu_friends_dropdown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/friends/?added&amp;amp;ref=tn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Recently Added<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/friends/?everyone&amp;amp;ref=tn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>All Friends<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_separator&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/invite.php?ref=tn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Invite Friends<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;fb_menu_item&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a</span></a> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/find-friends/?ref=friends&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Find Friends<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p>and our goal is to insert the two menu items before the "Recently Added" item. </p>
<p>For us to do that, we need to get the first child of the parent element and then insert our elements before it and to help us, i.e walking through the DOM selecting parent and childs, I use a <a href="http://gist.github.com/41440" target="_blank">little piece of code found on Github</a>, which eliminates whitespace issues between elements among other features. So our myfirstscript.user.js can be updated to :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// ==UserScript==</span>
<span style="color: #009900; font-style: italic;">// @name          My First GM script</span>
<span style="color: #009900; font-style: italic;">// @namespace     http://htmlblog.net</span>
<span style="color: #009900; font-style: italic;">// @description   basic &lt;a href=&quot;https://addons.mozilla.org/firefox/addon/748&quot; target=&quot;_blank&quot;&gt;Greasemonkey&lt;/a&gt; script</span>
<span style="color: #009900; font-style: italic;">// @include       http://www.facebook.com/</span>
<span style="color: #009900; font-style: italic;">// ==/UserScript==</span>
DOM = <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>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> get<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>id &amp;&amp; <span style="color: #000066; font-weight: bold;">typeof</span> id === <span style="color: #3366CC;">'string'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            id = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> id || <span style="color: #003366; font-weight: bold;">null</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> walk<span style="color: #66cc66;">&#40;</span>element, tag, walk, start, all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> el = get<span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span>start || walk<span style="color: #66cc66;">&#93;</span>, elements = all ? <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> : <span style="color: #003366; font-weight: bold;">null</span>;
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">nodeType</span> === <span style="color: #CC0000;">1</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>!tag || el.<span style="color: #006600;">tagName</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> === tag<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> el;
                <span style="color: #66cc66;">&#125;</span>
                elements.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            el = el<span style="color: #66cc66;">&#91;</span>walk<span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> elements;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// Get the element by its id</span>
        get: get,
&nbsp;
        walk: walk,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns the previousSibling of the Element (excluding text nodes).</span>
        getPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getPrevious, but returns a collection of all the matched previousSiblings.</span>
        getAllPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// As getPrevious, but tries to find the nextSibling (excluding text nodes).</span>
        getNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getNext, but returns a collection of all the matched nextSiblings.</span>
        getAllNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the firstChild (excluding text nodes).</span>
        getFirst: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the lastChild.</span>
        getLast: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #3366CC;">'lastChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the parentNode.</span>
        getParent: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getParent, but returns a collection of all the matched parentNodes up the tree.</span>
        getParents: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns all the Element's children (excluding text nodes).</span>
        getChildren: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Removes the Element from the DOM.</span>
        dispose: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            el = get<span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">parentNode</span><span style="color: #66cc66;">&#41;</span> ? el.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> : el;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>To get the parent element and its first child, we then append the following code :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// get drop down menu</span>
<span style="color: #003366; font-weight: bold;">var</span> parentNode = DOM.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">// get its first child</span>
<span style="color: #003366; font-weight: bold;">var</span> firstNode = DOM.<span style="color: #006600;">getFirst</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<h3 class="post-title">Creating our nodes</h3>
<p>Now we must create our two nodes which will be inserted afterward. This is done easily with the following code which is self explanatory :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/** For &quot;Recently Updated&quot; */</span>
<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
<span style="color: #003366; font-weight: bold;">var</span> recentDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
recentDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// create our link</span>
<span style="color: #003366; font-weight: bold;">var</span> recentLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
recentLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?recent&amp;ref=tn'</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add text to our link</span>
<span style="color: #003366; font-weight: bold;">var</span> recentDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Recently Updated'</span><span style="color: #66cc66;">&#41;</span>;
recentLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add link to our div</span>
recentDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">/** For &quot;Status Updates&quot; */</span>
<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
<span style="color: #003366; font-weight: bold;">var</span> statusDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
statusDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// create our link</span>
<span style="color: #003366; font-weight: bold;">var</span> statusLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
statusLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?status&amp;ref=tn'</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add text to our link</span>
<span style="color: #003366; font-weight: bold;">var</span> statusDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Status Updates'</span><span style="color: #66cc66;">&#41;</span>;
statusLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">// add link to our div</span>
statusDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We can also add a separator, for having a cleaner look :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/** Creates a separator, just to look good */</span>
<span style="color: #003366; font-weight: bold;">var</span> separatorDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
separatorDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_separator'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Finally we insert these 3 nodes before the first child element we got earlier on :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// add all divs before first child of menu</span>
parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>statusDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>recentDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>separatorDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Just to be on the safe side of things, we surround the whole block of code with a try and catch statement.</p>
<h3 class="post-title">Putting it all together</h3>
<p>So finally our code is like this :</p>
<pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">// ==UserScript==</span>
<span style="color: #009900; font-style: italic;">// @name          My First GM script</span>
<span style="color: #009900; font-style: italic;">// @namespace     http://htmlblog.net</span>
<span style="color: #009900; font-style: italic;">// @description   basic &lt;a href=&quot;https://addons.mozilla.org/firefox/addon/748&quot; target=&quot;_blank&quot;&gt;Greasemonkey&lt;/a&gt; script</span>
<span style="color: #009900; font-style: italic;">// @include       http://www.facebook.com/</span>
<span style="color: #009900; font-style: italic;">// ==/UserScript==</span>
&nbsp;
DOM = <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>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> get<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>id &amp;&amp; <span style="color: #000066; font-weight: bold;">typeof</span> id === <span style="color: #3366CC;">'string'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            id = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> id || <span style="color: #003366; font-weight: bold;">null</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> walk<span style="color: #66cc66;">&#40;</span>element, tag, walk, start, all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> el = get<span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span>start || walk<span style="color: #66cc66;">&#93;</span>, elements = all ? <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> : <span style="color: #003366; font-weight: bold;">null</span>;
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">nodeType</span> === <span style="color: #CC0000;">1</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>!tag || el.<span style="color: #006600;">tagName</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> === tag<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!all<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> el;
                <span style="color: #66cc66;">&#125;</span>
                elements.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            el = el<span style="color: #66cc66;">&#91;</span>walk<span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> elements;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// Get the element by its id</span>
        get: get,
&nbsp;
        walk: walk,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns the previousSibling of the Element (excluding text nodes).</span>
        getPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getPrevious, but returns a collection of all the matched previousSiblings.</span>
        getAllPrevious: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// As getPrevious, but tries to find the nextSibling (excluding text nodes).</span>
        getNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getNext, but returns a collection of all the matched nextSiblings.</span>
        getAllNext: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the firstChild (excluding text nodes).</span>
        getFirst: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the lastChild.</span>
        getLast: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'previousSibling'</span>, <span style="color: #3366CC;">'lastChild'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Works as getPrevious, but tries to find the parentNode.</span>
        getParent: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Like getParent, but returns a collection of all the matched parentNodes up the tree.</span>
        getParents: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'parentNode'</span>, <span style="color: #003366; font-weight: bold;">null</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Returns all the Element's children (excluding text nodes).</span>
        getChildren: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el, tag<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> walk<span style="color: #66cc66;">&#40;</span>el, tag, <span style="color: #3366CC;">'nextSibling'</span>, <span style="color: #3366CC;">'firstChild'</span>, <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>,
&nbsp;
        <span style="color: #009900; font-style: italic;">// Removes the Element from the DOM.</span>
        dispose: <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            el = get<span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>el.<span style="color: #006600;">parentNode</span><span style="color: #66cc66;">&#41;</span> ? el.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>el<span style="color: #66cc66;">&#41;</span> : el;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000066; font-weight: bold;">try</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// get drop down menu</span>
	<span style="color: #003366; font-weight: bold;">var</span> parentNode = DOM.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #009900; font-style: italic;">// get its first child</span>
	<span style="color: #003366; font-weight: bold;">var</span> firstNode = DOM.<span style="color: #006600;">getFirst</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'fb_menu_friends_dropdown'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/** For &quot;Recently Updated&quot; */</span>
	<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
	<span style="color: #003366; font-weight: bold;">var</span> recentDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
	recentDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// create our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> recentLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
	recentLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?recent&amp;ref=tn'</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add text to our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> recentDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Recently Updated'</span><span style="color: #66cc66;">&#41;</span>;
	recentLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add link to our div</span>
	recentDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>recentLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/** For &quot;Status Updates&quot; */</span>
	<span style="color: #009900; font-style: italic;">// create our div with class fb_menu_item</span>
	<span style="color: #003366; font-weight: bold;">var</span> statusDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
	statusDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_item'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// create our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> statusLink = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
	statusLink.<span style="color: #006600;">href</span> = <span style="color: #3366CC;">'http://www.facebook.com/friends/?status&amp;ref=tn'</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add text to our link</span>
	<span style="color: #003366; font-weight: bold;">var</span> statusDivContent = document.<span style="color: #006600;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Status Updates'</span><span style="color: #66cc66;">&#41;</span>;
	statusLink.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusDivContent<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add link to our div</span>
	statusDiv.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>statusLink<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">/** Creates a separator, just to look good */</span>
	<span style="color: #003366; font-weight: bold;">var</span> separatorDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #66cc66;">&#41;</span>;
	separatorDiv.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'class'</span>, <span style="color: #3366CC;">'fb_menu_separator'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// add both divs before first child of menu</span>
	parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>statusDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
	parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>recentDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
	parentNode.<span style="color: #006600;">insertBefore</span><span style="color: #66cc66;">&#40;</span>separatorDiv, firstNode<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000066; font-weight: bold;">catch</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<h3 class="post-title">Installing and testing our script</h3>
<p>Fire up Firefox and select <strong>"File" -> "Open File..."</strong> in the menu bar and then browse for your script, i.e myfirstscript.user.js in our case. You will be prompted to install the script by <a href="https://addons.mozilla.org/firefox/addon/748" target="_blank">Greasemonkey</a>. After installation is complete, head to Facebook, login and hover over the "Friends" menu, you will see your newly created menus.</p>
<p><a href="/demo/greasemonkey/fb_recently_updated_link.user.zip"><strong>Download script</strong></a><br />
<a href="/demo/greasemonkey/fb_recently_updated_link.user.js"><strong>Install script</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/writing-your-first-greasemonkey-script-adding-menus-to-facebooks-top-menu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WP To Top &#8211; a Wordpress plugin that takes you to the top</title>
		<link>http://htmlblog.net/wp-to-top/</link>
		<comments>http://htmlblog.net/wp-to-top/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 17:23:10 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp to top]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=110</guid>
		<description><![CDATA[About WP To Top
WP To Top is a Wordpress plugin that adds a "Back to top" link in your blog without modifying your template files. This is useful especially if you have long posts or long pages. You will have a nice "Back to top" or whatever-text-you-want link floating at the bottom right/left of your [...]]]></description>
			<content:encoded><![CDATA[<h3 class="post-title">About WP To Top</h3>
<p><a href="http://wordpress.org/extend/plugins/wp-to-top/" target="_blank">WP To Top</a> is a <a href="http://www.wordpress.org" target="_blank">Wordpress</a> plugin that adds a "Back to top" link in your blog without modifying your template files. This is useful especially if you have long posts or long pages. You will have a nice "Back to top" or whatever-text-you-want link floating at the bottom right/left of your page.</p>
<h3 class="post-title">Features</h3>
<ul>
<li>Smooth scrolling animation and fade in, fade out effect, powered by the YUI library</li>
<li>Customizable options via the admin panel, from the text to the position of the link</li>
<li>Works on almost all browsers including IE6 (yes!)</li>
</ul>
<h3 class="post-title">Download</h3>
<p><a href="http://wordpress.org/extend/plugins/wp-to-top/" target="_blank">You can get the plugin here</a></p>
<h3 class="post-title">Demo</h3>
<p>You have a demo on this page. Just scroll a little bit and you will see a nice "Take me up" link appearing at the bottom of your page.</p>
<h3 class="post-title">Installation</h3>
<ul>
<li>Extract <a href="http://wordpress.org/extend/plugins/wp-to-top/" target="_blank">wptotop.zip</a> in the "/wp-content/plugins/" directory</li>
<li>Activate the plugin through the "Plugins" menu in <a href="http://www.wordpress.org" target="_blank">WordPress</a></li>
<li>Go to "Settings" and then "WP To Top" to configure the plugin. The options are self explanatory and easy to understand.</li>
</ul>
<h3 class="post-title">Thanks</h3>
<p>I got the inspiration to write this plugin after having a look at <a href="http://davidwalsh.name/jquery-top-link" target="_blank">David Walsh's jQuery topLink Plugin</a>. Thanks to the <a href="http://developer.yahoo.com/yui" target="_blank">YUI team</a> for the great YUI library and <a href="http://semihhazar.com/blog/animated-page-scroll-with-yui/" target="_blank">Semih's Animated Page Scroll with YUI</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/wp-to-top/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>10 useful PHP PEAR packages</title>
		<link>http://htmlblog.net/10-useful-php-pear-packages/</link>
		<comments>http://htmlblog.net/10-useful-php-pear-packages/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 11:11:33 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[geo ip]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[live user]]></category>
		<category><![CDATA[mdb2]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[tar.gz]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://htmlblog.net/?p=89</guid>
		<description><![CDATA[MDB2
PEAR MDB2 is a merge of the PEAR DB and Metabase php database abstraction layers.
It provides a common API for all supported RDBMS. The main difference to most
other DB abstraction packages is that MDB2 goes much further to ensure
portability. MDB2 provides most of its many features optionally that
can be used to construct portable SQL statements:

Object-Oriented [...]]]></description>
			<content:encoded><![CDATA[<h3 class="post-title"><a href="http://pear.php.net/package/MDB2" target="_blank">MDB2</a></h3>
<p><a href="http://pear.php.net/package/MDB2" target="_blank">PEAR MDB2</a> is a merge of the PEAR DB and Metabase php database abstraction layers.</p>
<p>It provides a common API for all supported RDBMS. The main difference to most<br />
other DB abstraction packages is that MDB2 goes much further to ensure<br />
portability. MDB2 provides most of its many features optionally that<br />
can be used to construct portable SQL statements:</p>
<ul>
<li>Object-Oriented API</li>
<li>A DSN (data source name) or array format for specifying database servers</li>
<li>Datatype abstraction and on demand datatype conversion</li>
<li>Various optional fetch modes to fix portability issues</li>
<li>Portable error codes</li>
<li>Sequential and non sequential row fetching as well as bulk fetching</li>
<li>Ability to make buffered and unbuffered queries</li>
<li>Ordered array and associative array for the fetched rows</li>
<li>Prepare/execute (bind) named and unnamed placeholder emulation</li>
<li>Sequence/autoincrement emulation</li>
<li>Replace emulation</li>
<li>Limited sub select emulation</li>
<li>Row limit emulation</li>
<li>Transactions/savepoint support</li>
<li>Large Object support</li>
<li>Index/Unique Key/Primary Key support</li>
<li>Pattern matching abstraction</li>
<li>Module framework to load advanced functionality on demand</li>
<li>Ability to read the information schema</li>
<li>RDBMS management methods (creating, dropping, altering)</li>
<li>Reverse engineering schemas from an existing database</li>
<li>SQL function call abstraction</li>
<li>Full integration into the PEAR Framework</li>
<li>PHPDoc API documentation</li>
</ul>
<p><a href="http://www.installationwiki.org/MDB2" target="_blank">MDB2 - InstallationWiki</a><br />
<a href="http://codepoets.co.uk/pear_mdb2_php_database_howto_quickstart" target="_blank">How to use PHP and PEAR MDB2 </a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/Text_CAPTCHA" target="_blank">Text_CAPTCHA</a></h3>
<p><a href="http://pear.php.net/package/Text_CAPTCHA" target="_blank">Implementation</a> of CAPTCHAs (Completely Automated Public Turing tests to tell Computers and Humans Apart).<br />
<a href="http://www.kingf1.com/2008/07/16/using-pears-text_captcha-to-secure-web-forms" target="_blank">Using PEAR's Text_CAPTCHA to Secure Web Forms</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/Log">Log</a></h3>
<p><a href="http://pear.php.net/package/Log" target="_blank">The Log package</a> provides an abstracted logging framework. It includes output handlers for log files, databases, syslog, email, Firebug, and the console. It also provides composite and subject-observer logging mechanisms.<br />
<a href="http://www.indelible.org/php/Log/guide.html" target="_blank">The Log Package</a><br />
<a href="http://www.phpbuilder.com/columns/stump20021223.php3?page=2&amp;print_mode=1" target="_blank">PHPBuilder</a><br />
<a href="http://www.appelsiini.net/2007/2/debugging-php-with-firebug" target="_blank">Debugging PHP With Firebug</a><br />
<a href="http://www.go4expert.com/forums/showthread.php?t=1037" target="_blank">Advanced Logging in PHP with PEAR</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/LiveUser" target="_blank">LiveUser</a></h3>
<p><a href="http://pear.php.net/package/LiveUser" target="_blank">LiveUser</a> is a set of classes for dealing with user authentication<br />
and permission management. Basically, there are three main elements that make up this package:</p>
<ul>
<li>The LiveUser class</li>
<li>The Auth containers</li>
<li>The Perm containers</li>
</ul>
<p>The LiveUser class takes care of the login process and can be configured to use a certain permission container and one or more different auth containers.<br />
That means, you can have your users' data scattered amongst many data containers and have the LiveUser class try each defined container until the user is found.<br />
For example, you can have all website users who can apply for a new account online on the webserver's local database. Also, you want to enable all your company's employees to login to the site without the need to create new accounts for all of them. To achieve that, a second container can be defined to be used by the LiveUser class.</p>
<p>You can also define a permission container of your choice that will manage the rights for each user. Depending on the container, you can implement any kind of permission schemes for your application while having one consistent API.<br />
Using different permission and auth containers, it's easily possible to integrate newly written applications with older ones that have their own ways of storing permissions and user data. Just make a new container type and you're ready to go!</p>
<p><a href="http://wiki.pooteeweet.org/LiveUser/" target="_blank">PEAR::LiveUser Wiki</a><br />
<a href="http://jystewart.net/process/2005/08/getting-started-with-liveuser-permissions/" target="_blank">Getting Started with LiveUser Permissions</a><br />
<a href="http://www.gvngroup.be/doc/LiveUser/authentication.php" target="_blank">Authentication</a><br />
<a href="http://www.sitepoint.com/blogs/2004/06/11/php-authentication-and-access-control-libraries/" target="_blank">PHP Authentication and Access Control Libraries</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/Translation2" target="_blank">Translation2</a></h3>
<p><a href="http://pear.php.net/package/Translation2" target="_blank">This class provides</a> an easy way to retrieve all the strings for a multilingual site from a data source (i.e. db).<br />
The following containers are provided, more will follow:</p>
<ul>
<li>PEAR::DB</li>
<li>PEAR::MDB</li>
<li>PEAR::MDB2</li>
<li>gettext</li>
<li>XML</li>
<li>PEAR::DB_DataObject (experimental)</li>
</ul>
<p>It is designed to reduce the number of queries to the db, caching the results when possible.<br />
An Admin class is provided to easily manage translations (add/remove a language, add/remove a string).<br />
Currently, the following decorators are provided:</p>
<ul>
<li>CacheLiteFunction (for file-based caching)</li>
<li>CacheMemory (for memory-based caching)</li>
<li>DefaultText (to replace empty strings with their keys)</li>
<li>ErrorText (to replace empty strings with a custom error text)</li>
<li>Iconv (to switch from/to different encodings)</li>
<li>Lang (resort to fallback languages for empty strings)</li>
<li>SpecialChars (replace html entities with their hex codes)</li>
<li>UTF-8 (to convert UTF-8 strings to ISO-8859-1)</li>
</ul>
<p><a href="http://www.alberton.info/pear_translation2_tutorials.html" target="_blank">PEAR::Translation2 tutorials</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/Validate" target="_blank">Validate</a></h3>
<p><a href="http://pear.php.net/package/Validate" target="_blank">Package to validate</a> various data. It includes :</p>
<ul>
<li>numbers (min/max, decimal or not)</li>
<li>email (syntax, domain check, rfc822)</li>
<li>string (predefined type alpha upper and/or lowercase, numeric,...)</li>
<li>date (min, max, rfc822 compliant)</li>
<li>uri (RFC2396)</li>
<li>possibility valid multiple data with a single method call (::multiple)</li>
</ul>
<p><a href="http://www.phpbuilder.com/columns/ian_gilfillan20060630.php3" target="_blank">An introduction to PEAR's Validate package</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/Spreadsheet_Excel_Writer" target="_blank">Spreadsheet_Excel_Writer</a></h3>
<p><a href="http://pear.php.net/package/Spreadsheet_Excel_Writer" target="_blank">Spreadsheet_Excel_Writer</a> was born as a porting of the Spreadsheet::WriteExcel Perl module to PHP.<br />
It allows writing of Excel spreadsheets without the need for COM objects.<br />
It supports formulas, images (BMP) and all kinds of formatting for text and cells.<br />
It currently supports the BIFF5 format (Excel 5.0), so functionality appeared in the latest Excel versions is not yet available.<br />
<a href="http://www.sitepoint.com/article/pear-spreadsheet_excel_writer/">Generating Spreadsheets with PHP and PEAR</a><br />
<a href="http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.intro.php">What is Spreadsheet_Excel_Writer?</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/Net_GeoIP" target="_blank">Net_GeoIP</a></h3>
<p><a href="http://pear.php.net/package/Net_GeoIP" target="_blank">A library</a> that uses <a href="http://www.maxmind.com/app/geoip_country" target="_blank">Maxmind's GeoIP databases</a> to accurately determine geographic location of an IP address.<br />
<a href="http://htmlblog.net/geolocate-your-visitors-with-php-part-1/">Tutorial from HTML Blog</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/File_Archive" target="_blank">File_Archive</a></h3>
<p><a href="http://pear.php.net/package/File_Archive" target="_blank">This library</a> makes it very easy to use, writing simple code, yet the library is very powerful.<br />
It lets you easily read or generate tar, gz, tgz, bz2, tbz, zip, ar (or deb) archives to files, memory, mail or standard output.<br />
<a href="http://poocl.la-grotte.org/index.php" target="_blank">File_Archive tutorial</a><br />
<a href="http://www.sitepoint.com/blogs/2005/08/06/file_archive/" target="_blank">SitePoint » File_Archive</a></p>
<h3 class="post-title"><a href="http://pear.php.net/package/XML_Serializer" target="_blank">XML_Serializer</a></h3>
<p><a href="http://pear.php.net/package/XML_Serializer" target="_blank">XML_Serializer</a> serializes complex data structures like arrays or object as XML documents.<br />
This class helps you generating any XML document you require without the need for DOM.<br />
Furthermore this package can be used as a replacement to serialize() and unserialize() as it comes with a matching</p>
<p>XML_Unserializer that is able to create PHP data structures (like arrays and objects) from XML documents, if type hints are available.<br />
If you use the XML_Unserializer on standard XML files, it will try to guess how it has to be unserialized. In most cases it does exactly what you expect it to do.</p>
<p><a href="http://www.devshed.com/index2.php?option=content&amp;task=view&amp;id=410&amp;pop=1&amp;page=0&amp;hide_js=1" target="_blank">Dev Shed XML_Serializer</a><br />
<a href="http://www.sitepoint.com/article/xml-php-pear-xml_serializer/" target="_blank">Instant XML with PHP and PEAR::XML_Serializer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/10-useful-php-pear-packages/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>twitree.com &#8211; 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, <del datetime="2009-01-07T06:10:37+00:00">rate limiting</del>, etc...</p>
<p>Stay tuned for further information</p>
<p><strong>Latest update :</strong></p>
<p>twitterers can now </p>
<ul>
<li>update their status via twitree</li>
<li>follow a user by right clicking on the user and choose "Follow" from the contextual menu</li>
<li>send a direct message to a fellow twitterer by right clicking on the user and choose "Send message" from the contextual menu</li>
</ul>
<p>FAQ has also been added</p>
]]></content:encoded>
			<wfw:commentRss>http://htmlblog.net/twitreecom-see-on-which-leaves-the-birds-are/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</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>
		<slash:comments>4</slash:comments>
		</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>
		<slash:comments>1</slash:comments>
		</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>
		<slash:comments>4</slash:comments>
		</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>
		<slash:comments>3</slash:comments>
		</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>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Pixidou &#8211; an Open Source AJAX Image Editor (PHP and YUI based)</title>
		<link>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/</link>
		<comments>http://htmlblog.net/pixidou-an-open-source-ajax-image-editor-php-and-yui-based/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 17:42:09 +0000</pubDate>
		<dc:creator>asvin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[brightness]]></category>
		<category><![CDATA[contrast]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[flip]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[image editor]]></category>
		<category><![CDATA[negative]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[rotate]]></category>
		<category><![CDATA[tint]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[yui]]></category>

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

adjust brightness
adjust contrast
cropping
flipping
negative
resizing
rotating
tint

images.

What you need to get running

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

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

<!-- Dynamic page generated in 5.665 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2009-07-05 04:04:05 -->
