1//** Animated Collapsible DIV v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com. 2//** May 24th, 08'- Script rewritten and updated to 2.0. 3//** June 4th, 08'- Version 2.01: Bug fix to work with jquery 1.2.6 (which changed the way attr() behaves). 4//** March 5th, 09'- Version 2.2, which adds the following: 5 //1) ontoggle($, divobj, state) event that fires each time a DIV is expanded/collapsed, including when the page 1st loads 6 //2) Ability to expand a DIV via a URL parameter string, ie: index.htm?expanddiv=jason or index.htm?expanddiv=jason,kelly 7 8//** March 9th, 09'- Version 2.2.1: Optimized ontoggle event handler slightly. 9 10var animatedcollapse={ 11divholders: {}, //structure: {div.id, div.attrs, div.$divref} 12divgroups: {}, //structure: {groupname.count, groupname.lastactivedivid} 13statusholders: {}, //structure: {[statuselement.id, stype, [opensrc, closedsrc]], $target} 14lastactiveingroup: {}, //structure: {lastactivediv.id} 15 16show:function(divids){ //public method 17 if (typeof divids=="object"){ 18 for (var i=0; i<divids.length; i++) 19 this.showhide(divids[i], "show") 20 } 21 else 22 this.showhide(divids, "show") 23}, 24 25hide:function(divids){ //public method 26 if (typeof divids=="object"){ 27 for (var i=0; i<divids.length; i++) 28 this.showhide(divids[i], "hide") 29 } 30 else 31 this.showhide(divids, "hide") 32}, 33 34toggle:function(divid){ //public method 35 if (typeof divid=="object") 36 divid=divid[0] 37 this.showhide(divid, "toggle") 38}, 39 40addDiv:function(divid, attrstring){ //public function 41 this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring}) 42 this.divholders[divid].getAttr=function(name){ //assign getAttr() function to each divholder object 43 var attr=new RegExp(name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,) 44 return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null //return value portion (string), or 0 (false) if none found 45 } 46 this.currentid=divid //keep track of current div object being manipulated (in the event of chaining) 47 return this 48}, 49 50showhide:function(divid, action){ 51 var $divref=this.divholders[divid].$divref //reference collapsible DIV 52 if (this.divholders[divid] && $divref.length==1){ //if DIV exists 53 var targetgroup=this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any) 54 if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){ //If current DIV belongs to a group 55 if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid) //if last active DIV is set 56 this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first 57 this.slideengine(divid, 'show') 58 targetgroup.lastactivedivid=divid //remember last active DIV 59 } 60 else{ 61 this.slideengine(divid, action) 62 } 63 } 64}, 65 66slideengine:function(divid, action){ 67 var $divref=this.divholders[divid].$divref 68 if (this.divholders[divid] && $divref.length==1){ //if this DIV exists 69 var animateSetting={height: action} 70 if ($divref.attr('fade')) 71 animateSetting.opacity=action 72 $divref.animate(animateSetting, $divref.attr('speed')? parseInt($divref.attr('speed')) : 500, function(){ 73 if (animatedcollapse.ontoggle){ 74 try{ 75 animatedcollapse.ontoggle(jQuery, $divref.get(0), $divref.css('display')) 76 } 77 catch(e){ 78 alert("An error exists inside your \"ontoggle\" function:\n\n"+e+"\n\nAborting execution of function.") 79 } 80 } 81 }) 82 return false 83 } 84}, 85 86generatemap:function(){ 87 var map={} 88 for (var i=0; i<arguments.length; i++){ 89 if (arguments[i][1]!=null){ //do not generate name/value pair if value is null 90 map[arguments[i][0]]=arguments[i][1] 91 } 92 } 93 return map 94}, 95 96init:function(){ 97 var ac=this 98 jQuery(document).ready(function($){ 99 animatedcollapse.ontoggle=animatedcollapse.ontoggle || null 100 var urlparamopenids=animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc]) 101 var persistopenids=ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc') 102 var groupswithpersist=ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined 103 if (persistopenids!=null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet) 104 persistopenids=(persistopenids=='nada')? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids 105 groupswithpersist=(groupswithpersist==null || groupswithpersist=='nada')? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted 106 jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object
107 this.$divref=$('#'+this.id) 108 if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist)!=-1) && persistopenids!=null){ //if this div carries a user "persist" setting, or belong to a group with at least one div that does 109 var cssdisplay=(jQuery.inArray(this.id, persistopenids)!=-1)? 'block' : 'none' 110 } 111 else{ 112 var cssdisplay=this.getAttr('hide')? 'none' : null 113 } 114 if (urlparamopenids[0]=="all" || jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains the single array element "all", or this div's ID 115 cssdisplay='block' //set div to "block", overriding any other setting 116 } 117 else if (urlparamopenids[0]=="none"){ 118 cssdisplay='none' //set div to "none", overriding any other setting 119 } 120 this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay])) 121 this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')])) 122 if (this.getAttr('group')){ //if this DIV has the "group" attr defined 123 var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in 124 targetgroup.count=(targetgroup.count||0)+1 //count # of DIVs within this group 125 if (jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains this div's ID 126 targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded). Overrides other settings 127 targetgroup.overridepersist=1 //Indicate to override persisted div that would have been expanded 128 } 129 if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block" && typeof targetgroup.overridepersist=="undefined") //if this DIV was open by default or should be open due to persistence 130 targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded) 131 this.$divref.css({display:'none'}) //hide any DIV that's part of said group for now 132 } 133 }) //end divholders.each 134 jQuery.each(ac.divgroups, function(){ //loop through each group 135 if (this.lastactivedivid && urlparamopenids[0]!="none") //show last "active" DIV within each group (one that should be expanded), unless url param="none" 136 ac.divholders[this.lastactivedivid].$divref.show() 137 }) 138 if (animatedcollapse.ontoggle){ 139 jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object and fire ontoggle event 140 animatedcollapse.ontoggle(jQuery, this.$divref.get(0), this.$divref.css('display')) 141 }) 142 } 143/* //reserved for future implementation 144 var $allcontrols=$('a[rel]').filter('[@rel^="collapse["], [@rel^="expand["], [@rel^="toggle["]') //get all elements on page with rel="collapse[]", "expand[]" and "toggle[]" 145 $allcontrols.each(function(){ //loop though each control link 146 this._divids=this.getAttribute('rel').replace(/(^\w+)|(\s+)/g, "").replace(/[\[\]']/g, "") //cache value 'div1,div2,etc' within identifier[div1,div2,etc] 147 $(this).click(function(){ //assign click behavior to each control link 148 var relattr=this.getAttribute('rel') 149 var divids=(this._divids=="")? [] : this._divids.split(',') //convert 'div1,div2,etc' to array 150 if (divids.length>0){ 151 animatedcollapse[/expand/i.test(relattr)? 'show' : /collapse/i.test(relattr)? 'hide' : 'toggle'](divids) //call corresponding public function 152 return false 153 } 154 }) //end control.click 155 })// end control.each 156*/ 157 $(window).bind('unload', function(){ 158 ac.uninit() 159 }) 160 }) //end doc.ready() 161}, 162 163uninit:function(){ 164 var opendivids='', groupswithpersist='' 165 jQuery.each(this.divholders, function(){ 166 if (this.$divref.css('display')!='none'){ 167 opendivids+=this.id+',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc' 168 } 169 if (this.getAttr('group') && this.getAttr('persist')) 170 groupswithpersist+=this.getAttr('group')+',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc' 171 }) 172 opendivids=(opendivids=='')? 'nada' : opendivids.replace(/,$/, '') 173 groupswithpersist=(groupswithpersist=='')? 'nada' : groupswithpersist.replace(/,$/, '') 174 this.setCookie('acopendivids', opendivids) 175 this.setCookie('acgroupswithpersist', groupswithpersist) 176}, 177 178getCookie:function(Name){ 179 var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair 180 if (document.cookie.match(re)) //if cookie found 181 return document.cookie.match(re)[0].split("=")[1] //return its value 182 return null 183}, 184 185setCookie:function(name, value, days){ 186 if (typeof days!="undefined"){ //if set persistent cookie 187 var expireDate = new Date() 188 expireDate.setDate(expireDate.getDate()+days) 189 document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString() 190 } 191 else //else if this is a session only cookie 192 document.cookie = name+"="+value+"; path=/" 193}, 194 195urlparamselect:function(){ 196 window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=
196divid or divid1,divid2,etc 197 return (RegExp.$1!="")? RegExp.$1.split(",") : [] 198} 199 200}
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.