Debian Codegraph @

dijit/form/Button.js

raw symbols SCIP
1 define([
2 "require",
3 "dojo/_base/declare", // declare
4 "dojo/dom-class", // domClass.toggle
5 "dojo/has", // has("dijit-legacy-requires")
6 "dojo/_base/kernel", // kernel.deprecated
7 "dojo/_base/lang", // lang.trim
8 "dojo/ready",
9 "./_FormWidget",
10 "./_ButtonMixin",
11 "dojo/text!./templates/Button.html",
12 "../a11yclick" // template uses ondijitclick
13 ], function(require, declare, domClass, has, kernel, lang, ready, _FormWidget, _ButtonMixin, template){
14
15 // module:
16 // dijit/form/Button
17
18 // Back compat w/1.6, remove for 2.0
19 if(has("dijit-legacy-requires")){
20 ready(0, function(){
21 var requires = ["dijit/form/DropDownButton", "dijit/form/ComboButton", "dijit/form/ToggleButton"];
22 require(requires); // use indirection so modules not rolled into a build
23 });
24 }
25
26 var Button = declare("dijit.form.Button" + (has("dojo-bidi") ? "_NoBidi" : ""), [_FormWidget, _ButtonMixin], {
27 // summary:
28 // Basically the same thing as a normal HTML button, but with special styling.
29 // description:
30 // Buttons can display a label, an icon, or both.
31 // A label should always be specified (through innerHTML) or the label
32 // attribute. It can be hidden via showLabel=false.
33 // example:
34 // | <button data-dojo-type="dijit/form/Button" onClick="...">Hello world</button>
35 //
36 // example:
37 // | var button1 = new Button({label: "hello world", onClick: foo});
38 // | dojo.body().appendChild(button1.domNode);
39
40 // showLabel: Boolean
41 // Set this to true to hide the label text and display only the icon.
42 // (If showLabel=false then iconClass must be specified.)
43 // Especially useful for toolbars.
44 // If showLabel=true, the label will become the title (a.k.a. tooltip/hint) of the icon.
45 //
46 // The exception case is for computers in high-contrast mode, where the label
47 // will still be displayed, since the icon doesn't appear.
48 showLabel: true,
49
50 // iconClass: String
51 // Class to apply to DOMNode in button to make it display an icon
52 iconClass: "dijitNoIcon",
53 _setIconClassAttr: { node: "iconNode", type: "class" },
54
55 baseClass: "dijitButton",
56
57 templateString: template,
58
59 // Map widget attributes to DOMNode attributes.
60 _setValueAttr: "valueNode",
61 _setNameAttr: function(name){
62 // avoid breaking existing subclasses where valueNode undefined. Perhaps in 2.0 require it to be defined?
63 if(this.valueNode){
64 this.valueNode.setAttribute("name", name);
65 }
66 },
67
68 postCreate: function(){
69 this.inherited(arguments);
70 this._setLabelFromContainer();
71 },
72
73 _setLabelFromContainer: function(){
74 if(this.containerNode && !this.label){
75 // When markup was set as srcNodeRef.innerHTML, copy it to this.label, in case someone tries to
76 // reference that variable. Alternately, could have a _getLabelAttr() method to return
77 // this.containerNode.innerHTML.
78 this.label = lang.trim(this.containerNode.innerHTML);
79 this.onLabelSet(); // set this.titleNode.title etc. according to label
80 }
81 },
82
83 _setShowLabelAttr: function(val){
84 if(this.containerNode){
85 domClass.toggle(this.containerNode, "dijitDisplayNone", !val);
86 }
87 this._set("showLabel", val);
88 },
89
90 setLabel: function(/*String*/ content){
91 // summary:
92 // Deprecated. Use set('label', ...) instead.
93 kernel.deprecated("dijit.form.Button.setLabel() is deprecated. Use set('label', ...) instead.", "", "2.0");
94 this.set("label", content);
95 },
96
97 onLabelSet: function(){
98 this.inherited(arguments);
99 if(!this.showLabel && !("title" in this.params)){
100 this.titleNode.title = lang.trim(this.containerNode.innerText || this.containerNode.textContent || '');
101 }
102 }
103 });
104
105 if(has("dojo-bidi")){
106 Button = declare("dijit.form.Button", Button, {
107 onLabelSet: function(){
108 this.inherited(arguments);
109 if(this.titleNode.title){
110 this.applyTextDir(this.titleNode, this.titleNode.title);
111 }
112 },
113
114 _setTextDirAttr: function(/*String*/ textDir){
115 if(this._created && this.textDir != textDir){
116 this._set("textDir", textDir);
117 this._setLabelAttr(this.label); // call applyTextDir on both focusNode and titleNode
118 }
119 }
120 });
121 }
122
123 return Button;
124 });