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
|
/* Simple Accordion Script
* Requires Prototype and Script.aculo.us Libraries
* By: Brian Crescimanno <brian.crescimanno@gmail.com>
* http://briancrescimanno.com
* Adapted to Prado & minor improvements: Gabor Berczi <gabor.berczi@devworx.hu>
* This work is licensed under the Creative Commons Attribution-Share Alike 3.0
* http://creativecommons.org/licenses/by-sa/3.0/us/
*/
Prado.WebUI.TAccordion = Class.create();
Prado.WebUI.TAccordion.prototype =
{
initialize : function(options)
{
this.element = $(options.ID);
this.onInit(options);
Prado.Registry.set(options.ID, this);
},
onInit : function(options)
{
this.accordion = $(options.ID);
this.options = options;
this.hiddenField = $(options.ID+'_1');
if (this.options.maxHeight)
{
this.maxHeight = this.options.maxHeight;
} else {
this.maxHeight = 0;
this.checkMaxHeight();
}
this.currentView = null;
this.oldView = null;
var i = 0;
for(var view in this.options.Views)
{
var header = $(view+'_0');
if(header)
{
Event.stopObserving(header, "click");
Event.observe(header, "click", this.elementClicked.bindEvent(this,view));
if(this.hiddenField.value == i)
{
this.currentView = view;
if($(this.currentView).getHeight() != this.maxHeight)
$(this.currentView).setStyle({height: this.maxHeight+"px"});
}
}
i++;
}
},
checkMaxHeight: function()
{
for(var viewID in this.options.Views)
{
var view = $(viewID);
if(view.getHeight() > this.maxHeight)
this.maxHeight = view.getHeight();
}
},
elementClicked : function(event,viewID)
{
var i = 0;
for(var index in this.options.Views)
{
if ($(index))
{
var header = $(index+'_0');
if(index == viewID)
{
this.oldView = this.currentView;
this.currentView = index;
this.hiddenField.value=i;
}
}
i++;
}
if(this.oldView != this.currentView)
{
if(this.options.Duration > 0)
{
this.animate();
} else {
$(this.currentView).setStyle({ height: this.maxHeight+"px" });
$(this.currentView).show();
$(this.oldView).hide();
var oldHeader = $(this.oldView+'_0');
var currentHeader = $(this.currentView+'_0');
oldHeader.className=this.options.HeaderCssClass;
currentHeader.className=this.options.ActiveHeaderCssClass;
}
}
},
animate: function() {
var effects = new Array();
var options = {
sync: true,
scaleFrom: 0,
scaleContent: false,
transition: Effect.Transitions.sinoidal,
scaleMode: {
originalHeight: this.maxHeight,
originalWidth: this.accordion.getWidth()
},
scaleX: false,
scaleY: true
};
effects.push(new Effect.Scale(this.currentView, 100, options));
options = {
sync: true,
scaleContent: false,
transition: Effect.Transitions.sinoidal,
scaleX: false,
scaleY: true
};
effects.push(new Effect.Scale(this.oldView, 0, options));
var oldHeader = $(this.oldView+'_0');
var currentHeader = $(this.currentView+'_0');
new Effect.Parallel(effects, {
duration: this.options.Duration,
fps: 35,
queue: {
position: 'end',
scope: 'accordion'
},
beforeStart: function() {
$(this.currentView).setStyle({ height: "0px" });
$(this.currentView).show();
oldHeader.className=this.options.HeaderCssClass;
currentHeader.className=this.options.ActiveHeaderCssClass;
}.bind(this),
afterFinish: function() {
$(this.oldView).hide();
$(this.currentView).setStyle({ height: this.maxHeight+"px" });
}.bind(this)
});
}
};
|