<?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>Gareth Jones &#187; dojo</title>
	<atom:link href="http://blog.garethj.com/tag/dojo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.garethj.com</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2010 10:35:37 +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>Programmatic page layouts using dojo and existing markup</title>
		<link>http://blog.garethj.com/2010/08/programmatic-page-layouts-using-dojo-and-existing-markup/</link>
		<comments>http://blog.garethj.com/2010/08/programmatic-page-layouts-using-dojo-and-existing-markup/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 10:35:37 +0000</pubDate>
		<dc:creator>gareth</dc:creator>
				<category><![CDATA[techy solutions]]></category>
		<category><![CDATA[dijit]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[programmatic]]></category>

		<guid isPermaLink="false">http://blog.garethj.com/?p=215</guid>
		<description><![CDATA[The layout tutorials for dojo that I&#8217;ve seen all seem to fall into two categories: Markup-based: adding dojoType properties to HTML elements in the markup Programmatic: creating HTML elements in JavaScript When using a toolkit such as dojo for layout &#8230; <a href="http://blog.garethj.com/2010/08/programmatic-page-layouts-using-dojo-and-existing-markup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://docs.dojocampus.org/dijit/layout">layout tutorials</a> for <a href="http://www.dojotoolkit.org/">dojo</a> that I&#8217;ve seen all seem to fall into two categories:</p>
<ul>
<li><strong>Markup-based</strong>: adding dojoType properties to HTML elements in the markup</li>
<li><strong>Programmatic:</strong> creating HTML elements in JavaScript</li>
</ul>
<p>When using a toolkit such as dojo for layout rather than standard CSS, my preference would be to keep the dojo layout stuff entirely in JavaScript, separate from the markup, whilst still using HTML to describe my content. This allows an easy transition to/from dojo and CSS layout techniques, doesn&#8217;t clutter the markup with dojo specific stuff that would only be needed when JavaScript is enabled, and just provides a cleaner separation. I was sure this must be possible in dojo and it is; it just doesn&#8217;t seem to be well documented anywhere.<br />
<span id="more-215"></span><br />
After playing for a while (and with quite a bit of help from <a href="http://twitter.com/thomasj">James</a>), I turned this&#8230;</p>
<pre>&lt;script type="text/javascript"&gt;
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dijit.layout.ContentPane");
&lt;/script&gt;

&lt;div dojoType="dijit.layout.BorderContainer"
  style="width: 100%; height: 100%;"&gt;
  &lt;div dojoType="dijit.layout.ContentPane" region="top"&gt;
    Top pane
  &lt;/div&gt;
  &lt;div dojoType="dijit.layout.AccordionContainer" region="leading"&gt;
    &lt;div dojoType="dijit.layout.AccordionPane" title="pane #1"&gt;
      accordion pane #1
    &lt;/div&gt;
    &lt;div dojoType="dijit.layout.AccordionPane" title="pane #2"&gt;
      accordion pane #2
    &lt;/div&gt;
    &lt;div dojoType="dijit.layout.AccordionPane" title="pane #3"&gt;
      accordion pane #3
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div dojoType="dijit.layout.TabContainer" region="center"&gt;
    &lt;div dojoType="dijit.layout.ContentPane" title="tab #1"&gt;
      tab pane #1
    &lt;/div&gt;
    &lt;div dojoType="dijit.layout.ContentPane" title="tab #2"&gt;
      tab pane #2
    &lt;/div&gt;
    &lt;div dojoType="dijit.layout.ContentPane" title="tab #3"&gt;
      tab pane #3
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div dojoType="dijit.layout.ContentPane" region="trailing"&gt;
    Trailing pane
  &lt;/div&gt;
  &lt;div dojoType="dijit.layout.ContentPane" region="bottom"&gt;
    Bottom pane
  &lt;/div&gt;
&lt;/div&gt;

&lt;style type="text/css"&gt;
 html, body {
 width: 100%;
 height: 100%;
 margin: 0;
 }
&lt;/style&gt;</pre>
<p>&#8230;into this&#8230;</p>
<pre>&lt;script type="text/javascript"&gt;
  dojo.require("dijit.layout.BorderContainer");
  dojo.require("dijit.layout.TabContainer");
  dojo.require("dijit.layout.AccordionContainer");
  dojo.require("dijit.layout.ContentPane");

  dojo.ready(function () {
    var mainContainer = new dijit.layout.BorderContainer(
      {}, 'mainContainer');
    var topPane = new dijit.layout.ContentPane(
      {'region': 'top'}, 'topPane');
    mainContainer.addChild(topPane);
    var leftPane = new dijit.layout.AccordionContainer(
      {'region': 'leading'}, 'leftPane');
    var accordionPane1 = new dijit.layout.AccordionPane(
      {'title': 'pane #1'}, 'accordionPane1');
    var accordionPane2 = new dijit.layout.AccordionPane(
      {'title': 'pane #2'}, 'accordionPane2');
    var accordionPane3 = new dijit.layout.AccordionPane(
      {'title': 'pane #3'}, 'accordionPane3');
    leftPane.addChild(accordionPane1);
    leftPane.addChild(accordionPane2);
    leftPane.addChild(accordionPane3);
    mainContainer.addChild(leftPane);
    var centerPane = new dijit.layout.TabContainer(
      {'region': 'center'}, 'centerPane');
    var tabPane1 = new dijit.layout.AccordionPane(
      {'title': 'tab #1'}, 'tabPane1');
    var tabPane2 = new dijit.layout.AccordionPane(
      {'title': 'tab #2'}, 'tabPane2');
    var tabPane3 = new dijit.layout.AccordionPane(
      {'title': 'tab #3'}, 'tabPane3');
    centerPane.addChild(tabPane1);
    centerPane.addChild(tabPane2);
    centerPane.addChild(tabPane3);
    mainContainer.addChild(centerPane);
    var rightPane = new dijit.layout.ContentPane(
      {'region': 'trailing'}, 'rightPane');
    mainContainer.addChild(rightPane);
    var bottomPane = new dijit.layout.ContentPane(
      {'region': 'bottom'}, 'bottomPane');
    mainContainer.addChild(bottomPane);
    mainContainer.startup();
  });
&lt;/script&gt;

&lt;div id="mainContainer"&gt;
  &lt;div id="topPane"&gt;Top pane&lt;/div&gt;
  &lt;div id="leftPane"&gt;
    &lt;div id="accordionPane1"&gt;accordion pane #1&lt;/div&gt;
    &lt;div id="accordionPane2"&gt;accordion pane #2&lt;/div&gt;
    &lt;div id="accordionPane3"&gt;accordion pane #3&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="centerPane"&gt;
    &lt;div id="tabPane1"&gt;tab pane #1&lt;/div&gt;
    &lt;div id="tabPane2"&gt;tab pane #2&lt;/div&gt;
    &lt;div id="tabPane3"&gt;tab pane #3&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="rightPane"&gt;Trailing pane&lt;/div&gt;
  &lt;div id="bottomPane"&gt;Bottom pane&lt;/div&gt;
&lt;/div&gt;

&lt;style type="text/css"&gt;
  html, body, #mainContainer {
    width: 100%;
    height: 100%;
    margin: 0;
  }
&lt;/style&gt;</pre>
<p>There&#8217;s lots of code but I prefer the separation. In reality I&#8217;d move the JavaScript etc into a separate files but it&#8217;s easier to demonstrate like this.</p>
<p>A couple of gotchas:</p>
<ul>
<li> <strong>Adding extra HTML elements dynamically</strong><br />
Sometimes dojo will require extra <code>div</code>s for layout purposes (for different digit classes, e.g. dijit.layout.BorderContainer). Clearly it would be wrong to modify markup to include extra <code>div</code>s just for this so you&#8217;ll probably want to create them programmatically. This is fine, but instead of using <code>addChild</code> to append a child, you&#8217;ll need to place the new element in the DOM yourself using <code>dojo.place(myDynamicElement.domNode, myExistingElement.domNode);</code>.</li>
<li> <strong>Specifying the top level widget</strong><br />
If you use dojo&#8217;s markup method (with <code>djConfig="parseOnLoad:true"</code> set or running <code>dojo.parser.parse()</code>), the top level widgets are determined automatically. With this method, we need to manually start it by calling <code>startup()</code> on the top level widget (in our case, the <code>mainContainer</code> element). Otherwise, no layout occurs at all.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethj.com/2010/08/programmatic-page-layouts-using-dojo-and-existing-markup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dojo checkboxes</title>
		<link>http://blog.garethj.com/2008/07/dojo-checkboxes/</link>
		<comments>http://blog.garethj.com/2008/07/dojo-checkboxes/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 08:17:28 +0000</pubDate>
		<dc:creator>gareth</dc:creator>
				<category><![CDATA[techy solutions]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.garethj.com/?p=54</guid>
		<description><![CDATA[I recently hit this snag when working with Dojo. Basically I wanted to set the checked status of a checkbox on a webpage programmatically. Simple you might think? Apparently not as easy as it should be. Interaction with checkboxes has &#8230; <a href="http://blog.garethj.com/2008/07/dojo-checkboxes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently hit this snag when working with <a href="http://dojotoolkit.org/">Dojo</a>. Basically I wanted to set the checked status of a checkbox on a webpage programmatically. Simple you might think? Apparently not as easy as it should be.</p>
<p>Interaction with checkboxes has changed slightly in Dojo 1.1 (<a href="http://dojotoolkit.org/book/dojo-1-1-release-notes">apparently</a>) but <code>myCheckbox.setValue(true)</code> should be valid. When calling <code>dojo.byId('my-checkbox-id').setValue(true)</code>, I was getting an error saying the method didn&#8217;t exist. The object was definitely the checkbox as I could determine the correct checked state from that object (<code>myCheckbox.checked</code>) so I was very confused. I then remembered another way to access objects with Dojo is using the HTML attribute &#8216;<code>jsId</code>&#8216;. This creates a global javascript variable referring to that object in the DOM. So I set something like <code>jsId='myCheckbox'</code> and then called <code>myCheckbox.setValue(true)</code> and it worked!</p>
<p>Very odd behaviour. I can only guess that the javascript object created by Dojo using <code>jsId</code> and <code>dojo.byId()</code> is a different bit of code and creates an object pointing to the DOM checkbox object in a different way. Very strange but at least there&#8217;s the workaround above&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethj.com/2008/07/dojo-checkboxes/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
