1//** Accordion Content script: By Dynamic Drive, at http://www.dynamicdrive.com 2//** Created: Jan 7th, 08' 3 4//Version 1.3: April 3rd, 08': 5//**1) Script now no longer conflicts with other JS frameworks 6//**2) Adds custom oninit() and onopenclose() event handlers that fire when Accordion Content instance has initialized, plus whenever a header is opened/closed 7//**3) Adds support for expanding header(s) using the URL parameter (ie: http://mysite.com/accordion.htm?headerclass=0,1) 8 9//April 9th, 08': Fixed "defaultexpanded" setting not working when page first loads 10 11//Version 1.4: June 4th, 08': 12//**1) Added option to activate a header "mouseover" instead of the default "click" 13//**2) Bug persistence not working when used with jquery 1.2.6 14 15//Version 1.5: June 20th, 08': 16//**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). 17//**2) Changed cookie path to site wide for persistence feature 18//**3) Fixed bug so "expandedindices" parameter in oninit(headers, expandedindices) returns empty array [] instead of [-1] when no expanded headers found 19 20//**1) Version 1.5.1: June 27th, 08': Fixed "defaultexpanded" setting not working properly when used with jquery 1.2.6 21 22//Version 1.6: Oct 3rd, 08': 23//**1) Adds new "mouseoverdelay" param that sets delay before headers are activated when "revealtype" param is set to "mouseover" 24//**2) Fixed bug with "onemustopen" param not working properly when "revealtype" is set to "click" 25 26//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. 27 28//Version 1.7.1: May 28th, 09': Fixed issue that causes margins/paddings in accordion DIVs to be lost in IE8 29 30 31var ddaccordion={ 32 33 contentclassname:{}, //object to store corresponding contentclass name based on headerclass 34 35 expandone:function(headerclass, selected){ //PUBLIC function to expand a particular header 36 this.toggleone(headerclass, selected, "expand") 37 }, 38 39 collapseone:function(headerclass, selected){ //PUBLIC function to collapse a particular header 40 this.toggleone(headerclass, selected, "collapse") 41 }, 42 43 expandall:function(headerclass){ //PUBLIC function to expand all headers based on their shared CSS classname 44 var $=jQuery 45 var $headers=$('.'+headerclass) 46 $('.'+this.contentclassname[headerclass]+':hidden').each(function(){ 47 $headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion") 48 }) 49 }, 50 51 collapseall:function(headerclass){ //PUBLIC function to collapse all headers based on their shared CSS classname 52 var $=jQuery 53 var $headers=$('.'+headerclass) 54 $('.'+this.contentclassname[headerclass]+':visible').each(function(){ 55 $headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion") 56 }) 57 }, 58 59 toggleone:function(headerclass, selected, optstate){ //PUBLIC function to expand/ collapse a particular header 60 var $=jQuery 61 var $targetHeader=$('.'+headerclass).eq(selected) 62 var $subcontent=$('.'+this.contentclassname[headerclass]).eq(selected) 63 if (typeof optstate=="undefined" || optstate=="expand" && $subcontent.is(":hidden") || optstate=="collapse" && $subcontent.is(":visible")) 64 $targetHeader.trigger("evt_accordion") 65 }, 66 67 expandit:function($targetHeader, $targetContent, config, useractivated, directclick){ 68 this.transformHeader($targetHeader, config, "expand") 69 $targetContent.slideDown(config.animatespeed, function(){ 70 config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), useractivated) 71 if (config.postreveal=="gotourl" && directclick){ //if revealtype is "Go to Header URL upon click", and this is a direct click on the header 72 var targetLink=($targetHeader.is("a"))? $targetHeader.get(0) : $targetHeader.find('a:eq(0)').get(0) 73 if (targetLink) //if this header is a link 74 setTimeout(function(){location=targetLink.href}, 200) //ignore link target, as window.open(targetLink, targetLink.target) doesn't work in FF if popup blocker enabled 75 } 76 }) 77 }, 78
79 collapseit:function($targetHeader, $targetContent, config, isuseractivated){ 80 this.transformHeader($targetHeader, config, "collapse") 81 $targetContent.slideUp(config.animatespeed, function(){config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), isuseractivated)}) 82 }, 83 84 transformHeader:function($targetHeader, config, state){ 85 $targetHeader.addClass((state=="expand")? config.cssclass.expand : config.cssclass.collapse) //alternate btw "expand" and "collapse" CSS classes 86 .removeClass((state=="expand")? config.cssclass.collapse : config.cssclass.expand) 87 if (config.htmlsetting.location=='src'){ //Change header image (assuming header is an image)? 88 $targetHeader=($targetHeader.is("img"))? $targetHeader : $targetHeader.find('img').eq(0) //Set target to either header itself, or first image within header 89 $targetHeader.attr('src', (state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) //change header image 90 } 91 else if (config.htmlsetting.location=="prefix") //if change "prefix" HTML, locate dynamically added ".accordprefix" span tag and change it 92 $targetHeader.find('.accordprefix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) 93 else if (config.htmlsetting.location=="suffix") 94 $targetHeader.find('.accordsuffix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) 95 }, 96 97 urlparamselect:function(headerclass){ 98 var result=window.location.search.match(new RegExp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for "?headerclass=2,3,4" in URL 99 if (result!=null) 100 result=RegExp.$1.split(',') 101 return result //returns null, [index], or [index1,index2,etc], where index are the desired selected header indices 102 }, 103 104 getCookie:function(Name){ 105 var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair 106 if (document.cookie.match(re)) //if cookie found 107 return document.cookie.match(re)[0].split("=")[1] //return its value 108 return null 109 }, 110 111 setCookie:function(name, value){ 112 document.cookie = name + "=" + value + "; path=/" 113 }, 114 115 init:function(config){
116 document.write('<style type="text/css">\n') 117 document.write('.'+config.contentclass+'{display: none}\n') //generate CSS to hide contents 118 document.write('<\/style>') 119 jQuery(document).ready(function($){ 120 ddaccordion.urlparamselect(config.headerclass) 121 var persistedheaders=ddaccordion.getCookie(config.headerclass) 122 ddaccordion.contentclassname[config.headerclass]=config.contentclass //remember contentclass name based on headerclass 123 config.cssclass={collapse: config.toggleclass[0], expand: config.toggleclass[1]} //store expand and contract CSS classes as object properties 124 config.revealtype=config.revealtype || "click" 125 config.revealtype=config.revealtype.replace(/mouseover/i, "mouseenter") 126 if (config.revealtype=="clickgo"){ 127 config.postreveal="gotourl" //remember added action 128 config.revealtype="click" //overwrite revealtype to "click" keyword 129 } 130 if (typeof config.togglehtml=="undefined") 131 config.htmlsetting={location: "none"} 132 else 133 config.htmlsetting={location: config.togglehtml[0], collapse: config.togglehtml[1], expand: config.togglehtml[2]} //store HTML settings as object properties 134 config.oninit=(typeof config.oninit=="undefined")? function(){} : config.oninit //attach custom "oninit" event handler 135 config.onopenclose=(typeof config.onopenclose=="undefined")? function(){} : config.onopenclose //attach custom "onopenclose" event handler 136 var lastexpanded={} //object to hold reference to last expanded header and content (jquery objects) 137 var expandedindices=ddaccordion.urlparamselect(config.headerclass) || ((config.persiststate && persistedheaders!=null)? persistedheaders : config.defaultexpanded) 138 if (typeof expandedindices=='string') //test for string value (exception is config.defaultexpanded, which is an array) 139 expandedindices=expandedindices.replace(/c/ig, '').split(',') //transform string value to an array (ie: "c1,c2,c3" becomes [1,2,3] 140 var $subcontents=$('.'+config["contentclass"]) 141 if (expandedindices.length==1 && expandedindices[0]=="-1") //check for expandedindices value of [-1], indicating persistence is on and no content expanded 142 expandedindices=[] 143 if (config["collapseprev"] && expandedindices.length>1) //only allow one content open? 144 expandedindices=[expandedindices.pop()] //return last array element as an array (for sake of jQuery.inArray()) 145 if (config["onemustopen"] && expandedindices.length==0) //if at least one content should be open at all times and none are, open 1st header 146 expandedindices=[0] 147 $('.'+config["headerclass"]).each(function(index){ //loop through all headers 148 if (/(prefix)|(suffix)/i.test(config.htmlsetting.location) && $(this).html()!=""){ //add a SPAN element to header depending on user setting and if header is a container tag 149 $('<span class="accordprefix"></span>').prependTo(this) 150 $('<span class="accordsuffix"></span>').appendTo(this) 151 } 152 $(this).attr('headerindex', index+'h') //store position of this header relative to its peers 153 $subcontents.eq(index).attr('contentindex', index+'c') //store position of this content relative to its peers 154 var $subcontent=$subcontents.eq(index) 155 var needle=(typeof expandedindices[0]=="number")? index : index+'' //check for data type within expandedindices array- index should match that type 156 if (jQuery.inArray(needle, expandedindices)!=-1){ //check for headers that should be expanded automatically (convert index to string first) 157 if (config.animatedefault==false) 158 $subcontent.show() 159 ddaccordion.expandit($(this), $subcontent, config, false) //Last param sets 'isuseractivated' parameter 160 lastexpanded={$header:$(this), $content:$subcontent} 161 } //end check 162 else{ 163 $subcontent.hide() 164 config.onopenclose($(this).get(0), parseInt($(this).attr('headerindex')), $subcontent.css('display'), false) //Last Boolean value sets 'isuseractivated' parameter 165 ddaccordion.transformHeader($(this), config, "collapse") 166 } 167 }) 168 $('.'+config["headerclass"]).bind("evt_accordion", function(e, isdirectclick){ //assign custom event handler that expands/ contacts a header 169 var $subcontent=$subcontents.eq(parseInt($(this).attr('headerindex'))) //get subcontent that should be expanded/collapsed 170 if ($subcontent.css('display')=="none"){ 171 ddaccordion.expandit($(this), $subcontent, config, true, isdirectclick) //2nd last param sets 'isuseractivated' parameter 172 if (config["collapseprev"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){ //collapse previous content? 173 ddaccordion.collapseit(lastexpanded.$header, lastexpanded.$content, config, true) //Last Boolean value sets 'isuseractivated' parameter 174 } 175 lastexpanded={$header:$(this), $content:$subcontent} 176 } 177 else if (!config["onemustopen"] || config["onemustopen"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){ 178 ddaccordion.collapseit($(this), $subcontent, config, true) //Last Boolean value sets 'isuseractivated' parameter 179 } 180 }) 181 $('.'+config["headerclass"]).bind(config.revealtype, function(){ 182 if (config.revealtype=="mouseenter"){ 183 clearTimeout(config.revealdelay) 184 var headerindex=parseInt($(this).attr("headerindex")) 185 config.revealdelay=setTimeout(function(){ddaccordion.expandone(config["headerclass"], headerindex)}, config.mouseoverdelay || 0) 186 } 187 else{ 188 $(this).trigger("evt_accordion", [true]) 189 return false //cancel default click behavior 190 } 191 }) 192 $('.'+config["headerclass"]).bind("mouseleave", function(){ 193 clearTimeout(config.revealdelay) 194 }) 195 config.oninit($('.'+config["headerclass"]).get(), expandedindices) 196 $(window).bind('unload', function(){ //clean up and persist on page unload 197 $('.'+config["headerclass"]).unbind() 198 var expandedindices=[] 199 $('.'+config["contentclass"]+":visible").each(function(index){ //get indices of expanded headers 200 expandedindices.push($(this).attr('contentindex')) 201 }) 202 if (config.persiststate==true && $('.'+config["headerclass"]).length>0){ //persist state? 203 expandedindices=(expandedindices.length==0)? '-1c' : expandedindices //No contents expanded, indicate that with dummy '-1c' value? 204 ddaccordion.setCookie(config.headerclass, expandedindices) 205 } 206 }) 207 }) 208 } 209} 210 211//Order now ddaccordion 212//Initialize first demo: 213ddaccordion.init({
214 headerclass: "mypets", //Shared CSS class name of headers group 215 contentclass: "thepet", //Shared CSS class name of contents group 216 revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover" 217 mouseoverdelay: 900, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover 218 collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 219 defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content. 220 onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed) 221 animatedefault: false, //Should contents open by default be animated into view? 222 persiststate: true, //persist state of opened contents within browser session? 223 toggleclass: ["", "openpet1"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"] 224 togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs) 225 animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "fast" 226 oninit:function(expandedindices){ //custom code to run when headers have initalized 227 //do nothing 228 }, 229 onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed 230 //do nothing 231 } 232}) 233//Initialize 2nd demo: 234ddaccordion.init({ 235 headerclass: "technology1", //Shared CSS class name of headers group 236 contentclass: "thelanguage1", //Shared CSS class name of contents group 237 revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover" 238 mouseoverdelay: 900, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover 239 collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 240 defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content. 241 onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed) 242 animatedefault: false, //Should contents open by default be animated into view? 243 persiststate: true, //persist state of opened contents within browser session? 244 toggleclass: ["", "openpet1"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"] 245 togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs) 246 animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "fast" 247 oninit:function(expandedindices){ //custom code to run when headers have initalized 248 //do nothing 249 }, 250 onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed 251 //do nothing 252 } 253})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.