<?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>Traversal</title>
	<atom:link href="http://traversal.com.au/feed/" rel="self" type="application/rss+xml" />
	<link>http://traversal.com.au</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 07:46:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>JavaScript global closures and jQuery</title>
		<link>http://traversal.com.au/blog/2009/03/28/jquery-global-closures/</link>
		<comments>http://traversal.com.au/blog/2009/03/28/jquery-global-closures/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:32:53 +0000</pubDate>
		<dc:creator>Travis Hensgen</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://local.traversal.com.au/?p=103</guid>
		<description><![CDATA[Learn how to use JavaScript anonymous function wrappers and their jQuery variants to keep the global variable space tidy.]]></description>
			<content:encoded><![CDATA[<p>When adding JavaScript behaviours to your web site or application, keeping the global variable scope as clean as possible is a good practice to avoid naming conflicts, especially if you are using third party code from multiple sources.</p>
<h3>The anonymous function wrapper</h3>
<p><em>Closures</em> in JavaScript allow us to keep the global scope tidy &#8211; we can create one by declaring an anonymous function in the global scope, and then immediately calling that function, like so:</p>
<pre class="brush: js">
(function() {
// variables and functions declared here are not visible in global scope

})();
</pre>
<p>The syntax is strange but if you break it down it makes sense: we place brackets <em>around</em> the function declaration so that it&#8217;s clear to JavaScript that we are then operating on the function as if it&#8217;s a variable. </p>
<p>It might help to remember that in JavaScript, we can <em>also</em> declare a function like this:</p>
<pre class="brush: js">
var myFunc = function() { // function body
};

// now we can call the function like normal:
myFunc();
</pre>
<p>So, all the brackets around the function declaration do is take out the unnecessary step of assigning to an intermediate variable. Then, we immediately call the function with <code>()</code>, just like we did above with <code>myFunc</code> &#8211; calling the function ensures that the code is actually executed, which is rather important if we actually want to <em>achieve anything</em> inside the wrapper! <img src='http://traversal.com.au/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </p>
<p>The beauty of these anonymous function wrappers is that once you memorize the syntax, you don&#8217;t really have to think too hard about the mechanics of them. <img src='http://traversal.com.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>The jQuery version</h3>
<p>jQuery works hard to avoid polluting the global variable space by design. Out of the box, it only contains 2 global variables: the <code>jQuery</code> object itself, and its alias shorthand <code>$</code>. Building on the standard anonymous function wrapper, we can use the version illustrated below which has the additional benefit of ensuring that any use of <code>$</code> inside the wrapper will be a call to the <code>jQuery</code> object and not to <code>$</code> in another library such as Prototype or MooTools, if those happen to be used on the same page.</p>
<pre class="brush: js">
(function($) {
// code in here can safely use $, knowing it will reference jQuery

})(jQuery);
</pre>
<p>Here, the <code>$</code> shorthand is a named parameter in our anonymous function, whose value becomes the <code>jQuery</code> object in our immediate call &#8211; <code>(jQuery)</code>. Importantly, the value of <code>$</code> <em>outside</em> the function is retained - this works because with with JavaScript closures, function parameter variables are <em>also</em> local in scope to the code in that closure, and any values with the same name outside that closure are not affected.</p>
<p><strong>There is one gotcha:</strong> if you are using <em>jQuery</em> with <em>Prototype</em> or <em>MooTools</em>, it&#8217;s easiest to include <em>jQuery</em> <strong>before</strong> the other library, so that it doesn&#8217;t override the value of <code>$</code> <strong>outside</strong> the anonymous function. If for whatever reason you <em>must</em> include <em>jQuery</em> after <em>Prototype</em> or <em>MooTools</em>, you can call <code>jQuery.noConflict()</code> before you call the <code>$</code> shortcut in the other library &#8211; more information on this is available in the jQuery documentation <a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries">here</a>.</p>
<p>Once again though, the beauty of the jQuery wrapper code is that once you memorize it, the mechanics of how and why it works don&#8217;t really need to be fresh in your mind. But it still doesn&#8217;t hurt to know the how and why. <img src='http://traversal.com.au/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://traversal.com.au/blog/2009/03/28/jquery-global-closures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TextMate Math Bundle and the Box Model</title>
		<link>http://traversal.com.au/blog/2007/09/14/textmate-math-bundle-and-the-box-model/</link>
		<comments>http://traversal.com.au/blog/2007/09/14/textmate-math-bundle-and-the-box-model/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 03:25:50 +0000</pubDate>
		<dc:creator>Travis Hensgen</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://mondea.com.au/blog/?p=5</guid>
		<description><![CDATA[TextMate has plenty of great bundles that support HTML and CSS development, but perhaps less obvious is the Math bundle, which can help you brainlessly calculate the correct width value for your layouts.]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://macromates.com">TextMate</a>, oh yes I do. One thing I&#8217;ve found incredibly useful lately is the Math Bundle, which you can install yourself by pasting <a href="http://netcetera.org/cgi-bin/tmbundles.cgi?bundle=Math">the script listed here</a> into a Terminal window.</p>
<p>So, you know how in the CSS box model padding is NOT regarded as part of the width of the box, and you always have to rack your brain to subtract out the padding from the marquee you&#8217;ve measured in your graphics app? Well, not any more!</p>
<p>The Math bundle, among other things, lets you evaluate arithmetic expressions in your text documents. So let&#8217;s say I&#8217;ve got a div (#column_1) that has horizontal padding of 26 pixels, but a total width of 228 pixels as in the image below:</p>
<p><img src="http://traversal.com.au/images/tm_math_01.png" alt="" /></p>
<p>All those CSS experts out there know that I really need the width set to 228 &#8211; 26*2 pixels to take the padding into account, so let&#8217;s type that out:</p>
<p><img src="http://traversal.com.au/images/tm_math_02.png" alt="" /></p>
<p>Now, before I grab that sheet of paper and/or caffeine to do the sums, I just highlight the expression, press Shift-Ctrl-C and I get this:</p>
<p><img src="http://traversal.com.au/images/tm_math_03.png" alt="" /></p>
<p>Now I hit 2 to <strong>replace</strong> the expression (since my browser surely won&#8217;t understand my advanced mathematics), and voila! Instant box-model love:</p>
<p><img src="http://traversal.com.au/images/tm_math_04.png" alt="" /></p>
<p>Like I said, you gotta love TextMate! Makes me wonder why I even bothered studying maths up to a university level&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://traversal.com.au/blog/2007/09/14/textmate-math-bundle-and-the-box-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jscalendar skin &#8211; minium</title>
		<link>http://traversal.com.au/blog/2007/08/14/jscalendar-skin-minium/</link>
		<comments>http://traversal.com.au/blog/2007/08/14/jscalendar-skin-minium/#comments</comments>
		<pubDate>Tue, 14 Aug 2007 09:51:55 +0000</pubDate>
		<dc:creator>Travis Hensgen</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://mondea.com.au/blog/?p=4</guid>
		<description><![CDATA[A new skin that adopts the look of Apple's "pro" interfaces, for the excellent jscalendar component by Mihai Bazon of dynarch.com.]]></description>
			<content:encoded><![CDATA[<p>I really like the <a href="http://www.dynarch.com/projects/calendar/">jscalendar</a> popup calendar component by Mihai Bazon of <a href="http://www.dynarch.com">dynarch.com</a> and I&#8217;m sure I&#8217;m not alone &#8211; it manages to pack in a wealth of features yet still be intuitive to the average user.</p>
<p>I&#8217;m not so mad on the available skins however &#8211; in particular, the <em>Aqua</em> theme takes on the look and feel of the first few releases of Mac OS X when those white and grey background stripes were not-so-subtle and not-so-attractive. No, I wanted a skin that was a little more up-to-date for a project I&#8217;ve been working on, so after a few hours in the lab here is the <a href="http://traversal.com.au/downloads/jscalendar_minium.zip">Minium</a> skin (also based on a theme name I&#8217;m using for said project).</p>
<p><img src="http://traversal.com.au/images/jscalendar_minium.png" alt="Minium Theme Preview" /></p>
<p>Yep, it&#8217;s heavily inspired by Mac OS X, and in particular, Apple&#8217;s &#8220;pro&#8221; look and feel, which probably stuck in my head when I checked out <a href="http://www.apple.com/iwork/numbers/">Numbers</a> the day it was released <img src='http://traversal.com.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Hopefully this will be just the ticket for polishing up your web application too!</p>
<p><a href="http://traversal.com.au/downloads/jscalendar_minium.zip">Download <em>Minium</em> for jscalendar.</a></p>
<p>To use the skin with jscalendar, place the <em>minium</em> folder contained in the zip file inside the <em>skins</em> folder in your jscalendar install, and add a link tag to the theme.css file inside. </p>
]]></content:encoded>
			<wfw:commentRss>http://traversal.com.au/blog/2007/08/14/jscalendar-skin-minium/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Markup Conventions</title>
		<link>http://traversal.com.au/blog/2007/05/14/markup-conventions/</link>
		<comments>http://traversal.com.au/blog/2007/05/14/markup-conventions/#comments</comments>
		<pubDate>Mon, 14 May 2007 04:27:22 +0000</pubDate>
		<dc:creator>Travis Hensgen</dc:creator>
				<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://mondea.com.au/blog/?p=3</guid>
		<description><![CDATA[Many of us have our own conventions when working with HTML - here's one of mine for form elements.]]></description>
			<content:encoded><![CDATA[<p>While hardly earth shattering, one useful XHTML convention I&#8217;ve been using lately is to always make the id attribute the <strong>first</strong> on a tag, and make the class attribute the <strong>last</strong>. The most common case that I need both attributes is for input tags (and usually because IE 6 doesn&#8217;t support attribute-selectors), for example:</p>
<pre class="brush: xhtml">

&lt;input id=&quot;first-name&quot; name=&quot;first-name&quot; type=&quot;text&quot; classic=&quot;text&quot; /&gt;
</pre>
<p>Using this convention also means I can place the <code>id</code> and the <code>name</code> adjacent to each other &#8211; also handy. While this may not be the preferred convention for everyone, I find it&#8217;s just one more thing that helps me read that code in 6 months time &#8211; if I stick to it, it&#8217;s pretty quick for my eye to scan to that all-important information. </p>
]]></content:encoded>
			<wfw:commentRss>http://traversal.com.au/blog/2007/05/14/markup-conventions/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Announcing JEL</title>
		<link>http://traversal.com.au/blog/2007/05/09/hello-world-2/</link>
		<comments>http://traversal.com.au/blog/2007/05/09/hello-world-2/#comments</comments>
		<pubDate>Wed, 09 May 2007 09:49:36 +0000</pubDate>
		<dc:creator>Travis Hensgen</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JEL]]></category>

		<guid isPermaLink="false">http://traversal.com.au/wordpress/?p=5</guid>
		<description><![CDATA[I've decided to start writing a blog, and for my first post I'm releasing a library I've been working on - JEL (the JavaScript Enhancement Library) which is built on top of Prototype and Dean Edwards' Base library.]]></description>
			<content:encoded><![CDATA[<p>As part of my first foray into the blogosphere, I&#8217;m proud to announce the release of <a href="http://traversal.com.au/projects/jel-for-prototype/">JEL</a> (the JavaScript Enhancement Library) which, as the tagline suggests, aims to relieve the aches and pains of <strong>everyday</strong> web development. JEL is built on top of the fantastic <a href="http://prototypejs.org">Prototype</a> Framework and the stupidly useful <a href="http://dean.edwards.name/base/">Base</a> library by <a>Dean Edwards</a>, and I&#8217;d like to thank those people for their incredible gifts to the web developer community.</p>
<p>Far from being the next great JavaScript effects library (that domain is <a href="http://script.aculo.us">pretty</a> <a href="http://www.openrico.org/">well</a> <a href="http://berniecode.com/writing/animator.html">covered</a>) JEL is focused on the utilitarian, and was borne out of me being sick of writing the same old date-handling, string-handling or form validation code over and over again. Which means you&#8217;ll have more time to pimp your site up with JavaScript FX! Hooray!(?)</p>
<p>The JEL site contains full <a href="ttp://traversal.com.au/projects/jel-for-prototype/docs/">API Documentation</a> built with <a href="http://naturaldocs.org">NaturalDocs</a>, inspired by the MooTools documentation which is one of the best documentation sites I have ever seen (thanks Greg for NaturalDocs, and <a href="http://mad4milk.net/">Mad4Milk</a> for pointing me toward a brilliant way to document JavaScript code). And for those who don&#8217;t like reading reference docs, I have written up some <a href="ttp://traversal.com.au/projects/jel-for-prototype/manual/">Manual</a> pages to help you get started.</p>
<p>And yes, I know my site looks pretty much like the default WordPress template (&#8220;lame!&#8221; as <a href="http://en.wikipedia.org/wiki/John_Dorian">John Dorian</a> would surely say), but I&#8217;m tired of <a href="http://www.urbandictionary.com/define.php?term=lurking">lurking</a> and <em>content is king</em> right? Now that the first release of JEL is done, I&#8217;ll have more time to devote to a pretty template of my very own!</p>
<p>I&#8217;ve got a lot more to say about things I&#8217;ve picked up while developing JEL so stay tuned&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://traversal.com.au/blog/2007/05/09/hello-world-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>


<!-- W3 Total Cache: Page cache debug info:
Engine:             disk (enhanced)
Key:                feed/_index.html
Caching:            enabled
Status:             not cached
Creation Time:      0.695s
Header info:
X-Pingback:         http://traversal.com.au/xmlrpc.php
ETag:               "a5f57dbb29bdbd536820c6486321e873"
X-Powered-By:       W3 Total Cache/0.9.1.3
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 19 May 2012 16:21:58 GMT
Vary:               Accept-Encoding, Cookie
Content-Encoding:   gzip
-->
