ec2ccf917b6aebb34b33aca675c5e9390ebc47fe.svn-base 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. if (!dojo._hasResource["dijit.Declaration"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dijit.Declaration"] = true;
  6. dojo.provide("dijit.Declaration");
  7. dojo.require("dijit._Widget");
  8. dojo.require("dijit._Templated");
  9. dojo.declare("dijit.Declaration", dijit._Widget, {
  10. // summary:
  11. // The Declaration widget allows a user to declare new widget
  12. // classes directly from a snippet of markup.
  13. _noScript : true,
  14. widgetClass : "",
  15. replaceVars : true,
  16. defaults : null,
  17. mixins : [],
  18. buildRendering : function() {
  19. var src = this.srcNodeRef.parentNode
  20. .removeChild(this.srcNodeRef);
  21. var preambles = dojo.query(
  22. "> script[type='dojo/method'][event='preamble']",
  23. src).orphan();
  24. var scripts = dojo.query("> script[type^='dojo/']", src)
  25. .orphan();
  26. var srcType = src.nodeName;
  27. var propList = this.defaults || {};
  28. // map array of strings like [ "dijit.form.Button" ] to
  29. // array of mixin objects
  30. // (note that dojo.map(this.mixins, dojo.getObject) doesn't
  31. // work because it passes
  32. // a bogus third argument to getObject(), confusing it)
  33. this.mixins = this.mixins.length ? dojo.map(this.mixins,
  34. function(name) {
  35. return dojo.getObject(name);
  36. }) : [dijit._Widget, dijit._Templated];
  37. if (preambles.length) {
  38. // we only support one preamble. So be it.
  39. propList.preamble = dojo.parser
  40. ._functionFromScript(preambles[0]);
  41. }
  42. var parsedScripts = dojo.map(scripts, function(s) {
  43. var evt = s.getAttribute("event")
  44. || "postscript";
  45. return {
  46. event : evt,
  47. func : dojo.parser._functionFromScript(s)
  48. };
  49. });
  50. // do the connects for each <script type="dojo/connect"
  51. // event="foo"> block and make
  52. // all <script type="dojo/method"> tags execute right after
  53. // construction
  54. this.mixins.push(function() {
  55. dojo.forEach(parsedScripts, function(s) {
  56. dojo.connect(this, s.event, this,
  57. s.func);
  58. }, this);
  59. });
  60. propList.widgetsInTemplate = true;
  61. propList._skipNodeCache = true;
  62. propList.templateString = "<"
  63. + srcType
  64. + " class='"
  65. + src.className
  66. + "' dojoAttachPoint='"
  67. + (src.getAttribute("dojoAttachPoint") || '')
  68. + "' dojoAttachEvent='"
  69. + (src.getAttribute("dojoAttachEvent") || '')
  70. + "' >"
  71. + src.innerHTML.replace(/\%7B/g, "{").replace(
  72. /\%7D/g, "}") + "</" + srcType + ">";
  73. // console.debug(propList.templateString);
  74. // strip things so we don't create stuff under us in the
  75. // initial setup phase
  76. dojo.query("[dojoType]", src).forEach(function(node) {
  77. node.removeAttribute("dojoType");
  78. });
  79. // create the new widget class
  80. dojo.declare(this.widgetClass, this.mixins, propList);
  81. }
  82. });
  83. }