{"id":121,"date":"2006-10-23T16:10:23","date_gmt":"2006-10-23T16:10:23","guid":{"rendered":"http:\/\/lachy.id.au\/log\/2006\/10\/xbl-part1"},"modified":"2006-12-14T00:01:52","modified_gmt":"2006-12-14T00:01:52","slug":"xbl-part1","status":"publish","type":"post","link":"https:\/\/lachy.id.au\/log\/2006\/10\/xbl-part1","title":{"rendered":"XBL Part 1: Bindings"},"content":{"rendered":"<p>XML Binding Language (XBL) is a mechanism for extending the  presentation and behaviour of a document. The <a href=\"http:\/\/www.w3.org\/TR\/xbl\/\">XBL 2.0 specification<\/a> recently  reached <a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/\">Last Call<\/a> and it has some very cool features to look forward to using  in a few years.  It\u2019s somewhat based upon  the original <a href=\"http:\/\/www.mozilla.org\/projects\/xbl\/xbl.html\">XBL 1.0 specification<\/a> created and implemented by Mozilla, though  it has been significantly redesigned and is not backwards compatible with it.<\/p>\n<p>While reading this, keep in mind that XBL is still a working draft and any feature I discuss may change significanly between now and when it becomes a recommendation.  Presently, there are no implementations of XBL 2.0, so you can&#8217;t use it yet.<\/p>\n<h3 id=\"xbl-part1-binding\">Bindings<\/h3>\n<p>A binding is a way to attach presentation and behaviour to  an element.  The concept is similar to  the way we already style elements using CSS and attach event listeners to them  with JavaScript, but the idea is to add an extra layer of abstraction in  between to simplify the process.   Bindings are a not a way to replace existing authoring tools like CSS  and JavaScript, but rather an enhancement to them.<\/p>\n<p>There are four main aspects of a binding: implementations,  templates, handlers and resources.  In  this whopping 5 part series, I intend to give you a brief overview of each of these  components to explain their purpose and functionality.<\/p>\n<dl>\n<dt><a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#the-implementation\">Implementations<\/a><\/dt>\n<dd> Describe a set of methods,  properties and fields on an element.<\/dd>\n<dt><a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#the-handlers\">Handlers<\/a><\/dt>\n<dd>These offer an improved way to declare event listeners.<\/dd>\n<dt><a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#the-template\">Templates<\/a><\/dt>\n<dd>A way to enhance the  presentation (particularly layout) beyond what is possible with existing CSS  techniques.<\/dd>\n<dt><a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#the-resources\">Resources<\/a><\/dt>\n<dd>Additional stylesheets, images, video,  audio or any other content associated with the binding.<\/dd>\n<\/dl>\n<h3 id=\"xbl-part1-sample\">Sample Bindings<\/h3>\n<p>Bindings can be attached to elements in several ways: a  selector in the element attribute of the binding element, the &#8216;<code>binding<\/code>&#8216;  property in CSS or using a script.<\/p>\n<h4 id=\"xbl-part1-element-attr\">The <code>element<\/code> Attribute<\/h4>\n<p><a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#element\">The <code>element<\/code> attribute<\/a> specifies a selector.  The same type of selector you use with CSS,  so it\u2019s very easy to understand.  This  binding will be attached to all elements that match the selector: <code>#nav li<\/code>.<\/p>\n<pre><code>&lt;xbl xmlns=\"http:\/\/www.w3.org\/ns\/xbl\"&gt;\r\n  &lt;binding element=\"#nav li\"&gt;\r\n    &lt;implementation&gt;...&lt;\/implementation&gt;\r\n    &lt;template&gt;...&lt;\/template&gt;\r\n    &lt;handlers&gt;...&lt;\/handlers&gt;\r\n    &lt;resources&gt;...&lt;\/resources&gt;\r\n  &lt;\/binding&gt;\r\n&lt;\/xbl&gt;<\/code><\/pre>\n<h4 id=\"xbl-part1-binding-prop\">The &#8216;<code>binding<\/code>&#8216; Property<\/h4>\n<p><a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#the--xbl-binding\">The &#8216;<code>binding<\/code>&#8216; property<\/a> can be used in in your CSS to attach a binding, in exactly the same way you apply any other other style to an element.<\/p>\n<p><code>bindings.xml<\/code>:<\/p>\n<pre><code>&lt;xbl xmlns=\"http:\/\/www.w3.org\/ns\/xbl\"&gt;\r\n  &lt;binding id=\"foo\"&gt;\r\n    &lt;implementation&gt;...&lt;\/implementation&gt;\r\n    &lt;template&gt;...&lt;\/template&gt;\r\n    &lt;handlers&gt;...&lt;\/handlers&gt;\r\n    &lt;resources&gt;...&lt;\/resources&gt;\r\n  &lt;\/binding&gt;\r\n&lt;\/xbl&gt;<\/code><\/pre>\n<p>The stylesheet:<\/p>\n<pre><code>#nav li { binding: url(bindings.xml#foo); }<\/code><\/pre>\n<h4 id=\"xbl-part1-script\">Using a Script<\/h4>\n<p>Elements will implement the <a href=\"http:\/\/www.w3.org\/TR\/2006\/WD-xbl-20060907\/#the-elementxbl\">ElementXBL interface<\/a>, which  defines three methods: <code>addBinding()<\/code>,  <code>removeBinding()<\/code> and <code>hasBinding()<\/code>.  The <code>addBinding()<\/code> method can be used to attach  a binding to an individual element using a script, like this:<\/p>\n<pre><code>var e = ...; \/\/ Get the element somehow\r\ne.addBinding(\"bindings.xml#foo\");<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>An overview of the XML Binding Language. XBL 2.0.  Part 1 discusses the concept of a binding and how they can be attached to elements in the document.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,4,7,3],"tags":[],"_links":{"self":[{"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/posts\/121"}],"collection":[{"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":0,"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lachy.id.au\/log\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}