source: main/trunk/greenstone3/web/interfaces/default/js/classifier_scripts.js

Last change on this file was 38003, checked in by kjdon, 8 months ago

updates to handle having horizontal a-z lists inside a vertical bookshelf. now we open the sections in a more similar way to the bookshelves. opening in place, and keeping the rest of the bookshelves visible

  • Property svn:executable set to *
File size: 6.1 KB
Line 
1var inProgress = new Array();
2var openClassifiers = new Array();
3var busy = false;
4
5function isExpanded(sectionID)
6{
7 var divElem = gs.jqGet("div" + sectionID);
8 if(!divElem.css("display") || divElem.css("display") != "none")
9 {
10 return true;
11 }
12 return false;
13}
14
15function toggleSection(sectionID)
16{
17 var section = gs.jqGet("div" + sectionID);
18 var sectionToggle = gs.jqGet("toggle" + sectionID);
19
20 if(sectionToggle.length === 0)
21 {
22 return;
23 }
24
25 //If the div exists
26 // Test if 'section' exists.
27 // ==> Because we're using jQuery to do this we need to test the length of the object returned
28 // http://stackoverflow.com/questions/920236/how-can-i-detect-if-a-selector-returns-null
29 if(section.length !== 0)
30 {
31 var expanding = false;
32 if(isExpanded(sectionID))
33 {
34 expanding = false;
35 section.css("display", "none");
36 sectionToggle.attr("src", gs.imageURLs.expand);
37
38 if(openClassifiers[sectionID] != undefined && openClassifiers[sectionID].length !== 0)
39 {
40 delete openClassifiers[sectionID];
41 }
42 }
43 else
44 {
45 expanding = true;
46 section.css("display", "block");
47 sectionToggle.attr("src", gs.imageURLs.collapse);
48 openClassifiers[sectionID] = true;
49 }
50 updateOpenClassifiers();
51 if(typeof mapEnabled !== 'undefined' /*&& mapEnabled*/){
52 //console.log("Classifier scripts -> updateMap()");
53 toggleMapSection({"expand": expanding, "nodeID": sectionID});
54 updateMap();
55 }
56 }
57 else
58 {
59 httpBrowseRequest(sectionID, "vlist");
60 }
61}
62
63function toggleHListSection(sectionID)
64{
65
66 var parentID = getParentID(sectionID);
67 var section = document.getElementById('div' + sectionID);
68 var parent = document.getElementById('classifiernodelist'+parentID);
69 if (parent === null) {
70 console.log("couldn't find parent for "+sectionID);
71 return;
72 }
73 if(section != null) {
74
75
76 var expanding = false;
77 var sectionTitle = document.getElementById("title"+sectionID);
78 if(isExpanded(sectionID))
79 {
80 expanding = false;
81 section.style.display = "none";
82
83 sectionTitle.classList.remove("selectedHorizontalClassifierNode");
84 if(openClassifiers[sectionID] != undefined && openClassifiers[sectionID].length !== 0)
85 {
86 delete openClassifiers[sectionID];
87 }
88 }
89 else
90 {
91 expanding = true;
92 section.style.display="block";
93 sectionTitle.classList.add("selectedHorizontalClassifierNode");
94 openClassifiers[sectionID] = true;
95 }
96 updateOpenClassifiers();
97 if(typeof mapEnabled !== 'undefined' /*&& mapEnabled*/){
98 //console.log("Classifier scripts -> updateMap()");
99 toggleMapSection({"expand": expanding, "nodeID": sectionID});
100 updateMap();
101 }
102 }
103 else
104 {
105 // get teh content of the section
106 httpBrowseRequest(sectionID, "hlist");
107 }
108 // now hide the one that was already displayed (if any)
109 var children = parent.querySelectorAll('.childrenlist');
110 for (var i = 0; i < children.length; i++) {
111 var child = children[i];
112 var cid = child.id.substring(3); // remove 'div' from the id so we can get the section id
113 if (cid != sectionID) {
114 child.style.display="none";
115 var childTitle = document.getElementById('title'+cid);
116 childTitle.classList.remove("selectedHorizontalClassifierNode");
117 delete openClassifiers[cid];
118 }
119 }
120 updateOpenClassifiers();
121
122}
123
124function updateOpenClassifiers()
125{
126 var oc = "";
127 var first = true;
128 for(var key in openClassifiers)
129 {
130 if(first)
131 {
132 first = false;
133 }
134 else
135 {
136 oc += ",";
137 }
138
139 oc += key;
140 }
141
142 if(oc != undefined && oc != "")
143 {
144 window.location.hash = oc;
145 }
146}
147
148function openStoredClassifiers()
149{
150 if(window.location.hash != undefined && window.location.hash.length > 1)
151 {
152 var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
153 var loopFunction = function(sectionArray, index)
154 {
155 if(!busy && index < sectionArray.length)
156 {
157 busy = true;
158 toggleSection(sectionArray[index]);
159 setTimeout(function()
160 {
161 loopFunction(sectionArray, index + 1);
162 }, 25);
163
164 return true;
165 }
166
167 setTimeout(function()
168 {
169 loopFunction(sectionArray, index);
170 }, 25);
171 return false;
172 }
173
174 if(toOpen.length > 0)
175 {
176 loopFunction(toOpen, 0);
177 }
178 }
179}
180
181function getParentID(sectionID) {
182 if (sectionID.lastIndexOf(".") != -1) {
183 return sectionID.substring(0, sectionID.lastIndexOf("."));
184 }
185 return sectionID;
186}
187
188function httpBrowseRequest(sectionID, listType)
189{
190 if(!inProgress[sectionID])
191 {
192 inProgress[sectionID] = true;
193
194 if (listType != "hlist") {
195 var sectionToggle = gs.jqGet("toggle" + sectionID);
196 sectionToggle.attr("src", gs.imageURLs.loading);
197 }
198 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
199
200 if(gs.cgiParams.favouritebasket == "on")
201 {
202 url = url + "&favouritebasket=on";
203 }
204
205 if(url.indexOf("#") != -1)
206 {
207 url = url.substring(0, url.indexOf("#"));
208 }
209
210 $.ajax(url)
211 .done(function(data)
212 {
213 var newDiv = $("<div>");
214 if (listType == "hlist") {
215 var parent = gs.jqGet("classifiernodelist"+getParentID(sectionID));
216 var title = gs.jqGet("title"+sectionID);
217 title.addClass("selectedHorizontalClassifierNode");
218 parent.append(newDiv);
219
220 } else {
221 var sibling = gs.jqGet("title" + sectionID);
222 sibling.after(newDiv);
223 sectionToggle.attr("src", gs.imageURLs.collapse);
224
225 }
226 newDiv.html(data);
227
228 openClassifiers[sectionID] = true;
229
230 if(gs.cgiParams.favouritebasket == "on")
231 {
232 favouritesCheckout();
233 }
234 if(gs.cgiParams.documentbasket == "on")
235 {
236 dmcheckout();
237 }
238 updateOpenClassifiers();
239 if(typeof mapEnabled !== 'undefined'){
240 httpMapBrowseRequest(sectionID);
241 }
242 })
243 .fail(function()
244 {
245 if (listType != "hlist") {
246 sectionToggle.attr("src", gs.imageURLs.expand);
247 }
248 })
249 .always(function()
250 {
251 inProgress[sectionID] = false;
252 busy = false;
253 });
254 }
255
256}
Note: See TracBrowser for help on using the repository browser.