<?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; firefox</title>
	<atom:link href="http://cdmckay.org/blog/tag/firefox/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdmckay.org/blog</link>
	<description>Programming and Game Development</description>
	<lastBuildDate>Mon, 14 May 2012 21:11:58 +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>How to (kinda) fix Firefox&#8217;s showModalDialog</title>
		<link>http://cdmckay.org/blog/2009/07/07/how-to-kinda-fix-firefoxs-showmodaldialog/</link>
		<comments>http://cdmckay.org/blog/2009/07/07/how-to-kinda-fix-firefoxs-showmodaldialog/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 18:48:38 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[showmodaldialog]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=738</guid>
		<description><![CDATA[As someone who has had to write a lot of IE-only code (against my will, I swear!), I was pleased to hear that Firefox 3.0 added support for the IE JavaScript function window.showModalDialog. Being in the middle of re-writing an IE-only web application, I thought this would simplify rewriting the modal dialogs to be compatible [...]]]></description>
			<content:encoded><![CDATA[<p>As someone who has had to write a lot of IE-only code (against my will, I swear!), I was pleased to hear that Firefox 3.0 added support for the IE JavaScript function <code>window.showModalDialog</code>.  Being in the middle of re-writing an IE-only web application, I thought this would simplify rewriting the modal dialogs to be compatible with both browsers.</p>
<p>Unfortunately, I don&#8217;t think the folks at Mozilla put their best effort into this one.  </p>
<p><span id="more-738"></span></p>
<p>First of all, the Firefox implementation only supports a subset of the IE options.  Here&#8217;s a table showing what each browsers implementation supports according to their documentation:</p>
<table>
<tr>
<th colspan="3">Documented Support</th>
</tr>
<tr>
<th>Option</th>
<th><a href="http://msdn.microsoft.com/en-us/library/ms536759%28VS.85%29.aspx">Internet Explorer</a></th>
<th><a href="https://developer.mozilla.org/En/DOM/Window.showModalDialog">Firefox</a></th>
</tr>
<tr>
<td>dialogWidth</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogHeight</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogLeft</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogTop</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>center</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogHide</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>edge</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>resizable</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>scroll</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>status</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>unadorned</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
</table>
<p>Doesn&#8217;t seem too bad, right?  We still have <code>center</code>, <code>resizable</code> and <code>scroll</code> right? Right? <em>Wrong.</em> </p>
<h3>Documentation != Implementation</h3>
<p>It seems the guys who wrote the Firefox documentation weren&#8217;t the same guys who wrote the code. Including <code>center</code>, <code>resizable</code> or <code>scroll</code> in your arguments string has no effect whatsoever.  In fact, <code>center</code> is supposed to be <code>on</code> by default, but I can tell you right now that the modal dialog sure as hell isn&#8217;t centered.</p>
<p>Here&#8217;s an updated support matrix:</p>
<table>
<tr>
<th colspan="3">Actual Support</th>
</tr>
<tr>
<th>Option</th>
<th>Internet Explorer</th>
<th>Firefox</th>
</tr>
<tr>
<td>dialogWidth</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogHeight</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogLeft</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>dialogTop</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>center</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>dialogHide</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>edge</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>resizable</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>scroll</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>status</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>unadorned</td>
<td>Yes</td>
<td><strong>No</strong></td>
</tr>
</table>
<p>Fortunately, they did get one part right: the dialog is modal.  Woooo!</p>
<h3>Can we fix it?</h3>
<p>Well, we can, kinda.  We can&#8217;t fix <code>resizable</code>, because that&#8217;s a property of the window, and we can&#8217;t fix <code>scroll</code> for the same reason.  We can, however, emulate the <code>center</code> option by using <code>dialogLeft</code> and <code>dialogTop</code>.  Here&#8217;s some quick-and-dirty code I wrote to do that.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> oldShowModalDialog <span style="color: #339933;">=</span> window.<span style="color: #660066;">showModalDialog</span><span style="color: #339933;">;</span>
window.<span style="color: #660066;">showModalDialog</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> args<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>           
  <span style="color: #006600; font-style: italic;">// Convert the options string into an object.</span>
  <span style="color: #003366; font-weight: bold;">var</span> pairs <span style="color: #339933;">=</span> options.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s+/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> option <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>pairs<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> pair <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pair.<span style="color: #660066;">length</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    option<span style="color: #009900;">&#91;</span>pair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pair<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Get the width and height of the document.</span>
  <span style="color: #003366; font-weight: bold;">var</span> width <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> height <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Get the width and height of the dialog.</span>
  <span style="color: #003366; font-weight: bold;">var</span> dialogWidth <span style="color: #339933;">=</span> option.<span style="color: #660066;">dialogWidth</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #003366; font-weight: bold;">var</span> dialogHeight <span style="color: #339933;">=</span> option.<span style="color: #660066;">dialogHeight</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Calculate where the dialog needs to be to be</span>
  <span style="color: #006600; font-style: italic;">// centered.</span>
  <span style="color: #003366; font-weight: bold;">var</span> dialogLeft <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>width <span style="color: #339933;">-</span> dialogWidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> dialogTop <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>height <span style="color: #339933;">-</span> dialogHeight<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Add those settings to the options string.</span>
  options <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;dialogLeft: &quot;</span> <span style="color: #339933;">+</span> dialogLeft <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;; &quot;</span><span style="color: #339933;">;</span>
  options <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;dialogTop: &quot;</span> <span style="color: #339933;">+</span> dialogTop <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;; &quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Call the original function.</span>
  <span style="color: #000066; font-weight: bold;">return</span> oldShowModalDialog<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> args<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Although this code uses <a href="http://jquery.com">jQuery</a>, you could easily rewrite it to use vanilla JavaScript.</p>
<h3>Will it be fixed soon?</h3>
<p>Firefox has had <code>showModalDialog</code> since 3.0.  So naturally, you&#8217;d have assumed they&#8217;d have fixed this bug in 3.5, right?  Nope!  The bug still exists in 3.5.  Thus, I wouldn&#8217;t hold my breath on this one being fixed anytime soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/07/how-to-kinda-fix-firefoxs-showmodaldialog/feed/</wfw:commentRss>
		<slash:comments>2</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>

