PopupMenuItem.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dijit.PopupMenuItem"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit.PopupMenuItem"] = true;
  8. dojo.provide("dijit.PopupMenuItem");
  9. dojo.require("dijit.MenuItem");
  10. dojo.declare("dijit.PopupMenuItem",
  11. dijit.MenuItem,
  12. {
  13. _fillContent: function(){
  14. // summary:
  15. // When Menu is declared in markup, this code gets the menu label and
  16. // the popup widget from the srcNodeRef.
  17. // description:
  18. // srcNodeRefinnerHTML contains both the menu item text and a popup widget
  19. // The first part holds the menu item text and the second part is the popup
  20. // example:
  21. // | <div dojoType="dijit.PopupMenuItem">
  22. // | <span>pick me</span>
  23. // | <popup> ... </popup>
  24. // | </div>
  25. // tags:
  26. // protected
  27. if(this.srcNodeRef){
  28. var nodes = dojo.query("*", this.srcNodeRef);
  29. dijit.PopupMenuItem.superclass._fillContent.call(this, nodes[0]);
  30. // save pointer to srcNode so we can grab the drop down widget after it's instantiated
  31. this.dropDownContainer = this.srcNodeRef;
  32. }
  33. },
  34. startup: function(){
  35. if(this._started){ return; }
  36. this.inherited(arguments);
  37. // we didn't copy the dropdown widget from the this.srcNodeRef, so it's in no-man's
  38. // land now. move it to dojo.doc.body.
  39. if(!this.popup){
  40. var node = dojo.query("[widgetId]", this.dropDownContainer)[0];
  41. this.popup = dijit.byNode(node);
  42. }
  43. dojo.body().appendChild(this.popup.domNode);
  44. this.popup.startup();
  45. this.popup.domNode.style.display="none";
  46. if(this.arrowWrapper){
  47. dojo.style(this.arrowWrapper, "visibility", "");
  48. }
  49. dijit.setWaiState(this.focusNode, "haspopup", "true");
  50. },
  51. destroyDescendants: function(){
  52. if(this.popup){
  53. // Destroy the popup, unless it's already been destroyed. This can happen because
  54. // the popup is a direct child of <body> even though it's logically my child.
  55. if(!this.popup._destroyed){
  56. this.popup.destroyRecursive();
  57. }
  58. delete this.popup;
  59. }
  60. this.inherited(arguments);
  61. }
  62. });
  63. }