<?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>Guillermo Rauch&#039;s Devthought &#187; javascript</title>
	<atom:link href="http://www.devthought.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devthought.com</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 16:38:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JSConf 2010 Slides</title>
		<link>http://www.devthought.com/2010/05/03/jsconf-2010-slides/</link>
		<comments>http://www.devthought.com/2010/05/03/jsconf-2010-slides/#comments</comments>
		<pubDate>Mon, 03 May 2010 13:07:08 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Client side]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsconf]]></category>

		<guid isPermaLink="false">http://devthought.com/?p=1144</guid>
		<description><![CDATA[For those of us who didn&#8217;t make it, I&#8217;ve compiled a list of slides + blog posts from the JSConf 2010 Track A speakers Alex Russell &#8211; &#8220;Google Chrome Frame&#8221; Post: http://alex.dojotoolkit.org/ Slides: http://alex.dojotoolkit.org/10/jsconf/gcf.html Francisco Tolmasky &#8211; &#8220;Socratic: Documentation Done &#8230; <a href="http://www.devthought.com/2010/05/03/jsconf-2010-slides/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For those of us who didn&#8217;t make it, I&#8217;ve compiled a list of slides + blog posts from the JSConf 2010 Track A speakers</p>
<p><strong>Alex Russell &#8211; &#8220;Google Chrome Frame&#8221;</strong><br />
Post: <a href="http://alex.dojotoolkit.org/">http://alex.dojotoolkit.org/</a><br />
Slides: <a href="http://alex.dojotoolkit.org/10/jsconf/gcf.html">http://alex.dojotoolkit.org/10/jsconf/gcf.html</a></p>
<p><strong>Francisco Tolmasky &#8211; &#8220;Socratic: Documentation Done Right&#8221;</strong><br />
GitHub: <a href="http://github.com/tolmasky/socratic">http://github.com/tolmasky/socratic</a><br />
Slides: ?</p>
<p><strong>Aaron Newton &#8211; &#8220;Programming To Patterns&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/guest2ee5e2c/programming-to-patterns-presentation">http://www.slideshare.net/guest2ee5e2c/programming-to-patterns-presentation</a> (not up-to-date)</p>
<p><strong>Jed Schmidt &#8211; &#8220;A (fab) approach to web apps&#8221;</strong><br />
GitHub: <a href="http://github.com/jed/fab">http://github.com/jed/fab</a><br />
Slides: <a href="http://www.flickr.com/photos/tr4nslator/sets/72157623883700702/show/">http://www.flickr.com/photos/tr4nslator/sets/72157623883700702/show/</a></p>
<p><strong>Dmitry Baranovskiy &#8211; &#8220;Raphaël the Great&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/Dmitry.Baranovskiy/raphal-js-conf">http://www.slideshare.net/Dmitry.Baranovskiy/raphal-js-conf</a></p>
<p><strong>Douglas Crockford &#8211; &#8220;Really, JavaScript?&#8221;</strong><br />
?</p>
<p><strong>Tobias Schneider &#8211; &#8220;Flash is dead, long live Flash!&#8221;</strong><br />
GitHub: <a href="http://github.com/tobeytailor/gordon">http://github.com/tobeytailor/gordon</a><br />
Slides: <a href="http://www.slideshare.net/ConfEcho/flash-is-dead-long-live-flash">http://www.slideshare.net/ConfEcho/flash-is-dead-long-live-flash</a></p>
<p><strong>Makinde Adeagbo &#8211; &#8220;Primer: Facebook&#8217;s 2k of JavaScript to power (almost) all interactions&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/makinde/javascript-primer">http://www.slideshare.net/makinde/javascript-primer</a></p>
<p><strong>Steve Souders &#8211; &#8220;The Best of Steve&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/souders/jsconf-us-2010">http://www.slideshare.net/souders/jsconf-us-2010</a></p>
<p><strong>Jenn Lukas &#8211; &#8220;JavaScript and Web Standards Sitting in a Tree&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/JennLukas/javascript-and-web-standards-sitting-in-a-tree">http://www.slideshare.net/JennLukas/javascript-and-web-standards-sitting-in-a-tree</a></p>
<p><strong>Ryan Dahl &#8211; &#8220;Less is More in Node.js&#8221;</strong><br />
Slides: <a href="http://nodejs.org/jsconf2010.pdf">http://nodejs.org/jsconf2010.pdf</a></p>
<p><strong>Billy Hoffman &#8211; &#8220;JavaScript&#8217;s Evil Side&#8221;</strong><br />
Slides: ?</p>
<p><strong>John David Dalton &#8211; &#8220;All you can leet&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/johndaviddalton/jsconf-all-you-can-leet">http://www.slideshare.net/johndaviddalton/jsconf-all-you-can-leet</a></p>
<p><strong>Aaron Quint &#8211; &#8220;Making Bacon / Making Code&#8221;</strong><br />
GitHub: <a href="http://github.com/quirkey/sammy">http://github.com/quirkey/sammy</a><br />
Post: <a href="http://www.quirkey.com/blog/2010/04/20/making-baconmaking-code-jsconf-2010/">http://www.quirkey.com/blog/2010/04/20/making-baconmaking-code-jsconf-2010/</a><br />
Slides: <a href="http://swinger.quirkey.com/#/preso/aq-jsconf/display/1">http://swinger.quirkey.com/#/preso/aq-jsconf/display/1</a><br />
Video: <a href="http://bit.ly/9j7u3L">http://bit.ly/9j7u3L</a></p>
<p><strong>Dion Almaer, Ben Galbraith, and Matt McNulty &#8211; &#8220;The mobile web&#8221;</strong><br />
Slides: <a href="http://www.slideshare.net/dion/the-mobile-web-2010-jsconf">http://www.slideshare.net/dion/the-mobile-web-2010-jsconf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2010/05/03/jsconf-2010-slides/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Node.JS and the WebSocket protocol</title>
		<link>http://www.devthought.com/2009/12/06/nodejs-and-the-websocket-protocol/</link>
		<comments>http://www.devthought.com/2009/12/06/nodejs-and-the-websocket-protocol/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 09:00:18 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[comet]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://devthought.com/?p=1091</guid>
		<description><![CDATA[After reading Simon Willison&#8217;s post on Node.JS, I decided I&#8217;d give it a try myself. Today I released node.websocket.js After a couple of months I&#8217;ve been watching the progress on the WebSocket protocol, which gives JavaScript developers full-duplex communications channels &#8230; <a href="http://www.devthought.com/2009/12/06/nodejs-and-the-websocket-protocol/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After reading <a href="http://simonwillison.net/2009/Nov/23/node/">Simon Willison&#8217;s</a> post on Node.JS, I decided I&#8217;d give it a try myself. Today I released <a href="http://github.com/guille/node.websocket.js/">node.websocket.js</a></p>
<p>After a couple of months I&#8217;ve been watching the progress on the <a href="http://tools.ietf.org/pdf/draft-hixie-thewebsocketprotocol-60.pdf">WebSocket protocol</a>, which gives JavaScript developers full-duplex communications channels in the browser. This is a very exciting alternative to the COMET techniques we&#8217;re used to seeing.</p>
<p>Node.JS is a framework for networked, event-driven applications, where JavaScript has a natural fit. This particular implementation is built on top of the excellent <a href="http://code.google.com/p/v8/">V8 engine</a>.</p>
<p>Running the server is as simple as:</p>
<pre class='highlight ' lang="JavaScript">
$ node runserver.js
</pre>
<p><span id="more-1091"></span></p>
<p>Logging (in the Redis storage, an excellent persistent key-value storage mechanism which will be subject of another post) will begin.<br />
Writing a client is equally easy:</p>
<pre class='highlight ' lang="JavaScript">
var a = new WebSocket();
a.onmessage = function(event){
   console.log(event.data);
};
</pre>
<p>As you might know or induce already, the wonder of WebSocket is only available to a few selected browsers. To my knowledge only nightly Webkit, Chromium, trunk Firefox (and possibly Opera) have a decent degree of support of WebSocket.</p>
<p>The bigger goal of this project is to provide an API that allows fallback on techniques such as XHR streaming, long-polling, forever iframe (+htmlfile), for cross-browser support and rapid development. Writing the server side modules for node.websocket.js is really pretty easy thanks to the excellent <a href="http://nodejs.org/api.html#_modules">modules API</a> Node.JS provides. And a bunch of projects that allow you to plug in Node.JS to a variety of data sources<a href="http://wiki.github.com/ry/node"> are already available</a>.</p>
<p>Alexander Teinum also has a <a href="http://github.com/alexanderte/websocket-server-node.js">very minimal</a> implementation meant for local use, with which he&#8217;s empowering tools of the impressive <a href="http://www.brevityos.org/">BrevityOS</a> project. Other implementations include <a href="http://blogs.webtide.com/gregw/entry/jetty_websocket_server">Jetty&#8217;s</a> and <a href="http://kaazing.com">Kaazing</a>, both worth keeping an eye on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2009/12/06/nodejs-and-the-websocket-protocol/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Don&#039;t repeat your moo</title>
		<link>http://www.devthought.com/2009/03/02/dont-repeat-your-moo/</link>
		<comments>http://www.devthought.com/2009/03/02/dont-repeat-your-moo/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 14:25:22 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Client side]]></category>
		<category><![CDATA[dry]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://devthought.com/?p=390</guid>
		<description><![CDATA[Given the Object-Oriented nature of the MooTools framework, code repetition is something that is long forgotten (or should be) in the scripts your write. With the avoidance of code repetition comes code reusability, which results in your website being easier &#8230; <a href="http://www.devthought.com/2009/03/02/dont-repeat-your-moo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Given the Object-Oriented nature of the MooTools framework, code repetition is something that is long forgotten (or should be) in the scripts your write. With the avoidance of code repetition comes code reusability, which results in your website being easier to read, extend and maintain, and your scripts smaller in size.</p>
<p>At this point there&#8217;s no doubt in anyone&#8217;s mind that <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a> is a principle we should stick to. However, let&#8217;s examine how to achieve this in the right way.</p>
<p><span id="more-390"></span></p>
<h3>Natives extension</h3>
<p>A script, no matter its purpose, deals with various native objects all the time. These may be native types, such as Strings, Arrays, Objects, Numbers, or objects that are not native to the language but are to the browser rendering engine, such as HTMLElement.</p>
<p>MooTools, as you already know, empowers us to extend these Natives really easily. To add a <strong>repeat()</strong> method to a String, this is all it takes:</p>
<pre class='highlight ' lang="javascript">
String.implement({
	repeat: function(times){
		return new Array(times + 1).join(this);
	}
});
</pre>
<p>This is one of the pillars of code reusability within MooTools code. But, as I&#8217;ll explain later, it can be misused.</p>
<h3>Self-invoking functions</h3>
<p>Probably the most natural and straightforward way of avoiding code repetition is defining a function. The code above could have been written as:</p>
<pre class='highlight ' lang="javascript">
function repeat(str, times){
	return new Array(times +1).join(str);
}
</pre>
<p>A downside of the snippet above is the pollution of the global namespace. The function <em>repeat</em> would be available to all your scripts within the window you execute it in, potentially colliding with other functions. Or making it harder to maintain when another programmer comes along and writes another <em>repeat</em> function, which may even do something different.</p>
<p>That&#8217;s when self-invoking functions come to the rescue. As you already know, the local variables defined within a function are only available to that context. If you decide to use functions instead of extending a native, this is the smart way to do it:</p>
<pre class='highlight ' lang="javascript">
// we wrap our code in a self-invoking function
(function(){

   // local function within this context
   var repeat(str,times) = function(){
   	// ...
   });

   // notice we don't use var here, we want the Car class to be globally available
   Car = new Class({

      run: function() {
          var a = repeat('test', 20);
      }

   });

   ConvertibleCar = new Class({

      Extends: Car,

      display: function() {
          var b = repeat('some string', 20);
      }

   });

})();

// the repeat() we defined before is no longer accessible here
</pre>
<h3>When to use which method</h3>
<p>First of all, you might be wondering why you&#8217;d go through the trouble of defining a function within a sub-context if you could have extended String in the first place. That&#8217;s valid reasoning, but only because of the nature of the example.</p>
<p>If you&#8217;ve been writing MooTools code for a long time, maybe sometimes you found yourself <em>polluting your own Natives</em>, by extending them with functions that added little reusability value. An example:</p>
<pre class='highlight ' lang="javascript">
Element.implement({

	doSomethingSoSpecificThatIevenFindItHardToName: function(){
        	// ...
	}

});
</pre>
<p>Sometimes extending the natives just doesn&#8217;t feel right, specially if it&#8217;s for a logic you repeat several times but only within a class or subset of classes, and <em>it doesn&#8217;t award a public method</em> within your class. That&#8217;s when a function wrapped in a self-invoking function described above is best suited.</p>
<p>To finalize, let&#8217;s see a real-world example that contrasts these two approaches, taken from the MooTools Core.</p>
<pre class='highlight ' lang="javascript">
(function(){

var walk = function(element, walk, start, match, all, nocash){
	// internal dom walking logic
};

Element.implement({

	getPrevious: function(match, nocash){
		return walk(this, 'previousSibling', null, match, false, nocash);
	},

	getAllPrevious: function(match, nocash){
		return walk(this, 'previousSibling', null, match, true, nocash);
	},

	getNext: function(match, nocash){
		return walk(this, 'nextSibling', null, match, false, nocash);
	},

	getAllNext: function(match, nocash){
		return walk(this, 'nextSibling', null, match, true, nocash);
	},

	getFirst: function(match, nocash){
		return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
	},

        // ...

});

})();
</pre>
<p>As you can see, it extends Element with methods that you reuse a lot, and that even MooTools utilizes in its other components. However, there&#8217;s no point in making the <strong>walk</strong> function available to the rest of the Core, let alone your scripts, since it&#8217;s used in a very specific part which deals with the DOM manipulation. Its only purpose is avoiding code repetition in the several methods it implements to Element.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2009/03/02/dont-repeat-your-moo/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Adding placeholders to inputs in Javascript</title>
		<link>http://www.devthought.com/2009/02/21/adding-placeholders-to-inputs-in-javascript/</link>
		<comments>http://www.devthought.com/2009/02/21/adding-placeholders-to-inputs-in-javascript/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 16:03:11 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Client side]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://devthought.com/?p=323</guid>
		<description><![CDATA[As I release my latest MooTools plugin, PlaceholderInput, that adds support for input placeholders, I decided to explain my solution, and what others are available. An example of my implementation is seen on the Devthought sidebar, right next to this &#8230; <a href="http://www.devthought.com/2009/02/21/adding-placeholders-to-inputs-in-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As I release my latest MooTools plugin, <a href="/projects/mootools/placeholderinput/">PlaceholderInput</a>, that adds support for input placeholders, I decided to explain my solution, and what others are available.</p>
<p>An example of my implementation is seen on the Devthought sidebar, right next to this post. I&#8217;ll analyze next the different solutions that have been offered for this problem, and the upsides and downsides each has.</p>
<p><span id="more-323"></span></p>
<h3>Solution #1: background-image</h3>
<p>Upon the focus and blur events of the input, a background with the placeholder text is toggled.</p>
<p><strong>Advantages</strong></p>
<ul>
<li>The placeholder text is never submitted with the form</li>
</ul>
<p><strong>Disadvantages</strong></p>
<ul>
<li>A change in the text, font, style or size means re-exporting the image</li>
<li>The font rendering of the image and the actual text the user type will likely differ</li>
<li>It becomes harder to support internationalization</li>
</ul>
<h3>Solution #2: overlapped element</h3>
<p>A label or span element is positioned on top of the input. When the element is clicked, or the element is given focus, it disappears and the user can type normally.</p>
<p><strong>Advantages</strong></p>
<ul>
<li>The placeholder text is never submitted with the form</li>
<li>Easy to change or translate the placeholder value, just by altering the markup</li>
</ul>
<p><strong>Disadvantages</strong></p>
<ul>
<li>It&#8217;s very hard to position the text perfectly, in a cross browser fashion. Inputs should be padding less and border less to calculate the position perfectly, and styling becomes a problem.</li>
</ul>
<p>I&#8217;ve seen this method in the new Yahoo! Mail interface search input. I tested with a couple of browsers and some displayed the text with a considerable offset, which depicts the aforementioned disadvantage.</p>
<h3>Solution #3: altering the value</h3>
<p>This is the most common solution, and in my opinion, the easiest to maintain and deal with its shortcomings.</p>
<p><strong>Advantages</strong></p>
<ul>
<li>The text will be rendered in the same position and style as the typed text</li>
<li>Easy to change or translate the placeholder value, just by altering the markup</li>
</ul>
<p><strong>Disadvantages</strong></p>
<ul>
<li>Unless you check the form before it&#8217;s submitted, the placeholder value will be sent. This is not a major issue with frameworks, because you can override the methods used to access values (like <a href="/projects/mootools/placeholderinput/">my solution</a>)</li>
</ul>
<h3>The markup</h3>
<p>The most straightforward way to implement solution #3 would be adding a placeholder attribute to the input like this:</p>
<pre class='highlight ' lang="html4strict">
<input type="text" placeholder="Your email" value="" name="email" id="contact_email" />
<textarea placeholder="Your message" name="message" id="contact_message"></textarea>
</pre>
<p>This certainly won&#8217;t validate, but you can always extend your Doctype. The inputs would be easily retrieved with a CSS selector by Javascript (input[placeholder]).</p>
<p>Another more accessible approach would be to transform labels into placeholders. Thus:</p>
<pre class='highlight ' lang="html4strict">
<label for="contact_email" class="placeholder">Your email</label>
<input type="text" value="" name="email" id="contact_email" />
</pre>
<p>with some Javascript becomes</p>
<pre class='highlight ' lang="html4strict">
// we remove the label from the dom, or set it to display=none
<input type="text" value="" placeholder="Your email" name="email" id="contact_email" />
</pre>
<p>and then the placeholder behavior is added normally.</p>
<h3>MooTools implementation</h3>
<p>Please head to the <a href="/projects/mootools/placeholderinput">project page</a> to see this in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2009/02/21/adding-placeholders-to-inputs-in-javascript/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>BSOD comes to the Web</title>
		<link>http://www.devthought.com/2009/02/20/bsod-comes-to-the-web/</link>
		<comments>http://www.devthought.com/2009/02/20/bsod-comes-to-the-web/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 19:44:43 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Client side]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mootools plugin]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://devthought.com/?p=295</guid>
		<description><![CDATA[In my unstoppable pursuit of the best user experience scripting techniques, I decided to bring the famous BSOD to the web developers&#8217; world. I came up with a document describing the projections, possibilities and capabilities of my creation, which you &#8230; <a href="http://www.devthought.com/2009/02/20/bsod-comes-to-the-web/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my unstoppable pursuit of the best user experience scripting techniques, I decided to bring the famous BSOD to the web developers&#8217; world.</p>
<p><a class="imagelink" href="http://devthought.com/wp-content/projects/mootools/BSOD/"><img src="http://devthought.com/wp-content/uploads/2009/02/picture-8-300x210.png" alt="picture-8" title="picture-8" width="300" height="210" class="aligncenter size-medium wp-image-296" /></a></p>
<p>I came up with a document describing the projections, possibilities and capabilities of my creation, which you can <a href="http://devthought.com/wp-content/projects/mootools/BSOD/">access here</a>. It includes different scenarios and variations of this implementation.</p>
<p>Go to the <a href="http://devthought.com/projects/mootools/bsod/">project page</a> for download and other useful links.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2009/02/20/bsod-comes-to-the-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Flash currently aids Javascript development</title>
		<link>http://www.devthought.com/2008/01/14/how-flash-currently-aids-javascript-development/</link>
		<comments>http://www.devthought.com/2008/01/14/how-flash-currently-aids-javascript-development/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 02:29:23 +0000</pubDate>
		<dc:creator>Guillermo Rauch</dc:creator>
				<category><![CDATA[Client side]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[list]]></category>

		<guid isPermaLink="false">http://devthought.com/how-flash-currently-aids-javascript-development/</guid>
		<description><![CDATA[Most people tend to believe Javascript and Flash are meant to be rivals. However, for some important tasks, Javascript falls short and Macromedia comes to the rescue. Let&#8217;s revise some of the most remarkable scenarios. Uploading One of the most &#8230; <a href="http://www.devthought.com/2008/01/14/how-flash-currently-aids-javascript-development/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Most people tend to believe Javascript and Flash are meant to be rivals. However, for some important tasks, Javascript falls short and Macromedia comes to the rescue.</p>
<p>Let&#8217;s revise some of the most remarkable scenarios.</p>
<p><span id="more-60"></span></p>
<h3>Uploading</h3>
<p>One of the most common Flash and Javascript interaction is probably file uploading in forms. There&#8217;s almost no way to customize the input style in a cross browser fashion. Firefox, for instance, makes it impossible (for security reasons) to trigger the upload file selection unless the user clicks the Browse button. Among many other limitations.</p>
<p>But Flash comes to the rescue, with some really stunning implementations. It&#8217;s worth mentioning open source implementations like Fancy Upload (MooTools), <a href="http://www.pixeline.be/experiments/jqUploader/">jqUploader</a> (jQuery) and <a href="http://swfupload.org/">SWFUpload</a>. Flickr&#8217;s <a href="http://flickr.com/photos/upload/">new upload</a> also takes advantege of this method.</p>
<p><img src='http://devthought/New/wp-content/uploads/2008/01/1.png' alt='MooTools Upload implementation' /></p>
<h3>Clipboard access</h3>
<p>In most popular browsers, Javascript is not allowed to interact directly with the clipboard. The exception is the infamously insecure Internet Explorer 6:</p>
<div class="code jscode">
<p class="top"><a href="#" class="seecode">Click here to see Javascript code</a></p>
<p> <viewcode src="flashjs/code/1.txt" />
</div>
<p>Flash, however, allows developers to freely copy the text to the clipboard. <a href="http://www.jeffothy.com/weblog/clipboard-copy/">Jeffrey Larson</a> came up with the solution using a really small <a href="http://www.jeffothy.com/weblog/uploads/clipboard.php">swf file</a> from his Javascript code.</p>
<p>The code was further <a href="http://webchicanery.com/2006/11/14/clipboard-copy-javascript/">improved</a> to support Opera, which results in complete browsers compliance. There is a <a href="http://clientside.cnet.com/wiki/cnet-libraries/03-jswidgets/01-cms-and-form-helpers#clipboard.js">MooTools</a> implementation by Aaron Newton, and a <a href="http://joegornick.com/2007/10/29/extending-prototype-copy-to-clipboard/">Prototype</a> one.</p>
<h3>Photo editing / Drawing</h3>
<p>Another area where Javascript is still not quite ready for is photo editing. Flash proves reliable for such a task, and it&#8217;s what is commonly used right now, while Javascript is being left behind. </p>
<p>Here is a quick example of Flash <a href="http://www.mainada.net/inputdraw">outputting SVG</a>, and here is a full featured (but not freely available) image editor, <a href="http://www.picnik.com/app">Picnik</a>, that really shows how suitable Flash is for this.</p>
<p>The main reason Javacript falls short here is its limitation to come up with most effects, which is the reason js-based editors will do that server-side, adding a delay and thus hurting the user experience.</p>
<p>Some cool effects can be achieved in Javascript alone thanks to the <a href="http://www.netzgesta.de/bevel/">canvas tag</a>. But we&#8217;re still far from close to full-featured image editing.</p>
<h3>Sound</h3>
<p>The only sure way to play a sound file in a crossbrowser, crossplatform way is nowadays Flash. </p>
<p>There&#8217;s a solution available for most frameworks: <a href="http://widgets.rabidlabs.net/sounds/">MooSound</a>, <a href="http://code.google.com/p/gwt-voices/">GWT-Voices</a>, <a href="http://dev.jquery.com/view/trunk/plugins/sound/">jquery.sound</a>. The most popular standalone ones are <a href="http://www.schillmania.com/projects/soundmanager2/">SoundManager 2</a> and <a href="http://jssoundkit.sourceforge.net/">JSSoundKit</a>.</p>
<h3>Persistent Data Storage</h3>
<p>There might be certain scenarios where you&#8217;ll want to store large chunk of data in the client side (it could be for caching purposes, or for offline retrieval, for example. Flash is one of the most reliable ways, allowing you to store up to 100k seamlessly, and even more if the user authorizes it when prompted.</p>
<p>See <a href="http://manual.dojotoolkit.org/WikiHome/DojoDotBook/Book50">dojo.storage</a> for a nice implementation and proof-of-concept</p>
<p><strong>Note:</strong> i&#8217;m currently working on a MooTools implementation of this.</p>
<h3>Some scenarios where flash might be involved</h3>
<p>Ajax: see the <a href="http://fjax.enginpost.com/">fjax</a> project<br />
<br />Charts: see the <a href="http://developer.yahoo.com/yui/charts//">YUI.charts</a> project (and see <a href="http://people.iola.dk/olau/flot/examples/">flot</a> for a sweet jQuery approach!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devthought.com/2008/01/14/how-flash-currently-aids-javascript-development/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

