[Dojo-interest] Dojo without dojo special tag attribs

Peter E Higgins dante at dojotoolkit.org
Thu Aug 7 12:01:06 UTC 2008


Michał Zieliński wrote:
> Hi.
>
> I`m new to Dojo and I`d like to play with it a bit more.
> I like simplicity and don`t like mess in HTML code. Simple tags with ids or
> classes should be enough to write javascript stuff. Dojo needs some special
> atrribs in HTML tags. I read in manual that there is an option to use Dojo
> without this attribs. 
>
>   
Nope, the dojoType attribute is optional.

<div dojoType="dijit.TitlePane" id="myTitlePane" 
title="Wonderbar!">Content</div>

can be expressed without the parser like:

new dijit.TitlePane({ title:"Wonderbar" }, "myTitlePane");
<div id="myTitlePane">Content</div>

> Could you please tell me if the is any tutorial/article/note which describes
> more precisely how to achive clean HTML cooperates with Dojo?
> It would be nice to have some examples.
>
>   
The first couple examples come to mind:
http://higginsforpresident.net/2008/08/dojo-degradability/
http://turtle.dojotoolkit.org/~dante/skewDemo/demo.html (mostly valid 
html, new version is, but not published yet)
http://turtle.dojotoolkit.org/~dante/dojo.moj.oe/mojo.html (same case, 
just not published since update)

It is an aim of the new doc system to provide more copy/pastable 
programmatic examples. They currently exist as tests within the tests 
with the dojoTypes, so they are hard to spot sometimes (they don't stand 
out, because, well, they look like regular html ;) )
> (I don`t want to start discussion on standards, W3C, DTD, Validation, etc.
> It is my way of coding, the less the better and please don`t argue with this
> ;))
>
>   
No worries ... We have to do a lot of testing, and know the dojoType 
works ... it is TONS easier to offload the heavy lifting of creation 
onto the dojo.parser when we get into repetitious use cases, "add 
another example testing this tag", etc ...
> Regards,
> Mike
>   

Zend Framework offers dual declarative and programmatic options, and the 
way they pull it off is actually quite clever ... I have been meaning to 
write up a blog or something describing it, but the summary is:

keep a global object hash of id->widget props, onLoad, use dojo.attr() 
to decorate the nodes with the invalid tags, then run the parser 
immediately after ... the code is like 3 lines:

var dijitsInPage = [{ id:"foo", type:"dijit.TitlePane, title:"Hi!" }];
dojo.forEach(dijitsInPage, function(comp){
       var n = dojo.byId(comp['id']);
       dojo.attr(n, comp);
});
dojo.parser.parse();

Because validity one counts on initial page load ...

Hope this helps,

Regards,
Peter Higgins





More information about the Dojo-interest mailing list