_WidgetsInTemplateMixin.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. define("dijit/_WidgetsInTemplateMixin", [
  2. "dojo/_base/array", // array.forEach
  3. "dojo/_base/declare", // declare
  4. "dojo/parser", // parser.parse
  5. "dijit/registry" // registry.findWidgets
  6. ], function(array, declare, parser, registry){
  7. // module:
  8. // dijit/_WidgetsInTemplateMixin
  9. // summary:
  10. // Mixin to supplement _TemplatedMixin when template contains widgets
  11. return declare("dijit._WidgetsInTemplateMixin", null, {
  12. // summary:
  13. // Mixin to supplement _TemplatedMixin when template contains widgets
  14. // _earlyTemplatedStartup: Boolean
  15. // A fallback to preserve the 1.0 - 1.3 behavior of children in
  16. // templates having their startup called before the parent widget
  17. // fires postCreate. Defaults to 'false', causing child widgets to
  18. // have their .startup() called immediately before a parent widget
  19. // .startup(), but always after the parent .postCreate(). Set to
  20. // 'true' to re-enable to previous, arguably broken, behavior.
  21. _earlyTemplatedStartup: false,
  22. // widgetsInTemplate: [protected] Boolean
  23. // Should we parse the template to find widgets that might be
  24. // declared in markup inside it? (Remove for 2.0 and assume true)
  25. widgetsInTemplate: true,
  26. _beforeFillContent: function(){
  27. if(this.widgetsInTemplate){
  28. // Before copying over content, instantiate widgets in template
  29. var node = this.domNode;
  30. var cw = (this._startupWidgets = parser.parse(node, {
  31. noStart: !this._earlyTemplatedStartup,
  32. template: true,
  33. inherited: {dir: this.dir, lang: this.lang, textDir: this.textDir},
  34. propsThis: this, // so data-dojo-props of widgets in the template can reference "this" to refer to me
  35. scope: "dojo" // even in multi-version mode templates use dojoType/data-dojo-type
  36. }));
  37. this._supportingWidgets = registry.findWidgets(node);
  38. this._attachTemplateNodes(cw, function(n,p){
  39. return n[p];
  40. });
  41. }
  42. },
  43. startup: function(){
  44. array.forEach(this._startupWidgets, function(w){
  45. if(w && !w._started && w.startup){
  46. w.startup();
  47. }
  48. });
  49. this.inherited(arguments);
  50. }
  51. });
  52. });