821a4a795a4e5b2f514167b0254bd8c33594fa32.svn-base 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. if (!dojo._hasResource["dijit._base.manager"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dijit._base.manager"] = true;
  6. dojo.provide("dijit._base.manager");
  7. dojo.declare("dijit.WidgetSet", null, {
  8. constructor : function() {
  9. // summary:
  10. // A set of widgets indexed by id
  11. this._hash = {};
  12. },
  13. add : function(/* Widget */widget) {
  14. if (this._hash[widget.id]) {
  15. throw new Error("Tried to register widget with id=="
  16. + widget.id
  17. + " but that id is already registered");
  18. }
  19. this._hash[widget.id] = widget;
  20. },
  21. remove : function(/* String */id) {
  22. delete this._hash[id];
  23. },
  24. forEach : function(/* Function */func) {
  25. for (var id in this._hash) {
  26. func(this._hash[id]);
  27. }
  28. },
  29. filter : function(/* Function */filter) {
  30. var res = new dijit.WidgetSet();
  31. this.forEach(function(widget) {
  32. if (filter(widget)) {
  33. res.add(widget);
  34. }
  35. });
  36. return res; // dijit.WidgetSet
  37. },
  38. byId : function(/* String */id) {
  39. return this._hash[id];
  40. },
  41. byClass : function(/* String */cls) {
  42. return this.filter(function(widget) {
  43. return widget.declaredClass == cls;
  44. }); // dijit.WidgetSet
  45. }
  46. });
  47. // registry: list of all widgets on page
  48. dijit.registry = new dijit.WidgetSet();
  49. dijit._widgetTypeCtr = {};
  50. dijit.getUniqueId = function(/* String */widgetType) {
  51. // summary
  52. // Generates a unique id for a given widgetType
  53. var id;
  54. do {
  55. id = widgetType
  56. + "_"
  57. + (dijit._widgetTypeCtr[widgetType] !== undefined
  58. ? ++dijit._widgetTypeCtr[widgetType]
  59. : dijit._widgetTypeCtr[widgetType] = 0);
  60. } while (dijit.byId(id));
  61. return id; // String
  62. };
  63. if (dojo.isIE) {
  64. // Only run this for IE because we think it's only necessary in that
  65. // case,
  66. // and because it causes problems on FF. See bug #3531 for details.
  67. dojo.addOnUnload(function() {
  68. dijit.registry.forEach(function(widget) {
  69. widget.destroy();
  70. });
  71. });
  72. }
  73. dijit.byId = function(/* String|Widget */id) {
  74. // summary:
  75. // Returns a widget by its id, or if passed a widget, no-op (like
  76. // dojo.byId())
  77. return (dojo.isString(id)) ? dijit.registry.byId(id) : id; // Widget
  78. };
  79. dijit.byNode = function(/* DOMNode */node) {
  80. // summary:
  81. // Returns the widget as referenced by node
  82. return dijit.registry.byId(node.getAttribute("widgetId")); // Widget
  83. };
  84. dijit.getEnclosingWidget = function(/* DOMNode */node) {
  85. // summary:
  86. // Returns the widget whose dom tree contains node or null if
  87. // the node is not contained within the dom tree of any widget
  88. while (node) {
  89. if (node.getAttribute && node.getAttribute("widgetId")) {
  90. return dijit.registry.byId(node.getAttribute("widgetId"));
  91. }
  92. node = node.parentNode;
  93. }
  94. return null;
  95. };
  96. }