<?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</title>
	<atom:link href="http://hacks.mozilla.org/feed/" rel="self" type="application/rss+xml" />
	<link>https://hacks.mozilla.org</link>
	<description>hacks.mozilla.org</description>
	<lastBuildDate>Wed, 19 Jun 2013 12:07:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Updating and Tweaking your Firefox OS Developer Preview phone/Geeksphone</title>
		<link>https://hacks.mozilla.org/2013/06/updating-and-tweaking-your-firefox-os-developer-preview-phonegeeksphone/</link>
		<comments>https://hacks.mozilla.org/2013/06/updating-and-tweaking-your-firefox-os-developer-preview-phonegeeksphone/#comments</comments>
		<pubDate>Wed, 19 Jun 2013 12:07:13 +0000</pubDate>
		<dc:creator>Jason Weathersby</dc:creator>
				<category><![CDATA[Firefox OS]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21177</guid>
		<description><![CDATA[Developer Preview editions of the Firefox OS phone are now becoming widely available to the community, mainly through Geeksphone. Since these are for developers, naturally we want to encourage you to tinker and play with them as much as possible! In this post we will cover some basic tips on how to keep your phone [...]]]></description>
				<content:encoded><![CDATA[<p>Developer Preview editions of the Firefox OS phone are now becoming widely available to the community, mainly through <a href="http://www.geeksphone.com/">Geeksphone</a>. Since these are for developers, naturally we want to encourage you to tinker and play with them as much as possible! <br />In this post we will cover some basic tips on how to keep your phone up to date and how to tweak the system Gaia applications.</p>
<h2>Updating your Geeksphone to the latest images</h2>
<p>Firefox OS updates can be be downloaded from within the the Settings app, listed under Device information.  The phone can be set to check for updates daily, weekly or monthly.  In addition a “check now” button is provided.  When an update is available you will be prompted to download and install the current version.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/06/checkupate.png" alt=""/></p>
<p>The team at Geeksphone is also now providing the latest stable and nightly builds as self contained downloads for flashing your phone. Before proceeding make you have setup your phone as described in “Setting Up the Geeksphone Device” section of the <a href="https://hacks.mozilla.org/2013/05/pushing-firefox-os-apps-to-the-geeksphone/">Pushing Firefox OS Apps to the Geeksphone</a> post. This will insure that you can push data to the phone.</p>
<p>The builds are located at the <a href="http://downloads.geeksphone.com/">Geeksphone download site</a>. On this site you will be presented with options for selecting your device and what type of build you want to use.</p>
<p><a href="http://downloads.geeksphone.com/"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/06/geeksphone-downloads.png" alt=""></a></p>
<p>Download your particular build and extract the archive to your filesystem. The archive contains the images and commands required to flash the phone using Windows, Mac OS X or Linux. Before attempting to flash the phone make sure that you have enabled Remote debugging on the phone. This option can be set by launching the Settings app and navigating to <code>Device information -&gt; More information -&gt; Developer</code> tab. Also do not attempt to flash the phone if the power level is below 50%.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/06/remote-debugging.png" alt="" /></p>
<h3>Windows</h3>
<p>Open a Command Prompt (<code>start -&gt; type cmd in search -&gt; enter</code> on windows 7, <code>Windows key + X -&gt; select Command Prompt</code> on Windows 8) and cd to the directory containing the extracted files. Run:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">flash.bat.</pre></td></tr></table></div>

<h3>Mac OS X</h3>
<p>Open a Terminal (<code>Cmd + space -&gt; type terminal -&gt; enter</code>) window and cd to the directory containing the extracted files. Run:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>flash_mac.sh</pre></td></tr></table></div>

<h3>Linux</h3>
<p>Open a Terminal (control-alt-t on Ubuntu) window and cd to the directory containing the extracted files. Run:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>flash.sh</pre></td></tr></table></div>

<p>This should flash the new image to the phone. The phone will need to be setup again as all data will be cleared.</p>
<h2>Tweaking Gaia</h2>
<p>If you are of the industrious sort, you may want to tweak the default applications in Gaia &#8211; the UI in Firefox OS. In this section we will cover some of the basics for cloning Gaia and making changes to the default system apps. Bear in mind these tips are “at your own risk” and may involve you reading the later section “Ok, I bricked my phone”. Before proceeding make sure that you have adb and fastboot installed on your system. To verify if these are installed open a terminal and type adb devices with your phone connected. You should see something similar to the following.</p>
<p>You should also be able to run fastboot from the terminal. If you run fastboot, a set of parameter options should be displayed. If you do not have adb or fastboot installed, a quick Google search with your operating system will return several quick starts on how to install them. In addition to adb and fastboot you will need Git. If you do not currently have Git installed have a look at this <a href="https://help.github.com/articles/set-up-git">setup guide</a>. Finally make sure your phone is setup for remote debugging as described in the previous section.</p>
<p>Once you have the prerequisites you can open a terminal and cd to the directory you would like to clone the Gaia source code to and type the following commands.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>mozilla-b2g<span style="color: #000000; font-weight: bold;">/</span>gaia.git gaia
<span style="color: #7a0874; font-weight: bold;">cd</span> gaia</pre></td></tr></table></div>

<p>This will clone the current Gaia code to your system. Currently the Geeksphone Keon uses the v1.0.1 branch of Gaia code, so set the proper branch using the following command.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git checkout</span> <span style="color: #660033;">-b</span> v1.0.1 origin<span style="color: #000000; font-weight: bold;">/</span>v1.0.1</pre></td></tr></table></div>

<p>Most of the system apps are located in the apps subdirectory of gaia. You can now make any changes to these Firefox OS apps you wish. Once you have made changes run the following command to push the modified apps to your phone. This will by default push all the system apps to the phone:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">B2G_SYSTEM_APPS</span>=<span style="color: #000000;">1</span> <span style="color: #c20cb9; font-weight: bold;">make</span> install-gaia</pre></td></tr></table></div>

<p>If you only changed one of the apps you can specify the particular app using similar syntax. In this example only the calendar app will be pushed to the phone:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">APP</span>=calendar <span style="color: #007800;">B2G_SYSTEM_APPS</span>=<span style="color: #000000;">1</span> <span style="color: #c20cb9; font-weight: bold;">make</span> install-gaia</pre></td></tr></table></div>

<p>If you have issues while making the changes, you can reset the phone to default values using either of the following commands.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span> production
<span style="color: #c20cb9; font-weight: bold;">make</span> reset-gaia</pre></td></tr></table></div>

<p>Note: Bear in mind that either of the above commands will clear any data or apps that you have pushed to the phone.</p>
<h2>&#8220;Ok, I bricked my phone&#8221;</h2>
<p>If you are in the process of modifying your phone and it becomes “unresponsive” you should be able to recover it using fastboot with a simple procedure. The following illustrates reseting the Keon but other phones should have a similar process. You will also need to verify that you have fastboot installed.</p>
<p>First remove the USB cable and then remove the battery from the phone for thirty seconds. Then reinsert the battery and press the volume down button while holding the power button for a few seconds. Next re-connect the usb cable and run the following commands from a terminal window in the directory that contains the latest img files described in the first section of this post.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">fastboot flash recovery recovery.img
fastboot flash boot boot.img
fastboot flash userdata userdata.img
fastboot flash system system.img
fastboot reboot</pre></td></tr></table></div>

<p>This process should recover your phone.</p>
<h2>Go play!</h2>
<p>We hope these instructions are useful to you, and naturally we want you to be as happy about Firefox OS and the possibilities as we are! Feel free to play around with updating your devices, making changes/updates to Gaia apps and also to be inspired to take these learnings into <a href="https://hacks.mozilla.org/2013/02/getting-started-with-open-web-apps-why-and-how/">building your own Open Web Apps</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/06/updating-and-tweaking-your-firefox-os-developer-preview-phonegeeksphone/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Compete in the &#8220;Amp Your Firefox&#8221; Add-ons Contest</title>
		<link>https://hacks.mozilla.org/2013/06/compete-in-the-amp-your-firefox-add-ons-contest/</link>
		<comments>https://hacks.mozilla.org/2013/06/compete-in-the-amp-your-firefox-add-ons-contest/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 07:07:10 +0000</pubDate>
		<dc:creator>Jeff Griffiths</dc:creator>
				<category><![CDATA[Add-ons]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21053</guid>
		<description><![CDATA[People love their add-ons—85% of Firefox users have them installed, and there have been over 3 billion downloads since they revolutionized browsing in 2004. There are add-ons for almost everything under the sun: fun, productivity, personalization, even for making tea. Between June 13 – July 18, 2013, we challenge you to delight these fans by [...]]]></description>
				<content:encoded><![CDATA[<p>People love their add-ons—85% of Firefox users have them installed, and there have been over <a href="https://blog.mozilla.org/blog/2012/07/26/firefox-add-ons-cross-more-than-3-billion-downloads/">3 billion downloads</a> since they revolutionized browsing in 2004. There are add-ons for almost everything under the sun: <a href="https://addons.mozilla.org/en-US/firefox/addon/puzzle/">fun</a>, <a href="https://addons.mozilla.org/en-US/firefox/addon/leechblock/">productivity</a>, <a href="http://www.mozilla.org/en-US/firefox/customize/">personalization</a>, even for <a href="https://addons.mozilla.org/en-US/firefox/addon/tea-timer/">making tea</a>. <strong>Between June 13 – July 18, 2013</strong>, we challenge you to delight these fans by creating or updating add-ons that amp up their Firefox.</p>
<p>We’re also challenging you on the mobile front—with more than 10 million people using <a href="http://www.mozilla.org/en-US/firefox/fx/#mobile">Firefox for Android</a>, this is your chance to take the fun and personalization of add-ons to a fast-growing and passionate fan base.</p>
<p>A panel of <a href="https://blog.mozilla.org/addons/amp-your-firefox-judges">judges</a> will pick the best add-on from each prize <a href="https://blog.mozilla.org/addons/amp-your-firefox-winner-selection">category</a>, and the community will choose which category winner is the best overall add-on. Category winners will receive <a href="https://blog.mozilla.org/addons/amp-your-firefox-prizes/" target="_blank">Android tablets</a>, and the Best Overall winner will receive an 11-inch <a href="https://blog.mozilla.org/addons/amp-your-firefox-prizes/" target="_blank">Macbook Air</a>. All participants whose entry is approved (fully reviewed) for AMO will receive &#8220;Amp Your Firefox&#8221; <a href="http://blog.mozilla.org/addons/files/2013/05/Amp_Up_tshirt_concept.jpg" target="_blank">t-shirts</a>! The winning add-ons will also get tons of exposure on AMO and other Mozilla properties.</p>
<h2>The Categories</h2>
<h3>Best Mobile Add-on</h3>
<p>Create add-ons that take Firefox for Android to the next level for over 10 million users by improving readability, enhancing the web experience across devices, and rounding out browsing features—<a href="https://developer.mozilla.org/docs/Extensions/Mobile" target="_blank">get creative</a>!</p>
<h3>Best Mobile Add-on Port</h3>
<p>If you’ve created an add-on for desktop and think it would be great for a mobile audience, <a href="https://developer.mozilla.org/docs/Extensions/Mobile" target="_blank">port it over</a> to Firefox for Android!</p>
<h3>Best Game Add-on</h3>
<p>It takes creativity and imagination to make a great game add-on like <a href="https://addons.mozilla.org/firefox/addon/cheevos/" target="_blank">Cheevos</a> or <a href="https://addons.mozilla.org/firefox/addon/destroy-the-web/" target="_blank">Destroy the Web</a>&mdash;are you up for taking the challenge?</p>
<h3>Best Complete Theme</h3>
<p><a href="https://addons.mozilla.org/firefox/complete-themes/" target="_blank">Complete themes</a> can dramatically change the look of your Firefox—everything from buttons, window frames, tabs, and menus can be customized—the sky’s the limit. Create complete themes that are both aesthetically pleasing and transform the appearance of Firefox.</p>
<h3>Best Updated Add-on</h3>
<p>If you&#8217;ve created an add-on and want to freshen it up by adding new features, making it restartless, or porting it to the <a href="https://addons.mozilla.org/developers/builder" target="_blank">SDK</a>, this is the category for you.</p>
<h2>Mobile Next!</h2>
<p>One of the key categories we&#8217;re excited about for this competition is Mobile. Firefox for Android has done incredibly well in terms of user uptake and reviews in the Play marketplace, and the Android and Jetpack teams have both been working hard to make developing Add-ons for Mobile Firefox as easy as possible. Having said that, developing mobile add-ons is different enough that we thought we’d call out some of the highlights.</p>
<h3>NativeWindow &amp; BrowserApp</h3>
<p>NativeWindow and BrowserApp are privileged JavaScript APIs that allow developers to add their own custom functionality to the Native Java UI that is used on Firefox for Android instead of XUL. BrowserApp provides add-on developers the ability to interact with mobile browser tabs. NativeWindow allows developers to add menu items to the main and context menus, and to trigger native notifications.</p>
<p>Mark Finkle has created a <a href="https://github.com/mfinkle/skeleton-addon-fxandroid/blob/master/bootstrap.js">handy github repo</a> that includes all of the boilerplate code you’ll need to get started. Using this restartless add-on skeleton as the basis for your work, NativeWindow and BrowserApp are easy to access as properties off of the window object:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// show a toast immediately</span>
aWindow.<span style="color: #660066;">NativeWindow</span>.<span style="color: #660066;">toast</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Showing you a toast&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;short&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// add a menu item that shows a toast when clicked</span>
let menuId <span style="color: #339933;">=</span> aWindow.<span style="color: #660066;">NativeWindow</span>.<span style="color: #660066;">menu</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>“Hello<span style="color: #339933;">!</span>”<span style="color: #339933;">,</span> icon<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    aWindow.<span style="color: #660066;">NativeWindow</span>.<span style="color: #660066;">toast</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;I ran the callback!&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;short&quot;</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></td></tr></table></div>

<h3>Jetpack &#8211; mobile ready</h3>
<p>If you’re more comfortable with the Add-on SDK, I’m happy to report that the Jetpack team has done a lot of work to support mobile development. Most ( but not all ) Jetpack APIs work on Mobile, and the cfx command-line tool has been enhanced to be able to easily push your add-on onto the device for testing.</p>
<p>It is relatively simple to use NativeWindow from a Jetpack-based add-on:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// get the most recent window</span>
<span style="color: #000066; font-weight: bold;">const</span> utils <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'api-utils/window/utils'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">const</span> recent <span style="color: #339933;">=</span> utils.<span style="color: #660066;">getMostRecentBrowserWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// show a toast notification</span>
recent.<span style="color: #660066;">NativeWindow</span>.<span style="color: #660066;">toast</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span>opts.<span style="color: #660066;">message</span><span style="color: #339933;">,</span> duration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// listen for tabs events</span>
let tabs <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tabs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tabs.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ready'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tab<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>recent.<span style="color: #660066;">BrowserApp</span>.<span style="color: #660066;">selectedTab</span>.<span style="color: #660066;">id</span><span style="color: #339933;">,</span> tabs.<span style="color: #660066;">activeTab</span>.<span style="color: #660066;">id</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></td></tr></table></div>

<h3>Caveats</h3>
<p>Mobile phones present unique challenges for web browsers like Firefox mobile, so there are some very real limitations on what you can do with extensions as compared to desktop Firefox:</p>
<ul>
<li>Add-on Builder does not support packaging or running extensions on a phone</li>
<li>Firefox for Android does not support XUL overlays</li>
<li>not all of the Add-on SDK’s modules are compatible with Firefox for Android, please consult this <a href="https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/mobile.html#modules-compatibility" target="_blank">compatibility guide</a> for more information.</li>
</ul>
<p>For even more detail on using the NativeWindow api and Jetpack for hacking on mobile extensions, see <a href="https://blog.mozilla.org/addons/2013/06/13/jetpack-fennec-and-nativewindow/">the Jetpack, Fennec and NativeWindow blog post in the Mozilla Add-ons blog</a>.</p>
<h2>Get going!</h2>
<ul>
<li>See complete <a href="https://blog.mozilla.org/addons/amp-your-firefox/">contest details</a> on the AMO blog</li>
<li>See tutorials, articles, and connect with add-on developers in the <a href="https://developer.mozilla.org/en-US/addons">Developer Community</a> and <a href="https://addons.mozilla.org/en-US/developers/">Developer Hub</a></li>
<li>See articles on <a href="https://developer.mozilla.org/docs/Extensions/Mobile" target="_blank">developing extensions for Firefox on Android</a></li>
</ul>
<p>Have fun, and good luck!</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/06/compete-in-the-amp-your-firefox-add-ons-contest/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>May MDN sprint wrap-up</title>
		<link>https://hacks.mozilla.org/2013/06/may-mdn-sprint-wrap-up/</link>
		<comments>https://hacks.mozilla.org/2013/06/may-mdn-sprint-wrap-up/#comments</comments>
		<pubDate>Fri, 07 Jun 2013 14:59:28 +0000</pubDate>
		<dc:creator>Janet Swisher</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[MDN]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21121</guid>
		<description><![CDATA[Here are some of the high points from the MDN sprint that took place last weekend, May 31st and June 1st. New content Mixed security content blocking is now turned on by default in Firefox Aurora. David Bruant and Xavier Borderie improved the Mixed content page and David created How to fix a website with [...]]]></description>
				<content:encoded><![CDATA[<p>Here are some of the high points from the MDN sprint that took place last weekend, May 31st and June 1st.</p>
<h2>New content</h2>
<p><a href="https://blog.mozilla.org/tanvi/2013/04/10/mixed-content-blocking-enabled-in-firefox-23/">Mixed security content blocking</a> is now turned on by default in Firefox Aurora. <strong>David Bruant</strong> and <strong>Xavier Borderie</strong> improved the <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent">Mixed content</a> page and David created <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent/fix_website_with_mixed_content">How to fix a website with blocked mixed content</a>. </p>
<p><strong>J&eacute;r&eacute;mie Patonnier</strong> hosted the meet-up in the Paris office, and finished documenting the <a href="https://developer.mozilla.org/en-US/docs/tag/WebFM">WebFM API</a>. J&eacute;r&eacute;mie has been documenting lots of the hardware device APIs. Check out this <a href="https://developer.mozilla.org/en-US/docs/WebAPI/Detecting_device_orientation#Orientation_example">Device orientation example</a>, if your browser and device support it.</p>
<p>New contributor <strong>Scott Turner</strong> improved the <a href="https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB">Using IndexedDB</a> article.</p>
<h2>Translations</h2>
<p>A sprint meet-up in Mozilla&#8217;s Paris office meant that lots of French translation work got done, with lots of fixes to the corresponding English content along the way. Several people continued working after the end of the sprint, so by now:</p>
<ul>
<li><a href="https://developer.mozilla.org/fr/docs/Web/HTML/Element">All HTML element reference pages are translated into French</a>! Thanks to <strong>Thierry R&eacute;gagnon</strong>, <strong>Dorian Jamiais</strong>, <strong>Sphinx</strong>, <strong>mistyrouge</strong> and others who helped along the way. </li>
<li><strong>Jeremy Fourna</strong> translated several API pages into French: <a href="https://developer.mozilla.org/fr/docs/Web/API/AnimationEvent">AnimationEvent</a>, <a href="https://developer.mozilla.org/fr/docs/Web/API/Attr">Attr</a>, <a href="https://developer.mozilla.org/fr/docs/Web/API/AudioBuffer">AudioBuffer</a>, <a href="https://developer.mozilla.org/fr/docs/Web/API/AudioBufferSourceNode">AudioBufferSourceNode</a></li>
<li>Thierry and <strong>Jean-Bernard (&#8220;Goofy&#8221;) Marcon</strong> started translating the <a href="https://developer.mozilla.org/fr/docs/Web/Guide/HTML/Formulaires/Mon_premier_formulaire_HTML">HTML forms guide</a> into French.
</li>
<li><strong>Jesus Perez</strong> translated several <a href="https://developer.mozilla.org/es/docs/Aplicaciones">Apps</a> and <a href="https://developer.mozilla.org/es/docs/Mozilla/Firefox_OS">Firefox OS</a> docs into Spanish, which are very much needed to support the Firefox OS launch.
</li>
</ul>
<h2>Reviews</h2>
<p><strong>William Reynolds</strong> completed editorial reviews on a large number of articles, from <a href="https://developer.mozilla.org/en-US/docs/Rhino/Runtime">Rhino Runtime</a> to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object defineProperty</a>. </p>
<p><a href="https://developer.mozilla.org/en-US/docs/Project:MDN/Contributing/How_to_help#Content_reviews">Editorial reviews</a> (checking grammar, spelling, etc.) are a quick and easy way to contribute to MDN, even if you&#8217;re new to development. Lots of newcomers to MDN start out by doing editorial reviews &mdash; you can too! Just click <strong>Sign in</strong> on any MDN page, and create an account via <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Persona">Mozilla Persona</a>. </p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/06/may-mdn-sprint-wrap-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a simple paint game with HTML5 Canvas and Vanilla JavaScript</title>
		<link>https://hacks.mozilla.org/2013/06/building-a-simple-paint-game-with-html5-canvas-and-vanilla-javascript/</link>
		<comments>https://hacks.mozilla.org/2013/06/building-a-simple-paint-game-with-html5-canvas-and-vanilla-javascript/#comments</comments>
		<pubDate>Thu, 06 Jun 2013 06:47:42 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Firefox OS]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[pixels]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21115</guid>
		<description><![CDATA[When the talk is about HTML5 Canvas you mostly hear about libraries to make it work for legacy browsers, performance tricks like off-screen Canvas and ways to draw and animate sprites and tiles. This is only one part of Canvas, though. On the lowest level, Canvas is a way to manipulate pixels of a portion [...]]]></description>
				<content:encoded><![CDATA[<p>When the talk is about HTML5 Canvas you mostly hear about libraries to make it work for legacy browsers, performance tricks like off-screen Canvas and ways to draw and animate sprites and tiles. This is only one part of Canvas, though. On the lowest level, Canvas is a way to manipulate pixels of a portion of the screen. Either via a painting API or by directly manipulating the pixel array (which by the way is a <a href="http://www.khronos.org/registry/typedarray/specs/latest/">typed array</a> and thus performs admirably).</p>
<p>Using this knowledge, I thought it&#8217;d be fun to create a small game I saw in an ad for a tablet: a simple game for kids to paint letters. The result is a demo for FirefoxOS called <a href="http://codepo8.github.io/letterpaint/">Letterpaint</a> which will show up soon on the <a href="http://marketplace.mozilla.org/">Marketplace</a>. The <a href="https://github.com/codepo8/letterpaint/">code is on GitHub</a>.</p>
<p><a href="http://codepo8.github.io/letterpaint/"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/06/letterpaint.png" alt="letterpaint" width="319" height="479" class="alignnone size-full wp-image-21116" /></a></p>
<p>The fun thing about building Letterpaint was that I took a lot of shortcuts. Painting on a canvas is easy (and gets much easier using <a href="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html">Jacob Seidelin&#8217;s Canvas cheatsheet</a>), but on the first glance making sure that users stay in a certain shape is tricky. So is finding out how much of the letter has been filled in. However, by going back to seeing a Canvas as a collection of pixels, I found a simple way to make this work:</p>
<ul>
<li>When I paint the letter, I read out the amount of pixels that have the colour of the letter</li>
<li>When you click the mouse button or touch the screen I test the colour of the pixel at the current mouse/finger position</li>
<li>When the pixel is not transparent, you are inside the letter as the main Canvas by default is transparent</li>
<li>When you release the mouse or stop touching the screen I compare the amount of pixels of the paint colour with the ones of the letter.</li>
</ul>
<p>Simple, isn&#8217;t it? And it is all possible with two re-usable functions:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
  getpixelcolour(x, y)
  returns the rgba value of the pixel at position x and y
*/</span>
<span style="color: #000066; font-weight: bold;">function</span> getpixelcolour<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> pixels <span style="color: #339933;">=</span> cx.<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> c.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> c.<span style="color: #660066;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>y <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>pixels.<span style="color: #660066;">width</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
    r<span style="color: #339933;">:</span> pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    g<span style="color: #339933;">:</span> pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>index <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    b<span style="color: #339933;">:</span> pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>index <span style="color: #339933;">+</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    a<span style="color: #339933;">:</span> pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>index <span style="color: #339933;">+</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/*
  getpixelamount(r, g, b)
  returns the amount of pixels in the canvas of the colour 
  provided
*/</span>
<span style="color: #000066; font-weight: bold;">function</span> getpixelamount<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> g<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> pixels <span style="color: #339933;">=</span> cx.<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> c.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> c.<span style="color: #660066;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> all <span style="color: #339933;">=</span> pixels.<span style="color: #660066;">data</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> amount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</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> all<span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> <span style="color: #CC0000;">4</span><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>pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> r <span style="color: #339933;">&amp;&amp;</span>
        pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> g <span style="color: #339933;">&amp;&amp;</span>
        pixels.<span style="color: #660066;">data</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      amount<span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> amount<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Add some painting functions to that and you have the game done. You can see a <a href="http://codepo8.github.io/pixels-and-colours/">step by step guide of this online</a> (and <a href="https://github.com/codepo8/pixels-and-colours/">pull the code from GitHub</a>) and there is a screencast describing the tricks and decisions <a href="http://www.youtube.com/watch?v=9rsDNifGods">on YouTube</a>.</p>
<p><iframe width="500" height="281" src="https://www.youtube.com/embed/9rsDNifGods?rel=0" frameborder="0" allowfullscreen></iframe></p>
<p>The main thing to remember here is that it is very tempting to reach for libraries and tools to get things done quickly, but that it could mean that you think too complex. Browsers have very powerful tools built in for us, and in many cases it means you just need to be up-to-date and fearless in trying something &#8220;new&#8221; that comes out-of-the-box.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/06/building-a-simple-paint-game-with-html5-canvas-and-vanilla-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Proximity API</title>
		<link>https://hacks.mozilla.org/2013/06/the-proximity-api/</link>
		<comments>https://hacks.mozilla.org/2013/06/the-proximity-api/#comments</comments>
		<pubDate>Wed, 05 Jun 2013 10:54:04 +0000</pubDate>
		<dc:creator>Robert Nyman [Editor]</dc:creator>
				<category><![CDATA[Firefox OS]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[WebAPI]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21107</guid>
		<description><![CDATA[Something that&#8217;s very nice with bringing the web to the mobile platform with Firefox OS and WebAPIs is the ability to connect more into the physical world. One part there is the Proximity API, which is also a W3C Working Draft &#8211; Proximity Events. What it is The API is about detecting how close the [...]]]></description>
				<content:encoded><![CDATA[<p>Something that&#8217;s very nice with bringing the web to the mobile platform with Firefox OS and <a href="https://hacks.mozilla.org/2013/02/using-webapis-to-make-the-web-layer-more-capable/">WebAPIs</a> is the ability to connect more into the physical world. One part there is the Proximity API, which is also a <a href="http://www.w3.org/TR/proximity/">W3C Working Draft &#8211; Proximity Events</a>.</p>
<h2>What it is</h2>
<p>The API is about detecting how close the device is to any other physical object, by accessing the proximity sensor. There are two ways of working with proximity</p>
<ul>
<li>Device proximity</li>
<li>User proximity</li>
</ul>
<p>From the spec:</p>
<p>The <code>DeviceProximityEvent</code> interface provides web developers information about the distance between the hosting device and a nearby object.</p>
<p>The <code>UserProximityEvent</code> interface provides web developers a user-agent- and platform-specific approximation that the hosting device has sensed a nearby object.</p>
<h2>Using it</h2>
<p>Working with proximity is as easy as adding a couple of event handlers, depending on what you want to do. The <code>deviceproximity</code> event works with the metric system, and you will get back the distance in centimeters (these examples take for granted that you have an existing proximityDisplay element to present the values in). You are also able to check the minimum and maximum distance the sensor in your device supports. </p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/06/device-proximity.png" alt="" title="" /></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">ondeviceproximity</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Check proximity, in centimeters</span>
    <span style="color: #000066; font-weight: bold;">var</span> prox <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;strong&gt;Proximity: &lt;/strong&gt;&quot;</span> <span style="color: #339933;">+</span> event.<span style="color: #660066;">value</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; cm&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
        prox <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;strong&gt;Min value supported: &lt;/strong&gt;&quot;</span> <span style="color: #339933;">+</span> event.<span style="color: #660066;">min</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; cm&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
        prox <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;strong&gt;Max value supported: &lt;/strong&gt;&quot;</span> <span style="color: #339933;">+</span> event.<span style="color: #660066;">max</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; cm&quot;</span><span style="color: #339933;">;</span>
    proximityDisplay.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> prox<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It should be noted that the values sensors currently can return a quite small value, ranging from 0 up to 5 or 10 centimeters. In general, I believe the use case has been to detect if the user is holding the device up to the ear or not, but my personal opinion is that this could provide to be even more exciting if it supported, say, up to a meter!</p>
<p>With <code>userproximity</code>, the value you get back is a <code>near</code> property on the <code>event</code> object, which is a boolean returning whether the user is near to the sensor or not.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/06/user-proximity.png" alt="" title="" /></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">onuserproximity</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Check user proximity</span>
    <span style="color: #000066; font-weight: bold;">var</span> userProx <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;strong&gt;User proximity - near: &lt;/strong&gt;&quot;</span> <span style="color: #339933;">+</span> event.<span style="color: #660066;">near</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
    userProximityDisplay.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> userProx<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I&#8217;ve also added device and proximity code and testing to the <a href="https://github.com/robnyman/Firefox-OS-Boilerplate-App">Firefox OS Boilerplate App</a> so feel free to get the latest code there and play around with it.</p>
<h2>Web browser support</h2>
<p>The Proximity API is currently supported in:</p>
<ul>
<li><a href="https://developer.mozilla.org/en/docs/Mozilla/Firefox_OS">Firefox OS</a></li>
<li><a href="https://play.google.com/store/apps/details?id=org.mozilla.firefox&amp;hl=en">Firefox on Android</a></li>
</ul>
<h2>Conclusion</h2>
<p>Working with proximity is yet another example of crossing the gap between software and real physical context, and showing just how powerful the web can be. We hope to see you creating many interesting things based on it!</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/06/the-proximity-api/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building a Todo app for Firefox OS, part 1</title>
		<link>https://hacks.mozilla.org/2013/06/building-a-todo-app-for-firefox-os-part-1/</link>
		<comments>https://hacks.mozilla.org/2013/06/building-a-todo-app-for-firefox-os-part-1/#comments</comments>
		<pubDate>Tue, 04 Jun 2013 08:21:23 +0000</pubDate>
		<dc:creator>Fawad Hassan</dc:creator>
				<category><![CDATA[Firefox OS]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21077</guid>
		<description><![CDATA[This is the first part out of two in a tutorial series where we will build a Todo app for Firefox OS from scratch. I assume you have some understanding of HTML5, CSS3, JavaScript, jQuery/Zepto, and Backbone.js. In this part we will handcraft a properly structured and semantic UI of a Todo app using best [...]]]></description>
				<content:encoded><![CDATA[<p>This is the first part out of two in a tutorial series where we will build a Todo app for Firefox OS from scratch. I assume you have some understanding of HTML5, CSS3, JavaScript, jQuery/Zepto, and Backbone.js. In this part we will handcraft a properly structured and semantic UI of a Todo app using best practices for designing UIs for mobile.</p>
<p>The source for the <a href="https://github.com/iFadey/fos-todo-app">Todo app is available on GitHub</a>.</p>
<h2>Setting Up the Environment</h2>
<p>We will use <a target="_blank" href="http://volojs.org/">volo</a> as our package manager and build tool.</p>
<h3>Step 1</h3>
<p>First you need to install <a target="_blank" href="http://nodejs.org">Node.js</a> because volo depends on it. Windows and Mac users can download it from <a target="_blank" href="http://nodejs.org/download/">here</a>. But for Linux users, I recommend you use the package manager: <a target="_blank" href="https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager">instructions for installation using package manager on different distros</a>.</p>
<h3>Step 2</h3>
<p>Install volo using the following command.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">npm <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-g</span> volo</pre></td></tr></table></div>

<p>Make sure you use `sudo` before above command in *nix environment.</p>
<h3>Step 3</h3>
<p>Create a blank project <code>fos-todo-app</code> using `volo create` command.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">volo create fos-todo-app</pre></td></tr></table></div>

<p>This will create a folder <code>fos-todo-app</code> and copy required volo project files from GitHub.</p>
<p><strong>Remember</strong> we will work only with the files in <code>fos-todo-app/www</code> directory. If you have never worked with volo before, [Streamline your Process with Volo](http://net.tutsplus.com/tutorials/javascript-ajax/streamline-your-process-with-volo/) is a recommended read.</p>
<h3>Step 4</h3>
<p>Make sure you have the latest stable version of Firefox installed. Then [install the Firefox OS simulator add-on](https://addons.mozilla.org/en-US/firefox/addon/firefox-os-simulator/). At the end of this article we will test UI of our app in this simulator.</p>
<h3>Step 5</h3>
<p>Get the [MozTT font](https://github.com/mozilla-b2g/moztt/tree/master/MozTT) and install it. MozTT is the font used in Firefox OS. It&#8217;s an optional step but it&#8217;s better to install this font on your system so you can get consistent look and feel in the Firefox OS Simulator and the real phone.</p>
<h2>Todo View</h2>
<p>The first UI that we will build will show a title in the header, Add/Delete buttons in the footer and a todo list. This view will be used for viewing, editing, mark as complete, and deleting tasks.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/todo-view.png" alt="Todo View - Firefox OS"></p>
<p>Add <code>role="application"</code> attribute to the `body` element and write following HTML for the Todo View.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;view-todos&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;region&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Todos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;article</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;view-content&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;todo-list&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;todo-list reset-list&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;list&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;listitem&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My task 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">aria-hidden</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;btn edit&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Edit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;listitem&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;checkbox&quot;</span> checked<span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My task 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">aria-hidden</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;btn edit&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Edit<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/article<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;footer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menu</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;toolbar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;menuitem&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;btn add&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Add<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;menuitem&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;btn del&quot;</span> disabled<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Delete<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/footer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #808080; font-style: italic;">&lt;!--end view-todos--&gt;</span></pre></td></tr></table></div>

<p>Each view is assigned a <code>role="region"</code>. Within the view, you can have <code>header</code>, <code>footer</code> and any container element having the <code>view-content</code> class which will contain the contents of the view.</p>
<p>In the above view&#8217;s content, we have <code>ul[role=list]</code> which contains tasks entered by user. For testing purposes, I added two dummy tasks so you can understand each list item&#8217;s (`li[role=listitem]`) structure. Within each list item we have a <code>label</code> element containing a <code>&lt;input type="checkbox"&gt;</code> and a <code>span</code> element containing the text of task. The second element in the list item contains a <code>&lt;input type="text"&gt;</code> element which is initially hidden using attribute <code>aria-hidden="true"</code>. Finally the third element is <code>.btn.edit</code> (edit button).</p>
<p><strong>Note:</strong> Of course it&#8217;s not magic. We will write CSS for all these attributes. Check out <a href="http://alistapart.com/article/aria-and-progressive-enhancement">ARIA and Progressive Enhancement</a> if you are new to WAI-ARIA.</p>
<p>The purpose of placing the <code>label</code> in the list item is to display each task&#8217;s text and <code>input[type=text]</code> (which is initially hidden) will be used to edit that text. Any task can enter edit mode when user <a href="http://zeptojs.com/#touch"><code>tap</code></a> on <code>.btn.edit</code> (edit button). Similarly, tasks are &#8220;marked as completed&#8221; when user <code>tap</code> on <code>label</code>.</p>
<p>In the <code>footer</code> we have <code>menu[role=toolbar]</code> containing Add/Delete buttons. Later using CSS for these buttons, we will display a svg icon in background and hide an inner span in it.</p>
<h2>Add View</h2>
<p>The second and final view in our app will be used to add tasks to the todo list.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/add-view-1.png" alt="Add View"></p>
<p>In this view we have a textbox for entering a task&#8217;s text, and a insert contact link will be used to add the contact number using <a href="https://hacks.mozilla.org/2013/01/introducing-web-activities/">Web Activities</a>. Here&#8217;s the HTML for Add View.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;view-add&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;region&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>[+] Todo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;view-content&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;wrapper&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menu</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;options&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;activities&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;reset-list&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;list&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;listitem&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;task&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>[Insert Contact]<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">aria-owns</span>=<span style="color: #ff0000;">&quot;btn-add-done&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;task&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;task&quot;</span> required<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;footer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menu</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;toolbar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;btn-add-done&quot;</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;menuitem&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;btn done&quot;</span> disabled<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Done<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;menuitem&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;btn del&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cancel<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/footer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #808080; font-style: italic;">&lt;!--end view-add--&gt;</span></pre></td></tr></table></div>

<p>Note that the contents in <code>section.view-content</code> is wrapped using <code>div.wrapper</code> so we can limit its <code>max-width</code> and right align <code>menu.options</code>.</p>
<p>Second thing to note here is the <a href="http://www.w3.org/TR/wai-aria/states_and_properties#aria-owns"><code>aria-owns</code></a> attribute on <code>form</code> element. This attribute relates to the <code>form</code> with <code>btn-add-done</code>.</p>
<h2>Element Styles</h2>
<p>Let&#8217;s write the CSS for the HTML elements. An explanation is given in comments above each selector.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Stretch vertically */</span>
html<span style="color: #00AA00;">,</span> body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
body <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> radial-gradient<span style="color: #00AA00;">&#40;</span>ellipse at <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">231</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">76</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">60</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">192</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">57</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">43</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> MozTT<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Reset base size */</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Set font size relative to base size */</span>
  <span style="color: #808080; font-style: italic;">/* Check &lt;a href=&quot;http://snook.ca/archives/html_and_css/font-size-with-rem&quot;&gt;this&lt;/a&gt; article on rem usage */</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> 1.4rem<span style="color: #00AA00;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Remove spacing */</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> 3rem<span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
a <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFA49E</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</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>.3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
input<span style="color: #00AA00;">,</span> button<span style="color: #00AA00;">,</span> select<span style="color: #00AA00;">,</span> textarea <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-radius</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  box-shadow<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #993333;">text</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">,</span> textarea<span style="color: #00AA00;">,</span> select <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> MozTT<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> 1.3rem<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">300</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> .7rem .8rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h2>View Specific Styles</h2>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#view-todos</span> <span style="color: #00AA00;">&gt;</span> <span style="color: #6666ff;">.view-content</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: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#view-add</span> <span style="color: #00AA00;">&gt;</span> <span style="color: #6666ff;">.view-content</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> 2rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#view-add</span> <span style="color: #00AA00;">&gt;</span> <span style="color: #6666ff;">.view-content</span> <span style="color: #00AA00;">&gt;</span> <span style="color: #6666ff;">.wrapper</span> <span style="color: #00AA00;">&#123;</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;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">max-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">800px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#view-add</span> input<span style="color: #00AA00;">&#91;</span>name<span style="color: #00AA00;">=</span>task<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#view-add</span> <span style="color: #6666ff;">.options</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> .5rem <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#view-add</span> <span style="color: #6666ff;">.options</span> <span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>listitem<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> .5rem <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#view-add</span> <span style="color: #6666ff;">.options</span> a <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> .4rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h2>Module Styles</h2>
<h3>View Module</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* All views have region role so selecting them with attribute selector  */</span>
<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>region<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> radial-gradient<span style="color: #00AA00;">&#40;</span>ellipse at <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">231</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">76</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">60</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">192</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">57</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">43</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Stretch both vertically/horizontally */</span>
  <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
  overflow-x<span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>region<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> header <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> .5rem <span style="color: #cc66cc;">0</span> 1rem <span style="color: #cc66cc;">0</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>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>region<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> header <span style="color: #00AA00;">&gt;</span> h1 <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</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>.4<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>region<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> <span style="color: #6666ff;">.view-content</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> 1rem 4rem 1rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>region<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> footer <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</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>.2<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</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>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>region<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> footer <span style="color: #00AA00;">&gt;</span> menu<span style="color: #00AA00;">&#91;</span>role<span style="color: #00AA00;">=</span>toolbar<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>Button Module</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.btn</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> 3.5rem<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> 3.5rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span> <span style="color: #00AA00;">&gt;</span> span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span><span style="color: #3333ff;">:disabled </span><span style="color: #00AA00;">&#123;</span>
  opacity<span style="color: #00AA00;">:</span> .2<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span><span style="color: #6666ff;">.done</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/check.svg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span><span style="color: #6666ff;">.add</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/add.svg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span><span style="color: #6666ff;">.del</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/del.svg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span><span style="color: #6666ff;">.edit</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/edit.svg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btn</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span>.1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>Todo List Module</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.todo-list</span> <span style="color: #00AA00;">&gt;</span> li <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span>.1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.todo-list</span> <span style="color: #00AA00;">&gt;</span> li <span style="color: #00AA00;">&gt;</span> <span style="color: #6666ff;">.btn</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> 3.9rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.todo-list</span> label <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</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;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> 1rem 2.8rem 1rem 1rem<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.todo-list</span> <span style="color: #00AA00;">&gt;</span> li<span style="color: #3333ff;">:last-child</span><span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.todo-list</span> <span style="color: #00AA00;">&gt;</span> li<span style="color: #3333ff;">:last-child </span><span style="color: #00AA00;">&gt;</span> label <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.todo-list</span> label <span style="color: #00AA00;">&gt;</span> span <span style="color: #00AA00;">&#123;</span>
  transition<span style="color: #00AA00;">:</span> all .5s<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/***
  This selector is interesting. It creates a line-through and
  decrease opacity of text in span when checkbox is checked
***/</span>
<span style="color: #6666ff;">.todo-list</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>checkbox<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">line-through</span><span style="color: #00AA00;">;</span>
  opacity<span style="color: #00AA00;">:</span> .4<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.todo-list</span> <span style="color: #00AA00;">&gt;</span> li <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #993333;">text</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> .4rem<span style="color: #00AA00;">;</span>
  <span style="color: #808080; font-style: italic;">/* removing input padding and margin from 100% */</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span><span style="color: #933;">100%</span> - 2.3rem<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h2>Utility Styles</h2>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.reset-list</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#91;</span>aria-hidden<span style="color: #00AA00;">=</span>true<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> !important<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h2>Animations</h2>
<p>Following are a few animation effects that we will use to animate our views. Although we will use <a href="http://zeptojs.com">Zepto.js</a> which on run-time generates CSS3 animations using JavaScript, I prefer to write my own animations using CSS3 and make use of it by applying/removing CSS classes on DOM elements.</p>
<blockquote cite="http://zeptojs.com/">
<p>Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API. If you use jQuery, you already know how to use Zepto. ‐ <a href="http://zeptojs.com/">zeptojs.com</a></p>
</blockquote>
<p>Check out the <a href="http://css3.bradshawenterprises.com/animations/">How to use CSS Animations</a> tutorial for understanding CSS3 Animations better.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.slide-up-in</span> <span style="color: #00AA00;">&#123;</span>
  animation-name<span style="color: #00AA00;">:</span> slide-up-in<span style="color: #00AA00;">;</span>
  animation-duration<span style="color: #00AA00;">:</span> .6s<span style="color: #00AA00;">;</span>
  transform<span style="color: #00AA00;">:</span> translateY<span style="color: #00AA00;">&#40;</span><span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@keyframes slide-up-in {</span>
  <span style="color: #933;">0%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateY<span style="color: #00AA00;">&#40;</span><span style="color: #933;">30%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateY<span style="color: #00AA00;">&#40;</span><span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.slide-down-out</span> <span style="color: #00AA00;">&#123;</span>
  animation-name<span style="color: #00AA00;">:</span> slide-down-out<span style="color: #00AA00;">;</span>
  animation-duration<span style="color: #00AA00;">:</span> .6s<span style="color: #00AA00;">;</span>
  transform<span style="color: #00AA00;">:</span> translateY<span style="color: #00AA00;">&#40;</span><span style="color: #933;">30%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@keyframes slide-down-out {</span>
  <span style="color: #933;">0%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateY<span style="color: #00AA00;">&#40;</span><span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateY<span style="color: #00AA00;">&#40;</span><span style="color: #933;">30%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.slide-right-in</span> <span style="color: #00AA00;">&#123;</span>
  animation-name<span style="color: #00AA00;">:</span> slide-right-in<span style="color: #00AA00;">;</span>
  animation-duration<span style="color: #00AA00;">:</span> .6s<span style="color: #00AA00;">;</span>
  transform<span style="color: #00AA00;">:</span> translateX<span style="color: #00AA00;">&#40;</span><span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@keyframes slide-right-in {</span>
  <span style="color: #933;">0%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateX<span style="color: #00AA00;">&#40;</span><span style="color: #933;">-100%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateX<span style="color: #00AA00;">&#40;</span><span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.slide-left-out</span> <span style="color: #00AA00;">&#123;</span>
  animation-name<span style="color: #00AA00;">:</span> slide-left-out<span style="color: #00AA00;">;</span>
  animation-duration<span style="color: #00AA00;">:</span> .6s<span style="color: #00AA00;">;</span>
  transform<span style="color: #00AA00;">:</span> translateX<span style="color: #00AA00;">&#40;</span><span style="color: #933;">-100%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@keyframes slide-left-out {</span>
  <span style="color: #933;">0%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateX<span style="color: #00AA00;">&#40;</span><span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  <span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> transform<span style="color: #00AA00;">:</span> translateX<span style="color: #00AA00;">&#40;</span><span style="color: #933;">-100%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h2>Testing in Firefox OS Simulator</h2>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/simulator-window.png" alt="Firefox OS Simulator"></p>
<p>You can pretty easily test the UI we have developed using the Firefox OS Simulator. All you need is a <code>manifest.webapp</code> file in root directory (fos-todo-app/www). Add the following json in it.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="json" style="font-family:monospace;">{
  &quot;version&quot;: &quot;0.1&quot;,
  &quot;name&quot;: &quot;Todos&quot;,
  &quot;description&quot;: &quot;Awesome todo app by iFadey&quot;,
  &quot;launch_path&quot;: &quot;/index.html&quot;,
  &quot;icons&quot;: {
    &quot;16&quot;: &quot;/img/icons/icon-16.png&quot;,
    &quot;48&quot;: &quot;/img/icons/icon-48.png&quot;,
    &quot;128&quot;: &quot;/img/icons/icon-128.png&quot;
  },
  &quot;developer&quot;: {
    &quot;name&quot;: &quot;Fawad Hassan&quot;,
    &quot;url&quot;: &quot;http://ifadey.com&quot;
  },
  &quot;installs_allowed_from&quot;: [&quot;*&quot;],
  &quot;appcache_path&quot;: &quot;/cache.manifest&quot;,
  &quot;default_locale&quot;: &quot;en&quot;
}</pre></td></tr></table></div>

<p>Currently I haven&#8217;t added an app icon but don&#8217;t worry about it. Firefox OS adds a default app icon if it doesn&#8217;t find one mentioned in the manifest file. Now open the simulator tab from <code>Tools > Web Developer > Firefox OS Simulator</code>. Then click <code>Add Directory</code> button and select the manifest file from our app directory. This will add our app in the simulator.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/app-in-simulator.png"></p>
<h2>End of part 1</h2>
<p>Now you have gotten started with the Todo app and have gotten going with a few easy steps. In next part we will add life in our app using JavaScript (Backbone/Zepto). We will create Todo model, collection, and views and for the sake of simplicity, we will only store our todo collection in IndexedDB. We will also make use of Web Activities to inject contact number in text of todo task.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/06/building-a-todo-app-for-firefox-os-part-1/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>MDN sprint for better web tech resources &#8212; join in!</title>
		<link>https://hacks.mozilla.org/2013/05/mdn-sprint-for-better-web-tech-resources-join-in/</link>
		<comments>https://hacks.mozilla.org/2013/05/mdn-sprint-for-better-web-tech-resources-join-in/#comments</comments>
		<pubDate>Fri, 31 May 2013 07:35:10 +0000</pubDate>
		<dc:creator>Janet Swisher</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[MDN]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21063</guid>
		<description><![CDATA[MDN is one of our most important resources, and the core of knowledge and sharing for developers around the world. Additionally, it&#8217;s one of the vital cornerstones for all information we share at Mozilla Hacks, so in whatever way you can take part, it is highly appreciated. &#8211; Editor&#8217;s note Over on the Mozilla Developer [...]]]></description>
				<content:encoded><![CDATA[<p><em>MDN is one of our most important resources, and the core of knowledge and sharing for developers around the world. Additionally, it&#8217;s one of the vital cornerstones for all information we share at Mozilla Hacks, so in whatever way you can take part, it is highly appreciated. &#8211; Editor&#8217;s note</em></p>
<p>Over on the <a href="https://developer.mozilla.org">Mozilla Developer Network</a> site, this Friday and Saturday (May 31 and June 1), we&#8217;re having the latest in our series of &#8220;MDN sprints&#8221;. This is a chance for you to learn about a web development topic, and help improve the resources about it on MDN by sharing what you learn or what you already know. Please join us!</p>
<h2>About what?</h2>
<p>The major topical focus for this sprint is <a href="https://developer.mozilla.org/en-US/docs/WebAPI">Web device APIs</a>, which give JavaScript code access to device hardware. How about trying them out, and then writing some helpful code examples?</p>
<p>Another timely topic is <a href="https://blog.mozilla.org/tanvi/2013/04/10/mixed-content-blocking-enabled-in-firefox-23/">mixed content blocking</a>, which just arrived in the Firefox Aurora channel. Help us explain to Web developers how to fix sites so users won&#8217;t be tripped up by mixed-security content.</p>
<p>But those are just suggestions; any topic for Web developers or Mozilla developers is fair game. You can also find more info and ideas on the <a href="https://wiki.mozilla.org/MDN/Doc_sprints/2013May">MDN sprint wiki page</a>.</p>
<h2>Where?</h2>
<p>You can join in from anywhere in the world. Of course you could just dive into MDN, but part of the point of a sprint is to do it with other people. Join the <a href="irc://irc.mozilla.org/devmo">#devmo channel on irc.mozilla.org</a> to talk with other sprinters, about what you&#8217;re doing, they&#8217;re doing, or whatever. (Here&#8217;s <a href="http://wiki.mozilla.org/IRC">info about IRC</a> if you&#8217;re not familiar with it.) We might also do a Google Hangout, so ask about that when you drop in.</p>
<p>If you happen to be in San Francisco or Paris, we&#8217;re holding in-person meetups for this sprint on June 1st, at the Mozilla spaces in those cities. Come on by and sprint in person!</p>
<ul>
<li><a href="http://lanyrd.com/2013/mozhacks/">San Francisco meetup page on Lanyrd</a></li>
<li><a href="http://lanyrd.com/2013/mozhacks/">Paris meetup page on Lanyrd</a></li>
</ul>
<h2>When?</h2>
<p>The sprint officially runs from 8:00 a.m. PDT on May 31st (<a href="http://www.timeanddate.com/worldclock/fixedtime.html?msg=MDN+May+sprint+start&#038;iso=20130531T08&#038;p1=224">Starting time in your timezone<a>) to 5:00 p.m. PDT on June 1st (<a href="http://www.timeanddate.com/worldclock/fixedtime.html?msg=MDN+May+sprint+end&#038;iso=20130601T17&#038;p1=224">Ending time in your timezone</a>). Of course, you can start earlier or continue later, and stay for as long or as short a time as fits your schedule.</p>
<p>Sound interesting? Give it a try!</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/mdn-sprint-for-better-web-tech-resources-join-in/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Optimizing your JavaScript game for Firefox OS</title>
		<link>https://hacks.mozilla.org/2013/05/optimizing-your-javascript-game-for-firefox-os/</link>
		<comments>https://hacks.mozilla.org/2013/05/optimizing-your-javascript-game-for-firefox-os/#comments</comments>
		<pubDate>Thu, 30 May 2013 08:08:34 +0000</pubDate>
		<dc:creator>Louis Stowasser</dc:creator>
				<category><![CDATA[Featured Article]]></category>
		<category><![CDATA[Firefox OS]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[firefoxos]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21001</guid>
		<description><![CDATA[When developing on a quad core processor with 16 gigabytes of RAM you can easily forget to consider how it will perform on a mobile device. This article will detail some best practices and things to consider for moving a game to Firefox OS or any similar hardware target. Making the best of 256 Mb [...]]]></description>
				<content:encoded><![CDATA[<p><em>When developing on a quad core processor with 16 gigabytes of RAM you can easily forget to consider how it will perform on a mobile device. This article will detail some best practices and things to consider for moving a game to Firefox OS or any similar hardware target.</em></p>
<h2>Making the best of 256 Mb RAM/800 Mhz CPU</h2>
<p>There are many areas of focus to keep in mind while developing a game. When your goal is to draw 60 times a second, garbage collection and inefficient drawing calls start to get in your way. Let’s start with the basics&#8230;</p>
<h3>Don’t over-optimize</h3>
<p>This might sound counter-intuitive in an article about game optimization but optimization is the last step; performed on complete, working code. While it’s never a bad idea to keep these tips and tricks in mind, you don’t know whether you’ll need them until you’ve finished the game and played it on a device.</p>
<h2>Optimize Drawing</h2>
<p>Drawing on <a href="https://developer.mozilla.org/en-US/docs/HTML/Canvas">HTML5 2D canvas</a> is the biggest bottleneck in most JavaScript games, as all other updates are usually just algebra without touching the DOM. Canvas operations are hardware accelerated, which can give you some extra room to breath.</p>
<h3>Use whole-pixel rendering</h3>
<p>Sub-pixel rendering occurs when you render objects on a canvas without whole values.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">ctx.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>myImage<span style="color: #339933;">,</span> <span style="color: #CC0000;">0.3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>This causes the browser to do extra calculations to create the anti-aliasing effect. To avoid this, make sure to round all co-ordinates used in calls to <code>drawImage</code> using <code>Math.floor</code> or as you’ll reader further in the article, <code>bitwse</code> operators.</p>
<p><a href="http://jsperf.com/drawimage-whole-pixels">jsPerf &#8211; drawImage whole pixels</a>.</p>
<h3>Cache drawing in an offscreen canvas</h3>
<p>If you find yourself with complex drawing operations on each frame, consider creating an offscreen canvas, draw to it once (or whenever it changes) on the offscreen canvas, then on each frame draw the offscreen canvas.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">myEntity.<span style="color: #660066;">offscreenCanvas</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span>“canvas”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myEntity.<span style="color: #660066;">offscreenCanvas</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> myEntity.<span style="color: #660066;">width</span><span style="color: #339933;">;</span>
myEntity.<span style="color: #660066;">offscreenCanvas</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> myEntity.<span style="color: #660066;">height</span><span style="color: #339933;">;</span>
myEntity.<span style="color: #660066;">offscreenContext</span> <span style="color: #339933;">=</span> myEntity.<span style="color: #660066;">offscreenCanvas</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span>“2d”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
myEntity.<span style="color: #660066;">render</span><span style="color: #009900;">&#40;</span>myEntity.<span style="color: #660066;">offscreenContext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Use moz-opaque on the canvas tag (Firefox Only)</h3>
<p>If your game uses canvas and doesn’t need to be transparent, set the <code>moz-opaque</code> attribute on the canvas tag. This information can be used internally to optimize rendering.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;canvas</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mycanvas&quot;</span> moz-opaque<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Described more in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=430906">Bug 430906 &#8211; Add moz-opaque attribute on canvas</a>.</p>
<h3>Scaling canvas using CSS3 transform</h3>
<p>CSS3 transforms are faster by using the GPU. Best case is to not scale the canvas or have a smaller canvas and scale up rather than a bigger canvas and scale down. For Firefox OS, target 480 x 320 px.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> scaleX <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">/</span> window.<span style="color: #660066;">innerWidth</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> scaleY <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">/</span> window.<span style="color: #660066;">innerHeight</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> scaleToFit <span style="color: #339933;">=</span> <span style="">Math</span>.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>scaleX<span style="color: #339933;">,</span> scaleY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> scaleToCover <span style="color: #339933;">=</span> <span style="">Math</span>.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>scaleX<span style="color: #339933;">,</span> scaleY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
stage.<span style="color: #660066;">style</span>.<span style="color: #660066;">transformOrigin</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0 0&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//scale from top left</span>
stage.<span style="color: #660066;">style</span>.<span style="color: #660066;">transform</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;scale(&quot;</span> <span style="color: #339933;">+</span> scaleToFit <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;)&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>See it working in <a href="http://jsfiddle.net/digitarald/bYSkr/">this jsFiddle</a>.</p>
<h3>Nearest-neighbour rendering for scaling pixel-art</h3>
<p>Leading on from the last point, if your game is themed with pixel-art, you should use one of the following techniques when scaling the canvas. The default resizing algorithm creates a blurry effect and ruins the beautiful pixels.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;">canvas <span style="color: #00AA00;">&#123;</span>
  image-rendering<span style="color: #00AA00;">:</span> crisp-edges<span style="color: #00AA00;">;</span>
  image-rendering<span style="color: #00AA00;">:</span> -moz-crisp-edges<span style="color: #00AA00;">;</span>
  image-rendering<span style="color: #00AA00;">:</span> -webkit-optimize-contrast<span style="color: #00AA00;">;</span>
  -ms-interpolation-mode<span style="color: #00AA00;">:</span> nearest-neighbor<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>or</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span>‘2d’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">webkitImageSmoothingEnabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">mozImageSmoothingEnabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">imageSmoothingEnabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>More documentation is available on <a href="https://developer.mozilla.org/en-US/docs/CSS/image-rendering">MDN for image-rendering</a>.</p>
<h3>CSS for large background images</h3>
<p>If like most games you have a static background image, use a plain DIV element with a CSS background property and position it under the canvas. This will avoid drawing a large image to the canvas on every tick.</p>
<h3>Multiple canvases for layers</h3>
<p>Similar to the last point, you may find you have some elements that are frequently changing and moving around whereas other things (like UI) never change. An optimization in this situation is to create layers using multiple canvas elements.</p>
<p>For example you could create a UI layer that sits on top of everything and is only drawn during user input. You could create game layer where the frequently updating entities exist and a background layer for entities that rarely update.</p>
<p><script src="https://gist.github.com/louisstow/5610652.js"></script></p>
<noscript><a href="https://gist.github.com/louisstow/5610652">GitHub Gist</a></noscript>
<h3>Don’t scale images in drawImage</h3>
<p>Cache various sizes of your images on an offscreen canvas when loading as opposed to constantly scaling them in drawImage.</p>
<p><a href="http://jsperf.com/canvas-drawimage-scaling-performance">jsPerf &#8211; Canvas drawImage Scaling Performance</a>.</p>
<h3>Be careful with heavy physics libraries</h3>
<p>If possible, <a href="http://gamedev.tutsplus.com/series/custom-game-physics-engine/">roll your own physics</a> as libraries like Box2D don’t perform well on low-end Firefox OS devices.</p>
<p>When <a href="http://asmjs.org/">asm.js</a> support lands in Firefox OS, Emscripten-compiled libraries can take advantage of near-native performance. More reading in <a href="http://j15r.com/blog/2013/04/25/Box2d_Revisited">Box2d Revisited</a>.</p>
<h3>Use WebGL instead of Context 2D</h3>
<p>Easier said than done but giving all the heavy graphics lifting to the GPU will free up the CPU for greater good. Even though WebGL is 3D, you can use it to draw 2D surfaces. There are some libraries out there that aim to abstract the drawing contexts.</p>
<ul>
<li><a href="https://github.com/gameclosure/WebGL-2D">gameclosure &#8211; webgl-2d</a></li>
<li><a href="https://github.com/GoodBoyDigital/pixi.js/">GoodBoyDigital &#8211; pixi.js</a></li>
<li><a href="http://threejs.org/">ThreeJS</a></li>
</ul>
<h2>Minimize Garbage Collection</h2>
<p>JavaScript can spoil us when it comes to memory management. We generally don’t need to worry about memory leaks or conservatively allocating memory. But if we’ve allocated too much and garbage collection occurs in the middle of a frame, that can take up valuable time and result in a visible drop in FPS.</p>
<h3>Pool common objects and classes</h3>
<p>To minimise the amount of objects being cleaned during garbage collection, use a pre-initialised pool of objects and reuse them rather than creating new objects all the time.</p>
<h4>Code example of generic object pool:</h4>
<p><script src="https://gist.github.com/louisstow/5609992.js"></script></p>
<noscript><a href="https://gist.github.com/louisstow/5609992">GitHub Gist</a></noscript>
<h3>Avoid internal methods creating garbage</h3>
<p>There are various JavaScript methods that create new objects rather than modifying the existing one. This includes: <code>Array.slice</code>,  <code>Array.splice</code>, <code>Function.bind</code>.</p>
<h4>Read more about JavaScript garbage collection</h4>
<ul>
<li><a href="http://buildnewgames.com/garbage-collector-friendly-code/">High-Performance, Garbage-Collector-Friendly Code</a></li>
<li><a href="https://www.scirra.com/blog/76/how-to-write-low-garbage-real-time-javascript">How to write low garbage real-time Javascript</a></li>
</ul>
<h3>Avoid frequent calls to localStorage</h3>
<p>LocalStorage uses file IO and blocks the main thread to retrieve and save data. Use an in-memory object to cache the values of localStorage and even save writes for when the player is not mid-game.</p>
<h4>Code example of an abstract storage object:</h4>
<p><script src="https://gist.github.com/louisstow/5610444.js"></script></p>
<noscript><a href="https://gist.github.com/louisstow/5610444">GitHub Gist</a></noscript>
<h3>Async localStorage API with IndexedDB</h3>
<p>IndexedDB is a non-blocking API for storing data on the client but may be overkill for small and simple data. Gaia’s library to make localStorage API asynchronous, using IndexedDB is available on Github: <a href="https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js">async_storage.js</a>.</p>
<h2>Miscellaneous micro-optimization</h2>
<p>Sometimes when you’ve exhausted all your options and it just won’t go any faster, you can try some micro-optimizations below. However do note that these only start to make a difference in heavy usage when every millisecond counts. Look for them in your hot game loops.</p>
<dl class="hacks-games-post">
<dt>Use <code>x | 0</code> instead of <code>Math.floor</code></dt>
<dd>
<ul>
<li><a href="http://jsperf.com/math-floor-vs-math-round-vs-parseint/18">jsPerf &#8211; Math.floor vs Math.round vs parseInt vs Bitwise</a></li>
<li><a href="http://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/">Bitwise Gems and other optimizations</a></li>
</ul>
</dd>
<dt>Clear arrays with <code>.length = 0</code> to avoid creating a new Array</dt>
<dd>Sacrifice some CPU time to avoid creating garbage.</dd>
<dt>Use <code>if .. else</code> over <code>switch</code></dt>
<dd><a href="http://jsperf.com/switch-if-else">jsPerf &#8211; switch vs if-else</a></dd>
<dt>Date.now() over (+ new Date)</dt>
<dd><a href="http://jsperf.com/date-now-vs-new-date-gettime/2">jsPerf &#8211; Date.now vs new Date().getTime() vs +new Date</a></dd>
<dd>Or performance.now() for a sub-millisecond solution</dd>
<dt>Use TypedArrays for floats or integers (e.g. vectors and matrices)</dt>
<dd><a href="https://github.com/toji/gl-matrix">gl-matrix &#8211; Javascript Matrix and Vector library for High Performance WebGL apps</a></dd>
</dl>
<h2>Conclusion</h2>
<p>Building for mobile devices and not-so-strong hardware is a good and creative exercise, and we hope you will want to make sure your games work well on all platforms!</p>
<style>.hacks-games-post dt {font-weight: bold; font-style: normal; } .hacks-games-post dd { margin-bottom: 15px; } .hacks-games-post dd ul{margin-bottom: 0;}</style>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/optimizing-your-javascript-game-for-firefox-os/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Content Security Policy 1.0 lands in Firefox Aurora</title>
		<link>https://hacks.mozilla.org/2013/05/content-security-policy-1-0-lands-in-firefox-aurora/</link>
		<comments>https://hacks.mozilla.org/2013/05/content-security-policy-1-0-lands-in-firefox-aurora/#comments</comments>
		<pubDate>Wed, 29 May 2013 09:05:59 +0000</pubDate>
		<dc:creator>Frederik Braun</dc:creator>
				<category><![CDATA[Bleeding edge]]></category>
		<category><![CDATA[Firefox Aurora]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=21013</guid>
		<description><![CDATA[The information in this article is based on work together with Ian Melven, Kailas Patil and Tanvi Vyas. We have just landed support for the Content Security Policy (CSP) 1.0 specification in Firefox Aurora (Firefox 23), available as of tomorrow (May 30th). CSP is a security mechanism that aims to protect a website against content [...]]]></description>
				<content:encoded><![CDATA[<p><i>The information in this article is based on work together with Ian Melven, Kailas Patil and Tanvi Vyas</i>.</p>
<p>We have just landed support for the <a href="http://www.w3.org/TR/CSP/">Content Security Policy (CSP) 1.0<br />
specification</a> in <a href="http://www.mozilla.org/en-US/firefox/aurora/">Firefox Aurora</a> (Firefox 23), available as of tomorrow (May 30th). CSP is a security mechanism that aims to protect a website against content injection attacks by providing a whitelist of known-good domain names to accept JavaScript (and other content) from. CSP does this by sending a Content-Security-Policy header with the document it protects (yes, we lost the X prefix with the 1.0 version of the spec).</p>
<p>To effectively protect against XSS, a few JavaScript features have to be<br />
disabled:</p>
<ul>
<li>All inline JavaScript is disallowed. This means, that all the JavaScript code must be placed in a separate file that is linked via <code>&lt;script src=... &gt;</code></li>
<li>All calls to functions which allow JavaScript code being executed from strings (e.g., <em>eval</em>) are disabled</li>
</ul>
<h2>CSP now more intuitive and consistent</h2>
<p>While Firefox has had support for CSP since its invention here at Mozilla, things have been changing a lot. The streamlined development of a specification within the W3C has made the concept more intuitive and consistent. Most directives in a CSP header are now of a unified form which explicitly specifies the type of content you want to restrict:</p>
<ul>
<li>img-src</li>
<li>object-src</li>
<li>script-src</li>
<li>style-src and so on.</li>
</ul>
<p>Oh and if you feel like you must allow less secure JavaScript coding styles, you can add the values <em>unsafe-inline</em> or <em>unsafe-eval</em> to your list of script sources. (This used to be inline-script and eval-script before).</p>
<p>Start protecting your website by implementing CSP now!</p>
<p>But wait &#8211; isn’t that a bit tedious&#8230; Writing a complex policy and making sure that you remembered all the resources that your website requires? Don’t fret! Here comes <a href="https://addons.mozilla.org/en-US/firefox/addon/newusercspdesign/">UserCSP</a> again!</p>
<h2>Generate your Content Security Policies with UserCSP!</h2>
<p>During the last few months, Kailas Patil, a student in our <a href="https://wiki.mozilla.org/Security/Mentorship">Security Mentorship Program</a> has continued his GSoC <a href="https://blog.mozilla.org/tanvi/2012/09/18/user-specified-content-security-policy/">work from last year</a> to update <a href="https://addons.mozilla.org/en-US/firefox/addon/newusercspdesign/">UserCSP</a>.</p>
<p>UserCSP is a Firefox add-on that helps web developers and security-minded users use CSP. Web developers can create a Content Security Policy (CSP) for their site by using UserCSP’s infer CSP feature. This feature can list required resource URLs and turn them into a policy ready to plug into a CSP header.</p>
<p>In addition, UserCSP is the first step to expose a policy enforcement mechanism directly to web users. Furthermore, users can enforce a stricter policy than a page supplies through the add-on or apply a policy to  certain websites that don&#8217;t currently support CSP.</p>
<p>While earlier versions of UserCSP were more aligned to content security policies as originally invented at Mozilla, this version is updated to be in compliance with the CSP 1.0 specification. This means that policies derived with this add-on may work in all browsers as soon as they <a href="http://caniuse.com/#search=CSP">support</a> the specification. Hooray!</p>
<p>As this evolves and ships, our <a href="https://developer.mozilla.org/en-US/docs/Security/CSP">MDN documentation on Content Security Policy (CSP)</a> will keep on evolving, and we also plan to write more about this in the <a href="https://blog.mozilla.org/security/">Mozilla Security Blog</a> in the next few weeks, so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/content-security-policy-1-0-lands-in-firefox-aurora/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Compiling to JavaScript, and Debugging with Source Maps</title>
		<link>https://hacks.mozilla.org/2013/05/compiling-to-javascript-and-debugging-with-source-maps/</link>
		<comments>https://hacks.mozilla.org/2013/05/compiling-to-javascript-and-debugging-with-source-maps/#comments</comments>
		<pubDate>Wed, 22 May 2013 08:16:40 +0000</pubDate>
		<dc:creator>Nick Fitzgerald</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Firefox Aurora]]></category>
		<category><![CDATA[Firefox Nightly]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20937</guid>
		<description><![CDATA[Update 2013/05/29: I have updated the article to reflect recent changes in the source map specification where the //@ syntax for linking a source map to a script has been deprecated in favor of //# due to problems with Internet Explorer. This is a tutorial on how to write a compiler which generates JavaScript as [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Update 2013/05/29:</strong> <em>I have updated the article to reflect recent changes in the source map specification where the <code>//@</code> syntax for linking a source map to a script has been deprecated in favor of <code>//#</code> due to problems with Internet Explorer.</em></p>
<p>
  This is a tutorial on how to write a compiler which generates JavaScript as  its target language, and maintains line and column meta-data  in <a href="https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#heading=h.zhn1phd7ocnp">source  maps</a> for debugging. Storing line and column coordinates in a source map  allows the end-user of the compiler to debug the source code that they wrote,  rather than the ugly, generated JavaScript they are not familiar with.
</p>
<p>
  In this tutorial, we will be compiling a  small <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">Reverse  Polish Notation</a>, or RPN, language to JavaScript. The language is super  simple, and is nothing more than simple arithmetic with variable storage and  output capabilities. We are keeping the language simple so that we can focus  on integrating source maps with the compiler, rather than language  implementation details.
</p>
<h2>Availability</h2>
<p>
  Initial support for source maps in the debugger is available in Firefox 23  (Aurora at time of writing) with more improvements coming in Firefox 24  (Nightly at time of writing). Chrome DevTools also have support for source maps.
</p>
<h2>Overview of the Source Language</h2>
<p>
  RPN uses postfix notation, meaning that the operator follows its two  operands. One of the benefits of RPN is that as long as we limit ourselves to  binary operators, we do not need any parentheses, and do not need to worry  about operator precedence.
</p>
<p>
  Here is an example program in our source language:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">a <span style="color: #CC0000;">5</span> <span style="color: #339933;">=;</span>
b <span style="color: #CC0000;">3</span> <span style="color: #339933;">=;</span>
c a b <span style="color: #339933;">+</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">*</span> <span style="color: #339933;">=;</span></pre></td></tr></table></div>

<p>
  This is an equivalent program written in a language which uses infix notation  for its arithmetic operators:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">a <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
b <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
c <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>a <span style="color: #339933;">+</span> b<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  Our language will support addition, subtraction, multiplication, division,  assignment, and printing. The <code>print</code> operator&#8217;s first operand is  the value to print, the second operand is how many times to print the value  and must be greater than or equal to one:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #CC0000;">5</span> <span style="color: #CC0000;">1</span> print<span style="color: #339933;">;</span>
# Output<span style="color: #339933;">:</span>
# <span style="color: #CC0000;">5</span>
&nbsp;
<span style="color: #CC0000;">3</span> <span style="color: #CC0000;">4</span> print<span style="color: #339933;">;</span>
# Output<span style="color: #339933;">:</span>
# <span style="color: #CC0000;">3</span>
# <span style="color: #CC0000;">3</span>
# <span style="color: #CC0000;">3</span>
# <span style="color: #CC0000;">3</span>
&nbsp;
<span style="color: #CC0000;">4</span> print<span style="color: #339933;">;</span>
# Syntax error
&nbsp;
n <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">=;</span>
<span style="color: #CC0000;">4</span> n print<span style="color: #339933;">;</span>
# Runtime error</pre></td></tr></table></div>

<p>
  Lastly, division by zero should throw an error:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #CC0000;">5</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">/;</span>
# Runtime error</pre></td></tr></table></div>

<h2>Getting Setup</h2>
<p>
  We will be writing our compiler on <a href="http://nodejs.org/">Node.js</a>,  using <a href="http://jison.org/">Jison</a> to generate the parser for our  language from a grammar, and using  the <a href="https://github.com/mozilla/source-map"><code>source-map</code>  library</a> to help generate source maps.
</p>
<p>
  The first step is to <a href="http://nodejs.org/#download">download and  install Node.js</a> if you don&#8217;t already have it on your system.
</p>
<p>
  After you have installed Node.js, use its package manager <code>npm</code> to  create a new project for the compiler:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$ mkdir rpn
$ cd rpn<span style="color: #339933;">/</span>
$ npm init .</pre></td></tr></table></div>

<p>
  After the last command, <code>npm</code> will prompt you with a bunch of  questions. Enter your name and email, answer <code>./lib/rpn.js</code> for the  main module/entry point, and just let <code>npm</code> use the defaults that  it supplies for the rest of the questions.
</p>
<p>
  Once you have finished answering the prompts, create the directory layout for  the project:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$ mkdir lib
$ touch lib<span style="color: #339933;">/</span>rpn.<span style="color: #660066;">js</span>
$ mkdir <span style="color: #339933;">-</span>p lib<span style="color: #339933;">/</span>rpn</pre></td></tr></table></div>

<p>
  The public API for the compiler will reside within <code>lib/rpn.js</code>,  while the submodules we use to implement various things such as the lexer and  abstract syntax tree will live in <code>lib/rpn/*.js</code>.
</p>
<p>
  Next, open up the <code>package.json</code> file and add <code>jison</code>  and <code>source-map</code> to the project&#8217;s dependencies:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #3366CC;">&quot;dependencies&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;jison&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&gt;=0.4.4&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;source-map&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&gt;=0.1.22&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
...</pre></td></tr></table></div>

<p>
  Now we will install a link to our package in Node.js&#8217;s globally installed  packages directory. This allows us to import our package from the Node.js shell:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$ npm link .</pre></td></tr></table></div>

<p>
  Make sure that everything works by opening the Node.js shell and importing our  package:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$ node
<span style="color: #339933;">&gt;</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;rpn&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Writing the Lexer</h2>
<p>
  A lexer (also known as a scanner or tokenizer) breaks the inputted raw source  code into a stream of semantic tokens. For example in our case, we would want  to break the raw input string <code>"5 3 +;"</code> into something  like <code>["5", "3", "+", ";"]</code>.
</p>
<p>
  Because we are using Jison, rather than writing the lexer and parser by hand,  our job is much easier. All that is required is to supply a list of rules that  describe the types of tokens we are expecting. The left hand side of the rules  are regular expressions to match individual tokens, the right hand side are  the snippets of code to execute when an instance of the corresponding token  type is found. These tokens will be passed on to the parser in the next phase  of the compiler.
</p>
<p>
  Create the rules for lexical analysis in <code>lib/rpn/lex.js</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">exports.<span style="color: #660066;">lex</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  rules<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>s+&quot;</span><span style="color: #339933;">,</span>                   <span style="color: #3366CC;">&quot;/* Skip whitespace! */&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;#.*<span style="color: #000099; font-weight: bold;">\\</span>n&quot;</span><span style="color: #339933;">,</span>                 <span style="color: #3366CC;">&quot;/* Skip comments! */&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;;&quot;</span><span style="color: #339933;">,</span>                      <span style="color: #3366CC;">&quot;return 'SEMICOLON'&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>-?[0-9]+(<span style="color: #000099; font-weight: bold;">\\</span>.[0-9]+)?&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;return 'NUMBER';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;print&quot;</span><span style="color: #339933;">,</span>                  <span style="color: #3366CC;">&quot;return 'PRINT';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;</span><span style="color: #339933;">,</span>  <span style="color: #3366CC;">&quot;return 'VARIABLE';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #339933;">,</span>                      <span style="color: #3366CC;">&quot;return '=';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>+&quot;</span><span style="color: #339933;">,</span>                    <span style="color: #3366CC;">&quot;return '+';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>-&quot;</span><span style="color: #339933;">,</span>                    <span style="color: #3366CC;">&quot;return '-';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>*&quot;</span><span style="color: #339933;">,</span>                    <span style="color: #3366CC;">&quot;return '*';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>/&quot;</span><span style="color: #339933;">,</span>                    <span style="color: #3366CC;">&quot;return '/';&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;$&quot;</span><span style="color: #339933;">,</span>                      <span style="color: #3366CC;">&quot;return 'EOF';&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Writing the Parser</h2>
<p>
  The parser takes the tokens from the lexer one at a time and confirms that the  input is a valid program in our source language.
</p>
<p>
  Once again, the task of writing the parser is much easier than it would  otherwise be thanks to Jison. Rather than writing the parser ourselves, Jison  will programmatically create one for us if we provide a grammar for the  language.
</p>
<p>
  If all we cared about was whether the input was a valid program, we would stop  here. However, we are also going to compile the input to JavaScript, and to do  that we need to create an abstract syntax tree. We build the AST in the code  snippets next to each rule.
</p>
<p>
  A typical grammar contains productions with the form:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">LeftHandSide → RightHandSide1
             <span style="color: #339933;">|</span> RightHandSide2
             ...</pre></td></tr></table></div>

<p>
  However, in Jison we are a) writing in JavaScript, and b) also providing code to  execute for each rule so that we can create the AST. Therefore, we use the  following format:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">LeftHandSide<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
  <span style="color: #009900;">&#91;</span>RightHandSide1<span style="color: #339933;">,</span> CodeToExecute1<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#91;</span>RightHandSide2<span style="color: #339933;">,</span> CodeToExecute2<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  ...
<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>
  Inside the code snippets, there are a handful of magic variables we have  access to:
</p>
<ul>
<li>
    <code>$$</code>: The value of the left hand side of the production.
  </li>
<li>
    <code>$1</code>/<code>$2</code>/<code>$3</code>/etc: The value of the the    nth form in the right hand side of the production.
  </li>
<li>
    <code>@1</code>/<code>@2</code>/<code>@3</code>/etc: An object containing    the line and column coordinates where the nth form in the right hand side of    the production was parsed.
  </li>
<li>
    <code>yytext</code>: The full text of currently matched rule.
  </li>
</ul>
<p>
  Using this information, we can create the grammar  in <code>lib/rpn/bnf.js</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">exports.<span style="color: #660066;">bnf</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  start<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;input EOF&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;return $$;&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  input<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>           <span style="color: #3366CC;">&quot;$$ = [];&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;line input&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;$$ = [$1].concat($2);&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  line<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;exp SEMICOLON&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;$$ = $1;&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  exp<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;NUMBER&quot;</span><span style="color: #339933;">,</span>           <span style="color: #3366CC;">&quot;$$ = new yy.Number(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;VARIABLE&quot;</span><span style="color: #339933;">,</span>         <span style="color: #3366CC;">&quot;$$ = new yy.Variable(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;exp exp operator&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;$$ = new yy.Expression(@3.first_line, @3.first_column, $1, $2, $3);&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  operator<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;PRINT&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;$$ = new yy.Operator(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #339933;">,</span>     <span style="color: #3366CC;">&quot;$$ = new yy.Operator(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;+&quot;</span><span style="color: #339933;">,</span>     <span style="color: #3366CC;">&quot;$$ = new yy.Operator(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;-&quot;</span><span style="color: #339933;">,</span>     <span style="color: #3366CC;">&quot;$$ = new yy.Operator(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;*&quot;</span><span style="color: #339933;">,</span>     <span style="color: #3366CC;">&quot;$$ = new yy.Operator(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">,</span>     <span style="color: #3366CC;">&quot;$$ = new yy.Operator(@1.first_line, @1.first_column, yytext);&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Implementing the Abstract Syntax Tree</h2>
<p>
  Create the definitions for the abstract syntax tree nodes  in <code>lib/rpn/ast.js</code>.
</p>
<p>
  Since we will be maintaining line and column information in all of the AST  nodes, we can reuse some code by making a base prototype:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> AstNode <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span> column<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._line <span style="color: #339933;">=</span> line<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._column <span style="color: #339933;">=</span> column<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  The definitions for the rest of the AST nodes are pretty straight  forward. Link up the prototype chain, assign relevant attributes, and don&#8217;t  forget to call <code>AstNode</code>&#8216;s constructor:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">exports.<span style="">Number</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span> column<span style="color: #339933;">,</span> numberText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  AstNode.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> line<span style="color: #339933;">,</span> column<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._value <span style="color: #339933;">=</span> <span style="">Number</span><span style="color: #009900;">&#40;</span>numberText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
exports.<span style="">Number</span>.<span style="color: #000066; font-weight: bold;">prototype</span> <span style="color: #339933;">=</span> <span style="">Object</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>AstNode.<span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="color: #660066;">Variable</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span> column<span style="color: #339933;">,</span> variableText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  AstNode.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> line<span style="color: #339933;">,</span> column<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._name <span style="color: #339933;">=</span> variableText<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
exports.<span style="color: #660066;">Variable</span>.<span style="color: #000066; font-weight: bold;">prototype</span> <span style="color: #339933;">=</span> <span style="">Object</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>AstNode.<span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="color: #660066;">Expression</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span> column<span style="color: #339933;">,</span> operand1<span style="color: #339933;">,</span> operand2<span style="color: #339933;">,</span> operator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  AstNode.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> line<span style="color: #339933;">,</span> column<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._left <span style="color: #339933;">=</span> operand1<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._right <span style="color: #339933;">=</span> operand2<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>._operator <span style="color: #339933;">=</span> operator<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
exports.<span style="color: #660066;">Expression</span>.<span style="color: #000066; font-weight: bold;">prototype</span> <span style="color: #339933;">=</span> <span style="">Object</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>AstNode.<span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="color: #660066;">Operator</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>line<span style="color: #339933;">,</span> column<span style="color: #339933;">,</span> operatorText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  AstNode.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> line<span style="color: #339933;">,</span> column<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">symbol</span> <span style="color: #339933;">=</span> operatorText<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
exports.<span style="color: #660066;">Operator</span>.<span style="color: #000066; font-weight: bold;">prototype</span> <span style="color: #339933;">=</span> <span style="">Object</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>AstNode.<span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Compilation</h2>
<h3>Generated JavaScript</h3>
<p>
  Before we generate JavaScript, we need a plan. There are a couple ways we can  structure the outputted JavaScript.
</p>
<p>
  One strategy is to translate the RPN expressions to the equivalent human  readable JavaScript expression we would create if we had been writing  JavaScript all along. For example, if we were to port this RPN example:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">a <span style="color: #CC0000;">8</span> <span style="color: #339933;">=;</span>
b <span style="color: #CC0000;">2</span> <span style="color: #339933;">=;</span>
c a b <span style="color: #CC0000;">1</span> <span style="color: #339933;">-</span> <span style="color: #339933;">/</span> <span style="color: #339933;">=;</span></pre></td></tr></table></div>

<p>
  We might write the following JavaScript:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> c <span style="color: #339933;">=</span> a <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>b <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  However, this means that we are completely adopting the nuances of  JavaScript&#8217;s arithmetic. In an earlier example, we saw that a helpful runtime  error was thrown when any number was divided by zero. Most languages throw an  error when this occurs, however JavaScript does not; instead, the result  is <code>Infinity</code>. Therefore, we can&#8217;t completely embrace JavaScript&#8217;s  arithmetic system, and we must generate some code to check for divide-by-zero  errors ourselves. Adding this code gets a little tricky if we want to maintain  the strategy of generating human readable code.
</p>
<p>
  Another option is treating the JavaScript interpreter as a stack machine of  sorts and generating code that pushes and pops values to and from a  stack. Furthermore, stack machines are a natural fit for evaluating RPN. In  fact, it is such a good fit that  RPN <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">&#8220;was  independently reinvented by F. L. Bauer and E. W. Dijkstra in the early 1960s  to reduce computer memory access and utilize the stack to evaluate  expressions.&#8221;</a>
</p>
<p>
  Generating JavaScript code for the same example above, but utilizing the  JavaScript interpreter as a stack machine, might look something like this:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">push<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
env<span style="color: #009900;">&#91;</span>pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
env<span style="color: #009900;">&#91;</span>pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
temp <span style="color: #339933;">=</span> pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span>pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> temp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
temp <span style="color: #339933;">=</span> pop<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>temp <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #000066; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Divide by zero&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span>pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> temp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
push<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'c'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
env<span style="color: #009900;">&#91;</span>pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  This is the strategy we will follow. The generated code is a bit larger, and  we will require a preamble to define <code>push</code>, <code>pop</code>, etc,  but compilation becomes much easier. Furthermore, the fact that the generated  code isn&#8217;t as human readable only highlights the benefits of using source  maps!
</p>
<h3>Creating Source Maps</h3>
<p>
  If we weren&#8217;t generating source maps along with our generated JavaScript, we  could build the generated code via concatenating strings of code:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">code <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;push(&quot;</span> <span style="color: #339933;">+</span> operand1.<span style="color: #660066;">compile</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> operator.<span style="color: #660066;">compile</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> operand2.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  However, this doesn&#8217;t work when we are creating source maps because we need to  maintain line and column information. When we concatenate strings of code, we  lose that information.
</p>
<p>
  The <code>source-map</code> library contains <code>SourceNode</code> for  exactly this reason. If we add a new method on our base <code>AstNode</code>  prototype, we can rewrite our example like this:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> SourceNode <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;source-map&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SourceNode</span><span style="color: #339933;">;</span>
AstNode.<span style="color: #000066; font-weight: bold;">prototype</span>._sn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>originalFilename<span style="color: #339933;">,</span> chunk<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">new</span> SourceNode<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._line<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._column<span style="color: #339933;">,</span> originalFilename<span style="color: #339933;">,</span> chunk<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
...
&nbsp;
<span style="color: #660066;">code</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;foo.rpn&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>code<span style="color: #339933;">,</span>
                            <span style="color: #3366CC;">&quot;push(&quot;</span><span style="color: #339933;">,</span>
                            operand1.<span style="color: #660066;">compile</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>
                            operator.<span style="color: #660066;">compile</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>
                            operand2.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  Once we have completed building the <code>SourceNode</code> structure for the  whole input program, we can generate the compiled source and the source map by  calling the <code>SourceNode.prototype.toStringWithSourceMap</code>  method. This method returns an object with two  properties: <code>code</code>, which is a string containing the generated JavaScript source code; and <code>map</code>, which is the source map.
</p>
<h3>Implementing Compilation</h3>
<p>
  Now that we have a strategy for generating code, and understand how to  maintain line and column information so that we can generate source maps  easily, we can add the methods to compile our AST nodes  to <code>lib/rpn/ast.js</code>.
</p>
<p>
  To play nice with the global JavaScript environment, we will  namespace <code>push</code>, <code>pop</code>, etc,  under <code>__rpn</code>.
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> push<span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;__rpn.push(&quot;</span><span style="color: #339933;">,</span> val<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
AstNode.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compile</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #000066; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Not Yet Implemented&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
AstNode.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compileReference</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
AstNode.<span style="color: #000066; font-weight: bold;">prototype</span>._sn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>originalFilename<span style="color: #339933;">,</span> chunk<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">new</span> SourceNode<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._line<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._column<span style="color: #339933;">,</span> originalFilename<span style="color: #339933;">,</span> chunk<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="">Number</span>.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compile</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">originalFilename</span><span style="color: #339933;">,</span>
                  push<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._value.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="color: #660066;">Variable</span>.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compileReference</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">originalFilename</span><span style="color: #339933;">,</span>
                  push<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._name<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
exports.<span style="color: #660066;">Variable</span>.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compile</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">originalFilename</span><span style="color: #339933;">,</span>
                  push<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;window.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="color: #660066;">Expression</span>.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compile</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> temp <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;__rpn.temp&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> output <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">originalFilename</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._operator.<span style="color: #660066;">symbol</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'print'</span><span style="color: #339933;">:</span>
    <span style="color: #000066; font-weight: bold;">return</span> output
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._left.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._right.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; = __rpn.pop();<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;if (&quot;</span><span style="color: #339933;">,</span> temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; &lt;= 0) throw new Error('argument must be greater than 0');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;if (Math.floor(&quot;</span><span style="color: #339933;">,</span> temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;) != &quot;</span><span style="color: #339933;">,</span> temp<span style="color: #339933;">,</span>
            <span style="color: #3366CC;">&quot;) throw new Error('argument must be an integer');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>._operator.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;(__rpn.pop(), &quot;</span><span style="color: #339933;">,</span> temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'='</span><span style="color: #339933;">:</span>
    <span style="color: #000066; font-weight: bold;">return</span> output
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._right.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._left.<span style="color: #660066;">compileReference</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;window[__rpn.pop()] &quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._operator.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; __rpn.pop();<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'/'</span><span style="color: #339933;">:</span>
    <span style="color: #000066; font-weight: bold;">return</span> output
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._left.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._right.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; = __rpn.pop();<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;if (&quot;</span><span style="color: #339933;">,</span> temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; === 0) throw new Error('divide by zero error');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>push<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;__rpn.pop() &quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._operator.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">,</span> temp<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">default</span><span style="color: #339933;">:</span>
    <span style="color: #000066; font-weight: bold;">return</span> output
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._left.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>._right.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>temp<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; = __rpn.pop();<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>push<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;__rpn.pop() &quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>._operator.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">,</span> temp<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
exports.<span style="color: #660066;">Operator</span>.<span style="color: #000066; font-weight: bold;">prototype</span>.<span style="color: #660066;">compile</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<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><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">symbol</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;print&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">originalFilename</span><span style="color: #339933;">,</span>
                    <span style="color: #3366CC;">&quot;__rpn.print&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: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._sn<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">originalFilename</span><span style="color: #339933;">,</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">symbol</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Gluing it Together</h2>
<p>
  From here we have done all the difficult work, and we can run a victory lap by  connecting the modules together with a public API, and by creating a command  line script to call the compiler.
</p>
<p>
  The public API resides in <code>lib/rpn.js</code>. It also contains the  preamble, to initialize <code>__rpn</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> jison <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;jison&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> sourceMap <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;source-map&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> lex <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./rpn/lex&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">lex</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> bnf <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./rpn/bnf&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bnf</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> parser <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> jison.<span style="color: #660066;">Parser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  lex<span style="color: #339933;">:</span> lex<span style="color: #339933;">,</span>
  bnf<span style="color: #339933;">:</span> bnf
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
parser.<span style="color: #660066;">yy</span> <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./rpn/ast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">function</span> getPreamble <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">new</span> sourceMap.<span style="color: #660066;">SourceNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;var __rpn = {};<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;__rpn._stack = [];<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;__rpn.temp = 0;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;__rpn.push = function (val) {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  __rpn._stack.push(val);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;};<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;__rpn.pop = function () {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  if (__rpn._stack.length &gt; 0) {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;    return __rpn._stack.pop();<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  else {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;    throw new Error('can<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\'</span>t pop from empty stack');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;};<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;__rpn.print = function (val, repeat) {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  while (repeat-- &gt; 0) {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;    var el = document.createElement('div');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;    var txt = document.createTextNode(val);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;    el.appendChild(txt);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;    document.body.appendChild(el);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;  }<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;};<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
exports.<span style="color: #660066;">compile</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> expressions <span style="color: #339933;">=</span> parser.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>input.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> preamble <span style="color: #339933;">=</span> getPreamble<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> sourceMap.<span style="color: #660066;">SourceNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> preamble<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  result.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>expressions.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>exp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> exp.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>data<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  Create the command line script in <code>bin/rpn.js</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">#<span style="color: #339933;">!/</span>usr<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>env node
<span style="color: #000066; font-weight: bold;">var</span> fs <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">var</span> rpn <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;rpn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
process.<span style="color: #660066;">argv</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">var</span> input <span style="color: #339933;">=</span> fs.<span style="color: #660066;">readFileSync</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> output <span style="color: #339933;">=</span> rpn.<span style="color: #660066;">compile</span><span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    originalFilename<span style="color: #339933;">:</span> file
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toStringWithSourceMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    file<span style="color: #339933;">:</span> file.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\.[\w]+$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;.js.map&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">var</span> sourceMapFile <span style="color: #339933;">=</span> file.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\.[\w]+$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;.js.map&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fs.<span style="color: #660066;">writeFileSync</span><span style="color: #009900;">&#40;</span>file.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\.[\w]+$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                   output.<span style="color: #660066;">code</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>//# sourceMappingURL=&quot;</span> <span style="color: #339933;">+</span> sourceMapFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fs.<span style="color: #660066;">writeFileSync</span><span style="color: #009900;">&#40;</span>sourceMapFile<span style="color: #339933;">,</span> output.<span style="color: #660066;">map</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></td></tr></table></div>

<p>
  Note that our script will automatically add the <code>//# sourceMappingURL</code> comment directive so that the browser&#8217;s debugger knows  where to find the source map.
</p>
<p>
  After you create the script, update your <code>package.json</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #3366CC;">&quot;bin&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;rpn.js&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;./bin/rpn.js&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
...</pre></td></tr></table></div>

<p>
  And link the package again so that the script is installed on your system:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$ npm link .</pre></td></tr></table></div>

<h2>Seeing Results</h2>
<p>
  Here is an RPN program that we can use to test our compiler. I have saved it in <code>examples/simple-example.rpn</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">a <span style="color: #CC0000;">8</span> <span style="color: #339933;">=;</span>
b <span style="color: #CC0000;">3</span> <span style="color: #339933;">=;</span>
c a b <span style="color: #CC0000;">1</span> <span style="color: #339933;">-</span> <span style="color: #339933;">/</span> <span style="color: #339933;">=;</span>
c <span style="color: #CC0000;">1</span> print<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  Next, compile the script:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$ cd examples<span style="color: #339933;">/</span>
$ rpn.<span style="color: #660066;">js</span> simple<span style="color: #339933;">-</span>example.<span style="color: #660066;">rpn</span></pre></td></tr></table></div>

<p>
  This generates <code>simple-example.js</code>  and <code>simple-example.js.map</code>. When we include the JavaScript file in  a web page we should see the result of the computation printed on the page:
</p>
<p>    <img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/RPN-test-page.png" alt="Screenshot of simple-example.rpn's result" /></p>
<p>
  Great success!
</p>
<p>
  However, we aren&#8217;t always so lucky, and our arithmetic might have some  errors. Consider the following  example, <code>examples/with-error.rpn</code>:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">a <span style="color: #CC0000;">9</span> <span style="color: #339933;">=;</span>
b <span style="color: #CC0000;">3</span> <span style="color: #339933;">=;</span>
c a b <span style="color: #339933;">/</span> <span style="color: #339933;">=;</span>
c a b c <span style="color: #339933;">-</span> <span style="color: #339933;">/</span> <span style="color: #339933;">=;</span>
c <span style="color: #CC0000;">1</span> print<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
  We can compile this script and include the resulting JavaScript in a web page, but this time we won&#8217;t see any output on the page.
</p>
<p>
  By opening the debugger, setting the <em>pause on exceptions</em> option, and  reloading, we can see how daunting debugging without source maps can be:
</p>
<p>    <img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/RPN-pause-on-exceptions.png" alt="Screenshot of enabling pause on exceptions." /></p>
<p>    <a href="https://hacks.mozilla.org/wp-content/uploads/2013/05/without-sourcemaps.jpg"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/without-sourcemaps-500.png" alt="Screenshot of debugging with-error.rpn without source maps." /></a></p>
<p>
  The generated JavaScript is difficult to read, and unfamiliar to anyone who  authored the original RPN script. By enabling source maps in the debugger, we  can refresh and the exact line where the error ocurred in our original source  will be highlighted:
</p>
<p>    <img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/RPN-enabling-sourcemaps.png" alt="Screenshot of enabling source maps." /></p>
<p>
  <a href="https://hacks.mozilla.org/wp-content/uploads/2013/05/debugging-with-sourcemaps.jpg"><br />
    <img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/debugging-with-sourcemaps-500.png" alt="Screenshot of debugging with-error.rpn with source maps." /><br />
  </a>
</p>
<p>
  The debugging experience with source maps is orders of magnitude improved, and  makes compiling languages to JavaScript a serious possibility.
</p>
<p>
  At the end of the day though, the debugging experience is only as good as the  information encoded in the source maps by your compiler. It can be hard to  judge the quality of your source maps simply by looking at the set of source  location coordinates that they are mapping between, so Tobias Koppers created a tool to let you easily visualize your source maps.
</p>
<p>
  <a href="http://sokra.github.io/source-map-visualization/#base64,dmFyIF9fcnBuID0ge307Cl9fcnBuLl9zdGFjayA9IFtdOwpfX3Jwbi50ZW1wID0gMDsKX19ycG4ucHVzaCA9IGZ1bmN0aW9uICh2YWwpIHsKICBfX3Jwbi5fc3RhY2sucHVzaCh2YWwpOwp9OwpfX3Jwbi5wb3AgPSBmdW5jdGlvbiAoKSB7CiAgaWYgKF9fcnBuLl9zdGFjay5sZW5ndGggPiAwKSB7CiAgICByZXR1cm4gX19ycG4uX3N0YWNrLnBvcCgpOwogIH0KICBlbHNlIHsKICAgIHRocm93IG5ldyBFcnJvcignY2FuXCd0IHBvcCBmcm9tIGVtcHR5IHN0YWNrJyk7CiAgfQp9OwpfX3Jwbi5wcmludCA9IGZ1bmN0aW9uICh2YWwsIHJlcGVhdCkgewogIHdoaWxlIChyZXBlYXQtLSA+IDApIHsKICAgIHZhciBlbCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2RpdicpOwogICAgdmFyIHR4dCA9IGRvY3VtZW50LmNyZWF0ZVRleHROb2RlKHZhbCk7CiAgICBlbC5hcHBlbmRDaGlsZCh0eHQpOwogICAgZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChlbCk7CiAgfQp9OwpfX3Jwbi5wdXNoKDkpOwpfX3Jwbi5wdXNoKCdhJyk7CndpbmRvd1tfX3Jwbi5wb3AoKV0gPSBfX3Jwbi5wb3AoKTsKX19ycG4ucHVzaCgzKTsKX19ycG4ucHVzaCgnYicpOwp3aW5kb3dbX19ycG4ucG9wKCldID0gX19ycG4ucG9wKCk7Cl9fcnBuLnB1c2god2luZG93LmEpOwpfX3Jwbi5wdXNoKHdpbmRvdy5iKTsKX19ycG4udGVtcCA9IF9fcnBuLnBvcCgpOwppZiAoX19ycG4udGVtcCA9PT0gMCkgdGhyb3cgbmV3IEVycm9yKCdkaXZpZGUgYnkgemVybyBlcnJvcicpOwpfX3Jwbi5wdXNoKF9fcnBuLnBvcCgpIC8gX19ycG4udGVtcCk7Cl9fcnBuLnB1c2goJ2MnKTsKd2luZG93W19fcnBuLnBvcCgpXSA9IF9fcnBuLnBvcCgpOwpfX3Jwbi5wdXNoKHdpbmRvdy5hKTsKX19ycG4ucHVzaCh3aW5kb3cuYik7Cl9fcnBuLnB1c2god2luZG93LmMpOwpfX3Jwbi50ZW1wID0gX19ycG4ucG9wKCk7Cl9fcnBuLnB1c2goX19ycG4ucG9wKCkgLSBfX3Jwbi50ZW1wKTsKX19ycG4udGVtcCA9IF9fcnBuLnBvcCgpOwppZiAoX19ycG4udGVtcCA9PT0gMCkgdGhyb3cgbmV3IEVycm9yKCdkaXZpZGUgYnkgemVybyBlcnJvcicpOwpfX3Jwbi5wdXNoKF9fcnBuLnBvcCgpIC8gX19ycG4udGVtcCk7Cl9fcnBuLnB1c2goJ2MnKTsKd2luZG93W19fcnBuLnBvcCgpXSA9IF9fcnBuLnBvcCgpOwpfX3Jwbi5wdXNoKHdpbmRvdy5jKTsKX19ycG4ucHVzaCgxKTsKX19ycG4udGVtcCA9IF9fcnBuLnBvcCgpOwppZiAoX19ycG4udGVtcCA8PSAwKSB0aHJvdyBuZXcgRXJyb3IoJ2FyZ3VtZW50IG11c3QgYmUgZ3JlYXRlciB0aGFuIDAnKTsKaWYgKE1hdGguZmxvb3IoX19ycG4udGVtcCkgIT0gX19ycG4udGVtcCkgdGhyb3cgbmV3IEVycm9yKCdhcmd1bWVudCBtdXN0IGJlIGFuIGludGVnZXInKTsKX19ycG4ucHJpbnQoX19ycG4ucG9wKCksIF9fcnBuLnRlbXApOwoKLy9AIHNvdXJjZU1hcHBpbmdVUkw9d2l0aC1lcnJvci5qcy5tYXAK,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2l0aC1lcnJvci5qcy5tYXAiLCJzb3VyY2VzIjpbIndpdGgtZXJyb3IucnBuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBRSxXQUFBLENBQUE7QUFBRixXQUFBLENBQUEsQ0FBQSxDQUFBO0FBQUksb0JBQUEsQ0FBQTtBQUNGLFdBQUEsQ0FBQTtBQUFGLFdBQUEsQ0FBQSxDQUFBLENBQUE7QUFBSSxvQkFBQSxDQUFBO0FBQ0YsV0FBQSxPQUFBLENBQUE7QUFBRSxXQUFBLE9BQUEsQ0FBQTtBQUFFLFVBQUE7QUFBQSxJQUFBLFVBQUE7QUFBQSxXQUFBLFlBQUEsQ0FBQSxDQUFBLFVBQUE7QUFBTixXQUFBLENBQUEsQ0FBQSxDQUFBO0FBQVEsb0JBQUEsQ0FBQTtBQUNOLFdBQUEsT0FBQSxDQUFBO0FBQUUsV0FBQSxPQUFBLENBQUE7QUFBRSxXQUFBLE9BQUEsQ0FBQTtBQUFFLFVBQUE7QUFBQSxXQUFBLFlBQUEsQ0FBQSxDQUFBLFVBQUE7QUFBRSxVQUFBO0FBQUEsSUFBQSxVQUFBO0FBQUEsV0FBQSxZQUFBLENBQUEsQ0FBQSxVQUFBO0FBQVYsV0FBQSxDQUFBLENBQUEsQ0FBQTtBQUFZLG9CQUFBLENBQUE7QUFDWixXQUFBLE9BQUEsQ0FBQTtBQUFFLFdBQUEsQ0FBQTtBQUFFLFVBQUE7QUFBQSxJQUFBLFVBQUE7QUFBQSxlQUFBLFVBQUEsS0FBQSxVQUFBO0FBQUEsV0FBQSxjQUFBLFVBQUEifQ==,YSA5ID07CmIgMyA9OwpjIGEgYiAvID07CmMgYSBiIGMgLSAvID07CmMgMSBwcmludDs=">Here is the visualization of one of our source maps:  </a>
</p>
<p>
  <a href="https://hacks.mozilla.org/wp-content/uploads/2013/05/source-map-visualization.png"><br />
    <img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/source-map-visualization-500.png" alt="Screenshot of the source map visualization tool." /><br />
  </a>
</p>
<p>
  Good luck writing your own compiler that targets JavaScript!
</p>
<h2>References</h2>
<ul>
<li>
    <a href="https://github.com/mozilla/source-map">The <code>source-map</code> library</a>
  </li>
<li>
    <a href="https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#heading=h.zhn1phd7ocnp">The    source map specification</a>
  </li>
<li>
    <a href="https://github.com/fitzgen/rpn-js">The code used in this tutorial</a>
  </li>
<li>
    <a href="http://jison.org/">Jison</a>
  </li>
<li>
    <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">Reverse Polish Notation at Wikipedia</a>
  </li>
<li>
    <a href="http://dinosaur.compilertools.net/bison/bison_5.html#SEC16">Reverse Polish Notation calculator in Bison</a>
  </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/compiling-to-javascript-and-debugging-with-source-maps/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Introducing AWSBOX, the DiY PaaS for Node.JS – A Node.js holiday season, part 12</title>
		<link>https://hacks.mozilla.org/2013/05/introducing-awsbox-the-diy-paas-for-node-js-a-node-js-holiday-season-part-12/</link>
		<comments>https://hacks.mozilla.org/2013/05/introducing-awsbox-the-diy-paas-for-node-js-a-node-js-holiday-season-part-12/#comments</comments>
		<pubDate>Tue, 21 May 2013 19:44:47 +0000</pubDate>
		<dc:creator>Lloyd Hilaiel</dc:creator>
				<category><![CDATA[A Node.JS Holiday Season]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20963</guid>
		<description><![CDATA[This is episode 12, out of a total 12, in the A Node.JS Holiday Season series from Mozilla&#8217;s Identity team. It&#8217;s the last part, and covers awsbox. Once you&#8217;ve written a server in Node.js, how do you deploy it? Instead of using a pre-existing &#8220;Platform as a Service&#8221; (PaaS) provider, the Identity team at Mozilla [...]]]></description>
				<content:encoded><![CDATA[<blockquote><p>
    This is episode 12, out of a total 12, in the <a href="https://hacks.mozilla.org/category/a-node-js-holiday-season/as/brief/">A Node.JS Holiday Season series</a> from Mozilla&#8217;s Identity team. It&#8217;s the last part, and covers awsbox.
</p></blockquote>
<p>Once you&#8217;ve written a server in Node.js, how do you deploy it?<br />
Instead of using a pre-existing &#8220;Platform as a Service&#8221; (PaaS) provider, the <a href="http://identity.mozilla.com/">Identity team at Mozilla</a> chose to build custom infrastructure atop <a href="http://aws.amazon.com/ec2/">Amazon EC2</a>, and we&#8217;d like to tell you more about it.</p>
<p>Meet <a href="https://github.com/mozilla/awsbox">awsbox</a>, a minimalist PaaS layer for Node.js applications that&#8217;s currently handling nearly two dozen of the non-critical services that we support.<br />
Awsbox was designed to deliver simple, PaaS-style deployment without sacrificing the flexibility of custom infrastructure.</p>
<h2>Using awsbox</h2>
<p>In order to deploy a Node.JS project with awsbox, you must make some tiny changes to your application, provide your amazon credentials in the environment, and then you can deploy via the command line.</p>
<p>In terms of app changes, you must:</p>
<ol>
<li>Create an <code>.awsbox.json</code> file that specifies how to start the server.</li>
<li>add <code>awsbox</code> as a dependency in your <code>package.json</code></li>
<li>ensure your server binds to the port specified in the <code>PORT</code> environment variable</li>
</ol>
<p>To provide your amazon credentials, you must set <code>AWS_ID</code> and <code>AWS_SECRET</code> in your environment, two values which you can obtain through the <a href="http://aws.amazon.com/console/">amazon management console</a>.</p>
<p>With the initial application configuration complete, you can <code>npm install</code> which will install awsbox, and you&#8217;re ready to create your first server:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="plain" style="font-family:monospace;">$ node_modules/.bin/awsbox create -n MyFirstAWSBOX
reading .awsbox.json
attempting to set up VM &quot;MyFirstAWSBOX&quot;
   ... VM launched, waiting for startup (should take about 20s)
   ... Instance ready, setting human readable name in aws
   ... name set, waiting for ssh access and configuring
   ... public url will be: http://&lt;IP ADDRESS&gt;
   ... nope.  not yet.  retrying.
   ... victory!  server is accessible and configured
   ... applying system updates
   ... and your git remote is all set up
   ... configuring SSL behavior (enable)
&nbsp;
Yay! You have your very own deployment. Here are the basics:
&nbsp;
  1. deploy your code:  git push MyFirstAWSBOX HEAD:master
  2. visit your server on the web: http://&lt;IP ADDRESS&gt;
  3. ssh in with sudo: ssh ec2-user@&lt;IP ADDRESS&gt;
  4. ssh as the deployment user: ssh app@&lt;IP ADDRESS&gt;</pre></td></tr></table></div>

<p>The final step to deploy your application is to <code>git push</code>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">git push</span> MyFirstAWSBOX HEAD:master</pre></td></tr></table></div>

<p>And now your Node.JS application is hosted and running on an EC2 instance.  At this point, you&#8217;ve spent about twenty minutes with awsbox.  You&#8217;ve made minimal changes to your application.  You&#8217;ve deployed a new server and gotten your application up and running in EC2.  Finally, you&#8217;ve got an easy way to push changes that fits within your existing workflow (you just <code>git push</code> to a remote).</p>
<p>Now that you have a feel for how you use awsbox and the basic features it provides, let&#8217;s take a step back and look at what it actually is and how it works.</p>
<h2>awsbox is &#8230; A Minimalistic Contract</h2>
<p>Any hosting environment has certain expectations of the application that it will be running, <em>the contract</em>.  For awsbox this contract includes the following:</p>
<p><strong>What process(es) should be run</strong> are specified by the app in <code>.awsbox.json</code>.  At its simplest, the file may look like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;processes&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">&quot;path/to/myprocess.js&quot;</span> <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>What software must be installed</strong> is specified by the app in <code>package.json</code>.</p>
<p><strong>Which port to contact the server</strong> is delivered to the app via the <code>PORT</code> environment variable.</p>
<p>In building awsbox, a main goal was minimal invention, to make it easy to &#8220;port&#8221; an existing application.</p>
<h2>awsbox is &#8230; A Machine Image</h2>
<p>During the process of creating an instance, awsbox creates a machine instance from an &#8220;Amazon Machine Image&#8221;, which results in a running server that&#8217;s ready to accept your node.js application, install its dependencies, and run it.  The image is built from the <a href="http://aws.amazon.com/amazon-linux-ami/">Amazon Linux AMI</a> which is a custom linux distribution provided by amazon, and has access to popular rpm-based package repositories via <a href="http://en.wikipedia.org/wiki/Yellowdog_Updater,_Modified">yum</a>.  The ID of awsbox AMI is referenced in the <code>awsbox</code> javascript library.</p>
<p>This image is <em>pre-configured with multiple user accounts</em>.  <code>ec2-user</code> is an account that has sudo access to the machine.  <code>proxy</code> is an account that hosts an <a href="http://en.wikipedia.org/wiki/Reverse_proxy">HTTP reverse proxy</a> that with a <a href="https://github.com/mozilla/awsbox/blob/master/doc/HOW_DO_I.md#how-do-i-enable-ssl">few steps</a> can serve as an SSL terminator to let you support HTTPS without modifying your application.  Finally, the <code>app</code> user is the account that hosts all of your application code, your server logs, the server based git repository that you push to, and the <a href="https://www.kernel.org/pub/software/scm/git/docs/githooks.html">git post-commit hook</a> responsible for installing dependencies and starting your server after you push.</p>
<h2>awsbox is &#8230; Command Line Tools and Libraries</h2>
<p>At the time you <code>npm install</code> awsbox, a collection of javascript libraries and a command line tool are installed locally.  The command line tool gives you a much faster way to deploy servers than available through Amazon&#8217;s web console, and handles most of the complexity of creating an instance in EC2 that is ssh and web accessible.</p>
<p>The <code>awsbox</code> command line tool also provides many command line <em>verbs</em> to perform basic administration of your awsbox, which can be listed with <code>node_modules/.bin/awsbox -h</code>.</p>
<p>The most interesting verb is <code>create</code>, which actually creates a virtual machine.</p>
<h2>awsbox is &#8230; A Pile Of Features and Hooks</h2>
<p>Finally, any non-trivial server requires more than just a Node.JS service.  To support the unknown awsbox allows you to <a href="https://github.com/mozilla/awsbox/blob/master/doc/JSON.md#packages-optional">specify yum packages that should be installed</a> at instance creation time.  For more custom configuration you have two options:</p>
<p><strong>SSH in and do whatever you need to</strong>: The goal of awsbox is to let you move as fast as possible, and sometimes the most expedient way to get a new instance of a service up is to perform required steps manually and write a README.  But a more repeatable solution is available…</p>
<p><strong>Write scripts to automatically configure software for you</strong>: Awsbox has the <a href="https://github.com/mozilla/awsbox/blob/master/doc/JSON.md#remote_hooks-optional">notion of <em>hooks</em></a>, which occur at various stages of instance creation or deployment.  Using these hooks, it&#8217;s possible to <a href="https://github.com/mozilla/browserid/blob/4971e83b897829d866f99c0e398d52a7b3b9ec2b/scripts/awsbox_remote/post_create.sh">configure mysql</a>, <a href="https://github.com/mozilla/restmail.net/blob/44306506b1a33ed3c1fbc1b61f13b8d557b80141/aws_scripts/post_create.sh">install redis manually</a>, or do whatever you need to in order to get your service running.</p>
<h1>Is awsbox for Me?</h1>
<p>Having a single consistent mechanism of deploying non-critical services has been an incredible efficiency benefit for our team.  <em>Collaboration is easier</em> when you have a simple and well defined contract between application and environment.  <em>Diagnosis of issues</em> is faster when you have a consistent set of deployment conventions.  Finally, <em>moving from experiment to production environment is less costly</em> when an application has all of its dependencies explicitly expressed.</p>
<p>If you are looking for a deployment solution for your own experimental Node.JS services, give the ideas and design of awsbox a careful look.</p>
<h2>Previous articles in the series</h2>
<p>This was part twelve in <a href="https://hacks.mozilla.org/category/a-node-js-holiday-season/as/brief/">a series with a total of 12 posts about Node.js</a>. The previous ones are:</p>
<ul>
<li><a href="https://hacks.mozilla.org/2012/11/tracking-down-memory-leaks-in-node-js-a-node-js-holiday-season/">Tracking Down Memory Leaks in Node.js</a></li>
<li><a href="https://hacks.mozilla.org/2012/11/fully-loaded-node-a-node-js-holiday-season-part-2/">Fully Loaded Node</a></li>
<li><a href="https://hacks.mozilla.org/2012/12/using-secure-client-side-sessions-to-build-simple-and-scalable-node-js-applications-a-node-js-holiday-season-part-3/">Using secure client-side sessions to build simple and scalable Node.JS applications</a></li>
<li><a href="https://hacks.mozilla.org/2012/12/fantastic-front-end-performance-part-1-concatenate-compress-cache-a-node-js-holiday-season-part-4/">Fantastic front-end performance Part 1 – Concatenate, Compress &amp; Cache</a></li>
<li><a href="https://hacks.mozilla.org/2013/01/building-a-node-js-server-that-wont-melt-a-node-js-holiday-season-part-5/">Building A Node.JS Server That Won’t Melt</a></li>
<li><a href="https://hacks.mozilla.org/2013/02/fantastic-front-end-performance-in-node-part-2-a-node-js-holiday-season-part-6/">Fantastic front-end performance, part 2: caching dynamic content with etagify</a></li>
<li><a href="https://hacks.mozilla.org/2013/03/taming-configurations-with-node-convict-a-node-js-holiday-season-part-7/">Taming Configurations with node-convict</a></li>
<li><a href="https://hacks.mozilla.org/2013/03/fantastic-front-end-performance-part-3-big-performance-wins-by-optimizing-fonts-a-node-js-holiday-season-part-8/">Fantastic front end performance, part 3 – Big performance wins by optimizing fonts</a></li>
<li><a href="https://hacks.mozilla.org/2013/04/localize-your-node-js-service-part-1-of-3-a-node-js-holiday-season-part-9/">Localize Your Node.js Service, part 1 of 3</a></li>
<li><a href="https://hacks.mozilla.org/2013/04/localization-community-tools-process-part-2-of-3-a-node-js-holiday-season-part-10/">Localization community, tools &#038; process, part 2 of 3</a></li>
<li><a href="https://hacks.mozilla.org/2013/04/localization-in-action-part-3-of-3-a-node-js-holiday-season-part-11/">Localization in Action, part 3 of 3</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/introducing-awsbox-the-diy-paas-for-node-js-a-node-js-holiday-season-part-12/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Firefox Developer Tool Features for Firefox 23</title>
		<link>https://hacks.mozilla.org/2013/05/firefox-developer-tool-features-for-firefox-23/</link>
		<comments>https://hacks.mozilla.org/2013/05/firefox-developer-tool-features-for-firefox-23/#comments</comments>
		<pubDate>Tue, 21 May 2013 09:07:15 +0000</pubDate>
		<dc:creator>Rob Campbell</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Featured Article]]></category>
		<category><![CDATA[Firefox Aurora]]></category>
		<category><![CDATA[Firefox Nightly]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20790</guid>
		<description><![CDATA[Another uplift has left the building and it&#8217;s time to take a look at what&#8217;s in Firefox Developer Tools in Firefox 23 currently Aurora, our pre-beta channel. You can download it from the Aurora Download page today. Firefox 23 is currently scheduled to hit the release channel on Tuesday August 6th, 2013. Episode XXIII is [...]]]></description>
				<content:encoded><![CDATA[<p>Another uplift has left the building and it&#8217;s time to take a look at what&#8217;s in Firefox Developer Tools in Firefox 23 currently Aurora, our pre-beta channel. You can download it from <a href="http://www.mozilla.org/en-US/firefox/aurora/">the Aurora Download page</a> today. Firefox 23 is currently scheduled to hit the release channel on Tuesday August 6th, 2013.</p>
<p>Episode XXIII is a barn-storming, hair-raising spectacle of incredible epicness that is sure to delight and amuse. If you want a sneak peak at features under active development, give <a href="http://nightly.mozilla.org/">Nightly</a> a try.</p>
<h2>Network Monitor</h2>
<p>There&#8217;s a new tool in the toolbox: The Network Monitor. It&#8217;s a classic waterfall timeline view of network activity on a site. This data&#8217;s been available since Firefox 4 via the Web Console, albeit in a less visually pleasing way.</p>
<p><a href="https://hacks.mozilla.org/wp-content/uploads/2013/05/network-monitor.png"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/network-monitor-500.png" alt="" /></a></p>
<p>Please file bugs under the <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Firefox">Developer Tools: Netmonitor</a> component in Bugzilla.</p>
<h2>Remote Style Editor</h2>
<p>In Firefox 23, you can now edit styles via a Remote Connection on a suitably-enabled device. This should be great help for App Developers interested in testing and debugging styles on a mobile device over the remote protocol in real time.</p>
<p>As of the time of this writing, the Remote Style Editor should be compatible with Firefox for Android version 23, also scheduled for uplift to Aurora. We are working on <a href="https://github.com/mozilla/r2d2b2g/issues/499">incorporating the Style Editor Actors for the remote protocol into the Firefox OS Simulator</a> and investigating what it will take to backport them to Firefox OS release.</p>
<h2>Options Panel</h2>
<p>We&#8217;ve added a Gear menu to the Toolbar containing an Options panel for turning tools on or off. As we add more stuff, this is going to be a popular place to manage preferences related to the Developer Tools.</p>
<p>Currently, there are options to turn on the Light or Dark theme for the tools and enable Chrome Debugging.</p>
<h2>Initial SourceMap Support for Debugger Protocol</h2>
<p>The first pieces of SourceMap support for the Debugger have landed and we are now able to serve up SourceMapped JS files for your debugging pleasure. Soon to follow will be column support for breakpoints allowing you to debug minified JS with a SourceMap.</p>
<p>Watch for the upcoming blog post by Nick Fitzgerald on Hacks explaining the magic.</p>
<h2>Variables View Everywhere</h2>
<p>Our Variables View is an improved Object Inspector and an integral part of our Debugger. Naturally, we wanted to put it in Everything. So now the Web Console and Scratchpad have a Variables View. Use the ESC key to close it.</p>
<h2>Browser Console</h2>
<p>If you have Chrome Debugging turned on, check out the Browser Console. It&#8217;s a replacement for the ancient Error Console and gives you a Chrome-context command line for executing JavaScript against the browser. It&#8217;s nice and should be enabled by default in Firefox 24.</p>
<h2>GCLI Appcache Command</h2>
<p>We finally have a little something for developers trying to use App Cache to store offline data. A new <code>appcache</code> command for the Graphical Command Line. You can read about it in Mike Ratcliffe&#8217;s <a href="http://flailingmonkey.com/application-cache-not-a-douchebag">The Application Cache is no longer a Douchebag</a>.</p>
<h2>Web Console in Debugger Frame</h2>
<p>The Web Console is now fully-remoted (and has been since version 18). It now makes use of the Debugger&#8217;s current Frame if paused on a breakpoint.</p>
<h2>Multiple Paused Debuggers</h2>
<p>You can now debug multiple tabs at the same time using the Script Debugger. Previously, when attempting to use the debugger on two separate tabs, you&#8217;d be given a notification to resume the debugger in the other tab. Now you can debug as many tabs as you like.</p>
<p>There is one caveat to this awesome power, however. Due to the nested event loops each Debugger creates, you have to resume each tab in the order in which they were paused. Debug carefully and always carry a big stack.</p>
<p>You can see a comprehensive list of <a href="https://bugzilla.mozilla.org/buglist.cgi?list_id=6499762&amp;resolution=FIXED&amp;classification=Client%20Software&amp;chfieldto=2013-05-13&amp;chfield=target_milestone&amp;query_format=advanced&amp;chfieldfrom=2013-03-20&amp;chfieldvalue=Firefox%2023&amp;bug_status=RESOLVED&amp;bug_status=VERIFIED&amp;component=Developer%20Tools&amp;component=Developer%20Tools%3A%203D%20View&amp;component=Developer%20Tools%3A%20Console&amp;component=Developer%20Tools%3A%20Debugger&amp;component=Developer%20Tools%3A%20Framework&amp;component=Developer%20Tools%3A%20Graphic%20Commandline%20and%20Toolbar&amp;component=Developer%20Tools%3A%20Inspector&amp;component=Developer%20Tools%3A%20Netmonitor&amp;component=Developer%20Tools%3A%20Profiler&amp;component=Developer%20Tools%3A%20Responsive%20Mode&amp;component=Developer%20Tools%3A%20Scratchpad&amp;component=Developer%20Tools%3A%20Source%20Editor&amp;component=Developer%20Tools%3A%20Style%20Editor&amp;product=Firefox">bugfixes</a> in table form in <a href="http://robcee.net/2013/new-features-in-firefox-developer-tools-episode-23/">Firefox 23 Developer Tools Fixes</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/firefox-developer-tool-features-for-firefox-23/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Building a Notes App with IndexedDB, Redis and Node.js</title>
		<link>https://hacks.mozilla.org/2013/05/building-a-notes-app-with-indexeddb-redis-and-node-js/</link>
		<comments>https://hacks.mozilla.org/2013/05/building-a-notes-app-with-indexeddb-redis-and-node-js/#comments</comments>
		<pubDate>Thu, 16 May 2013 21:03:33 +0000</pubDate>
		<dc:creator>Jennifer Fong-Adwent</dc:creator>
				<category><![CDATA[IndexedDB]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20714</guid>
		<description><![CDATA[In this post, I&#8217;ll be talking about how to create a basic note-taking app that syncs local and remote content if you are online and defaults to saving locally if offline. Using Redis on the server-side When adding records in Redis, we aren&#8217;t working with a relational database like in MySQL or PostgreSQL. We are [...]]]></description>
				<content:encoded><![CDATA[<p>In this post, I&#8217;ll be talking about how to create a basic note-taking app that syncs local and remote content if you are online and defaults to saving locally if offline.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/generalnotes-1.png" alt="notes app sample" title=""></p>
<h3>Using Redis on the server-side</h3>
<p>When adding records in Redis, we aren&#8217;t working with a relational database like in MySQL or PostgreSQL. We are working with a structure like IndexedDB where there are keys and values. So what do we need when we only have keys and values to work with for a notes app? We need unique ids to reference each note and a hash of the note metadata. The metadata in this example, consists of the new unique id, a creation timestamp and the text.</p>
<p>Below is a way of creating an id with Redis in Node and then saving the note&#8217;s metadata.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Let's create a unique id for the new note.</span>
client.<span style="color: #660066;">incr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'notes:counter'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>err<span style="color: #339933;">,</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
...
&nbsp;
    <span style="color: #006600; font-style: italic;">// All note ids are referenced by the user's email and id.</span>
    <span style="color: #000066; font-weight: bold;">var</span> keyName <span style="color: #339933;">=</span> <span style="color: #3366CC;">'notes:'</span> <span style="color: #339933;">+</span> req.<span style="color: #660066;">session</span>.<span style="color: #660066;">email</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">':'</span> <span style="color: #339933;">+</span> id<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> req.<span style="color: #660066;">body</span>.<span style="color: #660066;">timestamp</span> <span style="color: #339933;">||</span> <span style="">Math</span>.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span><span style="">Date</span>.<span style="color: #660066;">now</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Add the new id to the user's list of note ids.</span>
    client.<span style="color: #660066;">lpush</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'notes:'</span> <span style="color: #339933;">+</span> req.<span style="color: #660066;">session</span>.<span style="color: #660066;">email</span><span style="color: #339933;">,</span> keyName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Add the new note to a hash.</span>
    client.<span style="color: #660066;">hmset</span><span style="color: #009900;">&#40;</span>keyName<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
      id<span style="color: #339933;">:</span> id<span style="color: #339933;">,</span>
      timestamp<span style="color: #339933;">:</span> timestamp<span style="color: #339933;">,</span>
      text<span style="color: #339933;">:</span> finalText
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
...
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This gives us the following key pattern for all notes on the server-side:</p>
<ol>
<li><code>notes:counter</code> contains all unique ids starting at 1.</li>
<li><code>notes:&lt;email&gt;</code> contains all the note ids that are owned by the user. This is a list that we reference when we want to loop through all the user&#8217;s notes to retrieve the metadata.</li>
<li><code>notes:&lt;email&gt;:&lt;note id&gt;</code> contains the note metadata. The user&#8217;s email address is used as a way to reference this note to the correct owner. When a user deletes a note, we want to verify that it matches the same email that they are logged in with, so you don&#8217;t have someone deleting a note that they don&#8217;t own.</li>
</ol>
<h2>Adding IndexedDB on the client-side</h2>
<p>Working with IndexedDB requires more code than localStorage. But because it is asynchronous, it makes it a better option for this app. The main reason for why it is a better option is two-fold:</p>
<ol>
<li>You don&#8217;t want to wait around for all your notes to process before the page renders all elements. Imagine having thousands of notes and having to wait for all of them to loop through before anything on the page appears. </li>
<li>You can&#8217;t save note objects as objects &#8211; you have to convert them to strings first, which means you will have to convert them back to objects before they are rendered. So something like <code>{ id: 1, text: 'my note text', timestamp: 1367847727 }</code> would have to be stringified in localStorage and then parsed back after the fact. Now imagine doing this for a lot of notes.</li>
</ol>
<p>Both do not equate to an ideal experience for the user &#8211; but what if we want to have the ease of localStorage&#8217;s API with the asynchronous features of IndexedDB? We can use <a href="https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js">Gaia&#8217;s async_storage.js</a> file to help merge the two worlds.</p>
<p>If we&#8217;re offline, we need to do two things similar to the server-side:</p>
<ol>
<li>Save a unique id for the note and apply it in an array of ids. Since we can&#8217;t reference a server-side id created by Redis, we&#8217;ll use a timestamp.</li>
<li>Save a local version of the note metadata.</li>
</ol>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  content<span style="color: #339933;">:</span> rendered<span style="color: #339933;">,</span>
  timestamp<span style="color: #339933;">:</span> id<span style="color: #339933;">,</span>
  text<span style="color: #339933;">:</span> content
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
asyncStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span>LOCAL_IDS<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">localIds</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  asyncStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span>LOCAL_NOTE <span style="color: #339933;">+</span> id<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> <span style="color: #000066; 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: #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></td></tr></table></div>

<p>The structure of the IndexedDB keys are very similar to the Redis ones. The pattern is as follows:</p>
<ol>
<li>All local ids are saved in a <code>localNoteIds</code> array</li>
<li>All local note objects are saved in <code>note:local:&lt;id&gt;</code> </li>
<li>All remote/synced ids are saved in a <code>noteIds</code> array</li>
<li>All remote/synced note objects are saved in <code>note:&lt;id&gt;</code> </li>
<li>Local notes use a timestamp for their unique id and this is converted to a valid server id once Redis saves the data</li>
</ol>
<p>Once we&#8217;re online, we can upload the local notes, save the remote ones on the client-side and then delete the local ones.</p>
<h2>Triggering note.js on the client-side</h2>
<p>Whenever we refresh the page, we need to attempt a sync with the server. If we are offline, let&#8217;s flag that and only grab what we have locally.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Get all local and remote notes.
 * If online, sync local and server notes; otherwise load whatever
 * IndexedDB has.
 */</span>
asyncStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'noteIds'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>rNoteIds<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  note.<span style="color: #660066;">remoteIds</span> <span style="color: #339933;">=</span> rNoteIds <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  asyncStorage.<span style="color: #660066;">getItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'localNoteIds'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>noteIds<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    note.<span style="color: #660066;">localIds</span> <span style="color: #339933;">=</span> noteIds <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    $.<span style="color: #000066; font-weight: bold;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/notes'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      note.<span style="color: #660066;">syncLocal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      note.<span style="color: #660066;">syncServer</span><span style="color: #009900;">&#40;</span>data<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: #660066;">fail</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      note.<span style="color: #660066;">offline</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      note.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'localNoteIds'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'note:local:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      note.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'noteIds'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'note:'</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>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Almost done!</h2>
<p>The code above provides the basics for a CRD notes app with support for local and remote syncing. But we&#8217;re not done yet.</p>
<p>On Safari, IndexedDB is not supported as they still use WebSQL. This means none of our IndexedDB code will work. To make this cross-browser compatible, we need to include a <a href="http://nparashuram.com/IndexedDBShim/">polyfill for browsers that only support WebSQL</a>. Include this before the rest of the code and IndexedDB support should work.</p>
<h2>The Final Product</h2>
<p>You can try out the app at <a href="http://notes.generalgoods.net">http://notes.generalgoods.net</a></p>
<h2>The Source Code</h2>
<p>To view the code for this app feel free to browse the <a href="https://github.com/ednapiranha/generalnotes">repository on Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/building-a-notes-app-with-indexeddb-redis-and-node-js/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Pushing Firefox OS Apps to the Geeksphone</title>
		<link>https://hacks.mozilla.org/2013/05/pushing-firefox-os-apps-to-the-geeksphone/</link>
		<comments>https://hacks.mozilla.org/2013/05/pushing-firefox-os-apps-to-the-geeksphone/#comments</comments>
		<pubDate>Tue, 14 May 2013 19:38:51 +0000</pubDate>
		<dc:creator>Jason Weathersby</dc:creator>
				<category><![CDATA[Firefox OS]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20829</guid>
		<description><![CDATA[A push to device feature was added in the 3.0 release of the Firefox OS Simulator. This feature allows web apps to be pushed to a connected device by clicking one button in the Simulator Dashboard. Availability of the Developer Preview Phone from Geeksphone has raised interest in the feature, so this post will detail [...]]]></description>
				<content:encoded><![CDATA[<p>A push to device feature was added in the 3.0 release of the <a href="https://hacks.mozilla.org/2013/05/firefox-os-simulator-3-0-released/">Firefox OS Simulator</a>. This feature allows web apps to be pushed to a connected device by clicking one button in the Simulator Dashboard. Availability of the <a href="https://hacks.mozilla.org/2013/04/geeksphone-to-start-selling-firefox-os-developer-preview-phones/">Developer Preview Phone from Geeksphone</a> has raised interest in the feature, so this post will detail how to configure your Geeksphone and the computer running the Simulator to make use of it.<br />
<img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/simulatoronmac.png" alt="Firefox OS Simulator on a Mac"/></p>
<h2>Setting Up the Geeksphone Device</h2>
<p>To push apps to the Geeksphone Firefox OS Developer Preview phone, you first need to enable Remote debugging. This can be done from the Settings app by selecting Device information > More Information > Developer -> Remote debugging. Now we are ready to configure the computer running the Simulator.</p>
<h3>Windows</h3>
<p>The team at Geeksphone recently released a set of drivers for Windows to support USB communication with their phones. The <a href="http://downloads.geeksphone.com/drivers/usb_driver.zip">drivers are available at Geeksphone&#8217;s Web Site (direct ZIP link)</a>.</p>
<p>To install them, first download and extract the zip file to a known location on your system. Next, connect the phone to your machine using the provided USB cable. Click on the Start Button and enter “Device Manager” in the Search programs and files text entry field and press enter. This will launch the Windows Device Manager. Alternatively, you can launch the Device Manager from the icon located in the Windows Control Panel.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/devicemanagerbefore.png" alt="Device Manager before driver installed" /></p>
<p>The connected phone will be listed under the Other Devices category. Right click on the Android label and select Update Driver Software&#8230;.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/updatedriver1.png" alt="Right Click options"/></p>
<p>In the Update Driver Software dialog, choose Browse my computer for driver software.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/updatedriver2.png" alt="Update driver dialog"/></p>
<p>Locate the usb_driver folder from the Geeksphone download and make sure the Include subfolders checkbox is checked. Click on the Next button.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/updatedriver3.png" alt="Locate Driver"/></p>
<p>You will most likely receive a Windows Security alert.  Select the Install this driver software anyway entry.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/updatedriver4.png" alt="Windows security alert prompt" /></p>
<p>This will install the proper USB drivers and list the phone as Geeksphone Device in the Device Manager. </p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/devicemanager.png" alt="Device manager with drivers updated"/></p>
<p>Launch the Firefox OS Simulator. The Dashboard should now contain a Push button and a Device connected message, and you should be able to add your Firefox OS app to the Simulator and push it to the phone.</p>
<h3>Linux</h3>
<p>If you are running the Simulator on a Linux machine, you will need to create or modify a udev rules file for the device. This process is described in “<a href="https://developer.android.com/tools/device.html">Setting up a Device for Development</a>&#8221; (Steps 3.a and 3.b). The Geeksphone Firefox OS Developer Preview phone idVendor attribute is  “05c6”, so your android.rules file should contain an entry similar to:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SUBSYSTEM</span>==”usb”, ATTR<span style="color: #7a0874; font-weight: bold;">&#123;</span>idVendor<span style="color: #7a0874; font-weight: bold;">&#125;</span>==”05c6”, <span style="color: #007800;">MODE</span>=”0666”, <span style="color: #007800;">GROUP</span>=”plugdev”</pre></td></tr></table></div>

<p>After making the above changes, either reboot the system or restart the udev service:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> service udev restart</pre></td></tr></table></div>

<p>If you make these changes and the push to device button does not show up in the Simulator Dashboard, please see this <a href="https://github.com/mozilla/r2d2b2g/issues/515">workaround</a>.</p>
<h3>Mac</h3>
<p>If you are running the Simulator on a Mac, no additional configuration is required to enable push to device.</p>
<h2>Reference</h2>
<p>Additional information about setting up and using the Firefox OS Simulator, including installing, adding apps, debugging and using the push to device capability can be found on the MDN page for the <a href="https://developer.mozilla.org/en-US/docs/Tools/Firefox_OS_Simulator">Firefox OS Simulator</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/pushing-firefox-os-apps-to-the-geeksphone/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Speed Up App Development with X-Tag and Web Components</title>
		<link>https://hacks.mozilla.org/2013/05/speed-up-app-development-with-x-tag-and-web-components/</link>
		<comments>https://hacks.mozilla.org/2013/05/speed-up-app-development-with-x-tag-and-web-components/#comments</comments>
		<pubDate>Mon, 13 May 2013 20:27:11 +0000</pubDate>
		<dc:creator>Daniel Buchner</dc:creator>
				<category><![CDATA[Web Developers]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20738</guid>
		<description><![CDATA[In the last few years we&#8217;ve witnessed an evolution in what &#8216;app&#8217; means to both developers and consumers. The word app evokes the idea of a rich, task-oriented user experience with highly optimized user interface that responds to its environment and can be used on an array of common devices. In order to make development [...]]]></description>
				<content:encoded><![CDATA[<p>In the last few years we&#8217;ve witnessed an evolution in what &#8216;app&#8217; means to both developers and consumers. The word app evokes the idea of a rich, task-oriented user experience with highly optimized user interface that responds to its environment and can be used on an array of common devices. In order to make development of rich app experiences easier, native platforms have generated many of their own controls and components that Just Work&#8482;. </p>
<p>For other native technology stacks, extensible components are all but assumed &#8211; not so much for the web. Soon, that all changes. We are on the verge of a declarative renaissance that will dramatically advance app development for the web platform, and Web Components will drive it.</p>
<p>X-Tag and Web Components offer features that obliterate the status quo for layout, UI, and widget development &#8211; here&#8217;s a few notable Web Component features:</p>
<ul>
<li>Create real custom elements the browser understands</li>
<li>Stop the instantiation madness: <strike>$$(&#8216;button.super&#8217;).initSuperButton()</strike></li>
<li>Remove unmanageable HTML widget guts from your app&#8217;s view files</li>
<li>Work with sharable components, based on standard technologies</li>
</ul>
<h2>Meet the Web Components Family</h2>
<p>Web Components is a group of W3C specifications, quickly moving toward standardization, that provide a robust HTML component model. You should not assume the following specs are implemented in your browser of choice. While these specifications are in various stages of implementation across browsers, you can use X-Tag (with either <a href="https://github.com/mozilla/web-components/blob/master/src/document.register.js">Mozilla</a> or <a href="https://github.com/toolkitchen/CustomElements/tree/master">Google&#8217;s</a> prollyfill) today to create custom elements that work well in recent version of Firefox, Chrome, Safari, and stock mobile browsers. X-Tag is a powerful sugar library primarily focused on wrapping and enhancing one of the draft-state Web Component specs: Custom Elements (document.register). We&#8217;ll get to X-Tag shortly &#8211; but for now, let&#8217;s quickly review the key features of each spec:</p>
<h3>Custom Elements</h3>
<p><a href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html" title="W3 Custom Elements spec">Custom Elements</a> provides you a way to create new elements for use in your environment. There are two ways to declare a new custom element, the imperative DOM API &#8211; document.register(), and the declarative HTML tag &#8211; <element> (whose DOM constructor is HTMLElementElement). After declaration, new custom elements can be created in the same ways native elements are, such as document.createElement, presences in original source (the markup of a page), and innerHTML, etc.</p>
<p>Here&#8217;s an example of what a custom element registration looks like in both the declarative and imperative styles:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">register</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'x-foo'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #339933;">:</span> <span style="">Object</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>HTMLElement.<span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    readyCallback<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> 
      value<span style="color: #339933;">:</span> <span style="color: #000066; 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: #006600; font-style: italic;">// do stuff here when your element is created</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div&gt;Barrrr me matey!&lt;/div&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>        
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    bar<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">get</span><span style="color: #339933;">:</span> <span style="color: #000066; 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: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'bar'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #006600; font-style: italic;">// add more properties to your custom prototype</span>
    <span style="color: #006600; font-style: italic;">// ...</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>element name<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;x-foo&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</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: #339933;">!==</span> window<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">prototype</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          readyCallback<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> 
            value<span style="color: #339933;">:</span> <span style="color: #000066; 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: #006600; font-style: italic;">// do stuff here when your element is created</span>
              <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div&gt;Barrrr me matey!&lt;/div&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>        
          <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
          bar<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">get</span><span style="color: #339933;">:</span> <span style="color: #000066; 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: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'bar'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>element<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>Shadow DOM</h3>
<p>The <a href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html" title="W3 Shadow DOM spec">Shadow DOM</a> allows you to encapsulate structural and supporting elements within components. Elements within <shadow-root> nodes remain visible for purposes of display UI (depending on the type of element and your styles), but are hidden from the rest of your application code, unless you explicitly cross the <a href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#dfn-shadow-boundary" title="W3 Shadow DOM spec - shadow boundary section">shadow boundary</a>.  </p>
<h3>HTML Templates</h3>
<p><a href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html" title="W3 HTML Templates spec">HTML Templates</a> bring simple DOM templating and markup reuse to the web platform &#8211; which are often shimmed today using the <a href="http://stackoverflow.com/questions/4912586/explanation-of-script-type-text-template-script" title="StackOverflow explanation of script tag templating hack"><code>HTMLScriptElement</code> + <code>DocumentFragment</code> hack-pattern</a>.</p>
<h3>HTML Imports</h3>
<p><a href="https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/imports/index.html" title="W3 HTML Imports spec">HTML Imports</a> are external HTML documents that contain declarative component definitions. HTML component documents can by imported using the <code>link</code> element with the <code>rel</code> attribute value <code>import</code>. Imported resources may themselves contain additional sub-imports, which the browser then retrieves and performs automatic dependency resolution upon.</p>
<h2>Web Components + X-Tag = WINNING</h2>
<p>Mozilla&#8217;s <a href="http://www.x-tags.org" title="X-Tags project site">X-Tag library</a> enhances the imperative (JavaScript) route for creating custom elements. X-Tag&#8217;s primary interface is the <code>xtag.register()</code> method &#8211; it wraps the soon-to-be standard <code>document.register()</code> DOM API with features and functionality that make development of amazing custom elements effortless.</p>
<h3>Creating a Custom Element</h3>
<p>Here&#8217;s a quick example of what registering a custom element looks like using X-Tag:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">xtag.<span style="color: #660066;">register</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'x-pirate'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
  lifecycle<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    ready<span style="color: #339933;">:</span> <span style="color: #000066; 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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;blockquote&gt;'</span> <span style="color: #339933;">+</span>
                         <span style="color: #3366CC;">'&lt;img src=&quot;pirate-1.png&quot;/&gt;Barrr me matey!'</span> <span style="color: #339933;">+</span>
                       <span style="color: #3366CC;">'&lt;/blockquote&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  accessors<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    src<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// X-Tag's attribute sugar relays any value passed to the src </span>
      <span style="color: #006600; font-style: italic;">// setter on to the src attribute of our &lt;x-pirate&gt; and its</span>
      <span style="color: #006600; font-style: italic;">// &lt;img&gt; element (specified by CSS selector), and vice versa.</span>
      attribute<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> selector<span style="color: #339933;">:</span> <span style="color: #3366CC;">'img'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #000066; font-weight: bold;">set</span><span style="color: #339933;">:</span> <span style="color: #000066; 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: #006600; font-style: italic;">// When a &lt;x-pirate&gt;'s src attribute/setter is changed, we </span>
        <span style="color: #006600; font-style: italic;">// stop everything to announce the arrival of a new pirate.</span>
        <span style="color: #006600; font-style: italic;">// Ex: doc.querySelector('x-pirate').src = 'pirate-2.png';</span>
        alert<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;There's a new captain on deck ye scurvy dogs!&quot;</span><span style="color: #009900;">&#41;</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>
  events<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This is an example of X-Tag's event and pseudo systems. The</span>
    <span style="color: #006600; font-style: italic;">// &quot;tap&quot; custom event handles the dance between click and touch,</span>
    <span style="color: #006600; font-style: italic;">// the &quot;:delegate(img)&quot; pseudo ensures our function is only </span>
    <span style="color: #006600; font-style: italic;">// called when tapping the &lt;img&gt; inside our &lt;x-pirate&gt;.</span>
    <span style="color: #3366CC;">'tap:delegate(blockquote &gt; img)'</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      alert<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A pirate's life for me!&quot;</span><span style="color: #009900;">&#41;</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: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>To the Democave Batman!</h3>
<p>We&#8217;re actively working on a custom element UI toolkit and style pack that will make development of app interfaces a breeze. It&#8217;s still in very early stages, but we have a <a href="http://ui.x-tags.org">few demos for you</a>.</p>
<h3>Get the Code</h3>
<p>Head over to <a href="http://www.x-tags.org" title="X-Tag project website">X-Tags.org</a> and grab the code to develop custom elements of your own. After you get the hang of things, start contributing to our <a href="https://github.com/x-tag" title="X-Tag on GitHub">open source effort</a>!</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/speed-up-app-development-with-x-tag-and-web-components/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Phones for Apps for Firefox OS</title>
		<link>https://hacks.mozilla.org/2013/05/phones-for-apps-for-firefox-os/</link>
		<comments>https://hacks.mozilla.org/2013/05/phones-for-apps-for-firefox-os/#comments</comments>
		<pubDate>Thu, 09 May 2013 14:38:13 +0000</pubDate>
		<dc:creator>Havi Hoffman</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Firefox OS]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20687</guid>
		<description><![CDATA[Update: Today, Monday, May 13 at 11:00am PDT, we closed the submission form for the Phones for Apps program. Thanks so much to all of you for your interest and enthusiasm. Your response has been overwhelming! We&#8217;ve received thousands of applications, more than we&#8217;re equipped to review in a timely fashion. We&#8217;ve started reviewing your [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Update:</strong> <em>Today, Monday, May 13 at 11:00am PDT, we closed the submission form for the Phones for Apps program. Thanks so much to all of you for your interest and enthusiasm. Your response has been overwhelming! We&#8217;ve received thousands of applications, more than we&#8217;re equipped to review in a timely fashion. </p>
<p>We&#8217;ve started reviewing your proposals, and in the next few weeks we plan to notify application builders and porters who&#8217;ve been selected. We regret we can&#8217;t respond to the thousands of you with great ideas for apps for Firefox OS. There will be other opportunities to get access to the the Developer Preview device. Please keep working on your apps. We can&#8217;t wait to see them in Firefox Marketplace.</em> </p>
<p>Hello HTML5 app developers, the open mobile web is calling.  </p>
<p>We know you&#8217;re out there, chomping at the bit, coding, testing, <a href="https://marketplace.firefox.com/developers/docs/quick_start" title="Firefox OS Quick Start" target="_blank">reading documentation</a>, downloading and <a href="https://hacks.mozilla.org/2013/05/firefox-os-simulator-3-0-released/" title="Firefox OS Simulator 3.0 Released" target="_blank">running the Firefox Simulator</a>. And you&#8217;re ready to &#8216;Send to Device.&#8217; You just need to get your hands on a device.</p>
<p>Today we&#8217;re announcing a new program with you in mind. We call it: <a href="http://bit.ly/phones-for-apps" title="Phones for Apps for Firefox OS" target="_blank"><em>Phones for Apps for Firefox OS</em></a>. </p>
<div id="attachment_20691" class="wp-caption aligncenter" style="width: 510px"><a href="https://marketplace.firefox.com/developers/"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/GeeksphoneDOFMarket-500x640.jpg" alt="Firefox Marketplace on the Geeksphone" width="500" height="640" class="size-large wp-image-20691" /></a><p class="wp-caption-text">Firefox Marketplace on the Geeksphone Keon</p></div>
<p>Maybe you&#8217;ve built apps in the past for Chrome, webOS, Blackberry WebWorks, or the PhoneGap store. Maybe you&#8217;ve created beautiful web apps for a desktop environment and now you want to port them to mobile. Maybe you&#8217;re a student about to start a summer break. We know you may not live anywhere near Bogota, Colombia or Warsaw, Poland, <a href="http://bit.ly/FxOSAppWorkshop-apply" title="Firefox OS App Workshop application" target="_blank">locations of upcoming App Workshops</a>.</p>
<h2>Wherever you are</h2>
<p>Wherever you are, if you can <a href="http://bit.ly/phones-for-apps" title="Phones for Apps for Firefox OS" target="_blank">show you&#8217;ve got a great app idea</a> and the skill to build it, we&#8217;d love to see your apps in the Marketplace when the Firefox OS launch begins later this summer. And to sweeten the deal, we&#8217;ll send a <a href="https://hacks.mozilla.org/2013/01/announcing-the-firefox-os-developer-preview-phone/" title="Announcing the Firefox OS Developer Preview Phone" target="_blank">Firefox OS Developer Preview device</a> for you to work with now. </p>
<p>When Firefox OS phones become available to consumers in select locales this summer, you&#8217;ll have an opportunity that only comes around once&#8212;a first-mover advantage in Firefox Marketplace. End users in Latin America, Eastern Europe and other launch locations will be on the lookout for playful and practical apps to install: games, tools, and utilities as well as locally relevant news, sports, travel, entertainment, review apps, and social sharing experiences. And you can build and submit them now! </p>
<h2>Apply now</h2>
<p>Tell us about the Firefox App you&#8217;d like to build or port. If your proposal is accepted, we&#8217;ll send you a Geeksphone Keon. Our device inventory is limited and our launch dates are approaching fast, so act now. This program will close at the end of May or when our limited supply of Geeksphones runs out. There&#8217;s a limit of one phone per app proposal. We can&#8217;t wait to see what you&#8217;re working on. There&#8217;s never been a better time to get started. </p>
<p><a href="http://bit.ly/phones-for-apps" title="Phones for Apps for Firefox OS" target="_blank">Apply here.</a></p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/phones-for-apps-for-firefox-os/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Embedding WebRTC Video Chat Right Into Your Website</title>
		<link>https://hacks.mozilla.org/2013/05/embedding-webrtc-video-chat-right-into-your-website/</link>
		<comments>https://hacks.mozilla.org/2013/05/embedding-webrtc-video-chat-right-into-your-website/#comments</comments>
		<pubDate>Tue, 07 May 2013 13:05:58 +0000</pubDate>
		<dc:creator>Dmitry Dragilev</dc:creator>
				<category><![CDATA[Featured Article]]></category>
		<category><![CDATA[WebRTC]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20647</guid>
		<description><![CDATA[Most of you remember the Hello Chrome, it&#8217;s Firefox calling! blog post right here in Mozilla Hacks demonstrating WebRTC video chat between Firefox and Chrome. It raised a lot of attention. Since then we here at Fresh Tilled Soil have seen a tremendous amount of startups and companies which have sprung up building products based [...]]]></description>
				<content:encoded><![CDATA[<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/webrtc-chat.png" alt="" title=""></p>
<p>Most of you remember the <a href="https://hacks.mozilla.org/2013/02/hello-chrome-its-firefox-calling/">Hello Chrome, it&#8217;s Firefox calling!</a> blog post right here in Mozilla Hacks demonstrating WebRTC video chat between Firefox and Chrome. It raised a lot of attention. Since then we here at Fresh Tilled Soil have seen a tremendous amount of startups and companies which have sprung up building products based WebRTC video chat technology. Tsashi Levent-Levi who is a WebRTC evangelist has been interviewing most of these companies on his blog, the list is <a href="http://bloggeek.me/webrtc-interviews/">quite impressive</a>!</p>
<h2>WebRTC chat demo</h2>
<p>Much like most of early adopters we have been playing around with WebRTC for quite awhile now. We have of course created <a href="http://freshtilledsoil.com/the-future-of-web/webrtc-video/">our own WebRTC video chat demo</a> and have also very recently released WebRTC video chat widgets.</p>
<p><iframe width="500" height="281" src="https://www.youtube.com/embed/sJtz2nee1zA" frameborder="0" allowfullscreen></iframe></p>
<p>The widgets work very simply, anybody can take the following HTML embed code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Begin Fresh Tilled Soil Video Chat Embed Code --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;freshtilledsoil_embed_widget&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;video-chat-widget&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;fts&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://freshtilledsoil.com/embed/webrtc-v5.js?r=FTS0316-CZ6NqG97&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- End Fresh Tilled Soil Video Chat Embed Code --&gt;</span></pre></td></tr></table></div>

<p>and add this code to any website or blog post. You&#8217;ll see the following widget on their website:</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/webrtc-chat-channel-chooser.png" alt="" title=""></p>
<p>From here it&#8217;s dead simple to start a WebRTC video chat, just make up a name for a room, type it in and click start chat. Tell the other person to do the same and you&#8217;re all set. </p>
<p>As always make sure you&#8217;re giving this a try in <a href="http://nightly.mozilla.org/">Firefox Nightly</a> or the latest stable build of <a href="https://www.google.com/intl/en/chrome/browser/">Google Chrome</a>. If you are on a tablet make sure you are on Google Chrome beta if you are using the Google Chrome browser. </p>
<p>Something else to note is that for this first version our video chat is limited to just two participants per a room. If a room name is occupied by two people the third person who tries to connect to this room simply won&#8217;t be able to connect.</p>
<h2>How It Works</h2>
<p>Without getting too deep into the code behind how WebRTC video chat actually works, let&#8217;s briefly go over what is actually happening behind the scenes when you click the start chat button and how WebRTC video chat actually works. Here is a step by step timeline of what actually happens to give you a better idea:</p>
<p><a href="https://hacks.mozilla.org/wp-content/uploads/2013/05/webRTC-BasicsOfHowItWorks2.png"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/05/webRTC-BasicsOfHowItWorks2.png"></a></p>
<p>A quick note about this step: &#8220;Once remote media starts streaming stop adding ICE candidates&#8221; &#8211; this is a temporary solution which might result in suboptimal media routing for many network topologies. It should only be used until Chrome&#8217;s ICE support is fixed. </p>
<p>A quick and very important tip to remember when you are trying to get this to work. We used a &#8216;polyfill&#8217; like technique as shown <a href="http://remysharp.com/2010/10/08/what-is-a-polyfill/">in this article by Remy Sharp.</a> As Remy describes we wrote a piece of code to adapt for the Firefox syntax to get cross-browser functionality. </p>
<h2>Issues We Ran Into and How We Solved Them</h2>
<p>As you might expect we ran into a number of problems and issues trying to build this. WebRTC is evolving quickly so we are working through a number of issues every day. Below are just some of the problems we ran into and how we solved them.</p>
<h3>PeerConnection capability in Google Chrome</h3>
<p>While working with the new PeerConnection capability in Chrome we discovered a strict order of operation for it to work; more specifically:</p>
<ul>
<li>Peers must be present with local streaming video before sending SIP (offer/answer SDP)</li>
<li>For &#8216;Answerer&#8217;; Do not add ICE candidate until the peer generates the &#8216;Answer SDP&#8217;</li>
<li>Once remote media starts streaming stop adding ICE candidates</li>
<li>Never create peer connect for answerer until you get the &#8216;Offer SDP&#8217;</li>
</ul>
<p>We fixed it by handling those issues and handling the connection in the order described above. This was crucial to making the connection work flawlessly. Before we did that it would work only every once in a while. </p>
<h3>Added latency due to lag</h3>
<p>When streaming to a mobile device there is added latency due to lag and limitations of surfing the net via mobile phone.</p>
<p>We solved this by making the resolution of streamed video reduced via a hash tag at the end of the URL. URL can optionally contain <code>'#res=low'</code> for low resolution stream video &amp; <code>'#res=hd'</code> for HiDefinition streaming video as an optional URL parameter. A quick note here that other configurable properties are now available such as frames per second which you can use for this same purpose. </p>
<h3>Recording the WebRTC demo</h3>
<p>We&#8217;ve been dabbling with recording video WebRTC demo. When recording video we used the new JavaScript type arrays to save the streaming data. We quickly discovered that it is only possible to record the video and audio separately.</p>
<p>We solved this by creating two instances of recording, one for the audio and one for the video, that utilized the new javascript data types and recorded both streams simultaneously.</p>
<h2>Conclusion</h2>
<p>It&#8217;s exciting to dabble in this stuff, we love WebRTC so much that we created an entire <a href="http://freshtilledsoil.com/the-future-of-web/">page dedicated to our experiments</a> with this technology and others which we believe will transform the web in 2013. If you have any question please give us a shout.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/embedding-webrtc-video-chat-right-into-your-website/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>How to Spread The Word About Your Code</title>
		<link>https://hacks.mozilla.org/2013/05/how-to-spread-the-word-about-your-code/</link>
		<comments>https://hacks.mozilla.org/2013/05/how-to-spread-the-word-about-your-code/#comments</comments>
		<pubDate>Mon, 06 May 2013 12:58:01 +0000</pubDate>
		<dc:creator>Peter Cooper</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web Developers]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20537</guid>
		<description><![CDATA[You spent an entire weekend building a library, jQuery plugin, build tool, or other great piece of code you wanted to share far and wide, but after some tweets and a failed attempt to make the front page of Hacker News, your creation languished, unloved, in a GitHub repo. A common situation for many developers [...]]]></description>
				<content:encoded><![CDATA[<p>You spent an entire weekend building a library, jQuery plugin, build tool, or other great piece of code you wanted to share far and wide, but after some tweets and a failed attempt to make the front page of <a href="https://news.ycombinator.com/">Hacker News</a>, your creation languished, unloved, in a GitHub repo. A common situation for many developers nowadays, but one you can avoid.</p>
<p>As the editor of several programming newsletters, I frequently get two types of e-mails from developers. Those reaching out to ask if I can mention their projects, and those expressing surprise and excitement that their work has been featured. If you&#8217;re a developer doing good work but feel more like you&#8217;d be in that second group, the three steps in this article are for you.</p>
<p>Before we get started, there&#8217;s a stumbling block we need to kick away. Terms like &#8216;marketing&#8217; and &#8216;advertising&#8217; are dirty words for many developers and it&#8217;s not uncommon for developers to be reluctant to do much promotion. &#8216;Build it and they will come&#8217; used to work when exciting open source projects were few and far between but now everyone seems to be working on something and making a noise about it. Few of the successes you see come through pure luck but because developers are actively promoting their work or, at least, making it <em>discoverable</em>. It&#8217;s time to join them!</p>
<h2>Step 1: Get your project ready</h2>
<p>Before you can promote your project, you need to make it attractive to potential users and evangelists (including general wellwishers, the media, and other developers).</p>
<h3>A good name</h3>
<p>Ensure your project has a palatable name. It doesn&#8217;t need to be clever or even descriptive, but it&#8217;s worth avoiding innuendos that may present a problem down the line. For example, the popular Testacular and Authgasm projects, are now named <a href="https://github.com/karma-runner">Karma</a> and <a href="https://github.com/binarylogic/authlogic">Authlogic</a> respectively after users raised a fuss.</p>
<p>You should perform a search for the name you choose to be sure you&#8217;re not clashing with anything else that&#8217;s popular or trademarked (did you know <a href="http://en.wikipedia.org/wiki/History_of_Firefox#Naming">Firefox was called</a> <em>Phoenix</em> and <em>Firebird</em> prior to <em>Firefox</em>?). The US Patent and Trademark Office <a href="http://tess2.uspto.gov/">has an online trademark search facility</a>.</p>
<p>A benefit of having a relatively unique or uncommon name is so you can search for it over time (or even set up a <a href="http://www.google.co.uk/alerts">Google Alerts</a> notification for the name) and find mentions of your project without many irrelevant results popping up. If you want to have something descriptive but unique, consider joining two words together. For example, when I created a Ruby library to do natural language detection, I called it <em>WhatLanguage</em> and it&#8217;s easy to search for.</p>
<h3>An official homepage or project URL</h3>
<p>The term &#8216;homepage&#8217; is a bit outdated but you ideally need a single &#8216;home&#8217; URL that you can promote and point people to in relation to your project. You don&#8217;t need to splash out on a fancy template or even a domain name, but your project needs a focal point. That could be an entire site with its own domain, such as those for <a href="http://yeoman.io/">Yeoman</a> or <a href="http://html5boilerplate.com/">HTML5 Boilerplate</a>, a simple single page on an existing domain, such as that for <a href="http://ndreckshage.github.io/roughdraft.js/">RoughDraft.js</a>, or even a regular GitHub repo, such as for <a href="https://github.com/GianlucaGuarini/vague.js">vague.js</a>.</p>
<p>If you have the freedom to do so, make sure your site looks good on the major browsers (including mobile), hook up some analytics to your page and ensure the &lt;title&gt; tag is well written. Use a title like <em>&#8220;MyProject &#8211; A JavaScript Library to X, Y and Z&#8221;</em> instead of just <em>&#8220;MyProject &#8211; About&#8221;</em> or a blank title. With social bookmarking, this matters as you can&#8217;t guarantee your evangelists will write a good title of their own.</p>
<p>If you&#8217;re not a Web designer, don&#8217;t have the time to spend making a complete design, but still want a complete site rather than just a GitHub repo and README, consider using a framework like <a href="http://twitter.github.io/bootstrap/">Bootstrap</a> as it&#8217;ll provide a clean layout out of the box and you can forget about many cross browser and device issues.</p>
<h3>Documentation and copywriting</h3>
<p>It&#8217;s only <em>just</em> a cliché that developers don&#8217;t like to write documentation, but you need <em>something</em> for potential users to fall back on, and time invested in producing useful documentation up front will pay dividends later.</p>
<p>At a cynically bare minimum, you need to write enough documentation that someone will be confident about sharing your link or promoting your project and not feel like they&#8217;re sending their own followers into a black hole of misunderstanding. This means your homepage or README needs to cover a few angles. You&#8217;ll need to:</p>
<ul>
<li>
<p><strong>Prominently feature a &#8220;[noun] is&#8221; paragraph.</strong> An alarming number of project homepages don&#8217;t explain, in simple terms, what the project is actually for or does. If you&#8217;ve built a JavaScript library that does language detection, say, you have to say so. For example: <em>&#8220;LanguageDetect is a JavaScript library for detecting the natural language of text.&#8221;</em></p>
<p>An excellent example of this in action is on <a href="http://libcinder.org/">libcinder.org</a> where it states right up front: <em>&#8220;Cinder is a community-developed, free and open source library for professional-quality creative coding in C++.&#8221;</em> Perfect!</li>
<li>
<p><strong>Write clear titles, subheadings, and support copy.</strong> At a bare minimum, ensure titles, subtitles, and <em>any</em> sort of writing on your homepage are straightforward and clear. Write for the lowest common denominator on your homepage. You can get more advanced elsewhere.</p>
</li>
<li>
<p><strong>Write a beginner&#8217;s tutorial and link to it from your home page.</strong> Unless everything&#8217;s simple enough to explain on a single page, quickly write a tutorial that covers basic installation and usage and either include it in your README file or put it on the Web and link to it from your README and/or homepage.</p>
</li>
<li>
<p><strong>State dependencies and requirements clearly.</strong> Does your library only work on a specific version of Node? Is it a browser extension for Firefox? Does your code require PostgreSQL, Redis, or another specific database? Be sure to include a bulletpoint list of dependencies and requirements for your project to be usable so as not to disappoint potential users.</p>
</li>
<li>
<p><strong>Specify the license for your code.</strong> While you <em>could</em> get away with keeping your licensing information tucked away in a LICENSE file in your GitHub repo, specifying what license your code is released under up front and center will help put many developers at ease. Likewise, if your project is commercial is nature and costs money, don&#8217;t hide that detail away and mislead visitors.</p>
</li>
<li>
<p><strong>If your project is a library or API, feature some example code on the homepage.</strong> Unless your library is particularly complex, let visitors see an example of its usage on the project homepage. If your API is good, this could be a great way to get an &#8216;easy sale.&#8217; I&#8217;m not a huge fan of the code example chosen but the <a href="http://www.ruby-lang.org/en/">homepage for Ruby</a> shows off this technique.</p>
</li>
</ul>
<h3>Extra materials</h3>
<p>A blog post is a great way to introduce a project that might need more background or have more of a story than it&#8217;s practical to tell on a homepage or within documentation. If there&#8217;s any sort of story behind your project, a blog post is a great way to tell it. Be sure to link to the post from your project&#8217;s homepage and consider promoting the blog post separately to relevant sites within your niche.</p>
<p>If you have the ability, recording a screencast or other sort of video can help. Could you put together a simple 5 minute screencast of how to install and use your library? Or have you built a game that could be demonstrated in a few minutes of gameplay? Record a simple video, put it on YouTube, and embed it on your homepage. Your accent <em>doesn&#8217;t</em> have to be as crisp as a newsreader&#8217;s and you don&#8217;t even have to appear within the video. All that matters is you get to the point quickly and your audio is tolerable (not muffled, clipping, or drowned in background music).</p>
<p>As the editor of several programming newsletters, I look at thousands of projects each year, and it&#8217;s still uncommon to see simple screencasts, yet they certainly help a project stand out and, as a consequence, make it more likely for me to talk about it. You can see a perfect example on <a href="http://laktek.github.io/punch/">Punch&#8217;s homepage</a>. The early popularity of Ruby on Rails also depended upon a popular &#8216;build a blog engine in 15 minutes&#8217; video, back when the concept of using video to promote an open source project was very novel.</p>
<p>If you&#8217;re sticking to the straight up, GitHub README approach (and it&#8217;s certainly not a bad idea for a simple library), a bonus tip is to create a tiny screencast of your code in action and convert it to an animated GIF for inclusion in your README. Richard Schneeman outlines this technique in <a href="http://schneems.com/post/41104255619/use-gifs-in-your-pull-request-for-good-not-evil">Use GIFs in your Pull Request for Good, not Evil</a>. The result is striking and could help your README stand out.</p>
<p>For further ideas on how to make your project stand out before you begin promoting it, check out the great <a href="http://blog.clojurewerkz.org/blog/2013/04/20/how-to-make-your-open-source-project-really-awesome/">How to Make Your Open Source Project Really Awesome</a> by Michael Klishin. It digs into more detail about versioning, announcements, having a changelog and writing good documentation.</p>
<h2>Step 2: Get the word out</h2>
<p>You&#8217;ve polished your project, got a URL to promote, and you&#8217;re ready to get the news out.</p>
<p>A word of caution, however. Don&#8217;t use every technique on day one. You could overload your site with traffic or, worse, be subjected to a barrage of online criticism if your work or site is broken. With something like a library or tool, a gentler approach will work well and building up small streams of visitors and users over time will give you a much better time.</p>
<h3>Social networking</h3>
<p>Your own social networking profiles are always a good place to start if you have them. You&#8217;ll get more immediate feedback from people who actually know you and if your project is particularly interesting, it could go viral even from a single mention.</p>
<p>A great example of a simple project going viral was <a href="http://en.wikipedia.org/wiki/YouTube_Instant">YouTube Instant</a> by Feross Aboukhadijeh. Feross built YouTube Instant quickly, mentioned it on Facebook before going to bed, and <a href="https://github.com/feross/feross.org/blob/master/_posts/2010-09-11-youtube-instant-media-frenzy.md">woke up to a flood</a> of traffic and press mentions.</p>
<p>If you like to experiment and have several bucks going spare, you could also consider paying for a <a href="https://www.facebook.com/help/promote">promoted post</a> on Facebook. This will give your post more visibility in your news feed, but is best reserved for if your Facebook friends are mostly developers or people likely to be interested in your project. If not, and you&#8217;d still like to spend some money, consider an ad on Reddit or a relevant programming blog instead.</p>
<h3>Influencers, bloggers, and niche media</h3>
<p>Whether you&#8217;re working on a JavaScript library, Firefox extension, backend app in Rails, or a theme for Bootstrap, your code will fit into one or more niches and every technical niche has a variety of &#8216;influencers&#8217;, people and publications who are popular and well known for the topic at hand.</p>
<p>Getting a tweet, retweet, or even an entire blog post from an influencer could have a significant impact on your project, as could being invited to blog elsewhere (Mozilla Hacks, for example!). If Brendan Eich tweeted about your JavaScript library, Lea Verou wrote a blog post about a CSS trick you discovered, or Paul Irish mentioned a Web development tool you built in a talk, you would attract a lot of interest quickly. It is key, however, to realize there are many great influencers in every space and you&#8217;ll achieve nothing by hounding any one person so be prepared to move on.</p>
<p>Spend some time working out who the influencers and key publications are in your niche. For Twitter, <a href="http://followerwonk.com/bio/">Followerwonk</a> is a handy tool that searches Twitter biographies for certain words. If you search for <em>&#8220;javascript&#8221;</em> the first page includes several users who would be useful to reach out to if you had a particularly interesting JavaScript-related release to promote. Reaching out on Twitter can be as simple as a single tweet and many busy folks prefer Twitter as it takes less time to reply than an e-mail. A single tweet from <a href="https://twitter.com/smashingmag">@smashingmag</a> could drive thousands of visitors your way, so consider tweeting them, and other similar accounts, when you have something relevant.</p>
<p>I&#8217;d also advise looking for blogs and e-mail newsletters in your niche. Start with something as simple as Googling for <em>&#8220;javascript blog&#8221;</em>, <em>&#8220;javascript newsletter&#8221;</em>, <em>&#8220;css blog&#8221;</em> or whatever&#8217;s relevant to your project. Most bloggers or e-mail newsletter publishers will not be offended by you sending them a quick note (emphasis on <em>quick</em>) letting them know about your work. Indeed, some weeks there can be a shortage of interesting things to write about and you might be doing them a huge favor.</p>
<p>If you choose to e-mail people (and your project will probably be more substantial than a few hours&#8217; work to justify this), take care not to make demands or to even expect a reply. Many bloggers and influential people have overflowing inboxes and struggle to reply to everything they receive. Make your e-mail as easy to process as possible by including a single URL (to your now superb homepage or README) and include your <em>&#8220;[noun] is&#8221;</em> paragraph. Don&#8217;t take a non-response as an insult but keep moving on to the next most relevant person. You might even consider taking a <em>&#8220;Here&#8217;s my project that does X, Y and Z. No reply needed, I just thought you might like it&#8221;</em> approach. Softly, softly works here, as long as you get to the point quickly.</p>
<p><a href="http://blog.asmartbear.com/email-pick-brain.html">How to get attention from internet celebrities</a> by Jason Cohen and <a href="http://www.sparringmind.com/perfect-email/">How to Write the Perfect Outreach Email</a> by Gregory Ciotti go into more detail about e-mail etiquette when promoting your work to influencers. While you might not need to contact any &#8216;celebrities&#8217; in your niche, the principles of keeping it short, including a call to action, and ensuring your work is appropriate to the person are really true for anyone you&#8217;re sending unsolicited messages to.</p>
<p>Podcasters are an often forgotten source of promotion opportunities too. While some podcasts don&#8217;t cover news or new releases at all, many do, and being on the radar of their hosts could help you get a mention on a show. Smashing Magazine has <a href="http://www.smashingmagazine.com/2013/04/19/podcasts-for-designers-developers/">put together a list of tech podcasts</a> covering the areas of design, user experience, and Web development in general. Again, keep your e-mails short and sweet with no sense of expectation to get the best results.</p>
<h3>User curated social news sites</h3>
<p>As well as reaching influencers and niche media, sometimes reaching the public &#8216;firehose&#8217; of news can work too, and there are few better examples of these in the modern world of development than <a href="https://news.ycombinator.com/">Hacker News</a> or <a href="http://www.reddit.com/">Reddit</a>.</p>
<p>Hacker News in particular is notoriously hard to reach the front page on and &#8216;gaming&#8217; it by getting other people to vote up your post can backfire. (Indeed, it will backfire if you link people to your post on Hacker News and encourage them to upvote. They have ways of detecting this behavior. Get people to manually find your post instead.) If you do reach the front page of Hacker News, of course, you can certainly expect an audience of many thousands of developers to be exposed to your work, so be sure to try.</p>
<p>With Reddit, the key isn&#8217;t to dive straight into a huge sub-Reddit like <a href="http://www.reddit.com/r/programming">/r/programming</a> but to look for sub-Reddits more directly related to your project. For a JavaScript library, I&#8217;d post to <a href="http://www.reddit.com/r/javascript">/r/javascript</a> or possibly <a href="http://www.reddit.com/r/webdev">/r/webdev</a>. Reddit ads can also perform well if you&#8217;re OK with spending some money and these can be targeted to specific sub-Reddits too.</p>
<p>There are many similar sites that are less well known but which are respected in their niches and can drive a lot of interested visitors, including <a href="https://news.layervault.com/stories">Designer News</a> (mobile and Web design), <a href="http://www.dzone.com/">DZone</a> (general developer stuff), <a href="http://www.echojs.com/">EchoJS</a> (JavaScript), <a href="http://rubyflow.com/">RubyFlow</a> (Ruby and Rails), and <a href="https://lobste.rs/">Lobste.rs</a> (general hacker and developer stuff). Finding the right site like this and taking time to make an on-topic, well written post will help a lot.</p>
<h3>The mass media / press</h3>
<p>This article is primarily focused on the promotion of open source and front-end projects and these are typically not frequently covered in print or on the TV or radio. If, however, you think the mass media <em>would</em> be relevant for your project, here are some other articles packed with handy tips:</p>
<ul>
<li><a href="http://www.shopify.com/blog/4404772-how-to-pr-like-a-pro-a-guide-to-getting-media-attention">How to PR Like a Pro: A Guide to Getting Media Attention</a></li>
<li><a href="http://onstartups.com/tabid/3339/bid/80121/How-To-Get-Media-Coverage-For-Your-Startup-A-Complete-Guide.aspx">How To Get Media Coverage For Your Startup: A Complete Guide</a></li>
<li><a href="http://www.shoemoney.com/2010/09/14/getting-press-for-your-website-application-or-service">Getting Press for Your Website, Application, or Service</a></li>
<li><a href="http://socialtriggers.com/get-press-with-no-connections/">How to Get Major Media Coverage For Your Business with No Connections</a></li>
<li><a href="http://www.pixelprospector.com/how-to-contact-press/">How to Contact Press (And Increase Changes To Get Press Coverage)</a> (oriented around promoting indie games but the essentials are there)</li>
</ul>
<h2>Step 3: Maintain momentum</h2>
<p>You&#8217;ve built up some interest, your GitHub stars, Reddit votes, and pageviews are all rocketing up, but now you want to capitalize on the attention and maintain some momentum.</p>
<h3>User support</h3>
<p>Whether you&#8217;ve built an open source project or a cool tool, you&#8217;re going to end up with users or fellow developers who want to provide feedback, get help, or point out issues with your work. On GitHub, the common way to do this is through the built-in &#8216;issues&#8217; tracker, but you might also find people start to e-mail you too.</p>
<p>Be sure to define a policy, whatever it is. Users won&#8217;t feel good about opening issues on your GitHub repo if there are already many unresolved issues there and your project could stagnate. Ensure you respond to your audience or at least make your policy clear within your README or on your site. If you don&#8217;t want issues raised or code contributions, make this clear up front.</p>
<h3>Extending your reach</h3>
<p>For many projects, create a dedicated Twitter account, blog, Facebook page, or Google+ page in advance is overkill, but if your project starts to take off, consider these things. They&#8217;ll provide an extra way not only for users to remain in touch with your project but also a way for them to help promote it by retweeting things you post or by directing potential new users your way.</p>
<p>You can also extend your reach in person by going to user groups and conferences and, if you&#8217;re really lucky, you can speak about your work too. This is a great way to get new users as people are much more likely to look into your work if they&#8217;ve met you in person.</p>
<h3>Avoid being defensive</h3>
<p>If your project does well on sites like Hacker News or Reddit, you&#8217;ll be tempted to read all of the comments your peers leave, but be careful. Comments about your work will, naturally, seem magnified in their intensity and critical comments that might not actually be mean spirited may seem as if they are to you.</p>
<p>It&#8217;s hard, but the best policy is to not let any overtly mean comments get to you, duly correct any observations that are wrong, and to thank anyone who goes out of their way to compliment your work. Even if you&#8217;re in the right, with the lack of body language and verbal cues, being too defensive can look bad online and result in the post becoming a lightning rod for drama. Engage as best you can, but if it feels wrong to reply to something, listen to your gut.</p>
<p>Be careful if you go into a new community to promote your work and get negative feedback. Most communities have rules or expectations and merely entering a community to promote your work is frequently considered a <em>faux pas.</em> Be sensitive to people&#8217;s environments and try to abide by a community&#8217;s rules at all times.</p>
<h3>The long term</h3>
<p>If your project does particularly well, you could be presented with the opportunity of turning it into a business in its own right. Many simple open source projects, often started by a single developer, have turned into long term work or even entire companies for their creators.</p>
<p>Back in 2010, Mitchell Hashimoto released <a href="http://www.vagrantup.com/">Vagrant</a>, a Ruby-based tool for building a deploying VirtualBox-based virtualized development environments. In late 2012, Mitchell launched <a href="http://techcrunch.com/2012/11/28/vagrant-founder-launches-hashicorp-to-support-his-open-source-developer-management-tool/">Hashicorp</a>, a company providing Vagrant consulting services to enterprise customers. An even higher profile example is <a href="http://en.wikipedia.org/wiki/Puppet_Labs">Puppet Labs</a>, a company built around the Puppet open-source configuration management tool and which has taken total funding of $45.5 million so far.</p>
<p>If your project becomes respected and heavily used within its field, you might also be approached to write a book or article about it or even speak at a conference. This is a good sign that your project has &#8216;made it&#8217; to some extent as publishers and event organizers are in the business of working out what it makes business sense to present.</p>
<h2>Putting it all together: A checklist</h2>
<p>This has only been a basic introduction to promoting your work and with practice you&#8217;ll come up with tons of tips of your own (it&#8217;d be excellent if you could share some in the comments here). Based on all of the ideas above, here&#8217;s a basic checklist to run through next time you release a new project and want to get some added exposure:</p>
<ul>
<li>Focus most of your efforts on your project&#8217;s homepage or README.</li>
<li>Check your project&#8217;s name doesn&#8217;t clash with anything else and is unique enough to find references to your work later.</li>
<li>Promote your work to your closest social group first to unbury any problems with your work.</li>
<li>Record a screencast or write a blog post about your project if some extra background would be useful for others.</li>
<li>Work out a perfect *&#8221;[project name] is&#8221;* sentence to describe what your project is or does.</li>
<li>Use your *&#8221;[project name] is&#8221;* sentence to give your page a descriptive title.</li>
<li>Find influential people, blogs, podcasts, and e-mail newsletters in your niche and send them a short, pleasant note.</li>
<li>Post to social news and bookmarking sites. Ensure your title is descriptive.</li>
<li>Use your *&#8221;[project name] is&#8221;* sentence in e-mails and contacts with influencers.</li>
<li>Take a positive, &#8220;look on the good side&#8221; approach to responding to comments about your work.</li>
</ul>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/how-to-spread-the-word-about-your-code/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Firefox OS Simulator 3.0 released</title>
		<link>https://hacks.mozilla.org/2013/05/firefox-os-simulator-3-0-released/</link>
		<comments>https://hacks.mozilla.org/2013/05/firefox-os-simulator-3-0-released/#comments</comments>
		<pubDate>Thu, 02 May 2013 17:31:54 +0000</pubDate>
		<dc:creator>Robert Nyman [Editor]</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Featured Article]]></category>
		<category><![CDATA[Firefox OS]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20622</guid>
		<description><![CDATA[About 6 weeks ago, we wrote about the preview of Firefox OS Simulator 3.0 and now we&#8217;re happy to release it! New features In our preview coverage, we listed the new features for this version: Push to Device Rotation simulation Basic geolocation API simulation Manifest validation Stability fixes for installation and updates to apps Newer [...]]]></description>
				<content:encoded><![CDATA[<p>About 6 weeks ago, we wrote about the <a href="https://hacks.mozilla.org/2013/03/firefox-os-simulator-previewing-version-3-0/">preview of Firefox OS Simulator 3.0</a> and now we&#8217;re happy to release it!</p>
<p><a href="https://hacks.mozilla.org/wp-content/uploads/2013/04/Simulator-overview.png"><img src="https://hacks.mozilla.org/wp-content/uploads/2013/04/Simulator-overview-500.png" alt="" title="" /></a></p>
<h2>New features</h2>
<p>In our preview coverage, we listed the new features for this version:</p>
<ul>
<li>Push to Device</li>
<li>Rotation simulation</li>
<li>Basic geolocation API simulation</li>
<li>Manifest validation</li>
<li>Stability fixes for installation and updates to apps</li>
<li>Newer versions of the Firefox rendering engine and Gaia (the UI for Firefox OS)</li>
</ul>
<p>Since then, apart from verifying and making the above functionality stable, other notable improvements are:</p>
<ul>
<li>Keyboard shortcut to repackage/reinstall/restart the current app &#8211; drastically improving workflow speed, especially for packaged apps</li>
<li>Significantly reduced download/installation size of the Firefox OS Simulator</li>
<li>Faster start time (partly due to above with smaller size)</li>
<li>Much newer versions of Firefox OS and Gaia</li>
<li>General bug fixes, making it more functional and reliable</li>
<li>OS-standard ways in the menu to close the Simulator, with corresponding keyboard shortcuts (Alt + F4 on Windows, Cmd + Q on Mac, Ctrl + Q on Linux)</li>
</ul>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/04/Simulator-refresh.png" alt="" title="" /></p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/04/Simulator-quit.png" alt="" title="" /></p>
<h2>Firefox OS Simulator documentation</h2>
<p>As part of this release, we&#8217;d also like to highlight our updated <a href="https://developer.mozilla.org/en-US/docs/Tools/Firefox_OS_Simulator">Firefox OS Simulator documentation on MDN</a> and also our <a href="https://developer.mozilla.org/en-US/docs/Tools/Firefox_OS_Simulator/Simulator_Walkthrough">Firefox OS Simulator walkthrough example</a>.</p>
<p><img src="https://hacks.mozilla.org/wp-content/uploads/2013/04/Simulator-manifest-error-expanded.png" alt="" title="" /></p>
<h2>Download/install the Firefox OS Simulator</h2>
<p>You can <a href="https://addons.mozilla.org/en-US/firefox/addon/firefox-os-simulator/">download version 3.0 of the Firefox OS Simulator from our add-ons web site</a>.</p>
<p>Please let us know what you think in the comments! If you encounter any bugs or problems, please <a href="https://github.com/mozilla/r2d2b2g/issues">file a bug</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/firefox-os-simulator-3-0-released/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Announcing the winners of the March 2013 Dev Derby!</title>
		<link>https://hacks.mozilla.org/2013/05/announcing-the-winners-of-the-march-2013-dev-derby/</link>
		<comments>https://hacks.mozilla.org/2013/05/announcing-the-winners-of-the-march-2013-dev-derby/#comments</comments>
		<pubDate>Wed, 01 May 2013 15:41:41 +0000</pubDate>
		<dc:creator>John Karahalis</dc:creator>
				<category><![CDATA[Dev Derby]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">https://hacks.mozilla.org/?p=20634</guid>
		<description><![CDATA[This past March, some of the most creative web developers out there showed us what they could do for the mobile Web in the March Dev Derby contest. After looking through the entries, our our three expert judges–Craig Cook, Franck Lecollinet, and Guillaume Lecollinet–decided on three winners and two runners-up. Not a contestant? There are [...]]]></description>
				<content:encoded><![CDATA[<p>This past March, some of the most creative web developers out there showed us what they could do for the mobile Web in the <a href="https://developer.mozilla.org/demos/devderby/2013/march">March Dev Derby</a> contest. After looking through the entries, our our <a href="https://developer.mozilla.org/demos/devderby#tab-judging">three expert judges</a>–Craig Cook, Franck Lecollinet, and Guillaume Lecollinet–decided on three winners and two runners-up.</p>
<p>Not a contestant? There are other reasons to be excited. Most importantly, all of these demos are completely open-source, making them wonderful lessons in the exciting mobile experiences you can create today using only the skills you already have.</p>
<p><img class="aligncenter size-full wp-image-8841" alt="Dev Derby" src="https://hacks.mozilla.org/wp-content/uploads/2011/07/logo-devderby.png" width="335" height="96" /></p>
<h2>The Results</h2>
<h3>Winners</h3>
<ul>
<li>First place: <a href="https://developer.mozilla.org/demos/detail/memory-cube">Memory Cube</a> by sophomore <a href="https://developer.mozilla.org/profiles/tx2z">Jesus Perez</a></li>
<li>Second place: <a href="https://developer.mozilla.org/demos/detail/writerrific">Writerrific</a> by designer and developer <a href="https://developer.mozilla.org/profiles/laurensdebackere">Laurens Debackere</a></li>
<li>Third place: <a href="https://developer.mozilla.org/demos/detail/loc-tag">Loc Tag</a> by newcomer <a href="https://developer.mozilla.org/profiles/bzub">bzub</a></li>
</ul>
<h3>Runners-up</h3>
<ul>
<li><a href="https://developer.mozilla.org/demos/detail/paint-my-dash">Paint my dash</a> by mobile Web lover <a href="https://developer.mozilla.org/profiles/Gioyik">Giovanny Andrés Góngora Granada</a></li>
<li><a href="https://developer.mozilla.org/demos/detail/ubercalc">Ubercalc</a> by the always impressive <a href="https://developer.mozilla.org/profiles/JoanC">JoanC</a></li>
</ul>
<p>The March Derby saw some great entries, from games to productivity applications to wonderfully useful location-based services and more. Please join me in congratulating these winners and <a href="https://developer.mozilla.org/demos/devderby/2013/march">all of our contributors</a> for making the wireless world a better and more exciting place.</p>
<p><em>Want to get a head start on an upcoming Derby? We are now accepting demos related to <a href="https://developer.mozilla.org/docs/WebRTC/navigator.getUserMedia">getUserMedia</a> (May) and <a href="https://developer.mozilla.org/docs/WebGL">WebGL</a> (June). Head over to the <a href="https://developer.mozilla.org/demos/devderby">Dev Derby</a> to get started.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://hacks.mozilla.org/2013/05/announcing-the-winners-of-the-march-2013-dev-derby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
