[483] | 1 | define([ |
---|
| 2 | "dojo/_base/declare", // declare |
---|
| 3 | "dojo/dom-style", // domStyle.set |
---|
| 4 | "dojo/_base/lang", |
---|
| 5 | "dojo/query", // query |
---|
| 6 | "./popup", |
---|
| 7 | "./registry", // registry.byNode |
---|
| 8 | "./MenuItem", |
---|
| 9 | "./hccss" |
---|
| 10 | ], function(declare, domStyle, lang, query, pm, registry, MenuItem){ |
---|
| 11 | |
---|
| 12 | // module: |
---|
| 13 | // dijit/PopupMenuItem |
---|
| 14 | |
---|
| 15 | return declare("dijit.PopupMenuItem", MenuItem, { |
---|
| 16 | // summary: |
---|
| 17 | // An item in a Menu that spawn a drop down (usually a drop down menu) |
---|
| 18 | |
---|
| 19 | _fillContent: function(){ |
---|
| 20 | // summary: |
---|
| 21 | // When Menu is declared in markup, this code gets the menu label and |
---|
| 22 | // the popup widget from the srcNodeRef. |
---|
| 23 | // description: |
---|
| 24 | // srcNodeRef.innerHTML contains both the menu item text and a popup widget |
---|
| 25 | // The first part holds the menu item text and the second part is the popup |
---|
| 26 | // example: |
---|
| 27 | // | <div data-dojo-type="dijit/PopupMenuItem"> |
---|
| 28 | // | <span>pick me</span> |
---|
| 29 | // | <popup> ... </popup> |
---|
| 30 | // | </div> |
---|
| 31 | // tags: |
---|
| 32 | // protected |
---|
| 33 | |
---|
| 34 | if(this.srcNodeRef){ |
---|
| 35 | var nodes = query("*", this.srcNodeRef); |
---|
| 36 | this.inherited(arguments, [nodes[0]]); |
---|
| 37 | |
---|
| 38 | // save pointer to srcNode so we can grab the drop down widget after it's instantiated |
---|
| 39 | this.dropDownContainer = this.srcNodeRef; |
---|
| 40 | } |
---|
| 41 | }, |
---|
| 42 | |
---|
| 43 | _openPopup: function(/*Object*/ params, /*Boolean*/ focus){ |
---|
| 44 | // summary: |
---|
| 45 | // Open the popup to the side of/underneath this MenuItem, and optionally focus first item |
---|
| 46 | // tags: |
---|
| 47 | // protected |
---|
| 48 | |
---|
| 49 | var popup = this.popup; |
---|
| 50 | |
---|
| 51 | pm.open(lang.delegate(params, { |
---|
| 52 | popup: this.popup, |
---|
| 53 | around: this.domNode |
---|
| 54 | })); |
---|
| 55 | |
---|
| 56 | if(focus && popup.focus){ |
---|
| 57 | popup.focus(); |
---|
| 58 | } |
---|
| 59 | }, |
---|
| 60 | |
---|
| 61 | _closePopup: function(){ |
---|
| 62 | pm.close(this.popup); |
---|
| 63 | this.popup.parentMenu = null; |
---|
| 64 | }, |
---|
| 65 | |
---|
| 66 | startup: function(){ |
---|
| 67 | if(this._started){ return; } |
---|
| 68 | this.inherited(arguments); |
---|
| 69 | |
---|
| 70 | // We didn't copy the dropdown widget from the this.srcNodeRef, so it's in no-man's |
---|
| 71 | // land now. Move it to <body>. |
---|
| 72 | if(!this.popup){ |
---|
| 73 | var node = query("[widgetId]", this.dropDownContainer)[0]; |
---|
| 74 | this.popup = registry.byNode(node); |
---|
| 75 | } |
---|
| 76 | this.ownerDocumentBody.appendChild(this.popup.domNode); |
---|
| 77 | this.popup.domNode.setAttribute("aria-labelledby", this.containerNode.id); |
---|
| 78 | this.popup.startup(); |
---|
| 79 | |
---|
| 80 | this.popup.domNode.style.display="none"; |
---|
| 81 | if(this.arrowWrapper){ |
---|
| 82 | domStyle.set(this.arrowWrapper, "visibility", ""); |
---|
| 83 | } |
---|
| 84 | this.focusNode.setAttribute("aria-haspopup", "true"); |
---|
| 85 | }, |
---|
| 86 | |
---|
| 87 | destroyDescendants: function(/*Boolean*/ preserveDom){ |
---|
| 88 | if(this.popup){ |
---|
| 89 | // Destroy the popup, unless it's already been destroyed. This can happen because |
---|
| 90 | // the popup is a direct child of <body> even though it's logically my child. |
---|
| 91 | if(!this.popup._destroyed){ |
---|
| 92 | this.popup.destroyRecursive(preserveDom); |
---|
| 93 | } |
---|
| 94 | delete this.popup; |
---|
| 95 | } |
---|
| 96 | this.inherited(arguments); |
---|
| 97 | } |
---|
| 98 | }); |
---|
| 99 | }); |
---|