<?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>unscriptable.com &#187; CSS</title>
	<atom:link href="http://unscriptable.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://unscriptable.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Mon, 26 Mar 2012 01:47:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>OOCSS for JavaScript Pirates</title>
		<link>http://unscriptable.com/2010/11/15/oocss-for-javascript-pirates/</link>
		<comments>http://unscriptable.com/2010/11/15/oocss-for-javascript-pirates/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 03:17:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Non-programming]]></category>
		<category><![CDATA[OOCSS]]></category>

		<guid isPermaLink="false">http://unscriptable.com/?p=676</guid>
		<description><![CDATA[A few weeks back I had the awesome opportunity to speak at the jQuery Conference in Boston. A colleague, Boaz Sender, encouraged me to propose a topic, but I couldn&#8217;t help wondering, &#8220;What could a dojo enthusiast possibly speak about at a jQuery conference?&#8221; Speak about dojo? Uh, no way. That wouldn&#8217;t fly. How about [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks back I had the awesome opportunity to speak at the <a href="http://events.jquery.org/2010/boston/">jQuery Conference in Boston</a>.  A colleague, <a href="http://boazsender.com/">Boaz Sender</a>, encouraged me to propose a topic, but I couldn&#8217;t help wondering, &#8220;What could a dojo enthusiast possibly speak about at a jQuery conference?&#8221;  </p>
<p><em>Speak about dojo? Uh, no way. That wouldn&#8217;t fly.</em></p>
<p><em>How about something about pure JavaScript? Maybe I could extract a feature of cujo.js and turn it into a jQuery plugin! &#8230; Nah, that&#8217;ll take too long.  No time.</em></p>
<p><em>Wait! OOCSS! It&#8217;s applicable to all JavaScript development!</em><br />
<span id="more-676"></span></p>
<p><!-- embedded slideshare widget --></p>
<div style="width:425px; float:right; margin-left: 10px;" id="__ss_5465648"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/unscriptable/oocss-for-javascript-pirates-jqcon-boston" title="OOCSS for JavaScript Pirates jQcon Boston">OOCSS for JavaScript Pirates jQcon Boston</a></strong><object id="__sse5465648" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=oocssforjavascriptpiratespresentationatjqconboston-101017095722-phpapp01&#038;rel=0&#038;stripped_title=oocss-for-javascript-pirates-jqcon-boston&#038;userName=unscriptable" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse5465648" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=oocssforjavascriptpiratespresentationatjqconboston-101017095722-phpapp01&#038;rel=0&#038;stripped_title=oocss-for-javascript-pirates-jqcon-boston&#038;userName=unscriptable" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/unscriptable">John Hann</a>.</div>
</div>
<p>I knew that topic was the best chance I had &#8212; if a dojo guy had a chance at all &#8212; to speak at a jQuery conference.  But how to sell the idea to jQuery developers?  Most of the JavaScript coders I know either don&#8217;t understand CSS or don&#8217;t care to understand it.  Well, to be fair, that description fits most of the dojo coders I know.  Lots of jQuery devs come from a design background, so they know CSS.  But still&#8230; how to let the conference attendees know that this talk won&#8217;t simply be about the same old CSS concepts?</p>
<p><em>I&#8217;ll have to just tell them it&#8217;s for advanced coders! This is <strong>CSS for JavaScript Pirates!!!</strong></em></p>
<p>There were only a few days left before I had to submit the proposal for the talk, so I did what every over-worked coder does: I waited until the night the proposal was due.  </p>
<p>I did two revisions before calling it good enough.  (I usually like to wait a few days between revisions because it makes it easier for me to judge the content objectively, but that almost never happens.)</p>
<p>At the bottom of my proposal, I added some additional notes:</p>
<blockquote><p>Note to reviewer: It&#8217;s no secret that I&#8217;m a dojo contributor working on a dojo-based MVC framework (cujo.js).  Let it be known that I&#8217;ve also worked on my share of jQuery projects!  (Who hasn&#8217;t?)  This talk is about OOCSS and JavaScript, not cujo.js or dojo.  I will be showing jQuery code snippets and will explain techniques that jQuery devs can use in their current projects.
</p></blockquote>
<p><em>That oughta alleviate any doubters.  I hope.</em></p>
<p>There was still one major problem, though.  I needed a demo.  I could show some code snippets on the screen, but without a real demo, it just wouldn&#8217;t have the same impact.  I thought I&#8217;d have to write one.  But I knew I&#8217;d never make the time and would end up rushing both the presentation and the demo.  That&#8217;d just make for a sucky experience &#8212; and a sucky, stressful week.</p>
<p>Then it dawned on me.  My buddy, <a href="http://blog.briancavalier.com/">Brian</a>, had an awesome demo already!  His <a href="http://briancavalier.com/digital-clock/">CSS3 Digital Clock</a> app would be perfect!  </p>
<p><em>First, let&#8217;s see if I even get picked. </em></p>
<p>Two days later I got the email with the subject line: &#8220;Your jQuery Boston Conference 2010 talk is accepted!&#8221;</p>
<p><em><strong>WOOHOO!!!</strong></em></p>
<p>A couple of emails, chat conversations, and phone calls later Brian was on the speaker list, too!  </p>
<p><em>This is gonna be EPIC!</em></p>
<p>And it was.  I got a bit nervous in the middle and forgot half of what I wanted to say, but I think I got the major points across.  Brian did an amazing demo, and several dozens of people came up to us later and thanked us for the talk.  I guess that means it was a success.  </p>
<p>Kudos to the jQuery team, to the conference organizers, and to the other speakers.  The whole conference was a huge success, imho.  I am quite honored to have been able to participate in such an awesome event.</p>
<p>For more about the presentation and OOCSS, check out some of these links:</p>
<p>Brian debuted the <a href="http://briancavalier.com/digital-clock/explode.html">exploding mod</a> of the digital clock at the show.  (Very cool.)</p>
<p>Brian&#8217;s <a href="http://blog.briancavalier.com/oocss-for-javascript-pirates-at-jqcon-2010">write-up</a> after the event.</p>
<p>Brian, looking more like a <a href="http://photos.brookhartfamily.com/Events/jQuery-Conference-Boston-2010/14226246_2VpfJ#1051103962_WwDrN">GQ model</a>, than a pirate.  </p>
<p>Me, looking <a href="http://photos.brookhartfamily.com/Events/jQuery-Conference-Boston-2010/14226246_2VpfJ#1051103183_kUhYa">rather stressed</a>. I think I was saying &#8220;yarrrrrrrr&#8221;.</p>
<p>Another link to the <a href="http://www.slideshare.net/unscriptable/oocss-for-javascript-pirates-jqcon-boston">slides</a>.</p>
<p><a href="http://speakerrate.com/talks/4642-oocss-for-javascript-pirates">Rate me and Brian</a> if you attended the talk!</p>
<p>The <a href="http://wiki.github.com/stubbornella/oocss/">github repo</a> for OOCSS.</p>
]]></content:encoded>
			<wfw:commentRss>http://unscriptable.com/2010/11/15/oocss-for-javascript-pirates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>cujo.js — OOJS, OOCSS, and OOHTML — Part 1 (OOCSS for Engineers)</title>
		<link>http://unscriptable.com/2010/08/31/cujo-js-oojs-oocss-and-oohtml-part-1/</link>
		<comments>http://unscriptable.com/2010/08/31/cujo-js-oojs-oocss-and-oohtml-part-1/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 11:47:07 +0000</pubDate>
		<dc:creator>John Hann</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[cujo.js]]></category>
		<category><![CDATA[In-browser MVC]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[OOCSS]]></category>

		<guid isPermaLink="false">http://unscriptable.com/?p=654</guid>
		<description><![CDATA[I've seen several engineer's eyes glaze over when I mention OOCSS, but don't dismiss it as just a rehashed retelling of how to structure your CSS.  OOCSS is a very powerful and efficient tool, especially when used in conjunction with Object-Oriented JavaScript and inheritable HTML templates. ]]></description>
			<content:encoded><![CDATA[<p>One of the coolest concepts in <a href="http://cujojs.com/">cujo.js</a> is the introduction of Object-Oriented CSS into the Views and Widgets.  I&#8217;ve seen several engineer&#8217;s eyes glaze over when I mention OOCSS, but don&#8217;t dismiss it as just a rehashed retelling of how to structure your CSS.  OOCSS is a very powerful and efficient tool, especially when used in conjunction with Object-Oriented JavaScript and inheritable HTML templates.  </p>
<p>I&#8217;d love to dive right in and show you how it all works in cujo.js, but you&#8217;ve got to have a firm understanding of OOCSS for any of it to make sense.  Let&#8217;s get started&#8230;</p>
<p><span id="more-654"></span></p>
<h2 id="basic-principles">Basic principles of OOCSS</h2>
<p>Where better to learn the basic principles of Nicole Sullivan&#8217;s OOCSS than from the <a href="http://wiki.github.com/stubbornella/oocss/">source</a>?  I highly recommend you watch the slideshow and read the FAQ.  Here are some of the main points:</p>
<p>An &#8220;object&#8221; in OOCSS is an HTML fragment and its associated CSS classes*.<br />
You extend objects by applying multiple classes to its root element.<br />
You must follow some basic guidelines:<br />
	Separate structure from skin (styling).<br />
	Separate container from content.<br />
	Don&#8217;t use ID attributes to define CSS rules.<br />
	Use CSS &#8220;hacks&#8221; for targeting and fixing browser quirks.</p>
<p>*Nicole alludes to some JavaScript associated with these OOCSS &#8220;objects&#8221; (a hilariously surprising assessment from the perspective of a JavaScript engineer who might think of JavaScript as the primary language and of CSS as secondary).  </p>
<p>Nicole includes several other guidelines, as well.  All the guidelines can be summarized into three major categories: 1) guidelines to help reuse objects and CSS classes, 2) guidelines to prevent unnecessary specificity increases, and 3) guidelines to allow OOCSS principles to work in ancient browsers.</p>
<p>The ultimate benefit of following OOCSS principles is optimal reuse of CSS rules and OOCSS objects.</p>
<p>For an excellent and detailed example of OOCSS in action (and a very slick use of CSS3), jump over to Brian Cavalier&#8217;s blog post, <a href="http://briancavalier.posterous.com/building-a-digital-clock-with-oocss-and-mvc">Building a digital clock with OOCSS and MVC </a>and come back.  </p>
<h2 id="oocss-inheritance">OOCSS inheritance</h2>
<p>If code reuse were the end of the story about OOCSS, it would certainly be no small achievement, to say the least.  Nicole has done an amazing service to the web industry, especially to those whose main job is to wrangle CSS.  But little did she know, she also planted a seed of inspiration in several JavaScript engineers&#8217; heads, mine included.  I had been already trying to form solid ideas around very similar CSS patterns, but couldn&#8217;t find the right words or evidence.  After watching her speak live at TXJS 2010, things started to become crystal clear &#8212; especially when she started talking about reusable objects.</p>
<p>One of the most common methods to reuse code is through inheritance.  In classical object-oriented languages, classes inherit attributes and behavior from ancestor classes.  The classes are then used to construct objects.  In prototypal languages (such as JavaScript), objects inherit attributes and behavior from ancestor objects.  However, in OOCSS, objects inherit attributes and <em>run-time</em> state from ancestor objects.</p>
<p>Read that one more time: &#8220;&#8230;objects inherit attributes and <em>run-time</em> state&#8230;&#8221;  We&#8217;re not talking about some static, compile-time concept as with classical inheritance.  And we&#8217;re not talking about inheritance that happens during object construction.  We&#8217;re talking about run-time, baby!  </p>
<p>As an object changes at run time from one state to another, so too do it&#8217;s descendants.  Or, conversely, as an object&#8217;s ancestors states change, so too does the object.  Brian and I talked about this concept and dubbed the term, &#8220;whole state&#8221;, to describe the object&#8217;s current state combined with the states of its ancestors.</p>
<p>Let&#8217;s jump right into an example to better grasp this.  Here&#8217;s a simple HTML snippet from a facetious &#8220;club&#8221; project:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;section class=&quot;club-view club-hawt-view&quot;&gt;
    &lt;ul class=&quot;club-list&quot;&gt;
        &lt;li class=&quot;club-item club-rock-item&quot;&gt;1st Item&lt;/li&gt;
        &lt;li class=&quot;club-item club-disco-item&quot;&gt;2nd Item&lt;/li&gt;
        &lt;li class=&quot;club-item club-pop-item&quot;&gt;3rd Item&lt;/li&gt;
    &lt;/ul&gt;
    &lt;button class=&quot;dance-mode-selector&quot;&gt;Let's do Disco!&lt;/button&gt;
&lt;/section&gt;</pre></div></div>

<p>Notice the name-spaced css classes (using dash-notation to be friendly to HTML4 strict documents).  While not important to this discussion, name-spaces are important to protect your code from name conflicts in large projects, especially if not all of the CSS uses OOCSS principles!</p>
<p>More importantly, notice the classes on the root element of our topmost &#8220;object&#8221;.  <code>club-view</code> and <code>club-hawt-view</code> describe static classes in the classical or prototypal sense.  <code>club-hawt-view</code> is a specialization of <code>club-view</code>. Underneath this <code>club-view</code> object (as we&#8217;ll call it for simplicity&#8217;s sake), we have other objects: <code>club-list</code> and <code>club-item</code>.  <code>club-item</code> has three different specializations, as well: <code>club-rock-item</code>, <code>club-disco-item</code>, and <code>club-pop-item</code>.</p>
<p>Note that we must specify both the base (ancestor) and specialization (descendant) classes on the element.  This is because CSS does not specify a way to declare the inheritance relationship in the stylesheet.  This is not a limitation of CSS, in my opinion, just an implementation detail.  </p>
<p>Interestingly, Nicole calls for declarative inheritance in her slides.  This would allow the designer to specify the link to the ancestor class in the stylesheet, rather than in the HTML.  Thus, only <code>club-hawt-view</code> would need to be specified on the object since the stylesheet would declare the link to the ancestor, <code>club-view</code>.  </p>
<p>(Some other <a href="http://lesscss.org/">projects</a> have implemented compile-time solutions to provide declarative inheritance.  However, declarative inheritance in the stylesheet may do little except save some bulk in the HTML, imho.  I&#8217;m on the fence about it.  It feels like it&#8217;s an idea invented out of basic misunderstanding of CSS inheritance, but I can&#8217;t really see any significant down-sides at the moment, either.  In fact, if used correctly, it may help clarify the difference between specialization CSS classes and stateful CSS classes in the HTML.)</p>
<h2 id="oocss-state">OOCSS state</h2>
<p>Now, imagine that we want to place our <code>club-view</code> object into disco mode when the user clicks the button.  In disco mode, we want to highlight certain objects and de-emphasize &#8212; or even hide &#8212; others.  For instance, we don&#8217;t want to show any <code>club-rock-item</code> objects. (Cuz rockers don&#8217;t do disco.)  We could set them to display:none, in this case.  </p>
<p>In a noobish implementation of this behavior, we would simply catch the button&#8217;s click event, query the <code>club-rock-item</code> elements, and hide them.  This is seductively easy (and dangerous) in jQuery:</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;">'.dance-mode-selector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.club-rock-item'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>or dojo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dance-mode-selector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.club-rock-item'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The less noobish of us know it&#8217;s a lot more cpu-efficient and flexible if we did this using CSS classes instead of manipulating the nodes&#8217; styles directly.  Let&#8217;s add the following CSS rule and change the click event handler to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.club-disco-mode</span> <span style="color: #6666ff;">.club-rock-item</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dance-mode-selector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.club-view'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'club-disco-mode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The resulting HTML would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;section class=&quot;club-view club-hawt-view club-disco-mode&quot;&gt;
    &lt;ul class=&quot;club-list&quot;&gt;
        &lt;li class=&quot;club-item club-rock-item&quot;&gt;1st Item&lt;/li&gt;
        &lt;li class=&quot;club-item club-disco-item&quot;&gt;2nd Item&lt;/li&gt;
        &lt;li class=&quot;club-item club-pop-item&quot;&gt;3rd Item&lt;/li&gt;
    &lt;/ul&gt;
    &lt;button class=&quot;dance-mode-selector&quot;&gt;Let's do Disco!&lt;/button&gt;
&lt;/section&gt;</pre></div></div>

<p>Notice I put the <code>club-disco-mode</code> class on the root object, not the <code>club-rock-item</code> objects (more about this in the next section).  Changing the CSS class instead of direct DOM styling puts the task of deciding how to handle <code>club-disco-mode</code> in the hands of the CSS designer where it belongs.  For instance, once she&#8217;s seen the button jolt upwards (as it would when the <code>club-rock-item</code> object disappeared), she&#8217;d likely throw up a little in her mouth or have a mild seizure induced by this severe UX <em>faux pas</em>!  Then she might mute the colors instead of removing the element from the layout.  </p>
<p>The beauty of this is that there&#8217;s no need to mess with the JavaScript to make this change.  The task of deciding styling and layout for this state change is defined entirely in the CSS.  In fact, the only dependency between the CSS and the JavaScript is the coordination of a single class name, <code>club-disco-mode</code>, on the root element of our object.  You can think of this class name as a message from the JavaScript to the CSS, telling the OOCSS object that it is in a new state.  We&#8217;ve essentially just decoupled the JavaScript from the CSS using a classic method used in object-oriented programming: <em>message passing</em>.  </p>
<p>Not impressed so far?  This is just good CSS practices cast in the light of classical OO, you say?  Ha ha, don&#8217;t worry.  We&#8217;ve only scratched the surface.  In a subsequent blog post, I&#8217;ll show you how cujo.js abstracts the concept of state changes, allowing both CSS (style and layout) and JavaScript (behavioral) state changes to execute in parallel with a single line of code.  </p>
<p>But first, let&#8217;s dig a little deeper into run-time state inheritance&#8230;</p>
<h2 id="oocss-run-time-state">OOCSS run-time state inheritance</h2>
<p>In our &#8220;club&#8221; app, we can also treat the repeated <code>club-item</code> elements as objects, too.  When we change the state of the root <code>club-view</code> object to <code>club-disco-mode</code>, we&#8217;ve also changed the state of all of the <code>club-item</code> objects.  We can take advantage of this by declaring OOCSS rules like the one below.  This rule is just like the earlier rule, but the style declarations have been changed to something less seizure-inducing to somebody with UX sensitivities:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.club-disco-mode</span> <span style="color: #6666ff;">.club-rock-item</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#777</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* grayed-out */</span></pre></div></div>

<p>You could read this as <em><code>club-rock-item</code> objects under the state of <code>club-disco-mode</code></em>.  If we wanted to be even more explicit, we could write it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.club-view</span><span style="color: #6666ff;">.club-disco-mode</span> <span style="color: #6666ff;">.club-rock-item</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#777</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* grayed-out */</span></pre></div></div>

<p>This translates to <em><code>club-rock-item</code> objects under <code>club-view</code> objects in the <code>club-disco-mode</code> state</em>.  Here we see how the <code>club-rock-item</code> objects inherit the state of their ancestor(s) and how we can define the style attributes of those objects in response to that state.  In the more explicit variant, we&#8217;ve also increased the specificity, which may not be desirable in all situations, so the shorter variant is also acceptable as long as it can&#8217;t be interpreted ambiguously.  </p>
<p>So, why did I declare the rules this way?  Why didn&#8217;t I change the state on the <code>club-rock-item</code> objects instead of the <code>club-view</code> object?  Because the button&#8217;s stated purpose is to change the state of the entire object, not of only the <code>club-item</code> objects!  Too often, we JavaScript engineers concentrate too much on the task at hand (manipulating the <code>club-rock-item</code> elements), not the semantic meaning of the user&#8217;s action (to change the state of the <code>club-view</code> object).  </p>
<p>Let&#8217;s revisit the <code>club-hawt-view</code> specialization class to better illustrate an example of why this is so important.  When this class is applied to our object, we potentially inherit a whole new set of CSS rules.  One of these rules could define an entirely different layout or a different styling.  Maybe in a <code>club-hawt-view</code> we&#8217;ve turned up the heat a bit:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.club-hawt-view</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fa7</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#500</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> <span style="color: #808080; font-style: italic;">/* red on orange! HAWT! */</span></pre></div></div>

<p>It just wouldn&#8217;t fit to de-emphasized the <code>club-rock-item</code> objects with a gray background, anymore.  The gray and orange clash.  Instead, when we&#8217;re in the <code>club-disco-mode</code> state, let&#8217;s embolden the font on the emphasized objects and just change the font color on the de-emphasized <code>club-rock-item</code>, not the background.  Let&#8217;s also add a dotted border around the whole object (yah, yah, I know this is getting really damn ugly, but hey, I&#8217;m an engineer):</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.club-hawt-view</span><span style="color: #6666ff;">.club-disco-mode</span> .club-disco-item<span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.club-hawt-view</span><span style="color: #6666ff;">.club-disco-mode</span> <span style="color: #6666ff;">.club-pop-item</span> <span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span> 
<span style="color: #6666ff;">.club-hawt-view</span><span style="color: #6666ff;">.club-disco-mode</span> <span style="color: #6666ff;">.club-rock-item</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#777</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span> 
<span style="color: #6666ff;">.club-hawt-view</span><span style="color: #6666ff;">.club-disco-mode</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">dotted</span> pink<span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The key point is that we didn&#8217;t have to change the JavaScript to deal with the specialized, <code>club-hawt-view</code> object.  We still just passed the same <code>club-disco-mode</code> message to the OOCSS <code>club-view</code> object from the JavaScript in response to a button click:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dance-mode-selector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.club-view'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'club-disco-mode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// still the same exact code!</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2 id="oocss-decreases-risk">OOCSS decreases risk</h2>
<p>This has been a simple example, but you can start to imagine why using JavaScript to programmatically change styling starts to get ugly.  Here&#8217;s what the code might look like if we used JavaScript instead of CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dance-mode-selector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.club-item'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">forEach</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: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dojo.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'club-disco-item'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> dojo.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'club-pop-item'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            dojo.<span style="color: #660066;">style</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'fontWeight'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bold'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            dojo.<span style="color: #660066;">style</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> backgroundColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'transparent'</span><span style="color: #339933;">,</span> color<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#777'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    dojo.<span style="color: #660066;">style</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'border'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'1px dotted pink'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is not reusable code, nor is it very maintainable once you start getting into more complex, real-life projects.  Brian pointed out to me that the general complexity of the situation can be summarized as O(n^m), where n == the total number of CSS classes on a node and m is the number of ancestry levels we may need to manipulate.  If we&#8217;re handling just 3 CSS classes on 3 levels, we&#8217;ve got up to 27 separate cases to consider in code.  </p>
<p>Worst of all, we&#8217;ve inextricably tied our button and our <code>club-item</code> elements together.  If we were to suddenly need a variation of the <code>club-view</code> objects without the <code>club-item</code> objects at all, we&#8217;d be forced to branch yet again.  </p>
<p>As Brian said in his post, declarative code &#8212; such as CSS &#8212; is inherently less risky to modify than procedural code.  </p>
<h2 id="oocss-for-ie">OOCSS in ancient browsers</h2>
<p>The astute CSS developer will have identified several problems with all of the CSS I&#8217;ve shown.  Specifically, none of it will work in IE6 at all!  Combination class selectors (<code>.club-hawt-view.club-disco-mode</code>, for instance) and transparency weren&#8217;t supported in IE until version 7.  Not to worry, cujo.js fixes those automatically.  It also fixes several other CSS2.1 and CSS3 shortcomings in IE.  cujo.js doesn&#8217;t come close to bringing IE up to CSS3 specifications, though, so don&#8217;t get too excited.  cujo.js only fixes IE enough to allow OOCSS to work to its fullest potential while also removing the dependencies between CSS, HTML, and JavaScript.  Separation of concerns has always been a major goal of CSS, but only CSS3 finally fulfills it.  More on that in yet another future blog post.</p>
<p><strong>[update]<br />
For years I thought IE6 didn&#8217;t support combination class selectors!  People are telling me that they work as long as you order the classes correctly (<code>.bar.foo {}</code> versus <code>.foo.bar {}</code>).  I must always order them the way that doesn&#8217;t work.  I&#8217;ll do some further testing and verify.<br />
[/update]</strong></p>
<p>You likely also noticed that Brian is using CSS3 transitions in his project.  Transitions are a critically powerful tool in any UX designers toolkit.  Unfortunately, IE and Firefox  still don&#8217;t support transitions (as of September 2010).  No biggie, cujo.js fixes that, too.  We&#8217;ve even extended transitions to include more popular timing functions such as bounce, elastic, sine, etc.  We&#8217;re also investigating other, more advanced types of transitions to emulate common use cases that don&#8217;t fit the CSS3 transitions model at all.  </p>
<p>For instance, transitions alone can&#8217;t animate an element being tossed into the trash.  Too often the element being deleted and the trash icon don&#8217;t share the same offsetParent or there&#8217;s an ancestor with overflow:hidden somewhere between.  For situations like this, you&#8217;d typically have to append the node to some common ancestor (likely the body element) and then animate it from the original location to the trash icon.  That kind of sequence comes in handy for accessibility-friendly alternatives to drag-and-drop &#8212; as well as a few other use cases.  So, we&#8217;ll be investigating ways to allow the CSS designer to take control of complex transitions like these without tinkering with the engineer&#8217;s JavaScript.</p>
<p>Still not convinced of the benefits of OOCSS?  Next we&#8217;ll see how to apply it in a client-side MVC architecture.  OOCSS becomes even more powerful when you combine it with view-controllers based on OOJS and ultra-simple, inheritable templates I&#8217;ve dubbed OOHTML.</p>
<p>What do you think so far?  Does OOCSS make sense?  Have you already used it in an MVC-based environment?  Let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://unscriptable.com/2010/08/31/cujo-js-oojs-oocss-and-oohtml-part-1/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Firefox&#8217;s proposed Resource Packages spec blows!</title>
		<link>http://unscriptable.com/2010/08/03/firefoxs-proposed-resource-packages-spec-sucks/</link>
		<comments>http://unscriptable.com/2010/08/03/firefoxs-proposed-resource-packages-spec-sucks/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 04:47:28 +0000</pubDate>
		<dc:creator>John Hann</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[cujo.js]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[HTML / DHTML]]></category>
		<category><![CDATA[In-browser MVC]]></category>

		<guid isPermaLink="false">http://unscriptable.com/?p=634</guid>
		<description><![CDATA[It&#8217;s no secret that one of the keys to a decent user experience is a responsive (fast) user interface. And the most critical component to a fast web app is minimizing the HTTP requests. So it&#8217;s no mystery that people are working on ways to solve this problem. Firefox, of course, is one of the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s no secret that one of the keys to a decent user experience is a <em>responsive (fast)</em> user interface.  And the most critical component to a fast web app is minimizing the HTTP requests.  So it&#8217;s no mystery that people are working on ways to solve this problem.  </p>
<p>Firefox, of course, is one of the <a href="http://limi.net/articles/resource-packages/">leaders in this area</a>.  Their proposal started out fine.  Here&#8217;s a sample of what it would look like (if you didn&#8217;t read the article):</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;resource-package&quot; 
      type=&quot;application/zip&quot; 
      href=&quot;/static/site-resources.zip&quot;
      content=&quot;javascript/jquery.js;
               css/reset.css;
               css/grid.css;
               css/main.css;
               images/save.png;
               images/info.png&quot; /&gt;</pre></div></div>

<p>You specify that the file, /static/site-resources.zip&#8221;, contains the listed resources.  JavaScript, CSS, and images.  (I imagine SWFs and videos would also be options.)</p>
<p>But for some reason, this concise, <a href="http://limi.net/articles/resource-packages/#inline-html">nearly-valid</a> implementation was trashed in favor of a terse, unfamiliar, and nearly unusable <a href="http://people.mozilla.org/~jlebar/respkg/">alternative</a>.  Here&#8217;s what the spec looks like now:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html packages='[pkg1.zip img1.png script.js styles/style.css]
                [static/pkg2.zip]'&gt;</pre></div></div>

<p>In this bastardization, the packages are specified as an attribute on the document element (<code>&lt;html&gt;</code> tag).  Package definitions in the <code>packages</code> attribute are delimited by square brackets, and the resources within them are delimited by spaces.  </p>
<p>WTF?  Not only is this ugly and non-standard, but it also has some serious drawbacks.  Here&#8217;s why:</p>
<p><span id="more-634"></span></p>
<h3>Reason #1: Any non-trivial web app has hundreds of resources</h3>
<p>The spec says that naming the resources is optional.  However, <em>not</em> naming them causes the browser to block all further downloads until the resource package is downloaded and unzipped.  So to gain optimal performance (not block), we&#8217;ve got to list every single resource?  Not only is that going to be one hell of a large &lt;html&gt; tag, but it also needs to be <em>maintained</em> every time a new resource is added to the app.</p>
<p>The real answer, of course, is to use a dependency-management and packaging solution.  <a href="http://api.dojotoolkit.org/jsdoc/HEAD/dojo.require">dojo.require</a>  and dojo.build do all of the work of resource packaging already.  (<a href="http://requirejs.org/">require.js</a> is a good start at dependency-management for the non-dojo world, but still lacks packaging. Admittedly, dojo only packages javascript and html templates, not css or images.  <a href="http://cujojs.com/">cujo.js</a> will also package css, but still not images.)</p>
<p>With dependency-management, resources are named <em>where they are used</em>, not in some other file.  Having to remember to go back and list every resource in every HTML file is nothing short of a maintenance hassle.</p>
<p>But hmmmm.  Maybe this is a not as big an issue as I originally thought.  If I am using a dependency-management solution, my resource packages would consist of one javascript file, one css file, and a few dozen images.  That&#8217;s still a lot of image files to maintain, but not as bad as maintaining hundreds of javascript and css files.</p>
<p>One of the reasons the browser needs to block is to allow for overrides.  If package, pkg2.zip, has a resource with the same path/name as a resource in a package declared earlier, pkg1.zip, then the resource in pkg2.zip will override (replace) the resource in pkg1.zip.  Therefore, the resources in the packages must be delineated &#8212; either explicitly or by inspecting the package &#8212; before the packages can be used.  </p>
<p>Again, this override functionality is just duplicating dependency-management solutions.  Object-oriented javascript allows us to override methods and properties.  OOCSS allows us to override CSS rules in a different, but equally effective, manner.  (cujo.js also allows for HTML template inheritance / overrides (OOHTML?).)</p>
<p>When done properly (small, concise OOJS, OOHTML, and OOCSS files) and combined with dependency-management, the download size should be exactly the same and amount of extra RAM needed by the browser should be small compared to the resource packaging solution.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pkg1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// base functionality (large)</span>
dojo.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pkg2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// overrides (small)</span></pre></div></div>

<h3>Reason #2: There&#8217;s no way to specify a resource package dynamically</h3>
<p>This is a non-starter for me.  I write client-heavy web apps.  These apps are typically long-running and are served to the browser as a single page.  In other words, the browser doesn&#8217;t load a new page every time the user takes an action.  Google Docs and Google Mail are good examples.  </p>
<p>Using dojo.require and dojo.build, I can package my apps into as many packages as I like.  (They&#8217;re called &#8220;layers&#8221; in dojo.)  This is especially important in a few scenarios:</p>
<ol>
<li>the app will load a package <em>only when needed</em></li>
<li>the user can switch &#8220;theme&#8221; packages dynamically</li>
<li>the user can switch language packages dynamically</li>
</ol>
<p>If Firefox goes forward with the <code>packages</code> attribute on the <code>&lt;html&gt;</code> tag, then I don&#8217;t see how this is possible.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> html <span style="color: #339933;">=</span> document.<span style="color: #660066;">documentElement</span><span style="color: #339933;">,</span>
    myNewPackage <span style="color: #339933;">=</span> <span style="color: #3366CC;">'pkg3.zip js/myModule.js images/myPng.png'</span><span style="color: #339933;">;</span>
html.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'packages'</span><span style="color: #339933;">,</span> html.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'packages'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' ['</span> <span style="color: #339933;">+</span> myNewPackage <span style="color: #339933;">+</span> <span style="color: #3366CC;">']'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Even if that did work (which I doubt it would), it would undoubtably be unbearably inefficient.  Re-parsing, re-scanning, and re-analyzing every package.</p>
<p>The original proposal did not have this problem.  It&#8217;s a lot simpler to just add a new <code>&lt;link&gt;</code> tag:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> head <span style="color: #339933;">=</span> document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">firstChild</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// assumes no comments before head!</span>
    link <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
link.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rel'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'resource-package'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
link.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'type'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'application/zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
link.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'pkg3.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
link.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contents'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'js/myModule.js; images/myPng.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
head.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>link<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// in dojo:</span>
<span style="color: #003366; font-weight: bold;">var</span> head <span style="color: #339933;">=</span> dojo.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
dojo.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'link'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>rel<span style="color: #339933;">:</span> <span style="color: #3366CC;">'resource-package'</span><span style="color: #339933;">,</span> type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'application/zip'</span><span style="color: #339933;">,</span> href<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pkg3.zip'</span><span style="color: #339933;">,</span> contents<span style="color: #339933;">:</span> <span style="color: #3366CC;">'js/myModule.js; images/myPng.png'</span><span style="color: #339933;">,</span> head<span style="color: #339933;">,</span> <span style="color: #3366CC;">'last'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>So. Can it be fixed?</h3>
<p>Of course.  But, frankly, I don&#8217;t really care.  For us dojo developers, all it&#8217;s going to help out with is images.  And since we&#8217;re using less and less images and more and more CSS3, images aren&#8217;t such a big deal going forward.   (border-image, border-radius, and gradient, FTW!)</p>
<p>But I guess, for image-heavy apps, there&#8217;s still a need.  So here&#8217;s how I&#8217;d fix it:</p>
<p>First of all, abandon that dumb-ass <code>packages</code> attribute.  It&#8217;s ugly, non-standard, and unworkable for the large apps that really need packaging.  Go back to the <code>&lt;link&gt;</code> tag.  That was a much better idea.</p>
<p>Or better yet, use the &lt;script&gt; tag.  (gasp)  And while you&#8217;re at it, fix the <code>defer</code> attribute so <em>I</em> can decide whether the package contains any resources that may need to invoke blocking.  (It could be a package of non-essential images, for instance.)</p>
<p>Hmmmm&#8230;. on second thought, the &lt;link&gt; may be semantically and syntactically better.  Therefore, maybe just add the <code>defer</code> attribute (and functionality) to the link tag?  </p>
<h3>Should it be fixed?</h3>
<p>The more I think about the proposed solutions, the more it seems they&#8217;re targeted toward trivial web apps/pages.  Unfortunately, it&#8217;s typically the larger, more sophisticated apps that need the performance boost.  </p>
<p>Therefore, I say, why bother?  </p>
<p>Instead, let&#8217;s find a way to package images and make dependency management a standard feature in javascript!</p>
<p>What do you say?  Am I missing something?  Do you have a better solution?  Please let me know in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://unscriptable.com/2010/08/03/firefoxs-proposed-resource-packages-spec-sucks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>It&#8217;s official: the Cujo Project is underway</title>
		<link>http://unscriptable.com/2010/06/09/its-official-the-cujo-project-is-underway/</link>
		<comments>http://unscriptable.com/2010/06/09/its-official-the-cujo-project-is-underway/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 01:43:37 +0000</pubDate>
		<dc:creator>John Hann</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[cujo.js]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://unscriptable.com/?p=611</guid>
		<description><![CDATA[I&#8217;ve teased. I&#8217;ve threatened. I&#8217;ve promised. The Cujo Project is finally underway. 14 years of RIA / web app development&#8230; 70+ web-based projects designed for demanding customers such as Nissan, Walmart, Pfizer&#8230; 6 years of OO javascript&#8230; Lead engineer on three powerful, proprietary javascript frameworks&#8230; You&#8217;d think those credentials would qualify me to be the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve teased.</p>
<p>I&#8217;ve threatened.</p>
<p>I&#8217;ve promised.</p>
<p>The <a href="http://cujojs.com/">Cujo Project</a> is finally underway.<br />
<span id="more-611"></span></p>
<ul>
<li>14 years of RIA / web app development&#8230;</li>
<li>70+ web-based projects designed for demanding customers such as Nissan, Walmart, Pfizer&#8230;</li>
<li>6 years of OO javascript&#8230;</li>
<li>Lead engineer on three powerful, proprietary javascript frameworks&#8230;</li>
</ul>
<p>You&#8217;d think those credentials would qualify me to be the lead committer for the ultimate open-source platform for building ultra-rich, in-browser applications.  </p>
<p>But you&#8217;d be wrong.  </p>
<p>The web is progressing so fast.  I sincerely believe that nobody &#8212; not even the grandfather of javascript, <a href="http://crockfordfacts.com/">Douglas Crockford</a> &#8212; can claim to have more than a few years of <em>pertinent</em> web experience.  (He might disagree, of course.)</p>
<p>For my part, it&#8217;s only been a few years since I discovered &#8212; I mean <em>really</em> discovered  &#8212; <em>functional</em> javascript.  OOCSS is next on my list of techniques to master.  </p>
<p>Unless you&#8217;ve devoted several years of your life to javascript and css, you can&#8217;t even begin to imagine how friggin smart their creators were.  If you don&#8217;t understand what I&#8217;m talking about &#8212; if you don&#8217;t agree that javascript and css are truly amazing creations &#8212; then you&#8217;re simply unenlightened.  </p>
<p>I, too, was once unenlightened.</p>
<p>To be fair, javascript and css have had several warts and still have a few today.  Speed was once a big problem.  Quirky, buggy, or non-existent feature support in major browsers was also a major setback.  </p>
<p>But those days are over.  Javascript 1.6 (the version almost fully supported by the laggard, IE8) is already sufficient to build world-class applications (IMHO), and ECMAScript5 (javascript 2.0?) is right around the corner.  CSS3 has added box-flex, transitions, and animations, which are critical for in-browser MVC (more on this in a future article!).  HTML5, of course, adds so many application-oriented features, I can&#8217;t even start to list them here (but you can go <a href="http://diveintohtml5.org/">here</a>).</p>
<p>This stuff is moving way too fast for anybody to fully grok the repercussions on rich web apps.  No, instead I think it&#8217;s my passion and persistence that will help me the most.</p>
<p>But it&#8217;ll also be my understanding of the needs of all of the different roles involved in the development of web apps: Front-End Engineers, UX Designers, Visual Designers, Quality Assurance Technicians.  This is where current attempts at in-browser MVC frameworks fail the hardest and why Cujo is different.</p>
<p>Stay tuned.  Cujo is coming.</p>
<p><em><strong>And it won&#8217;t bite.</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://unscriptable.com/2010/06/09/its-official-the-cujo-project-is-underway/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

