<?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>redemption in a blog &#187; JavaScript</title>
	<atom:link href="http://blog.codefront.net/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codefront.net</link>
	<description>Rails, Firefox, Anime, Mac</description>
	<lastBuildDate>Tue, 24 Jan 2012 01:47:54 +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>Best JavaScript library project roadmap I&#8217;ve seen</title>
		<link>http://blog.codefront.net/2007/11/15/best-javascript-library-project-roadmap-ive-seen/</link>
		<comments>http://blog.codefront.net/2007/11/15/best-javascript-library-project-roadmap-ive-seen/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 06:24:27 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/11/15/best-javascript-library-project-roadmap-ive-seen/</guid>
		<description><![CDATA[The mootools developers look like they are having fun defining their project roadmap: MooTools Plugin to uninstall Internet Explorer from any machine within network range]]></description>
			<content:encoded><![CDATA[<p>The mootools developers look like they are having fun defining their <a href="http://dev.mootools.net/roadmap">project roadmap</a>:</p>
<div class="img"><img src='http://blog.codefront.net/wp-content/uploads/2007/11/mootools-13-ie-milestone_thumb.png' alt='mootools 1.3 roadmap' /></div>
<p><br style="clear: both;" /></p>
<blockquote><p>MooTools Plugin to uninstall Internet Explorer from any machine within network range</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/11/15/best-javascript-library-project-roadmap-ive-seen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New on edge Rails: JSON serialization of ActiveRecord objects reaches maturity</title>
		<link>http://blog.codefront.net/2007/10/10/new-on-edge-rails-json-serialization-of-activerecord-objects-reaches-maturity/</link>
		<comments>http://blog.codefront.net/2007/10/10/new-on-edge-rails-json-serialization-of-activerecord-objects-reaches-maturity/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 16:13:02 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/10/10/new-on-edge-rails-json-serialization-of-activerecord-objects-reaches-maturity/</guid>
		<description><![CDATA[The last time I wrote about ActiveRecord#to_json on edge Rails, it was missing some key functionality. For one, you couldn&#8217;t include any associations. Another thing was you couldn&#8217;t do something like this in your controller: @authors = Author.find(:all) render :json => @authors.to_json(:only => :name) Oh and did I mention it wasn&#8217;t emitting valid JSON by [...]]]></description>
			<content:encoded><![CDATA[<p>The last time I <a href="/2007/09/24/new-in-edge-rails-serialize-activerecord-objects-to-json-with-activerecordto_json/">wrote about <code>ActiveRecord#to_json</code> on edge Rails</a>, it was missing some key functionality. For one, you couldn&#8217;t include any associations. Another thing was you couldn&#8217;t do something like this in your controller:</p>
<pre><code class="ruby">@authors = Author.find(:all)

render :json => @authors.to_json(:only => :name)</code></pre>
<p>Oh and did I mention <a href="/2007/06/20/how-to-get-strictly-valid-json-from-rails/">it wasn&#8217;t emitting valid JSON by default</a>?</p>
<p>In the last few weeks, several patches to the Rails trunk have fixed all these issues (most of these patches are already on the <a href="http://weblog.rubyonrails.com/2007/9/30/rails-2-0-0-preview-release">Rails 2.0 Preview Release</a>). JSON serialization of ActiveRecord objects is <em>finally</em> on par with XML serialization, and that old <a href="http://trac.codefront.net/jsonifier/">Jsonifier plugin</a> I wrote can finally be sent off to the plugin retirement home (though, I am thinking of porting all the JSON patches into Jsonifier to add Rails 2.0-like JSON serialization to Rails 1.2.4, but who knows, I <em>am</em> lazy).</p>
<p>Anyway, back to the new JSON stuff on edge Rails.</p>
<h3>No more invalid JSON from Rails</h3>
<p>Yes it&#8217;s true. No more <a href="/2007/06/20/how-to-get-strictly-valid-json-from-rails/">changing of module attribute to get Rails to produce valid JSON</a>. Thanks to <a href="http://blog.choonkeat.com/">Choon Keat</a> with his <a href=" http://www.ruby-forum.com/topic/124797">detailed SVN history snooping</a>, we finally managed to get a <a href="http://dev.rubyonrails.org/ticket/8762">patch to fix JSON encoding to quote all hash keys</a> <a href="http://dev.rubyonrails.org/changeset/7697">into Rails</a>.</p>
<h3>:include option can be used to include associations with ActiveRecord::Base#to_json</h3>
<p>At <a href="/2007/09/24/new-in-edge-rails-serialize-activerecord-objects-to-json-with-activerecordto_json/#comment-286519">DHH&#8217;s urging</a>, I submitted a <a href="http://dev.rubyonrails.org/ticket/9677">patch that added the <code>:include</code> option to <code>ActiveRecord#to_json</code></a>. Of course, it was a sloppy first submission and <a href="http://dev.rubyonrails.org/ticket/9677#comment:2">DHH pointed that out</a> &#8211; a little bit of DRY love and it was really great to see it <a href="http://dev.rubyonrails.org/changeset/7663">get committed</a> (I have a soft spot for JSON serialization from Rails, since I&#8217;d been trying to achieve the same thing with <a href="http://trac.codefront.net/jsonifier/">Jsonifier</a>). </p>
<p>So yes, now you can do:</p>
<pre><code class="ruby">json = @david.to_json(:include => :posts)
# or even...
json = @david.to_json(
  :include => {
    :posts => {
      :include => {
        :taggings => {
          :include => {
            :tag => { :only => :name }
          }
        }
      }
    }
})</code></pre>
<h3>Enumerable#to_json and Hash#to_json now accept options</h3>
<p>One problem with Jsonifier that I often get emails about is how the <code>to_json</code> options don&#8217;t work for lists (Enumerables). And why is this important? Well, we often retrieve collections of ActiveRecord objects at a time with <code>AR::B#find</code> so it&#8217;s not too much to ask to be able to do this in your controller actions:</p>
<pre><code class="ruby">@authors = Author.find(:all)

render :json => @authors.to_json(:only => :name)</code></pre>
<p>But of course you couldn&#8217;t, so I <a href="http://dev.rubyonrails.org/ticket/9751">patched away</a> by changing the <code>to_json</code> methods of Enumerable and Hash (and other types as well) to accept an optional <code>options</code> argument. Enumerables will pass on any <code>options</code> it receives to its elements. Hashes will respect :only and :except (as well as passing on the <code>options</code> to its elements).</p>
<h3>Unambiguous (non-US-centric) dates and times</h3>
<p>While Rails 1.2.3 (and 1.2.4) never supported encoding of Dates, Times and DateTimes, edge Rails has been happily supporting Date, Time and DateTime conversions to JSON since <a href="http://dev.rubyonrails.org/changeset/6773">revision 6673</a>. Unfortunately, the date string format is in MM/DD/YYYY format:</p>
<pre><code class="ruby">Time.now.to_json
=> "\"09/21/2007 12:15:02 UTC\""</code></pre>
<p>Geoff Buesing suggested that Rails should <a href="http://dev.rubyonrails.org/ticket/9750">change this</a> to the more unambiguous YYYY/MM/DD format. Finding the right date format is important not only for readability reasons, it&#8217;s also important that the date string is directly parsable by the many browser JavaScript implementations using the JavaScript <code>new Date(dateString)</code> function. There is no formal spec of how dates should be represented in JSON, but it&#8217;s most convenient that strings representing dates can be directly converted into JavaScript Date objects.</p>
<p>Testing in several browsers and on different platforms, albeit not extensively, we settled on the <code>%Y/%m/%d %H:%M:%S %z</code> (strftime) format (more details in the <a href="http://dev.rubyonrails.org/ticket/9750">comments of the Trac ticket</a>).</p>
<p>Now it is:</p>
<pre><code class="ruby">Time.now.to_json
=> "\"2007/09/21 12:15:02 +0800\""</code></pre>
<p>Much better.</p>
<h3>What&#8217;s left?</h3>
<p>Documentation, for one thing. ActiveRecord::Base#to_json is still undocumented (<a href="http://dev.rubyonrails.org/ticket/9814">docfix patch</a>). The <code>to_json</code> methods for Enumerable and Hash need documentation as well (will patch that soon).</p>
<p><code>ActiveRecord::Base#to_json</code> also doesn&#8217;t deal with binary attributes, which can be easily resolved by Base64-encoding them (patch coming soon, it gets slightly complicated when trying to do a <code>from_json</code>). And of course, optimization improvements are always nice (decoding from JSON especially).</p>
<p>So, if you use JSON at all, please come in and help patch the remaining bits before Rails 2.0 rolls out. If you can&#8217;t (or more realistically, don&#8217;t have the time to) patch Rails yourself, do help out by verifying patches :).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/10/10/new-on-edge-rails-json-serialization-of-activerecord-objects-reaches-maturity/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>New in Edge Rails: Serialize ActiveRecord objects to JSON with ActiveRecord#to_json</title>
		<link>http://blog.codefront.net/2007/09/24/new-in-edge-rails-serialize-activerecord-objects-to-json-with-activerecordto_json/</link>
		<comments>http://blog.codefront.net/2007/09/24/new-in-edge-rails-serialize-activerecord-objects-to-json-with-activerecordto_json/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 02:14:12 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/09/24/new-in-edge-rails-serialize-activerecord-objects-to-json-with-activerecordto_json/</guid>
		<description><![CDATA[Converting ActiveRecord instances to their JSON representation has always been a topic that has been dear to me. I&#8217;d tried to get a patch that adds to_json to ActiveRecord into Rails (but the quality of my patch was lacking in a few respects). The Jsonifier plugin that I wrote tried to address the lack of [...]]]></description>
			<content:encoded><![CDATA[<p>Converting ActiveRecord instances to their JSON representation has always been a topic that has been dear to me. I&#8217;d tried to get <a href="http://dev.rubyonrails.org/ticket/8920">a patch that adds <code>to_json</code> to ActiveRecord</a> into Rails (but the quality of my patch was lacking in a few respects). The <a href="http://trac.codefront.net/jsonifier">Jsonifier plugin</a> that I wrote tried to address the lack of built-in JSON serialization by adding a <code>ActiveRecord#to_json</code> method that acts much like <code>ActiveRecord#to_xml</code>.</p>
<p>So it is with mixed feelings when I discovered a couple of days ago when <a href="http://loudthinking.com/"><acronym title="David Heinemeier Hansson">DHH</acronym></a> committed a <a href="http://dev.rubyonrails.org/changeset/7519">changeset that added a native <code>ActiveRecord#to_json</code> method</a>. Of course, I&#8217;m elated that JSON serialization is given first class attention now, since the raison d&#8217;être of Jsonifier and my Rails patch was to do just that. A little bit of me is selfishly disappointed since it means that Jsonifier has become quite obsolete!</p>
<p>But it is an excellent change, I look forward to patching it up (if DHH doesn&#8217;t beat me to it &#8211; there&#8217;ve been so much activity on the Rails trunk recently) so that the <a href="http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/serializers/json_serializer.rb?rev=7519">JSON serializer</a> supports an <code>:include</code> options for including associations much like for <code>ActiveRecord#to_xml</code> and Jsonifier&#8217;s mixed in <code>to_json</code>.</p>
<p><ins>Update: I&#8217;ve submitted a <a href="http://dev.rubyonrails.org/ticket/9677">patch for adding <code>:include</code> to <code>ActiveRecord#to_json</code></a>. Please test it and give feedback or +1 ;).</ins></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/09/24/new-in-edge-rails-serialize-activerecord-objects-to-json-with-activerecordto_json/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery 1.2 goodness</title>
		<link>http://blog.codefront.net/2007/09/13/jquery-12-goodness/</link>
		<comments>http://blog.codefront.net/2007/09/13/jquery-12-goodness/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 07:04:54 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/09/13/jquery-12-goodness/</guid>
		<description><![CDATA[jQuery 1.2 was released yesterday and while it&#8217;s unfortunate that it doesn&#8217;t work with some of the fantastic jQuery plugins I am already using, there&#8217;re some really cool new features. In particular (this is my favorite), built-in cross-domain script loading via the getScript is just too convenient. This would be awesome for loading heavy scripts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jquery.com/blog/2007/09/10/jquery-12-jqueryextendawesome/">jQuery 1.2 was released yesterday</a> and while it&#8217;s unfortunate that it doesn&#8217;t work with some of the <a href="http://stilbuero.de/jquery/tabs/">fantastic</a> jQuery <a href="http://tablesorter.com/">plugins</a> I am already using, there&#8217;re some really cool new features. In particular (this is my favorite), built-in <a href="http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getScript">cross-domain script loading</a> via the <code>getScript</code> is just too convenient.</p>
<p>This would be awesome for loading heavy scripts later and only when they are &#8220;activated&#8221;, like Google Maps (which was exactly what I was trying to do earlier before realizing I&#8217;d need to setup a reverse proxy to workaround the cross-domain problem).</p>
<p>Oh, and the <a href="http://docs.jquery.com/Release:jQuery_1.2/Ajax#Disable_Caching">easy way to turn off browser caching in AJAX calls</a> is a nice convenience as well (no need to append random numbers or timestamps manually).</p>
<p>Yup, I&#8217;m in love with jQuery right now. Protoype and YUI have fallen by the wayside like Chinese first and second wives of yore.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/09/13/jquery-12-goodness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better JSON output from Rails with the Jsonifier plugin</title>
		<link>http://blog.codefront.net/2007/07/11/better-json-output-from-rails-with-the-jsonifier-plugin/</link>
		<comments>http://blog.codefront.net/2007/07/11/better-json-output-from-rails-with-the-jsonifier-plugin/#comments</comments>
		<pubDate>Wed, 11 Jul 2007 04:46:38 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/07/11/better-json-output-from-rails-with-the-jsonifier-plugin/</guid>
		<description><![CDATA[Update: Edge Rails now does whatever Jsonifier does (and more). Check out my blog post on JSON serialization maturity in edge Rails. This means that this plugin is virtually obsolete if you&#8217;re using edge Rails. If you&#8217;ve tried to output JSON from your Rails applications before, you&#8217;d probably have noticed how inadequate it all seems. [...]]]></description>
			<content:encoded><![CDATA[<p><ins>Update: Edge Rails now does whatever Jsonifier does (and more). Check out my blog <a href="http://blog.codefront.net/2007/10/10/new-on-edge-rails-json-serialization-of-activerecord-objects-reaches-maturity/">post on JSON serialization maturity in edge Rails</a>. This means that this plugin is virtually obsolete if you&#8217;re using edge Rails.</ins></p>
<p>If you&#8217;ve tried to output JSON from your Rails applications before, you&#8217;d probably have noticed how inadequate it all seems. Let&#8217;s look at the kind of output (pretty-printed for easier reading) you get from calling <code>to_json</code> on your typical User model:</p>
<pre><code class="javascript">{
  attributes: {
    id: 1,
    name: "Konata",
    awesome: true,
    created_at: "07/01/2007"
  }
}</code></pre>
<p>Some of the common problems developers who write applications that speak JSON have with this are:</p>
<ul>
<li>The <code>attributes</code> part is often unnecessary cruft when consuming ActiveRecord objects as JSON.</li>
<li>There&#8217;s no obvious way to control which attributes are shown in the JSON (e.g. you may want to hide private or lengthy attributes). The way to workaround this is either to write your own <code>to_json</code> instance method for your ActiveRecord model, or to use a Rails plugin (like <a href="http://geekblog.vodpod.com/?p=9">acts_as_json</a>) or a <a href="http://json.rubyforge.org/">gem</a>.</li>
<li>Including 2nd (or higher order) associations is tricky (as above, you can achieve this by defining your own <code>to_json</code> instance methods).</li>
</ul>
<h3>Under the hood of the current ActiveRecord#to_json</h3>
<p>The <code>to_json</code> method for ActiveRecord objects falls back on using that defined in <a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/json">ActiveSupport&#8217;s JSON classes</a>. The way it&#8217;s currently done, there are a bunch of JSON encoder classes defined for various types &#8211; when you call <code>to_json</code> on an ActiveRecord object it simply uses <a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/json/encoders/object.rb"><code>Object#to_json</code></a>.</p>
<p>By the way, see that <code>created_at: "07/01/2007"</code> bit in the example above which is the JSON output for a Date attribute? That&#8217;s in MM/DD/YYYY format. Yup, 1st July 2007 not 7th January 2007 you &#8220;rest of the world you&#8221;. Ouch, but at least you can use JavaScript&#8217;s <code>Date.parse()</code> on it directly as detailed in <a href="http://dev.rubyonrails.org/ticket/8399">this patch</a>. And before you ask, yes, <code>Date.parse()</code> doesn&#8217;t understand the YYYY-MM-DD format.</p>
<h3>Can has Rails patch?</h3>
<p>So about 2 days ago, I wrote a <a href="http://dev.rubyonrails.org/ticket/8920">Rails patch to boost ActiveRecord#to_json with an options hash</a>. Yep much like what you can do with <a href="http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html#M000910"><code>ActiveRecord#to_xml</code></a>.</p>
<p>I hope it gets committed into the core some day. I mean, gosh, isn&#8217;t Rails all about Web 2.0 mashups. It even has that fancy <code>render :json</code> thing. I do believe JSON output needs to be treated more seriously in Rails rather than the half-hearted attempt at JSON encoding. No? Well, if the patch doesn&#8217;t get accepted I&#8217;ll still have <a href="http://trac.codefront.net/jsonifier/">my plugin</a> (<a href="#jsonifier-plugin">see below</a>).</p>
<p>Anyway, let&#8217;s see some examples:</p>
<h3>Some examples, see?</h3>
<p>Assuming User and Post models where User has_many Posts:</p>
<pre><code class="ruby">david = User.find(1)
david.to_json  # {id: 1, name: "David", awesome: true, created_at: "07/01/2007"}
</code></pre>
<p>No more <code>attributes</code> cruft!</p>
<p><code>:only</code> and <code>:except</code> work the same way that as for <code>ActiveRecord#to_xml</code>:</p>
<pre><code class="ruby">david.to_json(:only => :name)                 # {name: "David"}
david.to_json(:only => [:id, :name])          # {id: 1, name: "David"}
david.to_json(:except => :created_at)         # {id: 1, name: "David", awesome: true}
david.to_json(:except => [:id, :created_at])  # {name: "David", awesome: true}</code></pre>
<p>You can use the <code>:methods</code> options as well to include any methods on the object.</p>
<pre><code class="ruby">david.to_json(:methods => :permalink)
  # {id: 1, name: "David", awesome: true, created_at: "07/01/2007", permalink => "1-David"}
david.to_json(:methods => [:permalink, :interestingness])
  # {id: 1, name: "David", awesome: true, created_at: "07/01/2007", \
  #   permalink => "1-David", :interestingness => 666}</code></pre>
<p>The <code>:include</code> option lets you include associations.</p>
<pre><code class="ruby">david.to_json(:include => :posts)
  # {id: 1, name: "David", awesome: true, created_at: "07/01/2007", \
  #    posts: [{id: 1, author_id: 1, title: "Welcome to the weblog"}, \
  #            {id: 2, author_id: 1, title: "So I was thinking"}]}</code></pre>
<p><code>:only</code>, <code>:except</code>, and <code>:methods</code> works on the included associations as well:</p>
<pre><code class="ruby">david.to_json(:include => { :posts => { :only => :title } })
  # {id: 1, name: "David", awesome: true, created_at: "07/01/2007", \
  #    posts: [{title: "Welcome to the weblog"}, \
  #            {title: "So I was thinking"}]}</code></pre>
<p>Of course, 2nd level (and higher order) associations work too:</p>
<pre><code class="ruby">david.to_json(:include => { :posts => { \
                              :include => { :comments => { \
                                              :only => :body } }, \
                              :only => :title } })
  # {id: 1, name: "David", awesome: true, created_at: "07/01/2007", \
  #    posts: [{comments: [{body: "1st post!"}, {body: "OMGWTFBBQ!"}], \
  #             title: "Welcome to the weblog"}, \
  #            {comments: [{body: "Don't think too hard"}], \
  #             title: "So I was thinking"}]}</code></pre>
<p>Please do give any feedback at the <a href="http://dev.rubyonrails.org/ticket/8920">Rails patch for ActiveRecord#to_json</a> or here. I wanna know what you feel about adding this functionality into the Rails core!</p>
<h3 id="jsonifier-plugin">Jsonifier plugin</h3>
<p>I&#8217;ve rolled the patch into a plugin: Jsonifier. The <a href="http://trac.codefront.net/jsonifier/">Jsonifier Trac</a> is at <a href="http://trac.codefront.net/jsonifier/">http://trac.codefront.net/jsonifier/</a>.</p>
<p>Git repository:</p>
<pre><code>git://github.com/chuyeow/jsonifier.git</code></pre>
<p>Github project page:</p>
<pre><code>http://github.com/chuyeow/jsonifier/</code></pre>
<p>To install the plugin:</p>
<pre><code>ruby script/plugin install git://github.com/chuyeow/jsonifier.git</code</pre>
<p> or <code>git clone</code> the repository manually into the <code>vendor/plugins</code> directory.</p>
<h3>A note on valid JSON</h3>
<p>The JSON Rails spits out by default is not strictly valid JSON since the <a href="http://www.ietf.org/rfc/rfc4627.txt?number=4627">JSON specifications</a> require keys to be double quoted. To get strictly valid JSON, add</p>
<pre><code class="ruby">ActiveSupport::JSON.unquote_hash_key_identifiers = false</code></pre>
<p>in your environment.rb (or in the Rails initializers directory if you're on edge). See <a href="http://blog.codefront.net/2007/06/20/how-to-get-strictly-valid-json-from-rails/">my blog post on how to get strictly valid JSON from Rails</a> for more info.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/07/11/better-json-output-from-rails-with-the-jsonifier-plugin/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Prototype 1.5.1 is baaaaad for Safari 1 and 2 users</title>
		<link>http://blog.codefront.net/2007/06/21/prototype-151-is-baaaaad-for-safari-1-and-2-users/</link>
		<comments>http://blog.codefront.net/2007/06/21/prototype-151-is-baaaaad-for-safari-1-and-2-users/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 11:15:00 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/06/21/prototype-151-is-baaaaad-for-safari-1-and-2-users/</guid>
		<description><![CDATA[Read the bug fix announcement. Upgrade! This was causing extremely puzzling crashes in Safari on Macs (pre-Safari 3 beta) on one of our applications and I&#8217;m glad (in some ways) that the problem lay with the Prototype library.]]></description>
			<content:encoded><![CDATA[<p>Read the <a href="http://prototypejs.org/2007/6/20/prototype-1-5-1-1-bugfix-release">bug fix announcement</a>. Upgrade! This was causing extremely puzzling crashes in Safari on Macs (pre-Safari 3 beta) on <a href="http://www.bezurk.com/hotels/singapore/singapore">one of our applications</a> and I&#8217;m glad (in some ways) that the problem lay with the Prototype library.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/06/21/prototype-151-is-baaaaad-for-safari-1-and-2-users/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Essential Firebug video for web developers</title>
		<link>http://blog.codefront.net/2007/01/28/essential-firebug-video-for-web-developers/</link>
		<comments>http://blog.codefront.net/2007/01/28/essential-firebug-video-for-web-developers/#comments</comments>
		<pubDate>Sun, 28 Jan 2007 06:41:45 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2007/01/28/essential-firebug-video-for-web-developers/</guid>
		<description><![CDATA[If you&#8217;re doing web development or design of any sort, you have to check out Joe Hewitt&#8217;s talk on Firebug at Yahoo! &#8211; download the movie or watch it online, just make sure you watch it. If you aren&#8217;t already using Firebug, this will convince you. If you are, you&#8217;ll probably find some gems in [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re doing web development or design of any sort, you have to check out <a href="http://www.yuiblog.com/blog/2007/01/26/video-hewitt-firebug/">Joe Hewitt&#8217;s talk on Firebug at Yahoo!</a> &#8211; download the movie or watch it online, just make sure you watch it.</p>
<p>If you aren&#8217;t already using <a href="http://getfirebug.com/">Firebug</a>, this will convince you. If you are, you&#8217;ll probably find some gems in there that you didn&#8217;t know before. I didn&#8217;t know that you could log events to elements on the fly, or press the up and down arrow keys to adjust numerical values (such as margins and paddings), or edit the values in the box model layout diagram, or hover over variable names to see a tooltip of their values in the JavaScript debugger, or conditional breakpoints.</p>
<p>Now if only it were able to detect JavaScript syntax errors that cause an entire JS file to be ignored by the browser. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2007/01/28/essential-firebug-video-for-web-developers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Beware of form parameters named &#8216;submit&#8217;</title>
		<link>http://blog.codefront.net/2006/08/16/beware-of-form-parameters-named-submit/</link>
		<comments>http://blog.codefront.net/2006/08/16/beware-of-form-parameters-named-submit/#comments</comments>
		<pubDate>Wed, 16 Aug 2006 12:10:35 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/2006/08/16/beware-of-form-parameters-named-submit/</guid>
		<description><![CDATA[Well, that is if you are ever going to be submitting the form via Javascript. We had to generate forms on the fly and POST them behind the scenes (i.e. in hidden &#60;iframe&#62;s), and got a decent script going, until a particular case failed for no apparent reason. I finally found that the problem was [...]]]></description>
			<content:encoded><![CDATA[<p>Well, that is if you are ever going to be submitting the form via Javascript. <a href="http://www.bezurk.com/">We</a> had to generate forms on the fly and POST them behind the scenes (i.e. in hidden &lt;iframe&gt;s), and got a decent script going, until a particular case failed for no apparent reason. I finally found that the problem was due to a form parameter named &#8220;submit&#8221; that overwrote the submit() function of the &lt;form&gt;. That&#8217;s, of course, after looking at all the wrong places.</p>
<p>So this doesn&#8217;t work:</p>
<pre><code class="html">&lt;form id="ninjaForm" action="/come/get/some" method="post"&gt;
  &lt;input id="someParam" name="someParam"
    type="hidden" value="Some value" /&gt;
  &lt;input id="submit" name="submit"
    type="hidden" value="Start search" /&gt;
&lt;/form>
&lt;script type="text/javascript"&gt;
  setTimeout("document.ninjaForm.submit()", 200);
&lt;/script&gt;</code></pre>
<p>When the browser tries to execute &#8220;document.ninjaForm.submit()&#8221;, it sees the &#8220;submit&#8221; form field (which overwrote the submit() function) instead and complains that &#8220;submit is not a function&#8221;.</p>
<p>Do this instead:</p>
<pre><code class="html">&lt;form id="ninjaForm" action="/come/get/some" method="post"&gt;
  &lt;script type="text/javascript"&gt;
    // Alias the submit function in case there is a 'submit' param.
    ninjaForm = document.getElementById('ninjaForm');
    ninjaForm.__submit = ninjaForm.submit;
  &lt;/script&gt;
  &lt;input id="someParam" name="someParam"
    type="hidden" value="Some value" /&gt;
  &lt;input id="submit" name="submit"
    type="hidden" value="Start search" /&gt;
&lt;/form&gt;
&lt;script type="text/javascript"&gt;
  setTimeout("ninjaForm.__submit();", 200);
&lt;/script&gt;</code></pre>
<p>That&#8217;s one way to workaround, of course, and we can get away with the &#8220;ninjaForm&#8221; global in this case.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2006/08/16/beware-of-form-parameters-named-submit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unobtrusive IFrame shim &#8211; a half solution</title>
		<link>http://blog.codefront.net/2006/08/01/unobtrusive-iframe-shim-a-half-solution/</link>
		<comments>http://blog.codefront.net/2006/08/01/unobtrusive-iframe-shim-a-half-solution/#comments</comments>
		<pubDate>Tue, 01 Aug 2006 11:33:50 +0000</pubDate>
		<dc:creator>Chu Yeow</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://blog.codefront.net/archives/2006/08/01/unobtrusive-iframe-shim-a-half-solution/</guid>
		<description><![CDATA[Something that really bugged me when using YUI Calendars and YUI AutoComplete widgets was how IFrame shims are currently being managed in libraries and home-brewed code (we use IFrame shims in many places as well). YUI Calendars doesn&#8217;t have a built-in IFrame shim, YUI AutoComplete has its own, and we use our own IFrame shim [...]]]></description>
			<content:encoded><![CDATA[<p>Something that really bugged me when using <a href="http://developer.yahoo.com/yui/calendar/">YUI Calendars</a> and <a href="http://developer.yahoo.com/yui/autocomplete">YUI AutoComplete</a> widgets was how IFrame shims are currently being managed in libraries and home-brewed code (we use IFrame shims in many places as well). YUI Calendars doesn&#8217;t have a built-in IFrame shim, YUI AutoComplete has its own, and we use our own IFrame shim library.</p>
<p>For the uninitiated, IFrame shims are basically IFrames dynamically inserted (hence &#8220;shim&#8221;) under overlaying DOM elements so that any &lt;select&gt; elements do not show through in IE 5.5 and above. A common example would be dynamically generated divs that float on top of drop downs in forms, such as the Yahoo! Calendar widget example below.</p>
<div class="img">
<img src="http://blog.codefront.net/wp-content/uploads/2006/08/see-thru-select-box.png" alt="An example of the select box see through problem in IE 5.5+" />
</div>
<p><br style="clear:both" /></p>
<p>So anyway, the thing that&#8217;s bugging me is the awkwardness in inserting IFrame shims where they are needed and the duplication of unnecessary code to create, show, and hide the IFrame shims. Ideally, I&#8217;d like to do something like this to attach IFrame shims and forget about them:</p>
<div class="code">var iframeShim = new net.codefront.IFrameShim(&#8216;elementId&#8217;);</div>
<p>Or the conceptually nicer way of attaching IFrame shim &#8220;behavior&#8221;:</p>
<div class="code">net.codefront.IFrameShim.attachShim($(&#8216;elementId&#8217;));</div>
<p>No need for manually displaying and hiding the IFrame shim, polluting display logic and event handlers. I don&#8217;t care how all that shimming is done nor should I have to. I don&#8217;t want to have to call displayShim() whenever I display a floating div and hideShim() when I hide it. It should be smart enough to display the shim when the overlay is showing and to hide when the overlay is no longer visible.</p>
<p>As it is, I am seeing code duplicated in many places to manage these IFrame shims, and that&#8217;s a <a href="http://c2.com/xp/CodeSmell.html">bad smell</a>. Ahh ahh, before I go further, I am completely aware that I could be completely off-base and such a miraculous time-saver of a library already exists. If so, I want to know!</p>
<p>Trying to fix this problem, I came up with this <a href="http://blog.codefront.net/examples/iframeshim.js">bit of JavaScript</a>, which you shouldn&#8217;t bother reading. The idea is to allow me to do this:</p>
<div class="code">var shim = new com.bezurk.widget.IFrameShim(&#8216;myFloatingCalendar&#8217;);<br />
shim.manualShim = false;<br />
shim.manualDeshim = false;</div>
<p>And I have a &#8216;myFloatingCalendar&#8217; element that&#8217;s automagically shimmed whenever it&#8217;s displayed. (The shim.manualShim and shim.manualDeshim are defaulted to false, and are shown purely for explanatory purposes.)</p>
<p>There is one problem though &#8211; I can&#8217;t figure out an elegant way to &#8220;listen&#8221; to the display and hide events of the element that&#8217;s shimmed. The way I&#8217;ve done it is to rely on <a href="http://www.sergiopereira.com/articles/prototype.js.html#Reference.PeriodicalExecuter">Prototype&#8217;s PeriodicalExecuter</a> (extended to support a stop() method) to poll for the visibility of the element. Naturally this is an ugly hack and causes noticeable flicker.</p>
<p>I&#8217;ve looked at custom events (YUI and Dojo have <em>very nice</em> event handling libraries) but can&#8217;t see how to hook this up unobtrusively. If you have a suggestion or a solution, I want to hear it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codefront.net/2006/08/01/unobtrusive-iframe-shim-a-half-solution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

