]>
Commit | Line | Data |
---|---|---|
1354d172 AD |
1 | require({cache:{ |
2 | 'url:dijit/form/templates/DropDownButton.html':"<span class=\"dijit dijitReset dijitInline\"\n\t><span class='dijitReset dijitInline dijitButtonNode'\n\t\tdata-dojo-attach-event=\"ondijitclick:_onClick\" data-dojo-attach-point=\"_buttonNode\"\n\t\t><span class=\"dijitReset dijitStretch dijitButtonContents\"\n\t\t\tdata-dojo-attach-point=\"focusNode,titleNode,_arrowWrapperNode\"\n\t\t\trole=\"button\" aria-haspopup=\"true\" aria-labelledby=\"${id}_label\"\n\t\t\t><span class=\"dijitReset dijitInline dijitIcon\"\n\t\t\t\tdata-dojo-attach-point=\"iconNode\"\n\t\t\t></span\n\t\t\t><span class=\"dijitReset dijitInline dijitButtonText\"\n\t\t\t\tdata-dojo-attach-point=\"containerNode,_popupStateNode\"\n\t\t\t\tid=\"${id}_label\"\n\t\t\t></span\n\t\t\t><span class=\"dijitReset dijitInline dijitArrowButtonInner\"></span\n\t\t\t><span class=\"dijitReset dijitInline dijitArrowButtonChar\">▼</span\n\t\t></span\n\t></span\n\t><input ${!nameAttrSetting} type=\"${type}\" value=\"${value}\" class=\"dijitOffScreen\" tabIndex=\"-1\"\n\t\tdata-dojo-attach-point=\"valueNode\"\n/></span>\n"}}); | |
3 | define("dijit/form/DropDownButton", [ | |
4 | "dojo/_base/declare", // declare | |
5 | "dojo/_base/lang", // hitch | |
6 | "dojo/query", // query | |
7 | "../registry", // registry.byNode | |
8 | "../popup", // dijit.popup2.hide | |
9 | "./Button", | |
10 | "../_Container", | |
11 | "../_HasDropDown", | |
12 | "dojo/text!./templates/DropDownButton.html" | |
13 | ], function(declare, lang, query, registry, popup, Button, _Container, _HasDropDown, template){ | |
14 | ||
15 | /*===== | |
16 | Button = dijit.form.Button; | |
17 | _Container = dijit._Container; | |
18 | _HasDropDown = dijit._HasDropDown; | |
19 | =====*/ | |
20 | ||
21 | // module: | |
22 | // dijit/form/DropDownButton | |
23 | // summary: | |
24 | // A button with a drop down | |
25 | ||
26 | ||
27 | return declare("dijit.form.DropDownButton", [Button, _Container, _HasDropDown], { | |
28 | // summary: | |
29 | // A button with a drop down | |
30 | // | |
31 | // example: | |
32 | // | <button data-dojo-type="dijit.form.DropDownButton"> | |
33 | // | Hello world | |
34 | // | <div data-dojo-type="dijit.Menu">...</div> | |
35 | // | </button> | |
36 | // | |
37 | // example: | |
38 | // | var button1 = new dijit.form.DropDownButton({ label: "hi", dropDown: new dijit.Menu(...) }); | |
39 | // | win.body().appendChild(button1); | |
40 | // | |
41 | ||
42 | baseClass : "dijitDropDownButton", | |
43 | ||
44 | templateString: template, | |
45 | ||
46 | _fillContent: function(){ | |
47 | // Overrides Button._fillContent(). | |
48 | // | |
49 | // My inner HTML contains both the button contents and a drop down widget, like | |
50 | // <DropDownButton> <span>push me</span> <Menu> ... </Menu> </DropDownButton> | |
51 | // The first node is assumed to be the button content. The widget is the popup. | |
52 | ||
53 | if(this.srcNodeRef){ // programatically created buttons might not define srcNodeRef | |
54 | //FIXME: figure out how to filter out the widget and use all remaining nodes as button | |
55 | // content, not just nodes[0] | |
56 | var nodes = query("*", this.srcNodeRef); | |
57 | this.inherited(arguments, [nodes[0]]); | |
58 | ||
59 | // save pointer to srcNode so we can grab the drop down widget after it's instantiated | |
60 | this.dropDownContainer = this.srcNodeRef; | |
61 | } | |
62 | }, | |
63 | ||
64 | startup: function(){ | |
65 | if(this._started){ return; } | |
66 | ||
67 | // the child widget from srcNodeRef is the dropdown widget. Insert it in the page DOM, | |
68 | // make it invisible, and store a reference to pass to the popup code. | |
69 | if(!this.dropDown && this.dropDownContainer){ | |
70 | var dropDownNode = query("[widgetId]", this.dropDownContainer)[0]; | |
71 | this.dropDown = registry.byNode(dropDownNode); | |
72 | delete this.dropDownContainer; | |
73 | } | |
74 | if(this.dropDown){ | |
75 | popup.hide(this.dropDown); | |
76 | } | |
77 | ||
78 | this.inherited(arguments); | |
79 | }, | |
80 | ||
81 | isLoaded: function(){ | |
82 | // Returns whether or not we are loaded - if our dropdown has an href, | |
83 | // then we want to check that. | |
84 | var dropDown = this.dropDown; | |
85 | return (!!dropDown && (!dropDown.href || dropDown.isLoaded)); | |
86 | }, | |
87 | ||
88 | loadDropDown: function(/*Function*/ callback){ | |
89 | // Default implementation assumes that drop down already exists, | |
90 | // but hasn't loaded it's data (ex: ContentPane w/href). | |
91 | // App must override if the drop down is lazy-created. | |
92 | var dropDown = this.dropDown; | |
93 | var handler = dropDown.on("load", lang.hitch(this, function(){ | |
94 | handler.remove(); | |
95 | callback(); | |
96 | })); | |
97 | dropDown.refresh(); // tell it to load | |
98 | }, | |
99 | ||
100 | isFocusable: function(){ | |
101 | // Overridden so that focus is handled by the _HasDropDown mixin, not by | |
102 | // the _FormWidget mixin. | |
103 | return this.inherited(arguments) && !this._mouseDown; | |
104 | } | |
105 | }); | |
106 | ||
107 | }); |