Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / layout / StackController.js @ 9

History | View | Annotate | Download (5.04 KB)

1
/*
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.layout.StackController"]){
9
dojo._hasResource["dijit.layout.StackController"]=true;
10
dojo.provide("dijit.layout.StackController");
11
dojo.require("dijit._Widget");
12
dojo.require("dijit._Templated");
13
dojo.require("dijit._Container");
14
dojo.require("dijit.form.ToggleButton");
15
dojo.requireLocalization("dijit","common",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
16
dojo.declare("dijit.layout.StackController",[dijit._Widget,dijit._Templated,dijit._Container],{templateString:"<span wairole='tablist' dojoAttachEvent='onkeypress' class='dijitStackController'></span>",containerId:"",buttonWidget:"dijit.layout._StackButton",postCreate:function(){
17
dijit.setWaiRole(this.domNode,"tablist");
18
this.pane2button={};
19
this.pane2handles={};
20
this.subscribe(this.containerId+"-startup","onStartup");
21
this.subscribe(this.containerId+"-addChild","onAddChild");
22
this.subscribe(this.containerId+"-removeChild","onRemoveChild");
23
this.subscribe(this.containerId+"-selectChild","onSelectChild");
24
this.subscribe(this.containerId+"-containerKeyPress","onContainerKeyPress");
25
},onStartup:function(_1){
26
dojo.forEach(_1.children,this.onAddChild,this);
27
if(_1.selected){
28
this.onSelectChild(_1.selected);
29
}
30
},destroy:function(){
31
for(var _2 in this.pane2button){
32
this.onRemoveChild(dijit.byId(_2));
33
}
34
this.inherited(arguments);
35
},onAddChild:function(_3,_4){
36
var _5=dojo.getObject(this.buttonWidget);
37
var _6=new _5({id:this.id+"_"+_3.id,label:_3.title,dir:_3.dir,lang:_3.lang,showLabel:_3.showTitle,iconClass:_3.iconClass,closeButton:_3.closable,title:_3.tooltip});
38
dijit.setWaiState(_6.focusNode,"selected","false");
39
this.pane2handles[_3.id]=[this.connect(_3,"set",function(_7,_8){
40
var _9={title:"label",showTitle:"showLabel",iconClass:"iconClass",closable:"closeButton",tooltip:"title"}[_7];
41
if(_9){
42
_6.set(_9,_8);
43
}
44
}),this.connect(_6,"onClick",dojo.hitch(this,"onButtonClick",_3)),this.connect(_6,"onClickCloseButton",dojo.hitch(this,"onCloseButtonClick",_3))];
45
this.addChild(_6,_4);
46
this.pane2button[_3.id]=_6;
47
_3.controlButton=_6;
48
if(!this._currentChild){
49
_6.focusNode.setAttribute("tabIndex","0");
50
dijit.setWaiState(_6.focusNode,"selected","true");
51
this._currentChild=_3;
52
}
53
if(!this.isLeftToRight()&&dojo.isIE&&this._rectifyRtlTabList){
54
this._rectifyRtlTabList();
55
}
56
},onRemoveChild:function(_a){
57
if(this._currentChild===_a){
58
this._currentChild=null;
59
}
60
dojo.forEach(this.pane2handles[_a.id],this.disconnect,this);
61
delete this.pane2handles[_a.id];
62
var _b=this.pane2button[_a.id];
63
if(_b){
64
this.removeChild(_b);
65
delete this.pane2button[_a.id];
66
_b.destroy();
67
}
68
delete _a.controlButton;
69
},onSelectChild:function(_c){
70
if(!_c){
71
return;
72
}
73
if(this._currentChild){
74
var _d=this.pane2button[this._currentChild.id];
75
_d.set("checked",false);
76
dijit.setWaiState(_d.focusNode,"selected","false");
77
_d.focusNode.setAttribute("tabIndex","-1");
78
}
79
var _e=this.pane2button[_c.id];
80
_e.set("checked",true);
81
dijit.setWaiState(_e.focusNode,"selected","true");
82
this._currentChild=_c;
83
_e.focusNode.setAttribute("tabIndex","0");
84
var _f=dijit.byId(this.containerId);
85
dijit.setWaiState(_f.containerNode,"labelledby",_e.id);
86
},onButtonClick:function(_10){
87
var _11=dijit.byId(this.containerId);
88
_11.selectChild(_10);
89
},onCloseButtonClick:function(_12){
90
var _13=dijit.byId(this.containerId);
91
_13.closeChild(_12);
92
if(this._currentChild){
93
var b=this.pane2button[this._currentChild.id];
94
if(b){
95
dijit.focus(b.focusNode||b.domNode);
96
}
97
}
98
},adjacent:function(_14){
99
if(!this.isLeftToRight()&&(!this.tabPosition||/top|bottom/.test(this.tabPosition))){
100
_14=!_14;
101
}
102
var _15=this.getChildren();
103
var _16=dojo.indexOf(_15,this.pane2button[this._currentChild.id]);
104
var _17=_14?1:_15.length-1;
105
return _15[(_16+_17)%_15.length];
106
},onkeypress:function(e){
107
if(this.disabled||e.altKey){
108
return;
109
}
110
var _18=null;
111
if(e.ctrlKey||!e._djpage){
112
var k=dojo.keys;
113
switch(e.charOrCode){
114
case k.LEFT_ARROW:
115
case k.UP_ARROW:
116
if(!e._djpage){
117
_18=false;
118
}
119
break;
120
case k.PAGE_UP:
121
if(e.ctrlKey){
122
_18=false;
123
}
124
break;
125
case k.RIGHT_ARROW:
126
case k.DOWN_ARROW:
127
if(!e._djpage){
128
_18=true;
129
}
130
break;
131
case k.PAGE_DOWN:
132
if(e.ctrlKey){
133
_18=true;
134
}
135
break;
136
case k.DELETE:
137
if(this._currentChild.closable){
138
this.onCloseButtonClick(this._currentChild);
139
}
140
dojo.stopEvent(e);
141
break;
142
default:
143
if(e.ctrlKey){
144
if(e.charOrCode===k.TAB){
145
this.adjacent(!e.shiftKey).onClick();
146
dojo.stopEvent(e);
147
}else{
148
if(e.charOrCode=="w"){
149
if(this._currentChild.closable){
150
this.onCloseButtonClick(this._currentChild);
151
}
152
dojo.stopEvent(e);
153
}
154
}
155
}
156
}
157
if(_18!==null){
158
this.adjacent(_18).onClick();
159
dojo.stopEvent(e);
160
}
161
}
162
},onContainerKeyPress:function(_19){
163
_19.e._djpage=_19.page;
164
this.onkeypress(_19.e);
165
}});
166
dojo.declare("dijit.layout._StackButton",dijit.form.ToggleButton,{tabIndex:"-1",postCreate:function(evt){
167
dijit.setWaiRole((this.focusNode||this.domNode),"tab");
168
this.inherited(arguments);
169
},onClick:function(evt){
170
dijit.focus(this.focusNode);
171
},onClickCloseButton:function(evt){
172
evt.stopPropagation();
173
}});
174
}