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

Last change on this file since 25010 was 25010, checked in by sjm84, 12 years ago

Improved how an ajax object is retrieved

  • 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 }, 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 = new gs.functions.ajaxRequest();
114
115 var sectionToggle = document.getElementById("toggle" + sectionID);
116 sectionToggle.setAttribute("src", gs.imageURLs.loading);
117
118 var url = document.URL;
119 url = url.replace(/(&|\?)cl=[a-z\.0-9]+/gi, "$1cl=" + sectionID + "&excerptid=div" + sectionID);
120
121 if(gs.cgiParams.berryBasket == "on")
122 {
123 url = url + "&berrybasket=on";
124 }
125
126 if(url.indexOf("#") != -1)
127 {
128 url = url.substring(0, url.indexOf("#"));
129 }
130 httpRequest.open('GET', url, true);
131 httpRequest.onreadystatechange = function()
132 {
133 if (httpRequest.readyState == 4)
134 {
135 if (httpRequest.status == 200)
136 {
137 var newDiv = document.createElement("div");
138 var sibling = document.getElementById("title" + sectionID);
139 var parent = sibling.parentNode;
140 if(sibling.nextSibling)
141 {
142 parent.insertBefore(newDiv, sibling.nextSibling);
143 }
144 else
145 {
146 parent.appendChild(newDiv);
147 }
148
149 newDiv.innerHTML = httpRequest.responseText;
150 sectionToggle.setAttribute("src", gs.imageURLs.collapse);
151 openClassifiers[sectionID] = true;
152
153 if(gs.cgiParams.berryBasket == "on")
154 {
155 checkout();
156 }
157 updateOpenClassifiers();
158 }
159 else
160 {
161 sectionToggle.setAttribute("src", gs.imageURLs.expand);
162 }
163 inProgress[sectionID] = false;
164 busy = false;
165 }
166 }
167 httpRequest.send();
168 }
169}
Note: See TracBrowser for help on using the repository browser.