<?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>boedesign - canadian based web developer eh</title>
	<atom:link href="http://boedesign.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://boedesign.com</link>
	<description>The dabbling of various web technologies by Jordan Boesch</description>
	<lastBuildDate>Sun, 29 Aug 2010 21:33:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>7shifts officially released!</title>
		<link>http://boedesign.com/blog/2010/08/28/7shifts-officially-released/</link>
		<comments>http://boedesign.com/blog/2010/08/28/7shifts-officially-released/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 14:04:55 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=703</guid>
		<description><![CDATA[I would like to announce that the project I&#8217;ve been working on for awhile has been released! It&#8217;s called 7shifts and it&#8217;s an application where part-time employees can check/manage their availability and schedules online. It&#8217;s free to sign up for a trial, so if you&#8217;re a company that employs part-time staff, this could make your [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to announce that the project I&#8217;ve been working on for awhile has been released! </p>
<p>It&#8217;s called <a href="http://7shifts.com">7shifts</a> and it&#8217;s an application where part-time employees can check/manage their availability and schedules online.  It&#8217;s free to sign up for a trial, so if you&#8217;re a company that employs part-time staff, this could make your life a whole lot easier.</p>
<p>You can <a href="http://twitter.com/7shifts">follow 7shifs on twitter</a> as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/08/28/7shifts-officially-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My top 3 custom WordPress functions</title>
		<link>http://boedesign.com/blog/2010/07/24/my-top-3-custom-wordpress-functions/</link>
		<comments>http://boedesign.com/blog/2010/07/24/my-top-3-custom-wordpress-functions/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 05:08:27 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=688</guid>
		<description><![CDATA[I&#8217;ve done quite a few sites in WordPress. Come to think of it, it&#8217;s pretty much all I do when it comes to throwing together a CMS-based site. Here are some really handy functions that I&#8217;ve written that I think would be handy for you other programming monkeys. 1. Calling get_bloginfo() from within the WYSIWYG [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done quite a few sites in WordPress.  Come to think of it, it&#8217;s pretty much all I do when it comes to throwing together a CMS-based site.  Here are some really handy functions that I&#8217;ve written that I think would be handy for you other programming monkeys.</p>
<h3>1. Calling get_bloginfo() from within the WYSIWYG</h3>
<p>
Moving a WP site to another domain can sometimes be annoying, with broken image paths within the content fields etc. Yes, you could use a typical SQL REPLACE to fix all your paths &#8211; that&#8217;s definitely an option.  Wouldn&#8217;t it be nice if you could code your path&#8217;s relatively and it would just work?  Well, I think so. That&#8217;s why I&#8217;ve come up with this convention.
</p>
<p>
You know how you can call <em>get_bloginfo(&#8216;template_directory&#8217;)</em> from a PHP file for the path to your template director? Awesome, but I want that same kind of functionality in the WYSIWYG content editor. Simple, just type {{ template_directory }} or {{ home }} or {{ rss2_url }} in the WYSIWYG.  <a href="http://codex.wordpress.org/Function_Reference/get_bloginfo" target="_blank">A full list of the options can be found here.</a>
</p>
<p>Put the code below in your themes functions.php file</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color:#494F51;">// Add a filter to make all calls to the_content() run through our little custom filter.</span>
add_filter<span style="color: #E5FFBE;01">&#40;</span><span style="color: #aaa;">'the_content'</span><span style="color: #aaa;01">,</span> <span style="color: #aaa;">'bloginfo_filter_content'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color:#494F51;">/**
* Handy-dandy find and replaces on things that are typed in the WYSIWYG
* Text betwen {{ }} should be keys for get_bloginfo();
*
* @param {String} $content The post_content passed in
*/</span>
<span style="color: #fff;">function</span> bloginfo_filter_content<span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$content</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
    <span style="color: #81869F;">$c</span> <span style="color: #aaa;01">=</span> <span style="color: #81869F;">$content</span><span style="color: #aaa;01">;</span>
&nbsp;
    <span style="color: #81869F;">$pattern</span> <span style="color: #aaa;01">=</span> <span style="color: #aaa;">&quot;/{{(.*?)}}/&quot;</span><span style="color: #aaa;01">;</span>
    <span style="color: #fff;">preg_match_all</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$pattern</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$content</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$matches</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
    <span style="color: #fff;">if</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$matches</span><span style="color: #E5FFBE;01">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
        <span style="color: #fff;">foreach</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$matches</span><span style="color: #E5FFBE;01">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #E5FFBE;01">&#93;</span> <span style="color: #fff;">as</span> <span style="color: #81869F;">$i</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #81869F;">$blog_option</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
            <span style="color: #81869F;">$blog_option_clean</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">strtolower</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">trim</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$blog_option</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
            <span style="color: #81869F;">$blog_val</span> <span style="color: #aaa;01">=</span> get_bloginfo<span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$blog_option_clean</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
            <span style="color:#494F51;">// If we passed an invalid key argument (doesnt exist), skip over and do nothing</span>
            <span style="color:#494F51;">// Note: invalid keys always default to the blogname key. That's how we check.</span>
            <span style="color: #fff;">if</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$blog_val</span> <span style="color: #aaa;01">==</span> get_bloginfo<span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">&amp;&amp;</span> <span style="color: #81869F;">$blog_option_clean</span> <span style="color: #aaa;01">!=</span> <span style="color: #aaa;">'blogname'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
                <span style="color: #fff;">continue</span><span style="color: #aaa;01">;</span> 
            <span style="color: #E5FFBE;01">&#125;</span>
            <span style="color: #fff;">else</span> <span style="color: #E5FFBE;01">&#123;</span>
                <span style="color: #81869F;">$c</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">str_replace</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$matches</span><span style="color: #E5FFBE;01">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #E5FFBE;01">&#91;</span><span style="color: #81869F;">$i</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$blog_val</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$c</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
            <span style="color: #E5FFBE;01">&#125;</span>
        <span style="color: #E5FFBE;01">&#125;</span>
    <span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
    <span style="color: #fff;">return</span> <span style="color: #81869F;">$c</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span></pre></div></div>

<p>Now whenever you call <a href="http://codex.wordpress.org/Function_Reference/the_content" target="_blank"><em>the_content()</em></a> in your while loop, it will run it through this filter and do any necessary replacements.</p>
<h3>2. List of tags without tag cloud weight</h3>
<p>
It seems kind of odd to me, but WordPress doesn&#8217;t seem to have a function to just list the tags like <a href="http://codex.wordpress.org/Template_Tags/wp_list_categories" target="_blank"><em>wp_list_categories()</em></a> does. Instead it offers <a href="http://codex.wordpress.org/Function_Reference/wp_tag_cloud" target="_blank"><em>wp_tag_cloud()</em></a>, which puts them in an ordered/unordered list but gives them a font-size weight (inline style attribute).  It&#8217;s yucky if you&#8217;re not using it for an actual tag cloud and just want to display the tags in a list.  You <em>could</em> just add a font-size: 11px !important; in your CSS to override any inline font-styles but I&#8217;m not a big fan of the !important declaration.  Here&#8217;s a fix:
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color:#494F51;">/**
* We want to list tags in an unordered list, but we don't want the style
* attribute to override our font-sizes that we set in the CSS
*/</span>
<span style="color: #fff;">function</span> list_tags<span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
    <span style="color: #81869F;">$tags</span> <span style="color: #aaa;01">=</span> wp_tag_cloud<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">array</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #aaa;">'format'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'list'</span><span style="color: #aaa;01">,</span> <span style="color: #aaa;">'echo'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #fff;">false</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> 
    <span style="color:#494F51;">// Get rid of that yucky style attribute that contains font-size</span>
    <span style="color: #fff;">return</span> <span style="color: #fff;">preg_replace</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #aaa;">'/style\s*=\s*(\'</span><span style="color: #aaa;01">|</span><span style="color: #aaa;">&quot;).+(\'|&quot;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">/</span>i<span style="color: #aaa;">', '</span><span style="color: #aaa;">', $tags);
&nbsp;
}</span></pre></div></div>

<h3>3. Get child pages from a parents page path</h3>
<p>
I wrote this function just because it&#8217;s short and useful.  Getting all child pages based on a path has never been easier, pass in a path like &#8216;work/people&#8217; or &#8216;people&#8217; and you&#8217;ll get the child pages in an array.
</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color:#494F51;">/**
* Get an array of child pages based on a parents path
*
* @param {String} $path The path of the page (permalink slug) 
*/</span>
<span style="color: #fff;">function</span> get_child_pages_by_page_path<span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$path</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
    <span style="color: #81869F;">$page_path</span> <span style="color: #aaa;01">=</span> get_page_by_path<span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$path</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
    <span style="color: #81869F;">$pages</span> <span style="color: #aaa;01">=</span> get_pages<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">array</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #aaa;">'child_of'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #81869F;">$page_path</span><span style="color: #aaa;01">-&gt;</span><span style="color: #E5FFBE;">ID</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
    <span style="color: #fff;">return</span> <span style="color: #81869F;">$pages</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span></pre></div></div>

<p>That is all.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/07/24/my-top-3-custom-wordpress-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TaxiMe iPhone App Released!</title>
		<link>http://boedesign.com/blog/2010/05/10/taxime-iphone-app-released/</link>
		<comments>http://boedesign.com/blog/2010/05/10/taxime-iphone-app-released/#comments</comments>
		<pubDate>Mon, 10 May 2010 14:40:28 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=678</guid>
		<description><![CDATA[The wait is finally over. For those who use TaxiMe on their iPhone or iPod Touch &#8211; this is for you. As of Friday, May 7th, the TaxiMe iPhone app is now available! For those who aren&#8217;t familiar with TaxiMe, it&#8217;s an app that I had created a year ago that estimates your cab fare [...]]]></description>
			<content:encoded><![CDATA[<p>The wait is finally over.  For those who use <a href="http://www.taxime.ca/">TaxiMe</a> on their iPhone or iPod Touch &#8211; this is for you.  As of Friday, May 7th, the <a href="http://ww.taxime.ca/iphone">TaxiMe iPhone app</a> is now available!</p>
<p>For those who aren&#8217;t familiar with <a href="http://www.taxime.ca/">TaxiMe</a>, it&#8217;s an app that I had created a year ago that estimates your cab fare for various cities across Canada and the US.</p>
<p>The iPhone app comes loaded with cool features that will make your pants drop.  Check out the video, screenshots and more goodies at <a href="http://ww.taxime.ca/iphone">www.taxime.ca/iphone</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/05/10/taxime-iphone-app-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick JavaScript Templating</title>
		<link>http://boedesign.com/blog/2010/03/30/quick-javascript-templating/</link>
		<comments>http://boedesign.com/blog/2010/03/30/quick-javascript-templating/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 04:32:00 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=624</guid>
		<description><![CDATA[At some point, all JavaScript developers encounter a situation that involves spitting out a large chunk of HTML to the page. I&#8217;ve seen a lot of ways to do JavaScript templating, from storing it in the JavaScript file itself to having it returned to you from an ajax request. After reading various techniques on JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>At some point, all JavaScript developers encounter a situation that involves spitting out a large chunk of HTML to the page.  I&#8217;ve seen a lot of ways to do JavaScript templating, from storing it in the JavaScript file itself to having it returned to you from an ajax request. </p>
<p>After reading <a href="http://ejohn.org/blog/javascript-micro-templating/">various</a> <a href="http://github.com/janl/mustache.js/">techniques</a> on JavaScript templating, I decided to take <a href="http://ejohn.org/blog/javascript-micro-templating/">John Resig&#8217;s idea</a> of using script tags in your HTML.  The reason I liked it was because you had your HTML in your HTML file.  No funny stuff, just HTML where it belongs.  I also liked the idea that it cached the templates &#8211; very good stuff. Here is what one of John&#8217;s examples looked like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color: #aaa;01">&lt;</span>script type<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;text/html&quot;</span> id<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;user_tmpl&quot;</span><span style="color: #aaa;01">&gt;</span>
    <span style="color: #aaa;01">&lt;%</span> <span style="color: #fff;">for</span> <span style="color: #E5FFBE;01">&#40;</span> <span style="color: #fff;">var</span> i <span style="color: #aaa;01">=</span> <span style="color: #cc66cc;">0</span><span style="color: #aaa;01">;</span> i <span style="color: #aaa;01">&lt;</span> users.<span style="color: #E5FFBE;">length</span><span style="color: #aaa;01">;</span> i<span style="color: #aaa;01">++</span> <span style="color: #E5FFBE;01">&#41;</span> <span style="color: #E5FFBE;01">&#123;</span> <span style="color: #aaa;01">%&gt;</span>
        <span style="color: #aaa;01">&lt;</span>li<span style="color: #aaa;01">&gt;&lt;</span>a href<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;&lt;%=users[i].url%&gt;&quot;</span><span style="color: #aaa;01">&gt;&lt;%=</span>users<span style="color: #E5FFBE;01">&#91;</span>i<span style="color: #E5FFBE;01">&#93;</span>.<span style="color: #E5FFBE;">name</span><span style="color: #aaa;01">%&gt;&lt;/</span>a<span style="color: #aaa;01">&gt;&lt;/</span>li<span style="color: #aaa;01">&gt;</span>
    <span style="color: #aaa;01">&lt;%</span> <span style="color: #E5FFBE;01">&#125;</span> <span style="color: #aaa;01">%&gt;</span>
<span style="color: #aaa;01">&lt;/</span>script<span style="color: #aaa;01">&gt;</span></pre></div></div>

<p>Right off the bat, what do you think?  Does it feel weird?  Does it feel like someone just pissed in your corn flakes?  To be honest, I felt that way when I first saw it.  This could be partly due to the fact that I have <strong>never</strong> used a script tag with a type text/html before.  As John points out, the browser doesn&#8217;t know how to treat it, so these script tags with text/html are ignored, which makes it a perfect cloaking device for sneaking in templates. </p>
<p>I love that it&#8217;s HTML right in the HTML, but I didn&#8217;t like that it still had JavaScript wrapped around it (for loop). In my case, all I want is simple templating with some caching, I don&#8217;t want to perform JavaScript actions.  I would much rather pull in the template and then perform the JavaScript actions within the JavaScript file itself.</p>
<p>Ok, I&#8217;ll get down to the geeky stuff.  Here is what I came up with.  </p>
<p><a class="linkbutton" href="http://gist.github.com/349932">Check out the Gist</a></p>
<h2>Usage</h2>
<h3>HTML</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">// The following HTML is in a script tag and will not render out on the page</span>
<span style="color: #aaa;01">&lt;</span>script type<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;text/html&quot;</span> id<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;user_tpl&quot;</span><span style="color: #aaa;01">&gt;</span>
    <span style="color: #aaa;01">&lt;</span>div<span style="color: #aaa;01">&gt;</span>
        <span style="color: #aaa;01">&lt;</span>a href<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;&lt;%= url %&gt;&quot;</span><span style="color: #aaa;01">&gt;&lt;%=</span> user <span style="color: #aaa;01">%&gt;&lt;/</span>a<span style="color: #aaa;01">&gt;</span>
        <span style="color: #aaa;01">&lt;</span>span<span style="color: #aaa;01">&gt;&lt;%=</span> something_in_span <span style="color: #aaa;01">%&gt;&lt;/</span>span<span style="color: #aaa;01">&gt;</span>
    <span style="color: #aaa;01">&lt;/</span>div<span style="color: #aaa;01">&gt;</span>
<span style="color: #aaa;01">&lt;/</span>script<span style="color: #aaa;01">&gt;</span></pre></div></div>

<h3>JavaScript</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">// @param 1 - The id/selector of the &lt;script&gt; element holding the HTML template</span>
<span style="color:#494F51;">// @param 2 - The data object containing the replacements</span>
<span style="color:#494F51;">// If you have jQuery you need to pass a jQuery selector</span>
<span style="color:#494F51;">// or else just pass it an id (without #)</span>
<span style="color: #fff;">var</span> tpl <span style="color: #aaa;01">=</span> Template.<span style="color: #E5FFBE;">draw</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'user_tpl'</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span> user<span style="color: #aaa;01">:</span> <span style="color: #fff;">'bob'</span><span style="color: #aaa;01">,</span> url<span style="color: #aaa;01">:</span> <span style="color: #fff;">'http://cornflakes.com'</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span>tpl<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// outputs </span>
<span style="color:#494F51;">/*
&lt;div&gt;
        &lt;a href=&quot;'http://cornflakes.com&quot;&gt;bob&lt;/a&gt;
        &lt;span&gt;&lt;%= something_in_span %&gt;&lt;/span&gt;
&lt;/div&gt;
*/</span></pre></div></div>

<p>Oops, we forgot to run a replacement for <%= something_in_span %> &#8211; no problem.  We can re-template the same string, by calling the <em>append</em> method.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">tpl <span style="color: #aaa;01">=</span> Template.<span style="color: #E5FFBE;">append</span><span style="color: #E5FFBE;01">&#40;</span>tpl<span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span> something_in_span<span style="color: #aaa;01">:</span> <span style="color: #fff;">'Hi im text inside a span'</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span>
<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span>tpl<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// outputs</span>
<span style="color:#494F51;">/* 
&lt;div&gt;
        &lt;a href=&quot;'http://cornflakes.com&quot;&gt;bob&lt;/a&gt;
        &lt;span&gt;Hi im text inside a span&lt;/span&gt;
&lt;/div&gt;
*/</span></pre></div></div>

<p>There are a <a href="https://developer.mozilla.org/en/JavaScript_templates">lot of templating scripts</a> out there and by no means is this the all-in-one solution.  This is just my approach to making something that&#8217;s lightweight, easy to use and utilizes caching.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/03/30/quick-javascript-templating/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Delegate and Undelegate in jQuery 1.4.2</title>
		<link>http://boedesign.com/blog/2010/03/05/using-delegate-and-undelegate-in-jquery-1-4-2/</link>
		<comments>http://boedesign.com/blog/2010/03/05/using-delegate-and-undelegate-in-jquery-1-4-2/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 14:13:51 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=618</guid>
		<description><![CDATA[View the article at http://www.learningjquery.com/2010/03/using-delegate-and-undelegate-in-jquery-1-4-2]]></description>
			<content:encoded><![CDATA[<p>View the article at <a href="http://www.learningjquery.com/2010/03/using-delegate-and-undelegate-in-jquery-1-4-2">http://www.learningjquery.com/2010/03/using-delegate-and-undelegate-in-jquery-1-4-2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/03/05/using-delegate-and-undelegate-in-jquery-1-4-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hijacking JavaScript/jQuery methods</title>
		<link>http://boedesign.com/blog/2010/02/13/hijacking-javascriptjquery-methods/</link>
		<comments>http://boedesign.com/blog/2010/02/13/hijacking-javascriptjquery-methods/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 17:13:05 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=586</guid>
		<description><![CDATA[Some people often wonder: &#8220;Hey, when a user calls $(&#8216;body&#8217;).css(&#8216;background&#8217;, &#8216;something-awesome&#8217;); is there a way I can run some code before that happens?&#8221;. The answer is yes and it&#8217;s not very hard to do. If there is a name for this technique, I&#8217;m not aware of it so I&#8217;m just going to call it &#8220;hijacking&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>Some people often wonder: &#8220;Hey, when a user calls $(&#8216;body&#8217;).css(&#8216;background&#8217;, &#8216;something-awesome&#8217;); is there a way I can run some code before that happens?&#8221;.  The answer is yes and it&#8217;s not very hard to do.  If there is a name for this technique, I&#8217;m not aware of it so I&#8217;m just going to call it &#8220;hijacking&#8221;.</p>
<p><strong>UPDATE:</strong> I have an expanded version of this technique.  It includes a destroy() method to restore the original function/method.  Check out the <a href="http://gist.github.com/309803">gist on github</a>.</p>
<p>The process would be to create a function that returns the method along with some custom arguments that have been tampered with (scary, I know). Here is something basic to achieve this effect:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">jQuery.<span style="color: #E5FFBE;">fn</span>.<span style="color: #E5FFBE;">css</span> <span style="color: #aaa;01">=</span> <span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>_jQueryCSS<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
	<span style="color: #fff;">return</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
		<span style="color:#494F51;">// Run some custom code here and alter the arguments passed in</span>
		<span style="color: #fff;">return</span> _jQueryCSS.<span style="color: #E5FFBE;">call</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">this</span><span style="color: #aaa;01">,</span> arguments<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
	<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#40;</span>jQuery.<span style="color: #E5FFBE;">fn</span>.<span style="color: #E5FFBE;">css</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>This technique has been done before by other developers.  <a href="http://james.padolsey.com/">James Padolsey</a> implements this technique in his <a href="http://github.com/jamespadolsey/jQuery-Plugins/blob/master/cross-domain-ajax/jquery.xdomainajax.js"><em>cross-domain-ajax plugin</em></a> and over-writes the jQuery.ajax method.</p>
<p>Normally I would stay clear of methods under another namespace <em>(Don&#8217;t modify objects you don&#8217;t own -Nicholas Zakas)</em> but sometimes it makes sense to over-write them to add your own custom bits like in James&#8217; case (just be careful <img src='http://boedesign.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , he&#8217;s not hurting the current functionality of jQuery.ajax, he&#8217;s simply augmenting it. I&#8217;ve created a simple function to handle this type of hijacking.</p>
<h3>The hijack function</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">/**
* Allows you to alter with arguments before the method is actually called
* @param {Function} method A method/function to call after doing some tampering
* @param {Function} cb A callback that is passed the arguments for you to play with
*/</span>
<span style="color: #fff;">function</span> hijack<span style="color: #E5FFBE;01">&#40;</span>method<span style="color: #aaa;01">,</span> cb<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
	<span style="color:#494F51;">// A function needs to be passed or there will be hell to pay</span>
	<span style="color: #fff;">if</span><span style="color: #E5FFBE;01">&#40;</span>Object.<span style="color: #E5FFBE;">prototype</span>.<span style="color: #E5FFBE;">toString</span>.<span style="color: #E5FFBE;">call</span><span style="color: #E5FFBE;01">&#40;</span>cb<span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">!==</span> <span style="color: #fff;">&quot;[object Function]&quot;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
		<span style="color: #fff;">throw</span> <span style="color: #fff;">new</span> Error<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'An anonymous function must be passed as the second parameter!'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
	<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
	<span style="color: #fff;">return</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
		<span style="color:#494F51;">// Turn arguments into a true array</span>
		<span style="color: #fff;">var</span> args <span style="color: #aaa;01">=</span> Array.<span style="color: #E5FFBE;">prototype</span>.<span style="color: #E5FFBE;">slice</span>.<span style="color: #E5FFBE;">call</span><span style="color: #E5FFBE;01">&#40;</span>arguments<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
		<span style="color:#494F51;">// Call the copied method and pass it some 'tampered' arguments from our callback</span>
		<span style="color: #fff;">return</span> method.<span style="color: #E5FFBE;">apply</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">this</span><span style="color: #aaa;01">,</span> cb.<span style="color: #E5FFBE;">call</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">this</span><span style="color: #aaa;01">,</span> args<span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">||</span> args<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span></pre></div></div>

<h3>Usage</h3>
<p>Here is a simple use-case of how you would hijack the CSS method in jQuery.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">// Hijack the CSS method in jQuery</span>
jQuery.<span style="color: #E5FFBE;">fn</span>.<span style="color: #E5FFBE;">css</span> <span style="color: #aaa;01">=</span> hijack<span style="color: #E5FFBE;01">&#40;</span>jQuery.<span style="color: #E5FFBE;">fn</span>.<span style="color: #E5FFBE;">css</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>user_args<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
	<span style="color:#494F51;">// Now store the arguments passed in by the user</span>
	<span style="color: #fff;">var</span> args <span style="color: #aaa;01">=</span> user_args<span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color:#494F51;">// Do some checking and alter the arguments</span>
	<span style="color: #fff;">if</span><span style="color: #E5FFBE;01">&#40;</span>args<span style="color: #E5FFBE;01">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #E5FFBE;01">&#93;</span> <span style="color: #aaa;01">==</span> <span style="color: #fff;">'background'</span> <span style="color: #aaa;01">&amp;&amp;</span> args<span style="color: #E5FFBE;01">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #E5FFBE;01">&#93;</span> <span style="color: #aaa;01">==</span> <span style="color: #fff;">'this-will-be-replaced-with-green'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
		args<span style="color: #E5FFBE;01">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #E5FFBE;01">&#93;</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">'green'</span><span style="color: #aaa;01">;</span>
	<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
	<span style="color: #fff;">return</span> args<span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>So now when I call:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">$<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'body'</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">css</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'background'</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">'this-will-be-replaced-with-green'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>It will run through my hijacked function and replace &#8216;this-will-be-replaced-with-green&#8217; with &#8216;green&#8217;.  And voila, your background is green.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/02/13/hijacking-javascriptjquery-methods/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JavaScript: Configs for Different Environments</title>
		<link>http://boedesign.com/blog/2010/01/21/javascript-configs/</link>
		<comments>http://boedesign.com/blog/2010/01/21/javascript-configs/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 04:41:49 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=559</guid>
		<description><![CDATA[When you&#8217;re developing a website, you typically have a development version of the site running locally (localhost), a staging version and a production version. Normally you would set up something that would automatically grab the necessary settings to use for that specific environment. Here&#8217;s what my CakePHP&#8217;s config/database.php file looks like (PHP4 unfortunately). You&#8217;ll notice [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re developing a website, you typically have a development version of the site running locally (localhost), a staging version and a production version.  Normally you would set up something that would automatically grab the necessary settings to use for that specific environment.</p>
<p>Here&#8217;s what my <a href="http://cakephp.org">CakePHP&#8217;s</a> config/database.php file looks like (PHP4 unfortunately). You&#8217;ll notice I have a set of options for my development environment ($dev) and one for my production environment ($prod).  You&#8217;ll notice that when <em>new DATABASE_CONFIG()</em> is called, the __contruct method will fire and set $this->default to the appropriate environment that we&#8217;re in.  It does this by checking to see if the domain that we&#8217;re on is the production domain.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color: #fff;">class</span> DATABASE_CONFIG <span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
	<span style="color: #fff;">var</span> <span style="color: #81869F;">$default</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">array</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// overridden</span>
&nbsp;
	<span style="color:#494F51;">// debugging enabled - development site</span>
	<span style="color: #fff;">var</span> <span style="color: #81869F;">$dev</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">array</span><span style="color: #E5FFBE;01">&#40;</span>
		<span style="color: #aaa;">'driver'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'mysql'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'persistent'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'host'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'localhost'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'port'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'login'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'root'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'password'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'root'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'database'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'polly_pocket'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'schema'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'prefix'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'encoding'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span>
	<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color:#494F51;">// debugging disabled - live site</span>
	<span style="color: #fff;">var</span> <span style="color: #81869F;">$prod</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">array</span><span style="color: #E5FFBE;01">&#40;</span>
		<span style="color: #aaa;">'driver'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'mysql'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'persistent'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'host'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'localhost'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'port'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'login'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'root'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'password'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'asodij390284niusofdiuh3823_SUPER_SECURE!!!'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'database'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">'polly_pocket'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'schema'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'prefix'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'encoding'</span> <span style="color: #aaa;01">=&gt;</span> <span style="color: #aaa;">''</span>
	<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #fff;">function</span> __construct<span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
		<span style="color: #81869F;">$this</span><span style="color: #aaa;01">-&gt;</span><span style="color: #E5FFBE;">default</span> <span style="color: #aaa;01">=</span> <span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">str_replace</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #aaa;">'www.'</span><span style="color: #aaa;01">,</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$_SERVER</span><span style="color: #E5FFBE;01">&#91;</span><span style="color: #aaa;">'HTTP_HOST'</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">==</span> <span style="color: #aaa;">'prod-live-site.com'</span><span style="color: #E5FFBE;01">&#41;</span> ? <span style="color: #81869F;">$this</span><span style="color: #aaa;01">-&gt;</span><span style="color: #E5FFBE;">prod</span> <span style="color: #aaa;01">:</span> <span style="color: #81869F;">$this</span><span style="color: #aaa;01">-&gt;</span><span style="color: #E5FFBE;">dev</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span></pre></div></div>

<p>I&#8217;m sure there is a simpler way of doing this, maybe merging in the necessary key/values with <em>array_merge</em> instead of re-writing the entire array &#8211; but you get the idea.</p>
<p>Now I want to talk about accomplishing the same sort of idea but with JavaScript.  I recently had to work on a project that was largely front-end.  Different configurations had to be used for different environments. Here is what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">/**
* Fire it up and set options
* @constructor
*/</span>	
<span style="color: #fff;">var</span> SiteName <span style="color: #aaa;01">=</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
	<span style="color:#494F51;">/**
	* We check the config host to load in and over-write the default settings
	* @private
	*/</span>
	<span style="color: #fff;">function</span> setOptions<span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
		<span style="color: #fff;">var</span> clean_host <span style="color: #aaa;01">=</span> <span style="color: #E5FFBE;01">&#40;</span>window.<span style="color: #E5FFBE;">location</span>.<span style="color: #E5FFBE;">hostname</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">replace</span><span style="color: #E5FFBE;01">&#40;</span><span style="color:#494F51;">/www./</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">''</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
		<span style="color: #fff;">if</span><span style="color: #E5FFBE;01">&#40;</span>config<span style="color: #E5FFBE;01">&#91;</span>clean_host<span style="color: #E5FFBE;01">&#93;</span> <span style="color: #aaa;01">&amp;&amp;</span> <span style="color: #fff;">typeof</span><span style="color: #E5FFBE;01">&#40;</span>config<span style="color: #E5FFBE;01">&#91;</span>clean_host<span style="color: #E5FFBE;01">&#93;</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">===</span> <span style="color: #fff;">'object'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
			<span style="color: #fff;">this</span>.<span style="color: #E5FFBE;">opts</span> <span style="color: #aaa;01">=</span> jQuery.<span style="color: #E5FFBE;">extend</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#123;</span><span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span> config.<span style="color: #fff;">default</span><span style="color: #aaa;01">,</span> config<span style="color: #E5FFBE;01">&#91;</span>clean_host<span style="color: #E5FFBE;01">&#93;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
		<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
	<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
	<span style="color:#494F51;">/**
	* Here is where we define our default set of options and our options to be merged/over-written with
	* options specific to the host name
	* @private
	*/</span>
	<span style="color: #fff;">var</span> config <span style="color: #aaa;01">=</span> <span style="color: #E5FFBE;01">&#123;</span>
		<span style="color: #fff;">&quot;default&quot;</span> <span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#123;</span>
			cache<span style="color: #aaa;01">:</span> <span style="color: #fff;">true</span><span style="color: #aaa;01">,</span>
			backgroundAnimated<span style="color: #aaa;01">:</span> <span style="color: #fff;">true</span><span style="color: #aaa;01">,</span>
			allowIE6Users<span style="color: #aaa;01">:</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
			blowUpMachineIfIE6User<span style="color: #aaa;01">:</span> <span style="color: #fff;">true</span><span style="color: #aaa;01">,</span>
			storeURL<span style="color: #aaa;01">:</span> <span style="color: #fff;">''</span><span style="color: #aaa;01">,</span>
			blogURL<span style="color: #aaa;01">:</span> <span style="color: #fff;">''</span>
		<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span>
		<span style="color: #fff;">&quot;localhost&quot;</span> <span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#123;</span>
			backgroundAnimated<span style="color: #aaa;01">:</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
			blogURL <span style="color: #aaa;01">:</span> <span style="color: #fff;">&quot;http://localhost/blog&quot;</span><span style="color: #aaa;01">,</span>
			storeURL<span style="color: #aaa;01">:</span> <span style="color: #fff;">&quot;http://localhost/store&quot;</span>
		<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span>
		<span style="color: #fff;">&quot;prod-live.com&quot;</span> <span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#123;</span>
			blogURL <span style="color: #aaa;01">:</span> <span style="color: #fff;">&quot;http://prod-live.com/blog&quot;</span><span style="color: #aaa;01">,</span>
			storeURL <span style="color: #aaa;01">:</span> <span style="color: #fff;">'http://store.prod-live.com/main'</span>
		<span style="color: #E5FFBE;01">&#125;</span>
	<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color:#494F51;">/**
	* Once the configs are merged from setOptions, it puts it in this new clean options object
	* @public
	*/</span>
	<span style="color: #fff;">this</span>.<span style="color: #E5FFBE;">opts</span> <span style="color: #aaa;01">=</span> <span style="color: #E5FFBE;01">&#123;</span><span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">;</span>
&nbsp;
	setOptions.<span style="color: #E5FFBE;">call</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">this</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
<span style="color: #fff;">var</span> MySite <span style="color: #aaa;01">=</span> <span style="color: #fff;">new</span> SiteName<span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
console.<span style="color: #E5FFBE;">log</span><span style="color: #E5FFBE;01">&#40;</span>MySite.<span style="color: #E5FFBE;">opts</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>
All this is doing is running a check to see if the config exists for the domain that we&#8217;re on and if so, merge it with the defaults.  It&#8217;s important to note that this technique uses jQuery&#8217;s <em><a href="http://api.jquery.com/jQuery.extend/">extend</a></em> method. If we are on the <em>localhost</em> domain then our <em>SiteName.opts</em> will look now like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color: #E5FFBE;01">&#123;</span> 
	cache<span style="color: #aaa;01">:</span> <span style="color: #fff;">true</span><span style="color: #aaa;01">,</span>
	backgroundAnimated<span style="color: #aaa;01">:</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
	allowIE6Users<span style="color: #aaa;01">:</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
	blowUpMachineIfIE6User<span style="color: #aaa;01">:</span> <span style="color: #fff;">true</span><span style="color: #aaa;01">,</span>
	blogURL <span style="color: #aaa;01">:</span> <span style="color: #fff;">&quot;http://localhost/blog&quot;</span><span style="color: #aaa;01">,</span>
	storeURL<span style="color: #aaa;01">:</span> <span style="color: #fff;">&quot;http://localhost/store&quot;</span>
<span style="color: #E5FFBE;01">&#125;</span></pre></div></div>

<p>I&#8217;m sure storing config in an XML file and parsing it would be a logical approach as well. I&#8217;m open to any suggestions and thoughts on this approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2010/01/21/javascript-configs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keystrokes for jQuery</title>
		<link>http://boedesign.com/blog/2009/12/30/keystrokes-for-jquery/</link>
		<comments>http://boedesign.com/blog/2009/12/30/keystrokes-for-jquery/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 21:34:11 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[lab]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=493</guid>
		<description><![CDATA[Background First off, I hope everyone had fun over the holidays &#8211; I certainly did! With the release of jQuery 1.4 jQuery 1.4 on the horizon for early in the new year, I decided I wanted to try out some of its new functionality. I&#8217;ve been reading blogs of some of the jQuery core developers [...]]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>First off, I hope everyone had fun over the holidays &#8211; I certainly did! With the release of jQuery 1.4 <strike><a href="http://blog.jquery.com/2009/12/18/jquery-14-alpha-2-released/">jQuery 1.4 on the horizon</a> for early in the new year</strike>, I decided I wanted to try out some of its new functionality.  I&#8217;ve been reading blogs of some of the jQuery core developers and I found <a href="http://brandonaaron.net/blog/2009/03/26/special-events">a post by Brandon Aaron</a> to be very interesting.  He talks about adding custom events to jQuery using its special event API.  So I started making my custom event plugin and then realized that you could not bind the event to the same element twice.  Meaning, you can&#8217;t do this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">$<span style="color: #E5FFBE;01">&#40;</span>document<span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">bind</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'myevent'</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span> data<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'some data'</span><span style="color: #E5FFBE;01">&#93;</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
$<span style="color: #E5FFBE;01">&#40;</span>document<span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">bind</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'myevent'</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span> data<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'more data'</span><span style="color: #E5FFBE;01">&#93;</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>
So I tried using namespaces and it still would only fire the first event bind, not the second.  Wow, what a drag.  Then I found that Brandon wrote a <a href="http://brandonaaron.net/blog/2009/06/4/jquery-edge-new-special-event-hooks">new article</a> about two new methods that were added to the custom event hook: <em>add</em> and <em>remove</em> .  They both get fired on an event &#8220;bind&#8221; and &#8220;unbind&#8221; &#8211; perfect!  Uh oh, these two methods are not available in the latest stable release of jQuery (1.3.2).  They are only available in the release of jQuery 1.4!  So yes, unfortunately, <strong>you have to upgrade to <a href="http://jquery.com">jQuery 1.4.2 (or greater)</a></strong> to use this plugin.
</p>
<h3>What is Keystrokes? (Hot keys)</h3>
<p>
Keystrokes is a jQuery plugin that can capture a sequence of keys that are pressed.  It would come in pretty handy if you were doing a web application and wanted to allow the users to use hot keys.   It can even detect combo keys like &#8216;shift+ctrl&#8217;.  It would operate exactly as you type it.  In this case, the user would hold down <em>shift</em>, hit <em>ctrl</em> and the event you specified would fire.</p>
<p>This plugin has been tested in: Firefox 3.5, Safari 4, Opera 10 and IE 7+. It might work in IE 6 but I&#8217;m not promising anything.</p>
<p><a class="linkbutton" href="http://github.com/jboesch/Keystrokes/archives/master">Download It! (v2.0)</a></p>
<p><a class="demobutton" href="/demos/keystrokes">Demo It!</a></p>
<h3>Setting it up</h3>
<p>Make sure these are in the head of your document</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="color: #E5FFBE;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;google.load('jquery','1.4.2');&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery.keystrokes.min.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<h3>Adding a basic event</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">$<span style="color: #E5FFBE;01">&#40;</span>document<span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">bind</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'keystrokes'</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span>
	<span style="color:#494F51;">// The key pattern you set your element to listen for</span>
	keys<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'i'</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">'p'</span><span style="color: #E5FFBE;01">&#93;</span>				
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
	<span style="color:#494F51;">// Throw a notification to the user what keys they successfully typed</span>
	<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'You typed : &lt;em&gt;'</span> <span style="color: #aaa;01">+</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #E5FFBE;">keys</span>.<span style="color: #E5FFBE;">join</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">', '</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">+</span> <span style="color: #fff;">'&lt;/em&gt;'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>If this is done correctly, when the user hits <em>i</em> then <em>p</em>, you will get an alert notification. See the <a href="/demos/keystrokes">demo page</a> for a full the full effect.</p>
<h3>Adding a basic event that unbinds itself upon successful key strokes</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">$<span style="color: #E5FFBE;01">&#40;</span>document<span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">bind</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'keystrokes.SingleItem'</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span>
	<span style="color:#494F51;">// The key pattern you set your element to listen for	</span>
	keys<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'m'</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">'arrow down+r'</span><span style="color: #E5FFBE;01">&#93;</span>		
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
	<span style="color:#494F51;">// Unbind this event after it's been successfully typed</span>
	$<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">this</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">unbind</span><span style="color: #E5FFBE;01">&#40;</span>event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #fff;">name</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
	<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'You typed : &lt;em&gt;'</span> <span style="color: #aaa;01">+</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #E5FFBE;">keys</span>.<span style="color: #E5FFBE;">join</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">', '</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">+</span> <span style="color: #fff;">'&lt;/em&gt;.  You cannot type it again because it has been unbound!'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<h3>Adding a more complex notification that contains multiple key sets</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">$<span style="color: #E5FFBE;01">&#40;</span>document<span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">bind</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'keystrokes.OtherNameSpace'</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#91;</span>		
	<span style="color: #E5FFBE;01">&#123;</span>
		<span style="color:#494F51;">// Define typed keys in sequence</span>
		keys<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'h'</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">'shift+p+o'</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #aaa;01">,</span>
		<span style="color:#494F51;">// If false, this will not execute the main callback, only the &quot;success&quot; callback on this stack item</span>
		proceedToMainCallback<span style="color: #aaa;01">:</span> <span style="color: #fff;">false</span><span style="color: #aaa;01">,</span>
		<span style="color:#494F51;">// The callback bound to this specific stack item</span>
		success<span style="color: #aaa;01">:</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
			<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'You typed : &lt;em&gt;'</span> <span style="color: #aaa;01">+</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #E5FFBE;">keys</span>.<span style="color: #E5FFBE;">join</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">', '</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">+</span> <span style="color: #fff;">'&lt;/em&gt;.  This has &quot;proceedToMainCallback: false&quot; so it will not call the main callback for this bound event.&lt;/em&gt;'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
		<span style="color: #E5FFBE;01">&#125;</span>
&nbsp;
	<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span>
	<span style="color: #E5FFBE;01">&#123;</span>
		<span style="color:#494F51;">// Define typed keys in sequence</span>
		keys<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'j'</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">'k'</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #aaa;01">,</span>
		<span style="color:#494F51;">// The callback bound to this specific stack item</span>
		success<span style="color: #aaa;01">:</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
			<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'You typed : &lt;em&gt;'</span> <span style="color: #aaa;01">+</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #E5FFBE;">keys</span>.<span style="color: #E5FFBE;">join</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">', '</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">+</span> <span style="color: #fff;">'&lt;/em&gt;'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
		<span style="color: #E5FFBE;01">&#125;</span>
	<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span>
	<span style="color: #E5FFBE;01">&#123;</span>
		<span style="color:#494F51;">// Define typed keys in sequence</span>
		keys<span style="color: #aaa;01">:</span> <span style="color: #E5FFBE;01">&#91;</span><span style="color: #fff;">'arrow up+comma+k'</span><span style="color: #aaa;01">,</span> <span style="color: #cc66cc;">1</span><span style="color: #aaa;01">,</span> <span style="color: #cc66cc;">2</span><span style="color: #aaa;01">,</span> <span style="color: #cc66cc;">3</span><span style="color: #E5FFBE;01">&#93;</span><span style="color: #aaa;01">,</span>
		<span style="color:#494F51;">// The callback bound to this specific stack item</span>
		success<span style="color: #aaa;01">:</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
			<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'You typed : &lt;em&gt;'</span> <span style="color: #aaa;01">+</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #E5FFBE;">keys</span>.<span style="color: #E5FFBE;">join</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">', '</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">+</span> <span style="color: #fff;">'&lt;/em&gt;'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
		<span style="color: #E5FFBE;01">&#125;</span>
	<span style="color: #E5FFBE;01">&#125;</span>			
<span style="color:#494F51;">// The main callback that gets called with every successful key sequence</span>
<span style="color:#494F51;">// This can be skipped by setting 'proceedToMainCallback: false' as an option in a stack item</span>
<span style="color: #E5FFBE;01">&#93;</span><span style="color: #aaa;01">,</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span>event<span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>	
		<span style="color:#494F51;">// Maybe get the whole stack.. if you want?</span>
		<span style="color: #fff;">var</span> stack <span style="color: #aaa;01">=</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack</span><span style="color: #aaa;01">;</span>
		<span style="color:#494F51;">// Get the specific stack item that was successfully typed</span>
		<span style="color: #fff;">var</span> data_keys <span style="color: #aaa;01">=</span> event.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">stack_item</span>.<span style="color: #E5FFBE;">keys</span>.<span style="color: #E5FFBE;">join</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">', '</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
		<span style="color:#494F51;">// Shout it out!</span>
		<span style="color: #fff;">alert</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'&lt;span&gt;This is the main callback for selected successful keystrokes. To skip this call, just set &quot;proceedToMainCallback: false&quot; in your stack item: &lt;/span&gt; '</span> <span style="color: #aaa;01">+</span> data_keys<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #E5FFBE;01">&#125;</span>
<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<h3>Key set options</h3>
<p>Below is a list of all possible options that go with a key set.</p>
<table>
<thead>
<tr>
<th>Key</th>
<th>Default Value</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>keys</td>
<td>[] (required)</td>
<td>Array</td>
<td>The specified key sequence you wish to listen for.  Example: ['shift+ctrl', 'o', 1, 5, 'space']</td>
</tr>
<tr>
<td>customValidation</td>
<td>null</td>
<td>Function</td>
<td>You can run your own validation and decide whether the user completed the key sequence the way you wanted them to.  See the <a href="/demos/keystrokes">demo</a> for an example.</td>
</tr>
<tr>
<td>success</td>
<td>null</td>
<td>Function</td>
<td>If you are using an array of key sets as seen in the advanced example, you can specify a callback unique to that key set.</td>
</tr>
<tr>
<td>proceedToMainCallback</td>
<td>true</td>
<td>Boolean</td>
<td>If you&#8217;ve specified a &#8216;success&#8217; callback (see above) and you don&#8217;t want to have the main callback executed, set this to false. This is more commonly used in the advanced example.</td>
</tr>
</tbody>
</table>
<h3>String list</h3>
<p>Below is a table of all possible key strings you can enter in your <em>keys</em> array. </p>
<table>
<thead>
<tr>
<th>Key Code</th>
<th>String</th>
</tr>
</thead>
<tbody>
<tr>
<td>8</td>
<td>backspace</td>
</tr>
<tr>
<td>9</td>
<td>tab</td>
</tr>
<tr>
<td>13</td>
<td>enter</td>
</tr>
<tr>
<td>16</td>
<td>shift</td>
</tr>
<tr>
<td>17</td>
<td>ctrl</td>
</tr>
<tr>
<td>18</td>
<td>alt</td>
</tr>
<tr>
<td>19</td>
<td>pause/break</td>
</tr>
<tr>
<td>20</td>
<td>caps lock</td>
</tr>
<tr>
<td>27</td>
<td>escape</td>
</tr>
<tr>
<td>33</td>
<td>page up</td>
</tr>
<tr>
<td>32</td>
<td>space</td>
</tr>
<tr>
<td>34</td>
<td>page down</td>
</tr>
<tr>
<td>35</td>
<td>end</td>
</tr>
<tr>
<td>36</td>
<td>home</td>
</tr>
<tr>
<td>37</td>
<td>arrow left</td>
</tr>
<tr>
<td>38</td>
<td>arrow up</td>
</tr>
<tr>
<td>39</td>
<td>arrow right</td>
</tr>
<tr>
<td>40</td>
<td>arrow down</td>
</tr>
<tr>
<td>44</td>
<td>print screen</td>
</tr>
<tr>
<td>45</td>
<td>insert</td>
</tr>
<tr>
<td>46</td>
<td>delete</td>
</tr>
<tr>
<td>48</td>
<td>0</td>
</tr>
<tr>
<td>49</td>
<td>1</td>
</tr>
<tr>
<td>50</td>
<td>2</td>
</tr>
<tr>
<td>51</td>
<td>3</td>
</tr>
<tr>
<td>52</td>
<td>4</td>
</tr>
<tr>
<td>53</td>
<td>5</td>
</tr>
<tr>
<td>54</td>
<td>6</td>
</tr>
<tr>
<td>55</td>
<td>7</td>
</tr>
<tr>
<td>56</td>
<td>8</td>
</tr>
<tr>
<td>57</td>
<td>9</td>
</tr>
<tr>
<td>59</td>
<td>semi-colon</td>
</tr>
<tr>
<td>61</td>
<td>add</td>
</tr>
<tr>
<td>65</td>
<td>a</td>
</tr>
<tr>
<td>66</td>
<td>b</td>
</tr>
<tr>
<td>67</td>
<td>c</td>
</tr>
<tr>
<td>68</td>
<td>d</td>
</tr>
<tr>
<td>69</td>
<td>e</td>
</tr>
<tr>
<td>70</td>
<td>f</td>
</tr>
<tr>
<td>71</td>
<td>g</td>
</tr>
<tr>
<td>72</td>
<td>h</td>
</tr>
<tr>
<td>73</td>
<td>i</td>
</tr>
<tr>
<td>74</td>
<td>j</td>
</tr>
<tr>
<td>75</td>
<td>k</td>
</tr>
<tr>
<td>76</td>
<td>l</td>
</tr>
<tr>
<td>77</td>
<td>m</td>
</tr>
<tr>
<td>78</td>
<td>n</td>
</tr>
<tr>
<td>79</td>
<td>o</td>
</tr>
<tr>
<td>80</td>
<td>p</td>
</tr>
<tr>
<td>81</td>
<td>q</td>
</tr>
<tr>
<td>82</td>
<td>r</td>
</tr>
<tr>
<td>83</td>
<td>s</td>
</tr>
<tr>
<td>84</td>
<td>t</td>
</tr>
<tr>
<td>85</td>
<td>u</td>
</tr>
<tr>
<td>86</td>
<td>v</td>
</tr>
<tr>
<td>87</td>
<td>w</td>
</tr>
<tr>
<td>88</td>
<td>x</td>
</tr>
<tr>
<td>89</td>
<td>y</td>
</tr>
<tr>
<td>90</td>
<td>z</td>
</tr>
<tr>
<td>91</td>
<td>left window key</td>
</tr>
<tr>
<td>92</td>
<td>right window key</td>
</tr>
<tr>
<td>93</td>
<td>select key</td>
</tr>
<tr>
<td>96</td>
<td>numpad 0</td>
</tr>
<tr>
<td>97</td>
<td>numpad 1</td>
</tr>
<tr>
<td>98</td>
<td>numpad 2</td>
</tr>
<tr>
<td>99</td>
<td>numpad 3</td>
</tr>
<tr>
<td>100</td>
<td>numpad 4</td>
</tr>
<tr>
<td>101</td>
<td>numpad 5</td>
</tr>
<tr>
<td>102</td>
<td>numpad 6</td>
</tr>
<tr>
<td>103</td>
<td>numpad 7</td>
</tr>
<tr>
<td>104</td>
<td>numpad 8</td>
</tr>
<tr>
<td>105</td>
<td>numpad 9</td>
</tr>
<tr>
<td>106</td>
<td>multiply</td>
</tr>
<tr>
<td>107</td>
<td>add</td>
</tr>
<tr>
<td>109</td>
<td>subtract</td>
</tr>
<tr>
<td>110</td>
<td>decimal point</td>
</tr>
<tr>
<td>111</td>
<td>divide</td>
</tr>
<tr>
<td>112</td>
<td>f1</td>
</tr>
<tr>
<td>113</td>
<td>f2</td>
</tr>
<tr>
<td>114</td>
<td>f3</td>
</tr>
<tr>
<td>115</td>
<td>f4</td>
</tr>
<tr>
<td>116</td>
<td>f5</td>
</tr>
<tr>
<td>117</td>
<td>f6</td>
</tr>
<tr>
<td>118</td>
<td>f7</td>
</tr>
<tr>
<td>119</td>
<td>f8</td>
</tr>
<tr>
<td>120</td>
<td>f9</td>
</tr>
<tr>
<td>121</td>
<td>f10</td>
</tr>
<tr>
<td>122</td>
<td>f11</td>
</tr>
<tr>
<td>123</td>
<td>f12</td>
</tr>
<tr>
<td>144</td>
<td>num lock</td>
</tr>
<tr>
<td>145</td>
<td>scroll lock</td>
</tr>
<tr>
<td>182</td>
<td>my computer (multimedia keyboard)</td>
</tr>
<tr>
<td>183</td>
<td>my calculator (multimedia keyboard)</td>
</tr>
<tr>
<td>186</td>
<td>semi-colon</td>
</tr>
<tr>
<td>187</td>
<td>equal sign</td>
</tr>
<tr>
<td>188</td>
<td>comma</td>
</tr>
<tr>
<td>189</td>
<td>dash</td>
</tr>
<tr>
<td>190</td>
<td>period</td>
</tr>
<tr>
<td>191</td>
<td>forward slash</td>
</tr>
<tr>
<td>192</td>
<td>tilde</td>
</tr>
<tr>
<td>219</td>
<td>open bracket</td>
</tr>
<tr>
<td>220</td>
<td>back slash</td>
</tr>
<tr>
<td>221</td>
<td>close bracket</td>
</tr>
<tr>
<td>222</td>
<td>single quote</td>
</tr>
<tr>
<td>224</td>
<td>command</td>
</tr>
</tbody>
</table>
<p>You can also add/modify to the string list by adding this line above your event calls:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">// Simply supply the key code and the string you wish to use.</span>
$.<span style="color: #E5FFBE;">extend</span><span style="color: #E5FFBE;01">&#40;</span>$.<span style="color: #E5FFBE;">event</span>.<span style="color: #E5FFBE;">special</span>.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">codes</span><span style="color: #aaa;01">,</span> <span style="color: #E5FFBE;01">&#123;</span> <span style="color: #cc66cc;">13</span> <span style="color: #aaa;01">:</span> <span style="color: #fff;">'my enter key'</span> <span style="color: #E5FFBE;01">&#125;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>If you have something like Firebug and you want to do some debugging, you can add this line above your event calls:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">$.<span style="color: #E5FFBE;">event</span>.<span style="color: #E5FFBE;">special</span>.<span style="color: #E5FFBE;">keystrokes</span>.<span style="color: #E5FFBE;">debug</span> <span style="color: #aaa;01">=</span> <span style="color: #fff;">true</span><span style="color: #aaa;01">;</span></pre></div></div>

<p>
Now, if you open up your console, you will be able to see what keys the script thinks you&#8217;re typing. If you hit a key that&#8217;s not registered in our string list, it will output that key code to the console and notify you.  This makes it easy for you to do your own customizations.
</p>
<p>By default, Keystrokes ignores when you&#8217;re typing keys in any input/textarea field.  If you want to track keys on an input field you have to bind it directly to that input element.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2009/12/30/keystrokes-for-jquery/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Dissecting jQuery.noConflict</title>
		<link>http://boedesign.com/blog/2009/12/07/dissecting-jquery-noconflict/</link>
		<comments>http://boedesign.com/blog/2009/12/07/dissecting-jquery-noconflict/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 07:57:33 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=455</guid>
		<description><![CDATA[Most jQuery users love it for its easy CSS selectors, DOM manipulation and slick effects. We don&#8217;t normally think about what happens behind the scenes when we call our favorite jQuery methods, we just naturally expect they work as desired. I&#8217;m going to start off my dissecting and explaining a relatively simple method called noConflict. [...]]]></description>
			<content:encoded><![CDATA[<p>Most jQuery users love it for its easy CSS selectors, DOM manipulation and slick effects.  We don&#8217;t normally think about what happens behind the scenes when we call our favorite jQuery methods, we just naturally expect they work as desired. </p>
<p>
I&#8217;m going to start off my dissecting and explaining a relatively simple method called <em>noConflict</em>. If you want to follow along you can download a <a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.js&#038;downloadBtn=">development copy of jQuery</a>.  As of this post, we&#8217;re using version 1.3.2.
</p>
<p>Open up the file and go to line 19.  You&#8217;ll see the code below</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color:#494F51;">// Map over jQuery in case of overwrite</span>
_jQuery <span style="color: #aaa;01">=</span> window.<span style="color: #E5FFBE;">jQuery</span><span style="color: #aaa;01">,</span>
<span style="color:#494F51;">// Map over the $ in case of overwrite</span>
_$ <span style="color: #aaa;01">=</span> window.$<span style="color: #aaa;01">,</span>
&nbsp;
jQuery <span style="color: #aaa;01">=</span> window.<span style="color: #E5FFBE;">jQuery</span> <span style="color: #aaa;01">=</span> window.$ <span style="color: #aaa;01">=</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span> selector<span style="color: #aaa;01">,</span> context <span style="color: #E5FFBE;01">&#41;</span> <span style="color: #E5FFBE;01">&#123;</span>
	<span style="color:#494F51;">// The jQuery object is actually just the init constructor 'enhanced'</span>
	<span style="color: #fff;">return</span> <span style="color: #fff;">new</span> jQuery.<span style="color: #E5FFBE;">fn</span>.<span style="color: #E5FFBE;">init</span><span style="color: #E5FFBE;01">&#40;</span> selector<span style="color: #aaa;01">,</span> context <span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span></pre></div></div>

<p>Right away you&#8217;ll notice that 2 variables are created with an underscore, this is to hold a reference to the old namespaces that might be in use.  For example, if we load the Prototype JavaScript framework before jQuery, it uses the $ function, so jQuery makes a copy of that reference before it over writes it with it&#8217;s own below.  Now if we ever want to get back to the Prototype $ reference, we can get at it with the _$ variable.</p>
<p>Note:  If you load the jQuery library before Prototype, there is no need to call <em>noConflict()</em>. But you will have to set up a new way to target elements &#8211; see below.</p>
<p>This now brings us to the <em>noConflict</em> method.  If you go to line 619 you&#8217;ll see our lovely method:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">noConflict<span style="color: #aaa;01">:</span> <span style="color: #fff;">function</span><span style="color: #E5FFBE;01">&#40;</span> deep <span style="color: #E5FFBE;01">&#41;</span> <span style="color: #E5FFBE;01">&#123;</span>
	window.$ <span style="color: #aaa;01">=</span> _$<span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #fff;">if</span> <span style="color: #E5FFBE;01">&#40;</span> deep <span style="color: #E5FFBE;01">&#41;</span>
		window.<span style="color: #E5FFBE;">jQuery</span> <span style="color: #aaa;01">=</span> _jQuery<span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #fff;">return</span> jQuery<span style="color: #aaa;01">;</span>
<span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">,</span></pre></div></div>

<p>Remember that _$ variable that get&#8217;s set at the top of the jQuery file?  There it is!  If you remember, we copied an existing $ reference (Prototype) into the _$ variable to get at it later if we wanted.  In this method we return the $ sign to it&#8217;s owner, which in this case is the Prototype $ function. It&#8217;s set by the line that says <em>window.$ = _$</em>. We use the <em>window</em> prefix to reference the global namespace.  Now we want our $ function back so we can use it for Prototype, you can do this by calling the <em>noConflict()</em> method:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;">jQuery.<span style="color: #E5FFBE;">noConflict</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
$<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'someid'</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">hide</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// The $ function is now using Prototype to target elements</span>
jQuery<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'#someid'</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">hide</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color:#494F51;">// The jQuery function is used instead of the $ function</span></pre></div></div>

<p>But I hate typing jQuery each time I target some elements, what can I do? Simple.  Since the <em>noConflict()</em> method returns the jQuery object, we can store that in a variable.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color: #fff;">var</span> jQ <span style="color: #aaa;01">=</span> jQuery.<span style="color: #E5FFBE;">noConflict</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
$<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'someid'</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">hide</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// The $ function is now using Prototype to target elements</span>
jQ<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'#someid'</span><span style="color: #E5FFBE;01">&#41;</span>.<span style="color: #E5FFBE;">hide</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color:#494F51;">// The jQ function after we set it above</span></pre></div></div>

<p>
 The <em>noConflict()</em> method also accepts one boolean parameter called <em>deep</em>.  For the most part, this does not need to be set unless you&#8217;re working in a high conflict environment.  For example, you might have 2 versions of jQuery running or something else using the jQuery namespace (god I hope not).  That might be grounds for setting the <em>deep</em> parameter to true. For example you could move the jQuery object to an entirely new namespace:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="color: #E5FFBE;"><span style="color: #aaa;01">&lt;</span>script type<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;text/javascript&quot;</span> src<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;js/jquery-1.3.1.js&quot;</span><span style="color: #aaa;01">&gt;&lt;/</span>script<span style="color: #aaa;01">&gt;</span>
<span style="color: #aaa;01">&lt;</span>script type<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;text/javascript&quot;</span> src<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;js/prototype.js&quot;</span><span style="color: #aaa;01">&gt;&lt;/</span>script<span style="color: #aaa;01">&gt;</span>
<span style="color: #aaa;01">&lt;</span>script type<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;text/javascript&quot;</span> src<span style="color: #aaa;01">=</span><span style="color: #fff;">&quot;js/jquery-1.3.2.js&quot;</span><span style="color: #aaa;01">&gt;&lt;/</span>script<span style="color: #aaa;01">&gt;</span>
<span style="color: #fff;">var</span> myNamespace <span style="color: #aaa;01">=</span> <span style="color: #E5FFBE;01">&#123;</span><span style="color: #E5FFBE;01">&#125;</span><span style="color: #aaa;01">;</span>
myNamespace.<span style="color: #E5FFBE;">query</span> <span style="color: #aaa;01">=</span> jQuery.<span style="color: #E5FFBE;">noConflict</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">true</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
myNamespace.<span style="color: #E5FFBE;">query</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'#my-id-with-new-version-of-jquery'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// This will execute using jQuery 1.3.2</span>
jQuery<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'#my-id-with-old-version-of-jquery'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// This will execute using jQuery 1.3.1</span>
$<span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">'my-id-with-prototype'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span> <span style="color:#494F51;">// This will execute using Prototype</span></pre></div></div>

<p><a href="/sandbox/noconflict.html">View the the demo</a> I made of <em>jQuery.noConflict(true)</em> in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2009/12/07/dissecting-jquery-noconflict/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Serverside JavaScript Minifying</title>
		<link>http://boedesign.com/blog/2009/12/02/serverside-javascript-minifying/</link>
		<comments>http://boedesign.com/blog/2009/12/02/serverside-javascript-minifying/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 10:52:20 +0000</pubDate>
		<dc:creator>Jordan Boesch</dc:creator>
				<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://boedesign.com/?p=429</guid>
		<description><![CDATA[JSMIN is a JavaScript minifying library that was founded by Douglas Crockford. Minifying is the act of taking your JavaScript code and stripping out unneeded white space and comments to reduce file size. Douglas Crockford offers a set of packages in common server side languages to accomplish this &#8211; whether it be PHP, Python or [...]]]></description>
			<content:encoded><![CDATA[<p>JSMIN is a JavaScript minifying library that was founded by <a href="http://www.crockford.com/javascript/jsmin.html">Douglas Crockford</a>.  Minifying is the act of taking your JavaScript code and stripping out unneeded white space and comments to reduce file size.  Douglas Crockford offers a set of packages in common server side languages to accomplish this &#8211; whether it be <a href="http://code.google.com/p/jsmin-php/">PHP</a>, <a href="http://www.crockford.com/javascript/jsmin.py.txt">Python</a> or <a href="http://inconspicuous.org/projects/jsmin/jsmin.java">Java</a>.  It&#8217;s important to note that <a href="http://developer.yahoo.com/yui/compressor/">there</a> <a href="http://www.askapache.com/online-tools/js-compress/">are</a> <a href="http://code.google.com/closure/compiler/">other</a> JavaScript compression and compiling tools out there,  I am just giving an example of one that I use frequently.</p>
<p>I&#8217;m going to show you what I&#8217;ve done with the PHP package of JSMIN.  </p>
<p>If you download the <a href="http://code.google.com/p/jsmin-php/">PHP package</a> you&#8217;ll see how to use is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color: #aaa; font-weight: bold;">&lt;?</span>
<span style="color: #fff;">require</span> <span style="color: #aaa;">'jsmin-1.1.1.php'</span><span style="color: #aaa;01">;</span>
<span style="color: #fff;">echo</span> JSMin<span style="color: #aaa;01">::</span><span style="color: #E5FFBE;">minify</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">file_get_contents</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #aaa;">'example.js'</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
<span style="color: #aaa; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
Brilliant!  It will output a bunch of ugly code right?  Well who cares if it&#8217;s ugly, it&#8217;s only for production.  What I wanted to do with this is have something that takes multiple JavaScript files, minifies them and then outputs it to 1 JavaScript file that&#8217;s all tightly bundled.  Here&#8217;s how to do that.
</p>
<p>First, you&#8217;ll want to make sure that the jsmin-1.1.1.php class is included.  Then write a function to handle the minifying of multiple JavaScript files.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color: #aaa; font-weight: bold;">&lt;?</span>
<span style="color:#494F51;">/********************************************
* Handle an array of JavaScript files, minify them and output them into 1 file.
* @param string $final_file The path to the final JavaScript file that will contain all minified contents
* @param array $js_files The array of JavaScript files to minify
* @return string The script tag including the path to the final JavaScript file
*/</span>
<span style="color: #fff;">function</span> drawMinJS<span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$final_file</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$js_files</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
&nbsp;
	<span style="color: #81869F;">$contents</span> <span style="color: #aaa;01">=</span> <span style="color: #aaa;">''</span><span style="color: #aaa;01">;</span>
	<span style="color: #fff;">foreach</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$js_files</span> <span style="color: #fff;">as</span> <span style="color: #81869F;">$src</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#123;</span>
		<span style="color:#494F51;">// We use a semicolon at the end to safely separate the files</span>
		<span style="color: #81869F;">$contents</span> <span style="color: #aaa;01">.=</span> JSMin<span style="color: #aaa;01">::</span><span style="color: #E5FFBE;">minify</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #fff;">file_get_contents</span><span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$src</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #E5FFBE;01">&#41;</span> <span style="color: #aaa;01">.</span> <span style="color: #aaa;">';'</span><span style="color: #aaa;01">;</span>
	<span style="color: #E5FFBE;01">&#125;</span>
	<span style="color: #81869F;">$str</span> <span style="color: #aaa;01">=</span> <span style="color: #aaa;">'&lt;script type=&quot;text/javascript&quot; src=&quot;'</span> <span style="color: #aaa;01">.</span> <span style="color: #81869F;">$final_file</span> <span style="color: #aaa;01">.</span> <span style="color: #aaa;">'&quot;&gt;&lt;/script&gt;'</span><span style="color: #aaa;01">;</span>
	file_put_contents<span style="color: #E5FFBE;01">&#40;</span><span style="color: #81869F;">$final_file</span><span style="color: #aaa;01">,</span> <span style="color: #81869F;">$contents</span><span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
&nbsp;
	<span style="color: #fff;">return</span> <span style="color: #81869F;">$str</span><span style="color: #aaa;01">;</span>
&nbsp;
<span style="color: #E5FFBE;01">&#125;</span>
<span style="color: #aaa; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then put the snippet below where ever you would like the script tag to appear.  Sometimes people put it in the &lt;head&gt; of the document and sometimes right before the &lt;/body&gt;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="color: #E5FFBE;"><span style="color: #aaa; font-weight: bold;">&lt;?</span>
<span style="color:#494F51;">// Not to worry, this outputs the actual &lt;script&gt; tag</span>
<span style="color: #fff;">echo</span> drawMinJS<span style="color: #E5FFBE;01">&#40;</span>
	<span style="color: #aaa;">'js/finalfile.min.js'</span><span style="color: #aaa;01">,</span>
	<span style="color: #fff;">array</span><span style="color: #E5FFBE;01">&#40;</span>
		<span style="color: #aaa;">'js/global.js'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'js/thickbox.js'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'js/twitter.js'</span><span style="color: #aaa;01">,</span>
		<span style="color: #aaa;">'js/events.js'</span>
	<span style="color: #E5FFBE;01">&#41;</span>
<span style="color: #E5FFBE;01">&#41;</span><span style="color: #aaa;01">;</span>
<span style="color: #aaa; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
Voila! The function will take all those JavaScript files in that array, minify them and put them into finalfile.min.js.<br />
I also recommend reading &#8220;<a href="http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/">The best way to load external JavaScript</a>&#8221; by Nicholas C. Zakas if you&#8217;re looking for more ways to improve performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://boedesign.com/blog/2009/12/02/serverside-javascript-minifying/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
