<?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>Cognition &#187; javascript</title>
	<atom:link href="http://www.cognition.ca/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cognition.ca</link>
	<description>Balls-in-the-air Entrepreneurship and Juggling.</description>
	<lastBuildDate>Tue, 24 Aug 2010 00:29:45 +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>Bondage in the XML world</title>
		<link>http://www.cognition.ca/2007/08/bondage-in-the-xml-world.html</link>
		<comments>http://www.cognition.ca/2007/08/bondage-in-the-xml-world.html#comments</comments>
		<pubDate>Mon, 06 Aug 2007 17:22:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[entrepreneurs]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[flock]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mozilla]]></category>

		<guid isPermaLink="false">http://www.cognition.ca/?p=10</guid>
		<description><![CDATA[Ah, the glories of SnM &#8211; and in this case, yes, I&#8217;m talking about bindings. Last time, I waxed verbose eloquent about the glories and the power of RDF. Today, I&#8217;m going to talk about how to use RDF to generate UI, in a flexible, extensible, and performant way. Actually, I&#8217;m lying. I&#8217;m going to [...]]]></description>
			<content:encoded><![CDATA[<p>Ah, the glories of SnM &#8211; and in this case, yes, I&#8217;m talking about bindings.</p>
<p>Last time, I waxed <span style="text-decoration: line-through;">verbose</span> eloquent about the glories and the power of RDF. Today, I&#8217;m going to talk about how to use RDF to generate UI, in a flexible, extensible, and performant way.</p>
<p>Actually, I&#8217;m lying. I&#8217;m going to talk about two DIFFERENT ways to do this. One of them is flexible and simple. The other is extensible and performant. You take your pick.</p>
<p>But first, a quick review.
<ul>
<li>XUL = HTML for the browser. Defines layout.</li>
<li>CSS = Stylesheets, of two kinds:</li>
<ul>
<li>one makes things look GOOD (themeable),</li>
<li>the other makes things WORK (moz-binding and functional layout).</li>
</ul>
<li>XBL = The wondrous binding language, essentially lets you create your own XUL elements of arbitrary complexity. This is where the magic happens.</li>
</ul>
<p>XBL brings the power and rigor of Agile Development to the declarative, XML world. When is the right time to refactor? When you write the same code for the <span style="font-style: italic;">second</span> time. When is the right time to make a XBL binding? When you&#8217;re going to have the same chunk of XUL <span style="font-style: italic;">twice</span>.</p>
<p>Alright, that should be enough to scare off anyone who&#8217;s not going to follow the next bit. Let&#8217;s dive into the nitty gritty.</p>
<p>As I mentioned last time, one of the beautiful things about RDF is that it allows you to express additional ARCs to capture service-specific data or metadata, on top of the base data. Think of sub-classing a generic PERSON to a <span style="font-style: italic;">youtube</span> PERSON, which allows us to keep track of the number of videos they have uploaded, a list of their friends, and maybe the last time they logged on.</p>
<p>So how can we do this in Flock?</p>
<ol>
<li>Declare an inherited coop object. (In this case, it would be YoutubePerson inherits from Person).</li>
<li>Create an inherited XBL binding for the relevant UI (personcards in the sidebar, FOAFcard for browsing friends of a friend, etc.)</li>
<li>Add an overlay to the sidebar XUL, that includes a service-specific CSS file to connect the inherited binding, with the relevant elements, like so:</li>
</ol>
<p><code>personbar.xul:</p>
<p>&lt;vbox datasources="rdf:flock-favorites" ref="urn:flock:peopleroot"><br /> &nbsp; &lt;template><br /> &nbsp; &nbsp;      &lt;rule rdftype="http://flock.com/rdf#Person"><br /> &nbsp; &nbsp; &nbsp;          &lt;personcard uri="rdf:*"<br /> &nbsp; &nbsp; &nbsp;              type="rdf:http://flock.com/rdf#Service"<br /> &nbsp; &nbsp; &nbsp;              name="rdf:http://flock.com/rdf#Name"<br /> &nbsp; &nbsp;          ... /><br /> &nbsp; &nbsp;      &lt;/rule><br /> &nbsp;  &lt;/template><br />&lt;/vbox></p>
<p>youtube-person-bindings.css:</p>
<p>personcard[type='youtube'] {<br /> &nbsp;  -moz-binding: url("chrome://your/binding/file/here.xml");<br />}</p>
<p>youtube-person-overlay.xul:</p>
<p>&lt;?xml-stylesheet <br /> &nbsp; href="chrome://flock/content/youtube-person-bindings.css" <br /> &nbsp; type="text/css"?></p>
<p>&lt;overlay id="youtubePersonOverlay"<br /> &nbsp;  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"<br /> &nbsp;  xmlns="...there.is.only.xul"><br /> &nbsp;     ...<br />&lt;/overlay><br /></code><br />Why is this cool? Or, why is this the right way to do it?
<ol>
<li>It works with either RDF templates, OR javascript document.createElement()</li>
<li>It means a single generic method of displaying ALL persons can output service-specific UI &#8211; Including service-specific ACTIONS in that UI.</li>
<li>It encapsulates the UI code per service, WITHOUT mashing that UI code into an xpcom service somewhere.</li>
<li>Services don&#8217;t HAVE to use specialized bindings &#8211; if they don&#8217;t define one, the generic binding will be used, which ought to <span style="font-style: italic;">just work.</span></li>
</ol>
<p>No approach is perfect, however. Here are the possible drawbacks:
<ol>
<li>The generic binding has to assume a very <span style="font-style: italic;">low</span> level of functionality, since it can only rely on the actions that <span style="font-style: italic;">every</span> service will have. So many services will end up duplicating binding code for a rich-but-common set of functions. (Perhaps this could be mitigated by inheriting from a more-sophisticated, common but not default binding?)</li>
<li>Since the attribtues on the element are only those common to all PERSONs, the binding may end up needing to use coop internally to fetch the additional metadata that it needs. (This is straightforward, but it <span style="font-style: italic;">does</span> add complexity.) Again, the template itself could be overridden with an overlay, but that spoils the elegance of this approach.</li>
<li><span style="font-style: italic;">Hopefully</span>, an inherited binding will still be able to take advantage of drag-n-drop handling code within the base binding, but this is definitely a point to watch out for in test-planning. Perhaps the most critical goal of this quasi-polymorphism is to ensure that the DnD behaviour is consistent across services.</li>
</ol>
<p>This is a little more technical than I was going for, as I&#8217;m trying to keep this blog accessible and approachable for ordinary coders. But, if you understand XUL, and you understand XBL, you ought to be able to grab this one and run with it.</p>
<span class="akst_link"><a href="http://www.cognition.ca/?p=10&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_10"  class="akst_share_link">Share This</a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.cognition.ca/2007/08/bondage-in-the-xml-world.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
