1//** Accordion Content script: By Dynamic Drive, at http://www.dynamicdrive.com 2//** Created: Jan 7th, 08'. Last updated: Aug 28th, 2018' to v2.2 3 4//Version 1.9: June 7th, 2010': 5//**1) Ajax content support added, so a given header's content can be dynamically fetched from an external file and on demand. 6//**2) Optimized script performance by caching header and content container references 7 8//Version 2.1: Feb 16th, 2012': 9//** 1) Added option ("scrolltoheader") to scroll to the expanded header in question after it expands (useful if a header contains long content). 10 11//Version 2.2: Aug 28th, 2018': 12//** 1) Added option "scrolltocontent" to scroll to the expanded content in question after it expands, which is useful if the content is in a different area of the page relative to the header. 13 14var ddaccordion={ 15 ajaxloadingmsg: '<img src="loading2.gif" /><br />Loading Content...', //customize HTML to output while Ajax content is being fetched (if applicable) 16 17 headergroup: {}, //object to store corresponding header group based on headerclass value 18 contentgroup: {}, //object to store corresponding content group based on headerclass value 19 20 preloadimages:function($images){ 21 $images.each(function(){ 22 var preloadimage=new Image() 23 preloadimage.src=this.src 24 }) 25 }, 26 27 expandone:function(headerclass, selected, scrolltoheader){ //PUBLIC function to expand a particular header 28 this.toggleone(headerclass, selected, "expand", scrolltoheader) 29 }, 30 31 collapseone:function(headerclass, selected){ //PUBLIC function to collapse a particular header 32 this.toggleone(headerclass, selected, "collapse") 33 }, 34 35 expandall:function(headerclass){ //PUBLIC function to expand all headers based on their shared CSS classname 36 var $headers=this.headergroup[headerclass] 37 this.contentgroup[headerclass].filter(':hidden').each(function(){ 38 $headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion") 39 }) 40 }, 41 42 collapseall:function(headerclass){ //PUBLIC function to collapse all headers based on their shared CSS classname 43 var $headers=this.headergroup[headerclass] 44 this.contentgroup[headerclass].filter(':visible').each(function(){ 45 $headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion") 46 }) 47 }, 48 49 toggleone:function(headerclass, selected, optstate, scrolltoheader){ //PUBLIC function to expand/ collapse a particular header 50 var $targetHeader=this.headergroup[headerclass].eq(selected) 51 var $subcontent=this.contentgroup[headerclass].eq(selected) 52 if (typeof optstate=="undefined" || optstate=="expand" && $subcontent.is(":hidden") || optstate=="collapse" && $subcontent.is(":visible")) 53 $targetHeader.trigger("evt_accordion", [false, scrolltoheader]) 54 }, 55 56 ajaxloadcontent:function($targetHeader, $targetContent, config, callback){ 57 var ajaxinfo=$targetHeader.data('ajaxinfo') 58 59 function handlecontent(content){ //nested function 60 if (content){ //if ajax content has loaded
61 ajaxinfo.cacheddata=content //remember ajax content 62 ajaxinfo.status="cached" //set ajax status to cached 63 if ($targetContent.queue("fx").length==0){ //if this content isn't currently expanding or collapsing 64 $targetContent.hide().html(content) //hide loading message, then set sub content's HTML to ajax content 65 ajaxinfo.status="complete" //set ajax status to complete 66 callback() //execute callback function- expand this sub content 67 } 68 } 69 if (ajaxinfo.status!="complete"){ 70 setTimeout(function(){handlecontent(ajaxinfo.cacheddata)}, 100) //call handlecontent() again until ajax content has loaded (ajaxinfo.cacheddata contains data) 71 } 72 } //end nested function 73 74 if (ajaxinfo.status=="none"){ //ajax data hasn't been fetched yet 75 $targetContent.html(this.ajaxloadingmsg) 76 $targetContent.slideDown(config.animatespeed) 77 ajaxinfo.status="loading" //set ajax status to "loading" 78 $.ajax({ 79 url: ajaxinfo.url, //path to external menu file 80 error:function(ajaxrequest){ 81 handlecontent('Error fetching content. Server Response: '+ajaxrequest.responseText) 82 }, 83 success:function(content){ 84 content=(content=="")? " " : content //if returned content is empty, set it to "space" is content no longer returns false/empty (hasn't loaded yet) 85 handlecontent(content) 86 } 87 }) 88 } 89 else if (ajaxinfo.status=="loading") 90 handlecontent(ajaxinfo.cacheddata) 91 }, 92 93 expandit:function($targetHeader, $targetContent, config, useractivated, directclick, skipanimation, scrolltoheader){ 94 var ajaxinfo=$targetHeader.data('ajaxinfo') 95 if (ajaxinfo){ //if this content should be fetched via Ajax 96 if (ajaxinfo.status=="none" || ajaxinfo.status=="loading") 97 this.ajaxloadcontent($targetHeader, $targetContent, config, function(){ddaccordion.expandit($targetHeader, $targetContent, config, useractivated, directclick)}) 98 else if (ajaxinfo.status=="cached"){ 99 $targetContent.html(ajaxinfo.cacheddata) 100 ajaxinfo.cacheddata=null 101 ajaxinfo.status="complete" 102 } 103 } 104 this.transformHeader($targetHeader, config, "expand") 105 $targetContent.slideDown(skipanimation? 0 : config.animatespeed, function(){ 106 config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), useractivated) 107 var scrolltocontent = config.scrolltocontent 108 if (scrolltoheader || scrolltocontent){ 109 var sthdelay=(config["collapseprev"])? 20 : 0 110 clearTimeout(config.sthtimer) 111 var $destination = (scrolltocontent)? $targetContent : $targetHeader 112 config.sthtimer=setTimeout(function(){ddaccordion.scrollToHeader($destination)}, sthdelay) 113 } 114 if (config.postreveal=="gotourl" && directclick){ //if revealtype is "Go to Header URL upon click", and this is a direct click on the header 115 var targetLink=($targetHeader.is("a"))? $targetHeader.get(0) : $targetHeader.find('a:eq(0)').get(0) 116 if (targetLink) //if this header is a link 117 setTimeout(function(){location=targetLink.href}, 200 + (scrolltoheader? 400+sthdelay : 0) ) //ignore link target, as window.open(targetLink, targetLink.target) doesn't work in FF if popup blocker enabled 118 } 119 }) 120 }, 121 122 scrollToHeader:function($targetHeader){ 123 ddaccordion.$docbody.stop().animate({scrollTop: $targetHeader.offset().top}, 400) 124 }, 125 126 collapseit:function($targetHeader, $targetContent, config, isuseractivated){ 127 this.transformHeader($targetHeader, config, "collapse") 128 $targetContent.slideUp(config.animatespeed, function(){config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), isuseractivated)}) 129 }, 130 131 transformHeader:function($targetHeader, config, state){ 132 $targetHeader.addClass((state=="expand")? config.cssclass.expand : config.cssclass.collapse) //alternate btw "expand" and "collapse" CSS classes 133 .removeClass((state=="expand")? config.cssclass.collapse : config.cssclass.expand) 134 if (config.htmlsetting.location=='src'){ //Change header image (assuming header is an image)? 135 $targetHeader=($targetHeader.is("img"))? $targetHeader : $targetHeader.find('img').eq(0) //Set target to either header itself, or first image within header 136 $targetHeader.attr('src', (state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) //change header image 137 } 138 else if (config.htmlsetting.location=="prefix") //if change "prefix" HTML, locate dynamically added ".accordprefix" span tag and change it 139 $targetHeader.find('.accordprefix').empty().append((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) 140 else if (config.htmlsetting.location=="suffix") 141 $targetHeader.find('.accordsuffix').empty().append((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) 142 }, 143 144 urlparamselect:function(headerclass){ 145 var result=window.location.search.match(new RegExp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for "?headerclass=2,3,4" in URL 146 if (result!=null)
147 result=RegExp.$1.split(',') 148 return result //returns null, [index], or [index1,index2,etc], where index are the desired selected header indices 149 }, 150 151 152 getCookie:function(Name){ 153 var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair 154 if (document.cookie.match(re)) //if cookie found 155 return document.cookie.match(re)[0].split("=")[1] //return its value 156 return null 157 }, 158 159 setCookie:function(name, value){ 160 document.cookie = name + "=" + value + "; path=/" 161 }, 162 163 init:function(config){ 164 document.write('<style type="text/css">\n') 165 document.write('.'+config.contentclass+'{display: none}\n') //generate CSS to hide contents 166 document.write('a.hiddenajaxlink{display: none}\n') //CSS class to hide ajax link 167 document.write('<\/style>') 168 jQuery(document).ready(function($){ 169 ddaccordion.urlparamselect(config.headerclass) 170 var persistedheaders=ddaccordion.getCookie(config.headerclass) 171 ddaccordion.headergroup[config.headerclass]=$('.'+config.headerclass) //remember header group for this accordion 172 ddaccordion.contentgroup[config.headerclass]=$('.'+config.contentclass) //remember content group for this accordion 173 ddaccordion.$docbody=(window.opera)? (document.compatMode=="CSS1Compat"? jQuery('html') : jQuery('body')) : jQuery('html,body') 174 var $headers=ddaccordion.headergroup[config.headerclass] 175 var $subcontents=ddaccordion.contentgroup[config.headerclass] 176 config.cssclass={collapse: config.toggleclass[0], expand: config.toggleclass[1]} //store expand and contract CSS classes as object properties 177 config.revealtype=config.revealtype || "click" 178 config.revealtype=config.revealtype.replace(/mouseover/i, "mouseenter") 179 if (config.revealtype=="clickgo"){ 180 config.postreveal="gotourl" //remember added action 181 config.revealtype="click" //overwrite revealtype to "click" keyword 182 } 183 if (typeof config.togglehtml=="undefined") 184 config.htmlsetting={location: "none"} 185 else 186 config.htmlsetting={location: config.togglehtml[0], collapse: config.togglehtml[1], expand: config.togglehtml[2]} //store HTML settings as object properties 187 config.oninit=(typeof config.oninit=="undefined")? function(){} : config.oninit //attach custom "oninit" event handler 188 config.onopenclose=(typeof config.onopenclose=="undefined")? function(){} : config.onopenclose //attach custom "onopenclose" event handler 189 var lastexpanded={} //object to hold reference to last expanded header and content (jquery objects) 190 var expandedindices=ddaccordion.urlparamselect(config.headerclass) || ((config.persiststate && persistedheaders!=null)? persistedheaders : config.defaultexpanded) 191 if (typeof expandedindices=='string') //test for string value (exception is config.defaultexpanded, which is an array) 192 expandedindices=expandedindices.replace(/c/ig, '').split(',') //transform string value to an array (ie: "c1,c2,c3" becomes [1,2,3] 193 if (expandedindices.length==1 && expandedindices[0]=="-1") //check for expandedindices value of [-1], indicating persistence is on and no content expanded 194 expandedindices=[] 195 if (config["collapseprev"] && expandedindices.length>1) //only allow one content open? 196 expandedindices=[expandedindices.pop()] //return last array element as an array (for sake of jQuery.inArray()) 197 if (config["onemustopen"] && expandedindices.length==0) //if at least one content should be open at all times and none are, open 1st header 198 expandedindices=[0] 199 $headers.each(function(index){ //loop through all headers 200 var $header=$(this) 201 if (/(prefix)|(suffix)/i.test(config.htmlsetting.location) && $header.html()!=""){ //add a SPAN element to header depending on user setting and if header is a container tag 202 $('<span class="accordprefix"></span>').prependTo(this) 203 $('<span class="accordsuffix"></span>').appendTo(this) 204 } 205 $header.attr('headerindex', index+'h') //store position of this header relative to its peers 206 $subcontents.eq(index).attr('contentindex', index+'c') //store position of this content relative to its peers 207 var $subcontent=$subcontents.eq(index) 208 var $hiddenajaxlink=$subcontent.find('a.hiddenajaxlink:eq(0)') //see if this content should be loaded via ajax 209 if ($hiddenajaxlink.length==1){ 210 $header.data('ajaxinfo', {url:$hiddenajaxlink.attr('href'), cacheddata:null, status:'none'}) //store info about this ajax content inside header 211 } 212 var needle=(typeof expandedindices[0]=="number")? index : index+'' //check for data type within expandedindices array- index should match that type 213 if (jQuery.inArray(needle, expandedindices)!=-1){ //check for headers that should be expanded automatically (convert index to string first) 214 ddaccordion.expandit($header, $subcontent, config, false, false, !config.animatedefault) //3rd last param sets 'isuseractivated' parameter, 2nd last sets isdirectclick, last sets skipanimation param 215 lastexpanded={$header:$header, $content:$subcontent} 216 } //end check 217 else{ 218 $subcontent.hide() 219 config.onopenclose($header.get(0), parseInt($header.attr('headerindex')), $subcontent.css('display'), false) //Last Boolean value sets 'isuseractivated' parameter 220 ddaccordion.transformHeader($header, config, "collapse") 221 } 222 }) 223 //if (config["scrolltoheader"] && lastexpanded.$header) 224 //ddaccordion.scrollToHeader(lastexpanded.$header) 225 $headers.bind("evt_accordion", function(e, isdirectclick, scrolltoheader){ //assign CUSTOM event handler that expands/ contacts a header 226 var $subcontent=$subcontents.eq(parseInt($(this).attr('headerindex'))) //get subcontent that should be expanded/collapsed 227 if ($subcontent.css('display')=="none"){ 228 ddaccordion.expandit($(this), $subcontent, config, true, isdirectclick, false, scrolltoheader) //2nd last param sets 'isuseractivated' parameter 229 if (config["collapseprev"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){ //collapse previous content? 230 ddaccordion.collapseit(lastexpanded.$header, lastexpanded.$content, config, true) //Last Boolean value sets 'isuseractivated' parameter 231 } 232 lastexpanded={$header:$(this), $content:$subcontent} 233 } 234 else if (!config["onemustopen"] || config["onemustopen"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){ 235 ddaccordion.collapseit($(this), $subcontent, config, true) //Last Boolean value sets 'isuseractivated' parameter 236 } 237 }) 238 $headers.bind(config.revealtype, function(){ 239 if (config.revealtype=="mouseenter"){ 240 clearTimeout(config.revealdelay) 241 var headerindex=parseInt($(this).attr("headerindex")) 242 config.revealdelay=setTimeout(function(){ddaccordion.expandone(config["headerclass"], headerindex, config.scrolltoheader)}, config.mouseoverdelay || 0) 243 } 244 else{ 245 $(this).trigger("evt_accordion", [true, config.scrolltoheader]) //last parameter indicates this is a direct click on the header 246 return false //cancel default click behavior 247 } 248 }) 249 $headers.bind("mouseleave", function(){ 250 clearTimeout(config.revealdelay) 251 }) 252 config.oninit($headers.get(), expandedindices) 253 $(window).bind('unload', function(){ //clean up and persist on page unload 254 $headers.unbind() 255 var expandedindices=[] 256 $subcontents.filter(':visible').each(function(index){ //get indices of expanded headers 257 expandedindices.push($(this).attr('contentindex')) 258 }) 259 if (config.persiststate==true && $headers.length>0){ //persist state? 260 expandedindices=(expandedindices.length==0)? '-1c' : expandedindices //No contents expanded, indicate that with dummy '-1c' value? 261 ddaccordion.setCookie(config.headerclass, expandedindices) 262 } 263 }) 264 }) 265 } 266} 267 268//preload any images defined inside ajaxloadingmsg variable 269ddaccordion.preloadimages(jQuery(ddaccordion.ajaxloadingmsg).filter('img'))
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.