/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
if(!dojo._hasResource["dijit.form.Button"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dijit.form.Button"] = true;
dojo.provide("dijit.form.Button");
dojo.require("dijit.form._FormWidget");
dojo.require("dijit._Container");
dojo.require("dijit._HasDropDown");
dojo.declare("dijit.form.Button",
dijit.form._FormWidget,
{
// 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:
// |
//
// example:
// | var button1 = new dijit.form.Button({label: "hello world", onClick: foo});
// | dojo.body().appendChild(button1.domNode);
// label: HTML String
// Text to display in button.
// If the label is hidden (showLabel=false) then and no title has
// been specified, then label is also set as title attribute of icon.
label: "",
// 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: "",
// type: String
// Defines the type of button. "button", "submit", or "reset".
type: "button",
baseClass: "dijitButton",
templateString: dojo.cache("dijit.form", "templates/Button.html", "●\n"),
attributeMap: dojo.delegate(dijit.form._FormWidget.prototype.attributeMap, {
value: "valueNode"
}),
_onClick: function(/*Event*/ e){
// summary:
// Internal function to handle click actions
if(this.disabled){
return false;
}
this._clicked(); // widget click actions
return this.onClick(e); // user click actions
},
_onButtonClick: function(/*Event*/ e){
// summary:
// Handler when the user activates the button portion.
if(this._onClick(e) === false){ // returning nothing is same as true
e.preventDefault(); // needed for checkbox
}else if(this.type == "submit" && !(this.valueNode||this.focusNode).form){ // see if a nonform widget needs to be signalled
for(var node=this.domNode; node.parentNode/*#5935*/; node=node.parentNode){
var widget=dijit.byNode(node);
if(widget && typeof widget._onSubmit == "function"){
widget._onSubmit(e);
break;
}
}
}else if(this.valueNode){
this.valueNode.click();
e.preventDefault(); // cancel BUTTON click and continue with hidden INPUT click
}
},
buildRendering: function(){
this.inherited(arguments);
dojo.setSelectable(this.focusNode, false);
},
_fillContent: function(/*DomNode*/ source){
// Overrides _Templated._fillContent().
// If button label is specified as srcNodeRef.innerHTML rather than
// this.params.label, handle it here.
// TODO: remove the method in 2.0, parser will do it all for me
if(source && (!this.params || !("label" in this.params))){
this.set('label', source.innerHTML);
}
},
_setShowLabelAttr: function(val){
if(this.containerNode){
dojo.toggleClass(this.containerNode, "dijitDisplayNone", !val);
}
this._set("showLabel", val);
},
onClick: function(/*Event*/ e){
// summary:
// Callback for when button is clicked.
// If type="submit", return true to perform submit, or false to cancel it.
// type:
// callback
return true; // Boolean
},
_clicked: function(/*Event*/ e){
// summary:
// Internal overridable function for when the button is clicked
},
setLabel: function(/*String*/ content){
// summary:
// Deprecated. Use set('label', ...) instead.
dojo.deprecated("dijit.form.Button.setLabel() is deprecated. Use set('label', ...) instead.", "", "2.0");
this.set("label", content);
},
_setLabelAttr: function(/*String*/ content){
// summary:
// Hook for set('label', ...) to work.
// description:
// Set the label (text) of the button; takes an HTML string.
this._set("label", content);
this.containerNode.innerHTML = content;
if(this.showLabel == false && !this.params.title){
this.titleNode.title = dojo.trim(this.containerNode.innerText || this.containerNode.textContent || '');
}
},
_setIconClassAttr: function(/*String*/ val){
// Custom method so that icon node is hidden when not in use, to avoid excess padding/margin
// appearing around it (even if it's a 0x0 sized node)
var oldVal = this.iconClass || "dijitNoIcon",
newVal = val || "dijitNoIcon";
dojo.replaceClass(this.iconNode, newVal, oldVal);
this._set("iconClass", val);
}
});
dojo.declare("dijit.form.DropDownButton", [dijit.form.Button, dijit._Container, dijit._HasDropDown], {
// summary:
// A button with a drop down
//
// example:
// |
//
// example:
// | var button1 = new dijit.form.DropDownButton({ label: "hi", dropDown: new dijit.Menu(...) });
// | dojo.body().appendChild(button1);
//
baseClass : "dijitDropDownButton",
templateString: dojo.cache("dijit.form", "templates/DropDownButton.html", "▼\n"),
_fillContent: function(){
// Overrides Button._fillContent().
//
// My inner HTML contains both the button contents and a drop down widget, like
//
▼ |