PopupMenuItem.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. define("dijit/PopupMenuItem", [
  2. "dojo/_base/declare", // declare
  3. "dojo/dom-style", // domStyle.set
  4. "dojo/query", // query
  5. "dojo/_base/window", // win.body
  6. "./registry", // registry.byNode
  7. "./MenuItem",
  8. "./hccss"
  9. ], function(declare, domStyle, query, win, registry, MenuItem){
  10. /*=====
  11. var MenuItem = dijit.MenuItem;
  12. =====*/
  13. // module:
  14. // dijit/PopupMenuItem
  15. // summary:
  16. // An item in a Menu that spawn a drop down (usually a drop down menu)
  17. return declare("dijit.PopupMenuItem", MenuItem, {
  18. // summary:
  19. // An item in a Menu that spawn a drop down (usually a drop down menu)
  20. _fillContent: function(){
  21. // summary:
  22. // When Menu is declared in markup, this code gets the menu label and
  23. // the popup widget from the srcNodeRef.
  24. // description:
  25. // srcNodeRefinnerHTML contains both the menu item text and a popup widget
  26. // The first part holds the menu item text and the second part is the popup
  27. // example:
  28. // | <div data-dojo-type="dijit.PopupMenuItem">
  29. // | <span>pick me</span>
  30. // | <popup> ... </popup>
  31. // | </div>
  32. // tags:
  33. // protected
  34. if(this.srcNodeRef){
  35. var nodes = query("*", this.srcNodeRef);
  36. this.inherited(arguments, [nodes[0]]);
  37. // save pointer to srcNode so we can grab the drop down widget after it's instantiated
  38. this.dropDownContainer = this.srcNodeRef;
  39. }
  40. },
  41. startup: function(){
  42. if(this._started){ return; }
  43. this.inherited(arguments);
  44. // we didn't copy the dropdown widget from the this.srcNodeRef, so it's in no-man's
  45. // land now. move it to win.doc.body.
  46. if(!this.popup){
  47. var node = query("[widgetId]", this.dropDownContainer)[0];
  48. this.popup = registry.byNode(node);
  49. }
  50. win.body().appendChild(this.popup.domNode);
  51. this.popup.startup();
  52. this.popup.domNode.style.display="none";
  53. if(this.arrowWrapper){
  54. domStyle.set(this.arrowWrapper, "visibility", "");
  55. }
  56. this.focusNode.setAttribute("aria-haspopup", "true");
  57. },
  58. destroyDescendants: function(/*Boolean*/ preserveDom){
  59. if(this.popup){
  60. // Destroy the popup, unless it's already been destroyed. This can happen because
  61. // the popup is a direct child of <body> even though it's logically my child.
  62. if(!this.popup._destroyed){
  63. this.popup.destroyRecursive(preserveDom);
  64. }
  65. delete this.popup;
  66. }
  67. this.inherited(arguments);
  68. }
  69. });
  70. });