Dojo Toolkit and XHTML
I had added > Dojo widgets to a website. After that, the markup was not > XHTML valid. I searched the internet and found a following solution for that problem. The main problem is, that you can use Dojo-specific html tags. Examples:
- If you configure the Dojo parser, you can add the ‘djConfig’ tag, which is unknown by the XHTML dtd. For example, you can add ‘djConfig=”parseOnLoad:false’.
- If you use widgets, you have the possibility to define the widgets via markup. The tag ‘dojoType’ is also unknown by the XHTML DTD.
Instead of using the markup tags, you have to add the widgets programmatically. The following script is an excerpt which shows, how a dialog can be added programmatically without damage the XHTML validation. It shows the page “dialog.html” in the dialog, if the user clicks on a link.
1. Load the Dojo javascript and css files:
<head> <script type="text/javascript" src="http://.../dojo/dojo.xd.js" ></script> <link type="text/css" rel="stylesheet" href="http://.../tundra.css"/>
2. Define the dialog in the addOnLoad event:
<script type="javascript"> dojo.require("dijit.Dialog"); dojo.addOnLoad(function() { // create the dialog dialog = new dijit.Dialog({ id: "dialog", style: "width: 200px; height: 240px;" }); });
3. Define a javascript function to call the dialog and set the attributes:
function showDialog() { dialog.attr("title", "Dialog Title"); dialog.attr("href", "dialog.htm"); dialog.show(); } </script> </head> <body> ...
4. Add the link to open the dialog:
<a href="javascript:showDialog();">Click on me</a> ... </body>
Finally, you can verify the page with the > Unicorn validator.
“…which is unknown by the XHTML dtd…”
This is an interesting point. I wonder how much effort would be required to make a Dojo-enabled version of the schema? Seems pretty straight-forward to me.
Nathan T. Freeman
September 19, 2010 at 6:12 pm
There was an argument going on around the Dojo 0.9-1.0 time frame to pack the Dojo specific attributes into their own namespace, so you would write
body dojo:djConfig=”parseonLoad:false”
but the Dojo team found it too [much work|irrelevant|performance impacting] to implement. Would have made validation much easier.
😦 stw
Stephan H. Wissel
September 20, 2010 at 2:28 am