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