Accordion_wev8.js
5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
Copyright (c) 2004-2005, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.widget.Accordion");
//
// TODO
// make it prettier
// active dragging upwards doesn't always shift other bars (direction calculation is wrong in this case)
//
// pull in widget infrastructure
dojo.require("dojo.widget.*");
// pull in our superclass
dojo.require("dojo.widget.SplitPane");
// pull in animation libraries
dojo.require("dojo.animation.Animation");
dojo.widget.Accordion = function(){
dojo.widget.html.SplitPane.call(this);
this.widgetType = "Accordion";
this._super = dojo.widget.AccordionPanel.superclass;
dojo.event.connect(this, "postCreate", this, "myPostCreate");
}
dojo.inherits(dojo.widget.Accordion, dojo.widget.html.SplitPane);
dojo.lang.extend(dojo.widget.Accordion, {
sizerWidth: 1,
activeSizing: 1,
animationInterval: 250,
openPanel: null,
myPostCreate: function(args, frag){
for(var i=0; i<this.sizers.length; i++){
var sn = this.sizers[i];
if(sn){
sn.style.border = "0px";
}
}
for(var i=0; i<this.children.length; i++){
this.children[i].setMinHeight();
if(this.children[i].open){
this.openPanel = this.children[i];
}
}
this.onResized();
},
setOpenPanel: function(panel){
if(!panel){ return; }
if(!this.openPanel){
this.openPanel = panel;
panel.open = true;
}else if(panel === this.openPanel){
// no-op
}else{
var closingPanel = this.openPanel;
var openingPanel = panel;
this.openPanel.sizeShare = 0;
this.openPanel.open = false;
this.openPanel.setMinHeight(true);
this.openPanel = panel;
this.openPanel.sizeShare = 100;
this.openPanel.open = true;
this.onResized();
// Don't animate if there is no interval
if (this.animationInterval == 0){
openingPanel.sizeShare = 100;
closingPanel.sizeShare = 0;
e.animation.accordion.onResized();
}else{
var line = new dojo.math.curves.Line([0,0], [0,100]);
var anim = new dojo.animation.Animation(
line,
this.animationInterval,
new dojo.math.curves.Bezier([[0],[0.05],[0.1],[0.9],[0.95],[1]])
);
var accordion = this;
anim.handler = function(e) {
switch(e.type) {
case "animate":
openingPanel.sizeShare = parseInt(e.y);
closingPanel.sizeShare = parseInt(100 - e.y);
accordion.onResized();
break;
case "end":
break;
}
}
anim.play();
}
}
}
});
dojo.widget.tags.addParseTreeHandler("dojo:Accordion");
dojo.widget.AccordionPanel = function(){
dojo.widget.html.SplitPanePanel.call(this);
this.widgetType = "AccordionPanel";
dojo.event.connect(this, "fillInTemplate", this, "myFillInTemplate");
dojo.event.connect(this, "postCreate", this, "myPostCreate");
}
dojo.inherits(dojo.widget.AccordionPanel, dojo.widget.html.SplitPanePanel);
dojo.lang.extend(dojo.widget.AccordionPanel, {
sizeMin:0,
initialSizeMin: null,
sizeShare: 0,
open: false,
label: "",
initialContent: "",
labelNode: null,
scrollContent: true,
initalContentNode: null,
contentNode: null,
templatePath: dojo.uri.dojoUri("src/widget/templates/AccordionPanel.html"),
templateCssPath: dojo.uri.dojoUri("src/widget/templates/AccordionPanel_wev8.css"),
setMinHeight: function(ignoreIC){
// now handle our setup
var lh = dojo.style.getContentHeight(this.labelNode);
if(!ignoreIC){
lh += dojo.style.getContentHeight(this.initialContentNode);
this.initialSizeMin = lh;
}
this.sizeMin = lh;
},
myFillInTemplate: function(args, frag){
var sn;
if(this.label.length > 0){
this.labelNode.innerHTML = this.label;
}else{
try{
sn = frag["dojo:label"][0]["dojo:label"].nodeRef;
while(sn.firstChild){
this.labelNode.firstChild.appendChild(sn.firstChild);
}
}catch(e){ }
}
if(this.initialContent.length > 0){
this.initialContentNode.innerHTML = this.initialContent;
}else{
try{
sn = frag["dojo:initialcontent"][0]["dojo:initialcontent"].nodeRef;
while(sn.firstChild){
this.initialContentNode.firstChild.appendChild(sn.firstChild);
}
}catch(e){ }
}
sn = frag["dojo:"+this.widgetType.toLowerCase()]["nodeRef"];
while(sn.firstChild){
this.contentNode.appendChild(sn.firstChild);
}
if(this.open){
this.sizeShare = 100;
}
},
myPostCreate: function(){
// this.domNode.style.overflow = "auto";
// this.domNode.style.position = "relative";
},
sizeSet: function(size){
if(!this.scrollContent){
return;
}
if(size <= this.sizeMin){
this.contentNode.style.display = "none";
}else{
// this.domNode.style.overflow = "hidden";
this.contentNode.style.display = "block";
this.contentNode.style.overflow = "auto";
var scrollSize = (size-((this.initialSizeMin) ? this.initialSizeMin : this.sizeMin));
if(dojo.render.html.ie){
this.contentNode.style.height = scrollSize+"px";
}else{
dojo.style.setOuterHeight(this.contentNode, scrollSize);
}
}
},
toggleOpen: function(evt){
this.parent.setOpenPanel(this);
}
});
dojo.widget.tags.addParseTreeHandler("dojo:AccordionPanel");