PopupMenuItem.js.uncompressed.js 2.2 KB

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