1 if(!dojo._hasResource["dijit.Declaration"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit.Declaration"] = true;
3 dojo.provide("dijit.Declaration");
4 dojo.require("dijit._Widget");
5 dojo.require("dijit._Templated");
12 // The Declaration widget allows a user to declare new widget
13 // classes directly from a snippet of markup.
20 buildRendering: function(){
21 var src = this.srcNodeRef.parentNode.removeChild(this.srcNodeRef);
22 var preambles = dojo.query("> script[type='dojo/method'][event='preamble']", src).orphan();
23 var scripts = dojo.query("> script[type^='dojo/']", src).orphan();
24 var srcType = src.nodeName;
26 var propList = this.defaults||{};
28 // map array of strings like [ "dijit.form.Button" ] to array of mixin objects
29 // (note that dojo.map(this.mixins, dojo.getObject) doesn't work because it passes
30 // a bogus third argument to getObject(), confusing it)
31 this.mixins = this.mixins.length ?
32 dojo.map(this.mixins, function(name){ return dojo.getObject(name); } ) :
33 [ dijit._Widget, dijit._Templated ];
36 // we only support one preamble. So be it.
37 propList.preamble = dojo.parser._functionFromScript(preambles[0]);
40 var parsedScripts = dojo.map(scripts, function(s){
41 var evt = s.getAttribute("event")||"postscript";
44 func: dojo.parser._functionFromScript(s)
48 // do the connects for each <script type="dojo/connect" event="foo"> block and make
49 // all <script type="dojo/method"> tags execute right after construction
50 this.mixins.push(function(){
51 dojo.forEach(parsedScripts, function(s){
52 dojo.connect(this, s.event, this, s.func);
56 propList.widgetsInTemplate = true;
57 propList._skipNodeCache = true;
58 propList.templateString = "<"+srcType+" class='"+src.className+"' dojoAttachPoint='"+(src.getAttribute("dojoAttachPoint")||'')+"' dojoAttachEvent='"+(src.getAttribute("dojoAttachEvent")||'')+"' >"+src.innerHTML.replace(/\%7B/g,"{").replace(/\%7D/g,"}")+"</"+srcType+">";
59 // console.debug(propList.templateString);
61 // strip things so we don't create stuff under us in the initial setup phase
62 dojo.query("[dojoType]", src).forEach(function(node){
63 node.removeAttribute("dojoType");
66 // create the new widget class