var mooCollapsibles = new Class({ Implements:[Options], options:{ buildToggler: false, expandDefault: false, sldDuratation: 500, sldTransition: Fx.Transitions.Cubic.easeOut, accordionEffect: false }, initialize:function(options){ this.setOptions(options); if($$(this.options.cllpsContainers).length > 0){this.start();}; }, start:function(){ var myCookieSet = Cookie.write('mooCollapsibles',1,{duration:365}); var myCookieRead = Cookie.read('mooCollapsibles'); var myCookieSaved = Cookie.read('mooCollapsiblesSaved'); if(this.options.showAlerts == true){ if(myCookieRead == 1 && myCookieSaved == null){ var cookieAlert = new Element('div', { 'class': 'mooCollapsiblesAlertGreen', 'html': '<p>Your settings will be saved from now on!</p>' }).inject(this.options.cllpsContainers[0],'before'); Cookie.write('mooCollapsiblesSaved',1,{duration:365}); }else if(myCookieRead == null){ var cookieAlert = new Element('div', { 'class': 'mooCollapsiblesAlertRed', 'html': '<p>You need to enable cookies for settings to be saved!</p>' }).inject(this.options.cllpsContainers[0],'before'); }; }; this.buildCollapsibles(); }, buildCollapsibles:function(){ this.options.cllpsBodies.each(function(el,i){ var cllpsClear = new Element('div', { 'class': 'cllpsClear' }).inject(el,'bottom'); }); var cllpsArr = []; this.options.cllpsHeaders.each(function(el,i){ var cllpsSlide = new Fx.Slide(this.options.cllpsBodies[i],{ duration: this.options.sldDuratation, transition: this.options.sldTransition }); cllpsArr[i] = cllpsSlide; var myCookie = Cookie.read('expand'+i); if(myCookie == null){ if(this.options.accordionEffect == true){ if(el != this.options.cllpsHeaders.getLast()){ cllpsArr[i].hide(); Cookie.write('expand'+i,'collapsed',{duration:365}); this.options.cllpsHeaders[i].removeClass('RotateButton'); }else{ if(Cookie.read('expand'+i) != null){ if(Cookie.read('expand'+i) == 'expanded'){ cllpsArr[i].show(); this.options.cllpsHeaders[i].addClass('RotateButton'); }else{ cllpsArr[i].hide(); this.options.cllpsHeaders[i].addRemove('RotateButton'); }; }else{ cllpsArr[i].show(); Cookie.write('expand'+i,'expanded',{duration:365}); this.options.cllpsHeaders[i].addClass('RotateButton'); }; }; }else{ if(this.options.expandDefault == true){ cllpsSlide.show(); Cookie.write('expand'+i,'expanded',{duration: 365}); el.addClass.delay(this.options.sldDuratation,el,'RotateButton'); }else{ cllpsSlide.hide(); Cookie.write('expand'+i,'collapsed',{duration: 365}); el.removeClass.delay(this.options.sldDuratation,el,'RotateButton'); }; }; }else{ if(myCookie == 'expanded'){ cllpsSlide.hide(); el.removeClass.delay(this.options.sldDuratation,el,'RotateButton'); }else{ cllpsSlide.hide(); el.removeClass.delay(this.options.sldDuratation,el,'RotateButton'); }; }; var linkButton = new Element('a',{ 'href': 'JavaScript:;', 'title': 'Ouvrir/Fermer', 'class': 'OpenCloseButton', 'html': '<span class="cllpsHidden">Ouvrir/Fermer</span>', 'styles':{ opacity: 0 }, 'events':{ 'click': function(){ var myCookie = Cookie.read('expand'+i); if(this.options.accordionEffect == true){ cllpsSlide.toggle(); cllpsArr.each(function(cllps,j){ if(j != i){ cllps.slideOut(); Cookie.write('expand'+j,'collapsed',{duration:365}); this.options.cllpsHeaders[j].removeClass.delay(this.options.sldDuratation,this.options.cllpsHeaders[j],'RotateButton'); }else{ if(Cookie.read('expand'+i) == 'expanded'){ Cookie.write('expand'+j,'collapsed',{duration:365}); }else{ Cookie.write('expand'+j,'expanded',{duration:365}); }; if(this.options.cllpsHeaders[j].hasClass('RotateButton') == true){ this.options.cllpsHeaders[j].removeClass.delay(this.options.sldDuratation,this.options.cllpsHeaders[j],'RotateButton'); }else{ this.options.cllpsHeaders[j].addClass.delay(this.options.sldDuratation,this.options.cllpsHeaders[j],'RotateButton'); }; }; },this); }else{ cllpsSlide.toggle(); if(myCookie == 'expanded'){ Cookie.write('expand'+i,'collapsed',{duration:365}); el.removeClass.delay(this.options.sldDuratation,el,'RotateButton'); }else{ Cookie.write('expand'+i,'expanded',{duration:365}); el.addClass.delay(this.options.sldDuratation,el,'RotateButton'); }; }; }.bind(this) } },this); linkButton.inject(el,'inside'); linkButton.set('tween',{duration:2000,transition:Fx.Transitions.Expo.easeIn}).tween('opacity',1); },this); if(this.options.buildToggler && this.options.accordionEffect != true){ var myToggler = new Element('div', { 'href': 'javascript:;', 'class': 'mooCollapsiblesToggler', 'html': '<a href="javascript:;" title="Collapse all" id="collapse-all">collapse all</a> | <a href="javascript:;" title="Expand all" id="expand-all">expand all</a>' }).inject(this.options.cllpsContainers[0],'before'); $('collapse-all').addEvent('click', function(){ this.options.cllpsHeaders.each(function(el,i){ cllpsArr[i].slideOut(); Cookie.write('expand'+i,'collapsed',{duration:365}); el.removeClass.delay(this.options.sldDuratation,el,'RotateButton'); },this); }.bind(this)); $('expand-all').addEvent('click', function(){ this.options.cllpsHeaders.each(function(el,i){ cllpsArr[i].slideIn(); Cookie.write('expand'+i,'expanded',{duration:365}); el.addClass.delay(this.options.sldDuratation,el,'RotateButton'); },this); }.bind(this)); }; } });
