<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://davidwalsh.name/wp-atom.php"><title type="text">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</title> <subtitle type="text">Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</subtitle><updated>2010-09-02T03:13:15Z</updated><link rel="alternate" type="text/html" href="http://davidwalsh.name" /> <id>http://davidwalsh.name/feed/atom</id><generator uri="http://wordpress.org/" version="3.0.1">WordPress</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Bludice" /><feedburner:info uri="bludice" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>43.072994</geo:lat><geo:long>-89.519924</geo:long><feedburner:emailServiceId>Bludice</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[MooTools Plugin:&#160;Event.Mock]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/s04ICqBxXrs/mootools-event" /> <id>http://davidwalsh.name/?p=5060</id> <updated>2010-09-02T03:13:15Z</updated> <published>2010-09-02T03:12:12Z</published> <category scheme="http://davidwalsh.name" term="MooTools" /> <summary type="html"><![CDATA[Those of you who visit this blog often know that I have a certain love for the simple things: simple CSS enhancements, simple PHP scripts, and most importantly, simple JavaScript plugins. One plugin that recently caught my attention was Arieh Glazer Event.Mock plugin. Event.Mock is a tiny MooTools plugin (essentially just a small function; not [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/mootools-event">MooTools Plugin:&nbsp;Event.Mock</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&nbsp;Listener'>dojo.connect: A Powerful Object and Event&nbsp;Listener</a></li><li><a
href='http://davidwalsh.name/mootools-event-stop' rel='bookmark' title='Permanent Link: MooTools Tip:&nbsp;Event.stop'>MooTools Tip:&nbsp;Event.stop</a></li><li><a
href='http://davidwalsh.name/count-mootools-events' rel='bookmark' title='Permanent Link: Count MooTools Events Per Element in MooTools&nbsp;1.2'>Count MooTools Events Per Element in MooTools&nbsp;1.2</a></li><li><a
href='http://davidwalsh.name/jquery-add-event' rel='bookmark' title='Permanent Link: Implement MooTools&#8217; Elements.addEvent in&nbsp;jQuery'>Implement MooTools&#8217; Elements.addEvent in&nbsp;jQuery</a></li><li><a
href='http://davidwalsh.name/plugin-element-filter' rel='bookmark' title='Permanent Link: New MooTools Plugin:&nbsp;ElementFilter'>New MooTools Plugin:&nbsp;ElementFilter</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/mootools-event">&lt;p&gt;Those of you who visit this blog often know that I have a certain love for the simple things:  simple CSS enhancements, simple PHP scripts, and most importantly, simple JavaScript plugins.  One plugin that recently caught my attention was Arieh Glazer Event.Mock plugin.  Event.Mock is a tiny MooTools plugin (essentially just a small function;  not a MooTools class) that does exactly what it says:  provides a Mock event for easy use with Element.fireEvent.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/http://mootools.net/forge/p/event_mock" class="demo"&gt;Download Event.Mock&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;Why&amp;nbsp;Event.Mock?&lt;/h2&gt;&lt;p&gt;One frequent MooTools occurrence is assigning an event to a given element, then firing an event on the given element.  The problem that occurs is that fireEvent doesn&amp;#8217;t provide an Event object to the event listener&amp;#8217;s function because a real event didn&amp;#8217;t occur.  Thus, if you reference the event within the listener function, you&amp;#8217;ll get an error:&lt;/p&gt;&lt;pre class="js"&gt;
/* assign an event to myElement */
$('myElement').addEvent('click',function(e) {
	var target = e.target;  /* ERROR! -- e is null */
})

/* fire an event */
$('myElement').fireEvent('click');
&lt;/pre&gt;&lt;p&gt;Event.Mock serves as a fake event to provide to the listener function.&lt;/p&gt;&lt;h2&gt;The Event.Mock MooTools&amp;nbsp;JavaScript&lt;/h2&gt;&lt;pre class="js"&gt;
/**
 * creates a Mock event to be used with fire event
 * @param Element target an element to set as the target of the event - not required
 *  @param string type the type of the event to be fired. Will not be used by IE - not required.
 *
 */
Event.Mock = function(target,type){
var e = window.event;
type = type || 'click';

if (document.createEvent){
    e = document.createEvent('HTMLEvents');
    e.initEvent(
        type, //event type
        false, //bubbles - set to false because the event should like normal fireEvent
        true //cancelable
    );
}
e = new Event(e);
e.target = target;
return e;
}
&lt;/pre&gt;&lt;p&gt;Event.Mock accepts two arguments: the first being the fake event&amp;#8217;s target element, the second being the type of event (i.e. &amp;#8220;click&amp;#8221;, &amp;#8220;mouseenter&amp;#8221;, etc.)  That means I can use Event.Mock as such:&lt;/p&gt;&lt;pre class="js"&gt;
/* listen! */
$('myElement').addEvent('click',function(e){
	/* log the event to the console */
	console.log(e);
});

/* fire! */
$('myElement').fireEvent('click',new Event.Mock($('myElement'),'mousedown'));
&lt;/pre&gt;&lt;p&gt;Boom.  No worries about event errors AND useful information, in the form of a fake event target and type, is event listener function.&lt;/p&gt;&lt;p&gt;Big ups to Arieh for his simple but useful MooTools plugin!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/mootools-event"&gt;MooTools Plugin:&amp;nbsp;Event.Mock&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&amp;nbsp;Listener'&gt;dojo.connect: A Powerful Object and Event&amp;nbsp;Listener&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/mootools-event-stop' rel='bookmark' title='Permanent Link: MooTools Tip:&amp;nbsp;Event.stop'&gt;MooTools Tip:&amp;nbsp;Event.stop&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/count-mootools-events' rel='bookmark' title='Permanent Link: Count MooTools Events Per Element in MooTools&amp;nbsp;1.2'&gt;Count MooTools Events Per Element in MooTools&amp;nbsp;1.2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/jquery-add-event' rel='bookmark' title='Permanent Link: Implement MooTools&amp;#8217; Elements.addEvent in&amp;nbsp;jQuery'&gt;Implement MooTools&amp;#8217; Elements.addEvent in&amp;nbsp;jQuery&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/plugin-element-filter' rel='bookmark' title='Permanent Link: New MooTools Plugin:&amp;nbsp;ElementFilter'&gt;New MooTools Plugin:&amp;nbsp;ElementFilter&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/s04ICqBxXrs" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/mootools-event#comments" thr:count="1" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/mootools-event/feed/atom" thr:count="1" /> <thr:total>1</thr:total> <feedburner:origLink>http://davidwalsh.name/mootools-event</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Duplicate the jQuery Homepage&#160;Tooltips]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/FdgTFtjsDiI/jquery-tooltips" /> <id>http://davidwalsh.name/?p=5056</id> <updated>2010-08-31T13:48:40Z</updated> <published>2010-08-31T13:48:40Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Markup" /><category scheme="http://davidwalsh.name" term="jQuery" /> <summary type="html"><![CDATA[The jQuery homepage has a pretty suave tooltip-like effect as seen below: The amount of jQuery required to duplicate this effect is next to nothing;  in fact, there&#8217;s more CSS than there is jQuery code!  Let&#8217;s explore how we can duplicate jQuery&#8217;s tooltip effect. View Demo The&#160;HTML The overall structure includes a wrapping DIV element [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/jquery-tooltips">Duplicate the jQuery Homepage&nbsp;Tooltips</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/jquery-homepage-mootools' rel='bookmark' title='Permanent Link: Duplicate the jQuery Homepage Tooltips Using&nbsp;MooTools'>Duplicate the jQuery Homepage Tooltips Using&nbsp;MooTools</a></li><li><a
href='http://davidwalsh.name/dojo-tooltips' rel='bookmark' title='Permanent Link: Duplicate the jQuery Homepage Tooltips Using&nbsp;Dojo'>Duplicate the jQuery Homepage Tooltips Using&nbsp;Dojo</a></li><li><a
href='http://davidwalsh.name/mootools-12-tooltips-customize' rel='bookmark' title='Permanent Link: MooTools 1.2 Tooltips: Customize Your&nbsp;Tips'>MooTools 1.2 Tooltips: Customize Your&nbsp;Tips</a></li><li><a
href='http://davidwalsh.name/jquery-comment-preview' rel='bookmark' title='Permanent Link: jQuery Comment&nbsp;Preview'>jQuery Comment&nbsp;Preview</a></li><li><a
href='http://davidwalsh.name/album-art' rel='bookmark' title='Permanent Link: Sexy Album Art with MooTools or&nbsp;jQuery'>Sexy Album Art with MooTools or&nbsp;jQuery</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/jquery-tooltips">&lt;p&gt;The jQuery homepage has a pretty suave tooltip-like effect as seen below:&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/dw-content/jquery-tooltips-jquery.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/jquery-home.png" alt="jQuery Tooltips" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The amount of jQuery required to duplicate this effect is next to nothing;  in fact, there&amp;#8217;s more CSS than there is jQuery code!  Let&amp;#8217;s explore how we can duplicate jQuery&amp;#8217;s tooltip effect.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/jquery-tooltips-jquery.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The&amp;nbsp;HTML&lt;/h2&gt;&lt;p&gt;The overall structure includes a wrapping DIV element with each tooltip link featured in a list:&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;div id="jq-intro" class="jq-clearfix"&amp;gt;
	&amp;lt;h2&amp;gt;jQuery is a new kind of JavaScript Library.&amp;lt;/h2&amp;gt;
	&amp;lt;p&amp;gt;jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and AJAX interactions for rapid web development. &amp;lt;strong&amp;gt;jQuery is designed to change the way that you write JavaScript.&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;
	&amp;lt;ul class="jq-checkpoints jq-clearfix"&amp;gt;
		&amp;lt;li&amp;gt;&amp;lt;a href="http://docs.jquery.com/Tutorials" title="Lightweight Footprint" class="jq-thickbox"&amp;gt;Lightweight Footprint&amp;lt;/a&amp;gt;
			&amp;lt;div class="jq-checkpointSubhead"&amp;gt;
				&amp;lt;p&amp;gt;About 18KB in size &amp;lt;em&amp;gt;(Minified and Gzipped)&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;
			&amp;lt;/div&amp;gt;
		&amp;lt;/li&amp;gt;
		&amp;lt;li&amp;gt;&amp;lt;a href="http://docs.jquery.com/Tutorials" title="CSS3 Compliant" class="jq-thickbox"&amp;gt;CSS3 Compliant&amp;lt;/a&amp;gt;
			&amp;lt;div class="jq-checkpointSubhead"&amp;gt;
				&amp;lt;p&amp;gt;Supports CSS 1-3 selectors and more!&amp;lt;/p&amp;gt;
			&amp;lt;/div&amp;gt;
		&amp;lt;/li&amp;gt;
		&amp;lt;li&amp;gt;&amp;lt;a href="http://docs.jquery.com/Tutorials" title="Cross-browser" class="jq-thickbox"&amp;gt;Cross-browser&amp;lt;/a&amp;gt;
			&amp;lt;div class="jq-checkpointSubhead"&amp;gt;
				&amp;lt;p&amp;gt;IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome&amp;lt;/p&amp;gt;
			&amp;lt;/div&amp;gt;
		&amp;lt;/li&amp;gt;
	&amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;p&gt;Note that the UL element has been given a jq-checkpoints CSS class &amp;#8212; we&amp;#8217;ll use that in a selector for both CSS styling and element collection using jQuery.&lt;/p&gt;&lt;h2&gt;The&amp;nbsp;CSS&lt;/h2&gt;&lt;p&gt;Like I said&amp;#8230;there&amp;#8217;s more CSS than there will be jQuery code:&lt;/p&gt;&lt;pre class="css"&gt;
#jq-intro 			{ padding-top:1em; width:605px; margin:0 auto; }
#jq-intro h2 		{ font-size:1.9em; font-weight:bold; color:#5DB0E6; line-height:1em; }
#jq-intro h2 span.jq-jquery { float:left; width:81px; height:23px; margin-right:.3em; position:relative; }
#jq-intro h2 span.jq-jquery span { position:absolute; left:-999999px; }
#jq-intro p 		{ clear:both; font-size:1.5em; margin:5px 0; font-weight:normal; line-height:1.6; }
#jq-intro ul 		{ padding:1.5em 0; list-style-type:none; }
#jq-intro li 		{ float:left; font-size:1.4em; }
#jq-intro li a 	{ color:#5DB0E6; font-weight:bold; text-decoration:underline; float:left; padding:0 30px 0 23px; }
#jq-intro li p 	{ font-size:12px; }
#jq-intro li 		{ position:relative; }
div.jq-checkpointSubhead { display:none; position:absolute; width:253px; height:54px; background:url(jquery-tooltip.png) 0 0 no-repeat; top:-1.5em; left:-35%; z-index:100; }
div.jq-checkpointSubhead p { font-size:1em; padding:10px 5px 0 50px; color:#AE0001; font-weight:bold; line-height:1.3em; margin:0; cursor:pointer; }
&lt;/pre&gt;&lt;p&gt;Most of the CSS is gloss for the overall look.  The important piece is the jq-checkpointSubhead CSS class being positioned absolutely and with an initial display value of none.  That will allow us to use the :hidden selector within jQuery.&lt;/p&gt;&lt;h2&gt;The jQuery&amp;nbsp;JavaScript&lt;/h2&gt;&lt;p&gt;And now for the jQuery JavaScript:&lt;/p&gt;&lt;pre class="js"&gt;
jQuery(document).ready(function() {
	var duration = 500;
	jQuery('.jq-checkpoints li').hover(
		function(){ jQuery(this).find('div.jq-checkpointSubhead:hidden').fadeIn(duration); },
		function(){ jQuery(this).find('div.jq-checkpointSubhead:visible').fadeOut(duration); }
	);
});
&lt;/pre&gt;&lt;p&gt;When the use hovers over the list items, the tooltip for the given list item fades in.  When the user leaves the list item, the tooltip fades out.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/jquery-tooltips-jquery.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;There you have it.  If you&amp;#8217;re interested in how to do this with out JavaScript frameworks, read my &lt;a
href="http://davidwalsh.name/jquery-homepage-mootools"&gt;MooTools&lt;/a&gt; and &lt;a
href="http://davidwalsh.name/dojo-tooltips"&gt;Dojo&lt;/a&gt; tutorials!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/jquery-tooltips"&gt;Duplicate the jQuery Homepage&amp;nbsp;Tooltips&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/jquery-homepage-mootools' rel='bookmark' title='Permanent Link: Duplicate the jQuery Homepage Tooltips Using&amp;nbsp;MooTools'&gt;Duplicate the jQuery Homepage Tooltips Using&amp;nbsp;MooTools&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-tooltips' rel='bookmark' title='Permanent Link: Duplicate the jQuery Homepage Tooltips Using&amp;nbsp;Dojo'&gt;Duplicate the jQuery Homepage Tooltips Using&amp;nbsp;Dojo&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/mootools-12-tooltips-customize' rel='bookmark' title='Permanent Link: MooTools 1.2 Tooltips: Customize Your&amp;nbsp;Tips'&gt;MooTools 1.2 Tooltips: Customize Your&amp;nbsp;Tips&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/jquery-comment-preview' rel='bookmark' title='Permanent Link: jQuery Comment&amp;nbsp;Preview'&gt;jQuery Comment&amp;nbsp;Preview&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/album-art' rel='bookmark' title='Permanent Link: Sexy Album Art with MooTools or&amp;nbsp;jQuery'&gt;Sexy Album Art with MooTools or&amp;nbsp;jQuery&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/FdgTFtjsDiI" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/jquery-tooltips#comments" thr:count="3" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/jquery-tooltips/feed/atom" thr:count="3" /> <thr:total>3</thr:total> <feedburner:origLink>http://davidwalsh.name/jquery-tooltips</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Quick Tip:  Object Indexing vs. Array&#160;Collection]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/nDTTU31_buY/object-array-index" /> <id>http://davidwalsh.name/?p=5052</id> <updated>2010-08-27T01:33:21Z</updated> <published>2010-08-26T13:47:13Z</published> <category scheme="http://davidwalsh.name" term="JavaScript" /><category scheme="http://davidwalsh.name" term="Optimization" /><category scheme="http://davidwalsh.name" term="PHP" /> <summary type="html"><![CDATA[The Setup &#38;&#160;Goal Let&#8217;s say that we have one large text document and we have a a bunch of keywords that we want to parse the document for.  We don&#8217;t care how many times times the keyword appears &#8212; we just care that it&#8217;s been used.  When we find a keyword, we need to record [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/object-array-index">Quick Tip:  Object Indexing vs. Array&nbsp;Collection</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/element-collection-manipulation-shortcut-using-mootools' rel='bookmark' title='Permanent Link: Element Collection Manipulation Shortcut Using MooTools&nbsp;1.2'>Element Collection Manipulation Shortcut Using MooTools&nbsp;1.2</a></li><li><a
href='http://davidwalsh.name/implementing-array-count-method-javascript' rel='bookmark' title='Permanent Link: Implementing an Array.count() Method in&nbsp;JavaScript'>Implementing an Array.count() Method in&nbsp;JavaScript</a></li><li><a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&nbsp;Listener'>dojo.connect: A Powerful Object and Event&nbsp;Listener</a></li><li><a
href='http://davidwalsh.name/array-shuffling-mootools' rel='bookmark' title='Permanent Link: Implement Array Shuffling in&nbsp;MooTools'>Implement Array Shuffling in&nbsp;MooTools</a></li><li><a
href='http://davidwalsh.name/access-object-properties' rel='bookmark' title='Permanent Link: Access JavaScript Object Variable&nbsp;Properties'>Access JavaScript Object Variable&nbsp;Properties</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/object-array-index">&lt;h2&gt;The Setup &amp;amp;&amp;nbsp;Goal&lt;/h2&gt;&lt;p&gt;Let&amp;#8217;s say that we have one large text document and we have a a bunch of keywords that we want to parse the document for.  We don&amp;#8217;t care how many times times the keyword appears &amp;#8212; we just care that it&amp;#8217;s been used.  When we find a keyword, we need to record that keyword been found so that we may check at a later time.&lt;/p&gt;&lt;h2&gt;Inefficient Method:  Array Collection and&amp;nbsp;Search&lt;/h2&gt;&lt;p&gt;The first method to record that a keyword has been found is by pushing the keyword into one array:&lt;/p&gt;&lt;pre class="js"&gt;
//Assume an array called "foundKeywords" was defined above
if(shouldSave(keyword)) {
	foundKeywords.push(keyword);
}
&lt;/pre&gt;&lt;p&gt;At the end of the document search, we&amp;#8217;d end up with an array like:&lt;/p&gt;&lt;pre class="js"&gt;
//the foundKeywords array looks like:
//['keyword1','keyword2','keyword2',...]
&lt;/pre&gt;&lt;p&gt;When it comes to checking this array for the existence of a given keyword, this method will prove inefficient.  Why?  Because we&amp;#8217;d need to loop through the array and search until we found the given keyword (if ever).  Those are a lot of &amp;#8220;wasted&amp;#8221; or fruitless cycles, even if we break the loop when the keyword was found.  Inefficient is the only word to describe this process.&lt;/p&gt;&lt;h2&gt;The Efficient Method:  Object with&amp;nbsp;Index&lt;/h2&gt;&lt;p&gt;The fastest method of checking a storing keywords for later reference is by object (in JavaScript) or associative array (in PHP).  Instead of adding the keyword to an array, we add the keyword as an index to a master object, giving the value as 1:&lt;/p&gt;&lt;pre class="js"&gt;
//Assume an object {} called "foundKeywords" was defined above
if(shouldSave(keyword)) {
	foundKeywords[keyword] = 1;
}
&lt;/pre&gt;&lt;p&gt;Why is this faster?  No wasted cycles looking blindly through an array.  The check is quick and simple:&lt;/p&gt;&lt;pre class="js"&gt;
if(foundKeywords[keyword]) { //FOUND!
	//do something
}
&lt;/pre&gt;&lt;p&gt;It&amp;#8217;s either an index or it&amp;#8217;s not!  In PHP, we&amp;#8217;d save the keyword to an associative array:&lt;/p&gt;&lt;pre class="php"&gt;
//Assume an array called "$found_keywords" was defined above
if(shouldSave($keyword)) {
	$found_keywords[$keyword] = 1;
}

//Later: checking if the keyword was there...
if($found_keywords[$keyword]) { //or array_key_exists($keyword,$found_keywords)
	//FOUND!
}
&lt;/pre&gt;&lt;p&gt;In a word&amp;#8230;awesome.  Not only fast but simple!&lt;/p&gt;&lt;p&gt;I cannot provide a benchmark because the speed of execution depends on how large the keyword array is.  Suffice to say, for the sake of simplicity and speed, using an object with keyword index is definitely the way to go!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/object-array-index"&gt;Quick Tip:  Object Indexing vs. Array&amp;nbsp;Collection&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/element-collection-manipulation-shortcut-using-mootools' rel='bookmark' title='Permanent Link: Element Collection Manipulation Shortcut Using MooTools&amp;nbsp;1.2'&gt;Element Collection Manipulation Shortcut Using MooTools&amp;nbsp;1.2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/implementing-array-count-method-javascript' rel='bookmark' title='Permanent Link: Implementing an Array.count() Method in&amp;nbsp;JavaScript'&gt;Implementing an Array.count() Method in&amp;nbsp;JavaScript&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&amp;nbsp;Listener'&gt;dojo.connect: A Powerful Object and Event&amp;nbsp;Listener&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/array-shuffling-mootools' rel='bookmark' title='Permanent Link: Implement Array Shuffling in&amp;nbsp;MooTools'&gt;Implement Array Shuffling in&amp;nbsp;MooTools&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/access-object-properties' rel='bookmark' title='Permanent Link: Access JavaScript Object Variable&amp;nbsp;Properties'&gt;Access JavaScript Object Variable&amp;nbsp;Properties&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/nDTTU31_buY" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/object-array-index#comments" thr:count="20" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/object-array-index/feed/atom" thr:count="20" /> <thr:total>20</thr:total> <feedburner:origLink>http://davidwalsh.name/object-array-index</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Create a Twitter AJAX Button with MooTools, jQuery, or&#160;Dojo]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/dNvXJRlAF1c/twitter-button" /> <id>http://davidwalsh.name/?p=5049</id> <updated>2010-08-26T13:35:48Z</updated> <published>2010-08-25T03:28:19Z</published> <category scheme="http://davidwalsh.name" term="AJAX" /><category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Dojo" /><category scheme="http://davidwalsh.name" term="Markup" /><category scheme="http://davidwalsh.name" term="MooTools" /><category scheme="http://davidwalsh.name" term="jQuery" /> <summary type="html"><![CDATA[There&#8217;s nothing like a subtle, slick website widget that effectively uses CSS and JavaScript to enhance the user experience.  Of course widgets like that take many hours to perfect, but it doesn&#8217;t take long for that effort to be rewarded with above-average user retention and buzz.  One of the widgets I love is Twitter&#8217;s &#8220;Follow&#8221; [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/twitter-button">Create a Twitter AJAX Button with MooTools, jQuery, or&nbsp;Dojo</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/dojo-twitter' rel='bookmark' title='Permanent Link: Create Twitter-Style Buttons with the Dojo&nbsp;Toolkit'>Create Twitter-Style Buttons with the Dojo&nbsp;Toolkit</a></li><li><a
href='http://davidwalsh.name/github-css' rel='bookmark' title='Permanent Link: Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&nbsp;JavaScript'>Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&nbsp;JavaScript</a></li><li><a
href='http://davidwalsh.name/dojo-ajax' rel='bookmark' title='Permanent Link: Animated AJAX Record Deletion Using&nbsp;Dojo'>Animated AJAX Record Deletion Using&nbsp;Dojo</a></li><li><a
href='http://davidwalsh.name/animated-button' rel='bookmark' title='Permanent Link: Create an Animated Sliding Button Using&nbsp;MooTools'>Create an Animated Sliding Button Using&nbsp;MooTools</a></li><li><a
href='http://davidwalsh.name/twitter-dropdown-jquery' rel='bookmark' title='Permanent Link: Create Twitter-Style Dropdowns Using&nbsp;jQuery'>Create Twitter-Style Dropdowns Using&nbsp;jQuery</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/twitter-button">&lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/twitter-button.jpg" alt="Twitter Button" class="image" /&gt;&lt;/a&gt;&lt;p&gt;There&amp;#8217;s nothing like a subtle, slick website widget that effectively uses CSS and JavaScript to enhance the user experience.  Of course widgets like that take many hours to perfect, but it doesn&amp;#8217;t take long for that effort to be rewarded with above-average user retention and buzz.  One of the widgets I love is Twitter&amp;#8217;s &amp;#8220;Follow&amp;#8221; button.  Let me show you how you can implement this functionality with three popular JavaScript toolkits:  MooTools, jQuery, and Dojo.&lt;/p&gt;&lt;p&gt;&lt;em&gt;Note:  This tutorial will only display the client side handling of the form submission &amp;#8212; NOT any PHP/MySQL/server-side handling of the request.&lt;/em&gt;&lt;/p&gt;&lt;div
class="actions"&gt; &lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php" class="demo"&gt;View MooTools Demo&lt;/a&gt; &lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php?lib=dojo" class="demo"&gt;View Dojo Demo&lt;/a&gt; &lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php?lib=jquery" class="demo"&gt;View jQuery Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The HTML&amp;nbsp;Structure&lt;/h2&gt;&lt;pre class="html"&gt;
&lt;form class="follow-form" method="post" action="twitter-follow.php"&gt;
	&lt;input type="hidden" name="followID" value="123456" /&gt;
	&lt;button type="submit" value="Actions" class="btn follow" title="123456"&gt;
		&lt;i&gt;&lt;/i&gt;&lt;span&gt;follow&lt;/span&gt;
	&lt;/button&gt;
&lt;/form&gt;
&lt;/pre&gt;&lt;p&gt;The HTML for the button is very simple.  The structure revolves around a BUTTON element which contains an I element and SPAN element.  You&amp;#8217;re probably thinking &amp;#8220;An I element?  WTF.&amp;#8221;  I know I did.  The truth of the matter is that the I element is deprecated and, as far as I&amp;#8217;m concerned, and be used for any purpose the developer would like.  I&amp;#8217;m also sure that Twitter doesn&amp;#8217;t mind saving bytes here or there.&lt;/p&gt;&lt;h2&gt;The CSS&amp;nbsp;Styles&lt;/h2&gt;&lt;pre class="css"&gt;
/* twitter button and its children */
button.btn { 
	-moz-border-radius:4px;
	-webkit-border-radius:4px;
	background-attachment:scroll;
	background-color:#ddd;
	background-image:url(http://s.twimg.com/a/1282150308/images/buttons/bg-btn.gif);
	background-position:0 0;
	background-repeat:repeat-x;
	border:1px solid #ddd;
	border-bottom:1px solid #ccc;
	color:#333;
	cursor:pointer;
	font-family:"Lucida Grande",sans-serif;
	font-size:11px;
	line-height:14px;
	padding:4px 8px 5px 8px;
	text-shadow:1px 1px 0 #fff;
	vertical-align:top;
}
button.btn:hover {
	border:1px solid #999;
	border-bottom-color:#888;
	color:#000;
	background-color:#d5d5d5;
	background-position:0 -6px;
}
button.btn:active {
	background-image:none !important;
	text-shadow:none !important;
}
			
button.btn i {
	background-image:url(http://s.twimg.com/a/1282150308/images/sprite-icons.png);
	background-position:-176px -32px;
	background-repeat:no-repeat;
	display:inline-block;
	height:13px;
	margin-right:5px;
	width:15px;
}
button.btn i.active	{ background:url(http://s.twimg.com/a/1282150308/images/spinner.gif); }

/* properties for the element that is generated *after* following */
span.following	{  background:#ffd; padding:5px 10px; }
span.following span { width:10px; height:9px; margin-right:5px; display:inline-block; background:url("http://s.twimg.com/a/1282150308/images/sprite-icons.png") -160px -16px no-repeat; }
&lt;/pre&gt;&lt;p&gt;Most of the styling for this button goes onto the BUTTON element itself.  You&amp;#8217;ll notice directives to round the button;  leaving the button sharp also please the eye.  Through the regular, hover, and active button states, check out how Twitter users the background position and colors to nicely modify the button without the need for additional images.  You&amp;#8217;ll also notice Twitter uses sprites&amp;#8230;as should you.&lt;/p&gt;&lt;h2&gt;The MooTools&amp;nbsp;JavaScript&lt;/h2&gt;&lt;pre class="js"&gt;
/* with mootools */
window.addEvent('domready',function() {
	/* fetch elements */
	$$('form.follow-form').each(function(form) {
		/* stop form event */
		form.addEvent('submit',function(e) {
			/* stop event */
			if(e) e.stop();
			/* send ajax request */
			var i = form.getElement('i');
			new Request({
				url: 'twitter-follow.php',
				method: 'post',
				data: {
					followID: form.getElement('input').value
				},
				onRequest: function() {
					i.addClass('active');
				},
				onSuccess: function() {
					var button = form.getElement('button');
					button.setStyle('display','none');
					new Element('span',{
						html: '&lt;span&gt;&lt;/span&gt;Following!',
						'class': 'following'
					}).inject(button,'after');
				},
				onComplete: function() {
					i.removeClass('active');
				}
			}).send();
		});
	});
});
&lt;/pre&gt;&lt;p&gt;The first step is grabbing all of the FORM elements with the follow-form CSS class.  Upon form submission, the default submission action is stopped.  An AJAX request is fired, using the INPUT element&amp;#8217;s ID as the user to follow.  When the request is fired, the I element&amp;#8217;s background image is set to the spinner.  When the request is complete, the button is hidden and a new SPAN element is displayed informing the user that they are now following the given user!&lt;/p&gt;&lt;h2&gt;The jQuery&amp;nbsp;JavaScript&lt;/h2&gt;&lt;pre class="js"&gt;
// Idiomatic jQuery by Doug Neiner
jQuery(function ($) {
	/* fetch elements and stop form event */
	$("form.follow-form").submit(function (e) {
		/* stop event */
		e.preventDefault();
		/* "on request" */
		$(this).find('i').addClass('active');
		/* send ajax request */
		$.post('twitter-follow.php', {
			followID: $(this).find('input').val()
		}, function () {
			/* find and hide button, create element */
			$(e.currentTarget)
			  .find('button').hide()
			  .after('&amp;lt;span class="following"&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;Following!&amp;lt;/span&amp;gt;');
		});
	});
});
&lt;/pre&gt;&lt;p&gt;The code above is based off of the MooTools code.  The workflow is exactly the same.&lt;/p&gt;&lt;h2&gt;The Dojo&amp;nbsp;JavaScript&lt;/h2&gt;&lt;pre class="js"&gt;
/* when the DOM is ready */
dojo.ready(function() {
	/* fetch elements */
	dojo.query('form.follow-form').forEach(function(form) {
		/* stop form event */
		dojo.connect(form,'onsubmit',function(e) {
			/* stop event */
			dojo.stopEvent(e);
			/* active class */
			dojo.query('i',form).addClass('active');
			/* get button */
			var button = dojo.query('button',form)[0];
			/* ajax request */
			dojo.xhrPost({
				form: form,
				load: function() {
					dojo.style(button,'display','none');
					dojo.create('span',{
						innerHTML: '&lt;span&gt;&lt;/span&gt;Following',
						className: 'following'
					},button,'after');
				}
			});
		});
	});
});
&lt;/pre&gt;&lt;p&gt;The code above is based off of the MooTools code.  The workflow is exactly the same.&lt;/p&gt;&lt;div
class="actions"&gt; &lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php" class="demo"&gt;View MooTools Demo&lt;/a&gt; &lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php?lib=dojo" class="demo"&gt;View Dojo Demo&lt;/a&gt; &lt;a
href="http://davidwalsh.name/dw-content/twitter-follow.php?lib=jquery" class="demo"&gt;View jQuery Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This &amp;#8220;Follow&amp;#8221; button is only one of many details that Twitter has paid attention to, just to make the user experience on the site better.  Take note from the effort put forth by large websites &amp;#8212; adding these types of details to your smaller websites can make the user experience much better for YOUR users!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/twitter-button"&gt;Create a Twitter AJAX Button with MooTools, jQuery, or&amp;nbsp;Dojo&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-twitter' rel='bookmark' title='Permanent Link: Create Twitter-Style Buttons with the Dojo&amp;nbsp;Toolkit'&gt;Create Twitter-Style Buttons with the Dojo&amp;nbsp;Toolkit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/github-css' rel='bookmark' title='Permanent Link: Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&amp;nbsp;JavaScript'&gt;Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&amp;nbsp;JavaScript&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-ajax' rel='bookmark' title='Permanent Link: Animated AJAX Record Deletion Using&amp;nbsp;Dojo'&gt;Animated AJAX Record Deletion Using&amp;nbsp;Dojo&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/animated-button' rel='bookmark' title='Permanent Link: Create an Animated Sliding Button Using&amp;nbsp;MooTools'&gt;Create an Animated Sliding Button Using&amp;nbsp;MooTools&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/twitter-dropdown-jquery' rel='bookmark' title='Permanent Link: Create Twitter-Style Dropdowns Using&amp;nbsp;jQuery'&gt;Create Twitter-Style Dropdowns Using&amp;nbsp;jQuery&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/dNvXJRlAF1c" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/twitter-button#comments" thr:count="8" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/twitter-button/feed/atom" thr:count="8" /> <thr:total>8</thr:total> <feedburner:origLink>http://davidwalsh.name/twitter-button</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Create a Dynamic Flickr Image Search with the Dojo&#160;Toolkit]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/y_eSmRTYM-4/dojo-flickr" /> <id>http://davidwalsh.name/?p=5051</id> <updated>2010-08-24T15:01:56Z</updated> <published>2010-08-24T01:46:49Z</published> <category scheme="http://davidwalsh.name" term="AJAX" /><category scheme="http://davidwalsh.name" term="APIs" /><category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Dojo" /><category scheme="http://davidwalsh.name" term="Markup" /> <summary type="html"><![CDATA[The Dojo Toolkit is a treasure chest of great JavaScript classes.  You can find basic JavaScript functionality classes for AJAX, node manipulation, animations, and the like within Dojo.  You can find elegant, functional UI widgets like DropDown Menus, tabbed interfaces, and form element replacements within Dijit.  In DojoX you can find charting libraries, special data [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/dojo-flickr">Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/dojo-context-menu' rel='bookmark' title='Permanent Link: Create a Context Menu with Dojo and&nbsp;Dijit'>Create a Context Menu with Dojo and&nbsp;Dijit</a></li><li><a
href='http://davidwalsh.name/dojo-accordion' rel='bookmark' title='Permanent Link: Create a Simple Dojo&nbsp;Accordion'>Create a Simple Dojo&nbsp;Accordion</a></li><li><a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&nbsp;Charting'>Dive Into Dojo Series:  Dijit and&nbsp;Charting</a></li><li><a
href='http://davidwalsh.name/dojo-digg' rel='bookmark' title='Permanent Link: Digg-Style Dynamic Share Widget Using the Dojo&nbsp;Toolkit'>Digg-Style Dynamic Share Widget Using the Dojo&nbsp;Toolkit</a></li><li><a
href='http://davidwalsh.name/dojo-tabs' rel='bookmark' title='Permanent Link: Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content'>Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/dojo-flickr">&lt;p&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-flickr.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/dojo-flickr.jpg" alt="Dojo Flickr" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The Dojo Toolkit is a treasure chest of great JavaScript classes.  You can find basic JavaScript functionality classes for AJAX, node manipulation, animations, and the like within Dojo.  You can find elegant, functional UI widgets like DropDown Menus, tabbed interfaces, and form element replacements within Dijit.  In DojoX you can find charting libraries, special data stores, vector graphic helpers, and much more.&lt;/p&gt;&lt;p&gt;This post aims to mesh the three collections together.  We&amp;#8217;ll be creating a tabbed interface for grabbing Flickr images using Dijit&amp;#8217;s TabContainer, &lt;a
href="http://www.dojotoolkit.org/reference-guide/dojox/data/FlickrStore.html#dojox-data-flickrstore" rel="nofollow"&gt;DojoX&amp;#8217;s Flickr data store&lt;/a&gt;, and basic Dojo code for event handling and node manipulation.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-flickr.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;Select a&amp;nbsp;Theme&lt;/h2&gt;&lt;p&gt;There are two main steps in adding a theme to the page:  importing the theme stylesheet and adding the theme as a class name to the &lt;code&gt;BODY&lt;/code&gt; element.&lt;/p&gt;&lt;pre class="css"&gt;
&amp;lt;style type="text/css"&amp;gt;
	/* bring in the claro theme */
	@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css";
	
	/* define styles per the images */
	a.thumb	{ display:inline-block; margin:0 20px 20px 0; }
	
&amp;lt;/style&amp;gt;
&lt;/pre&gt;&lt;pre class="html"&gt;
&amp;lt;body class="claro"&amp;gt;
&lt;/pre&gt;&lt;p&gt;The claro theme is new in Dojo 1.5 and happens to be my favorite.&lt;/p&gt;&lt;h2&gt;Import Dojo From CDN,&amp;nbsp;parseOnLoad:true&lt;/h2&gt;&lt;p&gt;Pulling from Google&amp;#8217;s CDN makes Dojo load lightning-fast.  Adding a &lt;code&gt;djConfig&lt;/code&gt; attribute with &lt;code&gt;parseOnLoad:true&lt;/code&gt; instructs Dojo to scour the page looking for widgets.&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript" djConfig="parseOnLoad:true"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;p&gt;Alternatively you could configure Dojo by using the &lt;code&gt;djConfig&lt;/code&gt; JavaScript variable:&lt;/p&gt;&lt;pre class=" js"&gt;
djConfig = {
	parseOnLoad: true
};
&lt;/pre&gt;&lt;p&gt;Either way will suffice.&lt;/p&gt;&lt;h2&gt;Create the HTML Structure: Tab Container and Search&amp;nbsp;Form&lt;/h2&gt;&lt;p&gt;Setting up the form comes first.  The form is going to be very simple, containing only a search box and a submit button.  Each node (&lt;code&gt;FORM&lt;/code&gt;, &lt;code&gt;INPUT&lt;/code&gt;, and &lt;code&gt;BUTTON&lt;/code&gt;) is converted to its Dijit widget equivalent to provide extra functionality and themed display.&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;!-- search will be here --&amp;gt;
&amp;lt;form dojoType="dijit.form.Form" id="searchForm"&amp;gt;
	&amp;lt;input dojoType="dijit.form.ValidationTextBox" id="searchBox" missingMessage="Please provide a term to search" placeholder="search term..." required="true" /&amp;gt;
	&amp;lt;button type="submit" dojoType="dijit.form.Button" id="searchButton"&amp;gt;Submit Search&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/pre&gt;&lt;p&gt;The search box becomes a &lt;code&gt;dijit.form.ValidationTextBox&lt;/code&gt; which allows me to require a value and display an error message if no term is provided.  I&amp;#8217;ve also used the &lt;code&gt;placeholder&lt;/code&gt; attribute to display a message in the search box when there is no value.  Dojo&amp;#8217;s internal awesomeness adds JavaScript support for the same functionality if the user&amp;#8217;s browser doesn&amp;#8217;t support &lt;code&gt;placeholder&lt;/code&gt; yet.&lt;/p&gt;&lt;p&gt;The second piece is placing the &lt;code&gt;TabContainer&lt;/code&gt; and its initial content pane in the page.  The initial &lt;code&gt;ContentPane&lt;/code&gt; content will simply be a &amp;#8220;welcome&amp;#8221; tab so that there&amp;#8217;s always one tab within the container:&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;!-- will set the eventual dimensions for the tab container --&amp;gt;
&amp;lt;div style="width:675px;height:400px"&amp;gt;
	&amp;lt;!-- will host all tabs and their content panes --&amp;gt;
	&amp;lt;div dojoType="dijit.layout.TabContainer" id="tabContainer" style="width:100%;height:100%;"&amp;gt;
		&amp;lt;!-- welcome pane: title is tab name, make this tab selected --&amp;gt;
		&amp;lt;div dojoType="dijit.layout.ContentPane" title="Welcome Pane" selected="true"&amp;gt;
			&amp;lt;p&amp;gt;
				Welcome to the Flickr Search data store and Tab Container example.  
				Submit your search and watch the tab load!
			&amp;lt;/p&amp;gt;
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;p&gt;Future tabs will be closable.&lt;/p&gt;&lt;h2&gt;Require Dojo/Dijit/DojoX&amp;nbsp;Dependencies&lt;/h2&gt;&lt;p&gt;Before we can create our widgets and use Dojo classes, we need to load them:&lt;/p&gt;&lt;pre class="js"&gt;
/* require necessary classes */
dojo.require('dijit.layout.TabContainer');
dojo.require('dijit.layout.ContentPane');
dojo.require('dijit.form.Button');
dojo.require('dijit.form.Form');
dojo.require('dijit.form.ValidationTextBox');
dojo.require('dojox.data.FlickrStore');
dojo.require('dijit.Tooltip');
&lt;/pre&gt;&lt;p&gt;Dojo&amp;#8217;s internal functionality will also direct dependencies of dependencies to be loaded.  If you aren&amp;#8217;t familiar with Dojo class loading, be sure to read &lt;a
href="http://davidwalsh.name/dojo-require"&gt;The Beauty of dojo.require()&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Dojo, Dijit, DojoX:  Make It&amp;nbsp;Happen&lt;/h2&gt;&lt;p&gt;Now that the theme is in place, HTML structure is there, and we&amp;#8217;ve required the necessary classes, we can code our application-specific JavaScript.  There&amp;#8217;s a decent amount of JavaScript need to make this work so let&amp;#8217;s break it down.&lt;/p&gt;&lt;p&gt;Start by creating an object which will hold all of our open tabs and an instance of &lt;code&gt;dojox.data.FlickrStore&lt;/code&gt; which will be used to query Flickr:&lt;/p&gt;&lt;pre class="js"&gt;
/* settings */
var tabSubjects = {};
var flickrStore = new dojox.data.FlickrStore();
&lt;/pre&gt;&lt;p&gt;Then collect the form elements as well as the &lt;code&gt;TabContainer&lt;/code&gt;:&lt;/p&gt;&lt;pre class="js"&gt;
/* collect proper elements */
var searchForm = dijit.byId('searchForm');
var searchBox = dijit.byId('searchBox');
var searchButton = dijit.byId('searchButton');
var tabContainer = dijit.byId('tabContainer');
&lt;/pre&gt;&lt;p&gt;Add a &amp;#8220;submit&amp;#8221; event listener to the &lt;code&gt;TabContainer&lt;/code&gt;&amp;#8230;&lt;/p&gt;&lt;pre class="js"&gt;
/* connect click event to search */
dojo.connect(searchForm,'onSubmit',function(e) {
&lt;/pre&gt;&lt;p&gt;&amp;#8230;which stops the normal form submission:&lt;/p&gt;&lt;pre class="js"&gt;
//stop!
dojo.stopEvent(e);
&lt;/pre&gt;&lt;p&gt;&amp;#8230;grabs the value of the search box:&lt;/p&gt;&lt;pre class="js"&gt;
//store value - set to lower case to save to caching object
var value = searchBox.get('value').toLowerCase();
&lt;/pre&gt;&lt;p&gt;If a value is present, make sure there isn&amp;#8217;t currently a search tab open for that term.  If there is, focus on it.  If this is a new search term, direct the &lt;code&gt;dojox.data.FlickrStore&lt;/code&gt; instance to search and return images for the given term.  Upon search, a new tab for this term is created with a default title and content string, added to the TabContainer, and this new tab is selected:&lt;/p&gt;&lt;pre class="js"&gt;
//if a value exists...
if(value) {
	//if the tab isn't already there...
	if(!tabSubjects[value]) {
		//do the search...
		flickrStore.fetch({
			query: { tags: value },
			onBegin: function() {
				//create the tab
				tabSubjects[value] = new dijit.layout.ContentPane({ 
					title:value, 
					content:'Searching for ' + value + '...', 
					closable:true,
					onClose: function() {
						//remove this from our saved tabs when closed
						tabSubjects[value] = null;
						return true;
					}
				});
				//add to tabcontainer and select
				tabContainer.addChild(tabSubjects[value]);
				tabContainer.selectChild(tabSubjects[value]);
			},
&lt;/pre&gt;&lt;p&gt;When the search is complete, we clear the contents of the tab&amp;#8217;s pane and loop through each returned image, injecting it into the content pane.  Lastly, we create a tooltip for the image which displays the image name when the user focuses on the image:&lt;/p&gt;&lt;pre class="js"&gt;
	onComplete: function(items) {
		//if we got items...
		if(items.length) {
			//clear the tab's content'
			tabSubjects[value].set('content','');
			//cycle through each image returned, inject into new tab, add tooltip
			dojo.forEach(items,function(item,i) {
				//create the link's ID for the tooltip
				var id = new Date().getTime() + '_' + i;
				var a = dojo.create('a',{ 
					href: flickrStore.getValue(item,'link'),
					className: 'thumb',
					target: '_blank',
					id:  id,
					innerHTML: '&amp;lt;img src="' + flickrStore.getValue(item,'imageUrlSmall') + '" alt="' + flickrStore.getValue(item,'title') +'" /&amp;gt;'
				},tabSubjects[value].domNode);
				//tooltip!
				new dijit.Tooltip({ label: flickrStore.getValue(item,'title'), connectId: id });
			});
		}
		else {
			//provide "no images" content
			tabSubjects[value].set('content','There were no images available for this term.');
		}
		//empty the search box
		searchBox.set('value','');
		
	}
});
&lt;/pre&gt;&lt;p&gt;Here&amp;#8217;s the complete JavaScript block for this app:&lt;/p&gt;&lt;pre class="js"&gt;
/* require necessary classes */
dojo.require('dijit.layout.TabContainer');
dojo.require('dijit.layout.ContentPane');
dojo.require('dijit.form.Button');
dojo.require('dijit.form.Form');
dojo.require('dijit.form.ValidationTextBox');
dojo.require('dojox.data.FlickrStore');
dojo.require('dijit.Tooltip');

/* when all classes have loaded... */
dojo.ready(function() {
	
	/* settings */
	var tabSubjects = {};
	var flickrStore = new dojox.data.FlickrStore();
	
	/* collect proper elements */
	var searchForm = dijit.byId('searchForm');
	var searchBox = dijit.byId('searchBox');
	var searchButton = dijit.byId('searchButton');
	var tabContainer = dijit.byId('tabContainer');
	
	/* connect click event to search */
	dojo.connect(searchForm,'onSubmit',function(e) {
		//stop!
		dojo.stopEvent(e);
		//store value
		var value = searchBox.get('value').toLowerCase();
		//if a value exists...
		if(value) {
			//if the tab isn't already there...
			if(!tabSubjects[value]) {
				//do the search...
				flickrStore.fetch({
					query: { tags: value },
					onBegin: function() {
						//create the tab
						tabSubjects[value] = new dijit.layout.ContentPane({ 
							title:value, 
							content:'Searching for ' + value + '...', 
							closable:true,
							onClose: function() {
								//remove this from our saved tabs when closed
								tabSubjects[value] = null;
								return true;
							}
						});
						//add to tabcontainer and select
						tabContainer.addChild(tabSubjects[value]);
						tabContainer.selectChild(tabSubjects[value]);
					},
					onComplete: function(items) {
						//if we got items...
						if(items.length) {
							//clear the tab's content'
							tabSubjects[value].set('content','');
							//cycle through each image returned, inject into new tab, add tooltip
							dojo.forEach(items,function(item,i) {
								//create the link's ID for the tooltip
								var id = new Date().getTime() + '_' + i;
								var a = dojo.create('a',{ 
									href: flickrStore.getValue(item,'link'),
									className: 'thumb',
									target: '_blank',
									id:  id,
									innerHTML: '&amp;lt;img src="' + flickrStore.getValue(item,'imageUrlSmall') + '" alt="' + flickrStore.getValue(item,'title') +'" /&amp;gt;'
								},tabSubjects[value].domNode);
								//tooltip!
								if(flickrStore.getValue(item,'title')) { new dijit.Tooltip({ label: flickrStore.getValue(item,'title'), connectId: id }); }
							});
						}
						else {
							//provide "no images" content
							tabSubjects[value].set('content','There were no images available for this term.');
						}
						//empty the search box
						searchBox.set('value','');
						
					}
				});
			}
			//if it does exist, focus on it
			else {
				tabContainer.selectChild(tabSubjects[value]);
			}
		}
	});
});
&lt;/pre&gt;&lt;p&gt;How long would you say this took to write?  Half hour?  Hour? Three hours?  Nope.  This mini-application only took me about 15 minutes to write!  DojoX also features a class for pulling images from Picasa.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-flickr.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Nice, huh?  Meshing Dojo, Dijit, and DojoX classes is a breeze thanks to Dojo&amp;#8217;s tightly knit class system.  I challenge you to create a simple application and see what you can do in an hour.  Use &lt;a
href="http://download.dojotoolkit.org/release-1.5.0/dojo-release-1.5.0/dijit/themes/themeTester.html"&gt;Theme Tester&lt;/a&gt; as a helper should you need inspiration!  And always share what you&amp;#8217;ve created when you&amp;#8217;re done!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/dojo-flickr"&gt;Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-context-menu' rel='bookmark' title='Permanent Link: Create a Context Menu with Dojo and&amp;nbsp;Dijit'&gt;Create a Context Menu with Dojo and&amp;nbsp;Dijit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-accordion' rel='bookmark' title='Permanent Link: Create a Simple Dojo&amp;nbsp;Accordion'&gt;Create a Simple Dojo&amp;nbsp;Accordion&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting'&gt;Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-digg' rel='bookmark' title='Permanent Link: Digg-Style Dynamic Share Widget Using the Dojo&amp;nbsp;Toolkit'&gt;Digg-Style Dynamic Share Widget Using the Dojo&amp;nbsp;Toolkit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-tabs' rel='bookmark' title='Permanent Link: Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content'&gt;Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/y_eSmRTYM-4" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/dojo-flickr#comments" thr:count="3" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/dojo-flickr/feed/atom" thr:count="3" /> <thr:total>3</thr:total> <feedburner:origLink>http://davidwalsh.name/dojo-flickr</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Dijit&#8217;s TabContainer Layout:  Easy Tabbed&#160;Content]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/HGLkOyyr_68/dojo-tabs" /> <id>http://davidwalsh.name/?p=5039</id> <updated>2010-08-23T03:56:15Z</updated> <published>2010-08-23T03:56:15Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Dojo" /><category scheme="http://davidwalsh.name" term="Markup" /> <summary type="html"><![CDATA[One of Dojo&#8217;s major advantages over other JavaScript toolkits is its Dijit library.  Dijit is a UI framework comprised of JavaScript widget classes, CSS files, and HTML templates.  One very useful layout class is the TabContainer.  TabContainer allows you to quickly create a tabbed content layout with minimal effort.  Keep reading to see what you [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/dojo-tabs">Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/dojo-accordion' rel='bookmark' title='Permanent Link: Create a Simple Dojo&nbsp;Accordion'>Create a Simple Dojo&nbsp;Accordion</a></li><li><a
href='http://davidwalsh.name/dojo-context-menu' rel='bookmark' title='Permanent Link: Create a Context Menu with Dojo and&nbsp;Dijit'>Create a Context Menu with Dojo and&nbsp;Dijit</a></li><li><a
href='http://davidwalsh.name/dojo-flickr' rel='bookmark' title='Permanent Link: Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit'>Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit</a></li><li><a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&nbsp;Charting'>Dive Into Dojo Series:  Dijit and&nbsp;Charting</a></li><li><a
href='http://davidwalsh.name/dojo-poupup-menu-hover' rel='bookmark' title='Permanent Link: Monkey Patching Dojo&#8217;s Menu&nbsp;Dijit'>Monkey Patching Dojo&#8217;s Menu&nbsp;Dijit</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/dojo-tabs">&lt;p&gt;One of Dojo&amp;#8217;s major advantages over other JavaScript toolkits is its Dijit library.  &lt;a
href="http://www.sitepen.com/blog/2010/07/12/dive-into-dijit/"&gt;Dijit is a UI framework&lt;/a&gt; comprised of JavaScript widget classes, CSS files, and HTML templates.  One very useful layout class is the TabContainer.  TabContainer allows you to quickly create a tabbed content layout with minimal effort.  Keep reading to see what you can create in just 10 minutes!&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-tabs.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/dojo-tabs.jpg" alt="Dojo Dijit Tabs" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-tabs.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The Basic Dijit&amp;nbsp;HTML&lt;/h2&gt;&lt;pre class="html"&gt;
&amp;lt;style type="text/css"&amp;gt;
	/* bring in the claro theme */
	@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css";

	/* bring in the widget-specific CSS classes */
	@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/layout/ContentPane.css";
	@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/layout/TabContainer.css";
&amp;lt;/style&amp;gt;
&amp;lt;body class="claro"&amp;gt;
&lt;/pre&gt;&lt;p&gt;The first piece of HTML requires grabbing the required CSS theme files and adding the theme name as a class to the BODY tag.  All widgets on the page will use the claro theme unless otherwise specified.  Once we have those details out of the way, we can code the HTML structure of TabContainer and ContentPanes:&lt;/p&gt;&lt;pre class="html"&gt;

&amp;lt;!-- will set the eventual dimensions for the tab container --&amp;gt;
&amp;lt;div style="width:600px;height:300px"&amp;gt;
	
	&amp;lt;!-- will host all tabs and their content panes --&amp;gt;
	&amp;lt;div dojoType="dijit.layout.TabContainer" id="tabContainer" style="width:100%;height:100%;"&amp;gt;
		
		&amp;lt;!-- content panes: title is tab name, make this tab selected --&amp;gt;
		&amp;lt;div dojoType="dijit.layout.ContentPane" title="Rod Stewart" selected="true"&amp;gt;			
			&amp;lt;p&amp;gt;Roderick David "Rod" Stewart, CBE (born 10 January 1945)[1] is a British singer-songwriter...&amp;lt;/p&amp;gt;			
		&amp;lt;/div&amp;gt;
		
		&amp;lt;!-- content panes: title is tab name, no special features here --&amp;gt;
		&amp;lt;div dojoType="dijit.layout.ContentPane" title="Oasis"&amp;gt;
			&amp;lt;p&amp;gt;Oasis were an English rock band that formed in Manchester in 1991...&amp;lt;/p&amp;gt;
		&amp;lt;/div&amp;gt;
		
		&amp;lt;!-- content panes: title is tab name, make this tab closable --&amp;gt;
		&amp;lt;div dojoType="dijit.layout.ContentPane" title="ColdPlay" closable="true" onClose="alert('Closing Tab!');"&amp;gt;
			&amp;lt;p&amp;gt;Coldplay are an English alternative rock band...&amp;lt;/p&amp;gt;
		&amp;lt;/div&amp;gt;
		
		&amp;lt;!-- content panes: title is tab name, load content remotely, preload --&amp;gt;
		&amp;lt;div dojoType="dijit.layout.ContentPane" title="SomeBand" href="some-page.html" preload="true"&amp;gt;
			&amp;lt;p&amp;gt;Lorem ipsum...&amp;lt;/p&amp;gt;
		&amp;lt;/div&amp;gt;
		
	&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;	
&lt;/pre&gt;&lt;p&gt;You&amp;#8217;ll notice the &lt;code&gt;dojoType&lt;/code&gt; attribute on a few of the DIVs;  that means we&amp;#8217;re creating our widgets declaratively, not programatically.  We&amp;#8217;ll address what that means in a moment.   For now, realize that the &lt;code&gt;dojoType&lt;/code&gt; attribute&amp;#8217;s content is the name of the JavaScript class that it will become.  The &lt;code&gt;title&lt;/code&gt; attribute text will become the actual tab&amp;#8217;s content.  Adding a &lt;code&gt;selected&lt;/code&gt; attribute will make the given tab start as the selected tab, and adding a &lt;code&gt;closable&lt;/code&gt; attribute will make the tab closable.&lt;/p&gt;&lt;p&gt;So how does Dojo know to turn these boring DIVs into rich widgets? &lt;code&gt;parseonLoad&lt;/code&gt;!&lt;/p&gt;&lt;h2&gt;Including Dojo with parseOnLoad; Requiring Dijit Widget&amp;nbsp;Classes&lt;/h2&gt;&lt;pre class="html"&gt;
&amp;lt;script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript" djConfig="parseOnLoad:true"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;p&gt;We start by pulling Dojo into the page with a normal &lt;code&gt;SCRIPT&lt;/code&gt; tag (AOL CDN, Google CDN, local build).  Note that I&amp;#8217;ve added a djConfig attribute with &lt;code&gt;parseOnLoad:true;&lt;/code&gt; &amp;#8212; this will instruct Dojo to scour the page looking for Dijit widgets once the required classes have loaded.  How do we require the proper classes?  By using &lt;a
href="http://davidwalsh.name/dojo-require"&gt;&lt;code&gt;dojo.require&lt;/code&gt;&lt;/a&gt;, of course:&lt;/p&gt;&lt;pre class="js"&gt;
&amp;lt;script type="text/javascript"&amp;gt;
	/* require necessary classes */
	dojo.require('dijit.layout.TabContainer');
	dojo.require('dijit.layout.ContentPane');
	dojo.require('dijit.form.Button');
	
	/* when all classes have loaded... */
	dojo.ready(function() {
		/* 
			don't need to do anything programmatically!
			parseOnLoad and dojoType does the magic!
		*/
	});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;p&gt;With the proper classes loaded, Dojo will now find all widgets and inject widgets into the page as necessary.&lt;/p&gt;&lt;h2&gt;That&amp;#8217;s&amp;nbsp;It?!&lt;/h2&gt;&lt;p&gt;Yep.  The demo I&amp;#8217;ve provided to me roughly 10 minutes to create.  I spent more time looking for information on Wikipedia than I did putting together the tab layout.  I really love the declarative method of widget creation &amp;#8212; it&amp;#8217;s less JavaScript write and quicker to code.  What you shouldn&amp;#8217;t lose sight of is that you can also control the Dijit widget programmatically after it&amp;#8217;s been created.&lt;/p&gt;&lt;h2&gt;Dynamically Adding&amp;nbsp;Tabs&lt;/h2&gt;&lt;p&gt;To this point our layout is static and was built declaratively.  Let&amp;#8217;s add a &lt;code&gt;Button&lt;/code&gt; widget to the page that, when clicked, adds a new tab to the container:&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;button dojoType="dijit.form.Button" id="addButton"&amp;gt;Add New Tab&amp;lt;/button&amp;gt;
&amp;lt;script type="text/javascript"&amp;gt;
dijit.connect('addButton')
dijit.byId('tabContainer').addChild(new dijit.layout.ContentPane({ title:'New Tab!', content:'This is new content!', closable:true }));
&amp;lt;/script&amp;gt;
&lt;/pre&gt;&lt;p&gt;I&amp;#8217;ve used &lt;code&gt;onClick&lt;/code&gt; to add a click event listener to the button which programmatically adds a new ContentPane to the TabContainer.  We start by grabbing the widget with &lt;code&gt;dijit.byId&lt;/code&gt; and proceed to add the new ContentPane instance as a child.  The object properties passed as parameters should be self explanatory but there&amp;#8217;s one more bonus &amp;#8212; if you prefer to loaded content from another file via AJAX, all you need to do is provide the file path via the &lt;code&gt;href&lt;/code&gt; property.  You may also preload the content of that pane by setting the &lt;code&gt;preload&lt;/code&gt; property to &lt;code&gt;true&lt;/code&gt;:&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;button dojoType="dijit.form.Button" id="addButton" onClick="dijit.byId('tabContainer').addChild(new dijit.layout.ContentPane({ title:'New Tab!', content:'This is new content!', closable:true }));"&amp;gt;Add New Tab&amp;lt;/button&amp;gt;
&lt;/pre&gt;&lt;p&gt;Doesn&amp;#8217;t it seem almost too easy?&lt;/p&gt;&lt;h2&gt;TabContainer&amp;nbsp;Accommodations&lt;/h2&gt; &lt;a
href="http://davidwalsh.name/dw-content/dojo-tabs.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/dojo-tabs2.jpg" alt="Dojo Tabs Container" class="image" /&gt;&lt;/a&gt;&lt;p&gt;Another awesome part of using Dojo TabContainer is that the class monitors the number of tabs and, if the tabs stretch further than the container&amp;#8217;s width, will add scrolling left and right controls as well as a table of contents dropdown to easily navigate through the tabs.  Additionally, the tab system is completely accessible and keyboard shortcuts work wonderfully!&lt;/p&gt;&lt;p&gt;You may also designate where tabs should display: &lt;code&gt;right-h&lt;/code&gt;, &lt;code&gt;left-h&lt;/code&gt;, &lt;code&gt;bottom&lt;/code&gt;, and &lt;code&gt;top&lt;/code&gt;, which is the default.  These options are placed within the &lt;code&gt;tabPosition&lt;/code&gt; setting:&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;div dojoType="dijit.layout.TabContainer" id="tabContainer" style="width:100%;height:100%;" tabPosition="right-h"&amp;gt;
&lt;/pre&gt;&lt;p&gt;Your layout changes simply by providing one parameter!&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-tabs.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Possibly the best part about Dijit is just how easy it is to take a static set of HTML markup and make it dynamic, especially when using the dynamic method of widget creation.  I encourage you to give Dijit a go by starting with this tutorial.  I also encourage you to take a look at Dojo&amp;#8217;s infamous Theme Tester page.  Theme Tester will show you just about every widget within Dijit in one spot.&lt;/p&gt;&lt;p&gt;Have any questions about jumping into Dijit?  Ask away!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/dojo-tabs"&gt;Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-accordion' rel='bookmark' title='Permanent Link: Create a Simple Dojo&amp;nbsp;Accordion'&gt;Create a Simple Dojo&amp;nbsp;Accordion&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-context-menu' rel='bookmark' title='Permanent Link: Create a Context Menu with Dojo and&amp;nbsp;Dijit'&gt;Create a Context Menu with Dojo and&amp;nbsp;Dijit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-flickr' rel='bookmark' title='Permanent Link: Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit'&gt;Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting'&gt;Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-poupup-menu-hover' rel='bookmark' title='Permanent Link: Monkey Patching Dojo&amp;#8217;s Menu&amp;nbsp;Dijit'&gt;Monkey Patching Dojo&amp;#8217;s Menu&amp;nbsp;Dijit&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/HGLkOyyr_68" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/dojo-tabs#comments" thr:count="8" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/dojo-tabs/feed/atom" thr:count="8" /> <thr:total>8</thr:total> <feedburner:origLink>http://davidwalsh.name/dojo-tabs</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Image Reflections with&#160;CSS]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/YsBvh9lB_4g/css-reflection" /> <id>http://davidwalsh.name/?p=5047</id> <updated>2010-08-22T17:10:54Z</updated> <published>2010-08-19T23:51:20Z</published> <category scheme="http://davidwalsh.name" term="Browsers" /><category scheme="http://davidwalsh.name" term="CSS" /> <summary type="html"><![CDATA[<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/css-reflection">Image Reflections with&nbsp;CSS</a></p>No related posts.]]></summary> <content type="html" xml:base="http://davidwalsh.name/css-reflection">&lt;a
href="http://davidwalsh.name/dw-content/safari-reflection.php" class="demo"&lt;img src="http://davidwalsh.name/dw-content/css-reflection.jpg" alt="CSS Image Reflection" class="image" /&gt;&lt;/a&gt;&lt;p&gt;Image reflection is a great way to subtly spice up an image.  The first method of creating these reflections was baking them right into the images themselves.  Within the past few years, we&amp;#8217;ve introduced &lt;a
href="http://davidwalsh.name/javascrip-reflection"&gt;JavaScript strategies&lt;/a&gt; and CANVAS alternatives to achieve image reflections without having to modify original images.  The minds behind WebKit have their own idea behind image reflection:  pure CSS.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/safari-reflection.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The Webkit&amp;nbsp;CSS&lt;/h2&gt;&lt;p&gt;The -webkit-box-reflect property accepts a value in the following format:&lt;/p&gt;&lt;pre class="css"&gt;
-webkit-box-reflect: 
	&amp;lt;direction&amp;gt; /* above|below|left|right */ 	
	&amp;lt;offset&amp;gt;    /* pixel value start offset from image */
	&amp;lt;mask-box-image&amp;gt; /* http://webkit.org/blog/181/css-masks/ */
&lt;/pre&gt;&lt;p&gt;A sample usage of -webkit-box-reflect looks like:&lt;/p&gt;&lt;pre class="css"&gt;
.reflectBelow	{ 
	-webkit-box-reflect: below 0
    -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(0.5, transparent), to(white)); 
}
&lt;/pre&gt;&lt;p&gt;An involved CSS value but well worth the work.  The gradient is linear from left top to left bottom from transparent to white, showing half (0.5 the image).&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/safari-reflection.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;WebKit first implemented CSS reflections in 2008 and, to my knowledge, no other browsers have implemented a similar API. I find that frustrating but image reflection isn&amp;#8217;t a priority so I can&amp;#8217;t complain too much.  I am glad, however, that this is just one of several CSS enhancements given to us by the developers of WebKit!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/css-reflection"&gt;Image Reflections with&amp;nbsp;CSS&lt;/a&gt;&lt;/p&gt;&lt;p&gt;No related posts.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/YsBvh9lB_4g" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/css-reflection#comments" thr:count="4" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/css-reflection/feed/atom" thr:count="4" /> <thr:total>4</thr:total> <feedburner:origLink>http://davidwalsh.name/css-reflection</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&#160;III]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/Ln2HmMP3oJc/dojo-mootools-jquery" /> <id>http://davidwalsh.name/?p=5045</id> <updated>2010-08-19T17:43:54Z</updated> <published>2010-08-19T02:32:54Z</published> <category scheme="http://davidwalsh.name" term="Dojo" /><category scheme="http://davidwalsh.name" term="MooTools" /><category scheme="http://davidwalsh.name" term="jQuery" /> <summary type="html"><![CDATA[My love of the JavaScript frameworks knows no bounds. Unfortunately too many developers stick to one framework without taking the time to learn the others. The more frameworks you know, the better a programmer you will be and the more money you&#8217;ll make. Let me show you how to accomplish a few more tasks using [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/dojo-mootools-jquery">Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&nbsp;III</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/mootools-jquery-dojo' rel='bookmark' title='Permanent Link: Accomplishing Common Tasks Using MooTools, jQuery, and&nbsp;Dojo'>Accomplishing Common Tasks Using MooTools, jQuery, and&nbsp;Dojo</a></li><li><a
href='http://davidwalsh.name/jquery-mootools-dojo' rel='bookmark' title='Permanent Link: Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&nbsp;II'>Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&nbsp;II</a></li><li><a
href='http://davidwalsh.name/dojo-mootools' rel='bookmark' title='Permanent Link: Quick Dojo Setup Snippet for MooTools&nbsp;Developers'>Quick Dojo Setup Snippet for MooTools&nbsp;Developers</a></li><li><a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&nbsp;Listener'>dojo.connect: A Powerful Object and Event&nbsp;Listener</a></li><li><a
href='http://davidwalsh.name/github-css' rel='bookmark' title='Permanent Link: Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&nbsp;JavaScript'>Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&nbsp;JavaScript</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/dojo-mootools-jquery">&lt;p&gt;My love of the JavaScript frameworks knows no bounds.  Unfortunately too many developers stick to one framework without taking the time to learn the others.  The more frameworks you know, the better a programmer you will be and the more money you&amp;#8217;ll make.  Let me show you how to accomplish a few more tasks using three JavaScript frameworks:  MooTools, jQuery, and Dojo.&lt;/p&gt;&lt;h2&gt;Calculate Element Dimensions and&amp;nbsp;Position&lt;/h2&gt;&lt;p&gt;Knowing not only the height and width of a dimension but it&amp;#8217;s top/left position from an offset parent or document body can be extremely helpful when trying to animate or move a DOM element.&lt;/p&gt;&lt;h3&gt;MooTools&lt;/h3&gt;&lt;pre class="js"&gt;
var dimensions = document.id('myElement').getDimensions();
/* returns:
{ 
	height: 4684,
	width: 1408,
	x: 1408,
	y: 4684
}
*/
&lt;/pre&gt;&lt;h3&gt;jQuery&lt;/h3&gt;&lt;pre class="js"&gt;
var myElement = jQuery('#myElement');
var position = myElement.position();
var dimensions = {
	height: myElement.height(),
	width: myElement.width(),
	top: position.top,
	left: position.left
};
&lt;/pre&gt;&lt;h3&gt;Dojo&lt;/h3&gt;&lt;pre class="js"&gt;
var dimension = dojo.coords('myElement');
/* returns:
{
	h: 4684,
	l: 0,
	t: 0,
	w: 1408,
	x: 0,
	y: 0
}
*/
&lt;/pre&gt;&lt;h2&gt;Extend an&amp;nbsp;Object&lt;/h2&gt;&lt;p&gt;Extending an object means taking on object and merging a second objects properties into it.  This is very helpful in merging default options with instance options.&lt;/p&gt;&lt;h3&gt;MooTools&lt;/h3&gt;&lt;pre class="js"&gt;
$extend(firstObject,{ anotherProperty:'anothervalue' });
//second arg is added to the first object
&lt;/pre&gt;&lt;h3&gt;jQuery&lt;/h3&gt;&lt;pre class="js"&gt;
jQuery.extend(firstObject,{ anotherProperty:'anothervalue' })
&lt;/pre&gt;&lt;h3&gt;Dojo&lt;/h3&gt;&lt;pre class="js"&gt;
dojo.mixin(firstObject,{ anotherProperty:'anothervalue' });
&lt;/pre&gt;&lt;h2&gt;Stop an&amp;nbsp;Event&lt;/h2&gt;&lt;p&gt;Stopping an event is helpful when looking to execute functionality (usually an XHR request) when a link is clicked.&lt;/p&gt;&lt;h3&gt;MooTools&lt;/h3&gt;&lt;pre class="js"&gt;
$('myElement').addEvent('click',function(e) {
	e.stop();
});
&lt;/pre&gt;&lt;h3&gt;jQuery&lt;/h3&gt;&lt;pre class="js"&gt;
$('#myElement').click(function(e){ 
	event.stopPropagation();
	e.preventDefault();
	// (no internal method that does both)
});
&lt;/pre&gt;&lt;h3&gt;Dojo&lt;/h3&gt;&lt;pre class="js"&gt;
dojo.connect(dojo.byId('myElement'),'onclick',function(e) {
	dojo.stopEvent(e);
});
&lt;/pre&gt;&lt;h2&gt;Load Content into an&amp;nbsp;Element&lt;/h2&gt;&lt;p&gt;Sure we can create an XHR request manually to load content into an element but why do that when your favorite lirbary can do that work for you?&lt;/p&gt;&lt;h3&gt;MooTools&lt;/h3&gt;&lt;pre class="js"&gt;
document.id('myElement').load('ajax/script.html');
&lt;/pre&gt;&lt;h3&gt;jQuery&lt;/h3&gt;&lt;pre class="js"&gt;
jQuery('#myElement').load('ajax/script.html');
&lt;/pre&gt;&lt;h3&gt;Dojo&lt;/h3&gt;&lt;pre class="js"&gt;
//as found on Pete Higgins' website:
//http://higginsforpresident.net/2009/12/140-characters-of-awesome/
dojo.extend(dojo.NodeList, {
	grab: function(url){
		dojo.xhr('GET', { url:url })
			.addCallback(this, function(response){
				this.addContent(response, 'only');
			});
		return this;
	}
});
dojo.query('#myElement').grab('header.html');
&lt;/pre&gt;&lt;h2&gt;Get and Set HTML&amp;nbsp;Content&lt;/h2&gt;&lt;p&gt;Getting and setting HTML is a frequent JavaScript operation&amp;#8230;yet each library handles it a bit differently.&lt;/p&gt;&lt;h3&gt;MooTools&lt;/h3&gt;&lt;pre class="js"&gt;
//get
var html = document.id('myElement').get('html');
//set
document.id('myElement').set('html','&lt;b&gt;Hello!&lt;/b&gt;');
&lt;/pre&gt;&lt;h3&gt;jQuery&lt;/h3&gt;&lt;pre class="js"&gt;
//get
var html = jQuery('#myElement').html();
//set
jQuery('#myElement').html('&lt;b&gt;Hello!&lt;/b&gt;');
&lt;/pre&gt;&lt;h3&gt;Dojo&lt;/h3&gt;&lt;pre class="js"&gt;
//get 
var html = dojo.byId('myElement').innerHTML
//set
dojo.byId('myElement').innerHTML = '&lt;b&gt;Hello!&lt;/b&gt;';
&lt;/pre&gt;&lt;h2&gt;Use Element&amp;nbsp;Storage&lt;/h2&gt;&lt;p&gt;Element data storage is important because it allows you to store settings within the element itself &amp;#8212; perfect for defeating scope and context issues.&lt;/p&gt;&lt;h3&gt;MooTools&lt;/h3&gt;&lt;pre class="js"&gt;
//set
document.id('myElement').store('key','value');
//get
var value = document.id('myElement').retrieve('key');
&lt;/pre&gt;&lt;h3&gt;jQuery&lt;/h3&gt;&lt;pre class="js"&gt;
//set
jQuery('#myElement').data('key','value');
//get
var value = jQuery('#myElement').data('key');
&lt;/pre&gt;&lt;h3&gt;Dojo&lt;/h3&gt;&lt;pre class="js"&gt;
//set
dojo.attr('myElement','data-key','value');
//get
dojo.attr('myElement','data-key');
&lt;/pre&gt;&lt;p&gt;There you are &amp;#8212; more proof that the toolkits are one in the same, all except the syntax.  Do yourself a favor and learn more than one JavaScript framework &amp;#8212; you&amp;#8217;ll be better for it!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/dojo-mootools-jquery"&gt;Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&amp;nbsp;III&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/mootools-jquery-dojo' rel='bookmark' title='Permanent Link: Accomplishing Common Tasks Using MooTools, jQuery, and&amp;nbsp;Dojo'&gt;Accomplishing Common Tasks Using MooTools, jQuery, and&amp;nbsp;Dojo&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/jquery-mootools-dojo' rel='bookmark' title='Permanent Link: Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&amp;nbsp;II'&gt;Accomplishing Common Tasks Using MooTools, jQuery, and Dojo&amp;nbsp;II&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-mootools' rel='bookmark' title='Permanent Link: Quick Dojo Setup Snippet for MooTools&amp;nbsp;Developers'&gt;Quick Dojo Setup Snippet for MooTools&amp;nbsp;Developers&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&amp;nbsp;Listener'&gt;dojo.connect: A Powerful Object and Event&amp;nbsp;Listener&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/github-css' rel='bookmark' title='Permanent Link: Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&amp;nbsp;JavaScript'&gt;Create GitHub-Style Buttons with CSS and jQuery, MooTools, or Dojo&amp;nbsp;JavaScript&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/Ln2HmMP3oJc" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/dojo-mootools-jquery#comments" thr:count="13" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/dojo-mootools-jquery/feed/atom" thr:count="13" /> <thr:total>13</thr:total> <feedburner:origLink>http://davidwalsh.name/dojo-mootools-jquery</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Create a Context Menu with Dojo and&#160;Dijit]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/wvys9Fa8-58/dojo-context-menu" /> <id>http://davidwalsh.name/?p=5044</id> <updated>2010-08-18T15:05:57Z</updated> <published>2010-08-18T14:30:28Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Dojo" /><category scheme="http://davidwalsh.name" term="Markup" /> <summary type="html"><![CDATA[Context menus, used in the right type of web application, can be invaluable.  They provide shortcut methods to different functionality within the application and, with just a right click, they are readily available.  Dojo&#8217;s Dijit frameworks provides an easy way to create stylish, flexible context menus in just minutes. View Demo The Dojo&#160;JavaScript /* require [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/dojo-context-menu">Create a Context Menu with Dojo and&nbsp;Dijit</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/dojo-accordion' rel='bookmark' title='Permanent Link: Create a Simple Dojo&nbsp;Accordion'>Create a Simple Dojo&nbsp;Accordion</a></li><li><a
href='http://davidwalsh.name/dojo-flickr' rel='bookmark' title='Permanent Link: Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit'>Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit</a></li><li><a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&nbsp;Charting'>Dive Into Dojo Series:  Dijit and&nbsp;Charting</a></li><li><a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&nbsp;Listener'>dojo.connect: A Powerful Object and Event&nbsp;Listener</a></li><li><a
href='http://davidwalsh.name/dojo-tabs' rel='bookmark' title='Permanent Link: Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content'>Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/dojo-context-menu">&lt;a
href="http://davidwalsh.name/dw-content/dojo-context-menu.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/dojo-context-menu.jpg" alt="Dojo Context Menu" class="image" /&gt;&lt;/a&gt;&lt;p&gt;Context menus, used in the right type of web application, can be invaluable.  They provide shortcut methods to different functionality within the application and, with just a right click, they are readily available.  Dojo&amp;#8217;s Dijit frameworks provides an easy way to create stylish, flexible context menus in just minutes.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-context-menu.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The Dojo&amp;nbsp;JavaScript&lt;/h2&gt;&lt;pre class="js"&gt;
/* require necessary classes */
dojo.require('dijit.Menu');
dojo.require('dijit.MenuSeparator');
dojo.require('dijit.MenuItem');
dojo.require('dijit.PopupMenuItem');
&lt;/pre&gt;&lt;p&gt;The above requires the necessary widget classes that will be used in the context menu.&lt;/p&gt;&lt;h2&gt;The Context Menu&amp;nbsp;HTML&lt;/h2&gt;&lt;pre class="html"&gt;
&amp;lt;-- menu container --&amp;gt;
&amp;lt;div dojoType="dijit.Menu" id="submenu1" contextMenuForWindow="true" style="display:none;"&amp;gt;

	&amp;lt;-- enabled menu item --&amp;gt;
	&amp;lt;div dojoType="dijit.MenuItem" id="enabledItem" onClick="Clicked enabled item!"&amp;gt;Enabled Item&amp;lt;/div&amp;gt;
	
	&amp;lt;-- disabled menu item --&amp;gt;
	&amp;lt;div dojoType="dijit.MenuItem" disabled="true"&amp;gt;Disabled Item&amp;lt;/div&amp;gt;
	
	&amp;lt;-- separator --&amp;gt;
	&amp;lt;div dojoType="dijit.MenuSeparator"&amp;gt;&amp;lt;/div&amp;gt;
	
	&amp;lt;-- menu items with icons --&amp;gt;
	&amp;lt;div dojoType="dijit.MenuItem" iconClass="dijitIconCut"
		onClick="alert('Cutting!')"&amp;gt;Cut&amp;lt;/div&amp;gt;
	&amp;lt;div dojoType="dijit.MenuItem" iconClass="dijitIconCopy"
		onClick="alert('not actually copying anything, just a test!')"&amp;gt;Copy&amp;lt;/div&amp;gt;
	
	&amp;lt;div dojoType="dijit.MenuSeparator"&amp;gt;&amp;lt;/div&amp;gt;
	
	&amp;lt;-- nested popup menus with items --&amp;gt;
	&amp;lt;div dojoType="dijit.PopupMenuItem"&amp;gt;
		&amp;lt;span&amp;gt;Enabled Submenu&amp;lt;/span&amp;gt;
		&amp;lt;div dojoType="dijit.Menu" id="submenu2"&amp;gt;
			&amp;lt;div dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')"&amp;gt;Submenu Item One&amp;lt;/div&amp;gt;
			&amp;lt;div dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')"&amp;gt;Submenu Item Two&amp;lt;/div&amp;gt;
			&amp;lt;div dojoType="dijit.PopupMenuItem"&amp;gt;
				&amp;lt;span&amp;gt;Deeper Submenu&amp;lt;/span&amp;gt;
				&amp;lt;div dojoType="dijit.Menu" id="submenu4"&amp;gt;
					&amp;lt;div dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 1!')"&amp;gt;Sub-sub-menu Item One&amp;lt;/div&amp;gt;
					&amp;lt;div dojoType="dijit.MenuItem" onClick="alert('Sub-submenu 2!')"&amp;gt;Sub-sub-menu Item Two&amp;lt;/div&amp;gt;
				&amp;lt;/div&amp;gt;
			&amp;lt;/div&amp;gt;
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
	
	&amp;lt;-- popup menu with disabled item --&amp;gt;
	&amp;lt;div dojoType="dijit.PopupMenuItem" disabled="true"&amp;gt;
		&amp;lt;span&amp;gt;Disabled Submenu&amp;lt;/span&amp;gt;
		&amp;lt;div dojoType="dijit.Menu" id="submenu3" style="display: none;"&amp;gt;
			&amp;lt;div dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')"&amp;gt;Submenu Item One&amp;lt;/div&amp;gt;
			&amp;lt;div dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')"&amp;gt;Submenu Item Two&amp;lt;/div&amp;gt;
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;p&gt;The menu is based on a system of nested DIV elements.  The top element is a dijit.Menu widget with child dijit.MenuItem widgets.  You may also add a dijit.MenuSeparator widget or a dijit.PopupMenuItem widget with child dijit.MenuItem widgets to create a popup menu.  You may disable menu items with &amp;#8220;disabled=&amp;#8217;true&amp;#8217;&amp;#8221; declaratively or by using JavaScript:&lt;/p&gt;&lt;pre class="js"&gt;
dijit.byId('enabledItem').attr('disabled','true');
&lt;/pre&gt;&lt;p&gt;So simple!  Context menus may also be created programmatically, but the declarative method of widget creation speeds up development.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-context-menu.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;This is just another way that Dojo&amp;#8217;s Dijit framework allows you to quickly create a functional UI widget in minutes!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/dojo-context-menu"&gt;Create a Context Menu with Dojo and&amp;nbsp;Dijit&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-accordion' rel='bookmark' title='Permanent Link: Create a Simple Dojo&amp;nbsp;Accordion'&gt;Create a Simple Dojo&amp;nbsp;Accordion&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-flickr' rel='bookmark' title='Permanent Link: Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit'&gt;Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting'&gt;Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-connect' rel='bookmark' title='Permanent Link: dojo.connect: A Powerful Object and Event&amp;nbsp;Listener'&gt;dojo.connect: A Powerful Object and Event&amp;nbsp;Listener&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-tabs' rel='bookmark' title='Permanent Link: Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content'&gt;Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/wvys9Fa8-58" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/dojo-context-menu#comments" thr:count="1" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/dojo-context-menu/feed/atom" thr:count="1" /> <thr:total>1</thr:total> <feedburner:origLink>http://davidwalsh.name/dojo-context-menu</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Create a Simple Dojo&#160;Accordion]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/w8n8Rq2-wxs/dojo-accordion" /> <id>http://davidwalsh.name/?p=5041</id> <updated>2010-08-20T16:38:06Z</updated> <published>2010-08-17T14:27:56Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Dojo" /><category scheme="http://davidwalsh.name" term="Markup" /> <summary type="html"><![CDATA[Let&#8217;s be honest:  even though we all giggle about how cheap of a thrill JavaScript accordions have become on the web, they remain an effective, useful widget.  Lots of content, small amount of space.  Dojo&#8217;s Dijit library provides an incredibly simply method by which you can add accordions to your website.  Let&#8217;s take a look [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/dojo-accordion">Create a Simple Dojo&nbsp;Accordion</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/dojo-tabs' rel='bookmark' title='Permanent Link: Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content'>Dijit&#8217;s TabContainer Layout:  Easy Tabbed&nbsp;Content</a></li><li><a
href='http://davidwalsh.name/dojo-flickr' rel='bookmark' title='Permanent Link: Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit'>Create a Dynamic Flickr Image Search with the Dojo&nbsp;Toolkit</a></li><li><a
href='http://davidwalsh.name/dojo-context-menu' rel='bookmark' title='Permanent Link: Create a Context Menu with Dojo and&nbsp;Dijit'>Create a Context Menu with Dojo and&nbsp;Dijit</a></li><li><a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&nbsp;Charting'>Dive Into Dojo Series:  Dijit and&nbsp;Charting</a></li><li><a
href='http://davidwalsh.name/dojo-require' rel='bookmark' title='Permanent Link: The Beauty of&nbsp;dojo.require()'>The Beauty of&nbsp;dojo.require()</a></li></ol>]]></summary> <content type="html" xml:base="http://davidwalsh.name/dojo-accordion">&lt;p&gt;Let&amp;#8217;s be honest:  even though we all giggle about how cheap of a thrill JavaScript accordions have become on the web, they remain an effective, useful widget.  Lots of content, small amount of space.  Dojo&amp;#8217;s Dijit library provides an incredibly simply method by which you can add accordions to your website.  Let&amp;#8217;s take a look at how we can implement a Dojo accordion!&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-accordion.php"&gt;&lt;img
src="http://davidwalsh.name/dw-content/dojo-accordion.jpg" alt="Dojo Accordion" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-accordion.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The Basic Dijit&amp;nbsp;HTML&lt;/h2&gt;&lt;pre class="html"&gt;&amp;lt;style type="text/css"&amp;gt;
	/* bring in the claro theme */
	@import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css";
&amp;lt;/style&amp;gt;
&amp;lt;body class="claro"&amp;gt;&lt;/pre&gt;&lt;p&gt;The first piece of HTML requires grabbing the required CSS theme files and adding the theme name as a class to the BODY tag.  All widgets on the page will use the claro theme unless otherwise specified.  Once we have those details out of the way, we can code the HTML structure of Accordion:&lt;/p&gt;&lt;pre class="html"&gt;
&amp;lt;-- The container must be a dijit.layout.AccordionContainer --&amp;gt;
&amp;lt;div id="accordion" dojoType="dijit.layout.AccordionContainer"&amp;gt;

	&amp;lt;-- Accordion item --&amp;gt;
	&amp;lt;div class="element" title="The Beatles" dojoType="dijit.layout.ContentPane"&amp;gt;
		&amp;lt;img src="http://davidwalsh.name/dw-content/accordion/let-it-be.jpg" class="image" /&amp;gt;
		&amp;lt;p&amp;gt;The Beatles were a pop and rock group from Liverpool, England...&amp;lt;/p&amp;gt;
	&amp;lt;/div&amp;gt;
	
	&amp;lt;-- Accordion item --&amp;gt;
	&amp;lt;div class="element" title="Rod Stewart" selected="true" dojoType="dijit.layout.ContentPane"&amp;gt;
		&amp;lt;img src="http://davidwalsh.name/dw-content/accordion/every-picture.jpg" class="image" /&amp;gt;
		&amp;lt;p&amp;gt;Roderick "Rod" David Stewart, CBE (born January 10, 1945), is a singer and songwriter...&amp;lt;/p&amp;gt;
	&amp;lt;/div&amp;gt;
	
	&amp;lt;-- Accordion item --&amp;gt;
	&amp;lt;div class="element" title="Oasis" dojoType="dijit.layout.ContentPane"&amp;gt;
		&amp;lt;img src="http://davidwalsh.name/dw-content/accordion/oasis.jpg" class="image" /&amp;gt;
		&amp;lt;p&amp;gt;Oasis are an English rock band that formed in Manchester in 1991...&amp;lt;/p&amp;gt;
	&amp;lt;/div&amp;gt;
	
&amp;lt;/div&amp;gt;
&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;title&lt;/code&gt; attribute text will become the Accordion control&amp;#8217;s heading.  Adding a &lt;code&gt;selected&lt;/code&gt; attribute will make the given accordion pane start as the selected pane.&lt;/p&gt;&lt;h2&gt;Including Dojo with parseOnLoad; Requiring Dijit Widget&amp;nbsp;Classes&lt;/h2&gt;&lt;pre class="html"&gt;&amp;lt;script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript" djConfig="parseOnLoad:true"&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;p&gt;We start by pulling Dojo into the page with a normal &lt;code&gt;SCRIPT&lt;/code&gt; tag (AOL CDN, Google CDN, local build).  Note that I&amp;#8217;ve added a djConfig attribute with &lt;code&gt;parseOnLoad:true;&lt;/code&gt; &amp;#8212; this will instruct Dojo to scour the page looking for Dijit widgets once the required classes have loaded.  How do we require the proper classes?  By using &lt;a
href="http://davidwalsh.name/dojo-require"&gt;&lt;code&gt;dojo.require&lt;/code&gt;&lt;/a&gt;, of course:&lt;/p&gt;&lt;pre class="js"&gt;&amp;lt;script type="text/javascript"&amp;gt;
	/* require necessary classes */
	dojo.require('dijit.layout.AccordionContainer');
	dojo.require('dijit.layout.ContentPane');
	/* when all classes have loaded... */
	dojo.ready(function() {
		/*
			don't need to do anything programmatically!
			parseOnLoad and dojoType does the magic!
		*/
	});
&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;p&gt;With the proper classes loaded, Dojo will now find all widgets and inject widgets into the page as necessary.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/dojo-accordion.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;All JavaScript toolkits have provided an easy way to create accordions and Dojo/Dijit is no exception!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Follow Me!&lt;/strong&gt; &lt;a
href="http://twitter.com/davidwalshblog"&gt;Twitter&lt;/a&gt; | &lt;a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869"&gt;Facebook&lt;/a&gt; | &lt;a
href="http://www.linkedin.com/in/davidjameswalsh"&gt;LinkedIn&lt;/a&gt; | &lt;a
href="http://mootools.net/forge/profile/davidwalsh"&gt;MooTools Forge.&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;Full David Walsh Blog Post: &lt;a
href="http://davidwalsh.name/dojo-accordion"&gt;Create a Simple Dojo&amp;nbsp;Accordion&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Related posts:&lt;ol&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-tabs' rel='bookmark' title='Permanent Link: Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content'&gt;Dijit&amp;#8217;s TabContainer Layout:  Easy Tabbed&amp;nbsp;Content&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-flickr' rel='bookmark' title='Permanent Link: Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit'&gt;Create a Dynamic Flickr Image Search with the Dojo&amp;nbsp;Toolkit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-context-menu' rel='bookmark' title='Permanent Link: Create a Context Menu with Dojo and&amp;nbsp;Dijit'&gt;Create a Context Menu with Dojo and&amp;nbsp;Dijit&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-dijit-charting' rel='bookmark' title='Permanent Link: Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting'&gt;Dive Into Dojo Series:  Dijit and&amp;nbsp;Charting&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a
href='http://davidwalsh.name/dojo-require' rel='bookmark' title='Permanent Link: The Beauty of&amp;nbsp;dojo.require()'&gt;The Beauty of&amp;nbsp;dojo.require()&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/w8n8Rq2-wxs" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/dojo-accordion#comments" thr:count="5" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/dojo-accordion/feed/atom" thr:count="5" /> <thr:total>5</thr:total> <feedburner:origLink>http://davidwalsh.name/dojo-accordion</feedburner:origLink></entry> </feed><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 126/386 queries in 6.912 seconds using disk

Served from: davidwalsh.name @ 2010-09-02 22:32:20 -->
