<?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>Cameron McKay &#187; JSS</title>
	<atom:link href="http://cdmckay.org/blog/tag/jss/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdmckay.org/blog</link>
	<description>Programming and Game Development</description>
	<lastBuildDate>Tue, 11 Oct 2011 05:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JSS in Action</title>
		<link>http://cdmckay.org/blog/2009/06/29/jss-in-action/</link>
		<comments>http://cdmckay.org/blog/2009/06/29/jss-in-action/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 07:05:15 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[JSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[reneelung]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=598</guid>
		<description><![CDATA[The first page to use JSS in the wild has recently been launched: reneelung.ca. The page was designed by my fiancee Renee Lung and programmed by me. You&#8217;ll notice if you look at the source that there is no JavaScript in the traditional sense. The page consists of three JavaScript files: the jQuery library, the [...]]]></description>
			<content:encoded><![CDATA[<p>The first page to use JSS in the wild has recently been launched: <a href="http://reneelung.ca">reneelung.ca</a>.</p>
<p>The page was designed by my fiancee Renee Lung and programmed by me.  You&#8217;ll notice if you look at the source that there is no JavaScript in the traditional sense.  The page consists of three JavaScript files: the jQuery library, the JSS plugin, and a JSS stylesheet.</p>
<p>I hope this gives people an idea of the power of JSS.  Read on for an annotated version of the JSS stylesheet used on that site (as of June 29th 2009).</p>
<p><span id="more-598"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Fades the background in on each page.</span>
<span style="color: #006600; font-style: italic;">// You'll notice the square bracket notation.  This is used to </span>
<span style="color: #006600; font-style: italic;">// attach multiple JSS commands to a single event property.  </span>
<span style="color: #006600; font-style: italic;">// They run in the order they are declared.</span>
<span style="color: #3366CC;">&quot;.background&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span> 
    <span style="color: #3366CC;">&quot;set-css (.background) display none&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #3366CC;">&quot;fade-in (.background) normal&quot;</span> 
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>  
&nbsp;
<span style="color: #006600; font-style: italic;">// This block only runs on the front page.</span>
<span style="color: #006600; font-style: italic;">// It is used to show a different button mouse-over </span>
<span style="color: #006600; font-style: italic;">// image on the frontpage.</span>
<span style="color: #3366CC;">&quot;.front .button&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span> 
    <span style="color: #006600; font-style: italic;">// This saves the name of mouseover image </span>
    <span style="color: #006600; font-style: italic;">// to the element so that the mouseover code</span>
    <span style="color: #006600; font-style: italic;">// (down further) can use it.</span>
    <span style="color: #006600; font-style: italic;">// The {id} is an attribute getter.</span>
    <span style="color: #006600; font-style: italic;">// Thus, if the id for one of the buttons is</span>
    <span style="color: #006600; font-style: italic;">// &quot;portfolio&quot;, then the class-over variable</span>
    <span style="color: #006600; font-style: italic;">// will be &quot;front-portfolio-over&quot;.</span>
    <span style="color: #3366CC;">&quot;set-data class-over front-{id}-over&quot;</span><span style="color: #339933;">,</span>       
    <span style="color: #3366CC;">&quot;preload-image gfx/buttons/front-{link-to}-over.png&quot;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This block runs on any page except the front page.</span>
<span style="color: #3366CC;">&quot;#window:not(.front) .button&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  setup<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span> 
    <span style="color: #3366CC;">&quot;set-data class-over {id}-over&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;preload-image gfx/buttons/{link-to}-over.png&quot;</span>
  <span style="color: #009900;">&#93;</span>  
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>  
&nbsp;
<span style="color: #006600; font-style: italic;">// This the code that is used to transition</span>
<span style="color: #006600; font-style: italic;">// between pages.</span>
<span style="color: #3366CC;">&quot;.button&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>    
  <span style="color: #006600; font-style: italic;">// This is the rollover code.  Pretty simple eh?</span>
  hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;toggle-class [class-over] | toggle-class [class-over]&quot;</span><span style="color: #339933;">,</span>
  click<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span>
    <span style="color: #006600; font-style: italic;">// This make the background fade out </span>
    <span style="color: #006600; font-style: italic;">// and then links the user to the link</span>
    <span style="color: #006600; font-style: italic;">// provided in the HTML.</span>
    <span style="color: #3366CC;">&quot;fade-out (.background) normal !then-link-to {@link-to}.html&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;fade-out (#portfolio-window) normal&quot;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This a custom user function.  They can</span>
<span style="color: #006600; font-style: italic;">// be tagged on to most JSS commands</span>
<span style="color: #006600; font-style: italic;">// (in cases where you'd have things like</span>
<span style="color: #006600; font-style: italic;">// a callback for an animation).</span>
<span style="color: #3366CC;">&quot;then-link-to&quot;</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>link_target<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>  
  <span style="color: #003366; font-weight: bold;">var</span> event <span style="color: #339933;">=</span> $.<span style="color: #660066;">Event</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  event.<span style="color: #660066;">data</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> arguments<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> link_target <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;link-to&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#40;</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;
<span style="color: #006600; font-style: italic;">// This is the code that handles making the </span>
<span style="color: #006600; font-style: italic;">// the images on the portfolio page &quot;glow&quot;</span>
<span style="color: #006600; font-style: italic;">// when you mouseover them.</span>
<span style="color: #3366CC;">&quot;div.artwork img&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// This &quot;setup&quot; event property is used</span>
  <span style="color: #006600; font-style: italic;">// to basically create a variable...</span>
  setup<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span> 
    <span style="color: #3366CC;">&quot;set-data opacity-off 0.3&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #3366CC;">&quot;set-css opacity [opacity-off]&quot;</span>
  <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// ... that is then used by the &quot;hover&quot;</span>
  <span style="color: #006600; font-style: italic;">// event property to set the opacity.</span>
  hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;fade-to 1 | fade-to [opacity-off]&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// The next block as well as the </span>
<span style="color: #006600; font-style: italic;">// two following #link-page-n classes are</span>
<span style="color: #006600; font-style: italic;">// an admittedly hack way of making pages,</span>
<span style="color: #006600; font-style: italic;">// but get the job done for a relatively simple</span>
<span style="color: #006600; font-style: italic;">// page.  If you were dealing with anymore</span>
<span style="color: #006600; font-style: italic;">// than a couple pages, this method would </span>
<span style="color: #006600; font-style: italic;">// quickly get unwieldly.</span>
&nbsp;
<span style="color: #3366CC;">&quot;#pager a&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  click<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span> 
    <span style="color: #3366CC;">&quot;set-css (.portfolio-window) display none&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;set-css (#pager a) font-weight normal&quot;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;#link-page-1&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  font_weight<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bold&quot;</span><span style="color: #339933;">,</span>
  click<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span>
    <span style="color: #3366CC;">&quot;set-css (#portfolio-page-1) display block&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;set-css font-weight bold&quot;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;#link-page-2&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  click<span style="color: #339933;">:</span> 
  <span style="color: #009900;">&#91;</span>
    <span style="color: #3366CC;">&quot;set-css (#portfolio-page-2) display block&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;set-css font-weight bold&quot;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This is using JSS to make an image</span>
<span style="color: #006600; font-style: italic;">// into a hyperlink.</span>
<span style="color: #3366CC;">&quot;#pdf-button&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  click<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;link-to {resume-link}&quot;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/06/29/jss-in-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSS 1.0.0-beta2 released!</title>
		<link>http://cdmckay.org/blog/2009/05/24/jss-100-beta-2-released/</link>
		<comments>http://cdmckay.org/blog/2009/05/24/jss-100-beta-2-released/#comments</comments>
		<pubDate>Mon, 25 May 2009 04:20:08 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[JSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[1.0.0-beta2]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=591</guid>
		<description><![CDATA[I&#8217;m proud to announce the release of JSS 1.0.0-beta2. Here are the changes: Fixed the way that {attributes} are handled when not using a selector. They should now properly grab the attribute from element that fired the event. Made it so each time a declaration block is applied, all the event handlers bound by JSS [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m proud to announce the release of <a href="http://javascript-stylesheets.googlecode.com/files/jquery.jss-1.0.0-beta2.js">JSS 1.0.0-beta2</a>.  Here are the changes:</p>
<ul>
<li>Fixed the way that {attributes} are handled when not using a selector.  They should now properly grab the attribute from element that fired the event.</li>
<li>Made it so each time a declaration block is applied, all the event handlers bound by JSS to the elements returned by that selector are unbound.</li>
<li>Fixed the semantics of the {@attr} syntax.  It now means that the eventTarget should always be used, regardless of whether or not a selector is defined.  In order to access the attributes of a selector use {@attr} now.</li>
<li>Added two new commands: set-data and remove-data.  These commands use the jQuery functions data() and removeData().  They are similar to set-attr and remove-attr except instead of storing the information in an attribute, they are stored in a table.  Data is accessed by using [data] syntax, similar to the {attr} syntax.</li>
<li>Added new event property: setup.  This event is fired when the JSS stylesheet is loaded (setup).  This is useful in certain cases where the user wants to setup some variables using set-data.</li>
<li>Made it so you can now set scroll-top and scroll-left via the set-attr command.</li>
<li>Added trigger command.  It can be used to trigger event properties on elements.</li>
<li>Fixed bug where you could put a string | in a binary command due to the<br />
simplistic implementation.  The new version requires any | to be escaped with \|.</li>
<li>Added fade-to command, based on the jQuery.fadeTo() command.</li>
<li>Added show and hide commands.</li>
<li>Fixed issue with data and attribute replacements not working correctly (i.e. the first event would replace them for all events).</li>
<li>Callbacks may now take string parameters.  For example, &#8220;fade-out (#target) normal !callback str1 str2&#8243;.</li>
</ul>
<p>I&#8217;ve also started writing documentation for the <a href="http://cdmckay.org/blog/jss/command-reference/">JSS commands</a>.  It is only partially completed but can still be helpful.  Check out the <a href="http://cdmckay.org/blog/jss">JSS homepage</a> for other documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/05/24/jss-100-beta-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSS 1.0.0-beta1 released!</title>
		<link>http://cdmckay.org/blog/2009/05/05/jss-100-beta1-released/</link>
		<comments>http://cdmckay.org/blog/2009/05/05/jss-100-beta1-released/#comments</comments>
		<pubDate>Tue, 05 May 2009 22:43:37 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[JSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=527</guid>
		<description><![CDATA[JSS 1.0.0-beta1 was released a couple minutes ago. This version of JSS should be mostly bug-free (although there are still many more tests to be written). For information on how to use JSS, see here and here. More extensive documentation will be forthcoming as I move towards a 1.0.0 release.]]></description>
			<content:encoded><![CDATA[<p><a href="http://javascript-stylesheets.googlecode.com/files/jquery.jss-1.0.0-beta1.js">JSS 1.0.0-beta1</a> was released a couple minutes ago.  This version of <a href="http://code.google.com/p/javascript-stylesheets/">JSS</a> should be mostly bug-free (although there are still many more tests to be written).  For information on how to use JSS, see <a href="http://cdmckay.org/blog/jss/">here</a> and <a href="http://cdmckay.org/blog/category/jss/">here</a>.</p>
<p>More extensive documentation will be forthcoming as I move towards a 1.0.0 release.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/05/05/jss-100-beta1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The JSS Stylesheet, Part 1</title>
		<link>http://cdmckay.org/blog/2009/05/05/the-jss-stylesheet/</link>
		<comments>http://cdmckay.org/blog/2009/05/05/the-jss-stylesheet/#comments</comments>
		<pubDate>Tue, 05 May 2009 16:05:40 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[JSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[event properties]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[stylesheets]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=459</guid>
		<description><![CDATA[I&#8217;ve said previously that JSS is a lot like CSS. What is CSS? Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation (that is, the look and formatting) of a document written in a markup language. If that blurb were written about JSS, it&#8217;d sound a little like this: JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve said previously that JSS is a lot like <a href="http://en.wikipedia.org/wiki/CSS">CSS</a>.  What is CSS?</p>
<blockquote><p>Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation (that is, the look and formatting) of a document written in a markup language.</p></blockquote>
<p>If that blurb were written about JSS, it&#8217;d sound a little like this:</p>
<blockquote><p>JavaScript Style Sheets (JSS) is a style sheet language used to describe the presentation (that is, the look and formatting) and functionality of a document written in HTML.</p></blockquote>
<p>In this article, we will look at the syntactic structure of a JSS stylesheet.  We will also talk briefly about including JSS stylesheets in your HTML documents.</p>
<p><span id="more-459"></span></p>
<p>At this point, some people may be wondering: <em>aren&#8217;t we mucking up CSS by combining functionality and presentation in the same place?</em>  This is a valid concern.  However, just because we can combine presentation and functionality in JSS, doesn&#8217;t necessarily mean we should.  A good JSS site will have two or more JSS stylesheets: one for JSS styles (if they are needed) and one for JSS event properties.  JSS event properties will be covered in a future article.</p>
<h3>Syntactic Structure</h3>
<p>Let&#8217;s get back to the CSS/JSS connection.  What do people do with CSS?  They write stylesheets.  More specifically, they write rules.  In JSS, we write rules too.  In fact, we write them in a very similar format to CSS, although with some important differences owing to the fact that JSS stylesheets are actually JavaScript programs.  Here&#8217;s the basic format of a CSS stylesheet:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">rule-selector-a
<span style="color: #00AA00;">&#123;</span>
  property-a<span style="color: #00AA00;">:</span> value-a<span style="color: #00AA00;">;</span>
  property-b<span style="color: #00AA00;">:</span> value-b<span style="color: #00AA00;">;</span>
  ...
<span style="color: #00AA00;">&#125;</span>
&nbsp;
rule-selector-b
<span style="color: #00AA00;">&#123;</span>
  property-a<span style="color: #00AA00;">:</span> value-a<span style="color: #00AA00;">;</span>
  property-b<span style="color: #00AA00;">:</span> value-b<span style="color: #00AA00;">;</span>
  ...
<span style="color: #00AA00;">&#125;</span>
&nbsp;
...</pre></div></div>

<p>In JSS, we use pretty much the same format, with the differences being the addition of boilerplate code (1), quoted selectors with colons (2), underscores instead of dashes in property names (3), quoted values with commas (4) and commas between rules (5).  The JSS format is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// (1)</span>
&nbsp;
<span style="color: #3366CC;">&quot;rule-selector-a&quot;</span><span style="color: #339933;">:</span> <span style="color: #006600; font-style: italic;">// (2)</span>
<span style="color: #009900;">&#123;</span>
  property_a<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-a&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// (3) and (4)</span>
  property_b<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-b&quot;</span><span style="color: #339933;">,</span>
  ...
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// (5)</span>
&nbsp;
<span style="color: #3366CC;">&quot;rule-selector-b&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  property_a<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-a&quot;</span><span style="color: #339933;">,</span>
  property_b<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-b&quot;</span><span style="color: #339933;">,</span>
  ...
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// (1)</span></pre></div></div>

<p>Let&#8217;s talk a bit about each of these difference:</p>
<ol>
<li><strong>Boilerplate code.</strong>  This is an unfortunate side effect of having to use JavaScript to extend CSS.  Fortunately, it&#8217;s the same for each JSS stylesheet, so it&#8217;s not too much of a hassle to remember.</li>
<li><strong>Quoted selectors with colons.</strong> Since the selector portion of a JSS rule is a string, it must be represented in JSS as a JavaScript string.  All strings in JavaScript must be either single-quoted (as in &#8216;Hello!&#8217;) or double-quoted (as in &#8220;w00t w00t&#8221;).  The colon following the selector is a necessity as internally, JSS selectors act as keys in a JavaScript object.  A JSS selector may be any valid jQuery selector.</li>
<li><strong>Underscores instead of dashes in property names.</strong>  This is not strictly true, although using underscores instead of dashes is the recommended way of representing JSS properties.  Consider, for example, the <em>font-family</em> property from CSS.  This can be represented in 3 ways in JSS:
<ol>
<li>font_family</li>
<li>&#8220;font_family&#8221;</li>
<li>&#8220;font-family&#8221;</li>
</ol>
</li>
<li><strong>Quoted values with commas.</strong> Unlike CSS, all values in JSS are quoted with either single or double quotes.  Furthermore, between declarations, there must be a comma.<br />
<br/></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// This is correct.</span>
<span style="color: #3366CC;">&quot;rule-selector-a&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  property_a<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-a&quot;</span><span style="color: #339933;">,</span>
  property_b<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-b&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This is incorrect.</span>
<span style="color: #3366CC;">&quot;rule-selector-b&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span>
  property_a<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-a&quot;</span><span style="color: #339933;">,</span>
  property_b<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value-b&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// This declaration should not </span>
                         <span style="color: #006600; font-style: italic;">// have a comma.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li><strong>Commas between rules.</strong> Like declarations, each rule must have a comma between it:

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">&quot;rule-selector-a&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #3366CC;">&quot;rule-selector-b&quot;</span><span style="color: #339933;">:</span>
<span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// Make sure the last rule has no comma after it.</span></pre></div></div>

</li>
</ol>
<h3>Loading JSS and JSS stylesheets</h3>
<p>Now that we understand the syntactic structure of a JSS stylesheet, it&#8217;s time to take look at how we include them in an HTML file.  Every page that makes use of JSS will have the following structure:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.jss.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sheet-1.jss.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sheet-2.jss.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    ...
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sheet-n.jss.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Your website here. --&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Let&#8217;s quickly go through the components here.  The first <code>script</code> tag includes the jQuery library, which is required by JSS.  The second <code>script</code> tag includes the JSS jQuery plugin, which is the brains of JSS, and is required for any JSS stylesheet to work.  All the <code>script</code> tags after that are the JSS stylesheets that you wish to load.</p>
<p>As you can see, you can add an unlimited number of JSS stylesheets, and when the page loads, they&#8217;ll be applied in the same order they are included in the page.  Keep in mind, however, that if you&#8217;re including many <code>script</code> tags on a single webpage, it is advisable to use some sort of JavaScript loader.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/05/05/the-jss-stylesheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing JSS</title>
		<link>http://cdmckay.org/blog/2009/04/30/introducing-jss/</link>
		<comments>http://cdmckay.org/blog/2009/04/30/introducing-jss/#comments</comments>
		<pubDate>Fri, 01 May 2009 04:43:34 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[JSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[stylesheet]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=391</guid>
		<description><![CDATA[Ever wanted to make an image rollover, but you don&#8217;t know JavaScript? In this tutorial, we show you how JSS, a CSS-like language, makes this a breeze. Consider these two images: Imagine we wanted to make them &#8220;rollover&#8221;, i.e. the zebra should be shown when nothing is happening, and the shark should be showed when [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to make an image rollover, but you don&#8217;t know JavaScript?  In this tutorial, we show you how JSS, a CSS-like language, makes this a breeze.</p>
<p><span id="more-391"></span></p>
<p>Consider these two images:</p>
<p><img src="http://couchware.ca/users/cam/example/rollover/image_off.gif" alt="Zebra" /><br />
<img src="http://couchware.ca/users/cam/example/rollover/image_on.gif" alt="Shark" /></p>
<p>Imagine we wanted to make them &#8220;rollover&#8221;, i.e. the zebra should be shown when nothing is happening, and the shark should be showed when the mouse is &#8220;rolled over&#8221; (i.e. on top of) the zebra.  Like this:</p>
<p><img src="http://couchware.ca/users/cam/example/rollover/image_off.gif" src-out="http://couchware.ca/users/cam/example/rollover/image_off.gif" src-over="http://couchware.ca/users/cam/example/rollover/image_on.gif" /><script src="http://www.google.com/jsapi" type="text/javascript"></script> <script type="text/javascript"><!--
google.load("jquery", "1.3.2");
google.setOnLoadCallback(function()
{
  $("img[src-over]").hover(
    function() { $(this).attr('src', $(this).attr('src-over')); },
    function() { $(this).attr('src', $(this).attr('src-out')); }
  );
});
// --></script></p>
<p>Before we start writing some JSS, let&#8217;s write some HTML for a page just showing the rollover at rest (i.e. just show a plain old static image):</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>JSS Rollover<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_off.png&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>If we copied this code into an HTML file and ran it on our browser, we would see a static image of a zebra.  Not that exciting, right?  Now let&#8217;s see how we can use JSS to make this zebra &#8220;rollover&#8221; to the shark when the mouse is on it.  Here&#8217;s the JSS stylesheet:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #3366CC;">&quot;img[src-over]&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #009900;">&#123;</span>
    hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;set-attr src {src-over} | set-attr src {src-out}&quot;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let&#8217;s step through this syntax, because there&#8217;s a lot going on here, even though it&#8217;s a single line.  First, let&#8217;s annotate the JSS source so we can refer to it easier:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// 1. Boilerplate that starts any JSS stylesheet.</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// 2. Rule</span>
  <span style="color: #3366CC;">&quot;img[src-over]&quot;</span><span style="color: #339933;">:</span> <span style="color: #006600; font-style: italic;">// 3. CSS Selector</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// 4. JSS Declaration</span>
    hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;set-attr src {src-over} | set-attr src {src-out}&quot;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you might have noticed, a JSS stylesheet looks very similar to a CSS stylesheet.  Let&#8217;s walk through the anatomy of a JSS stylesheet.</p>
<p>At the top of any JSS stylesheet there is some boilerplate code (1).  This is necessary because a JSS stylesheet is actually a JavaScript program.  However, beyond the fact that this boilerplate needs to be in every JSS stylesheet, you don&#8217;t really need to know what it does.</p>
<p>A JSS stylesheet is made up of an unlimited number of rules (2).  This is the same as in a CSS stylesheet.  Inside a JSS rule, there are two components, a selector (3) and an unlimited number of declarations (inside a declaration block) (4).  This is where we start to see some of the advantages of JSS over using plain CSS.</p>
<p>JSS selectors are powered by <a href="http://jquery.com">jQuery</a>.  As such, JSS supports any CSS3-compliant selector.  In addition, JSS also allows you to use any of the jQuery CSS selector extensions as well.</p>
<p>For example, in CSS, this stylesheet should stripe all the tables on the page as alternating gray and white:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">table tr<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>odd<span style="color: #00AA00;">&#41;</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;">#eee</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
table tr<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span>even<span style="color: #00AA00;">&#41;</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;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>However, if you tried to use that CSS stylesheet in the two most popular browsers available (IE7 and Firefox 3) you would discover that it didn&#8217;t work.  On the other hand, if you use the following JSS stylesheet&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #3366CC;">&quot;table tr:nth-child(odd)&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #009900;">&#123;</span> background_color<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;#eee&quot;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #3366CC;">&quot;table tr:nth-child(even)&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #009900;">&#123;</span> background_color<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;#fff&quot;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230;you would discover that it worked in all major browsers.  By using a JavaScript selector engine, JSS offers better cross-browser styling than regular CSS.</p>
<p><em>(Aside: Before all you web developers out there go crazy, I would like to note that I realize there are several drawbacks to using JavaScript to style your page.  Stay tuned to the end of this article for a discussion of them).</em></p>
<p>Now let&#8217;s return to our task of making a rollover.  How does the JSS stylesheet make it possible?  Let&#8217;s take a look at that JSS stylesheet again:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// 1. Boilerplate that starts any JSS stylesheet.</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// 2. Rule</span>
  <span style="color: #3366CC;">&quot;img[src-over]&quot;</span><span style="color: #339933;">:</span> <span style="color: #006600; font-style: italic;">// 3. CSS Selector</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// 4. JSS Declaration</span>
    hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;set-attr src {src-over} | set-attr src {src-out}&quot;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let&#8217;s look closer at the rule.  More specifically, take a look at the CSS selector.  For anyone familiar CSS, it reads &ldquo;select all <strong>img</strong> tags that have the attribute <strong>src-over</strong>&rdquo;.  Why would we want to do that?  Well, as it happens, we need some way to describe which image to use when the user mouses over our image.  In order to do that, we&#8217;re going to use something called a <strong>custom attribute</strong>.</p>
<p>Custom attributes are user-defined attributes on HTML tags.  For example, the <strong>img</strong> tag has an attribute called <strong>src</strong>.  That&#8217;s a proper attribute that is defined in a W3C recommendation.  What we&#8217;re going to do is add two new attributes, <strong>src-over</strong> and <strong>src-out</strong>, that are not part of any W3C standard.  We just made them up because they&#8217;re convenient for our purposes.</p>
<p>Now that we&#8217;ve decided that we&#8217;re adding these two attributes, we need to add them to our HTML file:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>JSS Rollover<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_off.png&quot;</span></span>
<span style="color: #009900;">        src-out<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_off.png&quot;</span> src-over<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_on.png&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>With that done, let&#8217;s take a look at the last part of the JSS stylesheet: the declaration.  A JSS declaration has a property (hover) and a value (&#8220;set-attr src {src-over} | set-attr src {src-out}&#8221;).  This is just like a CSS declaration, like &#8220;font-family: Arial, sans-serif&#8221;.  In that case, &#8220;font-family&#8221; is the property and &#8220;Arial, sans-serif&#8221; is the value.</p>
<p>In the case of the rollover JSS stylesheet, the hover property must have a value with the following structure:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;jss-expression | jss-expression&quot;</span></pre></div></div>

<p>The first JSS expression on the left is run when the mouse is over the image area, and the right JSS expression is run when the mouse leaves the image area.</p>
<p>Let&#8217;s look at what happens in the JSS rollover stylesheet when the mouse is brought over the image area:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">set<span style="color: #339933;">-</span>attr src <span style="color: #009900;">&#123;</span>src<span style="color: #339933;">-</span>over<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This JSS expression reads: &#8220;set the src attribute (of the selected element) to the contents of the src-over attribute (of the selected element)&#8221;.  This is because &#8220;set-attr&#8221; is a JSS <em>command</em>.  The &#8220;set-attr&#8221; command takes two arguments: the attribute to change, and the value to change it to.  That leaves one more question.  What&#8217;s the deal with the curly braces?</p>
<p>In JSS, curly braces are basically a &#8220;get-attr&#8221; command.  They fetch the value of an attribute.  In the context they are being used here, they fetch the value of the &#8220;src-over&#8221; attribute (which happens to be the name of the shark image &#8220;image_on.gif&#8221;).</p>
<p>With that information in hand, it can be deduced that the right hand side&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">set<span style="color: #339933;">-</span>attr src <span style="color: #009900;">&#123;</span>src<span style="color: #339933;">-</span>out<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&#8230;switches the src attribute back to src-out image URL when the mouse leaves the image area.</p>
<p>Thus, if we put it all together, and include the appropriate JavaScript files, we have the following.  In the &#8220;index.html&#8221; file we have:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>JSS Rollover<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text/javascript'</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'jquery.js'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text/javascript'</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'jquery.jss.js'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text/javascript'</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'styles.jss.js'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_off.png&quot;</span></span>
<span style="color: #009900;">        src-off<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_off.png&quot;</span> src-over<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image_on.png&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>And in the &#8220;styles.jss.js&#8221; file we have this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">jss</span>.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #3366CC;">&quot;img[src-over]&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #009900;">&#123;</span>
    hover<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;set-attr src {src-over} | set-attr src {src-out}&quot;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>These files together create a page that has a rollover that changes from zebra to shark when the mouse is hovered over it.  Better yet, this JSS stylesheet can be used with any web page to enable rollover images.  All the user has to do is set the &#8220;src-over&#8221; and &#8220;src-out&#8221; custom attributes.</p>
<h3>Notes on JSS Availability &amp; Performance</h3>
<p>JSS applies its stylesheets using JavaScript.  This has several implications to web designers using it.  First of all, in order for a site to take advantage of JSS, JavaScript must be enabled.  Fortunately, something like 95% of all web surfers have JavaScript enabled, so that&#8217;s not too big of deal.  Secondly, JSS is a lot slower than CSS.  For most websites, this difference will probably be imperceptible deal, but it&#8217;s still something to be aware of.</p>
<p>My recommendations would be this: if you can do it in CSS, and it works properly across all browsers, then use CSS.  There&#8217;s no reason not to.  However, if you need to use JSS features like event properties (like hover) or cross-browser selectors, then use JSS.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/04/30/introducing-jss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

