<?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>Design, Development, and Consulting</title>
	<atom:link href="http://netlumination.com/feed" rel="self" type="application/rss+xml" />
	<link>http://netlumination.com</link>
	<description>A web design, development, and consulting firm based in Portland, Oregon helping small businesseses and individuals.</description>
	<lastBuildDate>Sun, 19 Feb 2012 13:58:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Javascript Quizzes</title>
		<link>http://netlumination.com/blog/javascript-quizzes</link>
		<comments>http://netlumination.com/blog/javascript-quizzes#comments</comments>
		<pubDate>Sun, 05 Feb 2012 08:51:09 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1873</guid>
		<description><![CDATA[These are the Javascript quizes I&#8217;ve Tweeted and put up on jsFiddle: Important functionality on this page relies on Javascript. Please enable it if you want to see the content.]]></description>
			<content:encoded><![CDATA[<p>These are the Javascript quizes I&#8217;ve <a href="https://twitter.com/Peter_Ajtai">Tweeted</a> and put up on <a href="http://jsfiddle.net/user/pajtai/fiddles/">jsFiddle</a>:</p>
<p><span id="more-1873"></span></p>
<p><noscript>Important functionality on this page relies on Javascript. Please enable it if you want to see the content.</noscript></p>
<ul id="quizes">
</ul>
<p><script type="text/javascript">
(function() {
    var quizes = [],
        quizEl = document.getElementById("quizes"),
        i, ii,
        ellie, ellie2, ellie3, tags,
        a,
        message;
    quizes[1] = {"url":"http://jsfiddle.net/pajtai/5TZsw/show/","tags":["closures","references"]};
    quizes[2] = {"url":"http://jsfiddle.net/pajtai/6Shd9/show/","tags":["hoisting"]};
    quizes[3] = {"url":"http://jsfiddle.net/pajtai/yGmAf/show/","tags":["Date","timeouts","references","scope"]};
    quizes[4] = {"url":"http://jsfiddle.net/pajtai/Hm8YA/show/","tags":["length","arguments","Function"]};
    quizes[5] = {"url":"http://jsfiddle.net/pajtai/Ds8dn/show/","tags":["parseInt","radix"]};
    quizes[6] = {"url":"http://jsfiddle.net/pajtai/x6WkV/show/","tags":["inheritance","prototype"]};
    quizes[7] = {"url":"http://jsfiddle.net/pajtai/PSTja/show/","tags":["typeof","instanceof","constructor"]};
    quizes[8] = {"url":"http://jsfiddle.net/pajtai/k4PJm/show/","tags":["Booleans","Objects"]};
    quizes[9] = {"url":"http://jsfiddle.net/pajtai/U5uaS/show/","tags":["logic"]};
    quizes[10]= {"url":"http://jsfiddle.net/pajtai/YBXhD/show/","tags":["Arrays","length","addition","concatenation"]};
    quizes[11]= {"url":"http://jsfiddle.net/pajtai/66yrD/show/","tags":["setInterval","setTimeout","chaining"]};
    quizes[12]= {"url":"http://jsfiddle.net/pajtai/ejGX2/show/","tags":["variable assignment","arguments"]};
    quizes[13]= {"url":"http://jsfiddle.net/pajtai/fnTpG/show/","tags":["type conversion"]};
    quizes[14]= {"url":"http://jsfiddle.net/pajtai/eJ5ru/show/","tags":["scope", "this"]};
    for (i = 1; i < quizes.length; ++i) {
        ellie = document.createElement('li');
        a  = document.createElement('a');
        a.href = quizes[i].url;
        quizEl.appendChild(ellie);
        ellie.appendChild(a);
        a.appendChild(document.createTextNode("Quiz " + i));
        ellie2 = document.createElement('ul');
        ellie3 = document.createElement('li');
        ellie.appendChild(ellie2.appendChild(ellie3));
        tags = [];
        for (ii = 0; ii < quizes[i].tags.length; ++ii) {
            tags.push(quizes[i].tags[ii]);
        }
        ellie3.appendChild(document.createTextNode("Tags: " + tags.join(", ")));
    }
}());
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/javascript-quizzes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EBNFer</title>
		<link>http://netlumination.com/blog/ebnfer</link>
		<comments>http://netlumination.com/blog/ebnfer#comments</comments>
		<pubDate>Mon, 29 Aug 2011 05:08:49 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1844</guid>
		<description><![CDATA[EBNFer is a railroad diagram generator for WordPress. It lets you use WordPress shortcodes to parse and render Extended Backus–Naur Form diagrams. Download EBNFer from WordPress.org &#160; The EBNF parser and renderer is built off of the one created by Vincent Tscherter. Example usage: Shortcode attributes: title &#8211; Image title tag alt    - Image [...]]]></description>
			<content:encoded><![CDATA[<p>EBNFer is a railroad diagram generator for WordPress. It lets you use WordPress shortcodes to parse and render Extended Backus–Naur Form diagrams.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/ebnfer/">Download EBNFer from WordPress.org</a></strong></p>
<p>&nbsp;</p>
<p><span id="more-1844"></span>The EBNF parser and renderer is built off of the one created by <a href=" http://karmin.ch/ebnf/index">Vincent Tscherter</a>.</p>
<p>Example usage:</p>
<pre>[ebnf title="JSON RR Diagram"]
"JSON" {
object = "{" [ ( string ':' value ) { ',' string ':' value }  ] "}".
array = '['  [ value { ',' value } ] ']'.
}
[/ebnf]</pre>
<a href="http://netlumination.com/wp-content/plugins/ebnfer/images/7cc029e2f0697fc04122e42ad2b051b7.png"><img title="JSON RR Diagram" alt="EBNF Diagram"src="http://netlumination.com/wp-content/plugins/ebnfer/images/7cc029e2f0697fc04122e42ad2b051b7.png" /></a>
<p>Shortcode attributes:</p>
<ul>
<li>title &#8211; Image title tag</li>
<li>alt    - Image alt tag</li>
<li>link &#8211; Set to, &#8220;no&#8221; if you don&#8217;t want the image tag to link to the image</li>
</ul>
<div>Grammar use:</div>
<div>
<ul>
<li>Enclose optional title in quotes</li>
<li>Enclose all grammar rules in curly brackets { GRAMMAR }</li>
<li>End each grammar definition with a dot or semicolon RULE;</li>
<li>[...] means 0 or 1 times</li>
<li>{&#8230;} means 0 or many times</li>
<li>| means OR</li>
<li>Group things with parentheses.</li>
</ul>
</div>
<a href="http://netlumination.com/wp-content/plugins/ebnfer/images/2eab6741448eb8a8140d0075e61a69e1.png"><img alt="EBNF Diagram"src="http://netlumination.com/wp-content/plugins/ebnfer/images/2eab6741448eb8a8140d0075e61a69e1.png" /></a>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/ebnfer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PluGeSHin</title>
		<link>http://netlumination.com/blog/plugeshin</link>
		<comments>http://netlumination.com/blog/plugeshin#comments</comments>
		<pubDate>Mon, 15 Aug 2011 03:03:32 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1529</guid>
		<description><![CDATA[A WordPress Plugin for GeSHi Description PluGeSHin is a WordPress plugin by Peter Ajtai that lets you use the syntax highlighting of  GeSHi through WordPress shortcodes. You can download PluGeSHin and read about it over at WordPress.org. This page has samples of PluGeSHin in action. Highlighting with the default language (JS in my case) and [...]]]></description>
			<content:encoded><![CDATA[<h2>A WordPress Plugin for GeSHi</h2>
<h3><a name="description"></a>Description</h3>
<p><a href="http://netlumination.com/blog/plugeshin">PluGeSHin</a> is a <a href="http://wordpress.org/">WordPress</a> plugin by Peter Ajtai that lets you use the syntax highlighting of  <a href="http://qbnz.com/highlighter/">GeSHi</a> through WordPress <a href="http://codex.wordpress.org/Shortcode_API">shortcodes</a>.</p>
<p>You can <a href="http://wordpress.org/extend/plugins/plugeshin/">download PluGeSHin and read about it over at WordPress.org</a>.</p>
<p>This page has samples of PluGeSHin in action.</p>
<p><span id="more-1529"></span></p>
<p><strong>Highlighting with the default language (JS in my case) and default setting for line numbers showing:</strong></p>
<p><code>[geshi]CODE[/geshi]</code></p>
<pre class="javascript PluGeSHin"><span class="kw2">var</span> toggle <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span>theId<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="kw2">var</span> ellie <span class="sy0">=</span> document.<span class="me1">getElementById</span><span class="br0">&#40;</span>theId<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#40;</span>ellie.<span class="me1">style</span>.<span class="me1">display</span>   <span class="sy0">!==</span> <span class="st0">'none'</span> <span class="sy0">?</span>
         ellie.<span class="me1">style</span>.<span class="me1">display</span> <span class="sy0">=</span> <span class="st0">'none'</span> <span class="sy0">:</span>
         ellie.<span class="me1">style</span>.<span class="me1">display</span> <span class="sy0">=</span> <span class="st0">'block'</span>  <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<p><strong>Highlighting PHP without line numbers:</strong></p>
<p><code>[geshi lang="php" nums="0"]CODE[/geshi]</code></p>
<pre class="php PluGeSHin"><span class="kw2">&lt;?php</span>
<span class="kw2">class</span> SumOfPower <span class="br0">&#123;</span>
    <span class="kw2">function</span> __construct <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">// Start Timer</span>
        <span class="re0">$Timer1</span> <span class="sy0">=</span> <span class="kw2">new</span> CalcTimer<span class="sy0">;</span>
        <span class="re0">$Timer1</span> <span class="sy0">-&gt;</span> <span class="me1">StartTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="re0">$number</span> <span class="sy0">=</span> <a target="_self" href="http://www.php.net/sprintf"><span class="kw3">sprintf</span></a><span class="br0">&#40;</span> <a target="_self" href="http://www.php.net/number_format"><span class="kw3">number_format</span></a><span class="br0">&#40;</span><a target="_self" href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="nu0">2</span><span class="sy0">,</span><span class="nu0">1000</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$count</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> <span class="re0">$count</span> <span class="sy0">&lt;</span> <a target="_self" href="http://www.php.net/strlen"><span class="kw3">strlen</span></a><span class="br0">&#40;</span><span class="re0">$number</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="re0">$count</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="re0">$digit</span><span class="sy0">+=</span><span class="re0">$number</span><span class="br0">&#91;</span><span class="re0">$count</span><span class="br0">&#93;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
        <span class="kw1">echo</span> <span class="st0">&quot;The sum is <span class="es4">$digit</span>.&lt;br/&gt;&quot;</span><span class="sy0">;</span>
        <span class="co1">// Stop Timer</span>
        <span class="re0">$Timer1</span> <span class="sy0">-&gt;</span> <span class="me1">StopTimer</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
<span class="sy1">?&gt;</span></pre>
<p><strong>Highlighting C++ with line numbers, starting at line 37 and drawing attention to the fourth and 13th lines:</strong></p>
<p><code>[geshi lang="cpp" start="37" nums="1" highlight="4,13"]CODE[/geshi]</code></p>
<pre class="cpp PluGeSHin"><ol start="37"><li class="li1"><div class="de1"><span class="co2">#include &lt;iostream&gt;</span></div></li><li class="li1"><div class="de1"><span class="co2">#include &lt;string&gt;</span></div></li><li class="li1"><div class="de1"><span class="co2">#include &lt;sstream&gt;</span></div></li><li class="li1 ln-xtra"><div class="de1"><span class="co2">#include &lt;algorithm&gt;</span></div></li><li class="li1"><div class="de1"><span class="co2">#include &lt;iterator&gt;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="kw2">using</span> <span class="kw2">namespace</span> std<span class="sy4">;</span></div></li><li class="li1"><div class="de1">    string sentence <span class="sy1">=</span> <span class="st0">&quot;où chante une rivière&quot;</span><span class="sy4">;</span></div></li><li class="li1"><div class="de1">    istringstream iss<span class="br0">&#40;</span>sentence<span class="br0">&#41;</span><span class="sy4">;</span></div></li><li class="li1"><div class="de1">    copy<span class="br0">&#40;</span>istream_iterator<span class="sy1">&lt;</span>string<span class="sy1">&gt;</span><span class="br0">&#40;</span>iss<span class="br0">&#41;</span>,</div></li><li class="li1"><div class="de1">             istream_iterator<span class="sy1">&lt;</span>string<span class="sy1">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>,</div></li><li class="li1 ln-xtra"><div class="de1">             ostream_iterator<span class="sy1">&lt;</span>string<span class="sy1">&gt;</span><span class="br0">&#40;</span><span class="kw3">cout</span>, <span class="st0">&quot;<span class="es1">\n</span>&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy4">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li></ol></pre>
<p>Opening documentation links in a new tab:</p>
<p><code>[geshi lang="php" target="_blank"]CODE[/geshi]</code></p>
<pre class="php PluGeSHin"><span class="kw2">&lt;?php</span>
    <span class="re0">$string</span> <span class="sy0">=</span>
        <span class="st0">&quot;July 1, 2000 is on a &quot;</span> <span class="sy0">.</span>
        <a target="_blank" href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;l&quot;</span><span class="sy0">,</span> <a target="_blank" href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">7</span><span class="sy0">,</span> <span class="nu0">1</span><span class="sy0">,</span> <span class="nu0">2000</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/plugeshin/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Visibility Toggling with jQuery</title>
		<link>http://netlumination.com/blog/visibility-toggling-with-jquery</link>
		<comments>http://netlumination.com/blog/visibility-toggling-with-jquery#comments</comments>
		<pubDate>Mon, 16 Aug 2010 22:10:18 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[toggling]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1361</guid>
		<description><![CDATA[User interface design often makes use of showing and hiding blocks of content. It focuses one&#8217;s attention to the right thing, and it&#8217;s fun to do with jQuery. I&#8217;ll show you how to toggle the visibility on a group of selected elements. I&#8217;ll build up from a simple case to the more complicated ultimate goal. [...]]]></description>
			<content:encoded><![CDATA[<p>User interface design often makes use of showing and hiding blocks of content. It focuses one&#8217;s attention to the right thing, and it&#8217;s fun to do with <a href="http://jquery.com/">jQuery</a>.</p>
<p>I&#8217;ll show you how to toggle the visibility on a group of selected elements. I&#8217;ll build up from a simple case to the more complicated ultimate goal.</p>
<p><span id="more-1361"></span></p>
<p>First, whenever you&#8217;re working with jQuery and Javascript, you should probably get your references ready. For online references there&#8217;s the<a href="http://docs.jquery.com/Main_Page"> jQuery documentation</a> (which is easier to search with Google than with the site search, I find) and the <a href="https://developer.mozilla.org/en/javascript">Mozilla Development Center Javascript reference</a> among others. A very nice site to test, store, and share your jQuery snippets is <a href="http://jsfiddle.net/">jsFiddle</a>.</p>
<p>Ok, let&#8217;s get started. First let&#8217;s toggle the visibility of an element with jQuery using <a href="http://api.jquery.com/toggle/">.toggle()</a>. Since we&#8217;re talking about user interfaces, we&#8217;ll probably trigger the toggle with an action, let&#8217;s say a <a href="http://api.jquery.com/click/">.click()</a>:</p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="co1">// Toggle the visibility of all divs when one is clicked.</span>
    $<span class="br0">&#40;</span><span class="st0">&quot;input&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        $<span class="br0">&#40;</span><span class="st0">&quot;div&quot;</span><span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p><a href="http://jsfiddle.net/QXZ7p/">jsFiddle example</a></p>
<p>The code above will toggle the visibility of all the divs on a page if an input button is pressed.  The way this works is that after the document is ready, an event handler is bound to all the &lt;input&gt; elements. The handler waits for the user to click it. If clicked jQuery selects all the divs on the page and reverses their visibility. If they were invisible they become visible and vica versa.</p>
<p>Well, this was just to give you a tast of .toggle(), since the above example is pretty crude. Usually you want more control over which divs appear and disappear. In fact, an often trick part of visibility toggling in jQuery is to make sure each toggling button is linked uniquely to one block of content. You also want to ensure that when a block of content appears, all the other similar blocks of content disappears.</p>
<p>I&#8217;ll show you two methods of making sure that each time only one block of content appears, while all the other blocks of content disappears. The first method will only work if all the content blocks are siblings in the DOM. This will often be the case, since we&#8217;ll usually be dealing with semantically related chunks of content. The second way will be a little trickier but more flexible.</p>
<p>But before we start discussing siblings, let&#8217;s make sure we can toggle one specific div with one particular button. There&#8217;s many ways of doing this. I&#8217;ll show you how to use individual but related ids for the buttons and the content divs. Each button will have a name like, &#8220;block-x&#8221; where &#8220;x&#8221; is a number, and it&#8217;ll have a corresponding content block with the id &#8220;block-x-content&#8221;. Now if we have 3 content blocks, we could write one functions to control each block, for a total of 3 functions, but it&#8217;s more convenient and maintainable to generalize. We&#8217;re going to use input buttons with class &#8220;.toggler&#8221; to toggle the divs. You, of course, don&#8217;t have to use buttons, you can use other divs, or images, or whatever your little heart desires. So, so far we have:</p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
      <span class="co1">// Toggle the visibility of all divs when one is clicked.</span>
    $<span class="br0">&#40;</span><span class="st0">&quot;input.toggler&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        $<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p><a href="http://jsfiddle.net/N4PDK/">jsFiddle example</a></p>
<p>The most complex part is the line with the toggle. The previous line simply binds an click event handler to all input elements with a &#8220;toggler&#8221; class. The function that is triggered in case of a click is an anonymous function that toggles one div. To see witch div gets toggled we&#8217;ll look more closely at &#8220;$(&#8220;#&#8221; + $(this).attr(&#8220;id&#8221;) + &#8220;-content&#8221; )&#8221; . The part inside the parentheses is simply a jQuery selector string. The string starts with a literal &#8220;#&#8221;, so we know that an element with a certain ID is getting toggled. The &#8220;#&#8221; is followed by the &#8220;ID&#8221; attribute of the element that was clicked. So far we have something like $(&#8220;#block-x&#8221;). This by itself would make the buttons disappear. But we know that each button has a corresponding content block. This block is selected by concatenating &#8220;-content&#8221; to the previous to give us a toggling of $(&#8220;#block-x-content&#8221;). Where is the number in the ID attribute of the INPUT button we clicked. Notice how the visibility of each DIV is kept track of separately. .toggle() is doing all the hard work for us.</p>
<p>Well, we&#8217;re approaching what we want. The previous example is okay, in that it let&#8217;s us toggle things, but it doesn&#8217;t really feel like we&#8217;re concentrating the attention of the user to one pertinent block of information. To achieve that end, we must make all the other divs invisible when we make one div visible.</p>
<p>We only have to change one line to achieve this. We&#8217;ll go from:</p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p>to:</p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span>.<span class="me1">toggle</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">siblings</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">hide</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p>Notice how I chained the methods .siblings() and .hide() onto the previous line. This means that after toggling our content block, we&#8217;ll select the DOM siblings of that block and make them invisible. This means you have to make sure you&#8217;ve thought through your HTML. The easy way to do this is to nest all the content divs into a parent div, or if it makes sense, maybe to have content LIs in a parent UL or OL.</p>
<p>One final change is that you may not want the content to disappear if a button is pressed twice, so we&#8217;ll switch out .toggle() with .show() to give:<span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">​</span></p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
      <span class="co1">// Toggle the visibility of all divs when one is clicked.</span>
    $<span class="br0">&#40;</span><span class="st0">&quot;input.toggler&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        $<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span>.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">siblings</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">hide</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
​</pre>
<p><a href="http://jsfiddle.net/NeVDs/">jsFiddle example</a></p>
<p>But what if our content DIVs aren&#8217;t siblings? They usually should be, just because of the way information is structured on an HTML page, but we really don&#8217;t want to count on that. We want the flexibility to toggle any set of elements we want.</p>
<p>To toggle any set of elements we want, all we have to do is create jQuery set of the elements and use .not() in combination with that. I&#8217;ll show you how.</p>
<p>First, let&#8217;s say that we have 3 content divs. Let&#8217;s select all of them with jQuery:</p>
<pre class="javascript PluGeSHin"><span class="kw2">var</span> theDivs <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">&quot;#block-1-content, #block-2-content, #block-3-content);</span></pre>
<p>So, now theDivs is a jQuery selection of out content DIVs, let&#8217;s use that in combination with our click handler and .not() to toggle the appropriate content divs. Except, now I&#8217;m going to use an unordered list, so our content will be in LIs. If we&#8217;re dealing with unordered lists, we could easy have a situation where all the individual content LIs are not siblings of each other.</p>
<p>To show the corresponding content LI of a button, we&#8217;ll still use:</p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span>.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p>But now we can&#8217;t simply make the siblings disappear. Instead we&#8217;ll make everything from our jQuery slection &#8220;theDivs&#8221; that isn&#8217;t the corresponding content LI vanish. Like this:</p>
<pre class="javascript PluGeSHin">theDivs.<span class="me1">not</span><span class="br0">&#40;</span> $<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span>.<span class="me1">hide</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p>And that&#8217;s it! You can of course replace the .show() and .hide() methods with fancier animations like .slideDown() and .slideUp(), but overall we have a relatively simple to implement, generalizable way of toggling the visibility of a group of content divs. The full code will look something like this:</p>
<pre class="javascript PluGeSHin">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
      <span class="co1">// Create a selection of the content divs of interest</span>
    <span class="kw2">var</span> theDivs <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">&quot;#block-1-content, #block-2-content, #block-3-content&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="co1">// Toggle the visibility of all divs when one is clicked.</span>
    $<span class="br0">&#40;</span><span class="st0">&quot;input.toggler&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
        $<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span>.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        theDivs.<span class="me1">not</span><span class="br0">&#40;</span> $<span class="br0">&#40;</span> <span class="st0">&quot;#&quot;</span> <span class="sy0">+</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;-content&quot;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span>.<span class="me1">hide</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>​</pre>
<p><a href="http://jsfiddle.net/NNLzj/">jsFiddle example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/visibility-toggling-with-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Visualization</title>
		<link>http://netlumination.com/blog/data-visualization</link>
		<comments>http://netlumination.com/blog/data-visualization#comments</comments>
		<pubDate>Fri, 30 Jul 2010 01:37:18 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Zany]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1345</guid>
		<description><![CDATA[Sleeping time is a site with an interesting idea. It takes the time of a Twitter user&#8217;s Tweets, and it makes a guess at their sleep schedule. The idea is that if you&#8217;re sleeping, you won&#8217;t Tweet (obviously this only applies to amateur Tweeters). Once you enter a person&#8217;s nickname, the site draws out a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sleepingtime.org/">Sleeping time</a> is a site with an interesting idea. It takes the time of a Twitter user&#8217;s Tweets, and it makes a guess at their sleep schedule. The idea is that if you&#8217;re sleeping, you won&#8217;t Tweet (obviously this only applies to amateur Tweeters). Once you enter a person&#8217;s nickname, the site draws out a visualization of the sleep schedule. For example <a href="http://www.sleepingtime.org/Peter_Ajtai">here is my sleep schedule</a>.</p>
<p><img class="aligncenter size-full wp-image-1346" title="Sleep" src="http://netlumination.com/wp-content/uploads/2010/07/sleep.jpg" alt="sleep schedule" width="440" height="256" />Well, the first impression one gets is that I sleep as much as a<a href="http://science.education.nih.gov/supplements/nih3/sleep/guide/info-sleep.htm"> brown bat</a> (19.9 hours per day apparently). The red area is much larger than half the clock, so it looks like I sleep the whole day away.</p>
<p><span id="more-1345"></span></p>
<p>Of course the clock only has 12 hours on it, so while it looks like I sleep 2/3 of the day, I actually only sleep half of that, or 1/3 of the day, according to Sleeping Time.</p>
<p>So, if the visualization doesn&#8217;t give you a quick visual idea of what portion of a day you spend sleeping, what is it good for? It tells you what portion of half a day you spend sleeping, but that&#8217;s not really a metric that&#8217;s ingrained in any of our brains.</p>
<p>This is the problem with data visualization. A graph often looks clear cut and simple, but it is often simply not showing you an answer to the question your are asking.</p>
<p>If you found this post even mildly interesting, then you should know that a great book about graphs, charts, and other ways of showing data is <a href="http://www.amazon.com/gp/product/0961392142?ie=UTF8&amp;tag=slugophile-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0961392142">The Visual Display of Quantitative Information</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/data-visualization/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few code snippets.</title>
		<link>http://netlumination.com/blog/a-few-code-snippets</link>
		<comments>http://netlumination.com/blog/a-few-code-snippets#comments</comments>
		<pubDate>Sun, 25 Jul 2010 02:40:09 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[samples]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1325</guid>
		<description><![CDATA[I often write very short, very simply little code snippets just to test specific things in HTML, CSS, PHP, or Javascript (and jQuery).  These are short little blurbs, that are useful for looking at how certain specific things work. They are mostly notes to self. Here are links to a few of them: Short Code [...]]]></description>
			<content:encoded><![CDATA[<p>I often write very short, very simply little code snippets just to test specific things in HTML, CSS, PHP, or Javascript (and jQuery).  These are short little blurbs, that are useful for looking at how certain specific things work. They are mostly notes to self.</p>
<p>Here are links to a few of them:</p>
<table>
<tbody>
<tr>
<td colspan="2"><strong>Short Code Snippets:</strong></td>
</tr>
<tr>
<td>CSS</td>
<td><a href="http://peter-ajtai.com/examples/html/images.php">Change image on hover.</a></td>
</tr>
<tr>
<td>CSS</td>
<td><a href="http://peter-ajtai.com/examples/html/menu-good.html">Creating large clickable areas.</a></td>
</tr>
<tr>
<td>CSS</td>
<td><a href="http://peter-ajtai.com/examples/html/sample.html">Images sprites example</a> &#8211; <a href="http://peter-ajtai.com/examples/html/styles.css">External CSS is here</a> &#8211; <a href="http://peter-ajtai.com/examples/html/images/sprite.png">Sprite is here</a></td>
</tr>
<tr>
<td>DOM</td>
<td><a href="http://peter-ajtai.com/examples/html/dom.php">Checking how many elements in an ID.</a></td>
</tr>
<tr>
<td>Javascript</td>
<td><a href="http://peter-ajtai.com/examples/js/animation.php">Basketball animation</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/custom-iteration.php">Return ID of clicked LI</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/jq-exs.php">Sliding, fading, and disappearing</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/not.php">Not this array element</a></td>
</tr>
<tr>
<td>jQuery</td>
<td><a href="http://peter-ajtai.com/examples/js/toggle.php">Using toggle()</a></td>
</tr>
<tr>
<tr>
<td>jQuery</td>
<td><a href="http://jsfiddle.net/pG8kt/">A simple infinite image slider</a></td>
</tr>
<tr>
<td>PHP Algorithm</td>
<td><a href="http://peter-ajtai.com/examples/php/lll.php">A linear linked list</a></td>
</tr>
<tr>
<td>PHP Recursion</td>
<td><a href="http://peter-ajtai.com/examples/numbers.php">Turning digits into words</a></td>
</tr>
<tr>
<td>PHP JSON CSS</td>
<td><a href="http://peter-ajtai.com/examples/php/del.php">Retrieving and displaying information from Delicious</a></td>
</tr>
<tr>
<td colspan="2"><strong>Simple Apps:</strong></td>
</tr>
<tr>
<td>jQuery PHP</td>
<td><a href="http://peter-ajtai.com/examples/php/so.php">Guessing game using Stackapps and Stackoverflow data</a></td>
</tr>
<tr>
<td>jQuery PHP</td>
<td><a href="http://peter-ajtai.com/examples/js/highlight.php">Dynamic Syntax Highlighting</a></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/a-few-code-snippets/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pimp My Web Page: Simple to Complex</title>
		<link>http://netlumination.com/blog/pimp-my-web-page-simple-to-complex</link>
		<comments>http://netlumination.com/blog/pimp-my-web-page-simple-to-complex#comments</comments>
		<pubDate>Tue, 22 Jun 2010 06:28:51 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Website Advice]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1260</guid>
		<description><![CDATA[Let&#8217;s start with the simplest web page: Well, that&#8217;s nice, but there&#8217;s certain information missing. We should add a doctype to let the browser know what flavor of HTML, XHTML, etc we&#8217;re using. This declares the document type definition (DTD) in use for the document. We should also add things like the HTML elements, a [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s start with the simplest web page:</p>
<pre class="html4strict PluGeSHin"><span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Hello World!<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span></pre>
<p>Well, that&#8217;s nice, but there&#8217;s <a href="http://www.w3.org/TR/html401/struct/global.html">certain information missing</a>. We should add a doctype to let the browser know what flavor of HTML, XHTML, etc we&#8217;re using. This declares the document type definition (DTD) in use for the document.</p>
<p>We should also add things like the HTML elements, a HEAD element for specifying more information about the page, a BODY for the contents.</p>
<p>We should also let the browser know our character encoding with a meta tag.</p>
<p>So now we have:<span id="more-1260"></span></p>
<pre class="html4strict PluGeSHin"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/\\xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> xmlns<span class="sy0">=</span><span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-Type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html;charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Greetings World<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Hello World!<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></pre>
<p>What about the look of the page? Let&#8217;s add some CSS:</p>
<pre class="css PluGeSHin">&lt;!DOCTYPE html PUBLIC <span class="st0">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span> <span class="st0">&quot;http://www.w3.org/TR/\\xhtml1/DTD/xhtml1-strict.dtd&quot;</span><span class="sy0">&gt;</span>
&lt;html xmlns<span class="sy0">=</span><span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="sy0">&gt;</span>
    &lt;head<span class="sy0">&gt;</span>
        &lt;meta http-equiv<span class="sy0">=</span><span class="st0">&quot;Content-Type&quot;</span> <span class="kw1">content</span><span class="sy0">=</span><span class="st0">&quot;text/html;charset=utf-8&quot;</span> /<span class="sy0">&gt;</span>
        &lt;title<span class="sy0">&gt;</span>Greetings World&lt;/title<span class="sy0">&gt;</span>
        &lt;style type<span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
            body <span class="br0">&#123;</span>
                <span class="kw1">background-color</span><span class="sy0">:</span><span class="re0">#BDC4D4</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
        &lt;/style<span class="sy0">&gt;</span>
    &lt;/head<span class="sy0">&gt;</span>
    &lt;body<span class="sy0">&gt;</span>
        &lt;h1<span class="sy0">&gt;</span>Hello World!&lt;/h1<span class="sy0">&gt;</span>
    &lt;/body<span class="sy0">&gt;</span>
&lt;/html<span class="sy0">&gt;</span></pre>
<p>Of course we should throw that into an external style sheet:</p>
<pre class="html4strict PluGeSHin"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span class="sc-1">&lt;!-- sample.html --&gt;</span>
<span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> xmlns<span class="sy0">=</span><span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-Type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html;charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Greetings World<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/link.html"><span class="kw2">link</span></a> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;styles.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span> <span class="sy0">/</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Hello World!<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></pre>
<p>and:</p>
<pre class="css PluGeSHin"><span class="coMULTI">/* styles.css */</span>
body <span class="br0">&#123;</span>
    <span class="kw1">background-color</span><span class="sy0">:</span><span class="re0">#BDC4D4</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<p>Let&#8217;s add two images:</p>
<pre class="html4strict PluGeSHin"><span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
    An Image ==&gt;
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/one.png&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;image 1&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
<span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
    Another Image ==&gt;
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/two.png&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;image 2&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span></pre>
<p>Hmmm&#8230; but we&#8217;re making two requests to the server for these two images. We can pass the same amount of information to the user with only one request to the server using <a href="http://www.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/">sprites</a>.</p>
<p>Sprites are often used in divs or other elements as background images. We&#8217;ll use sprites as background images, but they&#8217;ll be the background to an IMG element. &#8220;null.png&#8221; is simply a transparent pixel:</p>
<p>The HTML:</p>
<pre class="html4strict PluGeSHin"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span class="sc-1">&lt;!-- sample.html --&gt;</span>
<span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> xmlns<span class="sy0">=</span><span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-Type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html;charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Greetings World<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/link.html"><span class="kw2">link</span></a> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;styles.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span> <span class="sy0">/</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Hello World!<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
            An Image ==&gt;
            <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/null.png&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;sprite image1&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;image 1&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
            Another Image ==&gt;
            <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/null.png&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;sprite image2&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;image 2&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></pre>
<p>The CSS:</p>
<pre class="css PluGeSHin"><span class="coMULTI">/* styles.css */</span>
body <span class="br0">&#123;</span>
    <span class="kw1">background-color</span><span class="sy0">:</span><span class="re0">#BDC4D4</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.sprite</span> <span class="br0">&#123;</span>
    <span class="kw1">width</span><span class="sy0">:</span><span class="re3">80px</span><span class="sy0">;</span>
    <span class="kw1">height</span><span class="sy0">:</span><span class="re3">80px</span><span class="sy0">;</span>
    <span class="kw1">background</span><span class="sy0">:</span><span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">'images/sprite.png'</span><span class="br0">&#41;</span>
<span class="br0">&#125;</span>
<span class="re1">.image2</span> <span class="br0">&#123;</span>
    <span class="kw1">background-position</span><span class="sy0">:</span><span class="re3">-80px</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<p>Well, ok, but our sight isn&#8217;t going to change much over time, so once a visitor see our site, they should cache it in their browser for future use. This&#8217;ll make the page load faster for everyone, since it reduces server load, and it speeds up the loading of pages by repeat visitors.</p>
<p>We can accomplich this using HTTP headers. This is not the HTML HEADER tag. HTTP headers are lines that the server sends to the browser before the contents of the page&#8230; this means we can&#8217;t put the HTTP headers into the HTML file. We&#8217;ll have to use something server side for this. PHP has a header() function, which makes things really easy:</p>
<pre class="php PluGeSHin"><span class="kw2">&lt;?php</span>
<span class="co1">// Expires one year from now</span>
<span class="re0">$expires</span> <span class="sy0">=</span> <a target="_self" href="http://www.php.net/mktime"><span class="kw3">mktime</span></a><span class="br0">&#40;</span><span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="sy0">,</span> <a target="_self" href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>   <a target="_self" href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;d&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>   <a target="_self" href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span><span class="sy0">+</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Format date</span>
<span class="re0">$date</span> <span class="sy0">=</span>  <a target="_self" href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st_h">'D, d M Y H:i:s'</span><span class="sy0">,</span> <span class="re0">$expires</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">// Send HTTP header</span>
<a target="_self" href="http://www.php.net/header"><span class="kw3">header</span></a><span class="br0">&#40;</span><span class="st0">&quot;Expires: <span class="es4">$date</span> GMT&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;!-- sample.html --&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=utf-8&quot; /&gt;
        &lt;title&gt;Greetings World&lt;/title&gt;
        &lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Hello World!&lt;/h1&gt;
        &lt;p&gt;
            An Image ==&gt;
            &lt;img src=&quot;images/null.png&quot; class=&quot;sprite image1&quot; alt=&quot;image 1&quot; /&gt;
        &lt;/p&gt;
        &lt;p&gt;
            Another Image ==&gt;
            &lt;img src=&quot;images/null.png&quot; class=&quot;sprite image2&quot; alt=&quot;image 2&quot; /&gt;
        &lt;/p&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>We could have done the above with Apache or whatever server itself we&#8217;re using. PHP is nice for illustration, since we can keep all the code in the HTML file. Since the HTTP header comes before the HTML content, you cannot put any HTML before the PHP header() function.</p>
<p>Ok, now we&#8217;re getting somewhere, but we&#8217;ve still got all this text and stuff on our web page&#8230;. ok we don&#8217;t, but we could have all this stuff, if we had a big web page, or it may look like a lot of stuff to someone with a limping dial up in East Timor. Well, why don&#8217;t we compress all our stuff. Let&#8217;s GZIP it.</p>
<pre class="html4strict PluGeSHin"><span class="sc2">&lt;?php</span>
<span class="sc2"><span class="sy0">//</span> Expires one year from now</span>
<span class="sc2">$expires <span class="sy0">=</span> mktime<span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, date<span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>,   date<span class="br0">&#40;</span><span class="st0">&quot;d&quot;</span><span class="br0">&#41;</span>,   date<span class="br0">&#40;</span><span class="st0">&quot;Y&quot;</span><span class="br0">&#41;</span>+<span class="nu0">1</span><span class="br0">&#41;</span>;</span>
<span class="sc2"><span class="sy0">//</span> Format date</span>
<span class="sc2">$date <span class="sy0">=</span>  date<span class="br0">&#40;</span><span class="st0">'D, d M Y H:i:s'</span>, $expires<span class="br0">&#41;</span>;</span>
<span class="sc2"><span class="sy0">//</span> Send HTTP header</span>
<span class="sc2">header<span class="br0">&#40;</span><span class="st0">&quot;Expires: $date GMT&quot;</span><span class="br0">&#41;</span>;</span>
<span class="sc2">if <span class="br0">&#40;</span>substr_count<span class="br0">&#40;</span>$_SERVER<span class="br0">&#91;</span><span class="st0">'HTTP_ACCEPT_ENCODING'</span><span class="br0">&#93;</span>, <span class="st0">'gzip'</span><span class="br0">&#41;</span><span class="br0">&#41;</span></span>
<span class="sc2">    ob_start<span class="br0">&#40;</span><span class="st0">&quot;ob_gzhandler&quot;</span><span class="br0">&#41;</span>;</span>
<span class="sc2">else</span>
<span class="sc2">    ob_start<span class="br0">&#40;</span><span class="br0">&#41;</span>;</span>
<span class="sc2">?&gt;</span>
<span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span class="sc-1">&lt;!-- sample.html --&gt;</span>
<span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a> xmlns<span class="sy0">=</span><span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/meta.html"><span class="kw2">meta</span></a> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;Content-Type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html;charset=utf-8&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>Greetings World<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/title.html"><span class="kw2">title</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/link.html"><span class="kw2">link</span></a> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;styles.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">media</span><span class="sy0">=</span><span class="st0">&quot;screen&quot;</span> <span class="sy0">/</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/head.html"><span class="kw2">head</span></a>&gt;</span>
    <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>Hello World!<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/h1.html"><span class="kw2">h1</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
            An Image ==&gt;
            <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/null.png&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;sprite image1&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;image 1&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
        <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
            Another Image ==&gt;
            <span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/img.html"><span class="kw2">img</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;images/null.png&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;sprite image2&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;image 2&quot;</span> <span class="sy0">/</span>&gt;</span>
        <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/p.html"><span class="kw2">p</span></a>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/body.html"><span class="kw2">body</span></a>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/html.html"><span class="kw2">html</span></a>&gt;</span></pre>
<p>You can <a href="http://www.gidnetwork.com/tools/gzip-test.php">confirm that you&#8217;re properly GZIPPED</a>.</p>
<p>Ok. With PHP we can also <a href="http://php.net/manual/en/function.flush.php">flush</a> the buffer early:</p>
<pre class="php PluGeSHin">&lt;/head&gt;
    <span class="kw2">&lt;?php</span> <a target="_self" href="http://www.php.net/flush"><span class="kw3">flush</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="sy1">?&gt;</span>
&lt;body&gt;</pre>
<p>It&#8217;s great that our CSS is in its own file, but it still has a bunch of whitespace. Why don&#8217;t we minify it.</p>
<p>I used the <a href="http://developer.yahoo.com/yui/compressor/">YUI compressor</a> with this command:</p>
<pre class="php PluGeSHin">java <span class="sy0">-</span>jar yuicompressor<span class="sy0">-</span>2<span class="sy0">.</span>4<span class="sy0">.</span>2<span class="sy0">.</span>jar styles<span class="sy0">.</span>css <span class="sy0">-</span>o styles<span class="sy0">.</span><a target="_self" href="http://www.php.net/min"><span class="kw3">min</span></a><span class="sy0">.</span>css <span class="sy0">--</span>type css</pre>
<p>To get this CSS file:</p>
<pre class="css PluGeSHin">body<span class="br0">&#123;</span><span class="kw1">background-color</span><span class="sy0">:</span><span class="re0">#BDC4D4</span><span class="sy0">;</span><span class="br0">&#125;</span><span class="re1">.sprite</span><span class="br0">&#123;</span><span class="kw1">width</span><span class="sy0">:</span><span class="re3">80px</span><span class="sy0">;</span><span class="kw1">height</span><span class="sy0">:</span><span class="re3">80px</span><span class="sy0">;</span><span class="kw1">background</span><span class="sy0">:</span><span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">'images/sprite.png'</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="br0">&#125;</span><span class="re1">.image2</span><span class="br0">&#123;</span><span class="kw1">background-position</span><span class="sy0">:</span><span class="re3">-80px</span><span class="sy0">;</span><span class="br0">&#125;</span></pre>
<p>We can do the same minification with our Javascript if we have any, and remember to include your Javascript as far to the bottom of the page as you can.</p>
<p>Take a look at the <a href="http://peter-ajtai.com/examples/html/sample.php">final page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/pimp-my-web-page-simple-to-complex/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery for a little night time reading</title>
		<link>http://netlumination.com/blog/jquery-for-a-little-night-time-reading</link>
		<comments>http://netlumination.com/blog/jquery-for-a-little-night-time-reading#comments</comments>
		<pubDate>Tue, 15 Jun 2010 01:16:26 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1242</guid>
		<description><![CDATA[If you use Javascript, JQuery is a great framework to speed up your coding. It&#8217;s essentially a collection of really convenient shortcuts. It does more, since JQuery also handles a lot of browser compatibility issues. So, you don&#8217;t have to go through your JQuery code to update it for new browsers, all you have to [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Javascript, <a href="http://jquery.com/">JQuery</a> is a great framework to speed up your coding. It&#8217;s essentially a collection of really convenient shortcuts. It does more, since JQuery also handles a lot of browser compatibility issues. So, you don&#8217;t have to go through your JQuery code to update it for new browsers, all you have to do is download the new version of JQuery, and your old commands will learn new tricks.</p>
<p>Ah, speaking of downloading JQuery, you just might want to understand how JQuery works if you use it. The first time I tried to do this, I simply clicked on my JQuery src file link:</p>
<pre class="html4strict PluGeSHin"><span class="sc2">&lt;<a target="_self" href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://peter-ajtai.com/jquery/jquery-1.4.2.min.js&quot;</span>&gt;&lt;<span class="sy0">/</span><a target="_self" href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></pre>
<p>&#8230; and this is what I saw:</p>
<p><img class="alignnone size-full wp-image-1243" title="Happy reading" src="http://netlumination.com/wp-content/uploads/2010/06/wall-o-text.jpg" alt="Wall o text JQuery" width="419" height="323" /></p>
<p>Fun reading, huh? <span id="more-1242"></span>Well, when your browser loads Javascript, it has to load each charachter, so the less whitespace there is, and the shorter the variable names are, the faster it will load.</p>
<p>This means you should be using this, the minified, version of JQuery on your site, but if you want some <del>pleasant and relaxing</del> reading&#8230; you should look at the uncompressed version. <a href="http://docs.jquery.com/Downloading_jQuery">JQuery shows you both versions very clearly on their download page</a>, but for some reason, it took me a while to realize that there is an uncompressed version. The <a href="http://code.jquery.com/jquery-latest.js">uncompressed version of the latest version is here</a>. The uncompressed version is actually very readable:</p>
<p><img class="alignnone size-full wp-image-1244" title="That's better" src="http://netlumination.com/wp-content/uploads/2010/06/readable.jpg" alt="Readable JQuery" width="423" height="352" /></p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/jquery-for-a-little-night-time-reading/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The joys of toxic asset ownership</title>
		<link>http://netlumination.com/blog/the-joys-of-toxic-asset-ownership</link>
		<comments>http://netlumination.com/blog/the-joys-of-toxic-asset-ownership#comments</comments>
		<pubDate>Fri, 11 Jun 2010 21:36:48 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Zany]]></category>
		<category><![CDATA[economics]]></category>
		<category><![CDATA[Planet Money]]></category>
		<category><![CDATA[real estate]]></category>
		<category><![CDATA[toxic assets]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1232</guid>
		<description><![CDATA[I tend to listen to a lot of podcasts while doing housework. Listening to things like Planet Money makes washing the dishes fun&#8230; well, maybe not, but it makes it feel like I&#8217;m learning something new while doing the same old same old. Not too long ago, the members of Planet Money pitched in, pooled [...]]]></description>
			<content:encoded><![CDATA[<p>I tend to listen to a lot of podcasts while doing housework. Listening to things like <a href="http://www.npr.org/blogs/money/">Planet Money</a> makes washing the dishes fun&#8230; well, maybe not, but it makes it feel like I&#8217;m learning something new while doing the same old same old.<span id="more-1232"></span></p>
<p>Not too long ago, the members of Planet Money pitched in, pooled their money, and bought their own $1,000&#8242;s worth of real estate based toxic assets. You can hear about how <a href="http://www.npr.org/templates/story/story.php?storyId=124587240">they picked their asset, bought it, and how it&#8217;s doing</a>. You can also hear about the types of things that affect whether the Planet Money team will get a good return on their investment&#8230;. It turns out, that having people not pay their monthly mortgage is ok, since the person who gave out the mortgage is then responsible for paying the money into the toxic asset coffers&#8230; whoever, if the home owners refinance, then the amount of money they have to pay decreases, and so the pay out to the toxic asset decreases. There&#8217;s also all sorts of other stories about the history of their specific toxic asset including <a href="http://www.npr.org/templates/story/story.php?storyId=124578382">an eye opening animated graphic showing the rate that the loans in the asset are going into delinquency</a>. (I do have to say that one of the downfalls of the graphic is that the number of loans in each state is not immediately apparent, even though these numbers vary from one to several thousand&#8230; so make sure you hover over the states you think are interesting to check the sample size).</p>
<p>It&#8217;s a great series of stories, and it lets you understand about toxic assets, and even makes you feel bad for Toxy&#8230;. Yes, Toxy is the name of the toxic asset. But seriously, this is some reporting that takes a subject that is often presented as dead boring and overly complicated, and Planet Money makes the subject personal, interesting, and entertaining. Just wanted to share.</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/the-joys-of-toxic-asset-ownership/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three Steps for Using JQuery in Your WordPress Theme</title>
		<link>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme</link>
		<comments>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme#comments</comments>
		<pubDate>Mon, 31 May 2010 05:58:39 +0000</pubDate>
		<dc:creator>Peter Ajtai</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://netlumination.com/?p=1202</guid>
		<description><![CDATA[This is a quick post on using Javascript and the JQuery framework in particular within your WordPress theme. It&#8217;s quick and pretty painless. This is just for regular themes, not admin themes, plugins, or posts. Step 1: Load JQuery and your custom JS onto your page with wp_enqueue_script(). It&#8217;s better to use wp_enqueue_script than hard [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick post on using Javascript and the JQuery framework in particular within your WordPress theme. It&#8217;s quick and pretty painless. This is just for regular themes, not admin themes, plugins, or posts.</p>
<p><strong>Step 1:</strong></p>
<p><strong><span id="more-1202"></span></strong></p>
<p>Load JQuery and your custom JS onto your page with wp_enqueue_script(). It&#8217;s better to use wp_enqueue_script than hard coding it into your page. This is because WordPress comes with JQuery, so you won&#8217;t have to worry about updating JQuery as new versions come out. WordPress will do the work for you.  Make sure wp_enqueue script is before wp_head(), or it won&#8217;t work.</p>
<p>Here&#8217;s a snippet from my template file (let&#8217;s say index.php). I&#8217;ve created my custom JQuery functions in my themes &#8220;scripts&#8221; directory with the file name &#8220;custom-js.js&#8221;. You also have to make up a handle or name for your collection of custom JQuery functions. I called mine custom:</p>
<pre class="php PluGeSHin"><span class="kw2">&lt;?php</span>
    wp_enqueue_script<span class="br0">&#40;</span><span class="st_h">'jquery'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    wp_enqueue_script<span class="br0">&#40;</span><span class="st_h">'custom'</span><span class="sy0">,</span> get_bloginfo<span class="br0">&#40;</span><span class="st_h">'stylesheet_directory'</span><span class="br0">&#41;</span> <span class="sy0">.</span> <span class="st_h">'/scripts/custom-js.js'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    wp_head<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// WP API Hook</span>
<span class="sy1">?&gt;</span></pre>
<p>get_bloginfo is your friend. If you hard code your themes directory into your code anywhere, you won&#8217;t be able to share it with others, and you&#8217;ll break everything if you ever move hosts or just directories.</p>
<p>Here&#8217;s another example. Let&#8217;s say you want to use <a href="http://code.google.com/apis/maps/documentation/javascript/examples/index.html">Google Maps</a> on your page. Here is the line of WP code that makes that possible:</p>
<pre class="php PluGeSHin"><span class="kw2">&lt;?php</span>
    wp_enqueue_script<span class="br0">&#40;</span><span class="st_h">'googleMaps'</span><span class="sy0">,</span> <span class="st_h">'http://maps.google.com/maps/api/js?sensor=false'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="sy1">?&gt;</span></pre>
<p>Finally, if you just want plain JS with no JQuery, you can simply leave out the line that calls JQuery but leave in the line that enqueues your custom functions. WordPress comes with a lot of other JS goodies besides JQuery. Scroll down to<a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script"> the bottom of this page</a> to look at all the other stuff included with WordPress.</p>
<p><strong>Step 2:</strong><br />
Write your JQuery. The only thing you have to look out for is that wp_enqueue_script() calls JQuery in no conflict mode. This means that $ will not work as a shortcut for JQuery functions. There are two simple solutions.</p>
<ol>
<li>Define another shortcut for JQuery functions.</li>
<li>Use a wrapper around your JQuery code.</li>
</ol>
<p>Here is how to define a new shortcut for JQuery functions, $j in this case. The script shown is a very effective test to see if you&#8217;ve got JQuery working in your theme. It&#8217;s a little blunt, but it&#8217;s effects are hard to miss.</p>
<pre class="javascript PluGeSHin"><span class="kw2">var</span> $j <span class="sy0">=</span> jQuery.<span class="me1">noConflict</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
$j<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
 $j<span class="br0">&#40;</span><span class="st0">&quot;body&quot;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span><span class="st0">&quot;Your page is belong to us... just kidding, but you can use JQuery now.&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p>Here is how to use a wrapper in order to use the default JQuery shortcut:</p>
<pre class="javascript PluGeSHin">jQuery<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>$<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    $<span class="br0">&#40;</span><span class="st0">&quot;body&quot;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span><span class="st0">&quot;Your page is belong to us... just kidding, but you can use JQuery now.&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre>
<p>Make sure you pay attention to all the curly brackets and parentheses. If the long and multiple parenthetical expressions annoy you, go check out <a href="http://www.cs.cmu.edu/afs/cs/project/theo-11/www/decision-trees.lisp">Lisp</a>.</p>
<p>Anyway, the second method is nice, since it let&#8217;s you use previously written code easily.</p>
<p><strong>Step 3:</strong></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://netlumination.com/blog/three-steps-for-using-jquery-in-your-wordpress-theme/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

