<?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>fforw.de &#187; dom</title>
	<atom:link href="http://fforw.de/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://fforw.de</link>
	<description>skip the boring parts</description>
	<lastBuildDate>Fri, 10 Sep 2010 16:32:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Annotating DOM nodes with JSON</title>
		<link>http://fforw.de/post/annotating-dom-nodes-with-json/</link>
		<comments>http://fforw.de/post/annotating-dom-nodes-with-json/#comments</comments>
		<pubDate>Mon, 03 Jul 2006 20:54:29 +0000</pubDate>
		<dc:creator>fforw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://blog.willie/?p=22</guid>
		<description><![CDATA[One problem when trying to do &#8220;The Right Thing &#8482;&#8221; and separate your webdesign into different layers is what to do when you need additional information to transform your nicely id and class annotated DOM nodes into fancy, javascript-enabled goodness: Where do you store that information? How do you associate it to the DOM nodes? [...]]]></description>
			<content:encoded><![CDATA[<p>One problem when trying to do &#8220;The Right Thing &#8482;&#8221; and <a href="Separate_it%21/">separate your webdesign into different layers </a>is what to do when you need additional information to transform your nicely id and class annotated DOM nodes into fancy, javascript-enabled goodness: </p>
<p>Where do you store that information? How do you associate it to the DOM nodes? I will present three approaches to this problem..</p>
<hr width="100%" size="2" />
<h5>Method 1: The squeaky clean  </h5>
<p>The first method is relatively straight-forward: You add ids or classes to your DOM nodes. Then you include a dynamically generated javascript library  in your document. </p>
<p>The problem with this is that the generated javascript library is requested in a new request which makes it nescessary to provide this request with the nescessary context to generate it. You also need to write code which finds your DOM nodes and finds the data from the included javascript library and associates both. You also walk over the server side data twice: Once to generate the DOM nodes and once to create the javascript library. </p>
<h5>Method 2: Compromising </h5>
<p>The second approach is to compromise a little on the separation ideal and render the javascript data from the first method right into the page source. </p>
<p>You don&#8217;t need to carry the context for the data into a second request for the javascript library, but you still need to wak the data twice on the server side, you still need to associate the DOM nodes to the data, and you have a big block of js data in the head section of your document. </p>
<h5>Method 3: Annotating DOM nodes with JSON </h5>
<p>I thought about a way to directly associate the DOM with additional data. <a href="http://json.org" title="JSON specification / tools">JSON</a>  seemed to be a good format to store the data. At first I thought about using a custom attribute but I did not like the idea of invalid HTML markup. Then I got another idea:</p>
<p>Why not use the event handlers? Something like</p>
<blockquote><pre>&lt;a href="/no_js" onclick="return { foo: 'extra', bar: 1};">Link&lt;/a></pre>
</blockquote>
<p>works pretty well. It is totally valid HTML, the onclick contains valid javascript code which can also be easily parsed by other tools. (It is basically just a JSON string wrapped with <em>a &#8220;return [...] ;&#8221; ) </em>When javascript is disabled, the link just executes normally and can provide non-javascript functionality. The data can be retrieved by executing &#8220;var data=linkNode.onclick();&#8221;. &#8220;But what about the fake event handler?&#8221; you might ask. Well.. if someone clicks on the unmodified link in a javascript enabled browser: <em>nothing happens</em>. The script just returns some data and does nothing else. The return code will be ignored by the browser environment due to this age-old, pre-DOM standard of canceling the event if the handler returns <em>false </em>and just going on if it returns <em>true</em> &#8212; since the data is something it evaluates to <em>true</em> so it&#8217;s just ignored.</p>
<p>On the server side things get much easier. Not only does no context need to be carried into another request but you also only need to walk over the data once.  You can ouput the HTML and the additional javascript data into the same part of the document.</p>
<p>I admit that this approach bends the <a href="../Separate_it%21/">rules of separation</a> a little, but in my opinion that&#8217;s ok.</p>
<ul>
<li>It uses onclick=&#8221;"  but   does not really put any code in there, just some data</li>
<li>The semantics of the original markup are kept as they are. The method only allows to annotate this &#8220;<em>base data</em>&#8221; with additional information.</li>
<li>The pros vastly outweigh the cons</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://fforw.de/post/annotating-dom-nodes-with-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Separate it!</title>
		<link>http://fforw.de/post/separate-it/</link>
		<comments>http://fforw.de/post/separate-it/#comments</comments>
		<pubDate>Mon, 03 Jul 2006 14:28:44 +0000</pubDate>
		<dc:creator>fforw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.willie/?p=23</guid>
		<description><![CDATA[One of the most important practices when developing complex web applications is to seperate them into different layers. This applies to the server side as well as to the client side of things. On the client side the separation usually is: Content The content of the web application expressed in semantic HTML markup, enriched with [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most important practices when developing complex web applications is to seperate them into different layers. This applies to the server side as well as to the client side of things. On the client side the separation usually is:</p>
<ul>
<li><em>Content</em> <br />The content of the web application expressed in semantic HTML markup, enriched with additional ids and classes to refer to in the other layers</li>
<li><em>Layout</em><strong><br /></strong>CSS rules for styling the content</li>
<li><em>Behaviour</em><strong><br /></strong>Javascript code transforming the DOM to provide a better user experience</li>
</ul>
<hr width="100%" size="2" />It is important that the second and third layer are optional. The <em>Content </em>layer should contain the basic information and be accessible without the <em>Layout </em>and the <em>Behaviour </em>layer. <em>Content</em> and <em>Layout </em>should look nice and work without the <em>Behaviour </em>layer.
<p />
<p>While this wisdom is very much common place for the first two layers, many people still don&#8217;t do the <em>Behaviour </em>layer correctly. There are several important points to this:</p>
<ol>
<li>Build every single page so that it works well without any javascript. Do not rely on javascript for navigation or load content via javascript etc.</li>
<li>Build your scripts so that they use DOM methods to transform the non-javascript page into a better page using javascript.</li>
<li>Use w3 DOM scripting in your pages. No <em>document.write</em> nonsense, no <em>onclick=&#8221;"</em> for events. If you want to or have to support Internet Explorer that means using additional addEvent methods. (See the links for John Resig&#8217;s excellent addEvent ) </li>
</ol>
<p><strong>Links:</strong></p>
<ul>
<li><a href="http://www.alistapart.com/articles/separationdilemma">A List Apart: Separation: The Web Designer&#8217;s Dilemma</a> </li>
<li> <a href="http://mezzoblue.com/downloads/markupguide/">mezzoblue Markup Guide </a>&#8211; about semantic HTML markup</li>
<li> <a href="http://ejohn.org/projects/flexible-javascript-events/" class="l">John Resig &#8211; Flexible Javascript Events</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://fforw.de/post/separate-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
