1 /* Simple Accordion Script
2 * Requires Prototype and Script.aculo.us Libraries
3 * By: Brian Crescimanno <brian.crescimanno@gmail.com>
4 * http://briancrescimanno.com
5 * Adapted to Prado & minor improvements: Gabor Berczi <gabor.berczi@devworx.hu>
6 * This work is licensed under the Creative Commons Attribution-Share Alike 3.0
7 * http://creativecommons.org/licenses/by-sa/3.0/us/
10 Prado.WebUI.TAccordion = Class.create(Prado.WebUI.Control,
12 onInit : function(options)
14 this.accordion = $(options.ID);
15 this.options = options;
16 this.hiddenField = $(options.ID+'_1');
18 if (this.options.maxHeight)
20 this.maxHeight = this.options.maxHeight;
23 this.checkMaxHeight();
26 this.currentView = null;
30 for(var view in this.options.Views)
32 var header = $(view+'_0');
35 this.observe(header, "click", this.elementClicked.bindEvent(this,view));
36 if(this.hiddenField.value == i)
38 this.currentView = view;
39 if($(this.currentView).getHeight() != this.maxHeight)
40 $(this.currentView).setStyle({height: this.maxHeight+"px"});
47 checkMaxHeight: function()
49 for(var viewID in this.options.Views)
52 if(view.getHeight() > this.maxHeight)
53 this.maxHeight = view.getHeight();
57 elementClicked : function(event,viewID)
59 // dummy effect to force processing of click into the event queue
60 // is not actually supposed to change the appearance of the accordion
65 from: 1.0, to: 1.0, duration: 0.0,
70 afterFinish: function() { obj.processElementClick(event, viewID); }
75 processElementClick : function(event,viewID)
78 for(var index in this.options.Views)
82 var header = $(index+'_0');
85 this.oldView = this.currentView;
86 this.currentView = index;
88 this.hiddenField.value=i;
93 if(this.oldView != this.currentView)
95 if(this.options.Duration > 0)
99 $(this.currentView).setStyle({ height: this.maxHeight+"px" });
100 $(this.currentView).show();
101 $(this.oldView).hide();
103 var oldHeader = $(this.oldView+'_0');
104 var currentHeader = $(this.currentView+'_0');
105 oldHeader.className=this.options.HeaderCssClass;
106 currentHeader.className=this.options.ActiveHeaderCssClass;
111 animate: function() {
112 var effects = new Array();
121 transition: Effect.Transitions.sinoidal,
123 originalHeight: this.maxHeight,
124 originalWidth: this.accordion.getWidth()
130 effects.push(new Effect.Scale(this.currentView, 100, options));
139 transition: Effect.Transitions.sinoidal,
144 effects.push(new Effect.Scale(this.oldView, 0, options));
146 var oldHeader = $(this.oldView+'_0');
147 var currentHeader = $(this.currentView+'_0');
149 new Effect.Parallel(effects, {
150 duration: this.options.Duration,
156 beforeStart: function() {
157 $(this.currentView).setStyle({ height: "0px" });
158 $(this.currentView).show();
160 oldHeader.className=this.options.HeaderCssClass;
161 currentHeader.className=this.options.ActiveHeaderCssClass;
163 afterFinish: function() {
164 $(this.oldView).hide();
165 $(this.currentView).setStyle({ height: this.maxHeight+"px" });