<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Raymond Camden&apos;s Blog - jQuery</title>
			<link>http://www.raymondcamden.com/index.cfm</link>
			<description>Raymond Camden&apos;s personal blog covering jQuery, Mobile, ColdFusion, and Web Development.</description>
			<language>en-us</language>
			<pubDate>Fri, 24 May 2013 16:10:41 -0400</pubDate>
			<lastBuildDate>Tue, 05 Mar 2013 09:07:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>raymondcamden@gmail.com</managingEditor>
			<webMaster>raymondcamden@gmail.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>raymondcamden@gmail.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>Simple Reverse Geocoding Example</title>
				<link>http://www.raymondcamden.com/index.cfm/2013/3/5/Simple-Reverse-Geocoding-Example</link>
				<description>
				
				Have you ever seen a web site that seemed to know where you were located? I&apos;m not talking about a map, but the actual &lt;i&gt;name&lt;/i&gt; of the location? This is done with a process called &quot;Reverse Geocoding.&quot; Whereas geocoding refers to translating a human-readable address into a longitude/latitude pair, reverse geocoding is, well, the opposite of that. Given a longitude/latitude pair, what would be the description of that location. In this blog post I&apos;ll show a simple example of this process. My example application will attempt to report the city and state you live in.Once again I&apos;ll be making use of Google for my example. One of the services of the Google Maps API is geocoding as well as &lt;a href=&quot;https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding&quot;&gt;reverse geocoding&lt;/a&gt;. Their reverse geocode API needs a longitude and latitude, we can get that easily enough using Geolocation. Here is a snippet of code that begins the process:

&lt;script src=&quot;https://gist.github.com/cfjedimaster/5091026.js&quot;&gt;&lt;/script&gt;

Please note that in this demo, if the user doesn&apos;t support geolocation I&apos;m not going to do anything else. They won&apos;t get an error though and won&apos;t know what they are missing. 

Once we have the longitude and latitude, we then fire off a request to the geocode service.

&lt;script src=&quot;https://gist.github.com/cfjedimaster/5091031.js&quot;&gt;&lt;/script&gt;

As with our initial geolocation support, all I care about here is a success. If anything goes wrong, I don&apos;t care and I just ignore it. 

So, here comes the difficult part. The result was from the geocode call is fairly complex. You get an array of results ordered by the quality of the match. If you check the &lt;a href=&quot;https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding&quot;&gt;docs&lt;/a&gt;, you can see an example of this. Each individual result is also fairly complex. You get an array of address parts that represent, obviously, parts of an address. If you read the &quot;Address Component Types&quot; section of the docs, you can see an explanation of the types of address parts. Each part has one or more of these types applied as a tag. 

Based on my reading of the spec, I determined I could get the city when the tag was &quot;locality&quot; and the state when the tag was &quot;administrative_area_level_1.&quot; This is US-centric and I&apos;ve not done any testing yet with other countries.

Given that I knew which tags to look for, I decided to work with the first result and see if I could match those tags:

&lt;script src=&quot;https://gist.github.com/cfjedimaster/5091064.js&quot;&gt;&lt;/script&gt;

Again, if there isn&apos;t a match I don&apos;t throw an error. Since this is simply window dressing for the site it doesn&apos;t really matter if we don&apos;t get a match. Want to see this in action? Check out the demo below. 

&lt;a href=&quot;http://raymondcamden.com/demos/2013/mar/4/test.html&quot;&gt;&lt;img src=&quot;http://www.raymondcamden.com/images/icon_128.png&quot; title=&quot;Demo, Baby&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Tue, 05 Mar 2013 09:07:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2013/3/5/Simple-Reverse-Geocoding-Example</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Presentation: Browser Tools for Debugging</title>
				<link>http://www.raymondcamden.com/index.cfm/2013/2/22/Presentation-Browser-Tools-for-Debugging</link>
				<description>
				
				A &lt;b&gt;huge&lt;/b&gt; thank you goes to &lt;a href=&quot;http://www.tricedesigns.com/&quot;&gt;Andrew Trice&lt;/a&gt; for spending &lt;i&gt;hours&lt;/i&gt; on polishing and editing a video of my last presentation. He uploaded it to Youtube and now you guys can watch it as well. I&apos;m proud of this presentation so I hope it is helpful. As always, criticism is welcome. You can download the demos and slide deck here: 

&lt;a href=&quot;https://github.com/cfjedimaster/BrowserToolsForDebuggingAndProfit&quot;&gt;https://github.com/cfjedimaster/BrowserToolsForDebuggingAndProfit&lt;/a&gt;

&lt;iframe width=&quot;601&quot; height=&quot;338&quot; src=&quot;http://www.youtube.com/embed/Zz0VyMPdKEg?rel=0&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;
				</description>
				
				
				<category>Mobile</category>
				
				<category>Development</category>
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Fri, 22 Feb 2013 14:32:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2013/2/22/Presentation-Browser-Tools-for-Debugging</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Google Map/Directions Mashup</title>
				<link>http://www.raymondcamden.com/index.cfm/2013/2/18/Google-MapDirections-Mashup</link>
				<description>
				
				A while back I ran into an interesting problem with Google Maps. I was booking travel for a conference and needing to find the closest Marriott to the conference location. I didn&apos;t know the area very well so seeing a few addresses meant nothing to me. I figured Google Maps would be able to help me, but I could only plot one location at a time. (To be clear, I bet there is a way to plot multiple addresses, I just couldn&apos;t find it.) I then tried the Directions service. That too was only able to work with two addresses. I ended up entering 4 or 5 Marriott addresses and just trying to remember which one seemed shorter. To get around this, I built a simple application that lets you enter up to five starting addresses and a destination. It then plots driving directions and reports on the total distances for each. It also reports on which starting address is the best.The code for this application is relatively simple. I began by creating a simple Bootstrapped UI:

&lt;img src=&quot;http://www.raymondcamden.com/images/screenshot64.png&quot; /&gt;

I built in a bit of basic validation logic (which isn&apos;t too exciting) and then began work on the real meat of the application. Here&apos;s the entire JavaScript library behind the demo.

&lt;script src=&quot;https://gist.github.com/cfjedimaster/4977674.js&quot;&gt;&lt;/script&gt;

The interesting part begins around line 47. I geocode the destination address first to ensure it is valid. (I should probably do the same for the starting addresses as well.) Once I have a valid destination address, I map it, and begin a loop for each of the starting addresses. I make use of the &lt;a href=&quot;https://developers.google.com/maps/documentation/directions/&quot;&gt;Google Directions API&lt;/a&gt; to get and plot the directions from each starting address to the destination. This API is very cool (I&apos;ve blogged on it a bunch already), but modifying the display of the plot is a bit broken. Unless you want to handle all of the drawing yourself, you can&apos;t really (nicely) do small modifications, like changing the initial pushpin. (Which is documented to work, but does not.) 

Here&apos;s a quick example:

&lt;img src=&quot;http://www.raymondcamden.com/images/screenshot65.png&quot; /&gt;

You can try this yourself by hitting the demo button below.

&lt;a href=&quot;http://www.raymondcamden.com/demos/2013/feb/13/test.html&quot;&gt;&lt;img src=&quot;http://www.raymondcamden.com/images/icon_128.png&quot; title=&quot;Demo, Baby&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Mon, 18 Feb 2013 07:56:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2013/2/18/Google-MapDirections-Mashup</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>jQuery Example: Related, hidden selects</title>
				<link>http://www.raymondcamden.com/index.cfm/2013/2/8/jQuery-Example-Related-hidden-selects</link>
				<description>
				
				This request came in from a reader and I thought I&apos;d share it. I&apos;m not sure how re-usable it is for others, nor will I promise that it is The Best jQuery Code ever. (Far from it.) But on the off chance the example helps others, I wanted to post it.The reader had a simple request - set up related selects. I&apos;ve done this many times before so that part wasn&apos;t such a big deal. The only twist here is that he wanted the related selects to only show up when selected. 

His data supported, at most, three levels of options. But not every option would have three levels.

Because of this restriction, I decided to simply build my code to support three levels total and not build some high level, super cool, infinite deep relation type doohicky. As it stands, if I were to see 4 or more related selects on a form I&apos;d run away screaming.

&lt;img src=&quot;http://www.raymondcamden.com/images/tumblr_mgoqplvaqr1s373hwo1_500.gif&quot; /&gt;

Let&apos;s then start off with the HTML portion of the code.

&lt;script src=&quot;https://gist.github.com/cfjedimaster/4741263.js&quot;&gt;&lt;/script&gt;

You can see my three drop downs in the form block. The second and third drop downs are wrapped in DIV tags and hidden with CSS. Notice too that I&apos;ve added in the drop downs with no options. The idea here is that I&apos;ll use jQuery to hide and manipulate the contents of these tags. Let&apos;s look at the code now.

&lt;script src=&quot;https://gist.github.com/cfjedimaster/4741285.js&quot;&gt;&lt;/script&gt;

First up is a set of code used to cache my selectors. This is a general jQuery best practice. 

I then have change handlers for my two drop downs. (Remember, we only support three levels max. As I said, you could possibly build something fancy that supported N levels, but I&apos;m one of those crazy people who like simple solutions.) In general, both handlers are pretty similar.

They get the value from the drop down and then automatically hide anything &quot;beneath&quot; them. For the first drop down this is both of the related divs. For the second it is only the third. 

If a value was selected, an AJAX call is fired off. Typically this would be to a dynamic datasource. To keep things simple I just built some basic static JSON files that return arrays. I can then take that array and populate a select. Note that I abstracted that logic in populateSelect().

And that&apos;s pretty much it. Not rocket science, but maybe useful. You can play with the demo by clicking the ginormous button below. This was tested in Chrome, Firefox, and IE10.

&lt;a href=&quot;http://www.raymondcamden.com/demos/2013/feb/8/test.html&quot;&gt;&lt;img src=&quot;http://www.raymondcamden.com/images/icon_128.png&quot; title=&quot;Demo, Baby&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Fri, 08 Feb 2013 13:12:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2013/2/8/jQuery-Example-Related-hidden-selects</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>A walkthrough of some basic jQuery help</title>
				<link>http://www.raymondcamden.com/index.cfm/2013/1/28/A-walkthrough-of-some-basic-jQuery-help</link>
				<description>
				
				Over the past few days I&apos;ve exchanged emails with David. He had a simple jQuery-based application and he ran into some issues with it. His problems were, I thought, fairly common and I thought it might make sense for me to share what he did and what I suggested. We went through a couple of iterations of this so you can see how the project evolved over time. One thing I want to point out. David writes his code differently than I do (as I expect everyone does!). When he asked for help, I tried to make my help/suggestions as minimally invasive as possible. I was tempted to just delete all his code and do it &quot;my way&quot;, but I thought working within his &apos;style&apos; would be less jarring. Ok, with that out of the way, let&apos;s look at his code.David wanted a form that - when changed - would automatically sum up the values. He included a mix of form fields for testing purposes and wanted to sum those fields with a class name of foo. Here is what he started with.

&lt;script src=&quot;https://gist.github.com/4661708.js&quot;&gt;&lt;/script&gt;

Right away I saw that his initial selector, #addhours, didn&apos;t actually match anything. Notice his form was actually identified as my-form. He made the same mistake with another selector as well. Don&apos;t forget that you can use Google Chrome Dev Tools to look into your DOM and ensure you&apos;re looking for the right IDs. If your DOM is big and messy (like my beard), you can also hop into the console and try selecting what your code is. In the screen shot below, look at the difference between a bad and good match.

&lt;img src=&quot;http://www.raymondcamden.com/images/screenshot60.png&quot; /&gt;

Continuing on - I then pointed out that his code wasn&apos;t within the $(document).ready block. Most people who write jQuery tend to &lt;i&gt;always&lt;/i&gt; include this by reflex, but if you don&apos;t, you can run into problems with your selectors. His code was trying to find DOM items before the DOM was actually done loading. You can mentally translate the $(document).ready block as &quot;I&apos;m ready to get down to business.&quot; In most cases, you almost always want to have your code in there. (Not always of course!) 

I modified his code a bit and returned this to him.

&lt;script src=&quot;https://gist.github.com/4615163.js&quot;&gt;&lt;/script&gt;

You can see the $(document).ready block as well as the corrected selectors. David then came back to me with this:

&lt;blockquote&gt;
I was able to use your example and it works great.  But how can the jquery be modified so that it runs on page load.  It works fine on the change event for the field with class &quot;foo&quot;.  I also wanted it to fire once the page is loaded so that any fields on screen go ahead and get counted. 
&lt;/blockquote&gt;

As he noted, the code handled &lt;i&gt;changes&lt;/i&gt; just fine. But if the form loaded with some initial values (he was using ColdFusion to generate the HTML dynamically) then the &apos;total&apos; field wasn&apos;t updated until he changed a value. 

To handle this, I simply broke out the event handler doing the math and added a call to it in the $(document).ready block. In the code sample below, notice too I modified one of the form fields to have an initial value.

&lt;script src=&quot;https://gist.github.com/4631529.js&quot;&gt;&lt;/script&gt;

Once again, he was good to go. Until today. He modified his code a bit so that users could dynamically add form fields to the page. He wanted his &apos;sum&apos; logic to apply to these new fields as well. Here is what he had:

&lt;script src=&quot;https://gist.github.com/4661751.js&quot;&gt;&lt;/script&gt;

For this, the issue came down to this original code...

$summands.on(&apos;change&apos;, doAdds);

This says: &quot;At the time of running, attach a change event handler to $summands.&quot; If you remember, summands was run like so,   $summands = $form.find(&apos;.foo&apos;), in document.ready. It was run &lt;b&gt;immediately and one time&lt;/b&gt;. So it found stuff once, and then was done. It didn&apos;t know the user had (possibly) added more stuff. 

So first I changed the code to this:

$(&quot;#addhours&quot;).on(&quot;change&quot;, &quot;.foo&quot;, doAdds);

This says: On any change event inside the addhours form, if it (the thing throwing the event) &lt;b&gt;&lt;i&gt;also&lt;/i&gt;&lt;/b&gt; has a foo class, run doAdds. This is a &quot;live&quot; event (in fact, the API used to be called live) and will find new stuff.

The next fix was to remove the code that created summands on startup. You will see it inside of doAdds now. You can&apos;t make it once and cache it since it can change. Here is the version I sent back to him.

&lt;script src=&quot;https://gist.github.com/4660804.js&quot;&gt;&lt;/script&gt;

A little messy - but again - I was trying to work within his original code.

Anyway, I hope this post-mortem is useful to others.
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Mon, 28 Jan 2013 21:58:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2013/1/28/A-walkthrough-of-some-basic-jQuery-help</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Testing Globalization Support in PhoneGap 2.2</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/11/15/Testing-Globalization-Support-in-PhoneGap-22</link>
				<description>
				
				One of the more interesting new features in PhoneGap 2.2 iss the inclusion of a globalization plugin into the core of the SDK itself. This plugin has many features, but basically boils down to the ability to get the user&apos;s locale and language as well as being able to format numbers and dates. You can read the &lt;a href=&quot;http://docs.phonegap.com/en/2.2.0/cordova_globalization_globalization.md.html#Globalization&quot;&gt;full API docs&lt;/a&gt; for a complete guide, but I thought it would be interesting to build a simple proof of concept application that tested out this feature.I began with a simple idea. I&apos;d build an application that showed a table of product orders. There would be a column of dates, a column of order quantities, and an order of profit. This would give me a chance to demonstrate localization formatting of dates, numbers, and currencies. (Note that you can also do percentages as well. Again, check the docs!)

The HTML of my application was essentially just a div to support the injected report. Here is the JavaScript code that generates the report. I&apos;m using fake data as opposed to doing an AJAX request.

&lt;script src=&quot;https://gist.github.com/4082217.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

The result is pretty much as you would expect:

&lt;img src=&quot;http://www.raymondcamden.com/images/iOS Simulator Screen shot Nov 15, 2012 3.48.18 PM.png&quot; /&gt;

So - obviously the solution would be to make use of the API to format those columns. Unfortunately, here is where I ran into a snag. The API calls are all asynchronous. Ouch. Normally this isn&apos;t a big deal, I can handle callbacks, but we&apos;ve got N*3 cells of data all of which must be fired off asynchronously. In order to create our display we have to wait for these to finish.

Luckily there is a solution for this. Unluckily, for me, it involves jQuery Deferreds. This is one of the most powerful features of jQuery and also the one that makes my brain bleed. 

The solution comes down to creating an array of deferred promises, essentially, an array of things that finish in an unknown time. This array can then be passed to the jQuery when() and then() operators which handles all of the chaining/waiting/collecting for me. Ready? Here&apos;s the updated coded.

&lt;script src=&quot;https://gist.github.com/4082258.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Taking this step by step, what I&apos;ve done is this:

&lt;ol&gt;
&lt;li&gt;First, create the array that will store the promises.
&lt;li&gt;For each order, we create three deferred objects. One for the date. One for the quantity. And one for the price. Notice that the Globalization API supports a failure callback if it can&apos;t format the value. For this application I simply then default to the original value.
&lt;li&gt;I pass this to when(), and then use then() to begin working with my result.
&lt;li&gt;The arguments passed to then match the array of data I sent in. So the first 3 array elements relate to the first order. And so on. You can see the math I use in the fakeOrder loop to handle getting the right value from that array.
&lt;/ol&gt;

So did it work? Hell yes. Here is the result on my iOS simulator:

&lt;img src=&quot;http://www.raymondcamden.com/images/iOS Simulator Screen shot Nov 15, 2012 4.51.16 PM.png&quot; /&gt;

How did I test other locales? I went into my iOS Simulator settings, went to General, then International. At first I changed the Language value. That was wrong. I then noticed Region Format. That&apos;s the one you want to tweak:

&lt;img src=&quot;http://www.raymondcamden.com/images/iOS Simulator Screen shot Nov 15, 2012 4.50.46 PM.png&quot; /&gt;

I set it to French/France, closed my application and reran it, and got...

&lt;img src=&quot;http://www.raymondcamden.com/images/iOS Simulator Screen shot Nov 15, 2012 4.50.02 PM.png&quot; /&gt;

Pretty sweet, right? Now my PhoneGap application will display data in a format that makes sense to my end users. For numbers and currencies this may not be a big deal, but for dates it can be huge.

So - obviously the asynchronous nature of the code may be a bit problematic. But it&apos;s not something you can&apos;t overcome. If I were building this for a client I&apos;d build a JavaScript function that would handle this behind the scenes so they could do one call and a callback and be done with it. That would keep my getData() function much cleaner.

I&apos;ve attached a zip of my code to this blog entry. Enjoy.
				</description>
				
				
				<category>Mobile</category>
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Thu, 15 Nov 2012 17:04:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/11/15/Testing-Globalization-Support-in-PhoneGap-22</guid>
				
				
				<enclosure url="http://www.raymondcamden.com/enclosures/www2.zip" length="6795863" type="application/zip"/>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Data-driven Edge Animate projects</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/11/7/Datadriven-Edge-Animate-projects</link>
				<description>
				
				This week I demonstrated &lt;a href=&quot;http://html.adobe.com/edge/animate/&quot;&gt;Edge Animate&lt;/a&gt; to two cities in Texas as part of the Create the Web tour. Animations are not something I typically spend a lot of time thinking about, but I was grateful for an opportunity to show off what I think is a pretty cool program. At my first presentation, an attendee asked if Edge Animate supported data-driven animations. Hear is what I told him, and a look at a simple proof of concept.First - I told him that - in my mind - Edge Animate would be fine for data-driven projects, but only those that involved at least &lt;i&gt;some&lt;/i&gt; timeline based animation. That distinction may not make sense if you&apos;ve never used Edge Animate before. (I encourage you to download it via the link I shared above.) Edge Animate has a timeline that allows you to create animations over time. So for example my animation may do one thing from time 0 to time 1, and something else from time 1 to time 4. Integrating data with that should not be a problem. Imagine a simple weather animation. You may have parts to a thermometer fly in and come together like a puzzle. At the end, you display the current temperature.

The other example though would be an animation that is entirely data driven with no concept of &quot;time&quot;. An  example of this could be a simple pie chart that updates with live data, using animation to smoothly modify the pie slices. 

Obviously there&apos;s a gray area here and each project is different. Edge Animate also makes it easy to add interactivity to your projects so assuming that only projects with crap flying around makes sense isn&apos;t exactly fair either. Hopefully you get my drift here. 

With all that aside, let&apos;s look at a real demo. This won&apos;t be the most exciting Edge Animation you will see but it will hopefully illustrate the concept. For my demo I want to build an animation of a box that comes onto the screen and then just displays some text. The data-driven part will come from the fact that the text we display will need to come from a server-side file. You could imagine this being a ColdFusion, PHP, or some other script. For now though I just made it simple text.

I began by creating the animation and using static text. I used two seconds for the &apos;rectangle fly in&apos; animation and a second for the text to fade in.

&lt;img src=&quot;http://www.raymondcamden.com/images/screenshot37.png&quot; /&gt;

You can see this in action here: &lt;a href=&quot;http://www.raymondcamden.com/demos/2012/nov/7/v1/Untitled-2.html&quot;&gt;http://www.raymondcamden.com/demos/2012/nov/7/v1/Untitled-2.html&lt;/a&gt;. Note that I didn&apos;t bother setting up any preloader or providing accessible support. I&apos;m trying to keep this as simple as possible.

So now we have a basic animation done. We could tweak it to make it prettier. Modify the flow of the movement. Etc. But let&apos;s focus on making this data driven. In order to do that I need to first stop the animation from running automatically. My Ajax call may be slow so I don&apos;t want anything to run until I&apos;ve gotten my data back. Turning off the autostart is as simple as clicking on the Stage in Edge Animate and disabling it in properties.

&lt;img src=&quot;http://www.raymondcamden.com/images/screenshot38.png&quot; /&gt;

That was easy. The next part was a bit more difficult. In a normal application, I&apos;d listen for a DOM ready type event before doing whatever I need to do. But I know that Edge Animate also has its own events. I assumed - but wasn&apos;t sure - that there was an event I could listen in for and trigger my own custom logic. With the Stage still selected, I clicked the Actions icon:

&lt;img src=&quot;http://www.raymondcamden.com/images/screenshot39.png&quot; /&gt;

I noticed the creationComplete event and assumed that was a safe bet. Going with the assumption that all my logic would go in here, I used the helpful menu of actions to guide how I&apos;d write the code. I first selected &quot;Set Element Text&quot; and Animate added the following block:

&lt;script src=&quot;https://gist.github.com/4033453.js?file=gistfile1.txt&quot;&gt;&lt;/script&gt;

My text symbol was already named Text so I left the code as is. The portion that read &quot;NewText&quot; would be changed to the result of my Ajax call, but for now, I just wanted to ensure this worked. 

Next, I knew that I&apos;d want to start the animation itself. This too was easy. I selected the &quot;Play from&quot; action and specified a value of 0.

&lt;script src=&quot;https://gist.github.com/4033487.js?file=gistfile1.txt&quot;&gt;&lt;/script&gt;

At this point, I noticed something odd. When I tested my animation, the text in the rectangle did not update. Something told me though that it may be the event I used. I don&apos;t have proof of this (but I&apos;ll find out), but I was willing to bet that the when Edge Animate ran the animation in the tool itself, it never fired a creationComplete event. I saved my work instead, ran it in the browser, and saw everything worked as expected.

You can view this version here: &lt;a href=&quot;http://www.raymondcamden.com/demos/2012/nov/7/v2/Untitled-2.html&quot;&gt;http://www.raymondcamden.com/demos/2012/nov/7/v2/Untitled-2.html&lt;/a&gt;. You should now see it run the animation and use the new text as opposed to the word &quot;STATIC&quot;. 

Woot! So now my work was almost done. I made a copy of my work and opened it in another editor. The file Untitled-2_edgeActions.js contained the event handler and custom logic I had created. Here it is as Edge Animate exported it.

&lt;script src=&quot;https://gist.github.com/4033520.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

And here it is after I modified it to do an Ajax call.

&lt;script src=&quot;https://gist.github.com/4033535.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Pretty simple, right? You can run the final version here: &lt;a href=&quot;http://www.raymondcamden.com/demos/2012/nov/7/v3/Untitled-2.html&quot;&gt;http://www.raymondcamden.com/demos/2012/nov/7/v3/Untitled-2.html&lt;/a&gt;
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Wed, 07 Nov 2012 07:10:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/11/7/Datadriven-Edge-Animate-projects</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Stop using jQuery!! (all the time...)</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/10/23/Stop-using-jQuery-all-the-time</link>
				<description>
				
				I apologize for the link bait. I feel bad doing it. But - at least you know I&apos;m not a slimy SEO person and there is something useful in this article. ;)

Yesterday I &lt;a href=&quot;http://www.raymondcamden.com/index.cfm/2012/10/22/Simple-POC--Dynamically-select-an-element-from-a-list-and-skip-the-last-chosen&quot;&gt;blogged&lt;/a&gt; a simple little POC (Proof of Concept) that demonstrated adding a class to a random list element. As I said in the post yesterday, this was rather trivial code, but I wanted to share it because of the use of LocalStorage.

About an hour or so after I posted it, something began to bug me. I opened up the template and looked at the Network requests in Chrome dev tools.&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip144.png&quot; /&gt;

Just in case it isn&apos;t obvious, let me break it down for you. My HTML document was a bit over 1.5K. The jQuery library, compressed, was 33K. To be fair, my HTML was limited to what was required for the demo, but even if I increased the size of my document ten fold, it would still be less than the size of the jQuery library.

Don&apos;t get me wrong. I love jQuery. I &lt;i&gt;love&lt;/i&gt; what it has done for my development, my career, and my skin care. (Um, ok.) That being said, you don&apos;t &lt;i&gt;need&lt;/i&gt; jQuery as much as you think. Consider what my demo did:

&lt;ul&gt;
&lt;li&gt;Run a function when the DOM was loaded.
&lt;li&gt;Find some DOM items via CSS selectors.
&lt;li&gt;Remove a class from one thing, add it to another.
&lt;/ul&gt;

That&apos;s it. Surely I could do that without an entire library, right? First, I switched to listening for the DOMContentLoaded event.

&lt;script src=&quot;https://gist.github.com/3938884.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

For finding DOM items, I made use of &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/DOM/Document.querySelector&quot;&gt;querySelector&lt;/a&gt; and &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/DOM/Document.querySelectorAll&quot;&gt;querySelectorAll&lt;/a&gt;. 

&lt;script src=&quot;https://gist.github.com/3938897.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

For adding and removing classes, I made use of the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/DOM/element.classList&quot;&gt;classList&lt;/a&gt; property.

&lt;script src=&quot;https://gist.github.com/3938904.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

After these changes, the size of my application was pretty much next to nothing.

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip145.png&quot; /&gt;

Here is the complete template. Any questions?

&lt;script src=&quot;https://gist.github.com/3938913.js?file=gistfile1.html&quot;&gt;&lt;/script&gt;
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Tue, 23 Oct 2012 08:49:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/10/23/Stop-using-jQuery-all-the-time</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Building a Parse.com Enabled PhoneGap App - Part 2</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/9/25/Building-a-Parsecom-Enabled-PhoneGap-App--Part-2</link>
				<description>
				
				Sorry it took me a few days to get part 2 done. My hope is to get a few more entries done this week with a wrap up by next week. If you haven&apos;t read the first part, follow the Related Entries links below. Hopefully you&apos;re up to date and ready to go.In the previous blog entry I discussed the purpose of the series and what the goal was for the application I&apos;m building. The Cow Tip Line will allow you to both report and find cows ready for tipping. While not really an enterprise-level application, I&apos;m going to touch on aspects that I think will be applicable and helpful for all. 

There are two main technologies I&apos;ll be using for this application. They are &lt;a href=&quot;http://www.phonegap.com&quot;&gt;PhoneGap&lt;/a&gt; and &lt;a href=&quot;http://www.parse.com&quot;&gt;Parse&lt;/a&gt;. In this blog entry I&apos;m going to focus on the set up steps you&apos;ll need to make use of these technologies. 

Let&apos;s tackle the easy one first - PhoneGap. In order to circumvent the normal &lt;a href=&quot;http://docs.phonegap.com/en/2.0.0/guide_getting-started_index.md.html&quot;&gt;Getting Started&lt;/a&gt; process, I&apos;m just going to make use of &lt;a href=&quot;http://build.phonegap.com&quot;&gt;PhoneGap Build&lt;/a&gt;. PhoneGap Build is a free service that can take care of building out your native applications for you. Using PhoneGap at the command line is easy. Using PhoneGap Build is even easier. Signing up requires an Adobe or Github username, and for more details, I encourage you to read my Adobe Developer Connection article: &lt;a href=&quot;http://www.adobe.com/devnet/phonegap/articles/phonegap-build-levels-up.html&quot;&gt;PhoneGap Build Levels Up&lt;/a&gt;. I&apos;m not even going to worry about this aspect till later in the series so you can entirely skip this part for now if you want.

Parse&apos;s set up is slightly more complex so the rest of the entry will focus on that process. If you plan on following along and building your own copy of the application, you will need to follow these steps. (And do leave me a comment below if you plan on doing this - I&apos;d just like to know who is paying attention. ;)

First, navigate over to the Parse &lt;a href=&quot;https://parse.com/#signup&quot;&gt;signup&lt;/a&gt;.

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip131.png&quot; /&gt;

Note that signup is 100% free and doesn&apos;t require a credit card. After signing up, you are immediately dropped into a form to create a new application:

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip132.png&quot; /&gt;

Now this part is a bit odd - after naming your first application, you get brought back to the main Parse site. Just click the Dashboard link, which will bring you to a listing of your apps - all one of them:

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip133.png&quot; /&gt;

Click the application and you&apos;re brought into the detail view of the application. Here you will want to make note of the keys to the left. There are two important values here, the Application ID and the JavaScript Key.

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip134.png&quot; /&gt;

You won&apos;t need them just yet, but keep in mind where they are. Finally, click Downloads.

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip135.png&quot; /&gt;

You will be interested in the JavaScript section. Development links to a readable copy of the JavaScript API whereas Production leads to the minified version. The blank project isn&apos;t necessarily blank. It actually has a bit of CSS and some code that automatically creates an object for you. You want to grab the minified version of the JavaScript library and drop it into a new folder.

I&apos;ve set up a folder for the root of my application called cowtipline. In there is a folder called &quot;js&quot; where I saved the Parse JavaScript library. I then made a very simple index.html file:

&lt;script src=&quot;https://gist.github.com/3784129.js&quot;&gt; &lt;/script&gt;

I&apos;ve provided my own Application ID and JavaScript Keys above. (And in case you&apos;re wondering about the safety of that - stay with me - the last entry in the series will discuss how we can secure those values.)

If you run this - nothing will happen. But we&apos;ve got the basics done and can now start coding. I&apos;ve also set up the GitHub repository here: &lt;a href=&quot;https://github.com/cfjedimaster/CowTipLine&quot;&gt;https://github.com/cfjedimaster/CowTipLine&lt;/a&gt;

In the next entry I&apos;ll begin setting up the UI based on the mockups from the previous &lt;a href=&quot;http://www.raymondcamden.com/index.cfm/2012/9/21/Building-a-Parsecom-Enabled-PhoneGap-App--Part-1&quot;&gt;entry&lt;/a&gt;. I&apos;ll also add the first set of logic to let you start creating Tips from the application.
				</description>
				
				
				<category>Mobile</category>
				
				<category>Development</category>
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Tue, 25 Sep 2012 14:39:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/9/25/Building-a-Parsecom-Enabled-PhoneGap-App--Part-2</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Example of a Parse.com JavaScript application with offline support</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/9/14/Example-of-a-Parsecom-JavaScript-application-with-offline-support</link>
				<description>
				
				This morning I got a seemingly innocent question from a reader:

&lt;blockquote&gt;
Came across your blog post on Parse + PhoneGap and wanted to get your opinion on the following use-case for that combo...

I&apos;ve been exploring the possibilities of an app that essentially has a web form (similar to the contact form you&apos;ve got right here, actually) that would store the resulting data via Parse. The reason being...it would be important that the app would allow a form to submit, even if there wasn&apos;t an active Internet connection available.

So, just wanted your thoughts on whether I am looking in the right direction to accomplish this. Don&apos;t have much experience in the way of iOS apps, but have to start somewhere, right?
&lt;/blockquote&gt;I replied to him with a basic outline:

&lt;ul&gt;
&lt;li&gt;When you submit the form, hit Parse if you are online, hit WebSQL if not.
&lt;li&gt;When the application starts, see if you have data in WebSQL, and if you are online, push it to parse.
&lt;/ul&gt;

That seemed simple enough, but I figured I might as well build a real demo just to prove it can be done. This is what I came up with. It&apos;s got some issues (don&apos;t we all?) but it covers the basics. As always though I&apos;m open to suggestions for how this could be done better.

I began by creating the layout for an application. Since the reader just mentioned a form, I built the entire application around one form. I decided to build a simple UFO Report Form. It has a field for the number of UFOs, your name, and the description. I didn&apos;t make use of any UI framework but instead directed my incredible design skills at the task.

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip121.png&quot; /&gt;

Here&apos;s the HTML behind the form, just in case your curious:

&lt;script src=&quot;https://gist.github.com/3722917.js?file=gistfile1.html&quot;&gt;&lt;/script&gt;

Fancy, eh? Ok, now it&apos;s time to get into the code. I&apos;m going to tackle this piece by piece, and it may get a bit confusing, but I&apos;ll post the entire file in one chunk at the end for your perusal. 

Whether or not we are online, we need to set up the database. This is done via the WebSQL API. While this API is deprecated, it is fully supported in PhoneGap and works great in Chrome, the main browser I use for testing.

&lt;script src=&quot;https://gist.github.com/3722935.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

I&apos;m not going to detail how this works as I&apos;ve covered it before (&lt;a href=&quot;http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support&quot;&gt;Example of PhoneGap&apos;s Database Support&lt;/a&gt;), but even if this is brand new to you I think you can get the idea.

After the database is set up, our application needs to upload any existing data to Parse. We&apos;re going to skip that now though and look at the basic form handling aspects of the code. 

I wrote a function to wrap my check for online/offline support. Why? I wrote this demo &lt;i&gt;without&lt;/i&gt; actually building it as a PhoneGap application. It should work fine when converting into a mobile application, and at that point my wrapper function can be modified to use PhoneGap&apos;s API, but for my initial testing I just wanted to use the navigator.onLine property. Having a wrapper also let me easily add in a hack (see the commented out line) to test being offline.

&lt;script src=&quot;https://gist.github.com/3722958.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

If we are online, I need to initialize Parse support. I won&apos;t repeat what is already covered in the &lt;a href=&quot;https://parse.com/docs/js_guide&quot;&gt;Parse JavaScript Guide&lt;/a&gt;. Instead, this is just an example of how I initialize Parse.com with my API keys and define an object type I&apos;m calling SightingObject (as in UFO sighting).

&lt;script src=&quot;https://gist.github.com/3722975.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Now let&apos;s look at the form handler. Remember, this needs to either save to Parse or to the database.

&lt;script src=&quot;https://gist.github.com/3722987.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

This code block is a bit large, so let&apos;s break it down. The first thing I do is grab the values from the form. As mentioned in the comments, it would probably make sense to do some basic validation. Screw validation - this is a demo. Next I do some basic UI stuff to let the user know that exciting things are happening in the background (although in theory, not as exciting as the UFO in front of them). Then we have the online/offline block. I&apos;ve taken the Parse logic out into another function that I&apos;ll show in a moment. The other part of the conditional simply writes it out to the database. In both cases we run a function, resetForm, that handles resetting my UI. 

Here is saveToParse. Notice how darn easy this is. Just in case it isn&apos;t obvious - this is all the code I need to store my data, permanently, in the cloud. It would only be easier if the Parse.com engineers fed me grapes and lime jello shots while I wrote the code.

&lt;script src=&quot;https://gist.github.com/3723019.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Before we get into the synchronization aspect, here is resetForm. Again, it just handles updating the UI and letting the user know something happened with their important data.

&lt;script src=&quot;https://gist.github.com/3723031.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

I did some quick testing and confirmed it was working. I used Parse.com&apos;s online data browser first:

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip122.png&quot; /&gt;

I then tested offline storage. Chrome makes it easy to check since it has a database viewer built in:

&lt;img src=&quot;http://www.raymondcamden.com/images/ScreenClip123.png&quot; /&gt;

That&apos;s almost it. The final piece of the puzzle is handling uploading the database data. This turned out to be simple too. If we are online, we can run a SQL against the table. If anything exists, we upload it and remove it.

&lt;script src=&quot;https://gist.github.com/3723060.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

That&apos;s basically it. The biggest issue with this code is that it doesn&apos;t handle a &lt;i&gt;change&lt;/i&gt; to your online/offline status, specifically, if you start the application offline, save some sightings, and then become online, it won&apos;t upload the old rows. That wouldn&apos;t be too hard to fix, but I was trying to keep it simple. At minimum, the next time you run the application it will upload those old records. For folks who want to see the entire code base, simply view the gist here: &lt;a href=&quot;https://gist.github.com/3723074&quot;&gt;https://gist.github.com/3723074&lt;/a&gt;

I&apos;ve also included a zip attached to this blog entry. (Note that the animated gif is courtesy of jQuery Mobile.)
				</description>
				
				
				<category>Mobile</category>
				
				<category>Development</category>
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Fri, 14 Sep 2012 10:53:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/9/14/Example-of-a-Parsecom-JavaScript-application-with-offline-support</guid>
				
				
				<enclosure url="http://www.raymondcamden.com/enclosures/parseofflinedemo.zip" length="41908" type="application/x-zip-compressed"/>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Proof of Concept - Build a download feature for IndexedDB</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/8/23/Proof-of-Concept--Build-a-download-feature-for-IndexedDB</link>
				<description>
				
				Before I begin, a quick editorial note. I almost didn&apos;t write this blog entry. After working on the code and getting everything working right, things quickly went to crap when I switched from Mac to Windows. I had odd results in Firefox as well. Overall, I feel that the solution I&apos;ve come up with here is solid, but the current browser implementations are... less than ideal. So, please keep that in mind. Perhaps you are reading this a year from now while cruising around on your jetpack and the browsers have settled down in terms of their IndexedDB support. Perhaps. Until then, please consider that what follows is going to be less than perfect in your browser.&lt;a href=&quot;http://www.w3.org/TR/IndexedDB/&quot;&gt;IndexedDB&lt;/a&gt; is a nice way to store massive amounts of data on the user&apos;s machine. This allows for personal storage of - well - just about anything. Browsers are still working on their implementation, and the feature can be a bit... tricky (see my earlier posts), but overall it can be an incredibly powerful feature.

I was thinking that it might be interesting to build a way to export and save data from an IndexedDB datasource. Why bother when the data is local? I don&apos;t know. Maybe as a way to save a &apos;version&apos; to a USB stick. Maybe as a way to upload later to another machine. To be honest, I just wanted to build it and see what it took. 

Thinking about the process, I broke it down to a few steps.

First - we need to get all the data from our datasource. IndexedDB has a simple way to iterate over an objectstore (think table). What isn&apos;t so easy though is handling the fact that this is an async operation. If you have more than one objectstore you have to wait until all are done. 

Second - once you have all the data, you need to serialize it. Luckily we can rely on the browser&apos;s native JSON support to quickly convert it.

The third and final step is to stream it to the user. Fellow Adobian Christian Cantrell has a good &lt;a href=&quot;http://blogs.adobe.com/cantrell/archives/2012/01/how-to-download-data-as-a-file-from-javascript.html&quot;&gt;blog entry&lt;/a&gt; on saving JavaScript data. But I used a modified version that made use of HTML5&apos;s new &quot;download&quot; attribute for anchors. 

Simple enough? I decided to begin with an earlier application I wrote that allowed for simple Note creation. If you&apos;ve got a recent Firefox installed, you can play with it right now:

&lt;a href=&quot;http://www.raymondcamden.com/demos/2012/aug/23/test.html&quot;&gt;http://www.raymondcamden.com/demos/2012/aug/23/test.html&lt;/a&gt;

This will not work in Chrome... sometimes... due to the issue I reported &lt;a href=&quot;http://www.raymondcamden.com/index.cfm/2012/6/12/Issues-with-IndexedDB-and-Chrome&quot;&gt;here&lt;/a&gt;. Oddly - Google Canary, on &lt;b&gt;Mac&lt;/b&gt; only, seems to work now - perfectly. That&apos;s the main browser I used for testing. But the &lt;b&gt;exact&lt;/b&gt; same Canary on Windows did not work. Confusing - I know. 

Even if you aren&apos;t using a browser that will handle the demo, I encourage you to hit the page and view source. I&apos;m going to be sharing lots of snippets as we go on.

To make the application a bit more complex I added a new objectstore called log. This is defined here:

&lt;script src=&quot;https://gist.github.com/3438351.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

This objectstore will simply contain log messages. I modified my code so that when I created and deleted notes it would simply log the actions. To simplify this I wrapped the logic into a nice utility function:

&lt;script src=&quot;https://gist.github.com/3438381.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

The end result is that my application is using two objectstores. One main &quot;note&quot; objectstore for the actual content and one called &quot;log&quot; which isn&apos;t actually shown to the user. 

I began the process of adding export support by adding a nice button to the top right of the application. Clicking this button begins the process I defined above.  As I mentioned, the first step was to actually get all the data. Because this is involves N asynchronous  processes, I decided to make use of jQuery Deferreds. jQuery Deferreds are black magic to me still. I have the hardest time wrapping my head around them but I was able to get something working. I&apos;m betting there are nicer ways of doing this and I hope my readers can share some tips. Basically though I loop through each objectstore in the database (and note this code is entirely abstract - it should work for any IndexedDB instance) and create a new Deferred to handle the data collection for an individual objectstore. When done looping over the data, I resolve the deferred by returning an array of objects. Finally, $.when is used to collect all of this. 

&lt;script src=&quot;https://gist.github.com/3438481.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Let&apos;s talk about the last few lines above. You can see where I stringify the entire data set in one line. That&apos;s damn convenient. Any browser that supports IndexedDB will support the JSON object so it&apos;s a no brainer to use. 

Sending the data to the user was also pretty simple. You can see where I - initially - made use of the &quot;Cantrell Solution&quot; (yes, I&apos;m using that term because it sounds cool ;). While this worked, it didn&apos;t allow for a file name. 

To get around this, I added an empty link to my DOM. That may not be necessary, I could have just made one in JavaScript, but it was quick and worked. If you view source you will see this in the layout: &amp;lt;a id=&quot;exportLink&quot; download=&quot;data.json&quot;&amp;gt;&amp;lt;/a&amp;gt;

Again - I feel kinda bad just dropping this into the page like that. I&apos;d probably do it  entirely virtually in the future. But note the download attribute. That&apos;s all it takes to &apos;suggest&apos; a filename for downloading. That&apos;s it! So given that I had a jQuery hook to the link already, I simply set the HREF equal to my serialized data. 

I initially tried to trigger a click, but for some reason, this didn&apos;t work correctly. Luckily I found a &lt;a href=&quot;http://stackoverflow.com/a/1421968/52160&quot;&gt;solution&lt;/a&gt; on StackOverflow - the fakeClick function. You can see it yourself if you view source.

Unfortunately, Firefox does not quite work right with the download attribute. It should be coming soon, but for me, it never worked right. That means to truly test this demo, the only browser I know of that can do it all is Google Canary on OS X. Hopefully that will change soon.

So - despite all the buts and warnings above - I hope this is an interesting demonstration for my readers. As always, I&apos;d love to hear your feedback on how this could be improved.
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Thu, 23 Aug 2012 11:09:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/8/23/Proof-of-Concept--Build-a-download-feature-for-IndexedDB</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Resources from my RIACon presentations</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/8/8/Resources-from-my-RIACon-presentations</link>
				<description>
				
				Thank you to everyone who showed up for my RIACon presentations. Any feedback, positive or negative, would be greatly appreciated. I&apos;ve attached the code and slide deck for the jQuery Mobile presentation to this blog post (link at the bottom). The resources for my HTML5 presentation may be found on Github: &lt;a href=&quot;https://github.com/cfjedimaster/html5-storage&quot;&gt;https://github.com/cfjedimaster/html5-storage&lt;/a&gt;
				</description>
				
				
				<category>Mobile</category>
				
				<category>Development</category>
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<category>HTML5</category>
				
				<pubDate>Wed, 08 Aug 2012 05:41:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/8/8/Resources-from-my-RIACon-presentations</guid>
				
				
				<enclosure url="http://www.raymondcamden.com/enclosures/Archive27.zip" length="1842821" type="application/zip"/>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using jQuery to load HTML and filter it by N selectors</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/8/2/Using-jQuery-to-load-HTML-and-filter-it-by-N-selectors</link>
				<description>
				
				Forgive the somewhat awkward title. Hopefully an explanation will make things a bit clearer. I was working on an application yesterday that needed to load in a HTML file via AJAX and display it on screen. The HTML happened to be documentation so I was going to simply display it as is on screen. Since I wasn&apos;t doing any processing, my code was very simple:&lt;script src=&quot;https://gist.github.com/3237187.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Easy, right? Well, the first thing I discovered was that the HTML I was loading included things I didn&apos;t want - headers, footers, etc. Again though this is easy enough to handle. You can tell jQuery&apos;s load() function to filter down to a DOM item. (As a reminder - if you are concerned about performance don&apos;t forget that you are still asking jQuery to load N bytes of HTML even though you are using &amp;lt;N bytes in the display.)

&lt;script src=&quot;https://gist.github.com/3237210.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

Woot. Almost there. This worked great, but the &quot;block&quot; of HTML this rendered was missing a nice header on top. I went back to the original source HTML and discovered that there was another div, header, that contained the title and would be perfect. 

But here was a problem. How do I tell the load() function to select *two* DOM items? Turns out this was easy as well - just provide a list:

&lt;script src=&quot;https://gist.github.com/3237220.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

This worked fine. But this leads to my question. Is this a good idea? Is there a better way? (Assuming you can&apos;t get &quot;pure&quot; data and must work with the HTML files.)
				</description>
				
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Thu, 02 Aug 2012 08:36:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/8/2/Using-jQuery-to-load-HTML-and-filter-it-by-N-selectors</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Example of form validation in a jQuery Mobile Application</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/7/30/Example-of-form-validation-in-a-jQuery-Mobile-Application</link>
				<description>
				
				Over the weekend I decided to write up a quick example of form validation in jQuery Mobile. Obviously there are many ways you can accomplish this and I just wanted to take my own little spin with it. Here&apos;s what I came up with and I&apos;d love to hear how other jQuery Mobile users are doing validation.Let&apos;s start off with a real simple jQM site. It will have a home page with links to two sub pages. My form will be on the second page. To be honest, I could have just built a one page site, but I wanted something with a trivial bit of navigation to it so it felt just a bit more realistic. I won&apos;t bore you with all the code (you can view source on the demo yourself), but here is our simple form:

&lt;script src=&quot;https://gist.github.com/3206892.js?file=gistfile1.html&quot;&gt;&lt;/script&gt;

The form consists of 6 fields: username, password, the password confirmation, your favorite color, and your home town. The validation rules should be:

&lt;ul&gt;
&lt;li&gt;Everything but the home town is required.&lt;/li&gt;
&lt;li&gt;Username, password, and the confirmation must be 5 characters minimum.&lt;/li&gt;
&lt;li&gt;The password confirmation must match the password.&lt;/li&gt;
&lt;/ul&gt;

Pretty simple, right? Without any validation at all, you can take this for a spin here:

&lt;a href=&quot;http://www.raymondcamden.com/demos/2012/jul/30/round1/&quot;&gt;Round 1&lt;/a&gt;

And if you don&apos;t want to bother with that - a quick screen shot (which I generated from &lt;a href=&quot;http://labs.adobe.com/technologies/shadow/&quot;&gt;Adobe Shadow&lt;/a&gt; thank you very much):

&lt;img src=&quot;http://www.raymondcamden.com/images/2012-07-30_08.32.59_HTC HTC ONE X.png&quot; /&gt;

Ok, so let&apos;s talk validation. It would certainly be cool if we could just use HTML5 form validation, right? I mean, look at the mobile browser support for Canvas: 

&lt;iframe src=&quot;http://caniuse.com/canvas/embed/agents=mobile&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

That&apos;s a hell of a lot of green. So obviously - if there is that much support for canvas, which is only mildly useful in practical matters - surely there is even higher support for form validation, something we probably all use &lt;b&gt;every single day&lt;/b&gt;.

&lt;iframe src=&quot;http://caniuse.com/form-validation/embed/agents=mobile&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

*sigh*

Ok, so moving on from that, let&apos;s talk options. Obviously we can roll our own JavaScript. It isn&apos;t terribly difficult to do so. But I thought it might be nice try the &lt;a href=&quot;http://docs.jquery.com/Plugins/Validation&quot;&gt;jQuery Validation plugin&lt;/a&gt;. I&apos;ve blogged on it before (see links at the bottom) and I liked how simple it made things. I thought I&apos;d give it a shot here and see how it ran.

The plugin provides two main ways of adding validation to a form. You can either add items to a class attribute of your form or supply a list of validation rules when initializing the plugin. Personally, I don&apos;t know which I prefer. I wish the plugin made use of a data-attribute instead of a class, but I like &lt;i&gt;seeing&lt;/i&gt; my rules in the HTML. I went with that approach but just keep in mind you have the other option as well.

Here&apos;s the updated HTML for the register page (just the form bits):

&lt;script src=&quot;https://gist.github.com/3207040.js?file=gistfile1.html&quot;&gt;&lt;/script&gt;

Notice the addition of class=&quot;required&quot; to my fields requiring validation. Also note the minlength of the first three fields. This is - pretty much - all it takes. The one big obvious piece missing is the &quot;confirmation must match password&quot; field but that can be handled in a custom rule. I also had to initialize the validation but that&apos;s one line of code: $(&quot;#registerForm&quot;).validate();

So far so good, right? But check out the result:

&lt;img src=&quot;http://www.raymondcamden.com/images/2012-07-30_08.35.00_HTC HTC ONE X.png&quot; /&gt;

First, the errors don&apos;t really stand out and second - note the error for the drop down. It&apos;s actually &lt;i&gt;inside&lt;/i&gt; the custom jQM drop down field. Not good. Let&apos;s tackle the design first. By default, the validation plugin will use an error class for displaying errors. That means it is pretty trivial to make it look a bit nicer:

&lt;script src=&quot;https://gist.github.com/3207056.js?file=gistfile1.css&quot;&gt;&lt;/script&gt;

Which results in:

&lt;img src=&quot;http://www.raymondcamden.com/images/2012-07-30_08.35.56_HTC HTC ONE X.png&quot; /&gt;

Nice. About halfway there. You can demo this version here: &lt;a href=&quot;http://www.raymondcamden.com/demos/2012/jul/30/round2/&quot;&gt;Round 2&lt;/a&gt; 

So what about the weird drop down behavior? We can use another feature of the plugin to handle that. You can use a property, errorPlacement, that allows you to dynamically determine where errors should be written out. While we&apos;re at it, we can also go ahead and create the custom rule for password matching.

&lt;script src=&quot;https://gist.github.com/3207067.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

To be honest, the use of .parent() there was a bit of a guess, but it worked on first try. In case you&apos;re curious, to add the custom validation to the second password field I just had to add the name to the class list: class=&quot;required passmatch&quot;.

&lt;img src=&quot;http://www.raymondcamden.com/images/2012-07-30_08.36.36_HTC HTC ONE X.png&quot; /&gt;

You can demo this version here: &lt;a href=&quot;http://www.raymondcamden.com/demos/2012/jul/30/round3/&quot;&gt;Round 3&lt;/a&gt;

So, what do you think? I&apos;d like to work on this a bit more. On the iPad, the errors are left aligned under the labels, which is kinda cool, but I could also see them being aligned with the fields instead. On desktop it is &lt;i&gt;way&lt;/i&gt; off but I kinda figure that is an edge case and not something I&apos;d have to worry about. As always, comments and critiques are welcome.
				</description>
				
				
				<category>Mobile</category>
				
				<category>jQuery</category>
				
				<category>JavaScript</category>
				
				<pubDate>Mon, 30 Jul 2012 08:17:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/7/30/Example-of-form-validation-in-a-jQuery-Mobile-Application</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Preventing navigation to a page in jQuery Mobile</title>
				<link>http://www.raymondcamden.com/index.cfm/2012/7/19/Preventing-navigation-to-a-page-in-jQuery-Mobile</link>
				<description>
				
				Here&apos;s an interesting situation I ran into recently. Consider a simple web site that begins with a login page. After you successfully login, you proceed to a &apos;home&apos; page with links to sub pages. But you want to prevent users from using their back button to return all the way to the login page. It isn&apos;t a security issue per se, but it is confusing. The user should only be able to go back to the post-login home page.In theory - this should be simple. jQuery Mobile exposes a pagebeforechange event. As you can guess, it is fired before you change to a page. According to the &lt;a href=&quot;http://jquerymobile.com/demos/1.1.1/docs/api/events.html&quot;&gt;docs&lt;/a&gt;, using preventDefault effectively blocks the loading of the page.

Easy then, right? The docs state that you are passed a data object that contains a &quot;toPage&quot; key. This is either a simple value (url) or a jQuery DOM item for the page. In theory, I can use this to detect someone loading the initial page and simply block it. Here&apos;s a snippet of the code I tried:

&lt;script src=&quot;https://gist.github.com/3147547.js?file=gistfile1.js&quot;&gt;&lt;/script&gt;

You can demo this yourself here (opens in new window): &lt;a href=&quot;http://raymondcamden.com/demos/2012/jul/17/index.html&quot; target=&quot;_new&quot;&gt;http://raymondcamden.com/demos/2012/jul/17/index.html&lt;/a&gt;

Now, if you try this, something interesting happens. When you click to visit page 2, and then click back in your browser, you will see that the page does not change, &lt;i&gt;but the url does!&lt;/i&gt;. So jQuery Mobile kinda &quot;half way&quot; worked but not completely. In testing I saw various problems with this. Just now, I wasn&apos;t able to go back anymore, but in other testing I would go back after a second click. It was a bit inconsistent for me. 

I posted this to the &lt;a href=&quot;http://forum.jquery.com/jquery-mobile&quot;&gt;jQuery Mobile forums&lt;/a&gt; and user &lt;a href=&quot;http://forum.jquery.com/user/kevin-b&quot;&gt;Kevin B&lt;/a&gt; had a great solution. He correctly pointed out that I was preventing jQuery Mobile from navigating but not preventing the browser itself from doing so. He suggested modifying the history directly to correct it. This could be done with a simple history.go(1) statement.

You can see a full example of his solution &lt;a href=&quot;http://forum.jquery.com/topic/pagebeforechange-working-halfway#14737000003502579&quot;&gt;here&lt;/a&gt;. I tried this back in the application I was building and it worked fine. I noticed that in my PhoneGap application that I received a jQuery object instead, but that simply required me doing a quick check on toPage.attr(&quot;id&quot;). 

Hopefully this makes sense and helps others.
				</description>
				
				
				<category>Mobile</category>
				
				<category>jQuery</category>
				
				<pubDate>Thu, 19 Jul 2012 18:00:00 -0400</pubDate>
				<guid>http://www.raymondcamden.com/index.cfm/2012/7/19/Preventing-navigation-to-a-page-in-jQuery-Mobile</guid>
				
				
			</item>
			
		 	
			</channel></rss>