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

Last change on this file since 33187 was 33187, checked in by wy59, 5 years ago

Bugfix to recently introduced bug: when there are bookshelves, suddenly the 33168 revision commit didn't display the map any more. This broke it for ImagesGPS' classifier display but also for our sectioned collection's classifier display. We still have issues with our classifier not showing all the correct maps and their bounds, but at least, the map shows again when a bookshelf has been opened.

  • 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 = 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 == undefined)
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 if(isExpanded(sectionID))
32 {
33 section.css("display", "none");
34 sectionToggle.attr("src", gs.imageURLs.expand);
35
36 if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
37 {
38 delete openClassifiers[sectionID];
39 }
40 }
41 else
42 {
43 section.css("display", "block");
44 sectionToggle.attr("src", gs.imageURLs.collapse);
45 openClassifiers[sectionID] = true;
46 }
47 updateOpenClassifiers();
48 if(typeof mapEnabled !== 'undefined' && mapEnabled){
49 //console.log("Classifier scripts -> updateMap()");
50 updateMap();
51 }
52 }
53 else
54 {
55 httpRequest(sectionID);
56 }
57}
58
59function updateOpenClassifiers()
60{
61 var oc = "";
62 var first = true;
63 for(var key in openClassifiers)
64 {
65 if(first)
66 {
67 first = false;
68 }
69 else
70 {
71 oc += ",";
72 }
73
74 oc += key;
75 }
76
77 if(oc != undefined && oc != "")
78 {
79 window.location.hash = oc;
80 }
81}
82
83function openStoredClassifiers()
84{
85 if(window.location.hash != undefined && window.location.hash.length > 1)
86 {
87 var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
88 var loopFunction = function(sectionArray, index)
89 {
90 if(!busy && index < sectionArray.length)
91 {
92 busy = true;
93 toggleSection(sectionArray[index]);
94 setTimeout(function()
95 {
96 loopFunction(sectionArray, index + 1);
97 }, 25);
98
99 return true;
100 }
101
102 setTimeout(function()
103 {
104 loopFunction(sectionArray, index);
105 }, 25);
106 return false;
107 }
108
109 if(toOpen.length > 0)
110 {
111 loopFunction(toOpen, 0);
112 }
113 }
114}
115
116function httpRequest(sectionID)
117{
118 if(!inProgress[sectionID])
119 {
120 inProgress[sectionID] = true;
121
122 var sectionToggle = gs.jqGet("toggle" + sectionID);
123 sectionToggle.attr("src", gs.imageURLs.loading);
124
125 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?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
137 $.ajax(url)
138 .success(function(data)
139 {
140 var newDiv = $("<div>");
141 var sibling = gs.jqGet("title" + sectionID);
142 sibling.after(newDiv);
143
144 newDiv.html(data);
145 sectionToggle.attr("src", gs.imageURLs.collapse);
146 openClassifiers[sectionID] = true;
147
148 if(gs.cgiParams.berrybasket == "on")
149 {
150 checkout();
151 }
152 else if(gs.cgiParams.documentbasket == "on")
153 {
154 dmcheckout();
155 }
156 updateOpenClassifiers();
157 if(typeof mapEnabled !== 'undefined'){
158 getSubClassifier(sectionID);
159 }
160 })
161 .error(function()
162 {
163 sectionToggle.attr("src", gs.imageURLs.expand);
164 })
165 .complete(function()
166 {
167 inProgress[sectionID] = false;
168 busy = false;
169 });
170 }
171}
Note: See TracBrowser for help on using the repository browser.