| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/aspect", |
| 4 |
"dojo/_base/declare", |
| 5 |
"dojo/_base/lang", |
| 6 |
"dojo/parser", |
| 7 |
"dojo/query", |
| 8 |
"./_Widget", |
| 9 |
"./_TemplatedMixin", |
| 10 |
"./_WidgetsInTemplateMixin", |
| 11 |
"dojo/NodeList-dom" |
| 12 |
], function(array, aspect, declare, lang, parser, query, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin){ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
return declare("dijit.Declaration", _Widget, { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
_noScript: true, |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
stopParser: true, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
widgetClass: "", |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
defaults: null, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
mixins: [], |
| 43 |
|
| 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 |
aspects = query("> script[type='dojo/aspect']", src).orphan(), |
| 49 |
srcType = src.nodeName; |
| 50 |
|
| 51 |
var propList = this.defaults || {}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
array.forEach(methods, function(s){ |
| 58 |
var evt = s.getAttribute("event") || s.getAttribute("data-dojo-event"), |
| 59 |
func = parser._functionFromScript(s, "data-dojo-"); |
| 60 |
if(evt){ |
| 61 |
propList[evt] = func; |
| 62 |
}else{ |
| 63 |
aspects.push(s); |
| 64 |
} |
| 65 |
}); |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if(this.mixins.length){ |
| 71 |
this.mixins = array.map(this.mixins, function(name){ return lang.getObject(name); } ); |
| 72 |
}else{ |
| 73 |
this.mixins = [ _Widget, _TemplatedMixin, _WidgetsInTemplateMixin ]; |
| 74 |
} |
| 75 |
|
| 76 |
propList._skipNodeCache = true; |
| 77 |
propList.templateString = |
| 78 |
"<"+srcType+" class='"+src.className+"'" + |
| 79 |
" data-dojo-attach-point='"+ |
| 80 |
(src.getAttribute("data-dojo-attach-point") || src.getAttribute("dojoAttachPoint") || '')+ |
| 81 |
"' data-dojo-attach-event='"+ |
| 82 |
(src.getAttribute("data-dojo-attach-event") || src.getAttribute("dojoAttachEvent") || '')+ |
| 83 |
"' >"+src.innerHTML.replace(/\%7B/g,"{").replace(/\%7D/g,"}")+"</"+srcType+">"; |
| 84 |
|
| 85 |
|
| 86 |
var wc = declare( |
| 87 |
this.widgetClass, |
| 88 |
this.mixins, |
| 89 |
propList |
| 90 |
); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
array.forEach(aspects, function(s){ |
| 100 |
var advice = s.getAttribute("data-dojo-advice") || "after", |
| 101 |
method = s.getAttribute("data-dojo-method") || "postscript", |
| 102 |
func = parser._functionFromScript(s); |
| 103 |
aspect.after(wc.prototype, method, func, true); |
| 104 |
}); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
array.forEach(connects, function(s){ |
| 109 |
var evt = s.getAttribute("event") || s.getAttribute("data-dojo-event"), |
| 110 |
func = parser._functionFromScript(s); |
| 111 |
aspect.after(wc.prototype, evt, func, true); |
| 112 |
}); |
| 113 |
} |
| 114 |
}); |
| 115 |
}); |