<?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>Webmonkey &#187; tutorial</title>
    <atom:link href="http://www.webmonkey.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
    <link>http://www.webmonkey.com</link>
    <description>The Web Developer&#039;s Resource</description>
    <lastBuildDate>Fri, 05 Apr 2013 20:20:46 +0000</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <generator>http://wordpress.org/?v=3.4.2</generator>
    
    <item>
        <title>Learn to Code by Watching Others Write It</title>
        <link>http://www.webmonkey.com/2012/05/learn-to-code-by-watching-others-write-it/</link>
        <comments>http://www.webmonkey.com/2012/05/learn-to-code-by-watching-others-write-it/#comments</comments>
        <pubDate>Thu, 31 May 2012 15:52:09 +0000</pubDate>

                <dc:creator>Scott Gilbertson</dc:creator>

        <guid isPermaLink="false">http://www.webmonkey.com/?p=56955</guid>
        		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Basics]]></category>
		<category><![CDATA[tutorial]]></category>
            <enclosure url="http://www.webmonkey.com/wp-content/uploads/2012/05/stopwatch-200x100.jpg" type="image/jpeg" length="48000" />
                    <description><![CDATA[<div class="rss_thumbnail"><img src="http://www.webmonkey.com/wp-content/uploads/2012/05/stopwatch.jpg" alt="Learn to Code by Watching Others Write It" /></div>Learning to code can be difficult, so sometimes it helps to watch someone else do it first. That's exactly what Code Player does -- show you the code as it’s written.]]></description>

            <content:encoded><![CDATA[<p><!-- wpautop enabled -->
<p><div id="attachment_56972" class="wp-caption aligncenter" style="width: 590px"><a href="http://www.webmonkey.com/wp-content/uploads/2012/05/stopwatch.jpg"><img src="http://www.webmonkey.com/wp-content/uploads/2012/05/stopwatch.jpg" alt="" title="stopwatch" width="580" height="305" class="size-full wp-image-56972" /></a><p class="wp-caption-text">Stopwatch in CSS 3, no JavaScript necessary. <em>Image: Screenshot/Webmonkey</em></p></div>Five years ago the hotness in web development was showing what you could create without resorting to Flash. Now it seems the same is true of JavaScript. While we&#8217;ve nothing against JavaScript, the increasingly powerful tools in CSS 3 mean that JavaScript is no longer a necessity for building cool stuff on the web.</p>
<p>The latest JavaScript-free demo we&#8217;ve run across is this <a href="http://thecodeplayer.com/walkthrough/make-a-stopwatch-using-css3-without-images-or-javascript">very cool stopwatch demo</a> made using only CSS 3, no images or JavaScript necessary. Now before you dive into the code and get all <a href="https://twitter.com/KarlVanHoet">Karl Van Hœt</a> on us, yes, there is a script used to handle CSS prefixing, but the actual stopwatch doesn&#8217;t require it to work. </p>
<p>But what caught our eye even more than the JavaScript-free stopwatch demo is the tutorial that accompanies it. The tutorial &#8212; which is one part screencast and one part code dump &#8212; is part of <a href="http://thecodeplayer.com/">Code Player</a>, which helps you learn how to do things by showing you the code as it&#8217;s written. It&#8217;s an interesting tutorial method, one we haven&#8217;t seen before. </p>
<p>Watching code being written isn&#8217;t for everyone, especially beginners who might not be able to easily follow what&#8217;s happening, but it&#8217;s well suited to those that already understand the basics and just want to see how some particular function was written. It also provides an interesting look at how other developers work, which in turn might teach you a new trick or two. </p>
<p>The Code Player offers a variety of playback speeds depending on how fast you want to run through the tutorial, and there&#8217;s a timeline scrubber for pausing and rewinding any bits you miss. Our only complaint is that Code Player forces focus in the browser; when you try to click another tab or do something in the background Code Player steals focus back immediately.</p>
<p>If learning something new by watching someone else type sounds intriguing, head on over to the <a href="http://thecodeplayer.com/">Code Player</a> site. And don&#8217;t worry if the stopwatch demo has no appeal for you, there are plenty of other tutorials to choose from. </p>
<div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2012/05/learn-to-code-by-watching-others-write-it/feed/</wfw:commentRss>
        <slash:comments>0</slash:comments>

        
    </item>
    
    <item>
        <title>Microdata: HTML5&#8242;s Best-Kept Secret</title>
        <link>http://www.webmonkey.com/2010/09/microdata-html5s-best-kept-secret/</link>
        <comments>http://www.webmonkey.com/2010/09/microdata-html5s-best-kept-secret/#comments</comments>
        <pubDate>Fri, 10 Sep 2010 17:46:24 +0000</pubDate>

                <dc:creator>Scott Gilbertson</dc:creator>

        <guid isPermaLink="false">http://www.webmonkey.com/?p=48655</guid>
        		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Basics]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[Microdata]]></category>
		<category><![CDATA[microformats]]></category>
		<category><![CDATA[RDFa]]></category>
		<category><![CDATA[tutorial]]></category>
            <enclosure url="http://www.webmonkey.com/wp-content/uploads/2010/09/moleskine.jpg" type="image/jpeg" length="48000" />
                    <description><![CDATA[<div class="rss_thumbnail"><img src="http://www.webmonkey.com/wp-content/uploads/2010/09/moleskine.jpg" alt="Microdata: HTML5&#8242;s Best-Kept Secret" /></div>Given the amount of industry noise about native video and scripted animations, you&#8217;d be forgiven if you had never heard of the new microdata specification included in HTML5. Similar to outside efforts like Microformats, HTML5&#8242;s microdata offers a way of extend HTML by adding custom vocabularies to your pages. The easiest way to understand it [...]]]></description>

            <content:encoded><![CDATA[<p><!-- wpautop enabled --><a href="http://www.webmonkey.com/wp-content/uploads/2010/09/moleskine.jpg"><img src="http://www.webmonkey.com/wp-content/uploads/2010/09/moleskine.jpg" alt="" title="moleskine" width="200" /></a>
<p>Given the amount of industry noise about native video and scripted animations, you&#8217;d be forgiven if you had never heard of the new microdata specification included in HTML5.</p>
<p>Similar to outside efforts like Microformats, HTML5&#8242;s microdata offers a way of extend HTML by adding custom vocabularies to your pages.</p>
<p>The easiest way to understand it is to consider a common use case. Let&#8217;s say you want list details about a business on your page &#8212; the name, address, telephone number and so on. To do that you&#8217;ll need to use some vocabulary in addition to HTML, since there is no <code>&lt;business></code> tag.</p>
<p>Using microdata, you can create your own custom name/value pairs to define a vocabulary that describes a business listing.</p>
<p>When a search engine spider comes along, it will know that not only is your data a business listing, but it can discover the address, the phone number, or even the precise geo-coordinates if you want to include them.</p>
<p>Given that HTML5 is still a draft at this point, why bother?</p>
<p>Actually, despite its lack of publicity and HTML5&#8242;s still-incomplete status, microdata is already being used by Google, which has started adding information gleaned from microdata markup to its search result snippets.</p>
<p><span id="more-48655"></span></p>
<p>Microdata is useful today, but what about <a href="http://www.webmonkey.com/2007/12/microformats_are_awesome__now_put_them_to_work_for_your_site/">Microformats</a> or more complex tools like RDFa? The answer is that all three will work (and Google, in most cases, understands all of them). </p>
<p>In the end, the differences between the three are primarily in the syntax, and each has its advantages and disadvantages. But given that the Microdata specification will very likely become an official recommended web standard as part of HTML5, it seems the most future-proof of the three options.</p>
<p>So how do we add Microdata to a web page? Consider the following basic HTML markup, which might be used to describe my local coffee shop:</p>
<p><pre class="brush: js">
&lt;div>
    &lt;h1>Hendershot's Coffee Bar&lt;/h1>
    &lt;p>1560 Oglethorpe Ave, Athens, GA&lt;/p>
&lt;/div>
</pre>
<p>This markup gets the basic information on the page and humans can read it, but search engine spiders aren&#8217;t going to get much out of it. While it&#8217;s true that even Google says you should design for humans first and robots second, we can improve this code without making it any less human readable.</p>
<h3>Microdata</h3>
<p>To rewrite this business listing using HTML5&#8242;s microdata syntax, we would do something like this:</p>
<p><pre class="brush: js">
&lt;div itemscope itemtype="http://data-vocabulary.org/Organization"> 
    &lt;h1 itemprop="name">Hendershot's Coffee Bar&lt;/h1>
    &lt;p itemprop="address" itemscope itemtype="http://data-vocabulary.org/Address">
      &lt;span itemprop="street-address">1560 Oglethorpe Ave&lt;/span>, 
      &lt;span itemprop="locality">Athens&lt;/span>, 
      &lt;span itemprop="region">GA&lt;/span>.
    &lt;/p>
&lt;/div>
</pre>
<p>The Microdata markup adds a couple attributes you may not have seen before, <code>itemscope</code>, <code>itemtype</code> and <code>itemprop</code>. The first is essentially just a top level marker, it tells the search engine spider that you&#8217;re about to define something in the following nested tags. The <code>itemtype</code> attribute tells the spider what you&#8217;re defining &#8212; in this case, an organization.</p>
<p>The rest of the markup should look pretty familiar if you&#8217;ve used Microformats. The main change is the <code>itemprop</code> attribute (short for item property) to define what each element is. Because our address is all one paragraph, we&#8217;ve added some span tags to define each element of the address separately &#8212; street address, locality and so on. If we wanted, we could add other properties like a phone number (<code>itemprop="tel"</code>), a URL (<code>itemprop="url"</code>) or even geodata (<code>itemprop="geo"</code>).</p>
<p>So where did we get these <code>itemprop</code> vocabularies from? Well, as the URL in the <code>itemtype</code> attribute indicates, they come from <a href="http://www.data-vocabulary.org/">data-vocabulary.org</a>. Of course you can make up your own itemprop syntax, but if you want search engine spiders to understand your microdata, you&#8217;re going to have to document what you&#8217;re doing. Since the definitions at data-vocabulary.org cover a number of common use cases &#8212; events, organizations, people, products, recipes, reviews &#8212; it makes a good starting point.</p>
<h3>Microformats and RDFa</h3>
<p>So how does Microdata fit with <a href="http://microformats.org/">Microformats</a> and <a href="http://www.w3.org/TR/xhtml-rdfa-primer/">RDFa</a>? Well, the <a href="http://www.whatwg.org/">WHAT-WG</a>, which helps to develop the HTML5 spec, decided the flame wars provoked by the debate over whether to use Microformats or RDFa lacked sufficient vehemence, so they added a third definition of their own.</p>
<p>Actually, the reasoning seems to have been something like this: Microformats are a really good idea, but essentially a hack. Because Microformats rely only on the <code>class</code> and <code>rel</code> attributes, writing parsers to read them is complicated.</p>
<p>At the same time, RDFa was designed to work with the now-defunct XHTML 2.0 spec. Although RDFa is being ported to work with HTML5, it can be overly complex for many use cases. RDFa is a bit like asking what time it is and having someone tell you how to build a watch. Yes, RDFa can do the same things HTML5 microdata and Microformats do (and more), but if the history of the web teaches us a lesson, it&#8217;s that simpler solutions almost always win.</p>
<h3>Further Reading</h3>
<p>Before you dive into microdata, be sure to check out all the options. Google has a nice <a href="http://www.google.com/support/webmasters/bin/topic.py?topic=21997">overview on adding microdata to your page</a>, and offers examples using all three markup syntaxes. Mark Pilgrim&#8217;s Dive Into HTML5 also devotes <a href="http://diveintohtml5.org/extensibility.html">a chapter to microdata</a> with more detail on how microdata parsers read your markup.</p>
<p>Also, keep in mind that it isn&#8217;t just search engines that stand to benefit from microdata on your pages. The HTML5 spec also defines a set of <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#microdata-dom-api">DOM APIs for web browsers to read and manipulate microdata</a> on your pages. At the moment, no browser supports the API, but most probably will eventually.</p>
<p>The more information you can give the web, the more it can do with that information. Eventually, search engines could use microdata to find your friends on the web (like <a href="http://hueniverse.com/xrd/">XRD</a> and <a href="http://code.google.com/p/webfinger/">WebFinger</a>) and browsers could use it to connect you with those friends no matter what flavor-of-the-month social site they might be using.</p>
<p><strong>See Also:</strong><br/></p>
<ul>
<li><a href="http://www.webmonkey.com/2010/09/using-microformats-in-html5/">Using Microformats in HTML5</a></li>
<li><a href="http://www.webmonkey.com/2010/05/where-on-the-web-is-html5/">Where on the Web Is HTML5?</a></li>
<li><a href="http://www.webmonkey.com/2010/02/Add_Semantic_Value_to_Your_Pages_With_HTML_5/">Add Semantic Value to Your Pages With HTML 5</a></li>
<li><a href="http://www.webmonkey.com/2007/12/microformats_are_awesome__now_put_them_to_work_for_your_site/">Microformats are Awesome, Now Put Them to Work for Your Site</a></li>
</ul>
<div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/09/microdata-html5s-best-kept-secret/feed/</wfw:commentRss>
        <slash:comments>16</slash:comments>

        
    </item>
    
    <item>
        <title>Embed Videos In Your Web Pages Using HTML5</title>
        <link>http://www.webmonkey.com/2010/05/embed-videos-in-your-web-pages-using-html5/</link>
        <comments>http://www.webmonkey.com/2010/05/embed-videos-in-your-web-pages-using-html5/#comments</comments>
        <pubDate>Mon, 10 May 2010 22:34:59 +0000</pubDate>

                <dc:creator>Scott Gilbertson</dc:creator>

        <guid isPermaLink="false">http://www.webmonkey.com/?p=47343</guid>
        		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[video]]></category>
        <description><![CDATA[HTML5 video is taking the web by storm. Not only has a very public (and contentious) debate unfolded on the web about the efficacy of presenting videos using HTML5 instead of Flash, but momentum is gathering behind the nascent web standard. From giant video sites like YouTube to Wikipedia, everyone it seems wants to get [...]]]></description>

            <content:encoded><![CDATA[<p><!-- wpautop enabled -->HTML5 video is taking the web by storm.</p>
<p>Not only has a very public (<a href="http://www.webmonkey.com/2010/05/who-needs-flash/">and contentious</a>) debate unfolded on the web about the efficacy of presenting videos using HTML5 instead of Flash, but momentum is gathering behind the nascent web standard.</p>
<p>From giant video sites like YouTube to Wikipedia, everyone it seems wants to get their video out of Flash and into native web formats. With Microsoft recently announcing it will support the HTML5 video tag in the coming Internet Explorer 9, expect even more sites to abandon Flash for native video.</p>
<p>So, you want in on the fun? Do you want to use some HTML5 video tags on your site right now? No problem. Fasten your seat belts, as we&#8217;re about to take a tour of the wonderful world of HTML5 video.</p>
<p><span id="more-47343"></span></p>
<h2>Browser Support for HTML5</h2>
<p>First, let&#8217;s deal with some very basic stuff, like where this will work and where it won&#8217;t. As you can see in the table below, only the latest versions of most browsers support native video playback using HTML5&#8242;s &lt;video&gt; tag.</p>
<table style="text-align: center; margin: 20px 0;" border="0">
<caption style="font-size: 14px; font-weight: bold; text-align: left; margin: 6px 0;">HTML5 &lt;video&gt; support by browser:</caption>
<thead>
<tr style="margin: 6px 0;">
<th style="width: 80px;" title="Firefox 3.0">Fx 3.0</th>
<th style="width: 80px;" title="Firefox 3.5">Fx 3.5</th>
<th style="width: 80px;" title="Internet Explorer 7">IE7</th>
<th style="width: 80px;" title="Internet Explorer 8">IE8</th>
<th style="width: 80px;" title="Internet Explorer 9">IE9</th>
<th style="width: 80px;" title="Safari 3">Safari 3</th>
<th style="width: 80px;" title="Safari 4">Safari 4</th>
<th style="width: 80px;" title="Google Chrome 3+">Chrome 3+</th>
<th style="width: 80px;" title="Opera 10.5">Opera 10.5</th>
</tr>
</thead>
<tbody>
<tr style="margin: 6px 0;">
<td>·</td>
<td>✓</td>
<td>·</td>
<td>·</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
</tbody>
</table>
<p>Since Firefox 3.0 and IE 7 &amp; 8 lack any support for HTML5 video, you&#8217;ll have to come up with a fallback plan for serving video to those users. Depending on what you want to do you, could fallback first to Quicktime and then, failing that, to Flash. That&#8217;s the strategy used in <a href="http://camendesign.com/code/video_for_everybody">Video for Everyone</a> (note that as of v0.4, Video for everyone no longer falls back to QuickTime).</p>
<p>To keep things simple we&#8217;re just going to fall straight from HTML5 to Flash.</p>
<h2>Formats, Codecs and Technicalities</h2>
<p>The next thing you need to understand is what is actually happening when you load and play a video file in your web browser. You&#8217;re probably used to thinking of video as .mp4 or .mov files, but unfortunately it&#8217;s not that simple. The actual file formats are just containers. Think of them as a bit like a .zip file &#8212; they hold other stuff inside.</p>
<p>Each container holds at minimum one video track and, most likely, one audio track. When you watch a movie online, your video player (most likely Flash) decodes both the audio and video and sends the information to your screen and speakers.</p>
<p>Why does this matter? Well, because the process of decoding what&#8217;s inside the video container file varies. To know how to decode a movie, the player (which is your web browser in the case of HTML5 video) has to know which codec the movie was encoded with.</p>
<p>When it comes to web video there are two codecs to worry about: <strong>H.264</strong> and <strong>Theora</strong>.</p>
<p>There&#8217;s a <a href="http://www.webmonkey.com/2010/02/royalty_deadline_extended__but_hdot264_is_still_bad_for_the_web/">huge debate right now</a> among <a href="http://www.webmonkey.com/2010/02/can_google_save_free__open_web_video_with_vp8_/">web developers</a>, <a href="http://www.webmonkey.com/2010/02/opera_cto_sees_open__plug-in-free_video_in_web_s_future/">browser makers</a> and just about everyone else as to which codec is right for the web. We believe that a free, open codec without patent and licensing restrictions is the best solution for the web. Sadly, neither codec exactly fulfills that dream, so for now, let&#8217;s just skip the whole argument and be practical &#8212; we&#8217;re going to use both codecs.</p>
<p>Why? Well, have a look at the table below, which shows which codecs work where and you&#8217;ll quickly see that there is no one-size-fits-all-browsers solution. Only Google Chrome can play both H.264 and Theora.</p>
<table style="text-align: center" border="0">
<caption style="font-size: 14px; font-weight: bold; text-align: left; margin: 6px 0;">Codec support by browser/platform:</caption>
<thead>
<tr style="margin: 8px 0;">
<th></th>
<th style="width: 80px;">Firefox</th>
<th style="width: 80px;">Opera</th>
<th style="width: 80px;">Chrome</th>
<th style="width: 80px;">Safari</th>
<th style="width: 80px;">IE 9</th>
<th style="width: 80px;">iPhone</th>
<th style="width: 80px;">Android</th>
</tr>
</thead>
<tbody>
<tr style="margin: 20px 0;">
<th style="text-align: left;">Ogg Theora</th>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>·</td>
<td>·</td>
<td>·</td>
</tr>
<tr style="margin: 8px 0;">
<th style="text-align: left;">H.264</th>
<td>·</td>
<td>·</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
<td>✓</td>
</tr>
</tbody>
</table>
<p>So, you may be thinking &#8230; if HTML5 video doesn&#8217;t work in IE7 or IE8 and it means I&#8217;m going to have to encode my videos twice, then why bother at all? Well, the best answer is simple: mobile users. If you want iPhone and Android users to be able to see your video, HTML5 is the only way to do it &#8212; Flash support is coming to Android sooner or later but for now HTML5 is the only option, and we all know Flash doesn&#8217;t run on the iPhone or the iPad.</p>
<h2>The HTML5 Code</h2>
<p>Here&#8217;s how to actually embed your videos. First, we encode video in both .ogv and .mp4 containers. Encoding video is beyond the scope of this article, so instead we suggest you check out Mark Pilgrim&#8217;s online book <a href="http://diveintohtml5.org/">Dive Into HTML5</a>, which has a whole chapter devoted to <a href="http://diveintohtml5.org/video.html">understanding video encoding</a>. Pilgrim&#8217;s encoding suggestions use free software to get the job done, and in the end you&#8217;ll have two files &#8212; one .mp4 and one .ogv.</p>
<p>Now it&#8217;s time to unleash those movies in pure HTML glory. Here&#8217;s the code:</p>
<pre class="brush: js">&lt;video width="560" height="340" controls&gt;
  &lt;source src="path/to/myvideo.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'&gt;
&lt;source src="path/to/myvideo.ogv" type='video/ogg; codecs="theora, vorbis"'&gt;
&lt;/video&gt;</pre>
<p>Yes, that&#8217;s it. What we&#8217;ve done here is use the <code>&lt;video&gt;</code> tag to specify the dimensions of our video, and to denote that we want to use the browser&#8217;s default controls. Then, within the video tag, we&#8217;ve added two <code>&lt;source&gt;</code> elements which link to our video files.</p>
<p>The &#8220;type&#8221; attribute of the <code>&lt;source&gt;</code> tag helps the browser understand which file it should load. It&#8217;s a bit of an ugly chunk of code that needs to specify the container format, the video codec and the audio codec.</p>
<p>In this case we&#8217;ve assumed standard .ogv and baseline encoded H.264 video as per Pilgrim&#8217;s tutorial. See the <a href="http://wiki.whatwg.org/wiki/Video_type_parameters">WHATWG wiki</a> for more information on which video types you can specify.</p>
<p>And there you have it &#8212; native web video, no plugins required.</p>
<h2>Dealing With Everyone Else</h2>
<p>What about IE7, IE8 and older versions of just about any other browser? Well, for those users, we&#8217;ll fall back on Flash. To do that, we just use an <code>&lt;embed&gt;</code> tag within our video tag:</p>
<pre class="brush: js">&lt;video width="560" height="340" controls&gt;
  &lt;source src="path/to/myvideo.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'&gt;  
&lt;source src="path/to/myvideo.ogv" type='video/ogg; codecs="theora, vorbis"'&gt;
  &lt;object width="640" height="384" type="application/x-shockwave-flash"
		data="path/to/swf/player.swf?image=placeholder.jpg&amp;file=path/to/myvideo.mp4"&gt;
		&lt;param name="movie" value="path/to/swf/player.swf?image=placeholder.jpg&amp;file=path/to/myvideo.mp4" /&gt;
	&lt;/object&gt;
&lt;/video&gt;</pre>
<p>Now any browser that doesn&#8217;t understand the HTML5 video tag will just continue on its way until it hits the object tag, which it should understand (note that the order, mp4 before ogv, is important for iPad support &#8212; Apple requires that mp4 be the first video file).</p>
<p>Of course for this to work you need a Flash video container. <a href="http://www.longtailvideo.com/players/jw-flv-player/">JW Player</a> is one popular example, or you can roll your own using Adobe&#8217;s tools. Also remember that we still haven&#8217;t handled the case of an older version of Firefox with no Flash plugin installed (maybe your users are surfing your tubes with an outdated Linux machine). You can always add good old text-based links to the video files as a catch-all fix for anyone who can&#8217;t, for whatever reason, see either the HTML5 or Flash versions.</p>
<h2>Conclusion</h2>
<p>Embedding HTML5 video isn&#8217;t significantly more difficult than using Flash, especially if you&#8217;ve been using H.264 video files in your Flash player &#8212; which is exactly what YouTube has done with its HTML5 beta.</p>
<p>While we&#8217;re concerned about the licensing and patent requirements of H.264, it isn&#8217;t hard to notice that if you skip Theora and make all non-H.264 fall back to Flash, you&#8217;ve still saved yourself a considerable encoding headache. In fact, that&#8217;s probably the best practical argument against Mozilla and Opera&#8217;s refusal to support H.264.</p>
<p>If you&#8217;d like to use some of the more advanced aspects of HTML5 video, be sure to check the <a href="http://jilion.com/sublime/video">SublimeVideo player</a>, which offers very nice JavaScript-powered set of custom controls. Also be sure to have a look at <a href="http://camendesign.com/code/video_for_everybody">Video for Everybody</a>, which makes for more complex code but handles just about every use case you could imagine. And there&#8217;s a <a href="http://open.pages.kevinwiliarty.com/external-video-for-everybody/">handy Video for Everybody WordPress plugin</a> as well.</p>
<p><strong>See Also:</strong></p>
<ul>
<li><a href="http://www.webmonkey.com/2010/02/building_web_pages_with_html_5/">Building Web Pages With HTML5</a></li>
<li><a href="http://www.webmonkey.com/2010/02/Add_Semantic_Value_to_Your_Pages_With_HTML_5/">Add Semantic Value to Your Pages With HTML5</a></li>
<li><a href="http://www.webmonkey.com/2010/05/who-needs-flash/">Who Needs Flash?</a></li>
</ul>
<div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/05/embed-videos-in-your-web-pages-using-html5/feed/</wfw:commentRss>
        <slash:comments>52</slash:comments>

        
    </item>
    
    <item>
        <title>Ajax for Beginners</title>
        <link>http://www.webmonkey.com/2010/02/ajax_for_beginners/</link>
        <comments>http://www.webmonkey.com/2010/02/ajax_for_beginners/#comments</comments>
        <pubDate>Wed, 17 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=775</guid>
        		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[JavaScript has had the XMLHttpRequest object for almost a decade now, but it really only started getting wide attention in 2004. All this attention was mostly due to some showoff web applications that made every developer who saw them think, &#8220;I want my site to do that!&#8221; But it also has to do with the [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --></p><p>JavaScript has had the XMLHttpRequest object for almost a decade now, but it really only started getting wide attention in 2004. All this attention was mostly due to some showoff web applications that made every developer who saw them think, &#8220;I want my site to do that!&#8221; But it also has to do with the spiffy, spiffy name given to it by the folks at AdaptivePath, who named this asynchronized application <a href="http://www.adaptivepath.com/publications/essays/archives/000385.php" class="external text" title="http://www.adaptivepath.com/publications/essays/archives/000385.php" rel="nofollow">Ajax</a>. Maybe you&#8217;ve heard of it?

</p><p>A few high-profile Google applications in particular made a splash with Ajax: <a href="http://maps.google.com/" class="external text" title="http://maps.google.com/" rel="nofollow">Maps</a> and <a href="http://gmail.google.com/gmail" class="external text" title="http://gmail.google.com/gmail" rel="nofollow">Gmail</a> were first. It also powers some of the core functionality in the user interface of the ever-so-popular photo sharing site <a href="http://www.flickr.com" class="external text" title="http://www.flickr.com" rel="nofollow">Flickr</a>. By now, Ajax has become integral to the fabric of the web, especially in the era of real-time applications like <a href="http://www.twitter.com">Twitter</a>, <a href="http://www.google.com/buzz">Buzz</a> and <a href="http://www.google.com/wave">Wave</a> (all of which use Ajax extensively in their webapp front ends, for the record). Ajax may also lay claim to being the first JavaScript object with its own <a href="http://www.ajaxian.com/" class="external text" title="http://www.ajaxian.com/" rel="nofollow">fan website</a>. Date.com doesn&#8217;t count, although I did have a scintillating chat with a lady there once about the getTimeZoneoffset method.



</p><span id="more-775"></span><p><br />

</p>

<a name="What_is_Ajax.3F"></a><h3> <span class="mw-headline">What is Ajax?</span></h3>

<p>So what is this fancy object that everybody wants a piece of? In brief, it&#8217;s a solution to one of the big annoyances of web interfaces. Generally, the user inputs some data or makes a choice, and clicks a button that sends the data to the server. The server takes a look at the data and sends back a whole new web page, which is loaded into the browser. Reloading a page every time you want to do something is annoying, disjunctive and time-consuming for the user. XMLHttpRequest moves that browser-server interaction to behind the scenes, so the user can just keep on playing with the same page, even while elements on the page are talking to the server! Go take a look at <a href="http://www.google.com/webhp?complete=1" class="external text" title="http://www.google.com/webhp?complete=1" rel="nofollow">Google Suggest</a> if I&#8217;ve lost you &#8212; it&#8217;s a nice, eloquent example of this.

</p><p>JavaScript has always been able to sneakily trigger a server-side script without anything happening in the browser by using a few classic tricks. This one, for example:<tt>onSubmit='runascript = new Image(); runascript.src="<a href="http://www.wired.com/images/archiveyscript.php" class="external free" title="http://www.wired.com/images/archiveyscript.php" rel="nofollow">http://www.wired.com/images/archiveyscript.php</a>?" + this.value'</tt>. That sort of chicanery is good, maybe, for caching form data to a file on the server, but it doesn&#8217;t return any information to the JavaScript that calls it, so its usefulness is limited. Ajax, on the other hand, can get a full parcel of data back from the script it calls. Hence the &#8220;XML&#8221; part of the name  &#8211;  which really is just there for looks, kind of like the &#8220;Java&#8221; part of JavaScript, because the returned data can be plain text or whatever you like, if XML is overkill or just not your cup of tea.

</p><p>This opens up millions of exciting possibilities. Every form submission, every JavaScript event, and heaven knows what else, can now interact with server-side databases and processing power. Data retrieval, password authentication, image generation &#8211;  you name it, Ajax can trigger it.

</p>

<a name="Making_Your_Own"></a><h3> <span class="mw-headline">Making Your Own</span></h3>



<p>The potential of Ajax-enhanced web apps is limited only by your imagination &#8211;  and by browser support. Mozilla-based browsers can do it, and Safari, and newer versions of Explorer, and Opera 8 but not Opera 7. It&#8217;s best to incorporate a fallback way of doing things for users who aren&#8217;t as cutting edge as you&#8217;d like them to be. Also, Explorer does things somewhat differently (of course) from all the other browsers, so it&#8217;s necessary to fork the code to account for the irritating little 80-odd percent of the population who use IE.

</p><p>Let&#8217;s build a simple application that accepts input from the user, passes it to some PHP on the server that checks it against a database, and returns the result to the browser. It comes in three parts. First, we need an HTML form. This you&#8217;ve seen before:

</p><p><br />

</p>

 <pre class="brush: js">&lt;html&gt;

 &lt;head&gt;

 &lt;title&gt;Report&lt;/title&gt;

 &lt;script type='text/javascript' src='xhr.js'&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="fallbackpage.php" method="post"&gt;



 &lt;p&gt;Welcome, student. Please enter your essay here:&lt;textarea name="essay" id="essay"&gt;

 &lt;/textarea&gt; &lt;input type="submit" name="submit" value="Submit" onClick="return

 grade(this.form.essay.value);"&gt;

 &lt;/p&gt;

 &lt;/form&gt;

 &lt;/body&gt;



 &lt;/html&gt;

</pre>

<p><br />

Note that, for users without support for our script (named xhr.js), the form will just submit to the fallback page at fallbackpage.php.

</p><p>Next comes the JavaScript. This is the exciting part, so we&#8217;ll take it slow.

</p>

 <pre class="brush: js"> function grade(essay) {

 </pre>

<p>First, we initialize the object. We have to do it two ways, for different browsers.

</p><p><br />

</p>

 <pre class="brush: js">    // Mozilla version

    if (window.XMLHttpRequest) {

        xhr = new XMLHttpRequest();

    }

    // IE version

    else if (window.ActiveXObject) {

        xhr = new ActiveXObject("Microsoft.XMLHTTP");

    }

 </pre>



<p>Then, we escape the user input to make it URL-safe:

</p>

 <pre class="brush: js">    essay=encodeURIComponent(essay);

 </pre>

<p>and use the <tt>open</tt> method of the object to open a connection to the PHP script:

</p>

 <pre class="brush: js">    xhr.open("POST","grade.php");

 </pre>

<p>The method requires two arguments:first, the HTTP method (GET or POST); second, the URL of the script.

</p><p>A quick HTTP header prepares the script for what it&#8217;s getting, and then the <tt>send</tt> method transmits the actual request:



</p>

 <pre class="brush: js"> xhr.setRequestHeader(

      'Content-Type',

      'application/x-www-form-urlencoded; charset=UTF-8'); xhr.send(essay); </pre>

<p>This last step isn&#8217;t necessary for GET requests, wherein all the data can be contained in the query string of the URL.

</p><p><br />

</p>

<a name="Getting_Results"></a><h3> <span class="mw-headline">Getting Results</span></h3>

<p>Now we&#8217;re ready to see if the HTTP request worked. The <tt>readyState</tt> property counts up from zero during the request, and shows 4 when the server page has loaded successfully.

</p>

 <pre class="brush: js"> xhr.onreadystatechange=function() {

      if (xhr.readyState==4) {

 </pre>



<p>If the request worked, then we can get the output of the server-side script by querying the <tt>responseText</tt> property, which contains a string. For more complex server script output, a <tt>responseXML</tt> property, which can hold a full document object of XML data, is also available.

</p>

 <pre class="brush: js">      grade = xhr.responseText;

      alert ("Nice essay. Your grade is " + grade);

    }

    return false;

 }

 </pre>

<p>Want to see all that in a pastable block? Here it is in a <a href="http://www.wired.com/wired/webmonkey/stuff/Ajax_for_Beginners_code1.html" class="external text" title="http://www.wired.com/wired/webmonkey/stuff/Ajax_for_Beginners_code1.html" rel="nofollow">separate file</a>.

</p><p>Finally, the third component is the PHP script, which lives on the server and waits patiently for the JavaScript to pass it some juicy data. This example uses PHP, but any language you like &#8212; Ruby, Perl, C, ASP &#8212; can do as well. The core of this example script is a natural-language function called <tt>grade_essay()</tt> that grades student essays from 1 to 100, but I will redact that part to conserve space.



</p>

 <pre class="brush: js"> &lt;?php

 function grade_essay($essay) {

      return strlen($essay);

 }

 $essay = urldecode(implode(file('php://input')));

 $grade = grade_essay($essay);

 echo $grade;

 ?&gt;



 </pre>

<p>The <tt>php://input</tt> grabs the POST data, which gets put into a string, decoded and passed to the ingenious grading algorithm. The algorithm returns a numeric grade. Lastly, we just output the grade with <tt>echo</tt>  &#8211;  ordinarily, this would display in the browser, but since the PHP script is running &#8220;behind the scenes,&#8221; the string output is simply returned to the JavaScript that called it. If you need structured data, an XML document would be output with an <tt>echo</tt> statement in just the same way, but the content-type of the output page must be set to <tt>text/xml</tt>.



</p><p>What the user sees is this:She types her essay into the text area in the browser, clicks Submit, and within instants an alert box pops up giving her a final grade on the essay. Invisibly, the essay has been sent to the server, read and evaluated by a team of PHP gnomes, and returned with a grade, without ever reloading the page. The user can modify her essay and resubmit it endlessly.

</p><p>And that&#8217;s the gist of the almost magical XMLHttpRequest object! The example is simple, but the uses of the object can be elaborately, multifariously clever. If you need further inspiration and edification, a burgeoning number of examples are dotted around the Web:

</p>

<ul><li> Ajax-powered start pages like <a href="http://www.google.com/ig" class="external text" title="http://www.google.com/ig" rel="nofollow">iGoogle</a>, <a href="http://www.pageflakes.com/" class="external text" title="http://www.pageflakes.com/" rel="nofollow">Pageflakes</a> and <a href="http://www.netvibes.com/" class="external text" title="http://www.netvibes.com/" rel="nofollow">Netvibes</a>

</li></ul>

<ul><li> Social news site <a href="http://digg.com" class="external text" title="http://digg.com" rel="nofollow">Digg</a>



</li></ul>

<ul><li> Movie rentals site <a href="http://www.netflix.com" class="external text" title="http://www.netflix.com" rel="nofollow">Netflix</a>

</li></ul>

<p><br />

But what data you send and receive with Ajax is up to you.

</p><p><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/ajax_for_beginners/feed/</wfw:commentRss>
        <slash:comments>8</slash:comments>

        
    </item>
    
    <item>
        <title>Send HTML-Formatted E-mail</title>
        <link>http://www.webmonkey.com/2010/02/send_html-formatted_e-mail/</link>
        <comments>http://www.webmonkey.com/2010/02/send_html-formatted_e-mail/#comments</comments>
        <pubDate>Tue, 16 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=476</guid>
        		<category><![CDATA[HTML]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[A wedding of linkable web pages and regular e-mail, HTML e-mail is a growing medium for Internet communications, and it&#8217;s getting easier to use. HTML e-mail brings the power of the web browser to your e-mail inbox. Maybe you receive daily newsletters, weather updates, gardening tips, or whatever with pictures, fancy text and backgrounds and [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --><p>A wedding of linkable web pages and regular e-mail, <b>HTML e-mail</b> is a growing medium for Internet communications, and it&#8217;s getting easier to use.

</p><p>HTML e-mail brings the power of the web browser to your e-mail inbox. Maybe you receive daily newsletters, weather updates, gardening tips, or whatever with pictures, fancy text and backgrounds and clickable links? That&#8217;s HTML e-mail. All the information and delivery ease of an e-mail but with the look and feel of a web pages.

</p><p>With a basic knowledge of web design and a touch of e-mail savvy, you, too, can offer your own content in this format.</p>
<br />
<span id="more-476"></span>


<table id="toc" class="toc" summary="Contents"><tbody><tr><td><div id="toctitle"><h2>Contents</h2> </div>



<ol>

<li><a href="#What_you.27ll_need">What you&#8217;ll need</a></li>

<li><a href="#Limitations">Limitations</a>

<ol>

<li><a href="#How_It_Works">How It Works</a></li>

</ol>

</li>

<li><a href="#Final_Analysis">Final Analysis</a></li>



</ol>





</td></tr></tbody></table>



<a name="What_you.27ll_need"></a><h3> <span class="mw-headline">What you&#8217;ll need</span></h3>

<p>It may seem like a needless step, but take a moment to be sure that your e-mail service supports all of the standard mail protocols like POP (Post Office Protocol), IMAP (Internet Mail Access Protocol), SMTP (Simple Mail Transfer Protocol), and MIME (Multipurpose Internet Mail Extensions). Free accounts are available from <a href="http://www.hotmail.com/" class="external text" title="http://www.hotmail.com/" rel="nofollow">Hotmail</a> and <a href="http://www.gmail.com/" class="external text" title="http://www.gmail.com/" rel="nofollow">Gmail</a> among others, should you need one.

</p><p><br />

</p>



<a name="Limitations"></a><h3> <span class="mw-headline">Limitations</span></h3>

<p>Before taking the plunge, beware of the challenges of any e-mail endeavor:list management, bounced mail, and angry subscribers. And if you think designing for multiple browsers is fun, you will <i>love</i> HTML e-mail agents that ignore your tags. Let&#8217;s spend a moment dwelling on the technology&#8217;s limitations.

</p><p>It&#8217;s not good practice to include frames or exceedingly large images in HTML e-mails. Page anchors and custom backgrounds are usually supported. You will need to use absolute links, since the user will view your page within a foreign domain. (Relative links can be converted to absolute links using a simple search-and-replace.)

</p><p>Also, some mail agents skip the <tt>bgcolor</tt> attribute in the <tt>&lt;body&gt;</tt> tag. One trick is to specify bgcolor in a <tt>&lt;td&gt;</tt> (table cell) and put your whole page within the one-cell table.



</p><p>Don&#8217;t forget the folks who accidentally receive your HTML e-mail through a standard ASCII-text mail agent. If you&#8217;re not careful, your audience will be looking at all your mark-up mess (the raw links might work, but the page won&#8217;t look pretty). For this crowd, insert a comment tag &#8212; so it won&#8217;t appear when it shouldn&#8217;t &#8212; with some friendly unsubscribe instructions. In my opinion, friendly unsubscribe instructions should be included as a basic courtesy on any e-mail sent to a subscriber list.

</p><p><br />

</p>

<a name="How_It_Works"></a><h4> <span class="mw-headline">How It Works</span></h4>

<p>Here&#8217;s how it works. Incoming mail is stored in your POP account on an internet server as multipart MIME documents. A message is divided into a text component and MIME file attachments. These attachments are associated with a URL that calls in the graphics, animations and other elements at viewing time.

</p><p>Outgoing HTML e-mail is sent like any other piece of internet mail using SMTP &#8212; the trick is to manipulate the header information that accompanies your message.

</p><p>In addition to <tt>To:</tt>, <tt>From:</tt>, <tt>Cc:</tt>, and <tt>Bcc:</tt>, an e-mail header specifies content type, transfer encoding, and display properties of the mail. The most important of these header fields for HTML e-mail is <tt>Content-Type</tt>. Most mail agents send mail with <tt>Content-Type:text/plain</tt>, but you want yours to read <tt>Content-Type:text/html</tt>. Most mail agents will not let you modify this field, so you have to be crafty. One solution is to compose your HTML e-mail manually using a Unix mailer program. This will enable you to type a customized header. Here&#8217;s an example of a test message with appropriate header information:



</p>

<pre class="brush: js">Errors:errors@YourDomain.com

From:Your Name &lt;you@YourDomain.com&gt;

To:Recipient Name &lt;them@Theirs.com&gt;

Subject:test message

MIME-Version:1.0

Content-Type:text/html; charset=us-ascii

Content-Transfer-Encoding:7bit

Content-Disposition:inline; filename="filename.html"

Content-Base:http://www.YourDomain.com



&lt;b&gt;Hello there.&lt;/b&gt;&lt;br&gt;

Monkey see, monkey do.

</pre>

<p>Notice the extra line break before the body of the message. In a Unix mailer program, the body begins with the line following two consecutive carriage returns and ends with a single period on its own line. To test your message, send it to yourself.

</p>



<pre class="brush: js"> % sendmail -t filename.html

</pre>

<p>The <tt>-t</tt> tells your Unix mailer to read the header information from the file itself.

</p><p>Congratulations! Now you can send HTML e-mail from a Unix prompt. It felt really great the first time I sent myself an HTML e-mail. I admit my enthusiasm has diminished over time.

</p><p>On the bright side, the tools have long since caught up. Most clients, including Microsoft Outlook and Mozilla Thunderbird can send and receive HTML e-mail. Most web-based e-mail programs can even default to &#8220;<tt>Content-Type:text/html</tt>&#8221; with a button-click.

</p><p>Now it&#8217;s time to set up an HTML e-mail offering on your own site. Just remember to take an occassional weekend to yourself. At least whistle while you work.

</p>

<a name="Final_Analysis"></a><h3> <span class="mw-headline">Final Analysis</span></h3>

<p>HTML e-mail will not change your life. It&#8217;s a communications gimmick, a remora clinging to the belly of the internet. Spun from the success of web-based e-mail, HTML e-mail brings designer layouts, graphics, animation, sound and interactivity to the genre. What&#8217;s more &#8212; it caters to laziness. The not-so-savvy web enthusiast can passively receive updated content from a growing list of web publishers. In commercial corridors, HTML e-mail is used to ping an ambivalent user base while providing useful information in a sexy format. It&#8217;s non-invasive push media. This fosters habit-forming behavior in the user and encourages clickthroughs to a site.



</p><p>In all fairness, my biggest gripe with HTML e-mail is download time. It&#8217;s e-mail at the speed of a web page, and it will make you wait. There&#8217;s some appeal to downloading personalized daily news while you&#8217;re brushing your teeth, but is it worth it? Be your own guide.

</p><p><span id="title_name_el" class="wm_hidden_meta_class" title="All about HTML e-mail" style="visibility: hidden;"> <span id="page_path_el" class="wm_hidden_meta_class" title="/webmonkey/98/08/" style="visibility: hidden;"> <span id="author_el" class="wm_hidden_meta_class" title="carter" style="visibility: hidden;"> <span id="creation_date_el" class="wm_hidden_meta_class" title="1998-02-26T24:00:00Z" style="visibility: hidden;"> </span></span></span></span>

</p><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/send_html-formatted_e-mail/feed/</wfw:commentRss>
        <slash:comments>0</slash:comments>

        
    </item>
    
    <item>
        <title>Use Filters in Photoshop</title>
        <link>http://www.webmonkey.com/2010/02/use_filters_in_photoshop/</link>
        <comments>http://www.webmonkey.com/2010/02/use_filters_in_photoshop/#comments</comments>
        <pubDate>Tue, 16 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=667</guid>
        		<category><![CDATA[Multimedia]]></category>
		<category><![CDATA[UI/UX]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[OK, you&#8217;ve created your own weblog and your hands are shaking with excitement and terror. You just posted an excellent new piece that details your grievances with that jerk Kelly at work, an essay that is by turns insightful and thrillingly alive with a kind of erotic frisson. But where are your readers? Where are [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --><p>OK, you&#8217;ve created your own weblog and your hands are shaking with excitement and terror. You just posted an excellent new piece that details your grievances with that jerk Kelly at work, an essay that is by turns insightful and thrillingly alive with a kind of erotic <i>frisson</i>. But where are your readers? Where are the hits? Why aren&#8217;t people falling over themselves to get at your sweet, sweet words?

</p><p>There are many possible explanations, but one is that people are shallow, crass, and easily distracted by shiny objects. If they come to your site and just see a page full of text, their eyes will glaze over and they&#8217;ll head right on back to the Nude Animated GIFs site.

</p><p>But, but, it&#8217;s the content that&#8217;s important, right? Shouldn&#8217;t your razor-sharp writing be enough to keep their attention? Wouldn&#8217;t dressing up the text with pretty pictures almost be an insult? Isn&#8217;t it what&#8217;s <i>in here</i> (gesturing toward heart) that matters most of all?

</p><p>Yes, truly, but in the real world people like to see their content all gussied up, preferably as sextastically as possible. Sure, you can give them a few <a href="/2010/02/Photoshop_Tips_for_the_Web" title="Tutorial:Photoshop Tips for the Web"> well-cropped and color-adjusted photos</a>. But your blog also needs its fair share of arty, distorted, eye-searing pictures! And what about a zany logo?



</p><p>Enter filters!

</p><span id="more-667"></span><p>You may not be an artist &#8211; so what if your talent lies in crafting the written word? &#8211; but I&#8217;m here to tell you that while technology can&#8217;t yet generate interesting writing (check back in 2006 when Microsoft Grisham comes out of beta), it can do a lot of artistic legwork for you. It&#8217;s a secret that Web designers have known for years:If you can score a copy of the 800-pound behemoth known as Adobe Photoshop, you can fake artistic ability with the best of them.

</p>

<table id="toc" class="toc" summary="Contents"><tbody><tr><td><div id="toctitle"><h2>Contents</h2> </div>

<ol>

<li><a href="#Filter_Up.21">Filter Up!</a></li>

<li><a href="#Photo_Phreaking">Photo Phreaking</a></li>



<li><a href="#Useful_Filters.2C_Eyesore_Filters">Useful Filters, Eyesore Filters</a></li>

<li><a href="#Logo.2C_go.2C_GO.21">Logo, go, GO!</a></li>

</ol>

</td></tr></tbody></table>



<a name="Filter_Up.21"></a><h4> <span class="mw-headline">Filter Up!</span></h4>

<p>Yes, Photoshop is expensive, and yes, it can have a pretty steep learning curve. As for the first problem, let&#8217;s assume you can borrow a friend&#8217;s copy, or perhaps pick up the cheaper, more streamlined <a href="http://www.adobe.com/products/photoshopel/main.html" class="external text" title="http://www.adobe.com/products/photoshopel/main.html" rel="nofollow">Photoshop Elements</a>. As for the learning curve, the good news is that we can safely ignore just about everything the program has to offer except what lurks under the Filter menu.



</p><p>Sure, Photoshop can put your head on a bodybuilder&#8217;s torso or change a hideous pink sweater to a eye-bleeding orange, but that involves reading the manual and rooting around in the toolbar and palettes and the like. With filters, all you have to do is choose an effect and see what happens. They&#8217;re all about trial-and-error and learning-by-doing.

</p><p>Filters got their name from the world of photography, where you could change how a picture looked &#8211; brighter, redder, fuzzier, etc. &#8211; by placing a filter over the lens. Photoshop filters do the same thing, just with much more variety and weirdness. The program comes with dozens of built-in effects that can make your photograph look like everything from a Seurat painting to a bad photocopy. And once you get tired of those, you can pick up some <a href="http://www.freephotoshop.com/html/free_plugins.html" class="external text" title="http://www.freephotoshop.com/html/free_plugins.html" rel="nofollow">free ones</a> or buy some from third-party companies like <a href="http://www.xaostools.com/" class="external text" title="http://www.xaostools.com/" rel="nofollow">Xaos Tools</a>, <a href="http://www.alienskin.com/" class="external text" title="http://www.alienskin.com/" rel="nofollow">Alien Skin</a>, or <a href="http://www.flamingpear.com/" class="external text" title="http://www.flamingpear.com/" rel="nofollow">Flaming Pear</a>.

</p><p>So fire up Photoshop, open up any image, and then start making your way down the Filter menu. Pick one and watch the dark magic unfold. Some filters (the ones with &#8220;&#8230;&#8221; after their names in the menu) will pop-up a dialogue box before working. Just hit OK to see the default action, or drag the sliders around and see how tweakable everything is. Most filters have a preview window to give you an idea of how messed-up your picture is about to become. Nine times out of ten I have no clue what a particular variable means, but I can mess around with it and see the results, so from then on I know what to expect.

</p><p>Now that you&#8217;ve got the gist of filters, let&#8217;s take a look at a few examples.

</p>

<a name="Photo_Phreaking"></a><h4> <span class="mw-headline">Photo Phreaking</span></h4>



<p>Let&#8217;s say I have a <a href="http://blog.tripod.lycos.com/" class="external text" title="http://blog.tripod.lycos.com/" rel="nofollow">blog on Tripod</a> that&#8217;s all about me, my thoughts on life, the pretend conversations I have with my cats, and sonnets about my enchanted experiences at the Renaissance Faire. Keep in mind that this is <i>purely hypothetical</i>. I update my blog with seven or eight thousand words a day, but would like to break things up a little with some nice pictures.

</p><p>So I do what any self-respecting weblog author would and take a photo of myself in the bathroom mirror. That way people can put a face to the name, which can simplify matters when filing for a restraining order. The snapshot ends up looking more like an ad for the camera:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/original.jpg" alt="original.jpg">

</p><p><i>Plain-old unfiltered snapshot.</i>

</p><p>Let&#8217;s take it to the next level. The most popular use for Photoshop filters is tricking people into thinking you have artistic abilities. So I go to the Filter menu and right up top is a collection of filters filed under Artistic. Yes, I would like to be artistic. I laugh at the suckers who went to art school and click on Watercolor.

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/watercolor_palette.gif" alt="watercolor_palette.gif">

</p><p><i>The Watercolor Palette in action.</i>

</p><p>Up pops a box that shows a preview of my photo under the influence of the Watercolor filter. (Note:If you can&#8217;t see the entire picture in the preview window, you can click on it and drag it around to see other parts.) Below are some sliders that let me fine-tune it:Brush Detail, Shadow Intensity, and Texture. What does Brush Detail mean? Who knows &#8211; let&#8217;s slide it around. Looks like the lower the detail, the blockier and faker my picture gets. So I crank that up to 9, and turn the Shadow Intensity to 0 so it&#8217;s not too dark. In this example, the lower the Texture setting, the smoother it looks, so I set that to 1. Then I hit OK to see what it looks like.

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/watercolor.jpg" alt="watercolor.jpg">

</p><p><i>Hey, Mom! I do have talent after all! Look at this watercolor I painted!</i>



</p><p>OK, Mom isn&#8217;t buying it. <i>You&#8217;ll never understand my art, Mother!!!</i> Maybe she&#8217;ll be more convinced by a sketch. I head on down to the Sketch sub-menu and choose Chalk &amp; Charcoal. Again, three sliders to adjust how it looks. Charcoal Area and Chalk Area let you balance how much of each drawing tool you use, and Stroke Pressure lets you control how many sketch-strokes appear. Did I learn this in the manual? Oh no <i>way</i>. I just messed around with them to see what they did. Here&#8217;s what I ended up with:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/chalk_charcoal.jpg" alt="chalk_charcoal.jpg">

</p><p><i>I just sketched this up at the local cafe!</i>

</p><p>My skills are growing exponentially. I slap that on my weblog, write &#8220;Untitled Self-Portrait [24 x 18", chalk &amp; charcoal]&#8221; underneath it and pass it off as my own handiwork. My site is getting more visually interesting and now the galleries are calling. So I crank out some more fake art using four of the other filter faves:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/underpainting.jpg" alt="underpainting.jpg">

</p><p><i>The Underpainting filter.</i>



</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/pointillize.jpg" alt="pointillize.jpg">

</p><p><i>The Pointillize filter.</i>

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/graphicpen.gif" alt="graphicpen.gif">

</p><p><i>The Graphic Pen filter.</i>

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stainedglass.jpg" alt="stainedglass.jpg">

</p><p><i>The Stained Glass filter.</i>

</p><p><br />

But there&#8217;s more to filters than duping people. They can also be instruments of Boundless Good and Wretched Evil, as you&#8217;ll see.

</p>

<a name="Useful_Filters.2C_Eyesore_Filters"></a><h4> <span class="mw-headline">Useful Filters, Eyesore Filters</span></h4>

<p>Aside from art-simulating filters, there are also what I like to call Actually Useful filters and Beautiful Eyesore filters. In the first category is a set of tools that are relatively subtle and can vastly improve your pictures, if used with care. They can be found under opposing headers:Blur and Sharpen.

</p><p>Blur filters soften the focus of your picture, while Sharpen filters make it clearer. If you don&#8217;t want to mess around with sliders and settings, just choose Blur or Blur More (or Sharpen or Sharpen More), which apply a subtle version of the filter. If you want to have more control over, crank up Gaussian Blur or Unsharp Mask, two of the most widely used Photoshop filters.



</p><p>I often use these Actually Useful filters in conjunction with other filters. For example, Watercolor could cause some jagged edges in a picture and ruin the illusion of authentic paint-on-canvas. Blurring the picture slightly can smooth out those edges.

</p><p>Or you can pretend you&#8217;re a better photographer than you really are by selecting a portion of your picture and blurring it out, as if you&#8217;d carefully adjusted the focus when snapping the photo:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/blur.jpg" alt="blur.jpg">

</p><p>(This does, however, require a quick trip to the toolbar. I used the lasso and sloppily drew a line around everything except the camera, thereby selecting it. I then blurred the background with Gaussian Blur.)

</p><p>At the other end of the spectrum are the Beautiful Eyesores. These filters are all about messing up your picture quickly and efficiently, and have been responsible for some of the most astonishingly awful website designs ever. Gaze upon the retro headache of Color Halftone:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/colorhalftone.gif" alt="colorhalftone.gif">

</p><p>&#8230;or the eerie wonder of Plastic Wrap:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/plasticwrap.jpg" alt="plasticwrap.jpg">

</p><p>&#8230;or the funhouse mirror of Pinch:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/pinch.jpg" alt="pinch.jpg">

</p><p>&#8230;or the disco fever of Glowing Edges:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/glowingedges.jpg" alt="glowingedges.jpg">

</p><p>&#8230;or the infamous Lens Flare:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/lensflare.jpg" alt="lensflare.jpg">

</p><p>These are but a small sample. Dig deep into the Filter menu and push those sliders to the extreme to really see what horrors Photoshop is capable of inflicting.

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/lensflare_palette.jpg" alt="lensflare_palette.jpg">

</p><p>But even Beautiful Eyesores can have palatable results. Let&#8217;s try throwing them at something other than a photograph.



</p>

<a name="Logo.2C_go.2C_GO.21"></a><h4> <span class="mw-headline">Logo, go, GO!</span></h4>

<p>Up till now we&#8217;ve been working with photographs which are, of course, Photoshop&#8217;s favorite thing. But what if I wanted to make a logo that featured the title of my site?

</p><p>Let&#8217;s say &#8211; again, <i>hypothetically</i> &#8211; that my weblog is called &#8220;Josh&#8217;s House of Stank.&#8221; I type the title into Photoshop and give it a blue background. (This calls for another brief trip to the toolbar to use the Type and Paint Bucket tools.) Like so:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank.gif" alt="stank.gif">

</p><p>Fine enough, but boring. What happens if we throw some filters at it? Let&#8217;s give ye olde Pinch another shot:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank_pinch.gif" alt="stank_pinch.gif">

</p><p>Not bad! Or maybe the aforementioned Glowing Edges:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank_glowingedges.gif" alt="stank_glowingedges.gif">

</p><p>Weird! Encouraged, I try some new ones, like Radial Blur, Mosaic Tiles, Emboss, or Extrude:

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank_radialblur.gif" alt="stank_radialblur.gif">

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank_mosaictiles.gif" alt="stank_mosaictiles.gif">



</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank_emboss.gif" alt="stank_emboss.gif">

</p><p><img src="http://www.wired.com/wired/webmonkey/stuff/Photoshop_FIlters/stank_extrude.gif" alt="stank_extrude.gif">

</p><p>As always, just choose some at random and play around with their options. Photoshop filters are extremely powerful and any one of them, even the most egregious Eyesore, can do something great if applied to the right subject and tweaked in the right direction.

</p><p>So play around with them for a while and before long you&#8217;ll have something intriguing enough to catch a visitor&#8217;s eye. Then they&#8217;ll be hooked, and will finally read your words, and after that &#8230; it&#8217;s all over. You will <i>own</i> them.

</p><p><br /><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/use_filters_in_photoshop/feed/</wfw:commentRss>
        <slash:comments>1</slash:comments>

        
    </item>
    
    <item>
        <title>Keep Sites Clean With Smarty</title>
        <link>http://www.webmonkey.com/2010/02/keep_sites_clean_with_smarty/</link>
        <comments>http://www.webmonkey.com/2010/02/keep_sites_clean_with_smarty/#comments</comments>
        <pubDate>Tue, 16 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=773</guid>
        		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[One of the main advantages of systems like PHP, XSSI, and CSS is the way they let us keep the functional code (or &#8220;business logic&#8221; as the eggheads call it) separate from how the content is rendered (&#8220;presentation&#8221;). At least in theory. In actuality, this separation happens all too rarely, and muddled code with everything [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --><p>One of the main advantages of systems like PHP, XSSI, and CSS is the way they let us keep the functional code (or &#8220;business logic&#8221; as the eggheads call it) separate from how the content is rendered (&#8220;presentation&#8221;). At least in theory.

</p><p>In actuality, this separation happens all too rarely, and muddled code with everything scrambled together is the norm. That kind of separation becomes especially important when multiple people are involved in a project, with designers, programmers and content writers working separately. Or, when you need to make frequent changes to, say, the look of a site without changing its wording, or vice versa.

</p><span id="more-773"></span><p><br />

</p>

<table id="toc" class="toc" summary="Contents"><tbody><tr><td><div id="toctitle"><h2>Contents</h2> </div>



<ol>

<li><a href="#The_Basic_Smarty_Template">The Basic Smarty Template</a></li>

<li><a href="#Installing_Smarty">Installing Smarty</a></li>

<li><a href="#Building_a_Smarty_Page">Building a Smarty Page</a></li>

<li><a href="#Template_Tricks">Template Tricks</a></li>



</ol>

</td></tr></tbody></table>



<a name="The_Basic_Smarty_Template"></a><h3> <span class="mw-headline">The Basic Smarty Template</span></h3>

<p><a href="http://smarty.php.net" class="external text" title="http://smarty.php.net" rel="nofollow">Smarty</a> makes separation much, much easier by layering a templating system on top of PHP. This allows flaky designers, unwashed programmers and who-needs-&#8217;em content monkeys to all do their own thing without even seeing, let alone stepping on, each other&#8217;s toes. A Smarty template acts as the intermediary between all of them. The template consists of a designed HTML page with slots for content that can be filled dynamically.

</p><p>An example of a template will clarify how this works:

</p>

<pre class="brush: js">

 &lt;html&gt;

 &lt;head&gt;



 &lt;title&gt;

 How to recognize {$name}

 &lt;/title&gt;

 &lt;/head&gt;

 &lt;body bgcolor="#000099"&gt;

 {$name}'s hair is {$haircolor}. He or she wears {$shoecolor} shoes.

 &lt;/body&gt;



 &lt;/html&gt;

</pre>

<p>The snazzy look of that template was created by a brilliant design team on giant CRT monitors, and the data inside the curly brackets is fed in from a PHP script created by a part-time web programmer with a burrito tattoo. The two have never met, and they like it that way.

</p><p>Naturally, templates typically get quite a bit more complex than that. But let&#8217;s start by installing Smarty.

</p>

<a name="Installing_Smarty"></a><h3> <span class="mw-headline">Installing Smarty</span></h3>

<p>All you need to get started is a web server running PHP. Download the latest release of Smarty from the <a href="http://www.smarty.net/download.php" class="external text" title="http://www.smarty.net/download.php" rel="nofollow">download page</a>, and untar the package:

</p>

<pre class="brush: js"> tar xzvf Smarty-x.y.z.tar.gz

</pre>



<p>It contains several directories, including an important one called libs:place that in its entirety somewhere in your PHP include path.

</p><p>If you don&#8217;t know where your include path is, it can be found by reading the output of the PHP function <tt>phpinfo()</tt>, and it can be modified in the php.ini file (if you have access to that on your server) or with the <tt>ini_set()</tt> function (if you don&#8217;t).

</p><p>Alternately, you can put it any old place and refer to its location specifically every time you <tt>include()</tt> it. The <tt>libs</tt> directory contains the functional heart of Smarty, the PHP classes that do the work.

</p><p>Next, create a web-accessible directory where you are going to build your first Smarty template. In this directory, create three subdirectories, called templates, templates_c and configs. Smarty uses these to work its magic, as we shall see.

</p><p>The installation of Smarty is now complete. You will have to reboot your server. Just kidding!

</p>



<a name="Building_a_Smarty_Page"></a><h3> <span class="mw-headline">Building a Smarty Page</span></h3>

<p>Two components are required for a Smarty page:a template file, which ends with a .tpl suffix, and a PHP file that invokes Smarty and gives values to the template variables. Going back to our hypothetical designer and programmer, the designer messes around with the template file to her heart&#8217;s content to control the looks of the page, and the programmer handles the PHP (and MySQL or what-have-you).

</p><p>Let&#8217;s start with that template page up top. Save it in your templates directory (that is where all templates should live) under the name <tt>recognize.tpl</tt>. Then, wearing our Programmer hat, we will breathe life into it by creating a basic PHP file, called <tt>recognize.php</tt>:

</p>

<pre class="brush: js">&lt;php&gt;

</pre>

<p>First we need to pull in the Smarty class:

</p>

<pre class="brush: js"> require 'Smarty.class.php';



</pre>

<p>If you didn&#8217;t put the libs directory in your include path like I told you, you&#8217;ll have to specify &#8216;<tt>/path/to/Smarty.class.php</tt>&#8216; explicitly.

</p><p>Then we create a Smarty object from the class:

</p>

<pre class="brush: js"> $smarty = new Smarty;

</pre>

<p>Every Smarty script begins in roughly this way. Now we can begin assigning values to variables, using the <tt>assign</tt> method of the Smarty class. In practice, these values will come from a database or other dynamic source.

</p>

<pre class="brush: js"> $firstname = 'Sandra';



 $smarty-&gt;assign('haircolor', 'auburn');



 $smarty-&gt;assign('shoecolor', 'taupe');



 $smarty-&gt;assign('name', $firstname);



</pre>

<p>Finally, we use the <tt>display</tt> method to call and display the template, nicely filled in with the values we assigned:

</p>

<pre class="brush: js"> $smarty-&gt;display('recognize.tpl');



 ?&gt;

</pre>

<p>End of script. Here&#8217;s a clean copy:

</p>

<pre class="brush: js"> &lt;php&gt;

 require 'Smarty.class.php';

 $smarty = new Smarty;

 $firstname = 'Sandra';

 $smarty-&gt;assign('haircolor', 'auburn');

 $smarty-&gt;assign('shoecolor', 'taupe');

 $smarty-&gt;assign('name', $firstname);

 $smarty-&gt;display('recognize.tpl');

 ?&gt;



</pre>

<p>If you launch <a href="http://yoursite.com/smartydir/recognize.php" class="external free" title="http://yoursite.com/smartydir/recognize.php" rel="nofollow">http://yoursite.com/smartydir/recognize.php</a> and you&#8217;ve done everything correctly, it should display a finished page saying that:

</p>

<pre class="brush: js"> Sandra's hair is auburn. He or she wears taupe shoes.

</pre>

<p>The first time Smarty displays the page, it also compiles the output into a PHP page and stores that in the templates_c directory. That makes everything run faster, since the Smarty engine doesn&#8217;t have to parse the template again until it&#8217;s changed.

</p><p>Congratulations! That&#8217;s your first Smarty page!

</p>

<a name="Template_Tricks"></a><h3> <span class="mw-headline">Template Tricks</span></h3>

<p>If that was all Smarty could do, it&#8217;d be kind of nifty but probably not worth a Webmonkey article this long. Since this article is still unspooling, we can therefore deduce that there&#8217;s more to Smarty, much more. A host of template functions are provided that make Smarty a genuinely robust way of doing things. Let&#8217;s put on that stylish Designer hat again.

</p><p>Working with a template, we aren&#8217;t limited to simply grabbing variable values from the PHP script and displaying them in nice colors. The display of variables can be changed dynamically in the template with a variety of modifier functions. For example, to convert the value of a string to all caps, we can use a reference in the template like this:



</p>

<pre class="brush: js"> I said, {$name}'s hair is {$haircolor|upper}!!!

</pre>

<p>The <tt>|upper</tt> causes the value of <tt>$haircolor</tt> to be displayed in uppercase:

</p>

<pre class="brush: js"> I said, Sandra's hair is AUBURN!!!

</pre>

<p>There are a number of other useful modifiers. <tt>Truncate</tt> is awfully handy when you want to display strings of varying or unknown lengths in a confined space:It chops off the end of the string at a length you specify. So if your template reads:



</p>

<pre class="brush: js"> My favorite foods are {$foods|truncate:15}

</pre>

<p>The output will be:

</p>

<pre class="brush: js"> My favorite foods are zucchini, lemons...

</pre>

<p>regardless of how long the actual content of the <tt>$foods</tt> variable is. That &#8220;15&#8243; in the template is an argument telling <tt>truncate</tt> how many characters to cut off at. You can pass additional arguments to change the appended text (&#8220;&#8230;&#8221; is the default) and to specify whether to chop off the string at the preceding word boundary or right in the middle of a word (&#8220;false&#8221; does the former, &#8220;true&#8221; the latter). Thus <tt>{$foods|truncate:5:"-aagh!":true}</tt> will cut off the string at five characters, regardless of whether the word is done or not, and append &#8220;-aagh!&#8221; to the truncated string:



</p>

<pre class="brush: js"> My favorite foods are zucch-aagh!

</pre>

<p>As you can see, the colon character <tt>:</tt> delimits arguments.

</p><p><tt>Wordwrap</tt> is used to word-wrap long strings, and also takes three optional arguments, specifying:the number of characters before wrapping (default is 80); what to put at the end of each line (default is <tt>n</tt>, the newline character); and whether to break lines at word boundaries (the default) or just exactly when the character count is met. So, to insert <br /> tags in a string every 40 characters, without respect for word boundaries, we use:<tt>{$string|wordwrap:40:"<br />":true}</tt>.



</p><p>One more:<tt>regex_replace</tt> allows for actual text replacement in the template. It uses the same syntax as PHP&#8217;s <a href="http://us3.php.net/preg_replace" class="external text" title="http://us3.php.net/preg_replace" rel="nofollow">preg_replace()</a> function. That is to say, it takes two arguments:first the regular expression for which to search the string, and second the text to replace it with. So, to replace every instance of the word &#8220;color&#8221; with &#8220;colour&#8221; and then put the string in all caps (sorry, not all these examples can be hilarious ones) we&#8217;d say <tt>{$string|regex_replace:"/color/":"colour"|upper}</tt>. Notice how I tacked a second modifier, <tt>upper</tt>, onto that. When multiple modifiers are used, they are evaluated from left to right.

</p><p>The arsenal of variable modifiers gives designers a nice little dose of power over the content. There&#8217;s more where that came from:Stay tuned for our intermediate Smarty course, in which we&#8217;ll cover advanced tools for template designers, like if/else statements and for loops; as well as some features for programmers to play with.

</p><p><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/keep_sites_clean_with_smarty/feed/</wfw:commentRss>
        <slash:comments>0</slash:comments>

        
    </item>
    
    <item>
        <title>Install and Use Cygwin</title>
        <link>http://www.webmonkey.com/2010/02/install_and_use_cygwin/</link>
        <comments>http://www.webmonkey.com/2010/02/install_and_use_cygwin/#comments</comments>
        <pubDate>Tue, 16 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=852</guid>
        		<category><![CDATA[Software]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[Windows provides a little command line utility called cmd.exe, but it has nothing close to the power of the Unix command line and its integrated free tools and applications. Fortunately, especially for addicts of the Unix way, there&#8217;s a way to use a lot of the Unix tools in a Windows environment. That way is [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --><p>Windows provides a little command line utility called <tt>cmd.exe</tt>, but it has nothing close to the power of the Unix command line and its integrated free tools and applications. Fortunately, especially for addicts of the Unix way, there&#8217;s a way to use a lot of the Unix tools in a Windows environment. That way is a free piece of software called Cygwin. Cygwin is a Unix-style command line for Windows; it comes with a selection of <a href="http://cygwin.com/packages/" class="external text" title="http://cygwin.com/packages/" rel="nofollow">hundreds of free tools</a> as well.

</p><p><br />

</p>



<a name="Installing_Cygwin"></a><h2> <span class="mw-headline">Installing Cygwin</span></h2>

<p>Installation is shockingly easy. Download <a href="http://www.cygwin.com/setup.exe" class="external free" title="http://www.cygwin.com/setup.exe" rel="nofollow">http://www.cygwin.com/setup.exe</a> onto your Windows computer, and then run the program.

</p><p>The setup utility walks you through installing Cygwin. When prompted to choose a download source, select &#8220;Install from Internet&#8221;. Choose a reasonably local download mirror from the choices it offers.

</p><p>Next, it&#8217;s time to choose which software packages you want included in your Cygwin installation. Choosing All is the easiest option, and it means you won&#8217;t get that annoying &#8220;command not found&#8221; error often &#8212; but it takes a long time to download everything, and it takes a lot of drive space. The packages are broken down into categories &#8212; Database, Devel, Editors &#8212; for ease of picking and choosing if you want to grab just the packages you need. I recommend blowing up the window to full screen for this process.

</p><p>After you&#8217;ve picked some or All and clicked the Next button, all those packages will download from the mirror site and be installed on your machine. You can watch a captivating progress bar while this happens.

</p><p>Finally you should see the &#8220;Installation Complete&#8221; message.

</p><p>If, later on, you realize that now you want a package you opted not to install the first time around, just run <tt>setup.exe</tt> again and choose it. It&#8217;ll be added to your Cygwin setup, and any updates will be downloaded too, while your existing installation is left intact.

</p><span id="more-852"></span>

<a name="X_and_Rxvt"></a><h2> <span class="mw-headline">X and Rxvt</span></h2>



<p>The X Window System is available via xorg.  To get it installed, install the X-startup-scripts package from the X11 category.  Then, the batch file C:cygwinusrX11R6binstartxwin.bat will start Xorg for you, indicated by a black X in the system tray.  The X server will sit around waiting for X applications to use your display.

</p><p>The default Cygwin shell window may be a little cumbersome sometimes, so the rxvt program provides a window that is more compatible with traditional Unix/Linux programs, especially those that might be running remotely.  To give yourself a convenient Rxvt icon, make sure that the Rxvt package is installed (categorized under Shells), and create a windows shortcut to C:CygwinbinRun.exe.  Then edit the shortcut&#8217;s properties so the Target reads:

<code>C:cygwinbinrun.exe /bin/rxvt -display&nbsp;:0.0 -e bash -login</code>

(If you decide not to use X, then leave off the -display&nbsp;:0.0, but some graphical programs may not work.)

</p>

<a name="Using_Cygwin"></a><h2> <span class="mw-headline">Using Cygwin</span></h2>

<p>Launch Cygwin in the way you ordinarily launch programs, be that the Start menu or a shortcut system. It&#8217;ll bring up a terminal window running the <a href="http://www.gnu.org/software/bash/manual/" class="external text" title="http://www.gnu.org/software/bash/manual/" rel="nofollow">bash</a> shell. Using bash, just a few keystrokes can accomplish things it takes unassisted Windows megabytes of shareware to do.

</p><p>There&#8217;s a little bit of rethinking necessary if you&#8217;re used to Windows&#8217; conventions. The C: drive is referred to as /cygdrive/c/ and so forth; your Desktop is at /cygdrive/c/Documents and Settings/User Name/Desktop

</p><p>To create a whole series of nested directories:



</p>

<pre class="brush: js">mkdir -p /cygdrive/c/Documents and Settings/User Name/My Documents/One/New/Directory/After/Another

</pre>

<p><br />

(note that you need to put a  before space characters in directory and file names)

</p><p>You can rename multiple files, too. Say you have a whole folder called mypics full of JPEGs with names like <tt>IMG_0203.JPG</tt>, and you&#8217;d like to add the prefix &#8220;vacation2006&#8243; to each file:

</p>

<pre class="brush: js">for i in mypics/IMG*.JPG; do mv $i vacation2006-$i; done

</pre>

<p><br />

To remove all empty files and folders from a directory:

</p>

<pre class="brush: js">find . -empty -maxdepth=1 -print0 | xargs -0 rm -rf

</pre><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/install_and_use_cygwin/feed/</wfw:commentRss>
        <slash:comments>1</slash:comments>

        
    </item>
    
    <item>
        <title>Get Started With JQuery</title>
        <link>http://www.webmonkey.com/2010/02/get_started_with_jquery/</link>
        <comments>http://www.webmonkey.com/2010/02/get_started_with_jquery/#comments</comments>
        <pubDate>Tue, 16 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=1000</guid>
        		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[Programming with JavaScript used to be hard. Just look at all the JavaScript tutorials written by our Webmonkeys. Over the years we&#8217;ve done what we can to help you make sense of JavaScript. Now we&#8217;re being helped out by JavaScript frameworks, like JQuery, Prototype and Moo Tools. These web frameworks sit on top of JavaScript [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --><p>Programming with JavaScript used to be hard. Just look at <a href="/2010/02/tag/programming/javascript" class="external text" title="/2010/02/tag/programming/javascript" rel="nofollow">all the JavaScript tutorials</a> written by our Webmonkeys. Over the years we&#8217;ve done what we can to help you make sense of JavaScript.

</p><p>Now we&#8217;re being helped out by JavaScript frameworks, like JQuery, Prototype and Moo Tools. These web frameworks sit on top of JavaScript and make some common tasks a whole lot easier. When you write in JQuery, as you will in this tutorial, you&#8217;re still writing JavaScript, but what used to be 50 lines may now be one or two. JQuery&#8217;s slogan is &#8220;write less, do more,&#8221; and it lives up to that promise.

</p><p>In this tutorial, I&#8217;ll introduce you to a new way to write JavaScript: the easy, JQuery way. We&#8217;ll retrieve multiple objects in a single line, add CSS classes and make things magically disappear. At the end, you&#8217;ll be able to create an expandable Frequently Asked Questions template, where users can click a question and the answer will appear below.

</p><p>You don&#8217;t have to be a pro to master JQuery (although going through Webmonkey&#8217;s <a href="/2010/02/tag/programming/javascript" class="external text" title="/2010/02/tag/programming/javascript" rel="nofollow">JavaScript tutorials</a> helps). Even if you&#8217;re new to JavaScript, you&#8217;ll want to read on and see what JQuery can do for you.

</p><span id="more-1000"></span>

<table id="toc" class="toc" summary="Contents"><tbody><tr><td><div id="toctitle"><h2>Contents</h2> </div>

<ol>

<li><a href="#What_you.27ll_need">What you&#8217;ll need</a></li>

<li><a href="#Your_Basic_HTML_Sets_the_Stage">Your Basic HTML Sets the Stage</a></li>

<li><a href="#You_Can_Get_Anything_With_JQuery">You Can Get Anything With JQuery</a>



<ol>

<li><a href="#Get_An_Object_By_ID">Get An Object By ID</a></li>

<li><a href="#Get_Objects_By_Class">Get Objects By Class</a></li>

<li><a href="#Get_Objects_By_Tag">Get Objects By Tag</a></li>

<li><a href="#Filtering_Objects">Filtering Objects</a></li>



</ol>

</li>

<li><a href="#Change_Things_Up_With_JQuery">Change Things Up With JQuery</a>

<ol>

<li><a href="#Change_CSS_Classes">Change CSS Classes</a></li>

<li><a href="#Change_An_Object.27s_Inner_Text">Change An Object&#8217;s Inner Text</a></li>

<li><a href="#Change_Your_Appearances:_Show_and_Hide">Change Your Appearances: Show and Hide</a></li>



</ol>

</li>

<li><a href="#Create_An_Expandable_FAQ_With_JQuery">Create An Expandable FAQ With JQuery</a>

<ol>

<li><a href="#Set_Up_The_HTML">Set Up The HTML</a></li>

<li><a href="#JQuery.27s_.22onLoad:_the_ready.28.29.22_Function">JQuery&#8217;s &#8220;onLoad: the ready()&#8221; Function</a></li>

<li><a href="#Make_Your_Questions_Clickable">Make Your Questions Clickable</a></li>



<li><a href="#Add_.22Expand_All.22_Option_to_FAQ">Add &#8220;Expand All&#8221; Option to FAQ</a></li>

</ol>

</li>

<li><a href="#Become_a_JQuery_Master">Become a JQuery Master</a></li>

</ol>





</td></tr></tbody></table>

<a name="What_you.27ll_need"></a><h2> <span class="mw-headline"> What you&#8217;ll need </span></h2>



<ul><li> Good understanding of HTML and CSS

</li><li> Very basic knowledge of JavaScript

</li><li> Willingness to have your mind blown away

</li></ul>

<p><br />

</p>

<a name="Your_Basic_HTML_Sets_the_Stage"></a><h2> <span class="mw-headline">Your Basic HTML Sets the Stage</span></h2>

<p>You should be excited to write some JQuery. I know I am. First, we have to get the HTML ready to go. Copy the code below into an empty document:

</p>

<pre class="brush: js">&lt;html&gt;

&lt;head&gt;



	&lt;title&gt;Testing JQuery&lt;/title&gt;

	&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"&gt;&lt;/script&gt;

	&lt;style&gt;

		// CSS goes here

	&lt;/style&gt;

	&lt;script&gt;



		// JavaScript goes here

	&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;



&lt;/body&gt;

&lt;/html&gt;

</pre>

<p>Opened in a browser, the above is blank. That&#8217;s because it&#8217;s only a starting place for the code we&#8217;ll be adding into it.

</p><p>Before we start writing code, I want to point out something interesting about one of the script tags. The one above the style tag and below the title tag calls to an external JavaScript file. That&#8217;s normal, but the URL where the <code>src</code> leads is not.



</p><p>Most shared JavaScript code requires you to download it and put it on your server. You can do that with JQuery if you want (<a href="http://docs.jquery.com/Downloading_jQuery" class="external text" title="http://docs.jquery.com/Downloading_jQuery" rel="nofollow">download JQuery</a>, if you&#8217;d like). However, you can piggyback off of Google&#8217;s servers by accessing the version stored on the Google Ajax APIs site, like we did in the example above.

</p><p>Another note about scripts. The code we create in this tutorial will be written within one main HTML file. Normally, we&#8217;d link to an external JavaScript file instead. The same goes for our CSS, which we&#8217;ll put between the style tags. I&#8217;m including scripts and styles inline because I want to make the code easy to read and manipulate.

</p><p>Before we move on to the code, let&#8217;s set up the HTML and CSS we&#8217;ll be using in the next section.

</p><p>Add this between the body tags:

</p>

<pre class="brush: js">&lt;div id="container"&gt;

&lt;span&gt;SPAN&lt;br /&gt;No id&lt;/br /&gt;No class&lt;/span&gt;



&lt;span class="test" id="second"&gt;SPAN&lt;br /&gt;id="second"&lt;br /&gt;class "test"&lt;/span&gt;

&lt;div class="test"&gt;DIV&lt;br /&gt;No id&lt;br /&gt;class "test"&lt;/div&gt;

&lt;/div&gt;



&lt;p&gt;

&lt;strong&gt;Toggles:&lt;/strong&gt;

&lt;/p&gt;

</pre>

<p>And put this between the style tags:

</p>

<pre class="brush: js">#container div, #container span

{

	width: 150px;

	height: 150px;

	display: block;

	float: left;

	border: 1px solid black;

}

#container .highlight

{

	border: 3px solid orange;

}

p

{

	clear: left;

}

p input

{

	display: block;

}

</pre>

<p>Reload the HTML file you created and you&#8217;ll see a few squares on your screen. Yay! Now let&#8217;s JQuery-ify the sucker.

</p>

<a name="You_Can_Get_Anything_With_JQuery"></a><h2> <span class="mw-headline">You Can Get Anything With JQuery</span></h2>



<p>One of the best features of JQuery is its tools for grabbing objects from a page. Most of this happens through the dollar sign function, with CSS-like commands. In this section, I&#8217;ll show some of the common ways of selecting objects, as well as filtering a list of objects down to just the few you want.

</p><p>To follow along, you can download the <a href="http://www.wired.com/wired/archive/webmonkey/JQuery/basic.html" class="external text" title="http://www.wired.com/wired/archive/webmonkey/JQuery/basic.html" rel="nofollow">basic HTML file</a> or copy and paste it from Webmonkey&#8217;s <a href="/2010/02/Basic_JQuery_HTML" title="CodeLibrary:Basic JQuery HTML"> code library</a>. I&#8217;ll also give you the code to add to this starting template at each step. By the end of this tutorial, you should have written a decent JQuery-powered expandable FAQ template.

</p><p><br />

</p>

<a name="Get_An_Object_By_ID"></a><h3> <span class="mw-headline">Get An Object By ID</span></h3>

<p>Identifying a single object by ID is similar to setting styles in CSS. Use the dollar sign function and pass the ID with a pound sign in front of it. Like this: <code>$("#second")</code>

</p><p>To test this out in our example HTML file, add the following underneath the &#8220;toggles&#8221; section near the bottom of the HTML:



</p>

<pre class="brush: js">&lt;input type="button" onClick="javascript:test_byid();" value="id='second'" /&gt;

</pre>

<p>This line adds a button to the page that, when clicked, calls the <code>test_byid()</code> function. Where is that function? We need to add it between the script tags in your example HTML file:

</p>

<pre class="brush: js">function test_byid()

{

	$("#second").toggleClass("highlight");

}

</pre>

<p>Reload the file and click the new button. The second span (the one with <code>id="second"</code>) highlights.

</p><p><br />

</p>

<a name="Get_Objects_By_Class"></a><h3> <span class="mw-headline">Get Objects By Class</span></h3>



<p>Grabbing all objects of a certain class also uses similar CSS commands and the dollar sign function. Check it: <code>$(".test")</code>

</p><p>Let&#8217;s test it in our example HTML file. Here&#8217;s the code for the testing button:

</p>

<pre class="brush: js">&lt;input type="button" onClick="javascript:test_byclass();" value="class='test'" /&gt;

</pre>

<p>And now the JavaScript, which you should paste below the previous function:

</p>

<pre class="brush: js">function test_byclass()

{

	$(".test").toggleClass("highlight");

}

</pre>

<p>Reload the file and click the new button. The two right boxes (the ones with class=&#8221;test&#8221;) highlight.

</p><p><br />

</p>

<a name="Get_Objects_By_Tag"></a><h3> <span class="mw-headline">Get Objects By Tag</span></h3>



<p>If you want all objects of a particular tag, you just need to pass the name of the tag to the dollar sign function. This is also similar to CSS: <code>$("span")</code>

</p><p>In our example HTML file, paste this code for the button to test getting objects by tag:

</p>

<pre class="brush: js">&lt;input type="button" onClick="javascript:test_bytag();" value="tag is 'span'" /&gt;

</pre>

<p>And the JavaScript function:

</p>

<pre class="brush: js">function test_bytag()

{

	$("span").toggleClass("highlight");

}

</pre>

<p>Reload and click the new button, you&#8217;ll see the two left boxes (the ones that are span tags) highlight.

</p><p><br />

</p>

<a name="Filtering_Objects"></a><h3> <span class="mw-headline">Filtering Objects</span></h3>



<p>JQuery has a whole lot of filters for finding only the items you want from a selection. We&#8217;ll filter the final example from the previous section, where we retrieved all the span tags.

</p><p>Here&#8217;s the HTML for the two filtering buttons:

</p>

<pre class="brush: js">&lt;input type="button" onClick="test_byfirstfilter();" value="the first object where tag is 'span'" /&gt;

&lt;input type="button" onClick="test_bynotfilter();" value="tag is 'span', but id is not 'second'" /&gt;

</pre>

<p>And the script for both of these filters:

</p>

<pre class="brush: js">function test_byfirstfilter()

{

	$("span:first").toggleClass("highlight");

}

function test_bynotfilter()

{

	$("span:not(#second)").toggleClass("highlight");

}

</pre>

<p>Filters all start with a colon. In these examples, we use the <b>:first</b> and <b>:not</b> filters.



</p><p>The&nbsp;:first filter returns only the first item in the collection. Where <code>$("span")</code> will return all the span tag objects, <code>$("span:first")</code> will return only the first span.

</p><p>Click the first of our two new buttons and we&#8217;ll see the first span highlights. Success!

</p><p>The second filter shows how to remove specific rules from being selected. This filter accepts a second set of CSS commands inside parentheses. The full JQuery command, <code>$("span:not(#second)")</code> will first grab all the spans, but then filter out any that have <code>id="second"</code>.

</p><p>Click the second of our two new buttons and we&#8217;ll see the first span highlights again. It is the only span that does not contain the &#8220;second&#8221; id.

</p><p>If you&#8217;ve been following along, your web page should now look something like this:



</p><p><iframe src="http://www.wired.com/wired/archive/webmonkey/JQuery/basic.html" name="Page1" align="middle" frameborder="0" height="500" scrolling="yes" width="600"></iframe>

</p><p>You can get quite a bit more complicated with the JQuery filters. There is a whole <a href="http://docs.jquery.com/Selectors" class="external text" title="http://docs.jquery.com/Selectors" rel="nofollow">list of filters</a> on the JQuery site.  See how to select every other element (i.e., for zebra striped tables), elements containing specific text, and more.

</p><p>Or, if you&#8217;re all filtered out, move on to the next section. I&#8217;ll show you how to actually /do something/ with the objects we&#8217;re selecting with JQuery.

</p>

<a name="Change_Things_Up_With_JQuery"></a><h2> <span class="mw-headline">Change Things Up With JQuery</span></h2>

<p>So far we&#8217;ve just selected objects on the page using JQuery. Now it&#8217;s time to do something with them. For this section, I&#8217;m removing all my previous HTML buttons and script from my file. You can work on the same one, or also clean house a bit. Or, like before, you can follow along with ****[advanced.html this section's examples]**** in one file.

</p><p>There is an aspect to what I&#8217;ve shown so far that you&#8217;ve probably noticed: highlighting. It&#8217;s an example of what can be done with the results from a JQuery call. The first item below shows how it&#8217;s done, then I&#8217;ll get into some other ways to manipulate the objects on the page using JQuery.

</p><p><br />

</p>

<a name="Change_CSS_Classes"></a><h3> <span class="mw-headline">Change CSS Classes</span></h3>



<p>To alter the design of a site as a user interacts with it, you most likely want to add or remove CSS classes. JQuery makes it easy. In fact, every example so far has toggled the &#8220;highlight&#8221; class, which puts a 3 pixel orange border around our example boxes.

</p><p>Add this HTML button to your file:

</p>

<pre class="brush: js">&lt;input type="button" onClick="test_changeclass();" value="Change CSS class of id='second'" /&gt;

</pre>

<p>And this script:

</p>

<pre class="brush: js">function test_changeclass()

{

	$("#second").toggleClass("highlight");

}

</pre>

<p>The code is actually the same as the example to retrieve a particular ID. Here, we use the toggleClass function to tell JQuery which class to either add or remove. If the class is already there, it removes. Otherwise, it adds.

</p><p>We can also change the toggleClass function to be addClass or removeClass to perform those functions directly.

</p><p><br />

</p>

<a name="Change_An_Object.27s_Inner_Text"></a><h3> <span class="mw-headline">Change An Object&#8217;s Inner Text</span></h3>



<p>So far we&#8217;ve just made changes to how something looks. How about bigger changes? In this example, we&#8217;ll change the text inside some of the boxes using JQuery.

</p><p>To do this, we&#8217;ll use the <b>text</b> function. It takes a string of text as an argument, where we tell it the new text to use.

</p><p>Here&#8217;s the HTML code for our button:

</p>

<pre class="brush: js">&lt;input type="button" onClick="test_changetext();" value="Change text where class='test'" /&gt;

</pre>

<p>And the script:

</p>

<pre class="brush: js">function test_changetext()

{

	$(".test").text("over-riding text for these boxes");

}

</pre>

<p>We use JQuery to return all the objects from the page with class &#8220;test&#8221;, then replace their inner text with the new text.

</p><p>Reload your file, click the new button, and suddenly your right two boxes (the ones with <code>class="test"</code>) will have new content inside.



</p><p>The important thing to notice here is that JQuery made the change over multiple objects, but only required one line. If there had been 50 objects with class test, the code would have been the same. No looping code needed. JQuery does the hard work for us.

</p><p>You&#8217;re probably beginning to see the real power of JQuery. In the next section, I&#8217;ll start making stuff disappear. Then you&#8217;ll /know/ it&#8217;s magic.

</p><p><br />

</p>

<a name="Change_Your_Appearances:_Show_and_Hide"></a><h3> <span class="mw-headline">Change Your Appearances: Show and Hide</span></h3>

<p>Now for some real fun. We&#8217;re going to make boxes disappear. To do this, we&#8217;ll need the hide function. Let&#8217;s get straight to the code, first for the button:

</p>

<pre class="brush: js">&lt;input type="button" onClick="test_hiding();" value="Hide where id='second'" /&gt;

</pre>

<p>And then the script:

</p>

<pre class="brush: js">function test_hiding()

{

	$("#second").hide();

}

</pre>

<p>Reload the page, click the new button, and just like that, the box goes away. As you may have guessed, to get it to return, you&#8217;ll need to call <code>$("#second").show()</code>. Instead, let&#8217;s try toggling, since it may be a more popular method than using show and hide independently.



</p><p>The idea behind a show/hide toggle is that if an object is currently displayed on the page, it will disappear. If it&#8217;s invisible, it will reappear. Voila!

</p><p>Here is the button code:

</p>

<pre class="brush: js">&lt;input type="button" onClick="test_hidetoggling();" value="Toggle show/hide where id='second'" /&gt;

</pre>

<p>And the script:

</p>

<pre class="brush: js">function test_hidetoggling()

{

	$("#second").toggle();

}

</pre>

<p>If you&#8217;ve been following along, the end result should look something like this:

</p><p><iframe src="http://www.wired.com/wired/archive/webmonkey/JQuery/advanced.html" name="Page1" align="middle" frameborder="0" height="500" scrolling="yes" width="600"></iframe>

</p><p>Notice the code is virtually the same as the show code? Instead of calling the show function, we call the toggle function. All the work to determine whether something is viewable is done by JQuery.

</p><p>This example of toggling viewability will come in handy for the next section. I&#8217;m going to show you how to create an FAQ that only shows the questions until you click to expand the answers.

</p><p><br />

</p>



<a name="Create_An_Expandable_FAQ_With_JQuery"></a><h2> <span class="mw-headline">Create An Expandable FAQ With JQuery</span></h2>

<p>In this section, I&#8217;ll show an example project that you can start using in the real world right away. We&#8217;ll create an FAQ with questions and answers, then use JQuery to hide the answers and display one when the question is clicked.

</p><p>You can follow along piece by piece or <a href="http://www.wired.com/wired/archive/wired/archive/webmonkey/JQuery/faq.html" class="external text" title="http://www.wired.com/wired/archive/wired/archive/webmonkey/JQuery/faq.html" rel="nofollow">download the file</a> or copy and paste it from the <a href="/2010/02/FAQ_Template_Using_JQuery" title="CodeLibrary:FAQ Template Using JQuery"> code library</a>.

</p>

<a name="Set_Up_The_HTML"></a><h3> <span class="mw-headline">Set Up The HTML</span></h3>

<p>Start with the shell of an HTML file, like in previous examples. Then add this definition list between the body tags:

</p>



<pre class="brush: js">&lt;dl&gt;

	&lt;dt&gt;Question number one&lt;/dt&gt;

	&lt;dd&gt;Answer to first question&lt;/dd&gt;



	&lt;dt&gt;Question number two&lt;/dt&gt;



	&lt;dd&gt;Answer to second question&lt;/dd&gt;



	&lt;dt&gt;Question number three&lt;/dt&gt;

	&lt;dd&gt;Answer to third question&lt;/dd&gt;

&lt;/dl&gt;



</pre>

<p>A definition list (&lt;dl&gt; tag) is a semantic way to show questions and answers. JQuery doesn&#8217;t require this, but this simple markup does make things easier. Inside the definition list, we have questions as definition terms (&lt;dt&gt; tags) and the answers as definition descriptions (&lt;dd&gt; tags).

</p><p><br />

</p>

<a name="JQuery.27s_.22onLoad:_the_ready.28.29.22_Function"></a><h3> <span class="mw-headline">JQuery&#8217;s &#8220;onLoad: the ready()&#8221; Function</span></h3>

<p>When the FAQ page is first loaded, we want the definitions to be hidden, so that only the questions are viewable. To do this, we need to call some JavaScript when the page first loads. JQuery provides a <code>ready()</code> function to make this easy.



</p><p>Between the script tags near the top of your code, add this JavaScript:

</p>

<pre class="brush: js">$(document).ready(function(){

	$("dd").hide();

});

</pre>

<p>When the document is loaded, the browser will run an anonymous function. That function is declared inside the ready function. If you haven&#8217;t seen this before, it may look strange, but it&#8217;s part of the power of JavaScript and JQuery.

</p><p>Inside the new function, we currently have one call, which may look familiar from previous sections of this tutorial. We are using JQuery to retrieve all the dd tags, then we&#8217;re calling the <code>hide()</code> function to make them disappear temporarily.

</p><p>Reload your HTML file and you should now only see the questions list.

</p><p><br />

</p>

<a name="Make_Your_Questions_Clickable"></a><h3> <span class="mw-headline">Make Your Questions Clickable</span></h3>

<p>Now that we have successfully hidden the FAQ answers, we want to allow users to click questions in order to display the appropriate answer. In order to do this, we need to use JQuery to tell the browser that every <code>dt</code> tag can be clicked, then also tell the browser what to do when it&#8217;s clicked.



</p><p>Add this code to your ready() function, just below the hide command from the previous section:

</p>

<pre class="brush: js">$("dt").click(function(){

	$(this).next().toggle();

});

</pre>

<p>Here we grab every dt tag, then run the click command, which attaches an event to the dt. Inside the click event, we create an anonymous function (similar to our <code>ready()</code> function) to toggle the visibility of the answer within the <code>dd</code> tag.

</p><p>You may be asking, where do we reference the <code>dd</code> tag? We don&#8217;t. We let the power of JQuery and our semantic code do the work:

</p>

<ol><li> Reference the object that was clicked with <code>$(this)</code>



</li><li> Call the <code>next()</code> function on the clicked object to return the object that comes after it in our HTML code. In this case, that is our dd tag.

</li><li> Toggle the visability of the dd tag.

</li></ol>

<p>Now, with very little JavaScript code, we&#8217;ve created an expandable FAQ that you could implement today. An added bonus is that this code has easy upkeep. Add or remove questions to the list and it still works without needing to edit any JavaScript code.

</p><p>You could stop here, or you could add one more enhancement to the FAQ: the &#8220;expand all&#8221; link.

</p><p><br />

</p>

<a name="Add_.22Expand_All.22_Option_to_FAQ"></a><h3> <span class="mw-headline">Add &#8220;Expand All&#8221; Option to FAQ</span></h3>

<p>Some people hate expandable FAQs. These people may be no fun at parties, but that doesn&#8217;t mean we should deprive them of reading your Q&amp;A. Let&#8217;s provide a one click option to show all the answers.



</p><p>Above your definition list (<code>dl</code>), add a simple hyperlink:

</p>

<pre class="brush: js">&lt;a href="#" onclick="showall();" id="linkshowall"&gt;Expand all&lt;/a&gt;

</pre>

<p>Though there&#8217;s nothing but a pound sign as the URL for this link, the onclick event calls a function called <code>showall()</code>. Let&#8217;s create that function and use a simple JQuery statement:

</p>

<pre class="brush: js">function showall()

{

	$("dd").show();

}

</pre>

<p>You may notice that the call to show all the definition descriptions (<code>dd</code>) is similar to hiding. Yet, instead of calling the <code>hide()</code> function, we call the <code>show()</code> function.



</p><p>The end result should look like this:

</p><p><iframe src="http://www.wired.com/wired/archive/webmonkey/JQuery/faq.html" name="Page1" align="middle" frameborder="0" height="200" scrolling="yes" width="600"></iframe>

</p><p><br />

Now you&#8217;ve appeased the expandable FAQ haters and learned a tiny bit more JQuery. Where else can you go from here? Read on in the final section.

</p><p><br />

</p>

<a name="Become_a_JQuery_Master"></a><h2> <span class="mw-headline">Become a JQuery Master</span></h2>

<p>If you&#8217;ve made it this far in the tutorial, you have a good idea of the power JQuery has, while being easy to write. Hopefully you&#8217;re looking to learn even more JQuery and maybe even to become a JQuery master.

</p><p>The <a href="http://docs.jquery.com/" class="external text" title="http://docs.jquery.com/" rel="nofollow">JQuery docs</a> are a little difficult to browse around, but are a good reference. Now you have a little knowledge of the way JQuery is written, you may be able to figure out how to use more advanced functions and filters. Just about every item in the docs has an example if you click through to the detail page.

</p><p>Here are a few particular JQuery docs to check out:

</p>



<ul><li> <a href="http://docs.jquery.com/Selectors" class="external text" title="http://docs.jquery.com/Selectors" rel="nofollow">More ways to select objects</a> &#8211; You&#8217;ll be surprised at the ways you can retrieve just the objects you need with JQuery. The hierarchy stuff almost makes my brain explode, but it&#8217;s extremely powerful.

</li><li> <a href="http://docs.jquery.com/Manipulation" class="external text" title="http://docs.jquery.com/Manipulation" rel="nofollow">More ways to manipulate objects</a> &#8211; In addition to changing its text, you can completely remove, append, prepend, and wrap objects.

</li><li> <a href="http://docs.jquery.com/Traversing" class="external text" title="http://docs.jquery.com/Traversing" rel="nofollow">View child and sibling objects in many ways</a> &#8211; If you liked the next() function, there&#8217;s a lot more where that came from.

</li></ul><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/get_started_with_jquery/feed/</wfw:commentRss>
        <slash:comments>11</slash:comments>

        
    </item>
    
    <item>
        <title>Mulders Stylesheets Tutorial</title>
        <link>http://www.webmonkey.com/2010/02/mulders_stylesheets_tutorial/</link>
        <comments>http://www.webmonkey.com/2010/02/mulders_stylesheets_tutorial/#comments</comments>
        <pubDate>Tue, 16 Feb 2010 01:45:47 +0000</pubDate>

                <dc:creator>Webmonkey Staff</dc:creator>

        <guid isPermaLink="false">http://stag.wired.com/primate/?p=607</guid>
        		<category><![CDATA[CSS]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wiki]]></category>
        <description><![CDATA[Cascading stylesheets are a new-ish technology that promises to make the Web a better place by allowing you to control layout like never before, to make smaller, faster pages, and to easily maintain many pages at once. Steve Mulder, author of &#8220;Web Designer&#8217;s Guide to Stylesheets,&#8221; created this five-day stylesheets tutorial which — modesty aside [...]]]></description>

            <content:encoded><![CDATA[<!-- wpautop disabled --><p>Cascading stylesheets are a new-ish technology that promises to make the Web a better place by allowing you to control layout like never before, to make smaller, faster pages, and to easily maintain many pages at once.

</p><p>Steve Mulder, author of &#8220;Web Designer&#8217;s Guide to Stylesheets,&#8221; created this five-day stylesheets tutorial which — modesty aside — kicks butt.

</p><p>Your journey begins with a quick trip through the basics of cascading stylesheets — everything you have to know to get started quickly.

</p><span id="more-607"></span><p>Then begin exploring the stylesheets properties that make them more than cool, starting with fonts. Stylesheets is your tool for calling fonts by name, controlling text size, specifying all manner of bolds and italics, and adding special effects.

</p><p>Stylesheets give you lots of control over how characters, words, and lines can be spaced relative to one another. These CSS properties give you power over the space between words and letters, the leading (vertical spacing) between lines of text, the alignment of text, margins and padding, borders, and floating elements.

</p><p>Lesson four introduces color and images into the mix. These CSS properties enable you to apply colors to elements and to place images behind elements.

</p><p>In the final lesson, you&#8217;ll discover what many people believe to be the coolest thing about CSS: positioning and layering. Positioning text and images on a Web page with HTML is a pain in the butt (think table tags, invisible spacer GIFs, browser and platform variations). If you&#8217;re tired of these limitations, CSS will make you feel like a god.

</p><p>After you&#8217;re done here, you may want to bulk up your skills even further by taking <a href="/2010/02/JavaScript_Tutorial" title="Tutorial:JavaScript Tutorial">Tutorial:JavaScript Tutorial</a>.

</p><p>P.S. Mulder tells us he has no relation to the X-Files&#8217; Mulder. But that&#8217;s what he <i>would</i> say.



</p><p><span id="title_name_el" class="wm_hidden_meta_class" title="Mulder's Stylesheets Tutorial" style="visibility: hidden;"> <span id="page_path_el" class="wm_hidden_meta_class" title="http://www.wired.com/wired/webmonkey/stuff/Mulder/" style="visibility: hidden;"> <span id="author_el" class="wm_hidden_meta_class" title="mulder" style="visibility: hidden;"> <span id="creation_date_el" class="wm_hidden_meta_class" title="1999-09-16T24:00:00Z" style="visibility: hidden;"> </span></span></span></span>

</p>

<div id="series">

<div class="series_hdr">From the series</div>

<table style="background: rgb(229, 249, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" width="620">

<tbody><tr>

<td>

<p><strong class="selflink">Tutorial:Mulders Stylesheets Tutorial</strong><br />

<a href="/2010/02/Mulders_Stylesheets_Tutorial_-_Lesson_1" title="Tutorial:Mulders Stylesheets Tutorial - Lesson 1">Tutorial:Mulders Stylesheets Tutorial &#8211; Lesson 1</a><br />

<a href="/2010/02/Mulders_Stylesheets_Tutorial_-_Lesson_2" title="Tutorial:Mulders Stylesheets Tutorial - Lesson 2">Tutorial:Mulders Stylesheets Tutorial &#8211; Lesson 2</a><br />



<a href="/2010/02/Mulders_Stylesheets_Tutorial_-_Lesson_3" title="Tutorial:Mulders Stylesheets Tutorial - Lesson 3">Tutorial:Mulders Stylesheets Tutorial &#8211; Lesson 3</a><br />

<a href="/2010/02/Mulders_Stylesheets_Tutorial_-_Lesson_4" title="Tutorial:Mulders Stylesheets Tutorial - Lesson 4">Tutorial:Mulders Stylesheets Tutorial &#8211; Lesson 4</a><br />

<a href="/2010/02/Mulders_Stylesheets_Tutorial_-_Lesson_5" title="Tutorial:Mulders Stylesheets Tutorial - Lesson 5">Tutorial:Mulders Stylesheets Tutorial &#8211; Lesson 5</a><br />

</p>

</td></tr></tbody></table>

</div><div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/02/mulders_stylesheets_tutorial/feed/</wfw:commentRss>
        <slash:comments>2</slash:comments>

        
    </item>
    </channel>
</rss>