<?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>The Lucid &#187; Javascript</title>
	<atom:link href="http://thelucid.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://thelucid.com</link>
	<description>The Lightweight Ramblings of Jamie Hill</description>
	<lastBuildDate>Sun, 11 Mar 2012 19:52:46 +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>Writing Javascript that runs in multiple environments (with a one-liner)</title>
		<link>http://thelucid.com/2011/07/14/writing-javascript-that-runs-in-multiple-environments-with-a-one-liner/</link>
		<comments>http://thelucid.com/2011/07/14/writing-javascript-that-runs-in-multiple-environments-with-a-one-liner/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 14:22:45 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[commonjs]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[oneliner]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=743</guid>
		<description><![CDATA[With the introduction of server-side javascript, it&#8217;s nice to be able to utilise any Javascript libraries you may write in both the browser and on the server. I&#8217;ve seen a few different approaches to this but wanted a one-liner that I could just stick at the top of an anonymous function&#8230; this is what I [...]]]></description>
			<content:encoded><![CDATA[<p>With the introduction of server-side javascript, it&#8217;s nice to be able to utilise any Javascript libraries you may write in both the browser and on the server. I&#8217;ve seen a few different approaches to this but wanted a one-liner that I could just stick at the top of an anonymous function&#8230; this is what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> MyLib <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> exports <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> exports <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">MyLib</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// MyLib.myFunction = ...</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now in NodeJS you can do:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> MyLib <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./mylib.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This also passes <a href="http://jslint.com">JS Lint</a> using the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*jslint */</span>
<span style="color: #009966; font-style: italic;">/*global exports */</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;use strict&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> MyLib <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> exports <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> exports <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">MyLib</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    MyLib.<span style="color: #660066;">foo</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'bar'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2011/07/14/writing-javascript-that-runs-in-multiple-environments-with-a-one-liner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Super simple jQuery templating</title>
		<link>http://thelucid.com/2010/07/27/super-simple-jquery-templating/</link>
		<comments>http://thelucid.com/2010/07/27/super-simple-jquery-templating/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:41:46 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[templating]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=628</guid>
		<description><![CDATA[Working with jQuery, it is common to find yourself needing some kind of templating solution. There are plenty out there, however sometimes the use-case is simple enough that you don&#8217;t really need a fully blow templating plugin. We&#8217;ll take a task list as an example (just to be original). Lets say you have the following [...]]]></description>
			<content:encoded><![CDATA[<p>Working with <a href="http://jquery.com">jQuery</a>, it is common to find yourself needing some kind of templating solution. There are <a href="http://ejohn.org/blog/javascript-micro-templating/">plenty</a> out <a href="http://github.com/trix/nano">there</a>, however sometimes the use-case is simple enough that you don&#8217;t really need a fully blow templating plugin.</p>
<p>We&#8217;ll take a task list as an example (just to be original). Lets say you have the following task objects in an array:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> tasks <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
  <span style="color: #009900;">&#123;</span> id<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'A todo item'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#123;</span> id<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'Another todo'</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you want to display them in an unordered list with checkboxes etc. What I like to do is create a &#8216;templates&#8217; object, which contains my basic templates:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> templates <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  taskList<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;ul class=&quot;task-list&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  taskItem<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;li&gt;&lt;input type=&quot;checkbox&quot; /&gt; &lt;span /&gt;&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>With these templates in place, it&#8217;s a simple case of cloning them when required and inserting the relevant data. jQuery&#8217;s &#8216;<a href="http://api.jquery.com/text/">text</a>&#8216; and &#8216;<a href="http://api.jquery.com/attr/">attr</a>&#8216; methods are ideal for this as they handle the escaping of html entities. Based on this we can iterate over our tasks array and insert the relevant items in the dom:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> list <span style="color: #339933;">=</span> templates.<span style="color: #660066;">taskList</span>.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>tasks<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  templates.<span style="color: #660066;">taskItem</span>.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  list.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s it, by using jQuery&#8217;s &#8216;<a href="http://api.jquery.com/text/">text</a>&#8216; and &#8216;<a href="http://api.jquery.com/attr/">attr</a>&#8216; functions, you have complete control over your templates, without having to remember to escape html. Your templates can be stored away in an external javascript file and everyone&#8217;s happy.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/07/27/super-simple-jquery-templating/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Ramble&#8221;, the Javascript Cucumber Port (work in progress)</title>
		<link>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/</link>
		<comments>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 02:27:12 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=608</guid>
		<description><![CDATA[I am a great fan of Cucumber when it comes to integration testing, however testing heavy use of Javascript can be a little tedious. I have looked into the different solutions out there such as Selenium but found them all to be fiddly to setup, however Capybara helps on this front. I was thinking, what [...]]]></description>
			<content:encoded><![CDATA[<p>I am a great fan of <a href="http://cukes.info/">Cucumber</a> when it comes to integration testing, however testing heavy use of Javascript can be a little tedious.</p>
<p>I have looked into the different solutions out there such as <a href="http://seleniumhq.org/">Selenium</a> but found them all to be fiddly to setup, however <a href="http://github.com/jnicklas/capybara">Capybara</a> helps on this front. I was thinking, what if Cucumber could run in the browser? No need for Javascript adapters or XML parsers, Safari/Chrome/Firefox already do a great job of this. Manipulating the page such as filling in forms, clicking links etc. could all be done with jQuery, in a very concise manor.</p>
<p>I decided to create a proof-of-concept while it was still fresh in my head. This is by no means a fully working release and the code leaves a lot to be desired in it&#8217;s current state, however it shows the benefits of a &#8220;Cucumber in the browser&#8221;. The main benefits I can see so far (for both javascript and non javascript apps) are:</p>
<ul>
<li><strong>Speed</strong> &#8211; browsers are getting extremely quick at this DOM stuff.</li>
<li><strong>Flexibility</strong> &#8211; everything happens client-side meaning you can easily test with any server technology.</li>
<li><strong>Simplicity</strong> &#8211; no need for complex javascript adapters, XML parsers etc.</li>
</ul>
<p>The basic file structure is very similar to Cucumber:</p>
<pre>
  - features
    index.html
    - js
        ramble.js
        jquery-1.4.2.js
      my.feature
    - steps
        web-steps.js
    - support
        paths.js
</pre>
<p>Step definitions can be defined in plain old javascript files with plain old jQuery, in this case web-steps.js. Currently the step definition are expected to throw an error if they cannot be fulfilled, this may change when a solid API is nailed down:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #006600; font-style: italic;">// The value of 'this' is the current document as a jQuery object.</span>
  ramble.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^I follow &quot;(.+)&quot;$/</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>link_text<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> link_text<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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>link.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Can't find link: &quot;</span> <span style="color: #339933;">+</span> link_text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    link.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Scenarios are exactly the same as in Cucumber, so you can do something like the following:</p>
<pre>
  Scenario: User fill out a form
    Given I am on the homepage
    And I follow "Tell us your name"
    And I fill in "First name" with "Jamie"
    And I fill in "Last name" with "Hill"
    And I press "Submit"
    Then I should see "Thank you for your details."
</pre>
<p>You can now simply drop the features folder into the public area of your app and visit the url in your browser. You should see the relevant steps go green or red as the app is navigated in an iFrame.</p>
<p>I plan to first tidy up the API (and unit test) and then aid the writing of scenarios by adding the ability to record them within the browser (Selenium style).</p>
<p>I&#8217;d like to hear peoples views on this&#8230; please don&#8217;t be too hard on the code, it&#8217;s more of a mind-dump than anything else at this stage (around 100 lines). There is an example of testing a static site included so just load the features/index.html file in your browser to see it run.</p>
<p>  <a href="http://github.com/soniciq/ramble">http://github.com/soniciq/ramble</a></p>
<p><strong>Update 04/07/10:</strong> As noted by Andrew in the comments, you will need a server running in order for browsers to get access to the pages for testing.</p>
<p>I have added a simple server script allowing the features to be run locally (requires Ruby). If you want to see it in action, just run:</p>
<pre>
cd /path/to/ramble/checkout
ruby server.rb
</pre>
<p>&#8230;and then visit <a href="http://localhost:1234/features">http://localhost:1234/features</a> in your browser (tested in Firefox, Chrome and Safari). Note that Ramble is not at all dependent on Ruby, it is just used for running a local test server.</p>
<h3>Screenshot</h3>
<p><a href="http://thelucid.com/files/ramble-in-action.png"><img src="http://thelucid.com/files/ramble-in-action-300x241.png" alt="Ramble in action" title="Ramble in action" width="300" height="241" class="aligncenter size-medium wp-image-620" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/07/04/ramble-the-javascript-cucumber-port/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>No &#8216;a:visited&#8217; in Safari 5&#8230; jQuery to the rescue?</title>
		<link>http://thelucid.com/2010/06/10/no-avisited-in-safari-5-jquery-to-the-rescue/</link>
		<comments>http://thelucid.com/2010/06/10/no-avisited-in-safari-5-jquery-to-the-rescue/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 15:36:12 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jquery safari javascript]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=597</guid>
		<description><![CDATA[With the release of Safari 5, it seems that the &#8216;:visited&#8217; CSS pseudo selector no longer takes affect. I completely understand it being removed due to breadcrumb sniffing but from a user&#8217;s perspective, differentiating between links that you have visited and those that you have not is very handy. jQuery to the rescue Using jQuery, [...]]]></description>
			<content:encoded><![CDATA[<p>With the release of <a href="http://www.apple.com/safari/">Safari 5</a>, it seems that the &#8216;:visited&#8217; CSS pseudo selector no longer takes affect. I completely understand it being removed due to <a href="http://ajaxian.com/archives/stop-sniffing-my-breadcrumbs">breadcrumb sniffing</a> but from a user&#8217;s perspective, differentiating between links that you have visited and those that you have not is very handy.</p>
<h3>jQuery to the rescue</h3>
<p>Using <a href="http://jquery.com/">jQuery</a>, we can easily add this functionality back in, without the XSS problems associated with the browser handling it.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a:not(.visited)'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'visited'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can then go ahead and set a different style for links that have the &#8216;visited&#8217; class.</p>
<p>The problem with this approach is that it will only work for links opened in a separate window or tab and not persist when you leave the current page, as all added classes will obviously be removed. There is probably a way to store a list of which links have been visited in a cookie, however each link would need a unique identifier&#8230; something for another time.</p>
<h3>Update</h3>
<p>It seems that the &#8216;:visited&#8217; selector does work in some cases in Safari 5 but not sure of the circumstances, can anyone shed any light on this?</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/06/10/no-avisited-in-safari-5-jquery-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>To SproutCore, or not to SproutCore&#8230;</title>
		<link>http://thelucid.com/2010/04/09/to-sproutcore-or-not-to-sproutcore/</link>
		<comments>http://thelucid.com/2010/04/09/to-sproutcore-or-not-to-sproutcore/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 19:02:47 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=579</guid>
		<description><![CDATA[I&#8217;ve been debating over the past week whether or not to use SproutCore for a large application I am working on. What follows are my initial thoughts on the framework, likes and dislikes. A fight with what&#8217;s right Right, I&#8217;m afraid I&#8217;m going to start with a negative in the hope that I can focus [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been debating over the past week whether or not to use <a href="http://www.sproutcore.com/">SproutCore</a> for a large application I am working on. What follows are my initial thoughts on the framework, likes and dislikes.</p>
<h3>A fight with what&#8217;s right</h3>
<p>Right, I&#8217;m afraid I&#8217;m going to start with a negative in the hope that I can focus more on the positives for the rest of the post.</p>
<p>I have been an advocate of Web Standards in the running on <a href="http://soniciq.com">SonicIQ</a> over the past 10 years, with this has come the adoption of <a href="http://en.wikipedia.org/wiki/Progressive_enhancement">Progressive Enhancement</a> using <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">Unobtrusive Javascript</a>. Now along come two cutting edge frameworks, <a href="http://www.sproutcore.com/">SproutCore</a> and <a href="http://en.wikipedia.org/wiki/Cappuccino">Cappuccino</a> who completely abandon this culture in search of a desktop-like feel to web apps.</p>
<p>Having been an early adopter of techniques like <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">Unobtrusive Javascript</a> and seeing the benefits they offer, I am reluctant to give the finger to those without Javascript, even if this is now a small minority. With the advent of HTML5 I suppose this becomes less of an issue as Javascript is one of the many standards under the whole HTML5 umbrella and is just expected to exist. I can&#8217;t help feeling a little dirty though having a page of just script tags.</p>
<p>Am I being too &#8220;precious&#8221; about <a href="http://en.wikipedia.org/wiki/Fault-tolerant_system">Graceful Degradation</a>, or is this still relevant with the arrival of HTML5?</p>
<h3>Fat Client</h3>
<p>Both <a href="http://www.sproutcore.com/">SproutCore</a> and <a href="http://en.wikipedia.org/wiki/Cappuccino">Cappuccino</a> opt for the &#8220;Fat Client&#8221; methodology, for anyone who has not heard of this (other than in the literal sense), this means that the client (browser) is made to do more of the grunt work usually accomplished by the server. This has a huge benefit of making the app feel much &#8220;snappier&#8221;, as common calculations, concatenations etc. are all done on the client-side, reducing the amount/size of calls to the server. Your server-side app acts more like a dumb data store, using REST to communicate data back and forth.</p>
<p>The downside to fat clients (I won&#8217;t do the obvious joke), is that there is a chance that your audience will see more than you want them too when visiting &#8220;View Source&#8221;. You obviously don&#8217;t want to give away Granddad&#8217;s age-old secret hangover cure in the Javascript source, however as long as you&#8217;re sensible and keep the business logic that is of any real value at the server-side, all should be fine.</p>
<h3>Fat Framework</h3>
<p>Unfortunately, in order to have the additional work handled by the client, you have to feed it more Javascript. The whole of <a href="http://www.sproutcore.com/">SproutCore</a> comes in at an impressive 500Kb uncompressed! That said, it will compress down to 100Kb when minified and gzipped.</p>
<p>Lets say you went with plain old <a href="http://jquery.com/">jQuery</a> as it&#8217;s smaller, and you&#8217;ll just add plugins for the bit&#8217;s you need. Well, by the time you include a chunk of <a href="http://jqueryui.com/">jQueryUI</a> when you want to be able to sort lists and drag stuff around&#8230; you&#8217;ve soon hit that 100Kb threshold.</p>
<p>So&#8230; is the size really an issue by the time it&#8217;s all been cached by the browser, images sprited, scripts concatenated into one file etc?</p>
<h3>Alternatives</h3>
<h4>Cappuccino</h4>
<p>One of the alternatives already mentioned is <a href="http://en.wikipedia.org/wiki/Cappuccino">Cappuccino</a>. To me the instant turn-off was <a href="http://cappuccino.org/learn/">Objective-J</a>, it&#8217;s very clever and all that but do I really want to have to learn another language when I already have Javascript under my belt. <a href="http://cappuccino.org/learn/">Objective-J</a> may have the benefit of easing portability to desktop apps, however I can&#8217;t see that this will ever be a flawless process.</p>
<h4>UKIJS</h4>
<p>Another lightweight alternative is <a href="http://ukijs.org/">UKIJS</a> which aims to bring the core UI element of the aforementioned frameworks, without the kitchen sink that comes with it.</p>
<p>I&#8217;ve had a brief play with <a href="http://ukijs.org/">UKIJS</a> and generally love the concept, however I can&#8217;t help but think it would be better built on top of jQuery instead of borrowing so much of the internals. Also as it is a young project, there are large gaps in the functionality, such as reordering of lists, custom cells in list view etc.</p>
<p>This is definitely one to watch as it seems like a great light-weight alternative to it&#8217;s bulkier competition.</p>
<h3>Conclusion</h3>
<p>I have only scratched the surface in my search for the best framework out of these options. My next job is to play with <a href="http://www.sproutcore.com/">SproutCore</a> a little more, to see if it caters for what I need.</p>
<p>Has anyone else had experience with these frameworks? What was the conclusion? Should we just abandon <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">Unobtrusive Javascript</a> when building web &#8220;Apps&#8221; and use it only for web &#8220;Sites&#8221;?</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2010/04/09/to-sproutcore-or-not-to-sproutcore/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>jQuery Colorbox within &#8220;overflow:hidden&#8221; container in Webkit</title>
		<link>http://thelucid.com/2009/12/29/jquery-colorbox-within-overflowhidden-container-in-webkit/</link>
		<comments>http://thelucid.com/2009/12/29/jquery-colorbox-within-overflowhidden-container-in-webkit/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 19:35:06 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[js jquery colorbox webkit fix bug]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=518</guid>
		<description><![CDATA[Wow, that&#8217;s a mouthful of a title. Just run into an interesting bug in Webkit I believe. When using Colorbox on a link contained inside a div who&#8217;s overflow attribute was set to hidden, the div was being scrolled to the bottom when hitting the &#8220;close&#8221; link of the colorbox. This only seemed to happen [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, that&#8217;s a mouthful of a title.</p>
<p>Just run into an interesting bug in Webkit I believe. When using <a href="http://colorpowered.com/colorbox/">Colorbox</a> on a link contained inside a div who&#8217;s overflow attribute was set to hidden, the div was being scrolled to the bottom when hitting the &#8220;close&#8221; link of the colorbox. This only seemed to happen in Webkit browsers.</p>
<p>The solution was to watch for a scroll event on the div in question and scroll back to 0:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> viewer <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#viewer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  viewer.<span style="color: #000066;">scroll</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> viewer.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Obviously, this is only a fix when you require your content to always be scrolled to the top, however this could serve as a starting point for other scenarios.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2009/12/29/jquery-colorbox-within-overflowhidden-container-in-webkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

