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

<channel>
	<title>Div Tags</title>
	<atom:link href="http://www.div-tags.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.div-tags.com</link>
	<description>Exploring the world of web development</description>
	<lastBuildDate>Wed, 13 Jun 2012 17:49:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Use :Hover Pseudo-Class To Add Visual Cues To Table Rows</title>
		<link>http://www.div-tags.com/css3/hover-pseudo-class-add-visual-cues-table-rows/</link>
		<comments>http://www.div-tags.com/css3/hover-pseudo-class-add-visual-cues-table-rows/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 17:12:51 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=355</guid>
		<description><![CDATA[The :hover pseudo-class can be used for all sorts of CSS effects. Traditionally it has been used to change the color of anchor links when you hover the cursor over the anchor. Now that browsers are better about their support &#8230; <a href="http://www.div-tags.com/css3/hover-pseudo-class-add-visual-cues-table-rows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><div id="attachment_360" class="wp-caption alignright" style="width: 310px"><a href="http://www.div-tags.com/wp-content/uploads/2011/03/pink_highlighter.jpg"><img src="http://www.div-tags.com/wp-content/uploads/2011/03/pink_highlighter.jpg" alt="Use the :hover pseudo-class for quick highlighting effects" title="Use the :hover pseudo-class for quick highlighting effects" width="300" height="158" class="size-full wp-image-360" /></a><p class="wp-caption-text">If you want to apply a pink highlighting effect to your table rows, you can do that easily!</p></div>The :hover pseudo-class can be used for all sorts of CSS effects. Traditionally it has been used to change the color of anchor links when you hover the cursor over the anchor. Now that browsers are better about their support for the :hover pseudo-class, we can <strong>add CSS hover effects to many DOM elements without using JavaScript!</strong></p>
<p>I want to show you a very simple example and, yes, probably some of you are going to laugh when you see it because, like it said, it&#8217;s simple and a bunch of people are already using it so we&#8217;re not breaking new ground here but I&#8217;m going to include it anyway since it might not be an obvious addition to some. Data-driven applications tend to have large tables containing many columns and rows of data. Adding a simple highlighting effect when the cursor hovers over a row can make sifting through that data easier on the user. Think of the case where we have an employee table with 10 columns and a table width that stretches the full width of a user&#8217;s monitor. The &#8220;Employee&#8217;s Name&#8221; column is on the far left of the screen and a link to update the employee&#8217;s information on the right-most column. Highlighting the row the user&#8217;s cursor is over will easily identify to the user the edit button they are about to click is truly the one associated with the employee they want to edit.</p>
<p><strong>Using the :hover pseudo-class is easy</strong>. Take a look at the CSS example below:</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.hiliteTbl</span> td <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* give the table cells a light grey background color by default */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.hiliteTbl</span> tr<span style="color: #3333ff;">:hover </span>td <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* turn hovered rows background color a slightly darker grey */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>And that&#8217;s really all there is to it. Now we just apply the &#8220;hiliteTbl&#8221; class to any table we want rows the users hovers over to change color and it will automatically be applied. Take a look at <a href="/demos/css/tr-hover-effect/">the demo page I created showing the :hover effect on table rows</a> in action and then try it out for yourself. If you have a web site with lots of data grids, using this effect will make your users&#8217; lives easier. They&#8217;ll be able to digest the information you feed them faster because you&#8217;re giving them helpful guidance. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/css3/hover-pseudo-class-add-visual-cues-table-rows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things To Remember When Writing Requirements Documents</title>
		<link>http://www.div-tags.com/design/remember-writing-requirements-documents/</link>
		<comments>http://www.div-tags.com/design/remember-writing-requirements-documents/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 19:38:45 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[theology]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=352</guid>
		<description><![CDATA[Creating a project plan involves many steps and at the center of this process is coming up with a complete requirements document. It&#8217;s important to capture as much information as possible so that you have a solid game plan heading &#8230; <a href="http://www.div-tags.com/design/remember-writing-requirements-documents/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Creating a project plan involves many steps and at the center of this process is coming up with a complete requirements document. It&#8217;s important to capture as much information as possible so that you have a solid game plan heading into the development phase. If you&#8217;re missing items from your requirements document, this can lead to wasted time and confusion later. Rebecca Heidgerd from <a href="http://www.makegreatwebsites.com/" target="_blank">www.makegreatwebsites.com</a> asked me to write another guest post talking about <a href="http://www.makegreatwebsites.com/post/3575498104" target="_blank">things developers can forget to include in their documentation</a> and what to avoid. Naturally I said yes so check out the article I&#8217;ve linked to and have a read for yourself!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/design/remember-writing-requirements-documents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Standard Ready For 2014!</title>
		<link>http://www.div-tags.com/html5/html5-standard-ready-2014/</link>
		<comments>http://www.div-tags.com/html5/html5-standard-ready-2014/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 22:09:41 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Recent News]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[w3c]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=350</guid>
		<description><![CDATA[Whoopee! W3C has announced the HTML5 specification will be complete by 2014. What a relief that is. So for all of you developers out there that are waiting for the final spec to be complete before incorporating the changes&#8230;don&#8217;t! That would &#8230; <a href="http://www.div-tags.com/html5/html5-standard-ready-2014/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Whoopee! W3C has announced <a title="learn more about w3c's announcement about the HTML5 standard" href="http://www.webmonkey.com/2011/02/html5-will-be-done-in-2014-what-comes-next/" target="_blank">the HTML5 specification will be complete by 2014</a>. What a relief that is. So for all of you developers out there that are waiting for the final spec to be complete before incorporating the changes&#8230;don&#8217;t! <a title="waiting for all your users to support HTML5 features is crazy" href="/html5/a-word-about-browsers/" target="_self">That would be a silly idea regardless on this announcement</a>!</p>
<p>As you&#8217;ve already seen on this site, there are <a title="learn how to use html5 storage instead of cookies" href="/html5/html5-storage-instead-of-cookies/" target="_self">plenty of examples</a> of <a title="learn how to add geolocation to your HTML5 application" href="/html5/create-location-based-solutions-with-geolocation-api/" target="_self">HTML5 support out in the wild</a> right now so there&#8217;s no use waiting to innovate later! Your users&#8217; browsers should already support a whole host of features so get using them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/html5/html5-standard-ready-2014/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decrease Page Load Time With Content Delivery Networks</title>
		<link>http://www.div-tags.com/coding/decrease-page-load-time-cdn/</link>
		<comments>http://www.div-tags.com/coding/decrease-page-load-time-cdn/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 15:56:53 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=333</guid>
		<description><![CDATA[A slow web site is not a fun experience for your clients. The last thing people want to see is the Windows hour glass or the Mac &#8220;color wheel of death&#8221; (note: I have no idea if people call it &#8230; <a href="http://www.div-tags.com/coding/decrease-page-load-time-cdn/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>A slow web site is not a fun experience for your clients. The last thing people want to see is the Windows hour glass or the Mac &#8220;color wheel of death&#8221; (note: I have no idea if people call it that but I&#8217;m starting the trend!). There are <strong>many factors contributing to a web site&#8217;s performance</strong>:</p>
<ul>
<li><strong>Web Hosting</strong> &#8211; The connection to your web server(s), the speed of those servers and how quickly they can process web requests are all big factors in your web site&#8217;s performance. Obviously the more you pay, the more powerful a server you&#8217;re going to get. You are in control of this just based on how much you&#8217;re willing to spend.</li>
<li><strong>Server-side Code</strong> &#8211; If you&#8217;re using server-side code (and which web site isn&#8217;t these days) and your code is poorly developed, that&#8217;s going to effect how quickly server requests are processed.</li>
<li><strong>Client-side Resources</strong> &#8211; Image, CSS and JavaScript files your clients need to download also contribute to web site performance. We talked earlier about <a title="learn how to minify your javascript and css files" href="/javascript/minify-your-javascript-css/" target="_self">minifying your JavaScript and CSS files</a> so that&#8217;s one option. Now I&#8217;ll give you another tip to speed up page loads by using Content Delivery Networks or CDNs.</li>
</ul>
<h2>Content Delivery Networks Explained</h2>
<p>What is a Content Delivery Network you ask? Very simply, it&#8217;s a system of web sites that <strong>host common JavaScript APIs cached on high performance web-servers</strong>. Such APIs would be jQuery, jQuery UI, Prototype, etc. just to name a few. Both <a title="visit Google's libraries API to download common javascript libraries" href="http://code.google.com/apis/libraries/devguide.html" target="_blank">Google</a> and <a title="visit Microsoft's content delivery network " href="http://www.asp.net/ajaxlibrary/cdn.ashx" target="_blank">Microsoft</a> offer up CDNs and you can reference these libraries in your own code.</p>
<p>Why would we want to reference APIs on a CDN instead of hosting it on your own server? There&#8217;s a few of reasons you would want to do this. First off, <strong>it&#8217;s one less file your web server needs to host</strong> and therefore, one less HTTP request the server needs to process. Even if the request only takes a couple hundred milliseconds to process, it&#8217;s still adds up. Depending on the traffic on your web site, milliseconds can add up to a huge performance loss over time.</p>
<p>Secondly, because <strong>CDNs are utilizing high-performance servers</strong> with a big pipeline for requests, chances are their servers are going to process a request and send the response much quicker than most hosts you&#8217;re using. As I said earlier, your hosting plan is definitely going to way in on this argument. If you spend a lot you&#8217;re going to get faster hosting so this might be a moot point but for those of us without bottomless wallets, I&#8217;ll show you some examples in a little bit of how my shared hosting plan just doesn&#8217;t offer the same performance as Google&#8217;s or Microsoft&#8217;s CDN.</p>
<p>Finally, the more web sites start using CDNs to reference libraries the more it&#8217;s going to improve page load times across the board. Say we take an example where <em>web site A</em> and <em>B</em> are both referencing the latest jQuery library on Google&#8217;s CDN.</p>
<ol>
<li>A user visits <em>web site A.</em></li>
<li>The browser downloads the jQuery library referenced on Google&#8217;s CDN.</li>
<li>The user then visits <em>web site B</em>, which references the same URL on the CDN.</li>
<li>The browser sees it already has that resource downloaded locally and can skip downloading the JS file again.</li>
</ol>
<p>Now in this particular example, <em>web site B</em> would really be the one to see the page load time decrease but honestly other users will visit <em>B</em> before <em>A</em>, thus <em>A</em> would get the load decrease and it would all even out in the long run. The point is the more web sites start reference CDNs the better since it will boost load times across the board.</p>
<h2>CDN performance in action</h2>
<p>To show you the <strong>benefits of using a CDN on your site</strong> I took a scenario where I had a web page referencing the same jQuery library on my web server and both Google&#8217;s and Microsoft&#8217;s CDN. The HTML for the page looks like this:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.div-tags.com/jquery.min-1.4.3.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.3.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Done!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></div>
<p>I cleared all the cached files from my browser (Chrome) before loading this page so that each file would have to be downloaded. I then used the Chrome developer tools to look at the download times for each resource:</p>
<div id="attachment_336" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/first-download.png"><img class="size-full wp-image-336 " title="First download of CDN JavaScript files" src="http://www.div-tags.com/wp-content/uploads/2011/02/first-download.png" alt="First download of CDN JavaScript files" width="648" height="337" /></a><p class="wp-caption-text">As we can see, Google really has the advantage on the CDN download.</p></div>
<div id="attachment_340" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/first-download-div-tags-stats.png"><img class="size-full wp-image-340 " title="First download of CDN files from div-tags.com" src="http://www.div-tags.com/wp-content/uploads/2011/02/first-download-div-tags-stats.png" alt="First download of CDN files from div-tags.com" width="648" height="337" /></a><p class="wp-caption-text">Wow, my hosting server is slow to send data!!</p></div>
<div id="attachment_341" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/first-download-google-cdn-stats.png"><img class="size-full wp-image-341 " title="First download of Google's CDN JavaScript files" src="http://www.div-tags.com/wp-content/uploads/2011/02/first-download-google-cdn-stats.png" alt="First download of Google's CDN JavaScript files" width="648" height="337" /></a><p class="wp-caption-text">Google has incredible response time for their hosting servers</p></div>
<div id="attachment_342" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/first-download-aspnet-cdn-stats.png"><img class="size-full wp-image-342 " title="First download from Microsoft's asp.net CDN" src="http://www.div-tags.com/wp-content/uploads/2011/02/first-download-aspnet-cdn-stats.png" alt="First download from Microsoft's asp.net CDN" width="648" height="337" /></a><p class="wp-caption-text">Microsoft has great response time as well though their send time is a little behind Google&#39;s</p></div>
<p>As we can see from these response times, Google is far and away the fastest at serving up files from their CDN. This really shouldn&#8217;t come as a surprise since their web sites generally are some of the fastest around. Microsoft comes in at second place and while their response time was quick, the downloading of the content kept their time from being close to Google&#8217;s. I&#8217;m not certain what would be causing that though. Perhaps Google is compressing their content? Finally we have my poor hosting plan coming up in last place. Though we&#8217;re still under 1 second, keep in mind this is just for a single JavaScript file. What if we start adding additional functionality that spans 3 or 4 additional JS files and they take the same time to download? Instead of a page loading in under a second, we&#8217;re up to 4-5 seconds and that will dramatically increase the frustation levels users would have with my site. Maybe it&#8217;s time I look for a better hosting plan!</p>
<h2>Load times of cached resources</h2>
<p>For the first request, my browser had to download each of the JS files since I didn&#8217;t have them stored locally. Now lets refresh the page and <strong>see how long it takes to load each cached file</strong>. One thing to keep in mind with this scenario is that the web servers are still going to be contacted to see if the JS files have been updated since our last request.</p>
<div id="attachment_343" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/cached-download.png"><img class="size-full wp-image-343 " title="Downloaded files are already in the browser cache" src="http://www.div-tags.com/wp-content/uploads/2011/02/cached-download.png" alt="Downloaded files are already in the browser cache" width="648" height="337" /></a><p class="wp-caption-text">Cached versions take much less time to load</p></div>
<div id="attachment_344" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/cached-download-div-tags-stats1.png"><img class="size-full wp-image-344 " title="Cached version of the CDN file on div.tags.com" src="http://www.div-tags.com/wp-content/uploads/2011/02/cached-download-div-tags-stats1.png" alt="Cached version of the CDN file on div.tags.com" width="648" height="337" /></a><p class="wp-caption-text">Ugh, connecting and waiting still take a good amount of time compared to the other two</p></div>
<div id="attachment_345" class="wp-caption aligncenter" style="width: 658px"><a href="http://www.div-tags.com/wp-content/uploads/2011/02/cached-download-google-cdn-stats.png"><img class="size-full wp-image-345 " title="Cached version of Google's CDN files" src="http://www.div-tags.com/wp-content/uploads/2011/02/cached-download-google-cdn-stats.png" alt="Cached version of Google's CDN files" width="648" height="337" /></a><p class="wp-caption-text">Google still takes the edge for cached CDN files</p></div>
<p>In the race of cached versions, Google still takes the edge but Microsoft&#8217;s CDN is a very close second. After the first download we can see that the gap between the two providers are reduced big time where the difference between the two is negligible. My server is taking up the rear so it looks like the obvious choice for me is to use Google&#8217;s CDN for the jQuery API.</p>
<p>If you were to use Microsoft&#8217;s CDN instead, since it is built into MVC development now, that&#8217;s a completely safe option too. Bottom line is <a title="A good article illustrating the importance of page load times" href="http://www.scottporad.com/2010/04/26/data-illustrating-the-benefits-of-improved-page-load-times/" target="_blank">the better your page load time, the better the user experience</a> you can offer. Take advantage of CDNs for common libraries so that you can offload some of the hosting work to the big guys&#8217; servers and you can have your server concentrating on processing your important application requests.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/coding/decrease-page-load-time-cdn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importance Of Source Control</title>
		<link>http://www.div-tags.com/coding/importance-source-control/</link>
		<comments>http://www.div-tags.com/coding/importance-source-control/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 01:42:17 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[tfs]]></category>
		<category><![CDATA[theology]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=329</guid>
		<description><![CDATA[If you&#8217;ve ever used Google Docs before, you may have noticed that every few seconds a version of your document is saved. Is that overkill? Probably. Is it necessary? Absolutely! You&#8217;ll never know when you might want to go back &#8230; <a href="http://www.div-tags.com/coding/importance-source-control/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve ever used Google Docs before, you may have noticed that every few seconds a version of your document is saved. Is that overkill? Probably. Is it necessary? Absolutely! You&#8217;ll never know when you might want to go back to a version of your document that&#8217;s a minute old, an hour old, 6 months old. The same idea holds true with your code!</p>
<p>I wanted to take a moment to remind all you developers out there, even those of you who are burning the midnight oil after work on hobby projects, <strong>how important it is to use some sort of source version control for your code</strong>. I would hope this would be a no brainer for those of you working in a team environment. If you&#8217;re not already using version control (i.e. &#8211; Team Foundation Server, SourceSafe, Subversion, etc) in that scenario then you better set something up immediately because you&#8217;re in a world of hurt if you lose code from a computer crash or an accidental file copy. Not only is it bad for you but it could be detrimental to the team and the company.</p>
<p>Ok, now, since source control is so important for teams, the question then becomes how is it important for solo projects? My response to that is easy. The reasons an individual would want to use source control are the same reasons a team would want to use it:</p>
<ul>
<li>Code repository/backup</li>
<li>Version history</li>
<li>Rollback code changes</li>
<li>Feature branching/merging</li>
</ul>
<p>The list could go on and even though you might think, &#8220;But Derek, I&#8217;m just working by myself. Why would I even bother going through the hassle of using source control?&#8221; know that the first time you lose a vital piece of code because of a hard drive failure or want to find out what the code looked like for a method a year ago that&#8217;s since been changed, you&#8217;re going to be swearing up a storm.</p>
<h2>Free Hosted Source Control</h2>
<p>We&#8217;ve got the reasons for source control out of the way lets figure out how we can add it to your current project. Think it&#8217;s a difficult process? Absolutely not! Not only is it easy to start using versioning, the best part is there are <strong>so many source control hosts which don&#8217;t cost you a penny!</strong> Below I&#8217;ve listed just a couple of the many web sites offering free source control hosting. As an added bonus project management abilities too so you track requirement documents, work items and bugs! You can host your project online so that you can work on code from multiple locations and/or with multiple people from all over the world.</p>
<ul>
<li><a title="find project hosting solutions at codeplex" href="http://www.codeplex.com" target="_blank">Codeplex (http://www.codeplex.com)</a> &#8211; this site offers source control with Team Foundation Server, Mercurial or Subversion. Great for Visual Studio developers and now that <a title="download teamprise, the tfs plug-in for eclipse" href="http://www.teamprise.com/" target="_blank">TFS has a plug-in for Eclipse</a>, many languages not native to Visual Studio such as PHP, Java, Python, etc can be integrated with ease.</li>
<li><a title="visit project hosting at google code" href="http://code.google.com/hosting/" target="_blank">Project Hosting on Google Code (http://code.google.com/hosting/)</a> &#8211; project hosting has been offered by Google for quite some time and is very popular in the open source community. They support Subversion and Mercurial version control.</li>
<li><a title="find git source control hosting at gitorious" href="http://gitorious.org/" target="_blank">Gitorious (http://gitorious.org/)</a> &#8211; Git is a relatively newish source control system that the developers claim is extremely fast. I haven&#8217;t had a chance to use it but I&#8217;ve read good things about it.</li>
</ul>
<p>So those are just three hosting sites of the many existing solutions out there. Bottom line, if you&#8217;re not already using source control, sign up for one of those sites and give it a try. You can also download a version control application such as Git or Subversion and run it off your local computer. Either way you choose, you&#8217;ll find out pretty quickly all the benefits you&#8217;ve been missing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/coding/importance-source-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep Your Footer At The Bottom Of The Page</title>
		<link>http://www.div-tags.com/css3/keep-footer-at-bottom-page/</link>
		<comments>http://www.div-tags.com/css3/keep-footer-at-bottom-page/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 16:55:06 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=326</guid>
		<description><![CDATA[If you&#8217;re like most developers out there, you&#8217;ve probably created a web site with a footer in your master template. This footer is supposed to stay at the bottom of the window independent of how much content you may have &#8230; <a href="http://www.div-tags.com/css3/keep-footer-at-bottom-page/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re like most developers out there, you&#8217;ve probably created a web site with a footer in your master template. This footer is supposed to stay at the bottom of the window independent of how much content you may have in the body of your page. You get finish coding your site and start filling pages with content. For those pages that fill the screen, your footer flows to the bottom of the window without a problem. Then you come to those one or two pages where there&#8217;s just not enough content to fill an entire window. What happens to the footer? It&#8217;s now floating in the middle of the window! Argh!!!</p>
<p>Thankfully, Joss over at <a title="visit cssreset.com" href="http://www.cssreset.com" target="_blank">cssreset.com</a> has posted an <a title="tutorial on how to keep the footer at the bottom of the window" href="http://www.cssreset.com/2010/css-tutorials/how-to-keep-footer-at-bottom-of-page-with-css/" target="_blank">easy tutorial on using CSS to keep the your web site footer at the bottom of the browser window</a> regardless of the page&#8217;s content. Give it a try and let me know if it works for you!</p>
<p>Note: I have this categorized under CSS3 but really that&#8217;s only because I don&#8217;t really have a CSS category. You don&#8217;t need CSS3 to use this feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/css3/keep-footer-at-bottom-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML5 Storage Instead Of Cookies</title>
		<link>http://www.div-tags.com/html5/html5-storage-instead-of-cookies/</link>
		<comments>http://www.div-tags.com/html5/html5-storage-instead-of-cookies/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 15:58:10 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[storage]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=299</guid>
		<description><![CDATA[HTTP Cookies have been around for a long time. They&#8217;re a good way to store information on the client&#8217;s computer, either temporarily or long-term. Cookies are also domain dependent, so we can assume the values we&#8217;re writing to the cookie &#8230; <a href="http://www.div-tags.com/html5/html5-storage-instead-of-cookies/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>HTTP Cookies have been around for a long time. They&#8217;re a good way to store information on the client&#8217;s computer, either temporarily or long-term. Cookies are also domain dependent, so we can assume the values we&#8217;re writing to the cookie will not be overwritten by another site. Up until now it really has been the only universal way of storing data client-side but it doesn&#8217;t come without its flaws. </p>
<p><div id="attachment_322" class="wp-caption alignright" style="width: 310px"><a href="http://www.div-tags.com/wp-content/uploads/2011/01/floppy-disks.jpg"><img src="http://www.div-tags.com/wp-content/uploads/2011/01/floppy-disks-300x225.jpg" alt="Cookies are as ancient as floppy disks" title="Cookies are as ancient as floppy disks" width="300" height="225" class="size-medium wp-image-322" /></a><p class="wp-caption-text">Cookies are like the floppy disks of the web. Old, out-dated and don't offer much storage.</p></div>The biggest problem with cookies is that they&#8217;re transmitted to the web server with every request made by the browser. In most applications, the server does not need every single value stored in the cookie on every request which means our requests are larger than they should be. Secondly, cookies officially have a maximum file size of 4kb. One could argue that cookies don&#8217;t really need to hold a lot of information so why do we need much storage space? While this is true, as web applications become more sophisticated it does limit the potential our applications can achieve.</p>
<p>The designers of the HTML5 specification have included a few different storage mechanisms that blow cookies out of the water (or should I say milk? heh, heh)! They have introduced two storage objects call sessionStorage &#038; localStorage as well as client-side SQL database capabilities. This article will talk about the first two storage features and we&#8217;ll leave the database talk for another time.</p>
<h2>The Storage Interface</h2>
<p>In order to understand sessionStorage and localStorage <strong>we need to know more about the <em>Storage</em> interface they both implement</strong>. Below is the interface written in no particular language, just a pseudo-language most developers would be able to understand by reading it over.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">interface Storage <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; readonly unsigned long length<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; string key<span style="color: #009900;">&#40;</span>unsigned long index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; string getItem<span style="color: #009900;">&#40;</span>string key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> setItem<span style="color: #009900;">&#40;</span>string key<span style="color: #339933;">,</span> object value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> removeItem<span style="color: #009900;">&#40;</span>string key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> clear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>It&#8217;s easiest to think of this interface as a &#8220;Dictionary&#8221; or &#8220;Hashtable&#8221; object that contains key/value pairs and has basic get/set/delete operations on its collection. There is also a <strong>length</strong> property which tells us how many items are currently in the collection as well as a <strong>clear</strong> function which will remove all items from our collection. </p>
<p>There is one important thing to note about this interface. Even though the <strong>setItem</strong> allows us to pass in objects, it&#8217;ll actually store the value as a string. Essentially it uses the value&#8217;s &#8220;toString&#8221; function and stores that. This means that if we&#8217;re saving a number, the value returned by the <strong>getItem</strong> function will need to be sent to the <strong>parseInt</strong> or <strong>parseFloat</strong> function afterwards.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> luckyNumber <span style="color: #339933;">=</span> <span style="color: #CC0000;">7</span><span style="color: #339933;">;</span><br />
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #339933;">,</span> luckyNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
luckyNumber <span style="color: #339933;">=</span> localStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;number&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data type is a '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>luckyNumber<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;' and has a value of: &quot;</span> <span style="color: #339933;">+</span> luckyNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;data type is a 'string' and has a value of: 7</span><br />
<br />
luckyNumber <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>luckyNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data type is a '&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>luckyNumber<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;' and has a value of: &quot;</span> <span style="color: #339933;">+</span> luckyNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;data type is a 'number' and has a value of: 7</span></div></div>
<p><em>Note: Mark Pilgrim over at <a href="http://diveintohtml5.com/detect.html#storage" target="_blank">diveintohtml5.com has a great piece of JavaScript to detect if localStorage is available</a> on a client&#8217;s browser. Make sure you&#8217;re detecting if your clients have this capability or, if you&#8217;re like this site, you can just <a href="/html5/a-word-about-browsers/">tell everyone to get with the times!</a></em></p>
<h2>Storing Arrays And Objects</h2>
<p>Using basic data types such as strings and numbers with the storage objects is straight forward. It gets a little more tricky when we want to put <strong>an array or an object into storage</strong>. Since using the &#8220;toString&#8221; function on each of these data types doesn&#8217;t return a good representation of that data type, we&#8217;re going to get some unexpected results. Take a look at the example below.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> foo <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bar&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// remember, setItem uses Array.toString() and Object.toString() to </span><br />
<span style="color: #006600; font-style: italic;">// &nbsp;get the value to store</span><br />
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;array&quot;</span><span style="color: #339933;">,</span> arr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">,</span> obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>localStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;array&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;1, 2, 3&quot;</span><br />
<br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>localStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;[object Object]&quot;</span></div></div>
<p>As you can see, storing our arrays and objects in their toString representations isn&#8217;t very useful to us. We can&#8217;t really use the string the getItem function returns and recreate our objects directly from it. Instead, we&#8217;re going to want to convert our objects into JSON and store that instead. Using the browser-native JSON object, we can accomplish this feat.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> foo <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bar&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;array&quot;</span><span style="color: #339933;">,</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #339933;">,</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>localStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;array&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;[ 1, 2, 3 ]&quot;</span><br />
<br />
obj <span style="color: #339933;">=</span> localStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;{ &quot;foo&quot; : &quot;bar&quot; }&quot;</span><br />
<br />
obj <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">foo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// output - &quot;bar&quot;</span></div></div>
<p><strong>Using the JSON.stringify function</strong>, we can easily convert our variables into their JSON string representation and later convert them back to their original data type form with <strong>JSON.parse</strong>. This is a very handy feature that should work on most of the latest browsers. One thing to keep in mind when using the <em>stringify</em> and <em>parse</em> functions is that it doesn&#8217;t not support objects which contain functions. It&#8217;ll throw exceptions if you try to stringify objects with functions. Be sure to use this only on data objects that contain properties only. If you need to use this on more complex objects, you&#8217;ll need to create your own custom serialization solution.</p>
<h2>Difference between sessionStorage and localStorage</h2>
<p>Now that we&#8217;ve reviewed the basics of the HTML5 storage mechanisms, lets talk about why there are two different storage objects available to develop with. <strong>Each top-level window context has its own instance of sessionStorage per domain.</strong> What this means is that you can have two separate tabs or windows open running the same code on the same site and each window will have its own separate storage container. </p>
<p>Think about the case where you are pricing out a vacation on Orbitz.com (or the travel site of your choice) and you have two tabs open. With tab A you pick Las Vegas for your destination and in tab B you pick Disney World. In tab A, you click a link to confirm your flight selection, move to tab B and click a link to confirm your hotel preference, go back to tab A and refresh your Vegas price but suddenly the site think&#8217;s you&#8217;ve selected a hotel in Orlando for your Vegas trip! Well that&#8217;s not right. Even though both tabs are using the same web server session, to the user it should be two complete different sessions. Using sessionStorage, we can keep data that is unique to each tab separate while still maintaining a single session on the web server! One thing to keep in mind though with this type of storage is that once the user closes the top-level window/tab that sessionStorage instance gets destroyed so don&#8217;t expect the same session data to always be there.</p>
<p><strong>For persistant data storage we turn to the localStorage object.</strong> Unlike sessionStorage, localStorage is shared across all sessions the client has on a single domain. It&#8217;s very similar to domain cookies with a couple of major differences:</p>
<ul>
<li><strong>Data doesn&#8217;t expire</strong> &#8211; Unlike cookies, we cannot set an expiration date on a particular value. The browser may offer a way to delete all locally stored data for a given domain but there is no way to have data automatically expire. Keep in mind though, in scripts we could also use the <strong>Storage.clear</strong> function at any time to delete everything from our storage container.</li>
<li><strong>Greater storage capacity</strong> &#8211; Officially, localStorage allows for a whopping 5MB of space, and that&#8217;s just the recommended size. Some browsers may offer more if browser developers choose to do so.</li>
</ul>
<h2>Did you hear that? Something changed!</h2>
<p>The final part of the new storage containers in HTML5 is the ability to listen for when data changes. <strong>The &#8220;storage&#8221; event fires off any time data has changed</strong> in the sessionStorage or localStorage containers. We can then register an event handler that&#8217;ll get called on every change. There&#8217;s no way to prevent the data from changing though as it&#8217;s more of an FYI to the rest of your application.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> onStorageChange<span style="color: #009900;">&#40;</span>storageEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>storageEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; storageEvent <span style="color: #339933;">=</span> window.<span style="color: #660066;">event</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// IE hack</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Key '&quot;</span> <span style="color: #339933;">+</span> storageEvent.<span style="color: #660066;">key</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;' changed from '&quot;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; storageEvent.<span style="color: #660066;">oldValue</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;' to '&quot;</span> <span style="color: #339933;">+</span> storageEvent.<span style="color: #660066;">newValue</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;storage&quot;</span><span style="color: #339933;">,</span> onStorageChange<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// need to handle IE8 and below</span><br />
&nbsp; &nbsp; window.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;onstorage&quot;</span><span style="color: #339933;">,</span> onStorageChange<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>The storage event has attributes that tell us what the old and new values are, what key the change happened to as well as what storage container contains the changed key/value pair. For more information about this event, you can <a href="http://dev.w3.org/html5/webstorage/#the-storage-event" target="_blank">read more at W3C&#8217;s storage specification</a>. </p>
<p>I hope this article has helped give you a better idea of the new storage features in HTML5. The best part is that this is just the beginning! In a later article, we&#8217;ll talk about the client-side SQL capabilities browsers are starting to implement, which will really open up web applications&#8217; ability to store data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/html5/html5-storage-instead-of-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event Handlers Using jQuery</title>
		<link>http://www.div-tags.com/jquery/event-handlers-using-jquery/</link>
		<comments>http://www.div-tags.com/jquery/event-handlers-using-jquery/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 23:06:19 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=284</guid>
		<description><![CDATA[Sorry it&#8217;s been so long since my last article. I just had to go off and get married and then go down to Argentina for the honeymoon! I know I haven&#8217;t really injected anything about my personal life onto this &#8230; <a href="http://www.div-tags.com/jquery/event-handlers-using-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Sorry it&#8217;s been so long since my last article. I just had to go off and get married and then go down to Argentina for the honeymoon! I know I haven&#8217;t really injected anything about my personal life onto this site (and I certainly don&#8217;t plan on doing that much in the future as I want to keep the conversation centered on technologies) but if you&#8217;re interesting in hearing about <a href="http://www.morethanmerlot.com/2011/01/honeymoon/" target="_blank">our trip</a> and all the <a href="http://www.morethanmerlot.com/2011/01/clos-de-chacras/" target="_blank">fantastic wines</a> we had, check out my wife&#8217;s site <a href="http://www.morethanmerlot.com" target="_blank">www.morethanmerlot.com</a>. And now on with the show&#8230;</p>
<p>In previous articles, I have preached the benefits of using jQuery. Its powerful API gives us the ability to <a href="/jquery/create-horizontal-drop-menu-jquery/">create drop down menus</a> and <a href="/jquery/ajax-post-to-web-page-with-jquery/">make asynchronous server requests</a>, just to name a few, without needing to write many lines of code. Today I&#8217;m going to talk about how easy it is to hook up event handlers with DOM elements using jQuery.</p>
<h2>Event handlers the ordinary JavaScript way</h2>
<p>Normally when we want to listen for an event on an HTML element, say the &#8220;click&#8221; event on an input button, we would attach some JavaScript code to the &#8220;onclick&#8221; attribute of the button that either performs an action inline or calls a function.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;click me&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clickHandler();&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;result&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; function clickHandler() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var x = document.getElementById(&quot;result&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; x.innerHTML = &quot;You clicked the button!&quot;;<br />
&nbsp; &nbsp; }<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></div></div>
<p>This way of using event handlers is perfectly fine and should work in (most) all browsers. But what if we wanted to register more than one event handler? Say we have a handler that keeps an incremental counter of button clicks and a different handler that changes the color of an element every time a button is clicked.</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;click me&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;callBothHandlers();&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; You've clicked on the button <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;count&quot;</span>&gt;</span>0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span> time(s).<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; This text changes color: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color:black;&quot;</span>&gt;</span>black<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; function callBothHandlers() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; incrementCount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; changeColor();<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; function incrementCount() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var x = document.getElementById(&quot;count&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; x.innerHTML = parseInt(x.innerHTML)++;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; function changeColor() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var x = document.getElementById(&quot;color&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; switch(x.innerHTML) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;black&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.style.color = &quot;red&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.innerHTML = &quot;red&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;red&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.style.color = &quot;blue&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.innerHTML = &quot;blue&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;blue&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.style.color = &quot;black&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.innerHTML = &quot;black&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></div></div>
<p>This isn&#8217;t really the most useful example but it does demonstrate what I was talking about. We created a helper function called &#8220;callBothHandlers&#8221; which calls both handlers. We could have also just called both handlers inline from the &#8220;onclick&#8221; attribute but I feel that&#8217;s a little sloppy. In general, I always like to have my events call a single function and from there do what I need to do. </p>
<h2>Event handlers the jQuery way</h2>
<p>In our example above we have two event handlers being called by a helper function. What happens when we need to be a little more dynamic? Over time one event handler might not be needed any more or a third handler might need to be added. Our example can&#8217;t really handle that well because we&#8217;ve hard-coded our helper function to only work with the two handlers. It would be great if we could dynamically register N event handlers with an element. Using jQuery and its <a href="http://api.jquery.com/category/events/" target="_blank">events functions</a> we can do exactly that. Using the &#8220;click&#8221; function we can dynamically register event handlers for an element. Lets take the example above and modify it to use jQuery:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;click me&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clickme&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; You've clicked on the button <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;count&quot;</span>&gt;</span>0<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span> time(s).<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
&nbsp; &nbsp; This text changes color: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;color:black;&quot;</span>&gt;</span>black<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
&nbsp; &nbsp; function incrementCount() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var x = $(&quot;count&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; x.text(parseInt(x.text())++);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; function changeColor() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var x = $(&quot;#color&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; switch(x.text()) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;black&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.css(&quot;color&quot;, &quot;red&quot;).text(&quot;red&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;red&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.css(&quot;color&quot;, &quot;blue&quot;).text(&quot;blue&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &quot;blue&quot;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.css(&quot;color&quot;, &quot;black&quot;).text(&quot;black&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; // register the event handlers on page load<br />
&nbsp; &nbsp; $(function() { <br />
&nbsp; &nbsp; &nbsp; &nbsp; $(&quot;#clickme&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .click(incrementCount)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .click(changeColor); <br />
&nbsp; &nbsp; });<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></div></div>
<p>Notice a couple of thing we&#8217;ve changed. First off is at the bottom of the JavaScript, we&#8217;ve added an anonymous function to be called once the page finishes loading. This function will look for the button and then register our two event handlers. Thanks to the power of jQuery chaining we can register both handlers all on one line of code (though I&#8217;ve spread it out over a few lines to make it easier to read). Secondly, the &#8220;changeColor&#8221; function will now set the element&#8217;s color using the jQuery &#8220;css&#8221; function (which modifies the &#8220;style&#8221; collection by passing it an attribute and value to change it to) and it&#8217;s text value on one line instead of taking up two lines as in the first example. Now our example is a more elegant way of getting the results that we want.</p>
<h2>Removing event handlers when necessary</h2>
<p>Earlier I mentioned the possibility of no longer needing an event handler. You can easily remove a handler with the &#8220;unbind&#8221; function. You pass to the function the name of the event whose handlers list you want to modify and the function to remove. If we wanted to get rid of the incremental function in our example above we would just call the following code:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#clickme&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> incrementCount<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>It&#8217;s as simple as that! The increment handler is now gone but our &#8220;changeColor&#8221; handler is still in tacked! This really opens up a lot of highly dynamic scenarios without the overhead of needing to write the management logic yourself. In addition to the &#8220;click&#8221; event, jQuery has event functions for many of the DOM events available. Some useful ones are:</p>
<ul>
<li>onfocus</li>
<li>onblur</li>
<li>onmouseover</li>
<li>onmouseout</li>
<li>onscroll</li>
<li>onsubmit</li>
</ul>
<p>Each one of these can be called like our examples above. Just remove the &#8220;on&#8221; and you have the appropriate name to use in your code. I&#8217;ve created a <a href="/demos/jquery/fun-with-event-handlers/">jQuery events demo page</a> that shows you how you can use the focus, blur, and click events plus another demonstration of multiple event handlers registered to a single DOM element. Give it a try and let me know if any other fun examples you can come up with!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/jquery/event-handlers-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reducing JavaScript Clutter With MVC3</title>
		<link>http://www.div-tags.com/asp-net/reducing-javascript-clutter-mvc3/</link>
		<comments>http://www.div-tags.com/asp-net/reducing-javascript-clutter-mvc3/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 17:49:30 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=275</guid>
		<description><![CDATA[I&#8217;ve been doing a little research lately trying to find good development blogs to follow and since I do a lot of my work in ASP.NET, it&#8217;s important to find resources that are relevant to those needs. I stumbled upon &#8230; <a href="http://www.div-tags.com/asp-net/reducing-javascript-clutter-mvc3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been doing a little research lately trying to find good development blogs to follow and since I do a lot of my work in ASP.NET, it&#8217;s important to find resources that are relevant to those needs. I stumbled upon another developer&#8217;s blog called &#8220;Yo Briefcase!&#8221; where the author has a ton of articles talking about ASP.NET development using MVC. In particular, I found the tidbits talking about <a title="Learn about the benefits of making unobtrusive javascript in mvc3" href="http://yobriefcase.posterous.com/unobtrusive-javascript-in-mvc3" target="_blank">unobtrusive JavaScript in MVC3</a> very insightful.</p>
<p>First off, I&#8217;m shocked that MVC has progressed already to the beta stages of version 3. It seems like yesterday that they just introduced the idea of MVC into ASP.NET development. Secondly, it&#8217;s also great to hear that ASP.NET MVC uses jQuery as its standard JavaScript library instead of using the ASP.NET Ajax. This doesn&#8217;t mean that your old code is obsolete, the old framework still works. It&#8217;s just nice to know that Microsoft can adopt others work as standard, especially in today&#8217;s web development. Writing and reading code is easier when everyone is on the same page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/asp-net/reducing-javascript-clutter-mvc3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a Horizontal Drop Down Menu with jQuery</title>
		<link>http://www.div-tags.com/jquery/create-horizontal-drop-menu-jquery/</link>
		<comments>http://www.div-tags.com/jquery/create-horizontal-drop-menu-jquery/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 15:30:28 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.div-tags.com/?p=260</guid>
		<description><![CDATA[Navigation for web sites is an ever evolving topic. It seems like every year or two there is a new and popular way to direct users around your site. The latest craze in site nav is &#8220;mega menus&#8221;. These menus &#8230; <a href="http://www.div-tags.com/jquery/create-horizontal-drop-menu-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_262" class="wp-caption alignright" style="width: 310px"><a href="http://www.div-tags.com/wp-content/uploads/2010/12/food-network-mega-menu.png"><img class="size-medium wp-image-262" title="An example of a mega menu from Food Network's web site" src="http://www.div-tags.com/wp-content/uploads/2010/12/food-network-mega-menu-300x249.png" alt="A mega menu example from foodnetwork.com" width="300" height="249" /></a><p class="wp-caption-text">FoodNetwork.com uses mega menus to make it easier for people to find what they need.</p></div>
<p>Navigation for web sites is an ever evolving topic. It seems like every year or two there is a new and popular way to direct users around your site. The latest craze in site nav is &#8220;mega menus&#8221;. These menus are similar to file menus found in desktop applications that everyone is familiar with (ie: the toolbar at the top of an application with options File | Edit | View&#8230;). File menu-type navigation has been around the internet for a while but what makes mega menus unique is that they flatten out your site so that more options are available to the user. Instead of taking two or three clicks to get the information they need, your users can get it with a single click. While it might look pretty complicated, <strong>creating drop down horizontal menus are incredibly easy to make thanks to jQuery</strong>.</p>
<h2>Start with the HTML</h2>
<p><strong>Using a simple unordered list and some CSS,</strong> we can create the basic elements of a menu. Take a look at the following example:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span><br />
&nbsp; &nbsp; #menu, #menu ul { <br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; padding:0px;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; #menu &gt; li {<br />
&nbsp; &nbsp; &nbsp; &nbsp; list-style:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; margin:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; padding:0px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; display:inline;<br />
&nbsp; &nbsp; &nbsp; &nbsp; position:relative;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; .menu_items { <br />
&nbsp; &nbsp; &nbsp; &nbsp; position:absolute;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; display:none;<br />
&nbsp; &nbsp; } &nbsp; <br />
&nbsp; &nbsp; .menu_items &gt; li { <br />
&nbsp; &nbsp; &nbsp; &nbsp; list-style:none;<br />
&nbsp; &nbsp; &nbsp; &nbsp; white-space:nowrap;<br />
&nbsp; &nbsp; }<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu_items&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu_items&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>Item 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu_items&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>Menu Item 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">u</span>&gt;</span></div></div>
<p>The above HTML and CSS uses list items and the inline display CSS property to make our menus appear horizontally instead of the default vertical layout unordered lists normally take on. Each list item also contains a very basic child list with 3 items a piece. If you were making a mega menu, your child items could contain much more advanced HTML than what we&#8217;re using here but for our purposes, a simple list will do. </p>
<h2>Hooking up events with jQuery</h2>
<p>Here&#8217;s where the fun begins. What we want to have happen is every time a user rolls over one of our main menu items, it&#8217;ll display that item&#8217;s children elements. A couple of years ago this would have taken a fair amount of code to accomplish this task but <strong>thanks to jQuery we can make a drop-down list effect with a couple of lines of JavaScript</strong>.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#menu &gt; li&quot;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #660066;">mouseenter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.menu_items&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #660066;">mouseleave</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.menu_items&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>The &#8220;mouseenter&#8221; and &#8220;mouseleave&#8221; events are Internet Explorer specific events but the jQuery framework actually makes it possible to handle this event across all major browsers. We&#8217;re using these two events instead of the standard &#8220;mouseover&#8221; and &#8220;mouseout&#8221; events because the latter two events can have unexpected behavior leading to our event handlers firing more than we&#8217;d like them to. I&#8217;m not going to go into the full details of these issues so if you want to know more, <a href="http://api.jquery.com/mouseenter/" target="_blank">read more under the &#8220;examples&#8221; section of the jQuery documentation</a>. </p>
<p>Anyway, back to our example. The JavaScript above, once the document has loaded, it&#8217;ll fetch each of our menu items and register event handlers on both the mouseenter and mouseleave events. The &#8220;enter&#8221; handler looks for the child list and makes it visible while the &#8220;leave&#8221; handler looks for that same child list and hides it. <strong>It&#8217;s a very quick and elegant solution for making a drop down menu</strong>. Take a look at the <a href="/demos/jquery/horizontal-drop-down-menu/" title="Try our drop down menu demo">drop down menu demo page</a> to see this effect in action.</p>
<p>With only a few HTML elements, some CSS and a couple of lines of JavaScript, you can very easily add a drop down menu to your web site. You should find doing so will make your navigation both simpler and more robust since you&#8217;ll be giving your users more ways to get to the content they really need instead of having to know your site&#8217;s layout by heart.</p>
<p>(Image courtesy <a href="http://www.foodnetwork.com/" target="_blank">Food Network</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.div-tags.com/jquery/create-horizontal-drop-menu-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
