<?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>buyco.ca &#187; Features</title>
	<atom:link href="http://www.buyco.ca/category/features/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.buyco.ca</link>
	<description>because someone stole my name</description>
	<lastBuildDate>Fri, 24 Jun 2011 01:23:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Day 2: On the edge of Canada</title>
		<link>http://www.buyco.ca/2011/06/23/on-the-edge-of-canada/</link>
		<comments>http://www.buyco.ca/2011/06/23/on-the-edge-of-canada/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 01:18:51 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Five Hole For Food]]></category>
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=261</guid>
		<description><![CDATA[The last 24 hours have been rough&#8230; mainly because I&#8217;ve been stuck in bed sick! Actually that&#8217;s not true, I&#8217;ve had a chance to spend some time working on some new videos. Here&#8217;s the latest&#8230; I only wish I could have joined the fellas on their adventures yesterday: FHFF TV: At the edge of Canada [...]]]></description>
			<content:encoded><![CDATA[<p>The last 24 hours have been rough&#8230; mainly because I&#8217;ve been stuck in bed sick! Actually that&#8217;s not true, I&#8217;ve had a chance to spend some time working on some new videos. Here&#8217;s the latest&#8230; I only wish I could have joined the fellas on their adventures yesterday:</p>
<p><iframe src="http://player.vimeo.com/video/25531955?title=0&amp;byline=0&amp;portrait=0" width="400" height="300" frameborder="0"></iframe>
<p><a href="http://vimeo.com/25531955">FHFF TV: At the edge of Canada</a> from <a href="http://vimeo.com/user7560507">Jonathan Buyco</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Tomorrow is going to be a full day of travel, and lots more to prepare! Keep up with more of our updates here:</p>
<p><a href="http://www.fiveholeforfood.com/snapshots-st-johns-nfld/" target="_blank">http://www.fiveholeforfood.com/snapshots-st-johns-nfld/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2011/06/23/on-the-edge-of-canada/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Day 1 &#8211; Vancouver to St John&#8217;s</title>
		<link>http://www.buyco.ca/2011/06/22/day-1-vancouver-to-st-johns/</link>
		<comments>http://www.buyco.ca/2011/06/22/day-1-vancouver-to-st-johns/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 07:06:55 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Five Hole For Food]]></category>
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=254</guid>
		<description><![CDATA[This morning our flight left Vancouver at 11am and we arrived in St. John&#8217;s Newfoundland at 12:30am local time. Not much can be said really about today since most of it was spent on a plane. I got a good 8 hours of sleep during the day, but I&#8217;m still tired. Weird saying that since [...]]]></description>
			<content:encoded><![CDATA[<p>This morning our flight left Vancouver at 11am and we arrived in St. John&#8217;s Newfoundland at 12:30am local time. Not much can be said really about today since most of it was spent on a plane. I got a good 8 hours of sleep during the day, but I&#8217;m still tired. Weird saying that since it&#8217;s currently 4:30am here.</p>
<p>The flights over were fantastic, and we have to thank WestJet for flying us out here! I think the other guys may have been a bit jealous because on both flights I think I got <a href="http://ow.ly/i/dhYC" target="_blank">the best seat in the house</a>. Totally makes sense&#8230;since I am the shortest guy out of us all <img src='http://www.buyco.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here&#8217;s a short little video of our first day and just a couple shout outs at the end. </p>
<p><object width="600" height="371"><param name="movie" value="http://www.youtube.com/v/1beSWFwG9gI?version=3&#038;hl=en_US&#038;hd=1&#038;ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/1beSWFwG9gI?version=3&#038;hl=en_US&#038;hd=1&#038;ap=%2526fmt%3D18" type="application/x-shockwave-flash" width="600" height="371" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>I have to give a HUGE thank-you to London Drugs who provided us with this awesome Panasonic HDC-TM700 camcorder. The quality on this bad boy is insane! It shoots at 1920&#215;1080/60p and you can tell with the video above. Muchos gracias for their support!</p>
<p>I should probably leave it at that, I think I hear the birds chirping outside. Don&#8217;t forget to follow along in our adventure, and to join in at one of the cities closest to you!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2011/06/22/day-1-vancouver-to-st-johns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m leaving on a jet plane!</title>
		<link>http://www.buyco.ca/2011/06/20/im-leaving-on-a-jet-plane/</link>
		<comments>http://www.buyco.ca/2011/06/20/im-leaving-on-a-jet-plane/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 23:38:23 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[fhff]]></category>
		<category><![CDATA[five hole for food]]></category>
		<category><![CDATA[food bank]]></category>
		<category><![CDATA[hockey]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=241</guid>
		<description><![CDATA[Tomorrow&#8217;s the big day &#8212; the day I leave to travel across the country with hopes to make a difference in this world. After the months of planning, the support of our generous sponsors, and the many hands making light of heavy work&#8230; Here&#8217;s our story: That&#8217;s the gist of it. We&#8217;ll be gone for [...]]]></description>
			<content:encoded><![CDATA[<p>Tomorrow&#8217;s the big day &#8212; the day I leave to travel across the country with hopes to make a difference in this world. After the months of planning, the support of our generous sponsors, and the many hands making light of heavy work&#8230; Here&#8217;s our story:</p>
<p><object width="600" height="371"><param name="movie" value="http://www.youtube.com/v/CCaXgl_moH8?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/CCaXgl_moH8?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="600" height="371" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>That&#8217;s the gist of it. We&#8217;ll be gone for a good 3 weeks and to be honest this is the longest I&#8217;ve ever been away from home. My last vacation was years ago, and for about a week (maybe)&#8230;although this isn&#8217;t even a vacation! There is still tons of work left to do, and I&#8217;ve got to be on my toes throughout the entire trip. It&#8217;s hard to say exactly what I&#8217;ll be doing because there is so much to be done. But what I can do is try my best to keep everyone updated with daily videos, tweets, photos, blog entries, and high fives.</p>
<p>All I ask is that if you&#8217;re in one of our cities that we hit, you make an appearance <img src='http://www.buyco.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;ll keep this post short and sweet and leave you with some links you may fancy.</p>
<p>Official Five Hole For Food links:<br />
Website: <a href="http://www.fiveholeforfood.com/" target="_blank">http://www.fiveholeforfood.com/</a><br />
YouTube channel: <a href="http://www.youtube.com/user/FiveHoleForFood" target="_blank">http://www.youtube.com/user/FiveHoleForFood</a><br />
Twitter account: <a href="http://twitter.com/fiveholeforfood" target="_blank">http://twitter.com/fiveholeforfood</a><br />
My twitter account: <a href="http://twitter.com/jonathanbuyco" target="_blank">http://twitter.com/jonathanbuyco</a><br />
My flickr account: <a href="http://www.flickr.com/photos/jonathanbuyco/">http://www.flickr.com/photos/jonathanbuyco/</a></p>
<p>Also, muchos gracias to some of our sponsors:<br />
<a href="http://www.fiveholeforfood.com/sponsors/" target="_blank">http://www.fiveholeforfood.com/sponsors/</a></p>
<p>This trip wouldn&#8217;t happen without them!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2011/06/20/im-leaving-on-a-jet-plane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glee Camp Vancouver Experience</title>
		<link>http://www.buyco.ca/2010/12/01/glee-camp-vancouver-experience/</link>
		<comments>http://www.buyco.ca/2010/12/01/glee-camp-vancouver-experience/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 18:09:39 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[glee]]></category>
		<category><![CDATA[glee camp]]></category>
		<category><![CDATA[rocket man]]></category>
		<category><![CDATA[somebody to love]]></category>
		<category><![CDATA[time warp]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=219</guid>
		<description><![CDATA[Last night I was fortunate enough to experience my friends singing and dancing on stage similar to that of Glee! Mind you I&#8217;ve never seen the TV show, but if it&#8217;s anything like what I saw tonight I&#8217;m a new fan. To give a bit of a back-story for this, my friend Mariel mentioned she [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I was fortunate enough to experience my friends singing and dancing on stage similar to that of Glee! Mind you I&#8217;ve never seen the TV show, but if it&#8217;s anything like what I saw tonight I&#8217;m a new fan.</p>
<p><a href="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0744.jpg" rel="shadowbox[Glee Camp Vancouver]"><img src="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0744-150x150.jpg" alt="" title="0_DSC_0744" width="150" height="150" class="alignnone size-thumbnail wp-image-223" /></a> <a href="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0746.jpg" rel="shadowbox[Glee Camp Vancouver]"><img src="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0746-150x150.jpg" alt="" title="0_DSC_0746" width="150" height="150" class="alignnone size-thumbnail wp-image-224" /></a> <a href="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0753.jpg" rel="shadowbox[Glee Camp Vancouver]"><img src="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0753-150x150.jpg" alt="" title="0_DSC_0753" width="150" height="150" class="alignnone size-thumbnail wp-image-225" /></a> <a href="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0760.jpg" rel="shadowbox[Glee Camp Vancouver]"><img src="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0760-150x150.jpg" alt="" title="0_DSC_0760" width="150" height="150" class="alignnone size-thumbnail wp-image-226" /></a> <a href="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0768.jpg" rel="shadowbox[Glee Camp Vancouver]"><img src="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0768-150x150.jpg" alt="" title="0_DSC_0768" width="150" height="150" class="alignnone size-thumbnail wp-image-227" /></a> <a href="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0769.jpg" rel="shadowbox[Glee Camp Vancouver]"><img class="alignnone size-thumbnail wp-image-228" title="0_DSC_0769" src="http://www.buyco.ca/wp-content/uploads/2010/12/0_DSC_0769-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>To give a bit of a back-story for this, my friend Mariel mentioned she joined a Glee club where they practice singing in a group. The first time she mentioned it I thought it was some kind of support group for people who have singing problems lol. Turned out she really enjoyed it and was having a great time with her group. So for the following ten weeks thereafter she and her group worked very hard to put together an amazing night! So without further adieu, here is Mariel, Taal, Shayne and the other members of the Vancouver Glee Camp!</p>
<p>Rocket Man:</p>
<p><object width="600" height="362"><param name="movie" value="http://www.youtube.com/v/VedfVrhBoeE?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/VedfVrhBoeE?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="362"></embed></object></p>
<p>Time Warp:</p>
<p><object width="600" height="362"><param name="movie" value="http://www.youtube.com/v/0ikQPERim-o?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/0ikQPERim-o?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="362"></embed></object></p>
<p>Somebody to Love:</p>
<p><object width="600" height="362"><param name="movie" value="http://www.youtube.com/v/bd1nd-JK7jw?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/bd1nd-JK7jw?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="362"></embed></object></p>
<p>Like a Prayer:</p>
<p><object width="600" height="362"><param name="movie" value="http://www.youtube.com/v/fd8eV5ZMtKw?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/fd8eV5ZMtKw?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="362"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2010/12/01/glee-camp-vancouver-experience/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Essentials: Compatibility</title>
		<link>http://www.buyco.ca/2010/07/23/javascript-compatibility/</link>
		<comments>http://www.buyco.ca/2010/07/23/javascript-compatibility/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 21:30:05 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Weekly JavaScript Workshops]]></category>
		<category><![CDATA[compatibility]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=200</guid>
		<description><![CDATA[It's one thing to create some amazing interactivity with JavaScript, it's another if you can get it to work with all modern browsers]]></description>
			<content:encoded><![CDATA[<h2>Week 3 &#8211; JavaScript Essentials: Compatibility</h2>
<h3>Compatibility</h3>
<h4>Who are you programming for?</h4>
<p>It&#8217;s one thing to create some amazing interactivity with JavaScript, it&#8217;s another if you can get it to work with all modern browsers, and it&#8217;s above and beyond when you also take into account the needs of browsers with JavaScript disabled.</p>
<p>Creating functionality to work on your site for one particular browser (and version) and for one particular operating system is easy. Getting it to work with other browsers on all operating systems is a more daunting task. Adding functionality to enable elegant error messages for browsers with JavaScript disabled is a work of art!</p>
<p>There are hundreds if not thousands of combinations of browser/operating system combinations. It&#8217;s our duty as web developers to ensure that our sites work with the most common browsers and operating systems, without sacrificing too much of the user&#8217;s experience. For this week&#8217;s session, we&#8217;re going to consider the following groups:</p>
<h5>Modern browsers with JavaScript enabled</h5>
<p>This group is going to be your best friend. These are the browsers which work exactly how you want them to, close to W3C spec and are compatible with almost every bit of modern JavaScript code&#8211;although their reliability can also be a big downfall in your habits. Always remember: Just because it works on Firefox on Windows, doesn&#8217;t mean it works for everything else.</p>
<h5>Older browsers with JavaScript enabled</h5>
<p>Although there are not too many users out there sporting the Internet Explorer 6.0 SP2, they shouldn&#8217;t be forgotten. It&#8217;s not difficult to test code for these types of browsers, you just have to not be lazy. But even if you are, there are alternatives to writing a completely different set of code just for compatibility&#8217;s sake.</p>
<h5>Any browser with JavaScript disabled</h5>
<p>This can include essentially any browser you can think of. This might be the easiest group to speak to because you can&#8217;t with JavaScript!</p>
<h4>Honorable Mentions</h4>
<p>There are some other types of browsers we are not going to consider for this particular week&#8217;s session, but it&#8217;s good to know that they exist.</p>
<h5>Mobile Browsers</h5>
<p>Here we enter the realm of mobile browsing. We are now dealing with even more platforms/operating systems, and types of mobile browsers. Now how many of them actually support JavaScript? This group I rarely worry about because I consider the demographic of my audience and this rarely falls within a project&#8217;s requirements. In the case of you having to build a site compatible with mobile devices, there are several emulators out there you can use on your computer to test the functionality of your site:</p>
<ul>
<li><a href="http://www.winwap.com/desktop_applications/browser_emulator" target="_blank">WinWAP Smartphone Browser Emulator</a></li>
<li><a href="http://www.marketcircle.com/iphoney/" target="_blank">iPhoney iPhone Web Simulator</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=C62D54A5-183A-4A1E-A7E2-CC500ED1F19A&#038;displaylang=en" target="_blank">Device Emulator 1.0 with Windows Mobile OS Images</a></li>
</ul>
<p>These are only a few of many emulators out there which you can use, but this is a good place to start.</p>
<h5>Internet Explorer</h5>
<p>Yes we will go over Internet Explorer, but IE should still be considered as a separate group only because of how easy it is to isolate this subset. Consider the following:</p>
<pre class="brush: xml;">
		&lt;html xmlns="http://www.w3.org/1999/xhtml">
		&lt;head>
		&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		&lt;title>Hello there&lt;/title>
		&lt;!--[if !IE]>-->
		&lt;!--&#038;lt![endif]>-->
		&lt;/head>
		&lt;body>
		&lt;/body>
		&lt;/html>
	</pre>
<p>IE is the only browser you can explicitly call out like this. When writing your code, whether it is JavaScript or even CSS, remember you have this in your arsenal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2010/07/23/javascript-compatibility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Essentials: Event Handlers</title>
		<link>http://www.buyco.ca/2010/07/08/event-handlers/</link>
		<comments>http://www.buyco.ca/2010/07/08/event-handlers/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 01:11:03 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Weekly JavaScript Workshops]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=189</guid>
		<description><![CDATA[Week 2 &#8211; JavaScript Essentials: Event handlers Events What&#8217;s an event? Exactly what you think it is. They are occurrences of actions happening on a web page. They can be triggered by a user or by the webpage itself. Some of the most commonly known events are ONLOAD, ONCLICK, and ONMOUSEOVER. Certain elements on a [...]]]></description>
			<content:encoded><![CDATA[<h2>Week 2 &#8211; JavaScript Essentials: Event handlers</h2>
<h3>Events</h3>
<h4>What&#8217;s an event?</h4>
<p>Exactly what you think it is. They are occurrences of actions happening on a web page. They can be triggered by a user or by the webpage itself. Some of the most commonly known events are ONLOAD, ONCLICK, and ONMOUSEOVER. Certain elements on a page can trigger any or many of these events. JavaScript has the ability to detect these events and may be utilized to execute functions based on these triggers.</p>
<h4>List of common events</h4>
<p>This is not comprehensive, but I&#8217;ve included several common events based on the element.</p>
<div class="tabs">
<ul>
<li>A
<div class="tabcontent">
<dl>
<dt>onMouseOver</dt>
<dd>Trigger: when you move your mouse over </dd>
<dt>onMouseOut</dt>
<dd>Trigger: user moves mouse off of element</dd>
<dt>onClick</dt>
<dd>Trigger: user clicks on the element</dd>
</dl></div>
</li>
<li>IMG
<div class="tabcontent">
<dl>
<dt>onMouseOver</dt>
<dd>Trigger: when you move your mouse over </dd>
<dt>onMouseOut</dt>
<dd>Trigger: user moves mouse off of element</dd>
<dt>onClick</dt>
<dd>Trigger: user clicks on the element</dd>
<dt>onLoad</dt>
<dd>Trigger: when the element is loaded</dd>
</dl></div>
</li>
<li>INPUT
<div class="tabcontent">
<dl>
<dt>onMouseOver</dt>
<dd>Trigger: when you move your mouse over </dd>
<dt>onMouseOut</dt>
<dd>Trigger: user moves mouse off of element</dd>
<dt>onFocus</dt>
<dd>Trigger: user focuses on an element</dd>
<dt>onBlur</dt>
<dd>Trigger: element loses focus</dd>
<dt>onKeyUp</dt>
<dd>Trigger: user is typing and after a key press</dd>
<dt>onKeyDown</dt>
<dd>Trigger: user is typing and on key press</dd>
</dl></div>
</li>
<li>SELECT
<div class="tabcontent">
<dl>
<dt>onChange</dt>
<dd>Trigger: user changes the selected value</dd>
<dt>onFocus</dt>
<dd>Trigger: user focuses on an element</dd>
<dt>onBlur</dt>
<dd>Trigger: element loses focus</dd>
</dl></div>
</li>
<li>FORM
<div class="tabcontent">
<dl>
<dt>onSubmit</dt>
<dd>Trigger: user attempts to submit a form</dd>
</dl></div>
</li>
<li>BODY
<div class="tabcontent">
<dl>
<dt>onLoad</dt>
<dd>Trigger: when the page is completely loaded</dd>
<dt>onUnLoad</dt>
<dd>Trigger: user leaves the page</dd>
</dl></div>
</li>
</ul></div>
<p>A list of events can be found on the W3C website: <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.htm" target="_blank">http://www.w3.org/TR/DOM-Level-2-Events/events.htm</a>. It is also important to understand that not all browsers handle events the same. An example reference can be found here: <a href="http://www.quirksmode.org/dom/events/index.html" target="_blank">http://www.quirksmode.org/dom/events/index.html</a>.</p>
<h3>Event Handling</h3>
<p>There are several ways to handle these events. Now that you have an understanding of what can trigger these events, we&#8217;re going to attempt to catch them and do something. For the sake of simplicity, we will just execute <em>alert(&#8216;Hello World&#8217;);</em> for the next exercise. Each time an event is triggered, we will pop up a JavaScript dialog box which says &#8220;Hello World.&#8221;</p>
<h4>Example: Anchor Events</h4>
<p>Consider the following markup:</p>
<pre class="brush: xml;">
		&lt;html xmlns="http://www.w3.org/1999/xhtml">
		&lt;head>
		&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		&lt;title>Hello there&lt;/title>
		&lt;/head>
		&lt;body>
		&lt;h1>This is the title&lt;/h1>
		&lt;p>This is a paragraph &lt;a href="#">with a link&lt;/a>&lt;/p>
		&lt;/body>
		&lt;/html>
	</pre>
<p>We are going to change line 8 and add some event handlers:</p>
<pre class="brush: xml; first-line: 8">
		&lt;p>This is a paragraph &lt;a href="#" onclick="alert('Hello World');">with a link&lt;/a>&lt;/p>
	</pre>
<pre class="brush: xml; first-line: 8">
		&lt;p>This is a paragraph &lt;a href="#" onmouseover="alert('Hello World');">with a link&lt;/a>&lt;/p>
	</pre>
<pre class="brush: xml; first-line: 8">
		&lt;p>This is a paragraph &lt;a href="#" onmouseout="alert('Hello World');">with a link&lt;/a>&lt;/p>
	</pre>
<p>Try it for yourself. In the first example, when you click &#8220;with a link,&#8221; the dialog box should pop up. In the next, as soon as you move your mouse over the link, the dialog box should pop up. In the final example, when you move your mouse off the link (after it being over it), the dialog box should pop up.</p>
<p>The same method can be used with other event handlers where we directly input the JavaScript code in a new attribute in the element defined by the event handler name. For the most part this works just fine, but there are several reasons why we don&#8217;t want to do it this way:</p>
<ol>
<li>
<h5>Designers aren&#8217;t developers</h5>
<p>A designer doesn&#8217;t always understand how the functionality of the page works. If he/she makes a change to a link with explicit event handlers defined, unexpected errors may occur.</p>
</li>
<li>
<h5>Content management systems</h5>
<p>Not all CMSs honor inline JavaScript and may remove it from the HTML. </p>
</li>
<li>
<h5>Page overhead</h5>
<p>Adding inline code adds additional overhead to your markup. </p>
</li>
<li>
<h5>Coding standards</h5>
<p>There are no real coding standards for JavaScript, except for the peace of mind knowing your logic is separated from your view. It makes things easier down the road if you need to make updates to your code. (ref: <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" target="_blank">MVC architecture</a>)</p>
</li>
</ol>
<p>With browsers being updated very frequently, and functionality for JavaScript compatibility always on the bend, consolidating your code into one place makes things easier to update and makes your code much more scalable. The MVC concept works well with respect to JavaScript and although not completely necessary, it can make your life a lot easier in the long run.</p>
<h4>Example: Unobtrusive Anchor Events</h4>
<p>When we separate our JavaScript code from our HTML markup, we still need to listen to those event triggers. Unobtrusive JavaScript is centered around the idea of separating functionality and form; behavior and presentation; controller and view; etc. We will continue with our example with anchors, and do the same with unobtrusive JavaScript.</p>
<p>In the previous week&#8217;s topic, <a href="../week-1">we discussed element selection</a>. We are going to use the same ideas and incorporate event listening.</p>
<p>Consider the following markup:</p>
<pre class="brush: xml;">
		&lt;html xmlns="http://www.w3.org/1999/xhtml">
		&lt;head>
		&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		&lt;title>Hello there&lt;/title>
		&lt;/head>
		&lt;body>
		&lt;h1>This is the title&lt;/h1>
		&lt;p>This is a paragraph &lt;a href="#" id="mylink">with a link&lt;/a>&lt;/p>
		&lt;/body>
		&lt;/html>
	</pre>
<p>To simplify this example, we are going to take into consideration the pure JavaScript &#8220;domload&#8221; function which is called on the dom load referred to in <a href="../week-1/#2-4-where-should-the-code-be-">Week 1&#8242;s workshop</a>. For our prototype and jQuery examples, we are going to use their respective &#8220;domload&#8221; functions. We are then assuming this code will be placed in the document&#8217;s HEAD.</p>
<p>We will also be calling the following function when these events are triggered:</p>
<pre class="brush: jscript">

					// our hello world function
					function helloWorld(e) {
						alert('Hello World');
					}
	</pre>
<h5>Example: Listening to &#8220;onClick&#8221;</h5>
<div class="tabs">
<ul>
<li>Pure Javascript
<div class="tabcontent">
<pre class="brush: jscript;">
					// our domload function from Week 1
					initDOMLoad(function() {

						// check what kind of event listener function we need to call
						var m;
						window.addEventListener ? m = true : m = false;

						// select the link
						if (document.getElementById) {
							var objLink = document.getElementById('mylink');

							// use appropriate event listener
							if (m) {
								objLink.addEventListener('click', helloWorld, false);
							}
							else {
								objLink.attachEvent('onclick', helloWorld);
							}
						}
					});
				</pre>
</p></div>
</li>
<li>Prototype
<div class="tabcontent">
<pre class="brush: jscript;">
					// listen on dom load
					document.observe('dom:loaded',function() {

						// select the link and listen on click
						$('mylink').observe('click', helloWorld);
					});
				</pre>
</p></div>
</li>
<li>jQuery
<div class="tabcontent">
<pre class="brush: jscript;">
					// listen on dom load
					$(document).ready(function() {

						// select the link and listen on click
						$('a#mylink').click(helloWorld);
					});
				</pre>
</p></div>
</li>
</ul></div>
<h5>Example: Listening to &#8220;onMouseOver&#8221;</h5>
<div class="tabs">
<ul>
<li>Pure Javascript
<div class="tabcontent">
<pre class="brush: jscript;">
					// our domload function from Week 1
					initDOMLoad(function() {

						// check what kind of event listener function we need to call
						var m;
						window.addEventListener ? m = true : m = false;

						// select the link
						if (document.getElementById) {
							var objLink = document.getElementById('mylink');

							// use appropriate event listener
							if (m) {
								objLink.addEventListener('mouseover', helloWorld, false);
							}
							else {
								objLink.attachEvent('onmouseover', helloWorld);
							}
						}
					});
				</pre>
</p></div>
</li>
<li>Prototype
<div class="tabcontent">
<pre class="brush: jscript;">
					// listen on dom load
					document.observe('dom:loaded',function() {

						// select the link and listen on click
						$('mylink').observe('mouseover', helloWorld);
					});
				</pre>
</p></div>
</li>
<li>jQuery
<div class="tabcontent">
<pre class="brush: jscript;">

					// listen on dom load
					$(document).ready(function() {

						// select the link and listen on click
						$('a#mylink').mouseover(helloWorld);
					});
				</pre>
</p></div>
</li>
</ul></div>
<h5>Example: Listening to &#8220;onMouseOut&#8221;</h5>
<div class="tabs">
<ul>
<li>Pure Javascript
<div class="tabcontent">
<pre class="brush: jscript;">
					// our domload function from Week 1
					initDOMLoad(function() {

						// check what kind of event listener function we need to call
						var m;
						window.addEventListener ? m = true : m = false;

						// select the link
						if (document.getElementById) {
							var objLink = document.getElementById('mylink');

							// use appropriate event listener
							if (m) {
								objLink.addEventListener('mouseout', helloWorld, false);
							}
							else {
								objLink.attachEvent('onmouseout', helloWorld);
							}
						}
					});
				</pre>
</p></div>
</li>
<li>Prototype
<div class="tabcontent">
<pre class="brush: jscript;">
					// listen on dom load
					document.observe('dom:loaded',function() {

						// select the link and listen on click
						$('mylink').observe('mouseout', helloWorld);
					});
				</pre>
</p></div>
</li>
<li>jQuery
<div class="tabcontent">
<pre class="brush: jscript;">
					// listen on dom load
					$(document).ready(function() {

						// select the link and listen on click
						$('a#mylink').mouseout(helloWorld);
					});
				</pre>
</p></div>
</li>
</ul></div>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2010/07/08/event-handlers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JavaScript Essentials: Execution Order, Selectors, DOM manipulation</title>
		<link>http://www.buyco.ca/2010/07/07/javascript-essentials-execution-order-selectors-dom-manipulation/</link>
		<comments>http://www.buyco.ca/2010/07/07/javascript-essentials-execution-order-selectors-dom-manipulation/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 00:33:47 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Weekly JavaScript Workshops]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=172</guid>
		<description><![CDATA[Execution order When does the script get executed? It&#8217;s important to understand that JavaScript code will be run at different times during the page&#8217;s loading process, or even after. You can place code in a number of areas of a page: within the HEAD tag, the BODY tag or explicitly in elements within the BODY. [...]]]></description>
			<content:encoded><![CDATA[<h3>Execution order</h3>
<h4>When does the script get executed?</h4>
<p>It&#8217;s important to understand that JavaScript code will be run at different times during the page&#8217;s loading process, or even after. You can place code in a number of areas of a page: within the HEAD tag, the BODY tag or explicitly in elements within the BODY. </p>
<p>Consider the following markup:</p>
<pre class="brush: xml;">
		&lt;html xmlns="http://www.w3.org/1999/xhtml">
		&lt;head>
		&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		&lt;title>Hello there&lt;/title>
		&lt;script>
		// you can put your script here in the HEAD
		&lt;/script>
		&lt;/head>
		&lt;body>
		&lt;script>
		// you can put your script here in the BODY
		&lt;/script>
		&lt;p>Or you can put it in an element like this &lt;a href="http://www.buyco.ca" onclick="javascript:void(0);">link&lt;/a>&lt;/p>
		&lt;/body>
		&lt;/html>
	</pre>
<h4>Order of script execution</h4>
<ol>
<li>&lt;HEAD> tag</li>
<li>&lt;BODY> tag</li>
<li>on DOM load</li>
<li>on PAGE load</li>
</ol>
<p>This is most simply the order of script execution on your page. Before we get too deep into the mechanics of event handling, I will explain in the simplest terms what DOM load and PAGE load is. They are not specific areas where you can drop your code, rather they are points in time during the process of a browser loading the page and it&#8217;s contents. You can write scripts in the HEAD and BODY which tells your browser to execute scripts at those two points in time.</p>
<p>The moment at which the document is loaded and ready, but before any external references are even downloaded yet, is DOM load. By external references, I am talking about images, referenced style sheets, etc. After the document is ready, your browser starts to download those external resources (images, stylesheets, etc). When those resources are completely downloaded and displayed, this is the point in time when the PAGE is loaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2010/07/07/javascript-essentials-execution-order-selectors-dom-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leveraging JavaScript Frameworks to Make Your Life Easier</title>
		<link>http://www.buyco.ca/2009/08/28/leveraging-javascript-frameworks-to-make-your-life-easier/</link>
		<comments>http://www.buyco.ca/2009/08/28/leveraging-javascript-frameworks-to-make-your-life-easier/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 09:51:44 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Dev Tips and Tricks]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=132</guid>
		<description><![CDATA[Are you all about programming in JavaScript? Save yourself some time and try implementing a scripting framework. ]]></description>
			<content:encoded><![CDATA[<h4>Framework Preface</h4>
<p>Are you a hardcore JavaScript/AJAX programmer who knows no bounds? Do you spend meticulous hours perfecting your code so it works on all browsers? I used to be like that. I still am, but the only difference is that I now don&#8217;t spend hours testing my code. This is mostly attributed to the Prototype framework. Today I&#8217;m going to go through a few features and benefits of using a JavaScript framework over writing custom code yourself which may require testing and re-testing. Of course there is still the need for testing even when using a framework, but the difference is that there will be a lot of cross-browser compliance which is no longer needed.
<p>There are other frameworks out there like jQuery and MooTools, but today we&#8217;ll start with what I&#8217;m more familiar with and with what I first started with. The documentation for Prototype is very thorough and I don&#8217;t want to explain everything, so I&#8217;ll start off with the major items which will change your JavaScript programming life!</p>
<h4>JavaScript Framework? Double you tee eff?</h4>
<p>You&#8217;re asking the right question. For the longest time I was always stuck in my own little JavaScript world where everything I coded was job-specific, customized, and with my own techniques. There were also little quirks which JavaScript had when rendering/running under different browsers/operating systems&#8211;these too were also solved using my own super secret techniques. What Prototype does, as well as other JavaScript frameworks, is give you the simple building-blocks which solve those quirks without you even needing to address them specifically. For example, if you want a <em>div</em> element to show or hide, you simply select the element and program the action. Sounds simple, but selecting that element requires some browser detection and compatibility verification. Let&#8217;s make a couple comparisons..</p>
<h4>Make your life easier</h4>
<p>Continuing on with the previous example, let&#8217;s select that <em>div</em> element given the following markup:</p>
<pre class="brush: xml">
&lt;div id="copy">
	&lt;p>Lorem ipsom dolor sit amet&lt;/p>
&lt;/div>
</pre>
<p>We&#8217;re not going to think of any invokers right now, let&#8217;s just try to hide the <em>div</em>. Here is what the JavaScript may have looked like prior to using Prototype:</p>
<pre class="brush: jscript;">
var objDivId = 'copy';
objDiv = document.layers ? document.layers[objDivId] : document.all ? document.all[objDivId] : document.getElementById ? document.getElementById(objDivId) : null;
objDiv != null ? objDiv.style.display = 'none' : '';
</pre>
<p>Obviously this isn&#8217;t the most efficient way of doing this, ideally I would create a function, but this is the shortest of shorthands to select and hide the <em>div</em> element while respecting all web browsers. Now let&#8217;s have a look at how this would look using the Prototype framework:</p>
<pre class="brush: jscript;">
var objDivId = 'copy';
objDiv = $(objDivId);
$(objDivId) ? $(objDivId).style.display = 'none' : '';
</pre>
<p>For this example, the difference is quite apparent. By using the $() utility method we can quickly select that <em>div</em> element without the worry of what browser is being used. Now, let&#8217;s see what happens when we try to hide more than one element. First here&#8217;s the HTML markup:</p>
<pre class="brush: xml">
&lt;div id="copy">
	&lt;p>Lorem ipsom dolor sit amet&lt;/p>
&lt;/div>
&lt;div id="button">
	&lt;p>This is a button&lt;/p>
&lt;/div>
&lt;div id="preview">
	&lt;p>This is a preview section&lt;/p>
&lt;/div>
</pre>
<p>I&#8217;m going to create a function to hopefully help the cause of the traditional JavaScript code and see how it compares to using Prototype. First the oldschool method:</p>
<pre class="brush: jscript;">
function getObject(id) {
	return document.layers ? document.layers[id] : document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : null;
}
var objDivIds = new Array('copy','button','preview');
for (var i=0; i&lt;objDivIds.length; i++) {
	objDiv = getObject(objDivIds[i]);
	objDiv.style.display = 'none';
}
</pre>
<p>And now the code for doing the same thing using Prototype:</p>
<pre class="brush: jscript;">
$('copy','button','preview').invoke('hide');
</pre>
<p>Say what!? Yeah, it&#8217;s that easy. The traditional method utilizes a function which will return the object instance. We then iterate through the three <em>div</em> elements and update each one individually.</p>
<p>In the Prototype version, we&#8217;re using a couple of included extensions. First, the selector $() utility method returns an Enumerable list of objects, and the <em>hide</em> function is invoked across all of those objects. Easy fo-sheezy.</p>
<p>There are also other ways of selecting multiple elements within a page. You can do this by applying some CSS knowledge. For example, let&#8217;s attach a tracking script to all of the links within a page. We want to first select all of the <em>A</em> elements, then iterate through them by adding a short querystring tag to it&#8217;s <em>href</em> attribute.</p>
<pre class="brush: jscript;">
var _TAG = '?source=buyco.ca';
$$('a').each(function(objA) {
	var url = objA.getAttribute('href');
	objA.setAttribute('href',url+_TAG);
});
</pre>
<p>This time I&#8217;m using the $$() utility method which will select a collection of elements. It takes in CSS-style selectors, such as: &#8216;a.external&#8217; (select all a elements with the classname external), or &#8216;div#nav ul li&#8217; (select all list items in the div with the id of &#8216;nav&#8217;). The full documentation on this can be found on the <a href="http://www.prototypejs.org/api/utility" title="Prototype API" target="_blank">Prototype API documentation website</a>.</p>
<h4>Post face?</h4>
<p>These are two short examples of a few things you can do (quicker) by utilizing a JavaScript framework. You will spend less time focused on browser compliance and more on the functionality and interactivity of your websites. It&#8217;s not a quick transition, but practice does make perfect! The documentation on the <a href="http://www.prototypejs.org/" target="_blank" title="Prototype JS">Prototype website</a> is awesome, and I still find myself going back to learn new things. The main point I&#8217;m trying to get across here is that there are tools out there to make our lives (as web developers) a whole lot easier. Don&#8217;t get stuck in a place where you&#8217;re too comfortable or you&#8217;ll end up writing IE6-compliant code forever. Spend your time on more important things like user-experience, and wicked-awesome-flashy-effects. Your site visitors will thank you:)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2009/08/28/leveraging-javascript-frameworks-to-make-your-life-easier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing with Image Sprites and CSS for Beginners (Part 2)</title>
		<link>http://www.buyco.ca/2009/08/27/optimizing-with-image-sprites-and-css-for-beginners-part-2/</link>
		<comments>http://www.buyco.ca/2009/08/27/optimizing-with-image-sprites-and-css-for-beginners-part-2/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 09:34:02 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=118</guid>
		<description><![CDATA[I know what a sprite is. Now what do I do?!]]></description>
			<content:encoded><![CDATA[<h4>I know what a sprite is, now what?</h4>
<p>In Part 1 of <a title="Optimizing with Image Sprites and CSS for Beginners" href="http://www.buyco.ca/2009/06/30/optimizing-with-image-sprites-and-css-for-beginners-part-1/">Optimizing with Image Sprites and CSS for Beginners</a> I went through an explanation of what sprites are, how they work, and why to even bother. This time around we&#8217;re going to jump into some implementation of these sprites. I am still calling this Beginner stuff (only so that I can hit everyone with some hardcore code in the future), but if you happen to get confused follow me on <a title="Follow Jonathan Buyco on Twitter" href="http://twitter.com/jonathanbuyco" target="_blank">Twitter</a> and ask away!</p>
<h4>What am I going to use the sprite for?</h4>
<p>First let&#8217;s figure out what we&#8217;re even going to use the sprite for. When you&#8217;re ready to start slicing up your design, use your intuition and think of the graphical elements which will be used and reused on your site; this usually includes your navigation and maybe some buttons. In this example I&#8217;m going to use a sprite to create a &#8220;close&#8221; button and a textual navigation bar (SEO FTW). Here&#8217;s what I&#8217;ll be working with:</p>
<p><img src="/images/sprites.gif" alt="sprites" /></p>
<h4>Let&#8217;s open with a close</h4>
<p>This is the close button which I want sprite-ized:</p>
<p><a id="close" title="Close this badboy" href="#">Close</a></p>
<p>Your processes may be different, but I always start off with the HTML markup. The reason is because I want it as clean as possible and easily accessible for our search crawler friends. With a few quick keystrokes and a little touch of magic, this is what my markup for the close button looks like:</p>
<pre class="brush: xml;">&lt;a href="/close" title="Close this badboy" id="close"&gt;Close&lt;/a&gt;</pre>
<p>That was easy! Now let&#8217;s fancy this up with a bit of CSS magic and add the graphical close icon:</p>
<pre class="brush: css;">a#close {
	display: block;
	height: 14px;
	line-height: 14px;
	font: 11px 'Verdana','Arial',sans-serif;
	padding-left: 20px;
	background: url(sprites.gif) -32px -100px no-repeat;
}
a#close:hover {
	background-position: -32px -114px;
}
a#close:active {
	background-position: -32px -128px;
}</pre>
<h4>Wait.. what?</h4>
<p>I skipped about 20 steps there, so let&#8217;s go through this line by line:</p>
<pre class="brush: css; first-line: 2">	display: block;</pre>
<p>We need to give our link element layout so the graphic doesn&#8217;t get cropped. Display as <em>block</em>, kablammo problem solved! Almost..</p>
<pre class="brush: css; first-line: 3">	height: 14px;</pre>
<p>The close button consists of a 14&#215;14 area on our sprite map. We need to set the <em>height</em> so we don&#8217;t get any cropping.</p>
<pre class="brush: css;first-line: 4">	line-height: 14px;
	font: 11px 'Verdana','Arial',sans-serif;</pre>
<p>This part is a bit arbitrary. I set the <em>line-height</em> just so the text is vertically positioned evenly, and the font is a tribute to <a title="Ikea says Goodbye to Futurea" href="http://www.idsgn.org/posts/ikea-says-goodbye-to-futura/" target="_blank">Ikea</a> (don&#8217;t hurt me <img src='http://www.buyco.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<pre class="brush: css;first-line: 6">	padding-left: 20px;
	background: url(sprites.gif) -32px -100px no-repeat;</pre>
<p>The fun part! The <em>padding</em> is there so that the text for &#8220;close&#8221; is shifted to the right and not disturbing the space for the graphic. But where the hell did I get the -32px -100px from? It&#8217;s the sprite&#8217;s position! 32 pixels from the left, and 100 pixels from the top. An easy way of finding your graphic positions in your sprite map is to open up the file in Photoshop, use the rectangular marquee tool (M), then start a selection from the top left of the document and end at the topmost and leftmost of the graphic. Check your Info window (F8) and take note of the width and height of your selection&#8211; and there are your positioning coordinates!</p>
<pre class="brush: css;first-line: 9">a#close:hover {
	background-position: -32px -114px;
}
a#close:active {
	background-position: -32px -128px;
}</pre>
<p>These modifiers are just added to give a hover and click effect to the button. The only style changing here is the position of the background which then points to the coordinates of the hover and active states. Put this all together and you have yourself a close button!</p>
<p>I obviously geared the markup for this single example, not taking into account that you may want to reuse the code. With just a small change to select the class of the elements instead of styling based on ID, you can have multiple instances of this button:</p>
<pre class="brush: css;">a.close {
	display: block;
	height: 14px;
	line-height: 14px;
	font: 11px 'Verdana','Arial',sans-serif;
	padding-left: 20px;
	background: url(sprites.gif) -32px -100px no-repeat;
}
a.close:hover {
	background-position: -32px -114px;
}
a.close:active {
	background-position: -32px -128px;
}</pre>
<p>For you newbies: it&#8217;s the dot.</p>
<h4>Navigation Sprite&#8217;ing</h4>
<div id="navigation">
<ul>
<li><a href="#1"><span id="nav-first"> </span><span>Link 1</span></a></li>
<li class="splitter"></li>
<li><a href="#2"><span>Link 2</span></a></li>
<li class="splitter"></li>
<li><a href="#3"><span>Link 3</span></a></li>
<li class="splitter"></li>
<li><a href="#4"><span>Link 4</span></a></li>
<li class="splitter"></li>
<li><a href="#5"><span id="nav-last"> </span><span>Link 5</span></a></li>
</ul>
</div>
<p><br style="clear: both;" /></p>
<p>This may seem a bit more advanced, but I am using very similar techniques as the example above. Once again, I&#8217;ll start off with the markup:</p>
<pre class="brush: xml;">
&lt;div id="navigation"&gt;
	&lt;ul title="Jon's awesome navigation"&gt;
		&lt;li&gt;&lt;a href="link1" title="link 1"&gt;&lt;span id="nav-first"&gt;&lt;/span&gt;&lt;span&gt;Link 1&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
		&lt;li class="splitter"&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="link2" title="link 1"&gt;&lt;span&gt;Link 2&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
		&lt;li class="splitter"&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="link3" title="link 1"&gt;&lt;span&gt;Link 3&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
		&lt;li class="splitter"&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="link4" title="link 1"&gt;&lt;span&gt;Link 4&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
		&lt;li class="splitter"&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="link5" title="link 1"&gt;&lt;span id="nav-last"&gt;&lt;/span&gt;&lt;span&gt;Link 5&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;</pre>
<p>Wow that looks like some dirty code. Forgive me for the empty <em>span</em> tags, it&#8217;s getting late. I&#8217;m assuming everyone&#8217;s navigation markup looks pretty similar to this, so it shouldn&#8217;t be much of a stretch to update your style sheets. Speaking of which, here they are for this example:</p>
<pre class="brush: css;">div#navigation {
	font: 11px 'Verdana','Arial',sans-serif;
}
div#navigation ul {
	margin: 0;
	padding: 0;
	height: 50px;
	background: url(sprites.gif) 0 0 repeat-x;
	float: left;
	list-style-type: none;
}
div#navigation ul li {
	float: left;
	display: block;
	width: 50px;
}
div#navigation ul li.splitter {
	width: 2px;
	height: 50px;
	background: url(sprites.gif) -7px -100px no-repeat;
	float: left;
}
div#navigation ul li a {
	display: block;
	height: 50px;
	line-height: 50px;
	color: #606;
	text-decoration: none;
}
div#navigation ul li a:hover {
	background: url(sprites.gif) 0 -50px repeat-x;
	color: #404
}
div#navigation ul li a span	{
	display: block;
	padding: 0 5px;
}
div#navigation ul li a span#nav-first {
	display: block;
	position: absolute;
	padding: 0 !important;
	width: 6px;
	height: 50px;
	background: url(sprites.gif) 0 -100px no-repeat;
}
div#navigation ul li a:hover span#nav-first {
	background: url(sprites.gif) -16px -100px
}
div#navigation ul li a span#nav-last {
	display: block;
	position: absolute;
	margin: 0 0 0 44px;
	padding: 0 !important;
	width: 6px;
	height: 50px;
	background: url(sprites.gif) -10px -100px no-repeat;
}
div#navigation ul li a:hover span#nav-last {
	background: url(sprites.gif) -26px -100px;
}</pre>
<p>Quite a bit of styles. It&#8217;s okay though, you&#8217;ve obviously gone through the first example a million times already, so this should be a breeze.</p>
<p>Now, a lot of the styling is there just for aesthetics so we&#8217;ll skip all of that. Let&#8217;s just jump to the areas where we&#8217;re using sprites:</p>
<pre class="brush: css;first-line: 4">div#navigation ul {
	margin: 0;
	padding: 0;
	height: 50px;
	background: url(sprites.gif) 0 0 repeat-x;
	float: left;
	list-style-type: none;
}</pre>
<p>Here we are actually going to be repeating the sprite as the background in the x direction because I want this navigation bar to expand in the event of new sections. When creating a sprite with the intention of repeating it as a background, keep in mind that they can only be repeated in one direction: x or y. You cannot repeat a slice of a sprite in both directions, otherwise you may have other graphics in the sprite included in the repetition. Looking back at the original sprite, this background can be repeated in the x direction since there are no other slices to the left or right of that area.</p>
<pre class="brush: css;first-line: 30">div#navigation ul li a:hover {
	background: url(sprites.gif) 0 -50px repeat-x;
	color: #404
}</pre>
<p>Skipping all the positioning and font styles, I want to add a hover effect. Once again I&#8217;m utilizing a repeating background in the x-direction. The position is found using my marquee technique above.</p>
<pre class="brush: css;first-line: 17">div#navigation ul li.splitter {
	width: 2px;
	height: 50px;
	background: url(sprites.gif) -7px -100px no-repeat;
	float: left;
}</pre>
<p>I thought the navigation bar would look a little weird without having some kind of splitter between each option, so the styles above should take care of that. Here I am actually specifying the width because I do not want the background to repeat.</p>
<pre class="brush: css;first-line: 38">div#navigation ul li a span#nav-first {
	display: block;
	position: absolute;
	padding: 0 !important;
	width: 6px;
	height: 50px;
	background: url(sprites.gif) 0 -100px no-repeat;
}
div#navigation ul li a:hover span#nav-first {
	background: url(sprites.gif) -16px -100px
}
div#navigation ul li a span#nav-last {
	display: block;
	position: absolute;
	margin: 0 0 0 44px;
	padding: 0 !important;
	width: 6px;
	height: 50px;
	background: url(sprites.gif) -10px -100px no-repeat;
}
div#navigation ul li a:hover span#nav-last {
	background: url(sprites.gif) -26px -100px;
}</pre>
<p>Here I&#8217;m just being a little fancy and adding the smooth bits at each end of the navigation bar. Essentially the same techniques used above.</p>
<h4>Holy Crap!</h4>
<p>Yeah, it&#8217;s a lot to take in but I didn&#8217;t lie when I said this was a beginner guide because I assume everyone reading this is an expert with CSS.</p>
<p>The examples above are merely examples. I hope no one copy-and-pastes the markup because it won&#8217;t work for your site (figuratively speaking). I hope you learn from what was presented above, test out your own techniques, and apply it in your daily web development ventures. The best way of learning is to do it yourself, this guide is only here as a guide and also because I have nothing better to do at 2:00AM on a Wednesday morning <img src='http://www.buyco.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2009/08/27/optimizing-with-image-sprites-and-css-for-beginners-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Optimizing with Image Sprites and CSS for Beginners (Part 1)</title>
		<link>http://www.buyco.ca/2009/06/30/optimizing-with-image-sprites-and-css-for-beginners-part-1/</link>
		<comments>http://www.buyco.ca/2009/06/30/optimizing-with-image-sprites-and-css-for-beginners-part-1/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 00:20:59 +0000</pubDate>
		<dc:creator>Buyco</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web Dev Tips and Tricks]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://www.buyco.ca/?p=70</guid>
		<description><![CDATA[Image Sprites and fancy CSS code-work can save your website visitors' download time.
]]></description>
			<content:encoded><![CDATA[<h4>What the hell is an image sprite? Why do I care? How do I use it?!</h4>
<p>That&#8217;s probably the same thought process I had when I first started reading about image sprites. After a few minutes of investigation via Google, I wanted to try to implement this technique every and anywhere possible on my websites. This isn&#8217;t necessarily a required method of implementation of a web site but it is still something that every web developer should at least have an understanding of.</p>
<p>In this 2-part series I&#8217;ll go over what an image sprite is, when to use them, how to use them, as well as provide a few examples.</p>
<h4>What is an image sprite?</h4>
<p>Back in the olden days (circa 90s), multiple images were merged into a single graphic file to quickly composite 2D games. <a href="http://upload.wikimedia.org/wikipedia/commons/0/03/Sprite-example.gif" target="_blank">Here is an example</a> [source: wikipedia]. Certain parts of this single graphic would be extracted and used to animate objects, characters, etc. We can utilize the same methodology with our websites and optimize load times (as well as provide an easy means of updating graphics when the times come).</p>
<h4>How does an image sprite work in the web-world?</h4>
<p>One of the greatest things to happen to a web developer / designer is the invention of Cascading Style Sheets. We can use CSS to pick certain coordinates within a sprite and display those areas on our websites. It may sound a bit tedious to have to find the pixel by pixel locations of every sprite you want to use, but in doing this you may be able to shave off precious load times of your web page.</p>
<h4>Decreasing load times? Wtf?</h4>
<p>When you want to increase the performance of a website, one of your key objectives is to reduce the amount of time it takes for a particular page (or pages) to load. One way is to keep the number of HTTP requests to a minimum. Any time you insert an image, or include a JavaScript file, or any other file for that matter, it is an additional HTTP request. In the nature of a sprite, you are making a single HTTP request for that graphic, then referencing different parts of it to be displayed on a web page. This works great granted that the size of the single graphic is less than the size of all it&#8217;s containing graphics individually (we&#8217;re talking bits and bytes here, not lengths and widths).</p>
<p>Another potential advantage is browser caching. Take, for example, this navigation bar:</p>
<p><a href="http://www.buyco.ca/wp-content/uploads/2009/06/an-nav.jpg"><img class="alignnone size-full wp-image-71" title="an-nav" src="http://www.buyco.ca/wp-content/uploads/2009/06/an-nav.jpg" alt="an-nav" width="610" height="33" /></a></p>
<p>In this case we assume that this navigation bar is split up into 8 images: 4 for the &#8220;default state&#8221;, and 4 for the &#8220;hover state&#8221;. When the user hovers their mouse over a particular image, the &#8220;hover state&#8221; image is loaded on the fly. That&#8217;s a single HTTP request for that extra image. If a user does not hover over all the graphics, not all of them will load, so basically this page will only load the additional images if it *really* needs to. But still not the best situation&#8230;</p>
<p>Each graphic is around 1.097Kb &#8211; 0.997Kb totaling 8.11Kb. In actuality, I used a single sprite totaling 3.292Kb. By loading even only the &#8220;default state&#8221; images, we are still reaching a size larger than the single sprite.</p>
<h4>Applications</h4>
<p>That is only one situation where you can really utilize the benefits of using a sprite. Using them for navigation bars with hover states is probably the most common use, but some sites have taken it a step further.</p>
<p>Take Google for example. Shaving off a single millisecond of load time of their site can translate into some amazing results (probably because they get millions of hits a day). You may not see this type of traffic, but in either case you still don&#8217;t want to have a slow website.</p>
<p>Back to my point, lets have a look at a screenshot of my iGoogle homepage:</p>
<p><a href="http://www.buyco.ca/wp-content/uploads/2009/06/igoogle.gif"><img class="alignnone size-full wp-image-72" title="igoogle" src="http://www.buyco.ca/wp-content/uploads/2009/06/igoogle.gif" alt="igoogle" width="621" height="135" /></a></p>
<p>Looks like a simple logo right? In actuality, the logo is a part of an image sprite:</p>
<p><a href="http://www.buyco.ca/wp-content/uploads/2009/06/ico_sprite_classic.gif"><img class="alignnone size-full wp-image-73" title="ico_sprite_classic" src="http://www.buyco.ca/wp-content/uploads/2009/06/ico_sprite_classic.gif" alt="ico_sprite_classic" width="167" height="68" /></a></p>
<p>All those smaller icons are used as elements within the page. With some fancy CSS code-work, only a single image is used on this page! (That&#8217;s actually a lie since I have multiple gadgets running with external image sources).</p>
<p>Other high-volume sites like Yahoo and eBay also use image sprites so why don&#8217;t you!?</p>
<p>Tune in next time as I go through a few implementation examples: Optimizing with Image Sprites and CSS for Beginners (Part 2)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.buyco.ca/2009/06/30/optimizing-with-image-sprites-and-css-for-beginners-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

