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