| 1 |
define([ |
| 2 |
"require", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/dom-class", |
| 5 |
"dojo/has", |
| 6 |
"dojo/_base/kernel", |
| 7 |
"dojo/_base/lang", |
| 8 |
"dojo/ready", |
| 9 |
"./_FormWidget", |
| 10 |
"./_ButtonMixin", |
| 11 |
"dojo/text!./templates/Button.html", |
| 12 |
"../a11yclick" |
| 13 |
], function(require, declare, domClass, has, kernel, lang, ready, _FormWidget, _ButtonMixin, template){ |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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); |
| 23 |
}); |
| 24 |
} |
| 25 |
|
| 26 |
var Button = declare("dijit.form.Button" + (has("dojo-bidi") ? "_NoBidi" : ""), [_FormWidget, _ButtonMixin], { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
showLabel: true, |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
iconClass: "dijitNoIcon", |
| 53 |
_setIconClassAttr: { node: "iconNode", type: "class" }, |
| 54 |
|
| 55 |
baseClass: "dijitButton", |
| 56 |
|
| 57 |
templateString: template, |
| 58 |
|
| 59 |
|
| 60 |
_setValueAttr: "valueNode", |
| 61 |
_setNameAttr: function(name){ |
| 62 |
|
| 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 |
|
| 76 |
|
| 77 |
|
| 78 |
this.label = lang.trim(this.containerNode.innerHTML); |
| 79 |
this.onLabelSet(); |
| 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( content){ |
| 91 |
|
| 92 |
|
| 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( textDir){ |
| 115 |
if(this._created && this.textDir != textDir){ |
| 116 |
this._set("textDir", textDir); |
| 117 |
this._setLabelAttr(this.label); |
| 118 |
} |
| 119 |
} |
| 120 |
}); |
| 121 |
} |
| 122 |
|
| 123 |
return Button; |
| 124 |
}); |