Rev 145 Rev 171
1 /*********************************************** 1 /***********************************************
2 * Switch Content script- © Dynamic Drive (www.dynamicdrive.com) 2 * Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
3 * This notice must stay intact for legal use. Last updated April 2nd, 2005. 3 * This notice must stay intact for legal use. Last updated April 2nd, 2005.
4 * Visit http://www.dynamicdrive.com/ for full source code 4 * Visit http://www.dynamicdrive.com/ for full source code
5 ***********************************************/ 5 ***********************************************/
6   6  
7 var enablepersist="on" // Enable saving state of content structure using session cookies? (on/off) 7 var enablepersist="on" // Enable saving state of content structure using session cookies? (on/off)
8 var collapseprevious="yes" // Collapse previously open content when opening present? (yes/no) 8 var collapseprevious="yes" // Collapse previously open content when opening present? (yes/no)
9   9  
10 var contractsymbol='<div class="minusbox">-</div>' // HTML for contract symbol. For image, use: <img src="${prefix}whatever.gif"> 10 var contractsymbol='<div class="minusbox">-</div>' // HTML for contract symbol. For image, use: <img src="${prefix}whatever.gif">
11 var expandsymbol='<div class="plusbox">+</div>' // HTML for expand symbol. 11 var expandsymbol='<div class="plusbox">+</div>' // HTML for expand symbol.
12 var expandonload=false 12 var expandonload=false
13   13  
14 if (document.getElementById) 14 if (document.getElementById)
15 { 15 {
16 document.write('<style type="text/css">') 16 document.write('<style type="text/css">')
17 document.write('.switchcontent{display:none;}') 17 document.write('.switchcontent{display:none;}')
18 document.write('</style>') 18 document.write('</style>')
19 } 19 }
20   20  
21 function getElementbyClass(rootobj, classname) 21 function getElementbyClass(rootobj, classname)
22 { 22 {
23 var temparray=new Array() 23 var temparray=new Array()
24 var inc=0 24 var inc=0
25 for (i=0; i<rootobj.length; i++) 25 for (i=0; i<rootobj.length; i++)
26 { 26 {
27 if (rootobj[i].className==classname) 27 if (rootobj[i].className==classname)
28 temparray[inc++]=rootobj[i] 28 temparray[inc++]=rootobj[i]
29 } 29 }
30 return temparray 30 return temparray
31 } 31 }
32   32  
33 function sweeptoggle(ec) 33 function sweeptoggle(ec)
34 { 34 {
35 var thestate=(ec=="expand")? "block" : "none" 35 var thestate=(ec=="expand")? "block" : "none"
36 var inc=0 36 var inc=0
37 while (ccollect[inc]) 37 while (ccollect[inc])
38 { 38 {
39 ccollect[inc].style.display=thestate 39 ccollect[inc].style.display=thestate
40 inc++ 40 inc++
41 } 41 }
42 revivestatus() 42 revivestatus()
43 collapseprevious = (ec=="expand")? "no" : "yes" 43 collapseprevious = (ec=="expand")? "no" : "yes"
44 } 44 }
45   45  
46   46  
47 function contractcontent(omit) 47 function contractcontent(omit)
48 { 48 {
49 var inc=0 49 var inc=0
50 while (ccollect[inc]) 50 while (ccollect[inc])
51 { 51 {
52 if (ccollect[inc].id!=omit) 52 if (ccollect[inc].id!=omit)
53 ccollect[inc].style.display="none" 53 ccollect[inc].style.display="none"
54 inc++ 54 inc++
55 } 55 }
56 } 56 }
57   57  
58 function expandcontent(curobj, cid) 58 function expandcontent(curobj, cid)
59 { 59 {
60 var spantags=curobj.getElementsByTagName("SPAN") 60 var spantags=curobj.getElementsByTagName("SPAN")
61 var showstateobj=getElementbyClass(spantags, "showstate") 61 var showstateobj=getElementbyClass(spantags, "showstate")
62 if (ccollect.length>0) 62 if (ccollect.length>0)
63 { 63 {
64 if (collapseprevious=="yes") 64 if (collapseprevious=="yes")
65 contractcontent(cid) 65 contractcontent(cid)
66 document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none" 66 document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
67 if (showstateobj.length>0) //if "showstate" span exists in header 67 if (showstateobj.length>0) //if "showstate" span exists in header
68 { 68 {
69 if (collapseprevious=="no") 69 if (collapseprevious=="no")
70 showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol 70 showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
71 else 71 else
72 revivestatus() 72 revivestatus()
73 } 73 }
74 } 74 }
75 } 75 }
76   76  
77 function revivecontent() 77 function revivecontent()
78 { 78 {
79 contractcontent("omitnothing") 79 contractcontent("omitnothing")
80 selectedItem=getselectedItem() 80 selectedItem=getselectedItem()
81 selectedComponents=selectedItem.split("|") 81 selectedComponents=selectedItem.split("|")
82 collapseprevious=selectedComponents[0] 82 collapseprevious=selectedComponents[0]
83 for (i=1; i<selectedComponents.length-1; i++) 83 for (i=1; i<selectedComponents.length-1; i++)
84 document.getElementById(selectedComponents[i]).style.display="block" 84 document.getElementById(selectedComponents[i]).style.display="block"
85 } 85 }
86   86  
87 function revivestatus() 87 function revivestatus()
88 { 88 {
89 var inc=0 89 var inc=0
90 while (statecollect[inc]) 90 while (statecollect[inc])
91 { 91 {
92 if (ccollect[inc].style.display=="block") 92 if (ccollect[inc].style.display=="block")
93 statecollect[inc].innerHTML=contractsymbol 93 statecollect[inc].innerHTML=contractsymbol
94 else 94 else
95 statecollect[inc].innerHTML=expandsymbol 95 statecollect[inc].innerHTML=expandsymbol
96 inc++ 96 inc++
97 } 97 }
98 } 98 }
99   99  
100 function get_cookie(Name) 100 function get_cookie(Name)
101 { 101 {
102 var search = Name + "=" 102 var search = Name + "="
103 var returnvalue = ""; 103 var returnvalue = "";
104 if (document.cookie.length > 0) 104 if (document.cookie.length > 0)
105 { 105 {
106 offset = document.cookie.indexOf(search) 106 offset = document.cookie.indexOf(search)
107 if (offset != -1) 107 if (offset != -1)
108 { 108 {
109 offset += search.length 109 offset += search.length
110 end = document.cookie.indexOf(";", offset); 110 end = document.cookie.indexOf(";", offset);
111 if (end == -1) end = document.cookie.length; 111 if (end == -1) end = document.cookie.length;
112 returnvalue=unescape(document.cookie.substring(offset, end)) 112 returnvalue=unescape(document.cookie.substring(offset, end))
113 } 113 }
114 } 114 }
115 return returnvalue; 115 return returnvalue;
116 } 116 }
117   117  
118 function getselectedItem() 118 function getselectedItem()
119 { 119 {
120 if (get_cookie(window.location.pathname) != "") 120 if (get_cookie(window.location.pathname) != "")
121 { 121 {
122 selectedItem=get_cookie(window.location.pathname) 122 selectedItem=get_cookie(window.location.pathname)
123 return selectedItem 123 return selectedItem
124 } 124 }
125 else 125 else
126 return "" 126 return ""
127 } 127 }
128   128  
129 function saveswitchstate() 129 function saveswitchstate()
130 { 130 {
131 var inc=0, selectedItem=collapseprevious+"|" 131 var inc=0, selectedItem=collapseprevious+"|"
132 while (ccollect[inc]) 132 while (ccollect[inc])
133 { 133 {
134 if (ccollect[inc].style.display=="block") 134 if (ccollect[inc].style.display=="block")
135 selectedItem+=ccollect[inc].id+"|" 135 selectedItem+=ccollect[inc].id+"|"
136 inc++ 136 inc++
137 } 137 }
138 document.cookie=window.location.pathname+"="+selectedItem 138 document.cookie=window.location.pathname+"="+selectedItem
139 } 139 }
140   140  
141 function do_onload() 141 function do_onload()
142 { 142 {
143 uniqueidn=window.location.pathname+"firsttimeload" 143 uniqueidn=window.location.pathname+"firsttimeload"
144 var alltags=document.all? document.all : document.getElementsByTagName("*") 144 var alltags=document.all? document.all : document.getElementsByTagName("*")
145 ccollect=getElementbyClass(alltags, "switchcontent") 145 ccollect=getElementbyClass(alltags, "switchcontent")
146 statecollect=getElementbyClass(alltags, "showstate") 146 statecollect=getElementbyClass(alltags, "showstate")
147 if (enablepersist=="on" && ccollect.length>0) 147 if (enablepersist=="on" && ccollect.length>0)
148 { 148 {
149 document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 149 document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
150 firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load 150 firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
151 if (!firsttimeload) 151 if (!firsttimeload)
152 revivecontent() 152 revivecontent()
153 } 153 }
154 if (ccollect.length>0 && statecollect.length>0) 154 if (ccollect.length>0 && statecollect.length>0)
155 revivestatus() 155 revivestatus()
156 156
157 if (expandonload) 157 if (expandonload)
158 sweeptoggle('expand') 158 sweeptoggle('expand')
159 } 159 }
160   160  
161 if (window.addEventListener) 161 if (window.addEventListener)
162 window.addEventListener("load", do_onload, false) 162 window.addEventListener("load", do_onload, false)
163 else if (window.attachEvent) 163 else if (window.attachEvent)
164 window.attachEvent("onload", do_onload) 164 window.attachEvent("onload", do_onload)
165 else if (document.getElementById) 165 else if (document.getElementById)
166 window.onload=do_onload 166 window.onload=do_onload
167   167  
168 if (enablepersist=="on" && document.getElementById) 168 if (enablepersist=="on" && document.getElementById)
169 window.onunload=saveswitchstate 169 window.onunload=saveswitchstate