<?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>JavaScriptly &#187; Development News</title> <atom:link href="http://javascriptly.com/category/development-news/feed/" rel="self" type="application/rss+xml" /><link>http://javascriptly.com</link> <description>JavaScript Techniques, Tricks and News</description> <lastBuildDate>Thu, 07 Jan 2010 13:47:39 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Prototype vs Class Inheritance in YUI 3</title><link>http://javascriptly.com/2010/01/prototype-vs-class-inheritance-in-yui-3/</link> <comments>http://javascriptly.com/2010/01/prototype-vs-class-inheritance-in-yui-3/#comments</comments> <pubDate>Thu, 07 Jan 2010 11:27:02 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Development News]]></category> <category><![CDATA[Solution]]></category> <category><![CDATA[OOP]]></category> <category><![CDATA[YUI 3.x]]></category><guid isPermaLink="false">http://javascriptly.com/?p=142</guid> <description><![CDATA[As I mentioned in the post YUI 3.0 – Changes From the Root, YUI 3 is a radical evolvement of the framework. One of the most interesting features it provides with is about much better support for OOP. YUI 3 supports two inheritance patterns via object prototype and “class”. Let’s examine the differences and advantages of [...]]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">As I mentioned in the post <a title="Permanent Link to YUI 3.0 – Changes From the Root" href="http://javascriptly.com/2008/08/yui-30-changes-from-the-root/">YUI 3.0 – Changes From the Root</a>, <a href="http://developer.yahoo.com/yui/3/" target="_blank">YUI 3</a> is a radical evolvement of the framework. One of the most interesting features it provides with is about much better support for OOP.</p><p style="text-align: justify;">YUI 3 supports two inheritance patterns via object prototype and “class”. Let’s examine the differences and advantages of each pattern.</p><p><a href="http://javascriptly.com/wp-content/uploads/2010/01/yui3-logo.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2010/01/yui3-logo.png" alt="" title="yui3-logo" width="464" height="255" class="alignleft size-full wp-image-143" /></a></p><h2>Prototypal Inheritance in YUI 3</h2><p style="text-align: justify;"><a href="http://javascript.crockford.com/prototypal.html" target="_blank">Suggested by Douglas Crockford</a>, prototypal inheritance pattern is to deal with objects, i.e. objects inherit from objects. YUI 3 supports prototypal inheritance from its core; it means you can utilize the pattern by including the seed file only:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> 
    src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div><p style="text-align: justify;">Now, for example, we have an object named <code>animal</code>:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> animal <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #339933;">,</span>
    level<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">,</span>
    say<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>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;I am an &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; at &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">level</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; level.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>animal.<span style="color: #660066;">say</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// I am an Animal at top level.</span></pre></div></div><p style="text-align: justify;">And you want to create an <code>elephant</code> object that is an inheritance of <code>animal</code>. It’s so easy to 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> elephant <span style="color: #339933;">=</span> Y.<span style="color: #660066;">Object</span><span style="color: #009900;">&#40;</span>animal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p style="text-align: justify;">Of course, you’ll need to modify the newly-born creature to make it a true elephant by overriding its parent properties and adding some new ones:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// override an animal’s property</span>
elephant.<span style="color: #660066;">level</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;second&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// add elephant’s own properties</span>
elephant.<span style="color: #660066;">trunk</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
elephant.<span style="color: #660066;">tusks</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span></pre></div></div><p style="text-align: justify;">However if you want the elephant to say more about its own belongings, you’ll have to redefine <code>say</code> method completely.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">elephant.<span style="color: #660066;">say</span> <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>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;I am an &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; at &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">level</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; level.&quot;</span>
        <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; I have &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">trunk</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; trunk and &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">tusks</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; tusks.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>elephant.<span style="color: #660066;">say</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// I am an Animal at second level. I have 1 trunk and 2 tusks.</span></pre></div></div><p>I think this pattern is quite easy to understand but before going forward to the next one, here are what we learn from it:</p><ol><li style="text-align: justify;">We can      create a new object that inherits all the properties and methods from an      existing object.</li><li style="text-align: justify;">We can      customize the new object by overwriting some/all of the members or adding      new ones.</li><li style="text-align: justify;"><p style="text-align: justify;">The dark part is an overwritten property has no way to reference its parent’s property.</p><p style="text-align: justify;"><strong>Note:</strong> In this pattern, the child’s properties do not really overwrite its parent’s ones but they just take higher precedence. So if we delete a child’s method, the parent’s one will be back magically. For example:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">delete</span> elephant.<span style="color: #660066;">say</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>elephant.<span style="color: #660066;">say</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// I am an Animal at second level.</span></pre></div></div></li></ol><h2>“Class” Inheritance in YUI 3</h2><p style="text-align: justify;">Yes, I know there are no true classes in JavaScript, however we can make <strong>constructor functions act like classes</strong> for OOP (you can read more from the book <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FObject-Oriented-JavaScript-high-quality-applications-libraries%2Fdp%2F1847194141%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1262840077%26sr%3D8-1&amp;tag=feed0e-20&amp;linkCode=ur2&amp;camp=178" target="_blank">Object-Oriented JavaScript</a> by Stoyan Stefanov).</p><p style="text-align: justify;"><strong>Note:</strong> From now on, for easier to understand the pattern, I’ll call all constructor functions (that are capitalized in examples) classes; don’t be confused.</p><p style="text-align: justify;">First, we’ll mimic above example by creating  <code>Animal</code> and <code>Elephant</code> classes as follows:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// parent class</span>
<span style="color: #003366; font-weight: bold;">function</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// parent’s properties</span>
Animal.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getName</span> <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>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
Animal.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #000066;">name</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// child class</span>
<span style="color: #003366; font-weight: bold;">function</span> Elephant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div><p style="text-align: justify;">YUI 3 supports class inheritance via <a href="http://developer.yahoo.com/yui/3/api/YUI%7Eoop.html">oop</a> module and because this is used widely by almost all other modules, you’ll rarely have to include it explicitly. However, for testing, just call <code>Y.extend()</code> method within <code>oop</code>’s scope (that let <code>Elephant</code> inherit <code>Animal</code> as you can guess):</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YUI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #003366; font-weight: bold;">use</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'oop'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>Y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    Y.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Elephant<span style="color: #339933;">,</span> Animal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// test code here</span>
    <span style="color: #006600; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Next we’ll do some tests:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create an object of Elephant</span>
<span style="color: #003366; font-weight: bold;">var</span> jumbo <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Elephant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// undefined</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #660066;">getName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// function</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// set name for the Elephant object			</span>
jumbo.<span style="color: #660066;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Jumbo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #660066;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Jumbo</span></pre></div></div><p style="text-align: justify;">You can see from the example, <code>jumbo</code> object which is an instance of <code>Elephant</code> class only inherit members of the prototype, not “private” members from parent’s class and it is considered a good practice to leave all instance-specific properties as private properties and to add all the public functionality to the prototype.</p><p style="text-align: justify;">Interestingly we can add some new properties with default values to child class via arguments of <code>Y.extend()</code>, for example, to add trunk and tusks to <code>Elephant</code> class:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create an object of Elephant “class”</span>
<span style="color: #003366; font-weight: bold;">var</span> jumbo <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Elephant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// undefined</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #660066;">getName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// function</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// set name for the elephant				</span>
jumbo.<span style="color: #660066;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Jumbo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #660066;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Jumbo</span></pre></div></div><p style="text-align: justify;">Last but not least, class inheritance has very powerful feature: <code>superclass</code> access. To see how it works, we’ll add a method to <code>Animal</code> class to let it say something.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// parent class</span>
<span style="color: #003366; font-weight: bold;">function</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// parent’s method</span>
Animal.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">say</span> <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>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;I am an animal.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div><p style="text-align: justify;">Then, we’ll overwrite say method in <code>Elephant</code> class, yet still be able to keep what <code>Animal</code> can say about.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Y.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Elephant<span style="color: #339933;">,</span> Animal<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>trunk<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> tusks<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
Elephant.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">say</span> <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>
    	  <span style="color: #000066; font-weight: bold;">return</span> Elephant.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">say</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> 
		<span style="color: #3366CC;">&quot; I have &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">trunk</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; trunk and &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">tusks</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; tusks.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// test</span>
jumbo <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Elephant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #660066;">say</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// I am an animal. I have 1 trunk and 2 tusks.</span></pre></div></div><p style="text-align: justify;">In summary, “class” inheritance pattern in YUI 3 is more powerful than prototypal counterpart though harder to get it full, here are some important points:</p><ol><li style="text-align: justify;">YUI 3      allows us to implement inheritance at (pseudo) class level in JavaScript.</li><li style="text-align: justify;">Inherited      classes cannot directly access to parent’s own members, children only      inherit prototype members by default.<p style="text-align: justify;"><strong>Note:</strong> Well, it is possible to inherit parent’s own properties by initializing the parent constructor from the child (but it is not always a good OOP practice). See example:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// parent class</span>
<span style="color: #003366; font-weight: bold;">function</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// child class</span>
<span style="color: #003366; font-weight: bold;">function</span> Elephant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// initialize the parent using the child as &quot;this&quot;</span>
    Elephant.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Y.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Elephant<span style="color: #339933;">,</span> Animal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// test</span>
jumbo <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Elephant<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>jumbo.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Animal</span></pre></div></div></li><li style="text-align: justify;">You      can gain access to the parent’s overridden methods via superclass.</li></ol><h2>Conclusion</h2><p style="text-align: justify;">Code reuse is considered as the most confusing part of JavaScript for it lacks robust OOP features that many modern programming languages provide by default. YUI 3 with the two inheritance patterns we’ve gone through is trying to fill the gap.</p><p style="text-align: justify;">Prototypal inheritance is easier to understand but limit in object inheritance only. To get full OO support in YUI 3, it is advisable to study “class” inheritance pattern provided by the framework.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/" rel="bookmark">corMVC: An jQuery-based MVC Framework</a></li><li><a href="http://javascriptly.com/2008/08/is-future-of-javascript-in-harmony/" rel="bookmark">Is Future of JavaScript in Harmony?</a></li><li><a href="http://javascriptly.com/2010/01/why-do-we-need-google-closure/" rel="bookmark">Why Do We Need Google Closure?</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2010/01/prototype-vs-class-inheritance-in-yui-3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Why Do We Need Google Closure?</title><link>http://javascriptly.com/2010/01/why-do-we-need-google-closure/</link> <comments>http://javascriptly.com/2010/01/why-do-we-need-google-closure/#comments</comments> <pubDate>Tue, 05 Jan 2010 03:52:26 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Development News]]></category> <category><![CDATA[Compressor]]></category> <category><![CDATA[Google]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Lib]]></category><guid isPermaLink="false">http://javascriptly.com/?p=136</guid> <description><![CDATA[Why Google Closure?When a new JavaScript library arrives, a question is often raised reasonably: “Why does the world need another library?” while we’ve already had too many good ones like jQuery, Prototype, Mootools, YUI… you name it. To find the right answer, just have a look at the package offered by Google under the name of [...]]]></description> <content:encoded><![CDATA[<h2>Why Google Closure?</h2><p><img src="http://javascriptly.com/wp-content/uploads/2010/01/google-closure-logo.png" alt="" title="google-closure-logo" width="128" height="128" class="alignleft size-full wp-image-139" /></p><p style="text-align: justify;">When a new JavaScript library arrives, a question is often raised reasonably: “<em>Why does the world need another library?</em>” while we’ve already had too many good ones like jQuery, Prototype, Mootools, YUI… you name it.</p><p style="text-align: justify;">To find the right answer, just have a look at the package offered by Google under the name of <a href="http://code.google.com/closure/" target="_blank">Closure project</a>. We’ll find there three sub-projects:</p><ol><li style="text-align: justify;"><strong><a href="http://code.google.com/closure/compiler/" target="_blank">Closure Compiler</a></strong>: a JavaScript optimizer.      This is not a “<em>yet</em> <em>another JavaScript compressor</em>”, it      can do more: Besides compressing your codes it can analyze your      code and remove “dead” parts, correct wrong syntax, check variable      references/types, warn about common pitfalls. The really good news is it      comes with a Firebug extension, called Closure Inspector, that allows us      to debug compressed code by linking obfuscated lines to original ones.</li><li style="text-align: justify;"><strong><a href="http://code.google.com/closure/library/" target="_blank">Closure Library</a></strong>: a JavaScript library (as we expect) intended for use with  Closure Compiler. Basically it can do all the common tasks like other libs such as DOM manipulation, server communication, animation/effect and encloses a large set of reusable UI widgets and controls.</li><li style="text-align: justify;"><strong><a href="http://code.google.com/closure/templates/" target="_blank">Closure Templates</a></strong>: is not just a client-side JavaScript template engine like Pure but can be used in server-side with Java.</li></ol><p style="text-align: justify;"><strong>Closure Library</strong> is a big library with more than 400 JavaScript files well organized into Java-like directory structure. We’ll find there something like packages, classes/sub-classes with Java-doc syntax description (in fact, you know, there are no true packages/classes in JavaScript.)</p><p><span id="more-136"></span></p><p style="text-align: justify;">Google don’t boast the library in term of better speed or DOM manipulation techniques, the advantages of Closure lie in application deployment. Powered by <strong>Closure Compiler</strong>, application using <strong>Closure Library</strong> can be highly object-oriented in development while can be compact, fast and safe in production. An example is worth a thousand words, so let’s see <a href="http://code.google.com/closure/library/docs/gettingstarted.html">official “<em>Hello World</em>” application</a> in development and deployment.</p><h3>1. JavaScript</h3><p style="text-align: left;">+ Get and put the lib into a directory called <code>closure-library-read-only</code></p><p style="text-align: left;">+ Create a JavaScript file (<code>hello.js</code>):</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">goog.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'goog.dom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> sayHi<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> newHeader <span style="color: #339933;">=</span> goog.<span style="color: #660066;">dom</span>.<span style="color: #660066;">createDom</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'h1'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'style'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'background-color:#EEE'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Hello world!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    goog.<span style="color: #660066;">dom</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #339933;">,</span> newHeader<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p style="text-align: justify;">The most notable line is the first line that <strong>dynamically</strong> includes <code>goog.dom</code> for DOM manipulation (which is defined in <code>dom/dom.js</code> file). All other “packages” can be included in the same way.</p><h3>2. HTML</h3><p style="text-align: left;">Now, create a HTML to display the result (<code>hello.html</code>):</p><div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;closure-library-read-only/closure/goog/base.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;hello.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body</span> <span style="color: #000066;">onload</span>=<span style="color: #ff0000;">&quot;sayHi()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p style="text-align: justify;">We’ll need to add <code>base.js</code> which is a bootstrap file to load other JavaScript files required and of course the <code>hello.js</code> file we’ve just created.</p><h3>3. Deployment</h3><p style="text-align: justify;">The above example works as long as you don’t mind to deploy 400+ files and let the application load all necessary JavaScript files (12 files weighted 356KB as captured image from Firebug below).</p><p style="text-align: left;"><a rel="lightbox" href="http://javascriptly.com/wp-content/uploads/2010/01/google-closure-hello-world-js-files.png"><img class="size-medium wp-image-137 aligncenter" title="google-closure-hello-world-js-files" src="http://javascriptly.com/wp-content/uploads/2010/01/google-closure-hello-world-js-files-499x139.png" alt="Google Closure JS Files Loaded" width="499" height="139" rel="lightbox" /></a></p><p style="text-align: justify;">However, thinking of an application with hundreds of JavaScript files required, usability would be a nightmare for this approach and that’s why Google provides a tool named <strong><a href="http://code.google.com/closure/library/docs/calcdeps.html">Dependency Calculation Script</a></strong> to relief the pain. The tool, as its name implies, can calculate dependencies for application and create a single JavaScript file. Using the tool in conjunction with <strong>Closure Compiler</strong> to remove redundant code you will end up with perfect result: all-in-one, small, fast and safe JavaScript file.</p><p style="text-align: justify;">Here is how to create the final script:</p><div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">closure-library-read-only<span style="color: #000000; font-weight: bold;">/</span>closure<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>calcdeps.py <span style="color: #660033;">-i</span> hello.js \
  <span style="color: #660033;">-p</span> closure-library-read-only <span style="color: #660033;">-o</span> compiled \
  <span style="color: #660033;">-c</span> compiler.jar \
  <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;--compilation_level=ADVANCED_OPTIMIZATIONS&quot;</span> \
  <span style="color: #000000; font-weight: bold;">&gt;</span> hello-compiled.js</pre></div></div><p style="text-align: justify;"><strong>Note:</strong> Because the advanced optimization functionality of <strong>Closure Compiler</strong> is to include only code portions that are called in file, before running above compilation command you’ll need to modify script <code>hello.js</code> slightly to execute <code>onload</code> function as follows:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">goog.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'goog.dom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> sayHi<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> newHeader <span style="color: #339933;">=</span> goog.<span style="color: #660066;">dom</span>.<span style="color: #660066;">createDom</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'h1'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'style'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'background-color:#EEE'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Hello world!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    goog.<span style="color: #660066;">dom</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #339933;">,</span> newHeader<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
window.<span style="color: #000066;">onload</span> <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>
    sayHi<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: #339933;">;</span></pre></td></tr></table></div><p>And don’t forget to remove <code>onload</code> call from HTML:</p><div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;hello-compiled.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p style="text-align: justify;">Now, look at the final result: a 3KB JavaScript file loaded in 64ms vs 356KB in 414ms respectively of un-optimized version that interprets to more than one hundred times better in size and seven times better in loading speed. (FYI, gzipping output, we’ll have less than 1KB file load only).</p><p><a href="http://javascriptly.com/wp-content/uploads/2010/01/google-closure-hello-world-js-files-optimized.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2010/01/google-closure-hello-world-js-files-optimized-500x56.png" alt="Google Closure JS File Load Optimized" title="google-closure-hello-world-js-files-optimized" width="500" height="56" class="aligncenter size-medium wp-image-138" /></a></p><h2>Conclusion</h2><p style="text-align: justify;">I neither see <strong>Closure Library</strong> as yet-another-JS-lib nor see <strong>Closure Compiler</strong> as yet-another-JS-compressor. They together provide a complete solution to create and deploy sophisticated web apps with confidence.</p><p style="text-align: justify;">It would not be a surprise that Google developers are using similar tools internally to create great web apps like GMail, Wave so it makes sense that we can utilize Closure to build a web application with the same level of efficiency, completion and beauty.</p><ul><li><strong><a href="http://javascriptly.com/examples/google-closure-example.zip">Download Example Code</a></strong></li></ul><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/javascript-in-google-chrome/" rel="bookmark">JavaScript in Google Chrome Not So That Fast</a></li><li><a href="http://javascriptly.com/2008/08/yui-30-changes-from-the-root/" rel="bookmark">YUI 3.0 – Changes From the Root</a></li><li><a href="http://javascriptly.com/2008/09/lightningdom-to-balance-dom-vs-innerhtml/" rel="bookmark">LightningDOM to Balance DOM vs innerHTML</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2010/01/why-do-we-need-google-closure/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Something for Christmas: Snowfall in Picture</title><link>http://javascriptly.com/2009/12/something-for-christmas-snowfall-in-picture/</link> <comments>http://javascriptly.com/2009/12/something-for-christmas-snowfall-in-picture/#comments</comments> <pubDate>Wed, 23 Dec 2009 07:05:26 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Misc]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[effect]]></category> <category><![CDATA[snowfall]]></category><guid isPermaLink="false">http://javascriptly.com/?p=62</guid> <description><![CDATA[ Now it is time for Christmas and if you want to add some snows to a picture like the below example, a cool jQuery plugin &#8212; created by Jason Brown &#8212; can come to help.View Live Demo Download PluginJust include the plugin along with the latest version of jQuery (1.3.2 currently) and initiate it as the [...]]]></description> <content:encoded><![CDATA[<p></p><p style="text-align: justify;">Now it is time for Christmas and if you want to add some snows to a picture like the below example, a cool jQuery plugin &#8212; created by <a href="http://www.somethinghitme.com/2009/12/20/snowfall-plugin-updated/" target="_blank">Jason Brown</a> &#8212; can come to help.</p><p><a href="http://javascriptly.com/wp-content/uploads/2009/12/snow-fall-in-picture.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2009/12/snow-fall-in-picture-500x378.png" alt="" title="snow-fall-in-picture" width="500" height="378" class="aligncenter size-medium wp-image-141" /></a></p><ul><li><strong><a href="http://javascriptly.com/examples/jquery-snowfall/">View Live Demo</a></strong></li><li><strong><a href="http://javascriptly.com/examples/jquery-snowfall/snowfall.jquery.zip">Download Plugin</a></strong></li></ul><p><span id="more-62"></span></p><p style="text-align: justify;">Just include the plugin along with the latest version of jQuery (1.3.2 currently) and initiate it as the following code</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#snow_window'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">snowfall</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		flakeCount <span style="color: #339933;">:</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span>
		flakeColor <span style="color: #339933;">:</span> <span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
		flakeIndex<span style="color: #339933;">:</span> <span style="color: #CC0000;">999999</span><span style="color: #339933;">,</span>
		minSize <span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
		maxSize <span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>
		minSpeed <span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span>
		maxSpeed <span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p style="text-align: justify;">where &#8220;<em>snow_window</em>&#8221; is the ID of target DIV in which snowflakes will fly. You can define number of snowflakes, their color, min/max sizes (just do not set too big sizes or they would look unnatural) and falling speed as parameters (<em>flakeCount</em>, <em>flakeColor</em> etc) in the initializing code.</p><p style="text-align: justify;">Of course, you can set the snowfall effect to the whole web page with</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;">snowfall</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p style="text-align: justify;"><strong>Tip:</strong> It won&#8217;t work properly with fixed positioning and you must explicitly set the target DIV with &#8220;<em>position: relative</em>&#8221; or you&#8217;ll see snow falling on top corner of the page instead.</p><p style="text-align: justify;">I hope you enjoy this Christmas and can surprise your friends with the snowfall effect.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2009/12/best-ie6-png-fixes/" rel="bookmark">Best IE6 “PNG Alpha-Transparency” Fixes</a></li><li><a href="http://javascriptly.com/2008/09/quick-useful-jquery-plugins/" rel="bookmark">Quick & Useful jQuery Plugins</a></li><li><a href="http://javascriptly.com/2009/12/firequery-an-introduction/" rel="bookmark">FireQuery - An Introduction</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2009/12/something-for-christmas-snowfall-in-picture/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>corMVC: An jQuery-based MVC Framework</title><link>http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/</link> <comments>http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/#comments</comments> <pubDate>Tue, 22 Dec 2009 10:16:28 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Solution]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[MVC]]></category><guid isPermaLink="false">http://javascriptly.com/?p=58</guid> <description><![CDATA[I know quite a few JavaScript MVC frameworks out there but corMVC is what makes me exited at most for a few reasons. corMVC stands for &#8220;client-only-required&#8221; Model-View-Controller and that means it does not depend on specific server-side technology. In case you want to demo something, it would be perfect if everything can be done on [...]]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">I know quite a few JavaScript MVC frameworks out there but <strong><a href="http://www.bennadel.com/resources/projects/cormvc/demo/index.htm#/" target="_blank">corMVC</a></strong> is what makes me exited at most for a few reasons.</p><p style="text-align: justify;"><strong>corMVC</strong> stands for &#8220;<strong>c</strong>lient-<strong>o</strong>nly-<strong>r</strong>equired&#8221; <strong>M</strong>odel-<strong>V</strong>iew-<strong>C</strong>ontroller and that means it does not depend on specific server-side technology. In case you want to demo something, it would be perfect if everything can be done on client side. Of course, you can save changes or load data from server (via Model) as the general illustration below.</p><div id="attachment_59" class="wp-caption alignnone" style="width: 510px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/cormvc-overview.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2009/12/cormvc-overview-500x238.png" alt="corMVC Overview" title="cormvc-overview" width="500" height="238" class="size-medium wp-image-59" /></a><p class="wp-caption-text">corMVC Overview</p></div><p style="text-align: justify;">Not like other JavaScript MVC solutions, <strong>corMVC</strong> is very simple and has very small footprint. It also does not require you to build the application using scaffolding or any other command-line utilities.</p><p><span id="more-58"></span></p><p style="text-align: justify;">The whole framework is actually a 19KB JavaScript file (not minified yet) named <em>Application.js<strong>,</strong></em> you&#8217;ll have to define models, views and controllers by yourself following the guidelines. It&#8217;s not hard especially for those who are familiar with modern MVC frameworks like Rails, Django or CakePHP.</p><p style="text-align: justify;">Running application built on <strong>corMVC</strong>, you&#8217;ll have almost the same impression of running a server-side MVC application for the URIs (after the hash, however) are changed based on actions. The following diagram is about how the framework detects URL changes and handles events accordingly.</p><p><a href="http://javascriptly.com/wp-content/uploads/2009/12/mvc-workflow.png" rel="lightbox"><img src="http://javascriptly.com/wp-content/uploads/2009/12/mvc-workflow-500x462.png" alt="" title="mvc-workflow" width="500" height="462" class="alignnone size-medium wp-image-60" /></a></p><p style="text-align: justify;">To get an overview of how the framework works and the interaction of model-view-controller we are going to examine <a href="http://www.bennadel.com/resources/presentations/jquery2/demo/#/" target="_blank">the demo application</a> called &#8220;<strong>Contacts</strong>&#8221; provided by <a href="http://www.bennadel.com/" target="_blank">Ben Nadel</a> &#8212; the author of <strong>corMVC</strong>. The app, as its name tells, is a contact manager that has all basic functionalities like Search, View, Add and Delete contact info on a single web page.</p><div id="attachment_61" class="wp-caption alignnone" style="width: 510px"><a href="http://www.bennadel.com/resources/presentations/jquery2/demo/#/contacts" target="_blank"><img src="http://javascriptly.com/wp-content/uploads/2009/12/contacts-app-ui-500x290.png" alt="MVC Contacts application" title="contacts-app-ui" width="500" height="290" class="size-medium wp-image-61" /></a><p class="wp-caption-text">MVC Contacts application</p></div><p style="text-align: justify;">Let&#8217;s look at definition of a &#8220;contact&#8221; model in &#8220;<em>contact.js</em>&#8221; file.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Add model to the application.</span>
window.<span style="color: #660066;">application</span>.<span style="color: #660066;">addModel</span><span style="color: #009900;">&#40;</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: #339933;">,</span> application <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the contact class.</span>
	<span style="color: #003366; font-weight: bold;">function</span> Contact<span style="color: #009900;">&#40;</span> id<span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span> phone<span style="color: #339933;">,</span> email <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">||</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">phone</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>phone <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">email</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>email <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I validate the contact instance.</span>
	Contact.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">validate</span> <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>
		<span style="color: #006600; font-style: italic;">// For now, we are just goint to validate TRUE on the client and let</span>
		<span style="color: #006600; font-style: italic;">// the full validation happen on the model peristence.</span>
		<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Return a new model class.</span>
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> Contact <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">,</span> window.<span style="color: #660066;">application</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">The code define a contact class with a few properties like ID, Name, Phone# and E-mail address and return the class as a model that will be used by Controllers/Views.</p><p style="text-align: justify;">The controller is more interesting and it&#8217;s not too difficult to understand though.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Add a controller to the application.</span>
window.<span style="color: #660066;">application</span>.<span style="color: #660066;">addController</span><span style="color: #009900;">&#40;</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: #339933;">,</span> application <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the controller class.</span>
	<span style="color: #003366; font-weight: bold;">function</span> Controller<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Route URL events to the controller's event handlers.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">index</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">index</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/add/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addContact</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/edit/:id&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">editContact</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">route</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;/contacts/delete/:id&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deleteContact</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Set default properties.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactListView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Extend the core application controller (required).</span>
	Controller.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> application.<span style="color: #660066;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I initialize the controller. I get called once the application starts</span>
	<span style="color: #006600; font-style: italic;">// running. At that point, the DOM is available and all the other model</span>
	<span style="color: #006600; font-style: italic;">// and view classes will have been added to the system.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</span> <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>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactListView</span> <span style="color: #339933;">=</span> application.<span style="color: #660066;">getView</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ContactList&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span> <span style="color: #339933;">=</span> application.<span style="color: #660066;">getView</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ContactForm&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the add event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">addContact</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Show the form view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span><span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the edit event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">editContact</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event<span style="color: #339933;">,</span> id <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Show the form view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactFormView</span><span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the delete event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">deleteContact</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event<span style="color: #339933;">,</span> id <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Delete the contact.</span>
		application.<span style="color: #660066;">getModel</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ContactService&quot;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">deleteContact</span><span style="color: #009900;">&#40;</span>
			id<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>
				application.<span style="color: #660066;">relocateTo</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;contacts&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the default event for this controller.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">index</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Show the list view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactListView</span><span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I show the given view; but first, I hide any existing view.</span>
	Controller.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">showView</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> view<span style="color: #339933;">,</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Check to see if there is a current view. If so, then hide it.</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span>.<span style="color: #660066;">hideView</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span>.<span style="color: #660066;">hideView</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Show the given view.</span>
		view.<span style="color: #660066;">showView</span><span style="color: #009900;">&#40;</span> event.<span style="color: #660066;">parameters</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Store the given view as the current view.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentView</span> <span style="color: #339933;">=</span> view<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
	<span style="color: #006600; font-style: italic;">// ----------------------------------------------------------------------- //</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Return a new contoller instance.</span>
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> Controller<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">,</span> window.<span style="color: #660066;">application</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Basically, the controller defines routes for events associated with handlers like <em>addContact</em>, <em>editContact</em>, <em>deleteContact</em>. In most of cases, the handlers are to show appropriated views or to send events to model for updates.</p><p style="text-align: justify;">There are a number of views required by the app such as &#8220;<em>Contact List</em>&#8220;, &#8220;<em>Contact Form</em>&#8221; and a simple view for progress notification. Here are excerpt codes from &#8220;<em>Contact List</em>&#8221; view that mostly to interact with user and send events to controller if necessary.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// Add view to the application.</span>
window.<span style="color: #660066;">application</span>.<span style="color: #660066;">addView</span><span style="color: #009900;">&#40;</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: #339933;">,</span> application <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// I am the contact list view class.</span>
	<span style="color: #003366; font-weight: bold;">function</span> ContactList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">layout</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addLink</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactList</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactTemplate</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// I initialize the view. I get called once the application starts</span>
	<span style="color: #006600; font-style: italic;">// running. At that point, the DOM is available and all the other model</span>
	<span style="color: #006600; font-style: italic;">// and view classes will have been added to the system.</span>
	ContactList.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">init</span> <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>
		<span style="color: #003366; font-weight: bold;">var</span> self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Initialize properties.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">layout</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-layout&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-header form&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;input&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">addLink</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-header a&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactList</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactTemplate</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#contact-list-item-template&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Bind the search form submit.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchForm</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Hand of to the search form handler.</span>
				self.<span style="color: #660066;">searchFormHandler</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Cancel the default event.</span>
				<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</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: #006600; font-style: italic;">// Bind the keypress event on the search criteria.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Filter the contact list.</span>
				self.<span style="color: #660066;">filterList</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</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: #006600; font-style: italic;">// Bind the keypress event to the search criteria so we can track </span>
		<span style="color: #006600; font-style: italic;">// the use of the special keys presses.</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">keypress</span><span style="color: #009900;">&#40;</span>
			<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// Store the SHIFT and ALT key status of the current click.</span>
				self.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;shift&quot;</span><span style="color: #339933;">,</span> event.<span style="color: #660066;">shiftKey</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				self.<span style="color: #660066;">searchCriteria</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;alt&quot;</span><span style="color: #339933;">,</span> event.<span style="color: #660066;">altKey</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: #006600; font-style: italic;">// Bind the list-level clicking (to avoid setting to many </span>
		<span style="color: #006600; font-style: italic;">// event handlers).</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">contactList</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> event <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> event.<span style="color: #660066;">target</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Check to see if the target is the &quot;more&quot; link.</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;a.more&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Toggle the list item details.</span>
					self.<span style="color: #660066;">toggleDetails</span><span style="color: #009900;">&#40;</span> target.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;li&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Blur the current link.</span>
					target.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Prevent default event.</span>
					<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Check to see if the target is a the &quot;delete&quot; link.</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;a.delete&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Blur the current link.</span>
					target.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Confirm that the user wants to delete the contact.</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Delete this contact?&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
						<span style="color: #006600; font-style: italic;">// This is a *hack* that we have to do since jQuery click() </span>
						<span style="color: #006600; font-style: italic;">// event won't trigger the default action of the link.</span>
						application.<span style="color: #660066;">setLocation</span><span style="color: #009900;">&#40;</span> target.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;href&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #009900;">&#125;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// Return false to cancel default event.</span>
					<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	....
&nbsp;
	<span style="color: #006600; font-style: italic;">// Return a new view class.</span>
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> ContactList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">,</span> window.<span style="color: #660066;">application</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Up till now, you may have had the overall knowledge of the framework and how to create a pure JavaScript MVC application. Yet, to get full understanding of <strong>corMVC</strong>, please see this great <a href="http://www.bennadel.com/resources/presentations/jquery2/video/">video presentation</a> in which Ben Nadel explains why he came to the framework, how the JavaScript/jQuery were used, step-by-step application building etc. (this is a multiple-part video and a bit lengthy but I&#8217;m sure it&#8217;ll pay off.)</p><ul><li><strong><a href="http://www.bennadel.com/resources/presentations/jquery2/code.zip">Download Demo Application Code</a></strong></li></ul><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/10-alternative-javascript-frameworks/" rel="bookmark">10 Alternative JavaScript Frameworks</a></li><li><a href="http://javascriptly.com/2008/09/chainjs-02-updated-examples/" rel="bookmark">Chain.js v0.2 – Updated Examples</a></li><li><a href="http://javascriptly.com/2008/09/comet-chat-app-meteor-server/" rel="bookmark">Simple Web Chat with Meteor Comet Server</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2009/12/coremvc-an-jquery-based-mvc-framework/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>FireQuery &#8211; An Introduction</title><link>http://javascriptly.com/2009/12/firequery-an-introduction/</link> <comments>http://javascriptly.com/2009/12/firequery-an-introduction/#comments</comments> <pubDate>Mon, 21 Dec 2009 06:41:37 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Firebug]]></category> <category><![CDATA[FireQuery]]></category><guid isPermaLink="false">http://javascriptly.com/?p=51</guid> <description><![CDATA[Installation FireQuery is an extension of Firebug created by BinaryAge to help developers to keep track with jQuery expressions, data and collections as expressed on tool website:Query expressions are intelligently presented in Firebug Console and DOM inspector attached jQuery data are first class citizens elements in jQuery collections are highlighted on hover jQuerify: enables you [...]]]></description> <content:encoded><![CDATA[<h2 style="text-align: justify;">Installation</h2><p style="text-align: justify;">FireQuery is an extension of Firebug created by <a href="http://www.binaryage.com/" target="_blank">BinaryAge</a> to help developers to keep track with jQuery expressions, data and collections as expressed on tool <a href="http://firequery.binaryage.com/" target="_blank">website</a>:</p><blockquote><ul><li> Query expressions are intelligently presented in Firebug Console and DOM inspector</li><li> attached jQuery data are first class citizens</li><li> elements in jQuery collections are highlighted on hover</li><li> jQuerify: enables you to inject jQuery into any web page</li></ul></blockquote><p style="text-align: justify;">You can install the tool from <a href="https://addons.mozilla.org/en-US/firefox/addon/12632" target="_blank">official Mozilla add-on page</a> (it requires Firebug 1.3+ already existed.) One note: You may have to find <a href="https://addons.mozilla.org/en-US/firefox/addons/versions/12632" target="_blank">an older version</a> (v0.3) to make it work with current official Firebug release (v1.4) as my experience on Windows.</p><h2 style="text-align: justify;">In Action</h2><p style="text-align: justify;">After installing the add-on and restarting Firefox, just go to <a href="http://firequery.binaryage.com/test/index.html" target="_blank">the test page</a> to see how FireQuery tracks embedded jQuery data on FireBug&#8217;s &#8220;<strong>HTML</strong>&#8221; tab. The image below illustrates the data embedded in accordance with the jQuery codes to inject them to the page.</p><p><span id="more-51"></span><br /><div id="attachment_53" class="wp-caption alignnone" style="width: 510px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/firequery-embedded-data.png" rel="lightbox"><img class="size-full wp-image-53" title="firequery-embedded-data" src="http://javascriptly.com/wp-content/uploads/2009/12/firequery-embedded-data.png" alt="FireQuery shows embedded data by jQuery" width="500" height="305" /></a><p class="wp-caption-text">FireQuery shows embedded data by jQuery</p></div></p><p style="text-align: justify;">Now, we&#8217;ll dig into cooler features. One of them is the ability to &#8220;jQuerify&#8221; any web page without jQuery support like <a href="http://www.google.com" target="_blank">Google.com</a> for example. This can be done simply by clicking &#8220;<strong>jQuerify</strong>&#8221; button on FireBug&#8217;s &#8220;<strong>Console</strong>&#8221; tab.</p><div id="attachment_54" class="wp-caption alignnone" style="width: 509px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/firequery-jquerify-google-dot-com.png" rel="lightbox"><img class="size-medium wp-image-54" title="firequery-jquerify-google-dot-com" src="http://javascriptly.com/wp-content/uploads/2009/12/firequery-jquerify-google-dot-com-499x319.png" alt="jQuerify Google.com with FireQuery" width="499" height="319" /></a><p class="wp-caption-text">jQuerify Google.com with FireQuery</p></div><p style="text-align: justify;">Wow, now you can execute any jQuery codes in the Google home page. Normally, there is nothing happen when you click on Google logo but you just want it to say hello instead. Paste the following code snippet to Firebug command window and run 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;">'#logo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><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>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello, I'm Google!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</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><div id="attachment_55" class="wp-caption alignnone" style="width: 509px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/firequery-running-jquery-snippet.png" rel="lightbox"><img class="size-medium wp-image-55" title="firequery-running-jquery-snippet" src="http://javascriptly.com/wp-content/uploads/2009/12/firequery-running-jquery-snippet-499x130.png" alt="Running jQuery snippet on Google.com" width="499" height="130" /></a><p class="wp-caption-text">Running jQuery snippet on Google.com</p></div><p style="text-align: justify;">Now, click on Google&#8217;s logo and you&#8217;ll see the alert dialog appears to say hello to you (no surprise) and the FireBug&#8217;s console also shows the jQuery command executed.</p><div id="attachment_57" class="wp-caption alignnone" style="width: 510px"><a href="http://javascriptly.com/wp-content/uploads/2009/12/google-dot-com-saying-hello.png" rel="lightbox"><img class="size-medium wp-image-57" title="google-dot-com-saying-hello" src="http://javascriptly.com/wp-content/uploads/2009/12/google-dot-com-saying-hello-500x292.png" alt="Google.com to say hello" width="500" height="292" /></a><p class="wp-caption-text">Google.com to say hello</p></div><h2>Conclusion</h2><p>FireQuery is a great tool for those who commit to jQuery as main JavaScript library or is going to write a jQuery plug-in. Also, It&#8217;s especially useful for developers, theme designers to see the jQuery&#8217;s data and effects in action without loading the library and writing codes in the templates.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2010/01/why-do-we-need-google-closure/" rel="bookmark">Why Do We Need Google Closure?</a></li><li><a href="http://javascriptly.com/2008/09/javascript-in-google-chrome/" rel="bookmark">JavaScript in Google Chrome Not So That Fast</a></li><li><a href="http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/" rel="bookmark">JavaScript to Detect Google Chrome</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2009/12/firequery-an-introduction/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery Code Content Assistance for Eclipse WTP</title><link>http://javascriptly.com/2008/10/jquery-eclipse-wtp/</link> <comments>http://javascriptly.com/2008/10/jquery-eclipse-wtp/#comments</comments> <pubDate>Tue, 14 Oct 2008 03:16:23 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[WTP]]></category><guid isPermaLink="false">http://javascriptly.com/?p=48</guid> <description><![CDATA[JavaScript code content assistance built in Eclipse WTP does very good job that I found even better than the same functionality in some commercial solutions, however, jQuery&#8217;s syntax is not supported (no surprise). That&#8217;s why jQueryWTP tool comes to help adding jQuery support to Eclipse WTP (and Eclipse PDT, MyEclipse which are based on WTP [...]]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">JavaScript code content assistance built in Eclipse WTP does very good job that I found even better than the same functionality in some commercial solutions, however, jQuery&#8217;s syntax is not supported (no surprise). That&#8217;s why jQueryWTP tool comes to help adding jQuery support to Eclipse WTP (and Eclipse PDT, MyEclipse which are based on WTP too.)</p><p style="text-align: justify;">This is not an Eclipse plugin instead a tool to patch the existing plugin and inject jQuery&#8217;s syntax support into it. First <a href="http://sourceforge.net/project/showfiles.php?group_id=202840&amp;package_id=241633&amp;release_id=631407">download the tool from SourceForce</a>; it&#8217;s a Java executable JAR so you can double-click to it or run it from command line:</p><div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">java <span style="color: #660033;">-jar</span> jqueryWTP0.2forJQuery1.2.6.jar</pre></div></div><p style="text-align: justify;">Now browse to plugin file</p><p style="text-align: justify;"><code>org.eclipse.wst.javascript.ui_xxxxxxx.jar</code></p><p style="text-align: justify;">and set output directory to generate the patch. Please backup the original file and set output directory different from source one.</p><p>&nbsp;</p><p style="text-align: justify;"><img class="alignnone size-full wp-image-49" title="jquery-eclipse-wtp-ui" src="http://javascriptly.com/wp-content/uploads/2008/10/jquery-eclipse-wtp-ui.gif" alt="jquery-eclipse-wtp-ui.gif" width="492" height="138" /></p><p>&nbsp;</p><p style="text-align: justify;">Select &#8220;<strong>Generate</strong>&#8221; button to get the patched file then copy over original file. Start Eclipse and open a HTML or script file to see jQuery&#8217;s functions listed on code assistance like image below.</p><p><span id="more-48"></span></p><p>&nbsp;</p><p style="text-align: justify;"><img class="alignnone size-full wp-image-50" title="jquery-eclipse-wtp-code-assistance" src="http://javascriptly.com/wp-content/uploads/2008/10/jquery-eclipse-wtp-code-assistance.gif" alt="wtp-code-assistance.gif" width="500" height="429" /></p><p>&nbsp;</p><p style="text-align: justify;">Find more info about jQueryWTP and donate for project <a href="http://www.langtags.com/jquerywtp/index.html" target="_blank">here</a>.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2010/01/why-do-we-need-google-closure/" rel="bookmark">Why Do We Need Google Closure?</a></li><li><a href="http://javascriptly.com/2009/12/best-ie6-png-fixes/" rel="bookmark">Best IE6 “PNG Alpha-Transparency” Fixes</a></li><li><a href="http://javascriptly.com/2009/12/firequery-an-introduction/" rel="bookmark">FireQuery - An Introduction</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/10/jquery-eclipse-wtp/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>Zend Framework 1.6 Comes with Dojo and FirePHP Integrated</title><link>http://javascriptly.com/2008/09/zend-16-comes-dojo-firephp-integrated/</link> <comments>http://javascriptly.com/2008/09/zend-16-comes-dojo-firephp-integrated/#comments</comments> <pubDate>Tue, 09 Sep 2008 04:42:39 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Development News]]></category> <category><![CDATA[Dojo]]></category> <category><![CDATA[Firebug]]></category> <category><![CDATA[FirePHP]]></category> <category><![CDATA[Zend]]></category><guid isPermaLink="false">http://javascriptly.com/?p=30</guid> <description><![CDATA[Probably the biggest change in Zend Framework (ZF) 1.6 is about Ajax support with integration of famous Dojo JavaScript toolkit. ZF 1.6 comes with several new helpers, elements and components that help to display/interact with Dojo widgets as announced on Zend&#8217;s official site.A dojo() placeholder view helper to facilitate Dojo integration in    [...]]]></description> <content:encoded><![CDATA[<p></p><p style="text-align: justify;"><a href="http://framework.zend.com"><img class="alignnone size-full wp-image-31" title="Zend Framework 1.6 with Dojo Integration" src="http://javascriptly.com/wp-content/uploads/2008/09/zend_16_dojo.png" alt="" width="500" height="135" border="0" /></a></p><p style="text-align: justify;">Probably the biggest change in Zend Framework (ZF) 1.6 is about Ajax support with integration of famous <a href="http://www.dojotoolkit.org/">Dojo JavaScript toolkit</a>. ZF 1.6 comes with several new helpers, elements and components that help to display/interact with Dojo widgets as <a href="http://framework.zend.com/announcements/2008-09-03-dojo">announced on Zend&#8217;s official site</a>.</p><blockquote><ul type="disc"><li style="text-align: justify;">A dojo() placeholder view helper to facilitate Dojo integration in      your views, including setting up the required script and style tags, dojo.require      statements, and more. In essence, this supports and enhances Dojo&#8217;s      modularity at the application level.</li><li style="text-align: justify;">Zend_View helpers and Zend_Form elements and decorators that      utilize Dijit, Dojo&#8217;s layout and widget platform. This simplifies creation      of Zend_Form elements that can be rendered as Dijits. For instance, highly      interactive widgets such as calendar choosers, time selectors, and      combo-boxes are provided.</li><li style="text-align: justify;">Zend_Dojo_Data, a component for creating dojo.data-compatible      response payloads. dojo.data defines a standard storage interface;      services providing data in this format can then be consumed by a variety      of Dojo facilities to provide highly flexible and dynamic content for your      user interfaces.</li><li style="text-align: justify;">A JSON-RPC server component: Zend_Json_Server. JSON-RPC is a      lightweight remote procedure call protocol, utilizing JSON for its      serialization format; it is useful for sites that require a high volume of      interaction between the user interface and server-side data stores, as it      allows exposing your server-side APIs in a format directly accessible via      your client. Dojo has native JSON-RPC capabilities, and Zend Framework      provides a JSON-RPC implementation that is both compatible with Dojo and      the published specifications.</li></ul></blockquote><p><span id="more-30"></span></p><p style="text-align: justify;">In order to help developer track JavaScript bugs, ZF 1.6 also provides native support for <a href="http://www.firephp.org/">FirePHP</a>, a Firebug extension for PHP-Ajax development. Using ZF 1.6 now you can log to Firebug Console via FirePHP instantly, no need to download the <a href="http://www.firephp.org/Wiki/Libraries/FirePHPCore" target="_blank">FirePHPCore</a> library.</p><p style="text-align: justify;">Two primary components are available &#8212; Zend_Log_Writer_Firebug and Zend_Db_Profiler_Firebug &#8211; providing functionality to log (any info you want) and profile database queries to Firebug console. Read more how to utilize FirePHP in ZF 1.6 <a href="http://www.christophdorn.com/Blog/2008/09/02/firephp-and-zend-framework-16/">here</a>.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/10-alternative-javascript-frameworks/" rel="bookmark">10 Alternative JavaScript Frameworks</a></li><li><a href="http://javascriptly.com/2008/09/javascript-in-google-chrome/" rel="bookmark">JavaScript in Google Chrome Not So That Fast</a></li><li><a href="http://javascriptly.com/2008/08/yui-30-changes-from-the-root/" rel="bookmark">YUI 3.0 – Changes From the Root</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/09/zend-16-comes-dojo-firephp-integrated/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript to Detect Google Chrome</title><link>http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/</link> <comments>http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/#comments</comments> <pubDate>Fri, 05 Sep 2008 07:04:22 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Solution]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[Google Chrome]]></category><guid isPermaLink="false">http://javascriptly.com/?p=26</guid> <description><![CDATA[The negative side of having a new (and promisingly become popular) browser, no matter how good it can be, is you&#8217;ll have to test your web apps with it among many others. Probably, the first step is to detect the browser from JavaScript code by parsing browser&#8217;s user agent, and here is what of Google Chrome.Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13I [...]]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">The negative side of having a new (and promisingly become popular) browser, no matter how good it can be, is you&#8217;ll have to test your web apps with it among many others.</p><p style="text-align: justify;">Probably, the first step is to detect the browser from JavaScript code by parsing browser&#8217;s user agent, and here is what of Google Chrome.</p><div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13</pre></div></div><p style="text-align: justify;">I guess old JavaScript codes can mistakenly tell it Safari like when running the code snippet below using JQuery&#8217;s browser utility.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	 $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div&gt;&quot;</span> <span style="color: #339933;">+</span> i <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; : &lt;span&gt;&quot;</span> <span style="color: #339933;">+</span> val <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/span&gt;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span>
		.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p><img class="size-full wp-image-27" title="jquery-browser-detection" src="http://javascriptly.com/wp-content/uploads/2008/09/jquery-browser-detection.gif" alt="" width="279" height="206" /></p><p style="text-align: justify;">It may be no problem until you find something wrong when your apps running on Chrome only. So, here is the code line to detect Chrome generally:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> is_chrome <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/chrome/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">toLowerCase</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></td></tr></table></div><p style="text-align: justify;">We&#8217;ll have to change the JQuery browser utility to support Chrome detection as follows:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> userAgent <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Figure out what browser is being used</span>
jQuery.<span style="color: #660066;">browser</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	version<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>userAgent.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	chrome<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/chrome/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	safari<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/webkit/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span>chrome<span style="color: #339933;">/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	opera<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/opera/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	msie<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/msie/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span>opera<span style="color: #339933;">/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	mozilla<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/mozilla/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!/</span><span style="color: #009900;">&#40;</span>compatible<span style="color: #339933;">|</span>webkit<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p style="text-align: justify;">Now, correct result shows on test screen:</p><p><img class="alignnone size-full wp-image-28" title="jquery-browser-detection2" src="http://javascriptly.com/wp-content/uploads/2008/09/jquery-browser-detection2.gif" alt="" width="280" height="234" /></p><p style="text-align: justify;">Just one notice: Current version of JQuery (1.2.6) is treating Chrome as if it was Safari and basically no serious problem has been found yet. Modifying browser detection can cause the lib render pages/elements incorrectly for it has no knowledge of Chrome&#8217;s rendering engine. To keep compatibility, you can change line 7 back to:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">	safari<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/webkit/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> userAgent <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></pre></td></tr></table></div><p><span id="more-26"></span></p><p>But in this case the browser will be detected as both Chrome and Safari &#8212; not nice solution, I accept.</p><p style="text-align: justify;">Anyway, it&#8217;s very likely that JQuery and other JavaScript frameworks will include Chrome to browser list for detection in next versions.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/javascript-in-google-chrome/" rel="bookmark">JavaScript in Google Chrome Not So That Fast</a></li><li><a href="http://javascriptly.com/2008/09/lightningdom-to-balance-dom-vs-innerhtml/" rel="bookmark">LightningDOM to Balance DOM vs innerHTML</a></li><li><a href="http://javascriptly.com/2008/08/turn-on-javascript-jit-in-firefox-31/" rel="bookmark">Turn on JavaScript JIT in Firefox 3.1</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>JavaScript in Google Chrome Not So That Fast</title><link>http://javascriptly.com/2008/09/javascript-in-google-chrome/</link> <comments>http://javascriptly.com/2008/09/javascript-in-google-chrome/#comments</comments> <pubDate>Wed, 03 Sep 2008 08:00:00 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Development News]]></category> <category><![CDATA[Firefox 3.1]]></category> <category><![CDATA[Google Chrome]]></category> <category><![CDATA[performance test]]></category><guid isPermaLink="false">http://javascriptly.com/?p=19</guid> <description><![CDATA[How well JavaScript works is what I highly concern about Google Chrome &#8212; the browser on headlines of all tech news today. The JavaScript engine embedded in Chrome, named V8, is developed by Google which implements ECMAScript 3 and can run standalone as stated on project website.V8 is Google&#8217;s open source JavaScript engine. V8 is [...]]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">How well JavaScript works is what I highly concern about Google Chrome &#8212; the browser on headlines of all tech news today.</p><p style="text-align: justify;">The JavaScript engine embedded in Chrome, named V8, is developed by Google which implements ECMAScript 3 and can run standalone as stated on <a href="http://code.google.com/p/v8/" target="_blank">project website</a>.</p><blockquote><ul class="unIndentedList"><li> V8 is Google&#8217;s open source JavaScript engine.</li><li> V8 is written in C++ and is used in Google Chrome, the open source browser from Google.</li><li> V8 implements ECMAScript as specified in ECMA-262, 3rd edition, and runs on Windows XP and Vista, Mac OS X 10.5 (Leopard), and Linux systems that use IA-32 or ARM processors.</li><li> V8 can run standalone, or can be embedded into any C++ application.</li></ul></blockquote><p style="text-align: justify;">Of course, we&#8217;ll have to mention the tests given out by Google itself that show JavaScript speed in Chrome  many times faster than in all other major browsers: IE, Firefox and Safari.</p><div id="attachment_20" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-20" title="chrome_subbenchmark_png" src="http://javascriptly.com/wp-content/uploads/2008/08/chrome_subbenchmark_png.png" alt="Google Chrome Benchmarks" width="500" height="386" /><p class="wp-caption-text">Google Chrome Benchmarks</p></div><p style="text-align: justify;">Anyway, they are tests guided by Google and I suspect that they seem be optimized toward the best of V8. So, the better way to see how good V8 perform in action is to run tests with popular JavaScript libraries like JQuery, Prototype, Dojo, Mootools, YUI which are being used in most of web applications in real world.</p><p>In a typical web application, JavaScript is mainly used for DOM selection/ manipulation rather than for heavy calculation. That’s why all libraries try to optimize DOM selection speed for (said) faster application.</p><p style="text-align: justify;">To have practical view, I decided to run Mootools’ SlickSpeed tests on Google Chrome 0.2 in comparison with Firefox 3.0.1, Safari 3.1 (Windows), IE6, Opera 9.5 and especially on the nightly build of Firefox 3.1b1pre with Tracemonkey &#8212; Mozilla&#8217;s recent effort to integrate Tamarin tracing into the existing SpiderMonkey JavaScript engine &#8212; enabled and disabled. Here are the results:</p><div id="attachment_21" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-21" title="slickspeed-benchmarks-chart" src="http://javascriptly.com/wp-content/uploads/2008/08/slickspeed-benchmarks-chart.png" alt="Chart: Mootools SlickSpeed Test Result" width="500" height="331" /><p class="wp-caption-text">Chart: Mootools SlickSpeed Test Results</p></div><div id="attachment_22" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-22" title="slickspeed-benchmarks" src="http://javascriptly.com/wp-content/uploads/2008/08/slickspeed-benchmarks.png" alt="SlickSpeed Benchmarks in details" width="500" height="304" /><p class="wp-caption-text">SlickSpeed Benchmarks in details</p></div><p><em>(All tests were run 10 times for each browser on Windows XP SP3, AMD x64 4400+ with 2GB RAM machine)</em></p><p style="text-align: justify;">It turns out that Google Chrome reached 6th place ahead the poor IE6 only, <strong>49% slower than the fastest browser: Opera 9.5</strong>. Firefox 3.1 has not proved faster than the previous version in the tests, even enabling JIT engine made the results worse. (I acknowledge that it’s just pre-release beta version and Tracemonkey is not designed for optimizing DOM manipulation).</p><p style="text-align: justify;">Some other conclusions we can get out from the above results (ruling out IE6 which falls far behind others in all tests) are:</p><p><span id="more-19"></span></p><ul><li>MooTools, Prototype and Dojo get the worst performance in Chrome and surprisingly JQuery enjoys the second best result.</li><li>JQuery’s selector performs best while YUI 2.5 provides the worst results across browsers (295% slower than JQuery) and Prototype is just slightly better than the worst (269% slower).</li><li>JQuery’s performance is quite browser-neutral while Dojo’s defers a lot from browser to browser, yet both are well optimized for speed.</li><li>Dojo’s selector does not play well in Firefox 3.1 currently causing several errors in tests.</li></ul><p style="text-align: justify;">Though DOM selector test does not tell everything about how fast a JavaScript engine is in real-world browsers, it brings out another aspect you may want to consider over what Google is advertising about V8 and Chrome.</p><p style="text-align: justify;">I recognize that Google Chrome is really good at rendering web pages (which contributes a lot to overall performance of an application) but I’ll stick with Firefox in most of cases for I cannot find a dozen of plugins/extensions I love in Chrome yet.</p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/" rel="bookmark">JavaScript to Detect Google Chrome</a></li><li><a href="http://javascriptly.com/2008/08/turn-on-javascript-jit-in-firefox-31/" rel="bookmark">Turn on JavaScript JIT in Firefox 3.1</a></li><li><a href="http://javascriptly.com/2008/09/lightningdom-to-balance-dom-vs-innerhtml/" rel="bookmark">LightningDOM to Balance DOM vs innerHTML</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/09/javascript-in-google-chrome/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>JQuery Site Re-redesign</title><link>http://javascriptly.com/2008/08/jquery-site-re-redesign/</link> <comments>http://javascriptly.com/2008/08/jquery-site-re-redesign/#comments</comments> <pubDate>Thu, 28 Aug 2008 18:00:14 +0000</pubDate> <dc:creator>Jimmy Vu</dc:creator> <category><![CDATA[Development News]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://javascriptly.com/?p=15</guid> <description><![CDATA[The redesign of JQuery DOT COM site recently gained a huge amount of comments; unfortunately most of them were not positive. Developers who have come along with the library feel unhappy with new slogan &#8220;Be a Javascript Rockstar&#8221; that, said, makes them look unprofessional.Response to a post on Ajaxian, shypht commented:Hate to say it, but [...]]]></description> <content:encoded><![CDATA[<p style="text-align: justify;">The redesign of JQuery DOT COM site recently <a href="http://jquery.com/blog/2008/08/29/jquerycom-site-redesign/">gained a huge amount of comments</a>; unfortunately most of them were not positive. Developers who have come along with the library feel unhappy with new slogan &#8220;<strong>Be a Javascript Rockstar</strong>&#8221; that, said, makes them look unprofessional.</p><p><img class="aligncenter size-full wp-image-16" title="Jquery Site Redesign" src="http://javascriptly.com/wp-content/uploads/2008/08/jquerycom1.png" alt="" width="362" height="410" /></p><p style="text-align: left;">Response to <a href="http://ajaxian.com/archives/jquerycom-redesigned-with-a-rock-star">a post on Ajaxian</a>, <em>shypht</em> commented:</p><blockquote><p style="text-align: justify;">Hate to say it, but image is everything. If I was trying to sell my manager on using jQuery, Prototype, Mootools or Dojo, and sent them to those sites, I think based on look alone jQuery would be at a disadvantage. &#8220;Write less, do more&#8221; is a great slogan, &#8220;Be a Javascript Rockstar&#8221;, not so much.</p><p>Strikes me as being an amateur, and more focused on flashy effects than functionality. I love jQuery, it&#8217;s helped me loads on my most recent project, but that header just makes me cringe a bit on the inside when I see it.</p></blockquote><p style="text-align: left;">While <em>Glen Lipka</em> described his feeling in more colorful words on <a href="http://commadot.com/the-ux-of-the-new-jquery-website/">his blog post</a>:</p><blockquote><p style="text-align: justify;">Truthfully, I feel alienated by it.  It doesn&#8217;t resonate with me.  It makes me feel old and lame.  My hair is not long and flowing. The rockstar isn&#8217;t me.  jQuery is me.  It&#8217;s different.</p></blockquote><p style="text-align: justify;">Obviously John Resig &amp; team did listen to the community and <a href="http://jquery.com/blog/2008/08/29/death-to-javascript-rock-stars/">decided to kill the &#8220;JavaScript RockStar&#8221;</a> on JQuery site.</p><p><span id="more-15"></span><br /> <img class="aligncenter size-full wp-image-17" title="JQuery Site Without The Rockstar" src="http://javascriptly.com/wp-content/uploads/2008/08/jquerycom2.png" alt="" width="410" height="505" /></p><p style="text-align: justify;">Apart from the new glossy UI, the best of JQuey site&#8217;s new design is to organize documentation for the library itself separately from hundreds of plugins and extentions. The new search functionality allows user to fine tune query to specific documents or keywords.</p><p style="text-align: justify;">Well, however, please keep in mind that nobody want to be a JavaScript rocktar! <img src='http://javascriptly.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div id="crp_related"><h2>Related Posts:</h2><ul><li><a href="http://javascriptly.com/2008/09/zend-16-comes-dojo-firephp-integrated/" rel="bookmark">Zend Framework 1.6 Comes with Dojo and FirePHP Integrated</a></li><li><a href="http://javascriptly.com/2008/08/yui-30-changes-from-the-root/" rel="bookmark">YUI 3.0 – Changes From the Root</a></li><li><a href="http://javascriptly.com/2008/09/comet-chat-app-meteor-server/" rel="bookmark">Simple Web Chat with Meteor Comet Server</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://javascriptly.com/2008/08/jquery-site-re-redesign/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 14/48 queries in 1.143 seconds using disk

Served from: quangvhg.virtual.vps-host.net @ 2010-09-08 13:24:09 -->