]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/Declaration.js.uncompressed.js
1 define("dijit/Declaration", [
2 "dojo/_base/array", // array.forEach array.map
3 "dojo/_base/connect", // connect.connect
4 "dojo/_base/declare", // declare
5 "dojo/_base/lang", // lang.getObject
6 "dojo/parser", // parser._functionFromScript
10 "./_WidgetsInTemplateMixin",
12 ], function(array
, connect
, declare
, lang
, parser
, query
, _Widget
, _TemplatedMixin
, _WidgetsInTemplateMixin
){
17 return declare("dijit.Declaration", _Widget
, {
19 // The Declaration widget allows a developer to declare new widget
20 // classes directly from a snippet of markup.
22 // _noScript: [private] Boolean
23 // Flag to parser to leave alone the script tags contained inside of me
26 // stopParser: [private] Boolean
27 // Flag to parser to not try and parse widgets declared inside of me
30 // widgetClass: [const] String
31 // Name of class being declared, ex: "acme.myWidget"
34 // propList: [const] Object
35 // Set of attributes for this widget along with default values, ex:
36 // {delay: 100, title: "hello world"}
39 // mixins: [const] String[]
40 // List containing the prototype for this widget, and also any mixins,
41 // ex: ["dijit._Widget", "dijit._Container"]
44 buildRendering: function(){
45 var src
= this.srcNodeRef
.parentNode
.removeChild(this.srcNodeRef
),
46 methods
= query("> script[type^='dojo/method']", src
).orphan(),
47 connects
= query("> script[type^='dojo/connect']", src
).orphan(),
48 srcType
= src
.nodeName
;
50 var propList
= this.defaults
|| {};
52 // For all methods defined like <script type="dojo/method" data-dojo-event="foo">,
53 // add that method to prototype.
54 // If there's no "event" specified then it's code to run on instantiation,
55 // so it becomes a connection to "postscript" (handled below).
56 array
.forEach(methods
, function(s
){
57 var evt
= s
.getAttribute("event") || s
.getAttribute("data-dojo-event"),
58 func
= parser
._functionFromScript(s
);
66 // map array of strings like [ "dijit.form.Button" ] to array of mixin objects
67 // (note that array.map(this.mixins, lang.getObject) doesn't work because it passes
68 // a bogus third argument to getObject(), confusing it)
69 if(this.mixins
.length
){
70 this.mixins
= array
.map(this.mixins
, function(name
){ return lang
.getObject(name
); } );
72 this.mixins
= [ _Widget
, _TemplatedMixin
, _WidgetsInTemplateMixin
];
75 propList
._skipNodeCache
= true;
76 propList
.templateString
=
77 "<"+srcType
+" class='"+src
.className
+"'" +
78 " data-dojo-attach-point='"+
79 (src
.getAttribute("data-dojo-attach-point") || src
.getAttribute("dojoAttachPoint") || '')+
80 "' data-dojo-attach-event='"+
81 (src
.getAttribute("data-dojo-attach-event") || src
.getAttribute("dojoAttachEvent") || '')+
82 "' >"+src
.innerHTML
.replace(/\%7B/g,"{").replace(/\%7D/g,"}")+"</"+srcType
+">";
84 // create the new widget class
91 // Handle <script> blocks of form:
92 // <script type="dojo/connect" data-dojo-event="foo">
94 // <script type="dojo/method">
95 // (Note that the second one is just shorthand for a dojo/connect to postscript)
96 // Since this is a connect in the declaration, we are actually connection to the method
97 // in the _prototype_.
98 array
.forEach(connects
, function(s
){
99 var evt
= s
.getAttribute("event") || s
.getAttribute("data-dojo-event") || "postscript",
100 func
= parser
._functionFromScript(s
);
101 connect
.connect(wc
.prototype, evt
, func
);