<?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>Mozilla Hacks - the Web developer blog &#187; Austin King</title>
	<atom:link href="http://hacks.mozilla.org/author/ozten/feed/" rel="self" type="application/rss+xml" />
	<link>http://hacks.mozilla.org</link>
	<description>hacks.mozilla.org</description>
	<lastBuildDate>Wed, 08 Feb 2012 22:52:35 +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>Screencast: BrowserID login flow on OpenPhoto.me</title>
		<link>http://hacks.mozilla.org/2011/11/screencast-browserid-login-flow-on-openphoto-me/</link>
		<comments>http://hacks.mozilla.org/2011/11/screencast-browserid-login-flow-on-openphoto-me/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 01:03:49 +0000</pubDate>
		<dc:creator>Austin King</dc:creator>
				<category><![CDATA[BrowserID]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Featured Demo]]></category>
		<category><![CDATA[Screencast]]></category>
		<category><![CDATA[BrowseriD]]></category>
		<category><![CDATA[OpenPhoto]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=10105</guid>
		<description><![CDATA[BrowserID is an initiative to provide the web with a better way to sign in. The web is a connected collection of resources and you should not have to have a user name and password for each of them when you could use the web instead. Today we show you a screencast of how easy [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://browserid.org/">BrowserID</a> is an initiative to provide the web with a better way to sign in. The web is a connected collection of resources and you should not have to have a user name and password for each of them when you could use the web instead. </p>
<p>Today we show you a screencast of how easy BrowserID makes it to login to a web site. For this, we&#8217;ll look at how the login flow for an existing BrowserID user works the first time they log in on a new website. Our example website is <a href="http://current.openphoto.me/">OpenPhoto</a>, a hot new photo sharing app that keeps users in control of their data.</p>
<h3>Screencast of logging into OpenPhoto with BrowserID</h3>
<p><video controls preload="none" style="width:100%;height:300px;" poster="http://cf.cdn.vid.ly/1l5i5m/poster.jpg"><source src="http://cf.cdn.vid.ly/1l5i5m/mp4.mp4" type="video/mp4"><source src="http://cf.cdn.vid.ly/1l5i5m/webm.webm" type="video/webm"><source src="http://cf.cdn.vid.ly/1l5i5m/ogv.ogv" type="video/ogg"><a target='_blank' href='http://vid.ly/1l5i5m'><img   src='http://cf.cdn.vid.ly/1l5i5m/poster.jpg' width="500"></a></video></p>
<h3>Get involved:</h3>
<p>BrowserID needs your help to grow and become a weapon of choice in the fight against insecure and annoying login systems. The great thing is that now is the time where you can be part of this.</p>
<ul>
<li><a href="https://github.com/mozilla/browserid/wiki/How-to-Use-BrowserID-on-Your-Site">Implement BrowserID</a></li>
<li><a href="http://theopenphotoproject.org/">Install OpenPhoto</a></li>
<li><a href="http://mozilla.github.com/browserid-field-guide/toc.html">Contribute to the Field Guide</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2011/11/screencast-browserid-login-flow-on-openphoto-me/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
<enclosure url="http://cf.cdn.vid.ly/1l5i5m/mp4.mp4" length="16057575" type="video/mp4" />
<enclosure url="http://cf.cdn.vid.ly/1l5i5m/webm.webm" length="16954384" type="video/webm" />
<enclosure url="http://cf.cdn.vid.ly/1l5i5m/ogv.ogv" length="15170781" type="video/ogg" />
		</item>
		<item>
		<title>XHR progress and rich file upload feedback</title>
		<link>http://hacks.mozilla.org/2009/06/xhr-progress-and-richer-file-uploading-feedback/</link>
		<comments>http://hacks.mozilla.org/2009/06/xhr-progress-and-richer-file-uploading-feedback/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 13:35:13 +0000</pubDate>
		<dc:creator>Austin King</dc:creator>
				<category><![CDATA[35 Days]]></category>
		<category><![CDATA[Feature]]></category>
		<category><![CDATA[Firefox 3.5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://hacks.mozilla.org/?p=682</guid>
		<description><![CDATA[This demo is by Olli Pettay (smaug) with help from Austin King. A common limitation on the web today has been a rich file upload widget for web applications. Many sites use Flash or a desktop helper applications to improve the experience of uploading files. Firefox 3.5 bridges one of these gaps allowing a better [...]]]></description>
			<content:encoded><![CDATA[<p><em>This demo is by Olli Pettay (smaug) with help from Austin King.</em></p>
<p>A common limitation on the web today has been a rich file upload widget for web applications. Many sites use Flash or a desktop helper applications to improve the experience of uploading files.</p>
<p>Firefox 3.5 bridges one of these gaps allowing a better progress indicator to be built. Many developers don’t realize that they can use Firefox’s File object (nsIDOMFile) and XMLHttpRequest together to accomplish file uploads. This demo will feature an upload widget that gives the kind of rich progress feedback that users have come to expect, as well as fast and easy multiple simultaneous file uploads.</p>
<p><strong>Progress Indicators</strong></p>
<p>It’s always a good idea to expose feedback that your application is hard at work for them, and when the current action is expected to finish.  The two main types of progress feedback are:</p>
<ul>
<li>indeterminate progress &#8211; some activity just happened
<li>deterministic progress I’m 40% done, I’m 42% done&#8230; etc
</ul>
<p><strong>Deterministicsaidwhat? The Demo</strong></p>
<p>We’ve created a simple file upload / download page that demonstrates the progress bar:</p>
<p><a href="http://mozilla.pettay.fi/xhr_upload/xhr_file_upload_demo_with_speed.html"><img width="500" height="97" src="http://hacks.mozilla.org/wp-content/uploads/2009/06/xhr-progress_500.jpg" border="0"></a></p>
<p>The demo is host at <a href="http://mozilla.pettay.fi/xhr_upload/xhr_file_upload_demo_with_speed.html">mozilla.pettay.fi</a> and requires <a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 3.5</a> beta4 or later. It demonstrates how to do multiple simultaneous file uploads without posting a form or leaving the current page. For each file upload / download we display the current speed, % complete, and bytes transmitted. We’ll go over a few key snippets of the code which are used in the screenshot above. Please click through the the <a title="demo" href="http://mozilla.pettay.fi/xhr_upload/xhr_file_upload_demo_with_speed.html">demo</a> and view source for the full code example.</p>
<p>The page contains two HTML inputs, one <code>type="file"</code> and one <code>type="button"</code>. The form is never actually submitted, instead we add an onclick handler to the button:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;startXHR();&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Upload file using XHR&quot;</span>&gt;</span></pre></div></div>

<p>In the startXHR function, we create an XMLHttpRequest and add an event handler to the XHR request to listen for the new &#8216;progress&#8217; event. With this ProgressEvent’s lengthComputable property, we will know if we are dealing with an indeterminate or deterministic progress. The object also gives us loaded and total bytes.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> xhr <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
xhr.<span style="color: #660066;">onprogress</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<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>evt.<span style="color: #660066;">lengthComputable</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    evt.<span style="color: #660066;">target</span>.<span style="color: #660066;">curLoad</span> <span style="color: #339933;">=</span> evt.<span style="color: #660066;">loaded</span><span style="color: #339933;">;</span>
    evt.<span style="color: #660066;">target</span>.<span style="color: #660066;">log</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">previousSibling</span>.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span>
        Number<span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">loaded</span><span style="color: #339933;">/</span>k<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">+</span> Number<span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">total</span><span style="color: #339933;">/</span>k<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;kB&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">lengthComputable</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> loaded <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">loaded</span> <span style="color: #339933;">/</span> evt.<span style="color: #660066;">total</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>loaded <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> newW <span style="color: #339933;">=</span> loaded <span style="color: #339933;">*</span> width<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newW <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> newW <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
            evt.<span style="color: #660066;">target</span>.<span style="color: #660066;">log</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> newW <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now we need some data to send. We grab the contents of the file directly from the input by id:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> files <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;file&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">files</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>files<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> file <span style="color: #339933;">=</span> files.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   xhr.<span style="color: #660066;">sendAsBinary</span><span style="color: #009900;">&#40;</span>file.<span style="color: #660066;">getAsBinary</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And the last step is to start the request:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">xhr.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;cgi-bin/posthandler.pl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #660066;">overrideMimeType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text/plain; charset=x-user-defined-binary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
xhr.<span style="color: #660066;">sendAsBinary</span><span style="color: #009900;">&#40;</span>file.<span style="color: #660066;">getAsBinary</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>These methods would also work with <code>xhr.upload.onprogress</code>.</p>
<p>Notice the use of the <a title="sendAsBinary" href="https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data">sendAsBinary</a> method on the <a title="XMLHttpRequest" href="https://developer.mozilla.org/En/Using_XMLHttpRequest" id="te5b">XMLHttpRequest</a> object and <a title="getAsBinary" href="https://developer.mozilla.org/En/NsIDOMFile" id="ketz">getAsBinary</a> on the File object. Starting with Firefox 3 you&#8217;ve been able to get at the contents of a file on the client side without form submission. This is quite useful for moving beyond the limitation of tranditional file input and form submissions. It is also part of an up and coming W3C <a title="standard" href="http://dev.w3.org/2006/webapi/FileUpload/publish/FileUpload.html#File-if" id="f-t1">standard</a> for FileUpload.</p>
<p>A related method that the nsIDOMFile provides is the getAsText method which returns a <a title="DOMString" href="https://developer.mozilla.org/En/DOM/DOMString" id="ylkc">DOMString</a> suitable for slicing, dicing, and displaying.</p>
<p>Here is an example usage, not used by the demo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">file.<span style="color: #660066;">getAsText</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;utf8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So that&#8217;s the gist of the code. Check out the <a href="http://mozilla.pettay.fi/xhr_upload/xhr_file_upload_demo_with_speed.html">demo and view it&#8217;s source</a>.</p>
<p><strong>Feedback In User Interfaces</strong></p>
<p>Exposing system feedback to users improves perceived performance. We<br />
can’t always determine how long something will take, so at a minimum we<br />
can show indeterminate progress.</p>
<p>During file uploads and file downloads (assuming the server gives us <code>Content-Length</code>) we do indeed know the total number of bytes. Firefox 3.5’s Progress Events support adds a progress event so that we can show actual upload/download progress.</p>
<p>Traditionally XMLHttpRequests were difficult to get deterministic progress back from. In theory, you could give it callbacks and watch for status code updates and textual message updates, but in practice they turn out to be not very useful. In the past, if a deterministic progress meter was important, you’d have to make a second XHR request to poll for progress.</p>
<p><strong>Enter Progress Events</strong></p>
<p>The W3C has a working draft for <a title="Progress Events 1.0" href="http://www.w3.org/TR/progress-events/" id="q91k">Progress Events 1.0</a> which we include in Firefox 3.5.  Firefox has added a key new DOM ProgressEvent <strong>progress</strong> event, as well as the <strong>loadstart</strong> event.  The other existing events included: error, abort and load.</p>
<p>These same events are also available for uploads and downloads. The progress event gives us the following properties:</p>
<ul>
<li>lengthComputable &#8211; true or false, is the size of the request known?
<li>loaded &#8211; number of bytes received so far
<li>total &#8211; number of bytes expected for entire request
</ul>
<p><strong>The Contract</strong></p>
<p>When you&#8217;re looking at the properties of those progress events, certain rules apply that you can depend on.  They are:</p>
<ul>
<li>The total property will be 0 when lengthComputable is false.
<li>The loadstart event is always signaled only once.
<li>The progress event is fired off zero or more times after loadstart.
</ul>
<p><a title="And that's it" href="http://mozilla.pettay.fi/xhr_upload/xhr_file_upload_demo_with_speed.html" id="a24v">And that&#8217;s it</a>. Go forth and improve file uploads with Firefox 3.5 goodness.</p>
]]></content:encoded>
			<wfw:commentRss>http://hacks.mozilla.org/2009/06/xhr-progress-and-richer-file-uploading-feedback/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
	</channel>
</rss>

