2150 |
mathias |
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");
|
|
|
6 |
|
|
|
7 |
dojo.declare(
|
|
|
8 |
"dijit.Declaration",
|
|
|
9 |
dijit._Widget,
|
|
|
10 |
{
|
|
|
11 |
// summary:
|
|
|
12 |
// The Declaration widget allows a user to declare new widget
|
|
|
13 |
// classes directly from a snippet of markup.
|
|
|
14 |
|
|
|
15 |
_noScript: true,
|
|
|
16 |
widgetClass: "",
|
|
|
17 |
replaceVars: true,
|
|
|
18 |
defaults: null,
|
|
|
19 |
mixins: [],
|
|
|
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;
|
|
|
25 |
|
|
|
26 |
var propList = this.defaults||{};
|
|
|
27 |
|
|
|
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 ];
|
|
|
34 |
|
|
|
35 |
if(preambles.length){
|
|
|
36 |
// we only support one preamble. So be it.
|
|
|
37 |
propList.preamble = dojo.parser._functionFromScript(preambles[0]);
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
var parsedScripts = dojo.map(scripts, function(s){
|
|
|
41 |
var evt = s.getAttribute("event")||"postscript";
|
|
|
42 |
return {
|
|
|
43 |
event: evt,
|
|
|
44 |
func: dojo.parser._functionFromScript(s)
|
|
|
45 |
};
|
|
|
46 |
});
|
|
|
47 |
|
|
|
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);
|
|
|
53 |
}, this);
|
|
|
54 |
});
|
|
|
55 |
|
|
|
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);
|
|
|
60 |
|
|
|
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");
|
|
|
64 |
});
|
|
|
65 |
|
|
|
66 |
// create the new widget class
|
|
|
67 |
dojo.declare(
|
|
|
68 |
this.widgetClass,
|
|
|
69 |
this.mixins,
|
|
|
70 |
propList
|
|
|
71 |
);
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
);
|
|
|
75 |
|
|
|
76 |
}
|