Debian Codegraph @

dijit/form/DropDownButton.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/_base/kernel",
4 "dojo/_base/lang", // hitch
5 "dojo/query", // query
6 "../registry", // registry.byNode
7 "../popup", // dijit.popup2.hide
8 "./Button",
9 "../_Container",
10 "../_HasDropDown",
11 "dojo/text!./templates/DropDownButton.html",
12 "../a11yclick" // template uses ondijitclick
13 ], function(declare, kernel, lang, query, registry, popup, Button, _Container, _HasDropDown, template){
14
15 // module:
16 // dijit/form/DropDownButton
17
18 return declare("dijit.form.DropDownButton", [Button, _Container, _HasDropDown], {
19 // summary:
20 // A button with a drop down
21 //
22 // example:
23 // | <button data-dojo-type="dijit/form/DropDownButton">
24 // | Hello world
25 // | <div data-dojo-type="dijit/Menu">...</div>
26 // | </button>
27 //
28 // example:
29 // | var button1 = new DropDownButton({ label: "hi", dropDown: new dijit.Menu(...) });
30 // | win.body().appendChild(button1);
31 //
32
33 baseClass: "dijitDropDownButton",
34
35 templateString: template,
36
37 _fillContent: function(){
38 // Overrides _TemplatedMixin#_fillContent().
39 // My inner HTML possibly contains both the button label and/or a drop down widget, like
40 // <DropDownButton> <span>push me</span> <Menu> ... </Menu> </DropDownButton>
41
42 var source = this.srcNodeRef;
43 var dest = this.containerNode;
44 if(source && dest){
45 while(source.hasChildNodes()){
46 var child = source.firstChild;
47 if(child.hasAttribute && (child.hasAttribute("data-dojo-type") || child.hasAttribute("dojoType") ||
48 child.hasAttribute("data-" + kernel._scopeName + "-type") ||
49 child.hasAttribute(kernel._scopeName + "Type"))){
50 // The parser hasn't gotten to this node yet, so save it in a wrapper <div>
51 // and then grab the instantiated widget in startup().
52 this.dropDownContainer = this.ownerDocument.createElement("div");
53 this.dropDownContainer.appendChild(child);
54 }else{
55 dest.appendChild(child);
56 }
57 }
58 }
59 },
60
61 startup: function(){
62 if(this._started){
63 return;
64 }
65
66 // the child widget from srcNodeRef is the dropdown widget. Insert it in the page DOM,
67 // make it invisible, and store a reference to pass to the popup code.
68 if(!this.dropDown && this.dropDownContainer){
69 this.dropDown = registry.byNode(this.dropDownContainer.firstChild);
70 delete this.dropDownContainer;
71 }
72 if(this.dropDown){
73 popup.hide(this.dropDown);
74 }
75
76 this.inherited(arguments);
77 },
78
79 isLoaded: function(){
80 // Returns whether or not we are loaded - if our dropdown has an href,
81 // then we want to check that.
82 var dropDown = this.dropDown;
83 return (!!dropDown && (!dropDown.href || dropDown.isLoaded));
84 },
85
86 loadDropDown: function(/*Function*/ callback){
87 // Default implementation assumes that drop down already exists,
88 // but hasn't loaded it's data (ex: ContentPane w/href).
89 // App must override if the drop down is lazy-created.
90 var dropDown = this.dropDown;
91 var handler = dropDown.on("load", lang.hitch(this, function(){
92 handler.remove();
93 callback();
94 }));
95 dropDown.refresh(); // tell it to load
96 },
97
98 isFocusable: function(){
99 // Overridden so that focus is handled by the _HasDropDown mixin, not by
100 // the _FormWidget mixin.
101 return this.inherited(arguments) && !this._mouseDown;
102 }
103 });
104 });