_WidgetsInTemplateMixin.js.uncompressed.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. define("dijit/_WidgetsInTemplateMixin", [
  2. "dojo/_base/array", // array.forEach
  3. "dojo/_base/declare", // declare
  4. "dojo/parser" // parser.parse
  5. ], function(array, declare, parser){
  6. // module:
  7. // dijit/_WidgetsInTemplateMixin
  8. return declare("dijit._WidgetsInTemplateMixin", null, {
  9. // summary:
  10. // Mixin to supplement _TemplatedMixin when template contains widgets
  11. // _earlyTemplatedStartup: Boolean
  12. // A fallback to preserve the 1.0 - 1.3 behavior of children in
  13. // templates having their startup called before the parent widget
  14. // fires postCreate. Defaults to 'false', causing child widgets to
  15. // have their .startup() called immediately before a parent widget
  16. // .startup(), but always after the parent .postCreate(). Set to
  17. // 'true' to re-enable to previous, arguably broken, behavior.
  18. _earlyTemplatedStartup: false,
  19. // widgetsInTemplate: [protected] Boolean
  20. // Should we parse the template to find widgets that might be
  21. // declared in markup inside it? (Remove for 2.0 and assume true)
  22. widgetsInTemplate: true,
  23. _beforeFillContent: function(){
  24. if(this.widgetsInTemplate){
  25. // Before copying over content, instantiate widgets in template
  26. var node = this.domNode;
  27. var cw = (this._startupWidgets = parser.parse(node, {
  28. noStart: !this._earlyTemplatedStartup,
  29. template: true,
  30. inherited: {dir: this.dir, lang: this.lang, textDir: this.textDir},
  31. propsThis: this, // so data-dojo-props of widgets in the template can reference "this" to refer to me
  32. scope: "dojo" // even in multi-version mode templates use dojoType/data-dojo-type
  33. }));
  34. if(!cw.isFulfilled()){
  35. throw new Error(this.declaredClass + ": parser returned unfilled promise (probably waiting for module auto-load), " +
  36. "unsupported by _WidgetsInTemplateMixin. Must pre-load all supporting widgets before instantiation.");
  37. }
  38. // _WidgetBase::destroy() will destroy any supporting widgets under this.domNode.
  39. // If we wanted to, we could call this.own() on anything in this._startupWidgets that was moved outside
  40. // of this.domNode (like Dialog, which is moved to <body>).
  41. this._attachTemplateNodes(cw, function(n,p){
  42. return n[p];
  43. });
  44. }
  45. },
  46. startup: function(){
  47. array.forEach(this._startupWidgets, function(w){
  48. if(w && !w._started && w.startup){
  49. w.startup();
  50. }
  51. });
  52. this.inherited(arguments);
  53. }
  54. });
  55. });