<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/css/rss20.xsl" type="text/xsl"?>
<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/" xmlns:pheedo="http://www.pheedo.com/namespace/pheedo">
	<channel>
		<title>SitePoint &#187; JavaScript &amp; CSS</title>
		<atom:link href="http://www.sitepoint.com/blogs/category/dhtml-css/feed/" rel="self" type="application/rss+xml"/>
		<link>http://www.sitepoint.com/blogs</link>
		<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
		<lastBuildDate>Sat, 07 Nov 2009 08:39:08 +0000</lastBuildDate>
		<generator>http://wordpress.org/?v=2.8.4</generator>
		<language>en</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
		<item>
			<title>Fixing Object Instances in JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=0db6ca4b30c8a06738f901a20f546712</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/10/21/javascript-object-instances/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/10/21/javascript-object-instances/#comments</comments>
			<pubDate>Tue, 20 Oct 2009 15:59:34 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category><![CDATA[javascript]]></category>
			<category>javascript</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=15206</guid>
			<description><![CDATA[Even experienced coders can get caught out by object handling in JavaScript, and handing your code to other developers can intensify problems. Craig looks at the problem of creating object instances and provides a quick solution.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=0db6ca4b30c8a06738f901a20f546712&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=0db6ca4b30c8a06738f901a20f546712&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img class="imgright" src="http://blogs.sitepointstatic.com/images/tech/179-js-object-instance.jpg" alt="JavaScript objects" width="190" height="190" />Do you know your JavaScript? Take a look at the following code sample and work out what value is shown in the final alert statement …</p>
<pre><code class="javascript">
// object constructor
function ObjectConstructor(a, b, c) {

	this.A = a;
	this.B = b;
	this.C = c;
	this.Total = a + b + c;

}

var obj = ObjectConstructor(1, 2, 3);

alert(obj.Total);
</code></pre>
<p>Hands up everyone who answered &#8220;6.&#8221;</p>
<p>Sorry, you&#8217;re wrong. The answer is … nothing &#8212; or an error stating that &#8216;obj&#8217; is undefined. So what&#8217;s gone wrong?</p>
<p>The simple answer is that we&#8217;ve forgotten the &#8216;new&#8217; operator so an object instance is never created. The statement should be:</p>
<div id="adz" class="horizontal"></div><pre><code class="javascript">
var obj = new ObjectConstructor(1, 2, 3);
</code></pre>
<p>It&#8217;s an easy mistake to make. Novice developers are unlikely to spot the missing operator because the code looks almost identical. Even experienced coders could find it tough to debug (especially since many assume JavaScript is a <a href="http://en.wikipedia.org/wiki/Procedural_language">procedural programming language</a> … which it can be, if you choose to write it that way).</p>
<p>The main problem is that <code>var obj = ObjectConstructor(1, 2, 3);</code> is a perfectly valid JavaScript statement and the interpretor engine will not throw an error. In that context, the value of obj is set to the value returned from the function ObjectConstructor; since no value is returned, obj remains &#8220;undefined&#8221; (a top-level JavaScript property).</p>
<p>This is unlikely to become a major problem if you&#8217;re developing, testing and debugging your own code. However, it could be a different matter when you&#8217;re providing a library or API to thousands of third-party developers. At some point, someone, somewhere, will miss that &#8216;new&#8217; operator and they will blame your code rather than theirs.</p>
<p>Fortunately, JavaScript is a flexible language. We can fix our constructor so an object is correctly created even when the &#8216;new&#8217; operator is omitted:</p>
<pre><code class="javascript">
// object constructor
function ObjectConstructor(a, b, c) {

	if (!(this instanceof arguments.callee)) {
		return new ObjectConstructor(a, b, c);
	}

	this.A = a;
	this.B = b;
	this.C = c;
	this.Total = a + b + c;

}
</code></pre>
<p>The additional &#8216;if&#8217; statement at the top of the constructor checks whether &#8216;this&#8217; is an instance of the object and returns one if necessary. The code <code>var obj = ObjectConstructor(1, 2, 3);</code> will now set obj to an object instance and &#8220;6&#8243; will be output by the alert statement.</p>
<p>Have you ever encountered this problem in your code or when using another library?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=0db6ca4b30c8a06738f901a20f546712&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=0db6ca4b30c8a06738f901a20f546712&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/10/21/javascript-object-instances/feed/</wfw:commentRss>
			<slash:comments>21</slash:comments>
		</item>
		<item>
			<title>CSS Frameworks and Semantic Class Names</title>
			<link>http://www.pheedcontent.com/click.phdo?i=adadb8e65cb945f6761aac2a903d57d7</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/10/06/css-frameworks-semantic-class-names/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/10/06/css-frameworks-semantic-class-names/#comments</comments>
			<pubDate>Mon, 05 Oct 2009 23:17:53 +0000</pubDate>
			<dc:creator>Kevin Yank</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category>CSS</category>
			<category>design</category>
			<category>frameworks</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=14814</guid>
			<description><![CDATA[CSS frameworks often contain crufty, non-semantic code. Does it have to be that way? Kevin shows us how semantic markup and CSS frameworks can coexist happily.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=adadb8e65cb945f6761aac2a903d57d7&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=adadb8e65cb945f6761aac2a903d57d7&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img class="imgright size-thumbnail wp-image-14817" title="CSS Dozer" src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/10/dozer-150x150.png" alt="A bulldozer pushing the letters C S S" width="150" height="150" /></p>
<p><strong>One of the most common complaints about CSS frameworks like <a href="http://blueprintcss.org/">Blueprint</a>, <a href="http://developer.yahoo.com/yui/grids/">YUI Grids</a>, and <a href="http://960.gs/">960.gs</a> is that they require designers to dirty their fingers by adding presentational class names to their HTML documents, like so:</strong></p>
<pre><code>&lt;div class="span-9 last"&gt;
&lt;div class="grid_6 alpha"&gt;</code></pre>
<p>Class names like <code>"span-9"</code> really bother designers who care about the quality of their HTML code, because they describe the <strong>appearance</strong> of an element; this should really be left to the CSS properties defined in your site&#8217;s style sheets. The problem with presentational class names is explained especially well by the W3C QA tip, <a href="http://www.w3.org/QA/Tips/goodclassnames"><cite>Use <code>class</code> with semantics in mind</cite></a>:</p>
<blockquote cite="http://www.w3.org/QA/Tips/goodclassnames"><p><strong>Good names don&#8217;t change.</strong> Think about <em>why</em> you want something to look a certain way, and not really about <em>how</em> it should look. Looks can always change, but the reasons for giving something a look stay the same.</p></blockquote>
<div id="adz" class="vertical"></div><p>Maybe you&#8217;re the pragmatic type who takes no issue with this sort of thing, or decides that it&#8217;s a necessary evil given the limitations of the CSS language. Nevertheless, there are plenty of front-end ninjas out there who refuse to use CSS frameworks for this very reason.</p>
<p>It turns out, however, that the latest crop of CSS frameworks provide clever solutions to the problem of presentational class names.</p>
<p><a href="http://blueprintcss.org/">Blueprint CSS</a>, the granddaddy of CSS layout frameworks, now includes a clever Ruby script called compress.rb in its download package. In <a href="http://www.jdclayton.com/blueprints_compress_a_walkthrough.html"><cite>Blueprint&#8217;s compress.rb: A Walkthrough</cite></a>, Blueprint author Joshua Clayton explains how to use the script to generate a custom version of the Blueprint style sheets using your own semantic class names.</p>
<p>The process boils down to writing a simple configuration file that tells the script how to map Blueprint&#8217;s presentational class names to your own semantically meaningful class names. The file will look like this:</p>
<pre><code>demo:
  path: /Users/kyank/Documents/myproject
  semantic_classes:
    ".header, .footer": ".span-24, div.span-24"
    ".content": ".span-18, div.span-18"
    ".sidebar": ".span-6, div.span-6,
                 .last, div.last"</code></pre>
<p>The <code>semantic_classes</code> section provides the mapping. In this example, the <code>header</code> and <code>footer</code> classes will be 24 grid units wide and the <code>content</code> class will be 18 grid units wide. The <code>sidebar</code> class will be 6 grid units wide and the last block in its row.</p>
<p>With this configuration file written, you simply run the compress.rb script, and the customized version of the Blueprint style sheet files (screen.css, print.css, and ie.css) will be generated in the specified path. The style sheet will contain rules like this one, that apply the grid dimensions to your custom class names:</p>
<pre><code>/* semantic class names */
.content {float:left;margin-right:10px;
  width:710px;}</code></pre>
<p>&#8230; and just like that, you gain all the layout facilities of Blueprint CSS with none of the HTML cruft!</p>
<p>If manually compiling your style sheets with a Ruby script sounds like a bit of a pain (which it can be &#8212; especially if you develop on a Windows computer without Ruby installed), a server-side CSS framework might be a better option for you.</p>
<p>CSS frameworks are popping up for all the major server-side programming languages. Two prominent examples include <a href="http://compass-style.org/">Compass</a> (for Ruby), and <a href="http://wiki.github.com/anthonyshort/csscaffold">Scaffold</a> (for PHP). These frameworks let you write your style sheets with extra language features, and automatically compile them to standard CSS code when sending them to the browser.</p>
<p>Using Scaffold, for example, you could write your style sheet like this:</p>
<pre><code>@grid {
  column-width:30;
  column-count:24;
  right-gutter-width:20;
  baseline:20;
  unit:px;
}
.header, .footer {
  +columns(24);
}
.content {
  +columns(18);
}
.sidebar {
  +columns(6);
  +last;
}</code></pre>
<p>The <code>@grid</code> at-rule sets up the options for Scaffold&#8217;s <a href="http://wiki.github.com/anthonyshort/csscaffold/layout-plugin">layout plugin</a>, and then lines like <code>+columns(24);</code> (called <strong>mixins</strong>) are compiled into standard CSS properties when the browser requests the style sheet.</p>
<p>These are just a couple of the ways that the latest CSS frameworks respond to those critics who complain about having to sacrifice HTML code quality to use them. Now you can have all the benefits of a well-tested layout framework, and apply them to your HTML code on your terms.</p>
<p style="text-align: right;"><cite>(photo: <a href="http://www.sxc.hu/photo/858987">Nbauer</a>)</cite></p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=adadb8e65cb945f6761aac2a903d57d7&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=adadb8e65cb945f6761aac2a903d57d7&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/10/06/css-frameworks-semantic-class-names/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		</item>
		<item>
			<title>Interesting CSS Quirks: Border-spacing</title>
			<link>http://www.pheedcontent.com/click.phdo?i=558f1069b5c6530ec1bf9b59f02ec856</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/10/01/interesting-css-quirks-border-spacing/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/10/01/interesting-css-quirks-border-spacing/#comments</comments>
			<pubDate>Thu, 01 Oct 2009 01:50:54 +0000</pubDate>
			<dc:creator>AlexW</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=14646</guid>
			<description><![CDATA[I came across a CSS peculiarity recently that had me scratching my head, so I thought it was worth popping in a little post here for future Googling head-scratchers. <br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=558f1069b5c6530ec1bf9b59f02ec856&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=558f1069b5c6530ec1bf9b59f02ec856&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p>I came across a CSS peculiarity recently that had me scratching my head, so I thought it was worth popping in a little post here for future Googling head-scratchers. </p>
<p>The <a href="http://webstandardsgroup.org/mail/">WSG mailing list</a> gets a lot of CSS layout questions sent to it and last week I noticed <a href="http://www.mail-archive.com/wsg@webstandardsgroup.org/msg39800.html">this query</a>. Tee wanted to visually reproduce the table layout shown below without adding extra wrapping DIVs or other non-semantic markup.</p>
<p><img src="http://www.sitepoint.com/examples/tabletest/example.png" alt="Example table layout" width="363px" height="188px" class="imgright" /></p>
<p>It&#8217;s not quite as simple as it looks. </p>
<div id="adz" class="horizontal"></div><p>Anyway, playing around <a href="http://www.sitepoint.com/examples/tabletest/tabletest.html">my approach</a>, I came across a CSS property I&#8217;ve rarely seen in use: <code>border-spacing</code>. </p>
<p>Now if you&#8217;re not super familiar with <code>border-spacing</code>, it&#8217;s essentially a better version of the old &#8216;cellspacing&#8217; table attribute (i.e. <code>&lt;table cellspacing="3px" ..</code>) , and controls the space *between* your table cells. Of course, if you set the table&#8217;s border to collapse (i.e. <code>border-collapse:collapse;</code>) there *is* no space between your table cells, so setting <code>border-spacing</code> becomes redundant.</p>
<p>The key advantage that CSS&#8217;s border-spacing has over HTML&#8217;s cellspacing (besides cleaner markup) is it allows you to set <em>different</em> horizontal and vertical spacing widths &#8212; seemingly perfect for creating the 5 pixel row separations required in the example. <code><a href="http://reference.sitepoint.com/html/table/cellspacing">Cellspacing</a></code> only accepts a single value.</p>
<p>Guessing the CSS, I didn&#8217;t get the result I expected when I tried (<a href="http://reference.sitepoint.com/css/border-spacing/demo">try for yourself</a>): </p>
<pre>
<code class="css">
table#grid {
	border-collapse:separate;
	border-spacing:  5px 0px ;
}
</code>
</pre>
<p><img src="http://i2.sitepoint.com/images/blogs/border-spacing.png" alt="Border-spacing in action" class="imgleft" />Counter-intuitively to the way <code>margin</code>, <code>padding</code>, <code>border</code> and every other CSS property I can think of operates, <code>border-spacing</code> asks for it&#8217;s horizontal value <em>before</em> it&#8217;s vertical value. Strange.</p>
<p>Other points to note with <code>border-spacing</code>:</p>
<ul>
<li>You aren&#8217;t able to assign different top, bottom, right and left values. This makes sense if you think about it, as we&#8217;re actually talking about an attribute of the TABLE, but I think it&#8217;s easy to trick yourself into thinking it&#8217;s part of the TD &#8212; it wraps around the TD borders after all.</li>
<li>Support is perfect in all modern browsers, but old IE6 &#038; 7 don&#8217;t support this property at all.</li>
</ul>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=558f1069b5c6530ec1bf9b59f02ec856&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=558f1069b5c6530ec1bf9b59f02ec856&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/10/01/interesting-css-quirks-border-spacing/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		</item>
		<item>
			<title>JSNES: a NES Emulator Written in JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=8c20aee44fe4db6ce2ddc242a97ca30c</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/09/27/jsnes-javascript-nes-emulator/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/09/27/jsnes-javascript-nes-emulator/#comments</comments>
			<pubDate>Sat, 26 Sep 2009 17:29:30 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category><![CDATA[development]]></category>
			<category><![CDATA[javascript]]></category>
			<category>development</category>
			<category>game</category>
			<category>JavaScript</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=14340</guid>
			<description><![CDATA[Just when you thought you'd seen everything in JavaScript, along comes a full NES emulator that is actually playable in a browser. Craig takes a look at JSNES.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=8c20aee44fe4db6ce2ddc242a97ca30c&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=8c20aee44fe4db6ce2ddc242a97ca30c&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sitepointstatic.com/images/tech/162-javascript-nes.png" width="256" height="256" alt="JSNES" class="imgright" />Today&#8217;s award for the most unlikely, probably pointless, but simply stunning use of JavaScript goes to Ben Firshman and his Nintendo Entertainment System emulator, JSNES.</p>
<p><a href="http://benfirshman.com/projects/jsnes/"><strong>Visit the JSNES page&#8230;</strong></a></p>
<p>The emulator is port of the Java-based <a href="http://www.virtualnes.com/">vNES</a> project. It uses the HTML <code>canvas</code> element for screen rendering (sorry Internet Explorer users) although sound is not supported yet.</p>
<p>There are 17 working games to try. Most will run in Firefox 3.5 or Safari 4, but neither browser offers a playable gaming experience. You&#8217;ll be lucky to achieve 10 frames per second on the highest-specification liquid-nitrogen-cooled ninja PC.</p>
<div id="adz" class="horizontal"></div><p>The real revelation, however, is Google Chrome &#8212; it runs the emulator at full speed (50-60 fps) on a modest PC. Google&#8217;s <code>canvas</code> performance optimization appears to be out-pacing the competition by a considerable margin. Both <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=509986">Mozilla</a> and <a href="https://bugs.webkit.org/show_bug.cgi?id=29534">WebKit</a> have raised bugs to investigate why there is such a noticeable speed difference.</p>
<p>Although JSNES is little more than an interesting experiment, it illustrates what can be achieved with modern JavaScript engines, some ingenuity, and lots of caffeine. Ben Firshman &#8212; you are a genius. My only question is &hellip; why?!!</p>
<p>See also: <a href="http://www.sitepoint.com/blogs/2009/10/16/ben-firshman-jsnes-interview/">SitePoint&#8217;s Exclusive Interview With Ben Firshman, Creator of JSNES</a></p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=8c20aee44fe4db6ce2ddc242a97ca30c&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=8c20aee44fe4db6ce2ddc242a97ca30c&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/09/27/jsnes-javascript-nes-emulator/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		</item>
		<item>
			<title>Who&#8217;s Using ARIA?</title>
			<link>http://www.pheedcontent.com/click.phdo?i=d8da1e69874b77babf0db07a58a810b5</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/09/16/whos-using-aria/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/09/16/whos-using-aria/#comments</comments>
			<pubDate>Wed, 16 Sep 2009 06:50:26 +0000</pubDate>
			<dc:creator>brothercake</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=14171</guid>
			<description><![CDATA[In this post, James discusses the concept of Accessible Rich Internet Applications, and asks "where are the users?"<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=d8da1e69874b77babf0db07a58a810b5&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=d8da1e69874b77babf0db07a58a810b5&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-14172" src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/09/pegs.jpg" alt="A square peg in a round hole" width="200" height="200" /></p>
<p>And I don&#8217;t mean developers, I mean <em>real people</em> — actual users, who are browsing the Web with assistive devices and making use of <a href="http://www.w3.org/WAI/intro/aria"><abbr title="Accessible Rich Internet Application">ARIA</abbr></a> enabled applications?</p>
<p>See, when I first researched the question of accessible Ajax for <a href="http://www.sitepoint.com/books/jsant1/">The JavaScript Anthology</a>, back in 2006, there was no such thing as <abbr title="Accessible Rich Internet Application">ARIA</abbr>; there was only the early draft ideas that would eventually become it, based largely on work done at IBM.</p>
<p>And I was unimpressed. Not because of any specific details, but over the entire concept behind it — the idea that all <abbr title="Rich Internet Applications">RIAs</abbr> needed to make them usable for screenreaders is <strong>more information</strong> seemed naïve.</p>
<div id="adz" class="vertical"></div><p>And now that we have a <a href="http://www.w3.org/TR/wai-aria/">formal specification</a>, with browsers and screenreaders that have working implementations, I ask the same question — are <abbr title="Rich Internet Applications">RIAs</abbr> really appropriate to assistive devices if only they had that role and state information, or are we trying to force a square peg into a round hole? Are we just adding layers of information on top of a paradigm that is fundamentally incompatible with the target devices?</p>
<p>What my question really comes down to is, can any Ajax-based application which requires an <abbr title="Application Programming Interface">API</abbr> to give the consuming device enough information to make sense of it, possibly be better than what we had before — where you submit a form and you get a new page in response — something that generations of devices were well able to comprehend.</p>
<p>I&#8217;m not trying to dredge up my <a href="http://dev.opera.com/articles/view/stop-using-ajax/">stop using Ajax</a> argument again — not at all, I accept that Ajax is here to stay, and welcome it as a valuable addition to the programmer&#8217;s toolkit. But the hype has yet to calm down, and Ajax is still over-used. The question of <strong>to what extent Ajax applications are expected to progressively enhance from static applications</strong> is still very much an issue, as the bulk of the comments in <a title="SitePoint blog post: 5 Reasons Why You Should Not Publish Supported Browser Lists, by Craig Buckler" href="http://www.sitepoint.com/blogs/2009/09/10/5-reasons-to-avoid-supported-browser-lists/">one of Craig&#8217;s recent posts</a> highlighted all too sharply.</p>
<p>So where are the <abbr title="Accessible Rich Internet Application">ARIA</abbr> users? And what do <em>they</em> think?</p>
<p>It&#8217;s an honest question, because I really don&#8217;t know. Is there any information? Have any studies been carried out, that convincingly answer the question of whether <abbr title="Accessible Rich Internet Application">ARIA</abbr> enabled applications are a better user experience for people using assistive technologies, compared with conventional post-and-response style applications, that <abbr title="Rich Internet Applications">RIAs</abbr> should otherwise be  expected to degrade to?</p>
<p>Is <abbr title="Accessible Rich Internet Application">ARIA</abbr> really the way forward, or is it just a solution looking for a problem?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=d8da1e69874b77babf0db07a58a810b5&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=d8da1e69874b77babf0db07a58a810b5&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/09/16/whos-using-aria/feed/</wfw:commentRss>
			<slash:comments>18</slash:comments>
		</item>
		<item>
			<title>How to Write a Cookie-less Session Library for JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=caab1f39362d4318b3df8c719a535b2d</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/09/03/javascript-session-variable-library/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/09/03/javascript-session-variable-library/#comments</comments>
			<pubDate>Wed, 02 Sep 2009 16:29:26 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category>cookies</category>
			<category>javascript</category>
			<category>sessions</category>
			<category>variables</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=13335</guid>
			<description><![CDATA[Craig provides the code for a stand-alone JavaScript session variable handling system that does not require cookies or third-party libraries.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=caab1f39362d4318b3df8c719a535b2d&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=caab1f39362d4318b3df8c719a535b2d&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sitepointstatic.com/images/tech/135-javascript-sessions.jpg" width="250" height="250" alt="the (JavaScript) Cookie Monster" class="imgright" />In my previous post, <a href="http://www.sitepoint.com/blogs/2009/09/02/cookieless-javascript-session-variables/">Cookie-less Session Variables in JavaScript</a>, we discovered how JavaScript session data could be saved to the window.name property. Today, we create a JavaScript library to exploit this property.</p>
<p><a href="http://blogs.sitepointstatic.com/examples/tech/js-session/index.html"><strong>View the JavaScript session library demonstration page&#8230;</strong></a></p>
<p>The code provides three main methods:</p>
<ul>
<li><strong>Session.set(<em>name</em>, <em>object</em>)</strong> &#8212; store a named session value/object</li>
<li><strong>Session.get(<em>name</em>)</strong> &#8212; retrieve a named session value/object</li>
<li><strong>Session.clear()</strong> &#8212; reset all the session data</li>
</ul>
<div id="adz" class="horizontal"></div><p>Another <strong>Session.dump()</strong> method returns all the JSON-encoded session data. This would normally be used for debugging purposes only.</p>
<p>The JavaScript code is loaded just before the closing <code>body</code> tag. First, we load the JSON library:</p>
<pre><code class="javascript">
&lt;script type=&quot;text/javascript&quot; src=&quot;json-serialization.js&quot;&gt;&lt;/script&gt;
</code></pre>
<p>The JSON library provides cross-browser serialization methods that are required by our Session library. For more information, refer to <a href="http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/">Cross-browser JSON Serialization in JavaScript</a>.</p>
<p>The <a href="http://blogs.sitepointstatic.com/examples/tech/js-session/session.js">session.js</a> file is loaded next. This is stand-alone code that can be implemented in any system &#8212; it does not depend on jQuery or any other JavaScript library. Working through the code:</p>
<pre><code class="javascript">
 if (JSON &amp;&amp; JSON.stringify &amp;&amp; JSON.parse) var Session = Session || (function() {

	// window object
	var win = window.top || window;

	// session store
	var store = (win.name ? JSON.parse(win.name) : {});
</code></pre>
<p>The first line defines our Session module. However, it will only be defined if the JSON library has been loaded and there are no other conflicting Session variables or functions.</p>
<p>The second line sets win to &#8216;window.top&#8217;. It is set to &#8216;window&#8217; if that is not available (perhaps if the browser does not support frames).</p>
<p>Next, we define a &#8217;store&#8217; object to hold all our session data. Exisiting JSON-encoded data in the window.name property is parsed but, if that is not available, &#8217;store&#8217; is set to an empty object.</p>
<pre><code class="javascript">
	// save store on page unload
	function Save() {
		win.name = JSON.stringify(store);
	};

	// page unload event
	if (window.addEventListener) window.addEventListener(&quot;unload&quot;, Save, false);
	else if (window.attachEvent) window.attachEvent(&quot;onunload&quot;, Save);
	else window.onunload = Save;
</code></pre>
<p>The private Save() function assigns the serialized the &#8217;store&#8217; object string to the window .name property. The following three lines define a cross-browser event which calls the Save function when the page is unloaded. Your pages can therefore modify the &#8217;store&#8217; as much as necessary, but the heavy work of serializing and saving only occurs at the last possible moment.</p>
<pre><code class="javascript">
	// public methods
	return {

		// set a session variable
		set: function(name, value) {
			store[name] = value;
		},

		// get a session value
		get: function(name) {
			return (store[name] ? store[name] : undefined);
		},

		// clear session
		clear: function() { store = {}; },

		// dump session data
		dump: function() { return JSON.stringify(store); }

	};

 })();
</code></pre>
<p>Finally, we have our four public set, get, clear and dump functions which handle the store object accordingly. The Session.get() method will return a JavaScript &#8216;undefined&#8217; value if a session name can not be found.</p>
<p>I hope you find the code useful. Feel free to use it in your own projects.</p>
<p>Useful resources:</p>
<ul>
<li><a href="http://blogs.sitepointstatic.com/examples/tech/js-session/index.html"><strong>JavaScript session variables demonstration page</strong></a></li>
<li><a href="http://blogs.sitepointstatic.com/examples/tech/js-session/session.js">Full JavaScript session.js code</a></li>
<li><a href="http://blogs.sitepointstatic.com/examples/tech/js-session/js-session.zip">Download full code in a ZIP file</a></li>
</ul>
<p>See also:</p>
<ul>
<li><a href="http://www.sitepoint.com/blogs/2009/09/02/cookieless-javascript-session-variables/">Cookie-less Session Variables in JavaScript</a></li>
<li><a href="http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/">Cross-browser JSON Serialization in JavaScript</a></li>
<li><a href="http://www.sitepoint.com/blogs/2009/07/22/how-to-develop-a-jquery-plugin/">How To Develop a jQuery Plugin</a></li>
<li><a href="http://www.sitepoint.com/blogs/2009/07/29/build-auto-expanding-textarea-1/">How to Build an Auto-Expanding Textarea jQuery Plugin</a></li>
</ul>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=caab1f39362d4318b3df8c719a535b2d&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=caab1f39362d4318b3df8c719a535b2d&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/09/03/javascript-session-variable-library/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		</item>
		<item>
			<title>Cookie-less Session Variables in JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=ce9dbaea787cd0c979818fc380ea1605</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/09/02/cookieless-javascript-session-variables/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/09/02/cookieless-javascript-session-variables/#comments</comments>
			<pubDate>Tue, 01 Sep 2009 17:14:10 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=13332</guid>
			<description><![CDATA[Cookies may be delicious, but they can be clumsy if you need to store temporary data in a JavaScript application. Craig provides an unlikely alternative...<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=ce9dbaea787cd0c979818fc380ea1605&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=ce9dbaea787cd0c979818fc380ea1605&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sitepointstatic.com/images/tech/135-javascript-sessions.jpg" width="250" height="250" alt="the (JavaScript) Cookie Monster" class="imgright" />Cookies may be delicious delicacies, but they can leave a nasty taste if you don&#8217;t cook them correctly! Cookies can be blocked by the user, storage space is limited to four 20Kb cookies per domain, only strings can be used, paths can cause confusion, and the data is normally passed as plain text in the HTTP header. Often, cookies can be overkill for client-side-heavy applications that need to save temporary state data.</p>
<p>Fortunately, there is a solution that allows you to store JavaScript data within the browser. The data is retained between page loads, it&#8217;ll survive page back/next events (even away from the domain), it does not require plugins or off-line storage facilities, it&#8217;ll hold at several megabytes of information, it is never transmitted to the server, and works in every browser. Bizarrely, it works by exploiting the window.name property (or window.top.name if you&#8217;re using multiple frames). </p>
<p>It&#8217;s rare for developers set the window.name property. Generally, it&#8217;s only required when you&#8217;re manipulating frames or pop-up windows. Even though I&#8217;d hope you weren&#8217;t doing that, you do not normally need to define a name for an application&#8217;s starting window. Although the name property is still a string, it can hold several megabytes of data. Some versions of Opera limit it to around 2Mb but most browsers offer 10MB or more.</p>
<p>It&#8217;s easy to try for yourself. Insert the following JavaScript code into a page on your site:</p>
<pre><code class="javascript">
window.name = &quot;This message will survive between page loads.&quot;;
</code></pre>
<p>Now add the following code to any other page:</p>
<div id="adz" class="vertical"></div><pre><code class="javascript">
alert(window.name);
</code></pre>
<p>Navigate from the first page to the second and you&#8217;ll find that the message data is retained.</p>
<p>As normal, there are a number of caveats:</p>
<ol>
<li>The window.name property can be analysed and changed if you navigate to page on another website. That&#8217;s easily thwarted by not providing external links within your application&#8217;s main window. However, to be on the safe side, don&#8217;t use window.name for storing secure data (unlikely to be a major problem for a client-side-only temporary data store).</li>
<li>window.name can only store strings. What if we need to save other data types or even complex objects? Serialization is the answer and, fortunately, we have already developed <a href="http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/">cross-browser code to generate JSON strings from any JavaScript object</a>.</li>
</ol>
<p>See also: <a href="http://www.sitepoint.com/blogs/2009/09/03/javascript-session-variable-library/">How to Write a Cookie-less Session Library for JavaScript</a>.</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=ce9dbaea787cd0c979818fc380ea1605&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=ce9dbaea787cd0c979818fc380ea1605&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/09/02/cookieless-javascript-session-variables/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		</item>
		<item>
			<title>CSS Font-Sizing: a Definitive Guide</title>
			<link>http://www.pheedcontent.com/click.phdo?i=b603e3a1ebb2c7419cb1bdc5f646844d</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/08/20/css-font-sizing-tutorial/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/08/20/css-font-sizing-tutorial/#comments</comments>
			<pubDate>Thu, 20 Aug 2009 07:43:19 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=13101</guid>
			<description><![CDATA[CSS font sizing appears to be easy until you try it. Craig provides a handy guide to the CSS font-size property and makes several useful recommendations.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=b603e3a1ebb2c7419cb1bdc5f646844d&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=b603e3a1ebb2c7419cb1bdc5f646844d&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sitepointstatic.com/images/tech/129-css-font-sizes.png" width="250" height="250" alt="CSS font sizing" class="imgright" />Font sizing in CSS sounds as though it should be easy. Until you try it. Many developers use the force; they tinker with the font-size property until it looks right only to find it&#8217;s different in another browser. A little understanding can go a long way&#8230;</p>
<h2>The font-size Property</h2>
<p>The <code>font-size</code> property can be set for any HTML tag (even if it would not normally contain textual content like <code>br</code>). It can be assigned a variety of absolute, relative, or length size parameters.</p>
<p>An element will inherit the font-size of its parent unless you override it. This is especially important when you specify relative sizes.</p>
<div id="adz" class="vertical"></div><h2>Absolute Font Sizing Keywords</h2>
<p>Several absolute font-sizing keywords are available. The font size is determined from a browser preset and the element will not inherit its parent&#8217;s size.</p>
<ul>
<li style="font-size: xx-small;">font-size: xx-small;</li>
<li style="font-size: x-small;">font-size: x-small;</li>
<li style="font-size: small;">font-size: small;</li>
<li style="font-size: medium;">font-size: medium;</li>
<li style="font-size: large;">font-size: large;</li>
<li style="font-size: x-large;">font-size: x-large;</li>
<li style="font-size: xx-large;">font-size: xx-large;</li>
</ul>
<p>Although most browsers support these keywords, the exact sizes will differ. They are a fairly crude method of font sizing and are generally avoided by most developers.</p>
<h2>Relative Font Sizing Keywords</h2>
<p>Two relative font-sizing keywords are available. The font is sized according to its parent element:</p>
<ul>
<li style="font-size: smaller;">font-size: smaller;</li>
<li style="font-size: larger;">font-size: larger;</li>
</ul>
<p>For example, if the parent has a font size of &#8216;medium&#8217;, a value of &#8216;larger&#8217; will set the element to &#8216;large&#8217;. Other font units are normally altered by a factor of around 1.2 but, again, there is no standard and browser results will differ.</p>
<h2>Absolute Lengths</h2>
<p>The <code>font-size</code> property can be assigned an absolute length:</p>
<ul>
<li><strong>mm</strong>: millimeters, e.g. 10mm.</li>
<li><strong>cm</strong>: centimeters, e.g. 1cm ( = 10mm).</li>
<li><strong>in</strong>: inches, e.g. 0.39in ( ~= 10mm).</li>
<li><strong>pt</strong>: point, where 1pt is generally assumed to be 1/72 inch e.g. 12pt.</li>
<li><strong>pc</strong>: pica, where 1pc is 12pt</li>
<li><strong>px</strong>: pixel, e.g. 14px.</li>
</ul>
<p>In general, there are issues with all these measurement units. Millimeters, centimeters and inches are inaccurate for a screen-based medium. Points and picas are unreliable since systems can use different <abbr title="dots per inch">dpi</abbr> settings. Pixel appears to be the most suitable, but it can lead to accessibility issues because the <a href="#textpagezoom">text cannot be resized in IE</a>.</p>
<h2>Relative Lengths</h2>
<p>The <code>font-size</code> property can be assigned a unit that it relative to its parent&#8217;s font size:</p>
<ul>
<li><strong>em</strong>: 1em is equivalent to the current font size, so 2em is twice as large.</li>
<li><strong>%</strong>: 100% is equivalent to the current font size, so 200% is twice as large.</li>
<li><strong>ex</strong>: 1ex is equivalent to the height of the letter &#8216;x&#8217; in the current font.</li>
</ul>
<p>Few developers use &#8216;ex&#8217;, but it can be useful in some situations where you need fine-grained font sizes, e.g. 1ex rather than 0.525em.</p>
<p>Percentage and &#8216;em&#8217; sizes are equivalent, e.g. 50% = 0.5em, 100% = 1em, 120% = 1.2em, etc. Some browsers exhibit subtle differences but it&#8217;s rarely a major problem. If you want to save every byte, you could choose the shortest definition, i.e. 50% is shorter than 0.5em and 1em is shorter than 100%.</p>
<h2 id="textpagezoom">Text Sizing and Page Zooming</h2>
<p>This is where additional complexity creeps in. Most browsers allow the user to:</p>
<ol>
<li>increase or decrease the base text size (image dimensions are not changed)</li>
<li>zoom the page in or out so all the text and graphics change accordingly, or</li>
<li>allow both text sizing and page zooming.</li>
</ol>
<p><em>Just to complicate matters further, Internet Explorer does not allow text resizing on elements which have a font size defined in pixels (px).</em></p>
<p>If you&#8217;re a designer moving to the web from a print background, it&#8217;s disconcerting to give the user that much power. Your design could be ruined by a user zooming in 200% but reducing the text size to 50%. And &#8212; no &#8212; there is nothing you can do to prevent it. Nor should you.</p>
<h2>CSS Font Sizing Recommendations</h2>
<p>The general consensus is that &#8216;em&#8217; or &#8216;%&#8217; is the best solution in most situations. Fonts can be finely scaled relative to each other and browser text sizing is supported. I would also recommend using a percentage <code>font-size</code> on the body tag; it results in better text-sizing in some older browsers.</p>
<p>There are a couple of other recommendations I would suggest when you&#8217;re developing a site:</p>
<ol>
<li>reset the font size and page zoom to their default values in all your browsers before testing (it&#8217;s caught me out a few times!)</li>
<li>try <em>reasonable</em> combinations of text sizing and page zooming in a variety of browsers to ensure the text remains readable.</li>
</ol>
<p>Has font sizing ever caused you problems? Do you have any other tips?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=b603e3a1ebb2c7419cb1bdc5f646844d&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=b603e3a1ebb2c7419cb1bdc5f646844d&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/08/20/css-font-sizing-tutorial/feed/</wfw:commentRss>
			<slash:comments>54</slash:comments>
		</item>
		<item>
			<title>Cross-browser JSON Serialization in JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=1b0f67a32a5ceaeaf1a1ea4ff6f43997</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/#comments</comments>
			<pubDate>Tue, 18 Aug 2009 17:24:27 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=13302</guid>
			<description><![CDATA[JSON serialization can be incredibly useful, but few browsers support it. Fortunately, Craig has provided a few lines of code that could be your serialization savior.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=1b0f67a32a5ceaeaf1a1ea4ff6f43997&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=1b0f67a32a5ceaeaf1a1ea4ff6f43997&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sitepointstatic.com/images/tech/133-javascript-serialization.jpg" width="260" height="260" alt="JavaScript JSON serialization" class="imgright" />In this article we will examine the benefits of object serialization, the current browser implementations, and develop some code that could help your Ajax-based projects.</p>
<p>Assume we have a fairly complex JavaScript object defined using literal notation:</p>
<pre><code class="javascript">
var obj1 = {
	b1: true,
	s1: &quot;text string&quot;,
	n1: 12345,
	n2: null,
	n3: undefined,
	a1: [ 1,1,2,3,5,8, [13, 21, 34] ],
	o1: {
		a: [3, 2, 1],
		b: {
			c: 42,
			d: [ 3.14, 1.618 ]
		}
	}
};
</code></pre>
<p>We can access any of the object properties in a variety of ways:</p>
<pre><code class="javascript">
obj1.s1;				// returns &quot;text string&quot;
obj1[&quot;n1&quot;];				// returns 12345
obj1.a1[6][1];			// returns 21
obj1[&quot;o1&quot;][&quot;b&quot;][&quot;c&quot;];	// returns 42
</code></pre>
<p>This object can also be passed to JavaScript functions and methods rather than specifying individual arguments. Useful stuff.</p>
<div id="adz" class="vertical"></div><p>However, what if we need to store this object in a cookie? What if we need to pass the object to a web services via an Ajax request? What if that web service wants to return a modified version of the object? The answer is serialization:</p>
<ul>
<li><strong>Serialization</strong> is the process of turning any object into a string.</li>
<li><strong>De-serialization</strong> turns that string back into a native object.</li>
</ul>
<p>Perhaps the best string notation we can use in JavaScript is JSON &#8212; JavaScript Object Notation. JSON is a lightweight data-interchange format inspired by JavaScript object literal notation as shown above. JSON is supported by PHP and many other server-side languages (refer to <a href="http://www.json.org/">json.org</a>).</p>
<p>There are two JSON methods in JavaScript:</p>
<ol>
<li><strong>JSON.stringify(<em>obj</em>)</strong> &#8212; converts an JavaScript object to a JSON string</li>
<li><strong>JSON.parse(<em>str</em>)</strong> &#8212; converts a JSON string back to a JavaScript object</li>
</ol>
<p>Unfortunately, very few browsers provide these methods. To date, only Firefox 3.5, Internet Explorer 8.0 and Chrome 3 beta offer native support. Some JavaScript libraries offer their own JSON tools (such as <a href="http://developer.yahoo.com/yui/json/">YUI</a>) but many do not (including <a href="http://jquery.com/">jQuery</a>).</p>
<p>However, all is not lost &#8212; JavaScript is flexible and we can implement the JSON stringify and parse methods whenever a browser requires them.</p>
<p>At the top of our code, we will create a JSON variable that points to the native JSON object or an empty object if it is unavailable:</p>
<pre><code class="javascript">
var JSON = JSON || {};
</code></pre>
<p>The JSON.stringify code is a little more complex:</p>
<pre><code class="javascript">
// implement JSON.stringify serialization
JSON.stringify = JSON.stringify || function (obj) {

	var t = typeof (obj);
	if (t != &quot;object&quot; || obj === null) {

		// simple data type
		if (t == &quot;string&quot;) obj = '&quot;'+obj+'&quot;';
		return String(obj);

	}
	else {

		// recurse array or object
		var n, v, json = [], arr = (obj &amp;&amp; obj.constructor == Array);

		for (n in obj) {
			v = obj[n]; t = typeof(v);

			if (t == &quot;string&quot;) v = '&quot;'+v+'&quot;';
			else if (t == &quot;object&quot; &amp;&amp; v !== null) v = JSON.stringify(v);

			json.push((arr ? &quot;&quot; : '&quot;' + n + '&quot;:') + String(v));
		}

		return (arr ? &quot;[&quot; : &quot;{&quot;) + String(json) + (arr ? &quot;]&quot; : &quot;}&quot;);
	}
};
</code></pre>
<p>If JSON.stringify is not available, we define a new function that accepts a single obj parameter. The parameter can be a single value, an array, or a complex object such as obj1 above.</p>
<p>The code examines the object type. Single values are returned immediately and only strings are modified to put quotes around the value.</p>
<p>If an array or object is passed, the code iterates through every property:</p>
<ol>
<li>Strings values have quotes added.</li>
<li>Child arrays or objects are recursively passed to the JSON.stringify function.</li>
<li>The resulting values are added to the end of a json[] array as a &#8220;name : value&#8221; string, or just a single value for array items.</li>
<li>Finally, the json array is converted to a comma-delimited list and returned within array [] or object {} brackets as necessary.</li>
</ol>
<p>If your brain&#8217;s aching, you&#8217;ll be pleased to know that the JSON.parse code is much simpler:</p>
<pre><code class="javascript">
// implement JSON.parse de-serialization
JSON.parse = JSON.parse || function (str) {
	if (str === "") str = '""';
	eval("var p=" + str + ";");
	return p;
};
</code></pre>
<p>This converts a JSON string to an object using eval().</p>
<p>Before you rush off to implement JSON serialization functions in all your projects, there are a few gotchas:</p>
<ul>
<li>This code has been intentionally kept short. It will work in most situations, but there are subtle differences with the native JSON.stringify and JSON.parse methods.</li>
<li>Not every JavaScript object is supported. For example, a Date() will return an empty object, whereas native JSON methods will encode it to a date/time string.</li>
<li>The code will serialize functions, e.g. var obj1 = { myfunc: function(x) {} }; whereas native JSON methods will not.</li>
<li>Very large objects will throw recursion errors.</li>
<li>The use of eval() in JSON.parse is inherently risky. It will not be a problem if you are calling your own web services, but calls to third-party applications could accidentally or intentionally break your page and cause security issues. If necessary, a safer (but longer and slower) JavaScript parser is available from <a href="http://www.json.org/">json.org</a>.</li>
</ul>
<p>I hope you find the code useful. Feel free to use it in your own projects.</p>
<p>Resource files:</p>
<ul>
<li><a href="http://blogs.sitepointstatic.com/examples/tech/json-serialization/index.html"><strong>JSON Serialization demonstration page</strong></a></li>
<li><a href="http://blogs.sitepointstatic.com/examples/tech/json-serialization/json-serialization.js">Full JavaScript code (json-serialization.js)</a></li>
<li><a href="http://blogs.sitepointstatic.com/examples/tech/json-serialization/json-serialization.zip">Download full code in a ZIP file</a></li>
</ul>
<p>Related reading:</p>
<ul>
<li><a href="http://www.sitepoint.com/blogs/2009/07/22/how-to-develop-a-jquery-plugin/">How To Develop a jQuery Plugin</a></li>
<li><a href="http://www.sitepoint.com/blogs/2009/07/29/build-auto-expanding-textarea-1/">How to Build an Auto-Expanding Textarea jQuery Plugin</a></li>
</ul>
<p><em>Coming soon: a useful application of JSON serialization&#8230;</em></p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=1b0f67a32a5ceaeaf1a1ea4ff6f43997&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=1b0f67a32a5ceaeaf1a1ea4ff6f43997&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		</item>
		<item>
			<title>How to Use Operating System Styles in CSS</title>
			<link>http://www.pheedcontent.com/click.phdo?i=eb17fdeee48f8b5375301bc3aa16b18b</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/08/11/css-system-styles/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/08/11/css-system-styles/#comments</comments>
			<pubDate>Mon, 10 Aug 2009 16:18:45 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category>css</category>
			<category>linux</category>
			<category>mac</category>
			<category>os</category>
			<category>os x</category>
			<category>unix</category>
			<category>windows</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=12911</guid>
			<description><![CDATA[CSS can reference fonts and colors defined for the underlying Operating System (Windows, Mac OS, Linux etc.) Craig discusses when this might be useful and provides a useful list of property values.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=eb17fdeee48f8b5375301bc3aa16b18b&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=eb17fdeee48f8b5375301bc3aa16b18b&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.sitepointstatic.com/images/tech/123-css-system-styles.jpg" alt="CSS system styles" width="265" height="265" class="imgright" />One of the lesser-known features of CSS2.1 is the ability to define fonts and colors that are in use by the underlying Operating System theme. This can be useful in situations when you require tighter OS integration, e.g. HTML help files, Adobe AIR or perhaps offline web applications.</p>
<p>Before we begin, there are a few caveats:</p>
<ul>
<li>Do not rely on these properties working in all OS/browser combinations. If your application must work in Opera on BeOS, then I&#8217;d recommend you test it first!</li>
<li>The properties have been deprecated in CSS3 in favor of the <a href="http://www.w3.org/TR/css3-ui/#system">appearance value type</a> (although browser support is extremely limited at this time).</li>
<li>There is nothing to prevent the user defining unusual, clashing, or ugly color schemes in their OS. Pages will reflect their choices &#8212; not your designer&#8217;s.</li>
</ul>
<style type="text/css">
.sys { font-size: 1em; }
.sys th { font-weight: bold; color: #fff; background-color: #888; }
.sys, .sys td, .sys th { text-align: left; padding: 1px 3px; border: 1px solid #666; border-collapse: collapse; }
.sys .prop { font-weight: bold; }
</style>
<h2>System Fonts</h2>
<div id="adz" class="horizontal"></div><p>System fonts are assigned using the &#8216;font&#8217; property. Note that the family, size, and style are all assigned as appropriate, e.g.</p>
<pre><code class="css">
body
{
	font: caption;
}
</code></pre>
<p>The following font values are available. The &#8216;Example&#8217; column shows the current font set by your OS.</p>
<table class="sys" summary="CSS2.1 system fonts">
<tr>
<th>Property</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td class="prop">caption</td>
<td>Controls font (buttons, drop-downs, etc.)</td>
<td style="font:caption;">ABC abc 123</td>
</tr>
<tr>
<td class="prop">icon</td>
<td>Icon label font</td>
<td style="font:icon;">ABC abc 123</td>
</tr>
<tr>
<td class="prop">menu</td>
<td>Menu font</td>
<td style="font:menu;">ABC abc 123</td>
</tr>
<tr>
<td class="prop">message-box</td>
<td>Dialog box font</td>
<td style="font:message-box;">ABC abc 123</td>
</tr>
<tr>
<td class="prop">small-caption</td>
<td>Small control labels</td>
<td style="font:small-caption;">ABC abc 123</td>
</tr>
<tr>
<td class="prop">status-bar</td>
<td>Status bar font</td>
<td style="font:status-bar;">ABC abc 123</td>
</tr>
</table>
<h2>System Colors</h2>
<p>System colors can be assigned to to any property that expects a color value, e.g.</p>
<pre><code class="css">
body
{
	color: WindowText;
	background-color: Window;
	border: 2px solid ActiveBorder;
}
</code></pre>
<p>The following color values are available. They are shown in <a href="http://en.wikipedia.org/wiki/Camel_case">CamelCase</a> for legibility, but any casing is valid. The &#8216;Example&#8217; column shows the color set by your OS.</p>
<table class="sys" summary="CSS2.1 system colors">
<tr>
<th>Property</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td class="prop">ActiveBorder</td>
<td>Active window border</td>
<td style="background-color:ActiveBorder;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ActiveCaption</td>
<td>Active window caption</td>
<td style="background-color:ActiveCaption;">&nbsp;</td>
</tr>
<tr>
<td class="prop">AppWorkspace</td>
<td>Background color of multiple document interface</td>
<td style="background-color:AppWorkspace;">&nbsp;</td>
</tr>
<tr>
<td class="prop">Background</td>
<td>Desktop background</td>
<td style="background-color:Background;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ButtonFace</td>
<td>Face color for 3D display elements</td>
<td style="background-color:ButtonFace;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ButtonHighlight</td>
<td>Dark shadow for 3D display elements (facing away from light)</td>
<td style="background-color:ButtonHighlight;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ButtonShadow</td>
<td>Shadow color for 3D display elements</td>
<td style="background-color:ButtonShadow;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ButtonText</td>
<td>Text on push buttons</td>
<td style="background-color:ButtonText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">CaptionText</td>
<td>Text in caption, size box, and scrollbar arrow box</td>
<td style="background-color:CaptionText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">GrayText</td>
<td>Grayed (disabled) text (#000 if not supported by OS)</td>
<td style="background-color:GrayText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">Highlight</td>
<td>Item(s) selected in a control</td>
<td style="background-color:Highlight;">&nbsp;</td>
</tr>
<tr>
<td class="prop">HighlightText</td>
<td>Text of item(s) selected in a control</td>
<td style="background-color:HighlightText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">InactiveBorder</td>
<td>Inactive window border</td>
<td style="background-color:InactiveBorder;">&nbsp;</td>
</tr>
<tr>
<td class="prop">InactiveCaption</td>
<td>Inactive window caption</td>
<td style="background-color:InactiveCaption;">&nbsp;</td>
</tr>
<tr>
<td class="prop">InactiveCaptionText</td>
<td>Color of text in an inactive caption</td>
<td style="background-color:InactiveCaptionText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">InfoBackground</td>
<td>Background color for tooltip controls</td>
<td style="background-color:InfoBackground;">&nbsp;</td>
</tr>
<tr>
<td class="prop">InfoText</td>
<td>Text color for tooltip controls</td>
<td style="background-color:InfoText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">Menu</td>
<td>Menu background</td>
<td style="background-color:Menu;">&nbsp;</td>
</tr>
<tr>
<td class="prop">MenuText</td>
<td>Text in menus</td>
<td style="background-color:MenuText;">&nbsp;</td>
</tr>
<tr>
<td class="prop">Scrollbar</td>
<td>Scroll bar gray area</td>
<td style="background-color:Scrollbar;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ThreeDDarkShadow</td>
<td>Dark shadow for 3D display elements</td>
<td style="background-color:ThreeDDarkShadow;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ThreeDFace</td>
<td>Face color for 3D display elements</td>
<td style="background-color:ThreeDFace;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ThreeDHighlight</td>
<td>Highlight color for 3D display elements</td>
<td style="background-color:ThreeDHighlight;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ThreeDLightShadow</td>
<td>Light color for 3D display elements (facing the light)</td>
<td style="background-color:ThreeDLightShadow;">&nbsp;</td>
</tr>
<tr>
<td class="prop">ThreeDShadow</td>
<td>Dark shadow for 3D display elements</td>
<td style="background-color:ThreeDShadow;">&nbsp;</td>
</tr>
<tr>
<td class="prop">Window</td>
<td>Window background</td>
<td style="background-color:Window;">&nbsp;</td>
</tr>
<tr>
<td class="prop">WindowFrame</td>
<td>Window frame</td>
<td style="background-color:WindowFrame;">&nbsp;</td>
</tr>
<tr>
<td class="prop">WindowText</td>
<td>Text in windows</td>
<td style="background-color:WindowText;">&nbsp;</td>
</tr>
</table>
<p>Would these properties be useful in your next project?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=eb17fdeee48f8b5375301bc3aa16b18b&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=eb17fdeee48f8b5375301bc3aa16b18b&p=1"/></a>
<img alt="" height="0" width="0" border="0" style="display:none" src="http://a.rfihub.com/eus.gif?eui=2225"/>]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/08/11/css-system-styles/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
<!-- Dynamic Page Served (once) in 1.522 seconds -->
<!-- Cached page served by WP-Cache -->