<?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>Ryan Stewart - Mountaineer Coding</title>
	<atom:link href="http://blog.digitalbackcountry.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.digitalbackcountry.com</link>
	<description>Just an average guy trying to drink above average beer.</description>
	<lastBuildDate>Thu, 02 Feb 2012 02:35:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hoping for a Web App Future</title>
		<link>http://blog.digitalbackcountry.com/2012/02/hoping-for-a-web-app-future/</link>
		<comments>http://blog.digitalbackcountry.com/2012/02/hoping-for-a-web-app-future/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 22:04:34 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PhoneGap]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[installable web apps]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[phonegap]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=3003</guid>
		<description><![CDATA[If I think back to 2006/2007 I was very happy with how things were shaking out. The web was on the upswing and we were moving away from native applications. All of the great things about the web&#8211;its ubiquity, its &#8230; <a href="http://blog.digitalbackcountry.com/2012/02/hoping-for-a-web-app-future/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If I think back to 2006/2007 I was very happy with how things were shaking out. The web was on the upswing and we were moving away from native applications. All of the great things about the web&#8211;its ubiquity, its freedom, its openness&#8211;were being harnessed to create native-like experiences that, I hoped at the time, would see us all do away with native apps. At the time, there wasn&#8217;t much (I thought) that web apps couldn&#8217;t do that we needed native apps for. How wrong I was. With the introduction of the iPhone, and subsequent smartphone releases, we&#8217;ve seen a huge shift back to native applications. Part of that is performance, right now native apps just feel better than mobile web apps, but it also came about because of just how many things native mobile apps could do. Geolocation, accelerometers, contact info&#8211;the smartphone showed how many things &#8220;apps&#8221; needed access to and for the most part those features have been exclusive to native applications. So just as the web was starting to really take off, we&#8217;ve slid back into native application territory.</p>
<p>It bummed me out, and still does. I thought AIR was an okay solution to the problem, but by the time AIR came around it was pretty clear that &#8220;the web&#8221; had come to mean HTML/JS, and I&#8217;m fine with that. So as PhoneGap started getting traction, and then Adobe took a major interest in the project, I was excited about the prospect of working on it as an Adobe evangelist, and more importantly, working with the teams behind it to see what else they had up their sleeves as the web moves forward.</p>
<p>But another side benefit is that it&#8217;s put me on what I&#8217;d consider the &#8220;right&#8221; side of the web argument. Two things got me thinking more about this. One was a <a href="http://www.bothsidesofthetable.com/2012/01/28/web-second-mobile-first/">very good post</a> by a VC named Mark Suster, who while not telling his companies to focus exclusively on the web, has told them to make it a big part of what they do. So many startups nowadays are thinking completely mobile-first while ignoring the web, I&#8217;d say at their peril. When I think of my own usage, I&#8217;m still using a lot of native apps (for reasons I can&#8217;t quite figure out) but the ones I enjoy most have a web component that is well done and part of the overall experience. Yelp comes to mind. Another is <a href="http://www.untappd.com">Untappd</a>. I can do almost anything I need to on the website version of Untappd so it&#8217;s not as though I&#8217;m getting a watered down experience. It more easily lets me move between contexts and devices while still using the service. I contrast that to something like <a href="http://foursquare.com">Foursquare</a> or <a href="http://www.path.com">Path</a>. Both are mobile-centric, and with Foursquare I can&#8217;t check in because it wants to be sure that I am where I say I am (using GPS) but it still makes the web side of it less useful for me. Path is unusable when you&#8217;re not on a mobile device as far as I can tell. When I log in all I get is &#8220;download the app&#8221;. Which I hate. Mobile is clearly important but the web can&#8217;t be ignored.</p>
<div id="attachment_3004" class="wp-caption aligncenter" style="width: 410px"><img src="http://blog.digitalbackcountry.com/wp-content/uploads/path_login-1.jpg" alt="Path Login" title="Path Login" width="400" height="308" class="size-full wp-image-3004" /><p class="wp-caption-text">If this is what I see when I log into your site, you&#039;re too mobile-first. </p></div>
<p>The second thing that got me thinking more about this was something <a href="http://brian.io">Brian Leroux</a> pointed to on the Cordova mailing list, a post by Tim Berners-Lee about <a href="http://lists.w3.org/Archives/Public/public-webapps/2012JanMar/0464.html">Installable Web Apps</a>. This is a model I would love to see take hold. As Tim notes, there are a few things that users need to have when they&#8217;re installing web apps, and some trust/permissions issues that need to be figured out. Right now, I think PhoneGap is closest to this model, but a huge, huge, part of me wishes PhoneGap didn&#8217;t need to exist. If we could somehow skip the native shim and just take for granted that every platform supported, and at its core used, installable web apps. Maybe something like the WebOS model. But we&#8217;re not there yet. So for now, I&#8217;m glad I get to work with PhoneGap and build apps with web technologies. Eventually though I think PhoneGap can be used as inspiration for installable web apps. This is kind of how the standards world moves, as more and more people adopt something, people find ways to bring that something back into the standards. I think some of PhoneGap&#8217;s APIs and methodologies would make a great start at the idea of installable web apps. And I think the guys behind PhoneGap will be at the forefront of making those things happen, which means Adobe is going to be a really cool place to be over the next few years. It feels like there is a lot of potential to change the world and while I miss spending time with Flash, I feel like the HTML/JS/CSS work I&#8217;ve been doing and that Adobe is investing in, will make a similar impact on the web down the road.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2012/02/hoping-for-a-web-app-future/" data-text="Hoping for a Web App Future" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2012/02/hoping-for-a-web-app-future/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2012/02/hoping-for-a-web-app-future/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Dealing with Binary Data from a Canvas Object using JavaScript TypedArrays</title>
		<link>http://blog.digitalbackcountry.com/2012/01/dealing-with-binary-data-from-a-canvas-object-using-javascript-typedarrays/</link>
		<comments>http://blog.digitalbackcountry.com/2012/01/dealing-with-binary-data-from-a-canvas-object-using-javascript-typedarrays/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 08:55:35 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[typedarrays]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2994</guid>
		<description><![CDATA[I&#8217;m not sure how helpful this will be for anyone, but during the process of doing a binary WebSocket demo I found myself learning a lot about JavaScript typed arrays and how that translates into binary data. The demo I &#8230; <a href="http://blog.digitalbackcountry.com/2012/01/dealing-with-binary-data-from-a-canvas-object-using-javascript-typedarrays/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure how helpful this will be for anyone, but during the process of doing a binary WebSocket demo I found myself learning a lot about JavaScript typed arrays and how that translates into binary data. The demo I wrote took Canvas image data and sent it over a binary WebSocket connection. The WebSocket server took that data and sent it out to all of the connected clients, who would then render the <code>Canvas</code> data as a PNG. It&#8217;s kind of a niche use case but I wanted to specifically create a binary WebSocket demo. It also was a more efficient way to send image data than doing something like base64 encoding it. First off, the <a href="https://developer.mozilla.org/en/">Mozilla documentation was REALLY helpful</a>. Major props to them.</p>
<h2>Translating Canvas Data Into a Binary Format</h2>
<p><code>Canvas</code> has a <code>getImageData()</code> method that gives you an <code>ImageData</code> object. Within that <code>ImageData</code> object is a <code>data</code> property, which has the actual array data of the image. Normally I would have been able to stop right there because that would (in theory) have the information I needed. But what I had to get at was the <code>ArrayBuffer</code>. The way the spec has been implemented you can&#8217;t do anything with the <a href="https://developer.mozilla.org/en/JavaScript_typed_arrays/ArrayBuffer"><code>ArrayBuffer</code></a>. Instead you have to use an ArrayBufferView, which takes the form of <a href="http://www.khronos.org/registry/typedarray/specs/latest/"><code>TypedArrays</code></a> in JavaScript. Luckily, to get the actual buffer you can just call the <code>buffer</code> property on any of the typed arrays and do what you want with it. But Canvas (at least in Chrome) is slightly different. The object you get from the <code>ArrayBuffer</code> of <code>ImageData.data</code> is something called <code><a href="https://developer.mozilla.org/en/DOM/CanvasPixelArray">CanvasPixelArray</a></code>. Currently <code>CanvasPixelArray</code> doesn&#8217;t behave like a regular typed array, it looks like it will become a <code><a href="http://www.khronos.org/registry/typedarray/specs/latest/#7.1">Uint8ClampedArray</a></code> but the way it works in Chrome right now the <code>CanvasPixelArray</code> doesn&#8217;t provide access to a <code>buffer</code> property so you can&#8217;t send/access the <code>ArrayBuffer</code> data. Luckily getting that data into a <code>Uint8Array</code>, which you <em>can</em> get the <code>buffer</code> data from is pretty easy:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">     imagedata <span style="color: #339933;">=</span> context.<span style="color: #660066;">getImageData</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> imagewidth<span style="color: #339933;">,</span>imageheight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #003366; font-weight: bold;">var</span> canvaspixelarray <span style="color: #339933;">=</span> imagedata.<span style="color: #660066;">data</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
     <span style="color: #003366; font-weight: bold;">var</span> canvaspixellen <span style="color: #339933;">=</span> canvaspixelarray.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> bytearray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Uint8Array<span style="color: #009900;">&#40;</span>canvaspixellen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>canvaspixellen<span style="color: #339933;">;++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          bytearray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> canvaspixelarray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span></pre></div></div>

<p>With that new <code>Uint8Array</code> all that we have to do is grab the <code>buffer</code> property and we can send it across the wire (beyond this post, but I&#8217;m planning on writing up the binary WebSocket info).</p>
<h2>Reassembling the pieces</h2>
<p>Now what I wanted to do was take that binary data from my <code>Canvas</code> and render it as a PNG file on the screen. The first step is to use a <code>Canvas</code> object to render out a PNG. But before that we have to get the data into a Canvas. In theory, you should be able to just do what happened above in reverse. But it&#8217;s not <em>quite</em> that simple. Once you get back the binary data from somewhere (WebSocket say), you&#8217;ve got an <code>ArrayBuffer</code> that you have to deal with. There is a <code>putImageData()</code> that takes an <code>ImageData</code> object, and we can create an <code>ImageData</code> object a few different ways, but you can&#8217;t set the <code>data</code> property of it. It&#8217;s read only. So we can&#8217;t take our data from the ArrayBuffer and just put it into our Canvas. We have to manually loop through the <code>data</code> property and line-by-line change the data.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">          <span style="color: #003366; font-weight: bold;">var</span> bytearray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Uint8Array<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
          <span style="color: #003366; font-weight: bold;">var</span> tempcanvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'canvas'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               tempcanvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> imageheight<span style="color: #339933;">;</span>
               tempcanvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> imagewidth<span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> tempcontext <span style="color: #339933;">=</span> tempcanvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #003366; font-weight: bold;">var</span> imgdata <span style="color: #339933;">=</span> tempcontext.<span style="color: #660066;">getImageData</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>imagewidth<span style="color: #339933;">,</span>imageheight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #003366; font-weight: bold;">var</span> imgdatalen <span style="color: #339933;">=</span> imgdata.<span style="color: #660066;">data</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">8</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>imgdatalen<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
          <span style="color: #009900;">&#123;</span>
               imgdata.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> bytearray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          tempcontext.<span style="color: #660066;">putImageData</span><span style="color: #009900;">&#40;</span>imgdata<span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If the above isn&#8217;t clear, basically I&#8217;m just creating a new <code>Uint8Array</code> with the data from the server, then creating the temporary <code>Canvas</code> so I can get image data from it, and when I have that, I&#8217;m looping through the <code>data</code> property and inserting my own data from the <code>Uint8Array</code>.</p>
<h2>Rendering it as a PNG</h2>
<p>So now we have a <code>Canvas</code> (not being displayed) that has all of the data from our server, so it&#8217;s an exact graphical copy of the info we received. Turning that into a PNG is actually pretty easy because HTML is awesome. <code>Canvas</code> has a <code>toDataURL()</code> method that will take whatever is in the <code>Canvas</code> and create a string that can be put into the <code>src</code> property of an image. Then putting that image somewhere on the DOM will display the data as an image.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">          <span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               img.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> imageheight<span style="color: #339933;">;</span>
               img.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> imagewidth<span style="color: #339933;">;</span>
               img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> tempcanvas.<span style="color: #660066;">toDataURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Fin</h2>
<p>Now that I&#8217;ve gotten my head around binary data a lot more, I&#8217;m kind of excited about JavaScript typed arrays. Looking through the list it looks like the typed arrays will help a lot with byte manipulation because of the different types. It also <a href="http://blog.n01se.net/?p=248">looks like they&#8217;re pretty fast</a> (at least the fastest option at the time of that post). </p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2012/01/dealing-with-binary-data-from-a-canvas-object-using-javascript-typedarrays/" data-text="Dealing with Binary Data from a Canvas Object using JavaScript TypedArrays" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2012/01/dealing-with-binary-data-from-a-canvas-object-using-javascript-typedarrays/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2012/01/dealing-with-binary-data-from-a-canvas-object-using-javascript-typedarrays/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HTML/JS/CSS and Tooling</title>
		<link>http://blog.digitalbackcountry.com/2012/01/htmljscss-and-tooling/</link>
		<comments>http://blog.digitalbackcountry.com/2012/01/htmljscss-and-tooling/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 21:13:18 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tooling]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2991</guid>
		<description><![CDATA[I enjoyed this post by Grant Skinner that walks through his view of the evolution of technology and where/how/when tooling starts to come in. Adobe makes tools for web professionals. That&#8217;s what we&#8217;ve always done and that&#8217;s what we&#8217;ll do &#8230; <a href="http://blog.digitalbackcountry.com/2012/01/htmljscss-and-tooling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://gskinner.com/blog/archives/2012/01/the-evolution-of-web-development-tools.html">enjoyed this post by Grant Skinner</a> that walks through his view of the evolution of technology and where/how/when tooling starts to come in. Adobe makes tools for web professionals. That&#8217;s what we&#8217;ve always done and that&#8217;s what we&#8217;ll do for a long time. You could even paint a broader brush that we make tools for creative people to share their creations. Watching our own evolution over the past year or so with regards to HTML tooling has been very interesting. We got some flack for not moving in earlier, but as Grant rightly points out, tools are a major investment and only once you have stability can you make that investment. It was never a matter of momentum around HTML or a focus on Flash, it was just the fact that things weren&#8217;t quite ready for tools.</p>
<p>In fact, I&#8217;d argue they still aren&#8217;t. But we&#8217;ve taken that as something that comes with the web. It&#8217;s always evolving, always moving, and while things will start to coalesce more and more, in the end, you have to get in and be ready to move. That&#8217;s kind of the approach we&#8217;ve taken with Adobe Edge. We just released <a href="http://success.adobe.com/en/na/sem/products/edge.html">Preview 4 of Edge</a> which incorporates a lot of features that people have been asking for. Some of it I&#8217;m not even sure if it was on the original roadmap. But the Edge team made a conscious decision to be very agile, to build Edge in such a way that it could incorporate customer feedback quickly, and then getting product management on board to do lots of versions very quickly. I think it&#8217;s worked out very well and despite being on the earlier side of Grant&#8217;s curves, I think Edge will be a very helpful tool for a lot of people because of it.</p>
<p>Developer tools are a bit of a different story in terms of both ecosystem and readiness in my mind. There isn&#8217;t one, big, HTML IDE that people seem to like (akin to Flash Builder, Eclipse or Visual Studio). Instead people seem to be using a lot of different things and experimenting. What actually seems to be most popular right now are the basic text editors like <a href="http://macromates.com/">TextMate</a> or <a href="http://www.sublimetext.com/">Sublime</a> (my favorite). These seem to be focused on helping smart people work faster. Lots of shortcuts, lots of snippets, but not a lot in terms of helping along the learning process. And I think that&#8217;s just where we are now as far as HTML/JS/CSS tooling. But I&#8217;m excited to see that evolution as well and see what happens when frameworks get a bit more standardized and more general web developers start jumping into JS more and more. Will those people need a more robust HTML/CSS/JS editor that&#8217;s still developer centric? And I think the answer is yes, but I think it&#8217;s also tough to really see what that would look like until the JS/HTML/CSS stack is a bit more solid. But I&#8217;m excited to watch it and find out. And from what I&#8217;ve seen of Adobe&#8217;s HTML tooling side, we&#8217;re taking a good approach and I&#8217;m excited to see what people think as the PMs share more and more of it.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2012/01/htmljscss-and-tooling/" data-text="HTML/JS/CSS and Tooling" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2012/01/htmljscss-and-tooling/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2012/01/htmljscss-and-tooling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Appreciating Tricks Because of What They Can Represent</title>
		<link>http://blog.digitalbackcountry.com/2012/01/appreciating-tricks-because-of-what-they-can-represent/</link>
		<comments>http://blog.digitalbackcountry.com/2012/01/appreciating-tricks-because-of-what-they-can-represent/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:28:49 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2985</guid>
		<description><![CDATA[Jeff Croft has a nice riff on some of the responses he got when he tweeted about what Steven Witten has done with his site, acko.net. It&#8217;s an insanely cool piece of CSS and 3D work and Steven did an &#8230; <a href="http://blog.digitalbackcountry.com/2012/01/appreciating-tricks-because-of-what-they-can-represent/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Jeff Croft <a href="http://jeffcroft.com/blog/2012/jan/16/forest-trees-acko-net/">has a nice riff</a> on some of the responses he got when he tweeted about what Steven Witten has done with his site, <a href="http://acko.net/">acko.net</a>. It&#8217;s an insanely cool piece of CSS and 3D work and Steven did <a href="http://acko.net/blog/making-love-to-webkit/">an informative writeup</a on how and why he did what he did. But when Jeff sent out the link, he got some feedback about performance being bad, about it spinning up fans, and about it not being as usable. Almost exactly the kinds of things we've heard about Flash content for so long.</p>
<p>It&#8217;s fascinating to see some of the anti-Flash attitudes manifest themselves in the new world of a very rich HTML5. And I think it goes to show that a lot of the animosity towards Flash was rooted in a very strict interpretation of what is &#8220;good&#8221; when it comes to UX and UI. I don&#8217;t even think that&#8217;s entirely wrong, but I do think that some of it misses the point. As Jeff noted, you have to have experiments like this that show off the technology. This kind of thing inspires people to think beyond the gimmick and potentially implement some of these ideas in a more usable and meaningful way. It also does a disservice to the fact that things like this make the web a more beautiful place. This isn&#8217;t &#8220;design&#8221; in the traditional sense. But it&#8217;s still art, and art should be celebrated. Most of the things I&#8217;ve seen on Twitter were pretty positive about the site and appreciated it, but the opposite reaction from a lot of the web standardistas was, as Jeff said, disappointing.</p>
<p>My plea for the potential creators of things like this is to not heed the mindset that because you&#8217;re using open standards you need to adhere to the unwritten rules of UX/UI design and what&#8217;s &#8220;good&#8221;. The open web is at the beginning of what is going to be an amazingly creative period. With technologies like CSS3 and Canvas, the open web has the building blocks in place to harness a lot of creative energy. That is going to take many forms and some of it won&#8217;t seem as useful as other bits. But it&#8217;s all part of a process, one that we saw with Flash, that ultimately leads to better ideas, better implementations, and a better web.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2012/01/appreciating-tricks-because-of-what-they-can-represent/" data-text="Appreciating Tricks Because of What They Can Represent" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2012/01/appreciating-tricks-because-of-what-they-can-represent/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2012/01/appreciating-tricks-because-of-what-they-can-represent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slides for my PhoneGap Presentation</title>
		<link>http://blog.digitalbackcountry.com/2012/01/slides-for-my-phonegap-presentation/</link>
		<comments>http://blog.digitalbackcountry.com/2012/01/slides-for-my-phonegap-presentation/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 22:38:10 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PhoneGap]]></category>
		<category><![CDATA[Presentations]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2981</guid>
		<description><![CDATA[I had the chance to present to the Seattle Web App Developers Group (formerly the Flex UG) and here are the slides from that presentation. Thanks a ton to everyone who came out. It was a lot of fun and &#8230; <a href="http://blog.digitalbackcountry.com/2012/01/slides-for-my-phonegap-presentation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had the chance to present to the <a href="http://www.meetup.com/Seattle-Web-App-Developers-Group/events/42180442/">Seattle Web App Developers Group</a> (formerly the Flex UG) and here are the slides from that presentation. Thanks a ton to everyone who came out. It was a lot of fun and it was exciting to see so many people interested in PhoneGap.</p>
<div style="width:425px" id="__ss_11090731"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/ryanstewart/phone-gap-preso" title="PhoneGap: Building Mobile Applications with HTML/JS" target="_blank">PhoneGap: Building Mobile Applications with HTML/JS</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/11090731" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/ryanstewart" target="_blank">Ryan Stewart</a> </div>
</p></div>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2012/01/slides-for-my-phonegap-presentation/" data-text="Slides for my PhoneGap Presentation" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2012/01/slides-for-my-phonegap-presentation/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2012/01/slides-for-my-phonegap-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Mobile-Themed Slider without jQuery Mobile</title>
		<link>http://blog.digitalbackcountry.com/2012/01/building-a-mobile-themed-slider-without-jquery-mobile/</link>
		<comments>http://blog.digitalbackcountry.com/2012/01/building-a-mobile-themed-slider-without-jquery-mobile/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 20:11:31 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[toggle-button]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2971</guid>
		<description><![CDATA[I&#8217;m generally a big fan of jQuery mobile. I think it&#8217;s an ambitious project and it&#8217;s got some areas that could be improved, but I&#8217;m glad we&#8217;re contributing and think it&#8217;s going to be a huge boon for mobile web &#8230; <a href="http://blog.digitalbackcountry.com/2012/01/building-a-mobile-themed-slider-without-jquery-mobile/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m generally a big fan of jQuery mobile. I think it&#8217;s an ambitious project and it&#8217;s got some areas that could be improved, but I&#8217;m glad we&#8217;re contributing and think it&#8217;s going to be a huge boon for mobile web applications as they get bigger and bigger. But building PhoneGap applications with jQuery Mobile is a bit problematic partly because the <a href="http://jquerymobile.com/strategy/">goal for the project</a> is &#8220;Delivering top-of-the-line JavaScript and a unified User Interface across the most-used smartphone web browsers&#8230;&#8221; and partly because jQuery Mobile can be tough to really customize if you want a specific look and feel. One of the things I wanted for something I&#8217;m working on is a slider that is a bit more boxy than the traditional slider used with jQuery Mobile. Some of this might have been possible with customizing the jQuery Mobile theme but I wanted to see what it would take to build my own from scratch.</p>
<p>This example is part of an app that&#8217;s using <a href="http://documentcloud.github.com/backbone/">Backbone.js</a> so I won&#8217;t post a working example because the Backbone.js infrastructure makes it kind of tough to strip out just the toggle button part. I&#8217;ll post the whole thing later, but wanted to show the general process.</p>
<h2>The Look and Feel</h2>
<p>To set it up I wrapped a <code>div</code> tag around a <code>select</code> tag with a couple of options. The div tag provided the border so it ended up being the track that the sider went along. This makes it pretty easy to customize the look and feel while still being very nicely degraded into a regular HTML select box.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">                         &lt;div id=&quot;toggle&quot; class=&quot;toggleoff&quot;&gt;
                         &lt;select name=&quot;activetoggle&quot; id=&quot;activetoggle&quot; class=&quot;selectoff&quot;&gt;
                              &lt;option value=&quot;all&quot;&gt;All&lt;/option&gt;
                              &lt;option value=&quot;active&quot;&gt;Active&lt;/option&gt;
                         &lt;/select&gt;
                         &lt;/div&gt;</pre></div></div>

<p>Initially both the <code>div</code> and the <code>select</code> start with &#8220;off&#8221; classes. At this point the CSS starts to take over and create a more slider-looking button. There is a cool <a href="http://davidwalsh.name/webkit-appearance"><code>-webkit-appearance</code></a> property that can be used on the slider to give it some instantaneous look/feel. But for the most part I rely on -webkit-border-image to customize the look and feel of the slider button. The CSS for the toggle button itself, the <code>div</code> tag, and the off states give us a basic looking toggle with no real toggle functionality because it behaves just like a regular HTML <code>select</code> box.</p>
<div id="attachment_2972" class="wp-caption aligncenter" style="width: 328px"><img src="http://blog.digitalbackcountry.com/wp-content/uploads/toggle_button_off.png" alt="" title="toggle_button_off" width="318" height="58" class="size-full wp-image-2972" /><p class="wp-caption-text">Toggle button off state</p></div>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">select <span style="color: #00AA00;">&#123;</span>
     -webkit-appearance<span style="color: #00AA00;">:</span> push-button<span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">155px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#cdcdcd</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.selectoff</span> <span style="color: #00AA00;">&#123;</span>
     -webkit-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;"> ../assets/button.up.png </span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">4</span> stretch stretch<span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#toggle</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">312px</span><span style="color: #00AA00;">;</span>
     -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
     -webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>    
     <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#cdcdcd</span><span style="color: #00AA00;">;</span>    
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.toggleoff</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">158px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -webkit-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#e7e7e7</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I have the benefit of using absolute positioning because I&#8217;m building this for an iPhone, but the CSS is pretty straightforward. I&#8217;ve got some <code>padding-left</code> properties so I can control how the text looks and where the actual toggle button appears within the <code>div</code> tag. This is why this particular strategy works. When I move between states I&#8217;m just going to change the position of the toggle button, I&#8217;m not actually doing anything with the <code>select</code> object itself other than changing how it looks and where it is. Here are the &#8220;on&#8221; classes.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&nbsp;
<span style="color: #6666ff;">.selecton</span> <span style="color: #00AA00;">&#123;</span>
     -webkit-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../assets/button.down.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">4</span> stretch stretch<span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.toggleon</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #3333ff;">:-webkit-linear-</span>gradient<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#bccead</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#cbdfba</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Just a couple of small changes to gradients and backgrounds so that when our button is on or active, it looks like this:</p>
<div id="attachment_2973" class="wp-caption aligncenter" style="width: 329px"><img src="http://blog.digitalbackcountry.com/wp-content/uploads/toggle_button_on.png" alt="" title="toggle_button_on" width="319" height="57" class="size-full wp-image-2973" /><p class="wp-caption-text">Toggle button on state</p></div>
<h2>Functionality</h2>
<p>Now that the CSS classes are set up I used jQuery to first add/remove the classes I wanted and finally set the value of the <code>select</code> box programatically. As I mentioned, this is using Backbone.js so the code may look a bit odd.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">          onMouseDown<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">displayingAll</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#activetoggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selectoff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#activetoggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selecton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#toggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toggleoff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#toggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toggleon&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#activetoggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;active&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         
               <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#activetoggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selecton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#activetoggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selectoff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#toggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toggleon&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#toggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;toggleoff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#activetoggle&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;all&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                             
               <span style="color: #009900;">&#125;</span></pre></div></div>

<p>My Backbone view has a variable, <code>displayingAll</code>, which I set to either true or false depending on what is currently visible. It helps track which classes need to be added/removed. But the first, and probably most important thing, is that I&#8217;m capturing the event and keeping it from doing anything. I don&#8217;t want the default <code>select</code> behavior at all so I can trap it and make sure it doesn&#8217;t keep doing the rest of its work. That means no pop up where the user can select values. Instead I go through and swap out the on/off classes to change the look of my button. Finally I use the <code>val()</code> method to set the value of the <code>select</code> so that what the screen is showing is the actual value of the <code>select</code> input.</p>
<p>So now the slider is working but we haven&#8217;t done any animation. So right now the slider just jumps back and forth. It works but it isn&#8217;t all that pretty. Luckily CSS3 is pretty awesome and we can leverage the very powerful <code>-webkit-transition</code> to help us out.</p>
<h2>Animation</h2>
<p>Animation for this example is insanely simple. Using the <code>-webkit-transition</code> CSS property we can listen for changes in the DOM on a specific property and whenever that property changes we can play a specific transition. The way I have set this up is that I&#8217;m changing the <code>padding-left</code> property between on/off classes so that&#8217;s the one we have to listen for.</p>
<p><em><strong>Quick sidenote</strong>: I struggled with this for a bit. At first I was using the <code>align</code> property of the <code>div</code> to move the toggle button back and forth. That had the benefit of being able to scale better for multiple pixel-widths. The button would move back and forth just fine but there wasn&#8217;t a way to animate the <code>align</code> property that I found, which makes sense. So to do animation I had to use a value that could be animated and <code>padding-left</code> ended up being a decent option.</em></p>
<p>In order to get the animation to trigger we have to add a single CSS property to the <code>#toggle</code> <code>div</code> tag:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">     -webkit-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">padding-left</span> 250ms ease-out<span style="color: #00AA00;">;</span></pre></div></div>

<p>So whenever the <code>padding-left</code> property changes (on a Webkit browser) a quarter of a second ease-out transition will play and move the toggle button back and forth. Under the hood we&#8217;re changing the value of the <code>select</code> so that if we have to rely on that value it&#8217;s all in sync while still creating a very specific look-and-feel for our toggle button.</p>
<p>I realize this isn&#8217;t entirely helpful without a working demo and I&#8217;ll work on getting a jsFiddle or something up to show it but I&#8217;m working on some other bits of the project and want to be able to share the whole thing when it&#8217;s done. One of the main things I learned: CSS3 transitions aren&#8217;t entirely intuitive when coming from the Flash world, but they&#8217;re very powerful.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2012/01/building-a-mobile-themed-slider-without-jquery-mobile/" data-text="Building a Mobile-Themed Slider without jQuery Mobile" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2012/01/building-a-mobile-themed-slider-without-jquery-mobile/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2012/01/building-a-mobile-themed-slider-without-jquery-mobile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Must Read: JavaScript: The Good Parts</title>
		<link>http://blog.digitalbackcountry.com/2011/12/must-read-javascript-the-good-parts/</link>
		<comments>http://blog.digitalbackcountry.com/2011/12/must-read-javascript-the-good-parts/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 04:15:05 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2966</guid>
		<description><![CDATA[I just finished JavaScript: The Good Parts by Douglas Crockford and I highly, highly recommend it for anyone who is coming from a programming world that isn&#8217;t JavaScript. It&#8217;s an intelligent, and well-written book, but it also does the best &#8230; <a href="http://blog.digitalbackcountry.com/2011/12/must-read-javascript-the-good-parts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_2967" class="wp-caption alignright" style="width: 310px"><a href="http://shop.oreilly.com/product/9780596517748.do#"><img src="http://blog.digitalbackcountry.com/wp-content/uploads/javascript_good_parts.jpg" alt="JavaScript: The Good Parts" title="JavaScript: The Good Parts" width="300" height="392" class="size-full wp-image-2967" /></a><p class="wp-caption-text">JavaScript: The Good Parts</p></div>I just finished <a href="http://shop.oreilly.com/product/9780596517748.do">JavaScript: The Good Parts by Douglas Crockford</a> and I highly, highly recommend it for anyone who is coming from a programming world that isn&#8217;t JavaScript. It&#8217;s an intelligent, and well-written book, but it also does the best job of anything I&#8217;ve seen yet at explaining some of the nuances of JavaScript and why they can be beneficial.</p>
<p>I was absolutely one of those people who looked at JavaScript as a runty kid brother when I compared it to ActionScript 3. I started off wanting a lot of what ActionScript 3 had in JavaScript. This book completely changed my opinion because it did a fantastic job of laying out how some of the seemingly less-well designed parts of JavaScript end up being pretty powerful. It also highlights some of the areas (like Scope) where JavaScript uses C-like syntax but doesn&#8217;t implement it in the same way and may trip up developers. Finally there are a couple of chapters on the bad and awful parts of JavaScript to be aware of.</p>
<p>In a lot of ways it&#8217;s the perfect book for someone coming from AS3 to JavaScript. I think it will give you some new found respect for JavaScript and help with some of the parts of JS that seem a little contrary.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2011/12/must-read-javascript-the-good-parts/" data-text="Must Read: JavaScript: The Good Parts" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2011/12/must-read-javascript-the-good-parts/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2011/12/must-read-javascript-the-good-parts/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Recreating the Path Menu with Adobe Edge</title>
		<link>http://blog.digitalbackcountry.com/2011/12/recreating-the-path-menu-with-adobe-edge/</link>
		<comments>http://blog.digitalbackcountry.com/2011/12/recreating-the-path-menu-with-adobe-edge/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 11:35:16 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[adobe edge]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[path]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2958</guid>
		<description><![CDATA[I saw this blog post by Victor Coulon about redoing the Path menu in CSS3 and thought it was really slick. I&#8217;m not as up to speed on CSS3 as I need to be yet, but after taking a look &#8230; <a href="http://blog.digitalbackcountry.com/2011/12/recreating-the-path-menu-with-adobe-edge/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I saw <a href="http://lab.victorcoulon.fr/css/path-menu/">this blog post by Victor Coulon about redoing the Path menu in CSS3</a> and thought it was really slick. I&#8217;m not as up to speed on CSS3 as I need to be yet, but after taking a look at the post, I thought this was a perfect use case for animation in an application. It&#8217;s unintrusive, adds some overall polish, and generally improves the user interface. I thought Victor&#8217;s demo was awesome and since this use case is a good one for animation, I thought it would be an ideal experiment for Adobe Edge. (<a href="http://www.digitalbackcountry.com/demos/edge/pathdemo/path.html">Final result is here</a>)</p>
<h2>The Animation</h2>
<p>Building the animation itself was quite simple. I took Victor&#8217;s graphics, made them transparent PNGs, and imported them into Edge. At that point it was just a matter of lining everything up and using the timeline to tweak the animation. I didn&#8217;t sit down and do the math on the circle, so the elements aren&#8217;t aligned perfectly (apologies) but it&#8217;s basically just six elements that all pop in from behind the plus button. With Edge it was pretty easy to add the bounce effect. I just set the easing property to <code>easeOutBack</code> and that gave me the bounce.</p>
<div id="attachment_2959" class="wp-caption aligncenter" style="width: 560px"><img src="http://blog.digitalbackcountry.com/wp-content/uploads/pan_graphic.png" alt="" title="Path in Edge" width="550" height="455" class="size-full wp-image-2959" /><p class="wp-caption-text">The project loaded in Adobe Edge</p></div>
<h2>Interaction</h2>
<p>While the animation was easy, it took me a bit to get the interaction down correctly. Basically whenever the red button was clicked I wanted to play the timeline animation. When it was clicked again I wanted to reverse it. Luckily Edge has a <a href="http://labs.adobe.com/technologies/edge/resources/jsapi.html">decent API</a> that makes working with the code it generates pretty straightforward. The biggest issue I ran into was that the <code>playReverse()</code> API can only be run on a symbol and I was having trouble figuring out how to get a symbol instance from within my click event. Running <code>play()</code> on the Composition (kind of the main Edge element, and the one Edge uses by default) runs off an entire set of other operations that made it tougher to do what I wanted.</p>
<p>So instead I used <code>comp.getStage()</code> to get an instance of the &#8220;stage&#8221; symbol where I could play and reverse the timeline at will. The result is pretty close to what Victor created and what the Path app uses. To do it all, I replaced the Adobe Edge DOM Ready Event Handler code in my <code><em>project_name</em>_edge.js</code> file with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Adobe Edge DOM Ready Event Handler
 */</span>
$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     comp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Edge.<span style="color: #660066;">Composition</span><span style="color: #009900;">&#40;</span>compId<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>stage<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;.&quot;</span> <span style="color: #339933;">+</span> compId<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">/**
 * Adobe Edge Timeline Launch
 */</span>
     comp.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> symb <span style="color: #339933;">=</span> comp.<span style="color: #660066;">getStage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stage_add_button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>played<span style="color: #009900;">&#41;</span>
               <span style="color: #009900;">&#123;</span>
                    symb.<span style="color: #660066;">playReverse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    played <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    symb.<span style="color: #660066;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    played <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Downsides</h2>
<p>One downside is that once I make a change in Edge it overwrites all of the changes I&#8217;ve made. I&#8217;m not sure if there&#8217;s a safe place to make JavaScript edits like the one above but I&#8217;m going to check with the team. The other downside is that it&#8217;s all JavaScript, which makes it kind of heavy and you won&#8217;t get the hardware transforms that some browsers use for CSS3. I&#8217;m not much of a designer but after this little proof of concept I&#8217;m excited to see how Edge could potentially be used to add some fine-tuned interactions like the Path menu.</p>
<p>You can <a href="http://www.digitalbackcountry.com/demos/edge/pathdemo/path.html">see a working demo here</a> and the <a href="https://github.com/ryanstewart/Path-Menu-Demo-with-Adobe-Edge">source for the project is up on GitHub</a>.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2011/12/recreating-the-path-menu-with-adobe-edge/" data-text="Recreating the Path Menu with Adobe Edge" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2011/12/recreating-the-path-menu-with-adobe-edge/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2011/12/recreating-the-path-menu-with-adobe-edge/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Passing Data Between Pages in jQuery Mobile</title>
		<link>http://blog.digitalbackcountry.com/2011/12/passing-data-between-pages-in-jquery-mobile/</link>
		<comments>http://blog.digitalbackcountry.com/2011/12/passing-data-between-pages-in-jquery-mobile/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 22:53:09 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery mobile]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[pages]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2954</guid>
		<description><![CDATA[Coming from Flex one of the things I&#8217;ve struggled a bit with is passing data between views in my jQuery Mobile applications. The template approach with Mustache worked really well, but it also had a lot of overhead. In fiddling &#8230; <a href="http://blog.digitalbackcountry.com/2011/12/passing-data-between-pages-in-jquery-mobile/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Coming from Flex one of the things I&#8217;ve struggled a bit with is passing data between views in my jQuery Mobile applications. The <a href="http://blog.digitalbackcountry.com/2011/11/javascript-templating-kind-of-like-itemrenderers-or-binding-from-flex/">template approach with Mustache worked really well</a>, but it also had a lot of overhead. In fiddling around today I found a more hacky way that seems to work pretty well (though I think the Mustache route is still better). It relies on the fact that the <code>pagebeforeshow</code> method provides a <code>prevPage</code> property as part of its <code>data</code> object. That <code>prevPage</code> property is just a representation of everything in DOM of the previous page. That means it&#8217;s relatively easy to use selectors and that object to pass data to the new page.</p>
<p>The setup of my pages is as follows. My first page has a list of breweries, and each brewery page has a list of the beers that brewery uses. When you click on any of the beers, it goes to a form that can be used to rate the beers and provide some extra information about them. My goal was to prepopulate some of those forms with the beer data I already had. For instance I know the beer name, brewery, and style of each beer, so I should be able to prepopulate those, but they change for every beer so it has to be dynamic.</p>
<p>Within each page I defined a hidden <code>div</code> with two <code>span</code> elements with <code>id</code>s that represent the brewery name and brewery location (since they&#8217;re the same for every beer). Then within the beer list I have a hidden <code>div</code> that contains the beer name and the beer style. Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div data-role=&quot;page&quot; id=&quot;aleasylum&quot; data-theme=&quot;e&quot; data-add-back-btn=&quot;true&quot;&gt;
     &lt;div data-role=&quot;header&quot;&gt;
          &lt;h1&gt;Ale Asylum&lt;/h1&gt;
     &lt;/div&gt;
     &lt;div style=&quot;display:none&quot;&gt;
          &lt;span id=&quot;brewernameinfo&quot;&gt;Ale Asylum&lt;/span&gt;
          &lt;span id=&quot;brewerlocationinfo&quot;&gt;Madison, WI&lt;/span&gt;
     &lt;/div&gt;    
     &lt;div data-role=&quot;content&quot;&gt;    
          &lt;ul data-role=&quot;listview&quot;&gt;
               &lt;li data-role=&quot;list-divider&quot;&gt;Year Round Beers&lt;/li&gt;
               &lt;li&gt;
                    &lt;a href=&quot;#beerdetails&quot;&gt;
                         &lt;img src=&quot;images/hopalicious-thumb.gif&quot; /&gt;
                         &lt;h3&gt;Hopalicious&lt;/h3&gt;
                         &lt;p&gt;5.8% abv. Eleven separate additions of cascade hops give this American pale ale its lush citrus aroma and bold hop flavor without crazy bitterness. Hopalicious is available year round in six packs and on tap throughout the Madison and Milwaukee regions.&lt;/p&gt;
                         &lt;div style=&quot;display:none&quot;&gt;
                              &lt;span id=&quot;beernameinfo&quot;&gt;Hopalicious&lt;/span&gt;
                              &lt;span id=&quot;beerstyleinfo&quot;&gt;IPA&lt;/span&gt;
                         &lt;/div&gt;
                    &lt;/a&gt;
               &lt;/li&gt;
               &lt;li&gt;
                    &lt;a href=&quot;#beerdetails&quot;&gt;
                         &lt;img src=&quot;images/madtown-nutbrown-thumb.gif&quot; /&gt;
                         &lt;h3&gt;Madtown Nutbrown&lt;/h3&gt;
                         &lt;p&gt;5.5% abv. Our nutbrown ale is velvety smooth with a rich caramel aroma. We blend seven different malts for just the right touch of sweetness and a creamy finish youÔøΩll really dig. Madtown Nutbrown is available year round in six packs and on tap throughout the Madison and Milwaukee regions.&lt;/p&gt;
                         &lt;div id=&quot;info&quot; style=&quot;display:none&quot;&gt;
                              &lt;span id=&quot;beernameinfo&quot;&gt;Madtown Nutbrown&lt;/span&gt;
                              &lt;span id=&quot;beerstyle&quot;&gt;IPA&lt;/span&gt;
                         &lt;/div&gt;                        
                    &lt;/a&gt;
               &lt;/li&gt;</pre></div></div>

<p>So in order to grab that, I just added an event listener to the <code>pagebeforeshow</code> method that uses selectors to grab the data. One of the critical parts is that jQuery selectors have an optional <code>context</code> property that can be set so that jQuery only selects from that context. In this case, since my pages are all using the same id names for the values, I need to set the context so that the selectors are only pulling from the previous page and not the entire document.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beerdetails'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pagebeforeshow'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #003366; font-weight: bold;">var</span> beername <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-btn-hover-e #beernameinfo'</span><span style="color: #339933;">,</span>data.<span style="color: #660066;">prevPage</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> brewername <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#brewernameinfo'</span><span style="color: #339933;">,</span>data.<span style="color: #660066;">prevPage</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> brewerlocation <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#brewerlocationinfo'</span><span style="color: #339933;">,</span>data.<span style="color: #660066;">prevPage</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> beerstyle <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-btn-hover-e #beerstyleinfo'</span><span style="color: #339933;">,</span>data.<span style="color: #660066;">prevPage</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beername'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>beername<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#brewername'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>brewername<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#brewerlocation'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>brewerlocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beerstyle'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>beerstyle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The code above executes before anything gets displayed on the new page, grabs the values from the first page with the hidden <code>div</code> tags, and then sets some of the form fields to those new values.</p>
<p>It strikes me as a bit odd that there isn&#8217;t an easier way to do this, so it could be that I&#8217;m just not googling the correct thing and jQuery Mobile has something built-in to help with this issue. It does seem like this can be done by <a href="http://forum.jquery.com/topic/passing-parameters-between-pages">using URL variables</a>, but what I like about this approach is that it&#8217;s a bit more semantic and there&#8217;s no required parsing of the URL string.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2011/12/passing-data-between-pages-in-jquery-mobile/" data-text="Passing Data Between Pages in jQuery Mobile" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2011/12/passing-data-between-pages-in-jquery-mobile/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2011/12/passing-data-between-pages-in-jquery-mobile/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Defining Callbacks/Events Handlers for Mustache.JS Templates</title>
		<link>http://blog.digitalbackcountry.com/2011/11/defining-callbacksevents-handlers-for-mustache-js-templates/</link>
		<comments>http://blog.digitalbackcountry.com/2011/11/defining-callbacksevents-handlers-for-mustache-js-templates/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 08:47:49 +0000</pubDate>
		<dc:creator>ryanstewart</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[lawnchair]]></category>
		<category><![CDATA[mustache]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://blog.digitalbackcountry.com/?p=2948</guid>
		<description><![CDATA[This is pretty basic, but I had to do a bit of digging to figure out the answer so I wanted to post it. Essentially, since I&#8217;m using Mustache.js to load templates, I wanted to find a way to bind &#8230; <a href="http://blog.digitalbackcountry.com/2011/11/defining-callbacksevents-handlers-for-mustache-js-templates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is pretty basic, but I had to do a bit of digging to figure out the answer so I wanted to post it. Essentially, since I&#8217;m using <a href="http://blog.digitalbackcountry.com/2011/11/javascript-templating-kind-of-like-itemrenderers-or-binding-from-flex/">Mustache.js to load templates</a>, I wanted to find a way to bind events to elements in those templates. My template has a form element and when the form gets submitted, I wanted to handle the data. The JavaScript is easy, especially with jQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">                         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beerform'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                              <span style="color: #003366; font-weight: bold;">var</span> beer_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beerform :input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                                   beer_obj<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
                              <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              beers.<span style="color: #660066;">all</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>arrBeers<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
                                   <span style="color: #003366; font-weight: bold;">var</span> beer_db_obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>beername<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">beername</span><span style="color: #339933;">,</span>brewername<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">brewername</span><span style="color: #339933;">,</span>brewerlocation<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">brewerlocation</span>
                         <span style="color: #339933;">,</span>beerstyle<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">beerstyle</span><span style="color: #339933;">,</span>quantity<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">quantity</span><span style="color: #339933;">,</span>purchasedate<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">purchasedate</span><span style="color: #339933;">,</span>price<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">price</span>
                         <span style="color: #339933;">,</span>cellardate<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">cellardate</span><span style="color: #339933;">,</span>cellartemp<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">cellartemp</span><span style="color: #339933;">,</span>brewdate<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">brewdate</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                                   console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>beer_db_obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                   beers.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>key<span style="color: #339933;">:</span>arrBeers.<span style="color: #660066;">length</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>value<span style="color: #339933;">:</span>beer_db_obj<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There&#8217;s kind of a lot of nastiness going on there, but basically I&#8217;m just getting all of the elements from the form that has been submitted, putting them into an object and then preparing them for the database and saving them using <a href="http://westcoastlogic.com/lawnchair/">Lawnchair</a>. The problem was that I was putting it in the same place I put all of my other JavaScript events, as a separate function inside my <a href="https://github.com/ryanstewart/BeerCellarManager/blob/master/scripts/app.js">app.js</a> file. But when I&#8217;d load the page and submit the form, nothing happened. It took me a couple of minutes to figure out what was going on.</p>
<p>Since Mustache doesn&#8217;t load things into the DOM right away, I had to make sure the above code was only being added <strong>after</strong> the Mustache template had loaded. By putting the code within the callback function for the original <code>get()</code> method, which retrieves the template with Ajax, and making sure the template had been injected into the DOM, it worked.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">               $.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'templates/beer_add.mustache'</span><span style="color: #339933;">,</span>
                    <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                         template <span style="color: #339933;">=</span> data<span style="color: #339933;">;</span>
                         <span style="color: #003366; font-weight: bold;">var</span> renderedhtml <span style="color: #339933;">=</span> Mustache.<span style="color: #660066;">to_html</span><span style="color: #009900;">&#40;</span>template<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#content'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>renderedhtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                         <span style="color: #006600; font-style: italic;">// the template is now in the DOM</span>
                         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beerform'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                              <span style="color: #003366; font-weight: bold;">var</span> beer_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#beerform :input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                                   beer_obj<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
                              <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              beers.<span style="color: #660066;">all</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>arrBeers<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
                                   <span style="color: #003366; font-weight: bold;">var</span> beer_db_obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>beername<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">beername</span><span style="color: #339933;">,</span>brewername<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">brewername</span><span style="color: #339933;">,</span>brewerlocation<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">brewerlocation</span>
                         <span style="color: #339933;">,</span>beerstyle<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">beerstyle</span><span style="color: #339933;">,</span>quantity<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">quantity</span><span style="color: #339933;">,</span>purchasedate<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">purchasedate</span><span style="color: #339933;">,</span>price<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">price</span>
                         <span style="color: #339933;">,</span>cellardate<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">cellardate</span><span style="color: #339933;">,</span>cellartemp<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">cellartemp</span><span style="color: #339933;">,</span>brewdate<span style="color: #339933;">:</span>beer_obj.<span style="color: #660066;">brewdate</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                                   console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>beer_db_obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                   beers.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>key<span style="color: #339933;">:</span>arrBeers.<span style="color: #660066;">length</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>value<span style="color: #339933;">:</span>beer_db_obj<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                              <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                              console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>beer_obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Fairly obvious once I figured it out, but I&#8217;m still having to remind myself of just how the DOM operates so I don&#8217;t run into issues like this.</p>
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://blog.digitalbackcountry.com/2011/11/defining-callbacksevents-handlers-for-mustache-js-templates/" data-text="Defining Callbacks/Events Handlers for Mustache.JS Templates" data-count="horizontal">Tweet</a><div class="alignright"><div class="g-plusone" data-href="http://blog.digitalbackcountry.com/2011/11/defining-callbacksevents-handlers-for-mustache-js-templates/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://blog.digitalbackcountry.com/2011/11/defining-callbacksevents-handlers-for-mustache-js-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching using disk: basic
Object Caching 1105/1107 objects using disk: basic

Served from: blog.digitalbackcountry.com @ 2012-02-04 02:18:51 -->
