//** accordion content script: by dynamic drive, at http://www.dynamicdrive.com //** created: jan 7th, 08' //version 1.3: april 3rd, 08': //**1) script now no longer conflicts with other js frameworks //**2) adds custom oninit() and onopenclose() event handlers that fire when accordion content instance has initialized, plus whenever a header is opened/closed //**3) adds support for expanding header(s) using the url parameter (ie: http://mysite.com/accordion.htm?headerclass=0,1) //april 9th, 08': fixed "defaultexpanded" setting not working when page first loads //version 1.4: june 4th, 08': //**1) added option to activate a header "mouseover" instead of the default "click" //**2) bug persistence not working when used with jquery 1.2.6 //version 1.5: june 20th, 08': //**1) adds new "onemustopen:true/false" parameter, which lets you set whether at least one header should be open at all times (so never all closed). //**2) changed cookie path to site wide for persistence feature //**3) fixed bug so "expandedindices" parameter in oninit(headers, expandedindices) returns empty array [] instead of [-1] when no expanded headers found //**1) version 1.5.1: june 27th, 08': fixed "defaultexpanded" setting not working properly when used with jquery 1.2.6 //version 1.6: oct 3rd, 08': //**1) adds new "mouseoverdelay" param that sets delay before headers are activated when "revealtype" param is set to "mouseover" //**2) fixed bug with "onemustopen" param not working properly when "revealtype" is set to "click" //version 1.7: march 24th, 09': adds a 3rd revealtype setting "clickgo", which causes browser to navigate to url specified inside the header after expanding its contents. //version 1.7.1: may 28th, 09': fixed issue that causes margins/paddings in accordion divs to be lost in ie8 var ddaccordion={ contentclassname:{}, //object to store corresponding contentclass name based on headerclass expandone:function(headerclass, selected){ //public function to expand a particular header this.toggleone(headerclass, selected, "expand") }, collapseone:function(headerclass, selected){ //public function to collapse a particular header this.toggleone(headerclass, selected, "collapse") }, expandall:function(headerclass){ //public function to expand all headers based on their shared css classname var $=jquery var $headers=$('.'+headerclass) $('.'+this.contentclassname[headerclass]+':hidden').each(function(){ $headers.eq(parseint($(this).attr('contentindex'))).trigger("evt_accordion") }) }, collapseall:function(headerclass){ //public function to collapse all headers based on their shared css classname var $=jquery var $headers=$('.'+headerclass) $('.'+this.contentclassname[headerclass]+':visible').each(function(){ $headers.eq(parseint($(this).attr('contentindex'))).trigger("evt_accordion") }) }, toggleone:function(headerclass, selected, optstate){ //public function to expand/ collapse a particular header var $=jquery var $targetheader=$('.'+headerclass).eq(selected) var $subcontent=$('.'+this.contentclassname[headerclass]).eq(selected) if (typeof optstate=="undefined" || optstate=="expand" && $subcontent.is(":hidden") || optstate=="collapse" && $subcontent.is(":visible")) $targetheader.trigger("evt_accordion") }, expandit:function($targetheader, $targetcontent, config, useractivated, directclick){ this.transformheader($targetheader, config, "expand") $targetcontent.slidedown(config.animatespeed, function(){ config.onopenclose($targetheader.get(0), parseint($targetheader.attr('headerindex')), $targetcontent.css('display'), useractivated) if (config.postreveal=="gotourl" && directclick){ //if revealtype is "go to header url upon click", and this is a direct click on the header var targetlink=($targetheader.is("a"))? $targetheader.get(0) : $targetheader.find('a:eq(0)').get(0) if (targetlink) //if this header is a link settimeout(function(){location=targetlink.href}, 200) //ignore link target, as window.open(targetlink, targetlink.target) doesn't work in ff if popup blocker enabled } }) }, collapseit:function($targetheader, $targetcontent, config, isuseractivated){ this.transformheader($targetheader, config, "collapse") $targetcontent.slideup(config.animatespeed, function(){config.onopenclose($targetheader.get(0), parseint($targetheader.attr('headerindex')), $targetcontent.css('display'), isuseractivated)}) }, transformheader:function($targetheader, config, state){ $targetheader.addclass((state=="expand")? config.cssclass.expand : config.cssclass.collapse) //alternate btw "expand" and "collapse" css classes .removeclass((state=="expand")? config.cssclass.collapse : config.cssclass.expand) if (config.htmlsetting.location=='src'){ //change header image (assuming header is an image)? $targetheader=($targetheader.is("img"))? $targetheader : $targetheader.find('img').eq(0) //set target to either header itself, or first image within header $targetheader.attr('src', (state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) //change header image } else if (config.htmlsetting.location=="prefix") //if change "prefix" html, locate dynamically added ".accordprefix" span tag and change it $targetheader.find('.accordprefix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) else if (config.htmlsetting.location=="suffix") $targetheader.find('.accordsuffix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) }, urlparamselect:function(headerclass){ var result=window.location.search.match(new regexp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for "?headerclass=2,3,4" in url if (result!=null) result=regexp.$1.split(',') return result //returns null, [index], or [index1,index2,etc], where index are the desired selected header indices }, getcookie:function(name){ var re=new regexp(name+"=[^;]+", "i") //construct re to search for target name/value pair if (document.cookie.match(re)) //if cookie found return document.cookie.match(re)[0].split("=")[1] //return its value return null }, setcookie:function(name, value){ document.cookie = name + "=" + value + "; path=/" }, init:function(config){ document.write('