1 | define([ |
---|
2 | "dojo/_base/declare", // declare |
---|
3 | "dojo/keys", // keys |
---|
4 | "../focus", // focus.focus() |
---|
5 | "./DropDownButton", |
---|
6 | "dojo/text!./templates/ComboButton.html" |
---|
7 | ], function(declare, keys, focus, DropDownButton, template){ |
---|
8 | |
---|
9 | // module: |
---|
10 | // dijit/form/ComboButton |
---|
11 | |
---|
12 | return declare("dijit.form.ComboButton", DropDownButton, { |
---|
13 | // summary: |
---|
14 | // A combination button and drop-down button. |
---|
15 | // Users can click one side to "press" the button, or click an arrow |
---|
16 | // icon to display the drop down. |
---|
17 | // |
---|
18 | // example: |
---|
19 | // | <button data-dojo-type="dijit/form/ComboButton" onClick="..."> |
---|
20 | // | <span>Hello world</span> |
---|
21 | // | <div data-dojo-type="dijit/Menu">...</div> |
---|
22 | // | </button> |
---|
23 | // |
---|
24 | // example: |
---|
25 | // | var button1 = new ComboButton({label: "hello world", onClick: foo, dropDown: "myMenu"}); |
---|
26 | // | dojo.body().appendChild(button1.domNode); |
---|
27 | // |
---|
28 | |
---|
29 | templateString: template, |
---|
30 | |
---|
31 | // Map widget attributes to DOMNode attributes. |
---|
32 | _setIdAttr: "", // override _FormWidgetMixin which puts id on the focusNode |
---|
33 | _setTabIndexAttr: ["focusNode", "titleNode"], |
---|
34 | _setTitleAttr: "titleNode", |
---|
35 | |
---|
36 | // optionsTitle: String |
---|
37 | // Text that describes the options menu (accessibility) |
---|
38 | optionsTitle: "", |
---|
39 | |
---|
40 | baseClass: "dijitComboButton", |
---|
41 | |
---|
42 | // Set classes like dijitButtonContentsHover or dijitArrowButtonActive depending on |
---|
43 | // mouse action over specified node |
---|
44 | cssStateNodes: { |
---|
45 | "buttonNode": "dijitButtonNode", |
---|
46 | "titleNode": "dijitButtonContents", |
---|
47 | "_popupStateNode": "dijitDownArrowButton" |
---|
48 | }, |
---|
49 | |
---|
50 | _focusedNode: null, |
---|
51 | |
---|
52 | _onButtonKeyDown: function(/*Event*/ evt){ |
---|
53 | // summary: |
---|
54 | // Handler for right arrow key when focus is on left part of button |
---|
55 | if(evt.keyCode == keys[this.isLeftToRight() ? "RIGHT_ARROW" : "LEFT_ARROW"]){ |
---|
56 | focus.focus(this._popupStateNode); |
---|
57 | evt.stopPropagation(); |
---|
58 | evt.preventDefault(); |
---|
59 | } |
---|
60 | }, |
---|
61 | |
---|
62 | _onArrowKeyDown: function(/*Event*/ evt){ |
---|
63 | // summary: |
---|
64 | // Handler for left arrow key when focus is on right part of button |
---|
65 | if(evt.keyCode == keys[this.isLeftToRight() ? "LEFT_ARROW" : "RIGHT_ARROW"]){ |
---|
66 | focus.focus(this.titleNode); |
---|
67 | evt.stopPropagation(); |
---|
68 | evt.preventDefault(); |
---|
69 | } |
---|
70 | }, |
---|
71 | |
---|
72 | focus: function(/*String*/ position){ |
---|
73 | // summary: |
---|
74 | // Focuses this widget to according to position, if specified, |
---|
75 | // otherwise on arrow node |
---|
76 | // position: |
---|
77 | // "start" or "end" |
---|
78 | if(!this.disabled){ |
---|
79 | focus.focus(position == "start" ? this.titleNode : this._popupStateNode); |
---|
80 | } |
---|
81 | } |
---|
82 | }); |
---|
83 | }); |
---|