UNPKG

dijit

Version:

Dijit provides a complete collection of user interface controls based on Dojo, giving you the power to create web applications that are highly optimized for usability, performance, internationalization, accessibility, but above all deliver an incredible u

125 lines (108 loc) 4.13 kB
define([ "require", "dojo/_base/declare", // declare "dojo/dom-class", // domClass.toggle "dojo/has", // has("dijit-legacy-requires") "dojo/_base/kernel", // kernel.deprecated "dojo/_base/lang", // lang.trim "dojo/ready", "./_FormWidget", "./_ButtonMixin", "dojo/text!./templates/Button.html", "../a11yclick" // template uses ondijitclick ], function(require, declare, domClass, has, kernel, lang, ready, _FormWidget, _ButtonMixin, template){ // module: // dijit/form/Button // Back compat w/1.6, remove for 2.0 if(has("dijit-legacy-requires")){ ready(0, function(){ var requires = ["dijit/form/DropDownButton", "dijit/form/ComboButton", "dijit/form/ToggleButton"]; require(requires); // use indirection so modules not rolled into a build }); } var Button = declare("dijit.form.Button" + (has("dojo-bidi") ? "_NoBidi" : ""), [_FormWidget, _ButtonMixin], { // summary: // Basically the same thing as a normal HTML button, but with special styling. // description: // Buttons can display a label, an icon, or both. // A label should always be specified (through innerHTML) or the label // attribute. It can be hidden via showLabel=false. // example: // | <button data-dojo-type="dijit/form/Button" onClick="...">Hello world</button> // // example: // | var button1 = new Button({label: "hello world", onClick: foo}); // | dojo.body().appendChild(button1.domNode); // showLabel: Boolean // Set this to true to hide the label text and display only the icon. // (If showLabel=false then iconClass must be specified.) // Especially useful for toolbars. // If showLabel=true, the label will become the title (a.k.a. tooltip/hint) of the icon. // // The exception case is for computers in high-contrast mode, where the label // will still be displayed, since the icon doesn't appear. showLabel: true, // iconClass: String // Class to apply to DOMNode in button to make it display an icon iconClass: "dijitNoIcon", _setIconClassAttr: { node: "iconNode", type: "class" }, baseClass: "dijitButton", templateString: template, // Map widget attributes to DOMNode attributes. _setValueAttr: "valueNode", _setNameAttr: function(name){ // avoid breaking existing subclasses where valueNode undefined. Perhaps in 2.0 require it to be defined? if(this.valueNode){ this.valueNode.setAttribute("name", name); } }, postCreate: function(){ this.inherited(arguments); this._setLabelFromContainer(); }, _setLabelFromContainer: function(){ if(this.containerNode && !this.label){ // When markup was set as srcNodeRef.innerHTML, copy it to this.label, in case someone tries to // reference that variable. Alternately, could have a _getLabelAttr() method to return // this.containerNode.innerHTML. this.label = lang.trim(this.containerNode.innerHTML); this.onLabelSet(); // set this.titleNode.title etc. according to label } }, _setShowLabelAttr: function(val){ if(this.containerNode){ domClass.toggle(this.containerNode, "dijitDisplayNone", !val); } this._set("showLabel", val); }, setLabel: function(/*String*/ content){ // summary: // Deprecated. Use set('label', ...) instead. kernel.deprecated("dijit.form.Button.setLabel() is deprecated. Use set('label', ...) instead.", "", "2.0"); this.set("label", content); }, onLabelSet: function(){ this.inherited(arguments); if(!this.showLabel && !("title" in this.params)){ this.titleNode.title = lang.trim(this.containerNode.innerText || this.containerNode.textContent || ''); } } }); if(has("dojo-bidi")){ Button = declare("dijit.form.Button", Button, { onLabelSet: function(){ this.inherited(arguments); if(this.titleNode.title){ this.applyTextDir(this.titleNode, this.titleNode.title); } }, _setTextDirAttr: function(/*String*/ textDir){ if(this._created && this.textDir != textDir){ this._set("textDir", textDir); this._setLabelAttr(this.label); // call applyTextDir on both focusNode and titleNode } } }); } return Button; });