source: main/trunk/greenstone3/web/interfaces/oran/js/classifier_scripts.js@ 24520

Last change on this file since 24520 was 24520, checked in by sjm84, 13 years ago

The expanding classifers will now remain open if you press back to revisit the page, also adding xsltParams to the gs variable, also changed Document Maker to Document Basket in the pref.xsl file

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1var inProgress = new Array();
2var openClassifiers = new Array();
3var busy = false;
4
5function isExpanded(sectionID)
6{
7 var divElem = document.getElementById("div" + sectionID);
8 if(!divElem.style.display || divElem.style.display == "block")
9 {
10 return true;
11 }
12 return false;
13}
14
15function toggleSection(sectionID)
16{
17 var section = document.getElementById("div" + sectionID);
18 var sectionToggle = document.getElementById("toggle" + sectionID);
19
20 if(sectionToggle == undefined)
21 {
22 return;
23 }
24
25 if(section)
26 {
27 if(isExpanded(sectionID))
28 {
29 section.style.display = "none";
30 sectionToggle.setAttribute("src", gs.imageURLs.expand);
31
32 if(openClassifiers[sectionID] != undefined)
33 {
34 delete openClassifiers[sectionID];
35 }
36 }
37 else
38 {
39 section.style.display = "block";
40 sectionToggle.setAttribute("src", gs.imageURLs.collapse);
41 openClassifiers[sectionID] = true;
42 }
43 updateOpenClassifiers();
44 }
45 else
46 {
47 httpRequest(sectionID);
48 }
49}
50
51function updateOpenClassifiers()
52{
53 var oc = "";
54 var first = true;
55 for(var key in openClassifiers)
56 {
57 if(first)
58 {
59 first = false;
60 }
61 else
62 {
63 oc += ",";
64 }
65
66 oc += key;
67 }
68
69 if(oc != undefined)
70 {
71 window.location.hash = oc;
72 }
73}
74
75function openStoredClassifiers()
76{
77 if(window.location.hash != undefined && window.location.hash.length > 1)
78 {
79 var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
80 var loopFunction = function(sectionArray, index)
81 {
82 if(!busy && index < sectionArray.length)
83 {
84 busy = true;
85 toggleSection(sectionArray[index]);
86 setTimeout(function()
87 {
88 loopFunction(sectionArray, index + 1);
89 }, 50);
90
91 return true
92 }
93
94 setTimeout(function()
95 {
96 loopFunction(sectionArray, index);
97 }, 50);
98 return false;
99 }
100
101 if(toOpen.length > 0)
102 {
103 loopFunction(toOpen, 0);
104 }
105 }
106}
107
108function httpRequest(sectionID)
109{
110 if(!inProgress[sectionID])
111 {
112 inProgress[sectionID] = true;
113 var httpRequest;
114 if (window.XMLHttpRequest) {
115 httpRequest = new XMLHttpRequest();
116 }
117 else if (window.ActiveXObject) {
118 httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
119 }
120
121 var sectionToggle = document.getElementById("toggle" + sectionID);
122 sectionToggle.setAttribute("src", gs.imageURLs.loading);
123
124 var url = document.URL;
125 url = url.replace(/(&|\?)cl=[a-z\.0-9]+/gi, "$1cl=" + sectionID + "&excerptid=div" + sectionID);
126
127 if(gs.cgiParams.berryBasket == "on")
128 {
129 url = url + "&berrybasket=on";
130 }
131
132 httpRequest.open('GET', url, true);
133 httpRequest.onreadystatechange = function()
134 {
135 if (httpRequest.readyState == 4)
136 {
137 if (httpRequest.status == 200)
138 {
139 var newDiv = document.createElement("div");
140 var sibling = document.getElementById("title" + sectionID);
141 var parent = sibling.parentNode;
142 if(sibling.nextSibling)
143 {
144 parent.insertBefore(newDiv, sibling.nextSibling);
145 }
146 else
147 {
148 parent.appendChild(newDiv);
149 }
150
151 newDiv.innerHTML = httpRequest.responseText;
152 sectionToggle.setAttribute("src", gs.imageURLs.collapse);
153 openClassifiers[sectionID] = true;
154
155 if(gs.cgiParams.berryBasket == "on")
156 {
157 checkout();
158 }
159 updateOpenClassifiers();
160 }
161 else
162 {
163 sectionToggle.setAttribute("src", gs.imageURLs.expand);
164 }
165 inProgress[sectionID] = false;
166 busy = false;
167 }
168 }
169 httpRequest.send();
170 }
171}
Note: See TracBrowser for help on using the repository browser.