Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / form / Button.js @ 12

History | View | Annotate | Download (7.79 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dijit.form.Button"]){
9
dojo._hasResource["dijit.form.Button"]=true;
10
dojo.provide("dijit.form.Button");
11
dojo.require("dijit.form._FormWidget");
12
dojo.require("dijit._Container");
13
dojo.require("dijit._HasDropDown");
14
dojo.declare("dijit.form.Button",dijit.form._FormWidget,{label:"",showLabel:true,iconClass:"",type:"button",baseClass:"dijitButton",templateString:dojo.cache("dijit.form","templates/Button.html","<span class=\"dijit dijitReset dijitInline\"\n\t><span class=\"dijitReset dijitInline dijitButtonNode\"\n\t\tdojoAttachEvent=\"ondijitclick:_onButtonClick\"\n\t\t><span class=\"dijitReset dijitStretch dijitButtonContents\"\n\t\t\tdojoAttachPoint=\"titleNode,focusNode\"\n\t\t\twaiRole=\"button\" waiState=\"labelledby-${id}_label\"\n\t\t\t><span class=\"dijitReset dijitInline dijitIcon\" dojoAttachPoint=\"iconNode\"></span\n\t\t\t><span class=\"dijitReset dijitToggleButtonIconChar\">&#x25CF;</span\n\t\t\t><span class=\"dijitReset dijitInline dijitButtonText\"\n\t\t\t\tid=\"${id}_label\"\n\t\t\t\tdojoAttachPoint=\"containerNode\"\n\t\t\t></span\n\t\t></span\n\t></span\n\t><input ${!nameAttrSetting} type=\"${type}\" value=\"${value}\" class=\"dijitOffScreen\"\n\t\tdojoAttachPoint=\"valueNode\"\n/></span>\n"),attributeMap:dojo.delegate(dijit.form._FormWidget.prototype.attributeMap,{value:"valueNode",iconClass:{node:"iconNode",type:"class"}}),_onClick:function(e){
15
if(this.disabled){
16
return false;
17
}
18
this._clicked();
19
return this.onClick(e);
20
},_onButtonClick:function(e){
21
if(this._onClick(e)===false){
22
e.preventDefault();
23
}else{
24
if(this.type=="submit"&&!(this.valueNode||this.focusNode).form){
25
for(var _1=this.domNode;_1.parentNode;_1=_1.parentNode){
26
var _2=dijit.byNode(_1);
27
if(_2&&typeof _2._onSubmit=="function"){
28
_2._onSubmit(e);
29
break;
30
}
31
}
32
}else{
33
if(this.valueNode){
34
this.valueNode.click();
35
e.preventDefault();
36
}
37
}
38
}
39
},_fillContent:function(_3){
40
if(_3&&(!this.params||!("label" in this.params))){
41
this.set("label",_3.innerHTML);
42
}
43
},postCreate:function(){
44
dojo.setSelectable(this.focusNode,false);
45
this.inherited(arguments);
46
},_setShowLabelAttr:function(_4){
47
if(this.containerNode){
48
dojo.toggleClass(this.containerNode,"dijitDisplayNone",!_4);
49
}
50
this.showLabel=_4;
51
},onClick:function(e){
52
return true;
53
},_clicked:function(e){
54
},setLabel:function(_5){
55
dojo.deprecated("dijit.form.Button.setLabel() is deprecated.  Use set('label', ...) instead.","","2.0");
56
this.set("label",_5);
57
},_setLabelAttr:function(_6){
58
this.containerNode.innerHTML=this.label=_6;
59
if(this.showLabel==false&&!this.params.title){
60
this.titleNode.title=dojo.trim(this.containerNode.innerText||this.containerNode.textContent||"");
61
}
62
}});
63
dojo.declare("dijit.form.DropDownButton",[dijit.form.Button,dijit._Container,dijit._HasDropDown],{baseClass:"dijitDropDownButton",templateString:dojo.cache("dijit.form","templates/DropDownButton.html","<span class=\"dijit dijitReset dijitInline\"\n\t><span class='dijitReset dijitInline dijitButtonNode'\n\t\tdojoAttachEvent=\"ondijitclick:_onButtonClick\" dojoAttachPoint=\"_buttonNode\"\n\t\t><span class=\"dijitReset dijitStretch dijitButtonContents\"\n\t\t\tdojoAttachPoint=\"focusNode,titleNode,_arrowWrapperNode\"\n\t\t\twaiRole=\"button\" waiState=\"haspopup-true,labelledby-${id}_label\"\n\t\t\t><span class=\"dijitReset dijitInline dijitIcon\"\n\t\t\t\tdojoAttachPoint=\"iconNode\"\n\t\t\t></span\n\t\t\t><span class=\"dijitReset dijitInline dijitButtonText\"\n\t\t\t\tdojoAttachPoint=\"containerNode,_popupStateNode\"\n\t\t\t\tid=\"${id}_label\"\n\t\t\t></span\n\t\t\t><span class=\"dijitReset dijitInline dijitArrowButtonInner\"></span\n\t\t\t><span class=\"dijitReset dijitInline dijitArrowButtonChar\">&#9660;</span\n\t\t></span\n\t></span\n\t><input ${!nameAttrSetting} type=\"${type}\" value=\"${value}\" class=\"dijitOffScreen\"\n\t\tdojoAttachPoint=\"valueNode\"\n/></span>\n"),_fillContent:function(){
64
if(this.srcNodeRef){
65
var _7=dojo.query("*",this.srcNodeRef);
66
dijit.form.DropDownButton.superclass._fillContent.call(this,_7[0]);
67
this.dropDownContainer=this.srcNodeRef;
68
}
69
},startup:function(){
70
if(this._started){
71
return;
72
}
73
if(!this.dropDown){
74
var _8=dojo.query("[widgetId]",this.dropDownContainer)[0];
75
this.dropDown=dijit.byNode(_8);
76
delete this.dropDownContainer;
77
}
78
dijit.popup.moveOffScreen(this.dropDown.domNode);
79
this.inherited(arguments);
80
},isLoaded:function(){
81
var _9=this.dropDown;
82
return (!_9.href||_9.isLoaded);
83
},loadDropDown:function(){
84
var _a=this.dropDown;
85
if(!_a){
86
return;
87
}
88
if(!this.isLoaded()){
89
var _b=dojo.connect(_a,"onLoad",this,function(){
90
dojo.disconnect(_b);
91
this.openDropDown();
92
});
93
_a.refresh();
94
}else{
95
this.openDropDown();
96
}
97
},isFocusable:function(){
98
return this.inherited(arguments)&&!this._mouseDown;
99
}});
100
dojo.declare("dijit.form.ComboButton",dijit.form.DropDownButton,{templateString:dojo.cache("dijit.form","templates/ComboButton.html","<table class=\"dijit dijitReset dijitInline dijitLeft\"\n\tcellspacing='0' cellpadding='0' waiRole=\"presentation\"\n\t><tbody waiRole=\"presentation\"><tr waiRole=\"presentation\"\n\t\t><td class=\"dijitReset dijitStretch dijitButtonNode\" dojoAttachPoint=\"buttonNode\" dojoAttachEvent=\"ondijitclick:_onButtonClick,onkeypress:_onButtonKeyPress\"\n\t\t><div id=\"${id}_button\" class=\"dijitReset dijitButtonContents\"\n\t\t\tdojoAttachPoint=\"titleNode\"\n\t\t\twaiRole=\"button\" waiState=\"labelledby-${id}_label\"\n\t\t\t><div class=\"dijitReset dijitInline dijitIcon\" dojoAttachPoint=\"iconNode\" waiRole=\"presentation\"></div\n\t\t\t><div class=\"dijitReset dijitInline dijitButtonText\" id=\"${id}_label\" dojoAttachPoint=\"containerNode\" waiRole=\"presentation\"></div\n\t\t></div\n\t\t></td\n\t\t><td id=\"${id}_arrow\" class='dijitReset dijitRight dijitButtonNode dijitArrowButton'\n\t\t\tdojoAttachPoint=\"_popupStateNode,focusNode,_buttonNode\"\n\t\t\tdojoAttachEvent=\"onkeypress:_onArrowKeyPress\"\n\t\t\ttitle=\"${optionsTitle}\"\n\t\t\twaiRole=\"button\" waiState=\"haspopup-true\"\n\t\t\t><div class=\"dijitReset dijitArrowButtonInner\" waiRole=\"presentation\"></div\n\t\t\t><div class=\"dijitReset dijitArrowButtonChar\" waiRole=\"presentation\">&#9660;</div\n\t\t></td\n\t\t><td style=\"display:none !important;\"\n\t\t\t><input ${!nameAttrSetting} type=\"${type}\" value=\"${value}\" dojoAttachPoint=\"valueNode\"\n\t\t/></td></tr></tbody\n></table>\n"),attributeMap:dojo.mixin(dojo.clone(dijit.form.Button.prototype.attributeMap),{id:"",tabIndex:["focusNode","titleNode"],title:"titleNode"}),optionsTitle:"",baseClass:"dijitComboButton",cssStateNodes:{"buttonNode":"dijitButtonNode","titleNode":"dijitButtonContents","_popupStateNode":"dijitDownArrowButton"},_focusedNode:null,_onButtonKeyPress:function(_c){
101
if(_c.charOrCode==dojo.keys[this.isLeftToRight()?"RIGHT_ARROW":"LEFT_ARROW"]){
102
dijit.focus(this._popupStateNode);
103
dojo.stopEvent(_c);
104
}
105
},_onArrowKeyPress:function(_d){
106
if(_d.charOrCode==dojo.keys[this.isLeftToRight()?"LEFT_ARROW":"RIGHT_ARROW"]){
107
dijit.focus(this.titleNode);
108
dojo.stopEvent(_d);
109
}
110
},focus:function(_e){
111
dijit.focus(_e=="start"?this.titleNode:this._popupStateNode);
112
}});
113
dojo.declare("dijit.form.ToggleButton",dijit.form.Button,{baseClass:"dijitToggleButton",checked:false,attributeMap:dojo.mixin(dojo.clone(dijit.form.Button.prototype.attributeMap),{checked:"focusNode"}),_clicked:function(_f){
114
this.set("checked",!this.checked);
115
},_setCheckedAttr:function(_10,_11){
116
this.checked=_10;
117
dojo.attr(this.focusNode||this.domNode,"checked",_10);
118
dijit.setWaiState(this.focusNode||this.domNode,"pressed",_10);
119
this._handleOnChange(_10,_11);
120
},setChecked:function(_12){
121
dojo.deprecated("setChecked("+_12+") is deprecated. Use set('checked',"+_12+") instead.","","2.0");
122
this.set("checked",_12);
123
},reset:function(){
124
this._hasBeenBlurred=false;
125
this.set("checked",this.params.checked||false);
126
}});
127
}