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

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

Added a missing ;

  • Property svn:executable set to *
File size: 3.6 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 }, 25);
90
91 return true;
92 }
93
94 setTimeout(function()
95 {
96 loopFunction(sectionArray, index);
97 }, 25);
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 if(url.indexOf("#") != -1)
133 {
134 url = url.substring(0, url.indexOf("#"));
135 }
136 httpRequest.open('GET', url, true);
137 httpRequest.onreadystatechange = function()
138 {
139 if (httpRequest.readyState == 4)
140 {
141 if (httpRequest.status == 200)
142 {
143 var newDiv = document.createElement("div");
144 var sibling = document.getElementById("title" + sectionID);
145 var parent = sibling.parentNode;
146 if(sibling.nextSibling)
147 {
148 parent.insertBefore(newDiv, sibling.nextSibling);
149 }
150 else
151 {
152 parent.appendChild(newDiv);
153 }
154
155 newDiv.innerHTML = httpRequest.responseText;
156 sectionToggle.setAttribute("src", gs.imageURLs.collapse);
157 openClassifiers[sectionID] = true;
158
159 if(gs.cgiParams.berryBasket == "on")
160 {
161 checkout();
162 }
163 updateOpenClassifiers();
164 }
165 else
166 {
167 sectionToggle.setAttribute("src", gs.imageURLs.expand);
168 }
169 inProgress[sectionID] = false;
170 busy = false;
171 }
172 }
173 httpRequest.send();
174 }
175}
Note: See TracBrowser for help on using the repository browser.