source: Dev/branches/rest-dojo-ui/client/dijit/form/DropDownButton.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.1 KB
Line 
1define([
2        "dojo/_base/declare", // declare
3        "dojo/_base/lang",      // hitch
4        "dojo/query", // query
5        "../registry",  // registry.byNode
6        "../popup",             // dijit.popup2.hide
7        "./Button",
8        "../_Container",
9        "../_HasDropDown",
10        "dojo/text!./templates/DropDownButton.html"
11], function(declare, lang, query, registry, popup, Button, _Container, _HasDropDown, template){
12
13/*=====
14        Button = dijit.form.Button;
15        _Container = dijit._Container;
16        _HasDropDown = dijit._HasDropDown;
17=====*/
18
19// module:
20//              dijit/form/DropDownButton
21// summary:
22//              A button with a drop down
23
24
25return declare("dijit.form.DropDownButton", [Button, _Container, _HasDropDown], {
26        // summary:
27        //              A button with a drop down
28        //
29        // example:
30        // |    <button data-dojo-type="dijit.form.DropDownButton">
31        // |            Hello world
32        // |            <div data-dojo-type="dijit.Menu">...</div>
33        // |    </button>
34        //
35        // example:
36        // |    var button1 = new dijit.form.DropDownButton({ label: "hi", dropDown: new dijit.Menu(...) });
37        // |    win.body().appendChild(button1);
38        //
39
40        baseClass : "dijitDropDownButton",
41
42        templateString: template,
43
44        _fillContent: function(){
45                // Overrides Button._fillContent().
46                //
47                // My inner HTML contains both the button contents and a drop down widget, like
48                // <DropDownButton>  <span>push me</span>  <Menu> ... </Menu> </DropDownButton>
49                // The first node is assumed to be the button content. The widget is the popup.
50
51                if(this.srcNodeRef){ // programatically created buttons might not define srcNodeRef
52                        //FIXME: figure out how to filter out the widget and use all remaining nodes as button
53                        //      content, not just nodes[0]
54                        var nodes = query("*", this.srcNodeRef);
55                        this.inherited(arguments, [nodes[0]]);
56
57                        // save pointer to srcNode so we can grab the drop down widget after it's instantiated
58                        this.dropDownContainer = this.srcNodeRef;
59                }
60        },
61
62        startup: function(){
63                if(this._started){ return; }
64
65                // the child widget from srcNodeRef is the dropdown widget.  Insert it in the page DOM,
66                // make it invisible, and store a reference to pass to the popup code.
67                if(!this.dropDown && this.dropDownContainer){
68                        var dropDownNode = query("[widgetId]", this.dropDownContainer)[0];
69                        this.dropDown = registry.byNode(dropDownNode);
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
105});
Note: See TracBrowser for help on using the repository browser.