source: Dev/branches/rest-dojo-ui/client/dijit/form/Button.js @ 274

Last change on this file since 274 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.9 KB
Line 
1define([
2        "require",
3        "dojo/_base/declare", // declare
4        "dojo/dom-class", // domClass.toggle
5        "dojo/_base/kernel", // kernel.deprecated
6        "dojo/_base/lang", // lang.trim
7        "dojo/ready",
8        "./_FormWidget",
9        "./_ButtonMixin",
10        "dojo/text!./templates/Button.html"
11], function(require, declare, domClass, kernel, lang, ready, _FormWidget, _ButtonMixin, template){
12
13/*=====
14        var _FormWidget = dijit.form._FormWidget;
15        var _ButtonMixin = dijit.form._ButtonMixin;
16=====*/
17
18// module:
19//              dijit/form/Button
20// summary:
21//              Button widget
22
23// Back compat w/1.6, remove for 2.0
24if(!kernel.isAsync){
25        ready(0, function(){
26                var requires = ["dijit/form/DropDownButton", "dijit/form/ComboButton", "dijit/form/ToggleButton"];
27                require(requires);      // use indirection so modules not rolled into a build
28        });
29}
30
31return declare("dijit.form.Button", [_FormWidget, _ButtonMixin], {
32        // summary:
33        //              Basically the same thing as a normal HTML button, but with special styling.
34        // description:
35        //              Buttons can display a label, an icon, or both.
36        //              A label should always be specified (through innerHTML) or the label
37        //              attribute.  It can be hidden via showLabel=false.
38        // example:
39        // |    <button data-dojo-type="dijit.form.Button" onClick="...">Hello world</button>
40        //
41        // example:
42        // |    var button1 = new dijit.form.Button({label: "hello world", onClick: foo});
43        // |    dojo.body().appendChild(button1.domNode);
44
45        // showLabel: Boolean
46        //              Set this to true to hide the label text and display only the icon.
47        //              (If showLabel=false then iconClass must be specified.)
48        //              Especially useful for toolbars.
49        //              If showLabel=true, the label will become the title (a.k.a. tooltip/hint) of the icon.
50        //
51        //              The exception case is for computers in high-contrast mode, where the label
52        //              will still be displayed, since the icon doesn't appear.
53        showLabel: true,
54
55        // iconClass: String
56        //              Class to apply to DOMNode in button to make it display an icon
57        iconClass: "dijitNoIcon",
58        _setIconClassAttr: { node: "iconNode", type: "class" },
59
60        baseClass: "dijitButton",
61
62        templateString: template,
63
64        // Map widget attributes to DOMNode attributes.
65        _setValueAttr: "valueNode",
66
67        _onClick: function(/*Event*/ e){
68                // summary:
69                //              Internal function to handle click actions
70                var ok = this.inherited(arguments);
71                if(ok){
72                        if(this.valueNode){
73                                this.valueNode.click();
74                                e.preventDefault(); // cancel BUTTON click and continue with hidden INPUT click
75                                // leave ok = true so that subclasses can do what they need to do
76                        }
77                }
78                return ok;
79        },
80
81        _fillContent: function(/*DomNode*/ source){
82                // Overrides _Templated._fillContent().
83                // If button label is specified as srcNodeRef.innerHTML rather than
84                // this.params.label, handle it here.
85                // TODO: remove the method in 2.0, parser will do it all for me
86                if(source && (!this.params || !("label" in this.params))){
87                        var sourceLabel = lang.trim(source.innerHTML);
88                        if(sourceLabel){
89                                this.label = sourceLabel; // _applyAttributes will be called after buildRendering completes to update the DOM
90                        }
91                }
92        },
93
94        _setShowLabelAttr: function(val){
95                if(this.containerNode){
96                        domClass.toggle(this.containerNode, "dijitDisplayNone", !val);
97                }
98                this._set("showLabel", val);
99        },
100
101        setLabel: function(/*String*/ content){
102                // summary:
103                //              Deprecated.  Use set('label', ...) instead.
104                kernel.deprecated("dijit.form.Button.setLabel() is deprecated.  Use set('label', ...) instead.", "", "2.0");
105                this.set("label", content);
106        },
107
108        _setLabelAttr: function(/*String*/ content){
109                // summary:
110                //              Hook for set('label', ...) to work.
111                // description:
112                //              Set the label (text) of the button; takes an HTML string.
113                //              If the label is hidden (showLabel=false) then and no title has
114                //              been specified, then label is also set as title attribute of icon.
115                this.inherited(arguments);
116                if(!this.showLabel && !("title" in this.params)){
117                        this.titleNode.title = lang.trim(this.containerNode.innerText || this.containerNode.textContent || '');
118                }
119        }
120});
121
122
123});
124
Note: See TracBrowser for help on using the repository browser.