// // Set up all accordions // accordion.prototype = { // // Setup the Variables // showAccordion : null, currentAccordion : null, duration : null, effects : [], animating : false, pContainer: null, pOptions: null, cookiePosition: 'closed', // // Initialize the accordions // initialize: function(container, options) { if (!$(container)) { throw(container+" doesn't exist!"); return false; } this.options = Object.extend({ resizeSpeed : 8, classNames : { toggle : 'accordion_toggle', toggleActive : 'accordion_toggle_active', content : 'accordion_content' }, defaultSize : { height : null, width : null }, direction : 'vertical', onEvent : 'click' }, options || {}); this.pContainer = container; this.pOptions = this.options; this.duration = ((11-this.options.resizeSpeed)*0.15); this.refresh(); }, refresh: function() { this.cookiePosition = this.readCookie(this.options.cookieName); if(this.cookiePosition==null) this.cookiePosition = this.createCookie(this.options.cookieName,"closed",1); var accordions = $$('#'+this.pContainer+' .'+this.pOptions.classNames.toggle); accordions.each(function(accordion) { Event.observe(accordion, this.pOptions.onEvent, this.activate.bind(this, accordion), false); if (this.pOptions.onEvent == 'click') { accordion.onclick = function() {return false;}; } /*if(this.cookiePosition=="closed") { if (this.pOptions.direction == 'horizontal') { var options = {width: '0px', display:'none'}; } else { var options = {height: '0px', display:'none'}; } this.currentAccordion = $(accordion.next(0)).setStyle(options); } else {*/ if (this.pOptions.direction == 'horizontal') { var options = {width: 'auto', display:'block'}; } else { var options = {height: 'auto', display:'block'}; } this.currentAccordion = $(accordion.next(0)).setStyle(options); this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive); // } // options.merge({display: 'none'}); }.bind(this)); }, // // Activate an accordion // activate : function(accordion) { if (this.animating) { return false; } this.effects = []; this.currentAccordion = $(accordion.next(0)); this.currentAccordion.setStyle({ display: 'block' }); this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive); if (this.options.direction == 'horizontal') { this.scaling = $H({ scaleX: true, scaleY: false }); } else { this.scaling = $H({ scaleX: false, scaleY: true }); } if (this.cookiePosition == 'open' || this.currentAccordion == this.showAccordion) { this.cookiePosition = this.createCookie(this.options.cookieName,"closed",1); this.deactivate(); } else { this.cookiePosition = this.createCookie(this.options.cookieName,"open",1); this._handleAccordion(); } }, // // Deactivate an active accordion // deactivate : function() { var options = $H({ duration: this.duration, scaleContent: false, transition: Effect.Transitions.sinoidal, queue: { position: 'end', scope: 'accordionAnimation' }, scaleMode: { originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight, originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth }, afterFinish: function() { this.showAccordion.setStyle({ height: 0, display: 'none' }); this.showAccordion = null; this.animating = false; }.bind(this) }); // options.merge(this.scaling); if(this.showAccordion==null) { this.showAccordion = this.currentAccordion; } this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive); new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject()); }, // // Handle the open/close actions of the accordion // _handleAccordion : function() { var options = $H({ sync: true, scaleFrom: 0, scaleContent: false, transition: Effect.Transitions.sinoidal, scaleMode: { originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight, originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth } }); options.merge(this.scaling); this.effects.push( new Effect.Scale(this.currentAccordion, 100, options.update(this.scaling).toObject()) ); if (this.showAccordion) { if (this.showAccordion.previous(0)) { this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive); } else { this.currentAccordion.removeClassName(this.options.classNames.toggleActive); } options = $H({ sync: true, scaleContent: false, transition: Effect.Transitions.sinoidal }); options.merge(this.scaling); this.effects.push( new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject()) ); } new Effect.Parallel(this.effects, { duration: this.duration, queue: { position: 'end', scope: 'accordionAnimation' }, beforeStart: function() { this.animating = true; }.bind(this), afterFinish: function() { if (this.showAccordion) { this.showAccordion.setStyle({ display: 'none' }); } $(this.currentAccordion).setStyle({ height: 'auto' }); this.showAccordion = this.currentAccordion; this.animating = false; }.bind(this) }); }, createCookie : function(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; return value; }, readCookie : function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } } var accordionFilter = {}; var loadAccordions = function() { accordionFilter = new accordion('vertical_container', { resizeSpeed : 7, cookieName : 'asp_shop_filter_position' }); //save accordionFilter object instance in window object (can be accessed by any block then) window.accordionFilter = accordionFilter; } // // In our case we want to load them onload // Event.observe(window, 'load', loadAccordions, false);