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

Last change on this file since 33289 was 33289, checked in by wy59, 5 years ago
  1. References to new Array() changed to [] and _docList now no longer initalised with new Array but with {} because it was being used as a map. 2. Added toggleMapSection and modified httpMapBrowseRequest() to do as Dr Bainbridge had suggested: httpMapBrowseRequest would add the JSON info for the docs returned for the expanded classifier into a data attribute for the expanded classifier ID. Then on expanding during toggling a classifier, the map would add the doc info for each of the docs stored in the data attribute for the toggled section into the _docList map, and on closing the bookshelf when toggling a classifier the affected docs (those referenced in the toggled section's data attribute) would be removed from the _docList. 3. This did not solve the original problem that performSearchForMarkers() was always being called when the map bounds were extended since _docList maintained not just the expanded visible docs but also the nearbyDocs from the proximity search for what else could be displayed on the map. Dr Bainbridge solved all this by cleaning up the existing code (e.g. renaming functions like performSearchForMarkers changed to performProximitySearch and renaming variables like _nearbyDocs to _nearbyDocsByDistance) and introducing new variables like the new array nearbyDocListByProximity. The array nearbyDocListByProximity is emptied and repopulated by the performProximitySearch() function. These docs only need to be displayed on the map, so the list can be recreated on every expanded bookshelf. performProximitySearch() will first empty the _nearbyDocListByProximity array after removing its markers from the current map, then it will perform the search and add each document found that's not already in _docList (i.e. not already visible in one of the expanded classifiers) to _nearbyDocListByProximity. These docs' shapes are then drawn on the map at lower opacity but on updateMap)() these docs won't trigger a bounds_changed, as the bounds are only calculated based on the main docs, the ones in the now reduced _docList, and not based on the nearby docs in _nearbyDocListByProximity. 4. Dr Bainbridge fixed an issue whereby expanding the first node would not get nearby docs for it with performProximitySearch() as the map bounds were invalid due to incomplete map initialisation. The culprit was with setting the map display to hidden, turning it on thereafter with display block never changed the map bounds from 0 back to something valid when the map bounds were printed before the fitBounds() call. Also, setting the map's visibility to hidden with 0px height and then to visible with a positive height would result in the map bounds calculated longitude to be 0. The solution Dr Bainbridge came up with was to only use visibility rather than display, but not set the height, instead on hidden map setting the position to absolute would allow the visible elements to continue to flow on the page and when the map was set to visible, its position property should be returned to relative. 5. Added debugging and info logging functions.
  • Property svn:executable set to *
File size: 3.9 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 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].length !== 0) //if(openClassifiers[sectionID] != undefined)
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);
60 }
61}
62
63function updateOpenClassifiers()
64{
65 var oc = "";
66 var first = true;
67 for(var key in openClassifiers)
68 {
69 if(first)
70 {
71 first = false;
72 }
73 else
74 {
75 oc += ",";
76 }
77
78 oc += key;
79 }
80
81 if(oc != undefined && oc != "")
82 {
83 window.location.hash = oc;
84 }
85}
86
87function openStoredClassifiers()
88{
89 if(window.location.hash != undefined && window.location.hash.length > 1)
90 {
91 var toOpen = window.location.hash.substring(1,window.location.hash.length).split(",");
92 var loopFunction = function(sectionArray, index)
93 {
94 if(!busy && index < sectionArray.length)
95 {
96 busy = true;
97 toggleSection(sectionArray[index]);
98 setTimeout(function()
99 {
100 loopFunction(sectionArray, index + 1);
101 }, 25);
102
103 return true;
104 }
105
106 setTimeout(function()
107 {
108 loopFunction(sectionArray, index);
109 }, 25);
110 return false;
111 }
112
113 if(toOpen.length > 0)
114 {
115 loopFunction(toOpen, 0);
116 }
117 }
118}
119
120function httpBrowseRequest(sectionID)
121{
122 if(!inProgress[sectionID])
123 {
124 inProgress[sectionID] = true;
125
126 var sectionToggle = gs.jqGet("toggle" + sectionID);
127 sectionToggle.attr("src", gs.imageURLs.loading);
128
129 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
130
131 if(gs.cgiParams.berrybasket == "on")
132 {
133 url = url + "&berrybasket=on";
134 }
135 if(gs.cgiParams.favouritebasket == "on")
136 {
137 url = url + "&favouritebasket=on";
138 }
139
140 if(url.indexOf("#") != -1)
141 {
142 url = url.substring(0, url.indexOf("#"));
143 }
144
145 $.ajax(url)
146 .success(function(data)
147 {
148 var newDiv = $("<div>");
149 var sibling = gs.jqGet("title" + sectionID);
150 sibling.after(newDiv);
151
152 newDiv.html(data);
153 sectionToggle.attr("src", gs.imageURLs.collapse);
154 openClassifiers[sectionID] = true;
155
156 if(gs.cgiParams.berrybasket == "on")
157 {
158 berryCheckout();
159 }
160 if(gs.cgiParams.favouritebasket == "on")
161 {
162 favouritesCheckout();
163 }
164 if(gs.cgiParams.documentbasket == "on")
165 {
166 dmcheckout();
167 }
168 updateOpenClassifiers();
169 if(typeof mapEnabled !== 'undefined'){
170 httpMapBrowseRequest(sectionID);
171 }
172 })
173 .error(function()
174 {
175 sectionToggle.attr("src", gs.imageURLs.expand);
176 })
177 .complete(function()
178 {
179 inProgress[sectionID] = false;
180 busy = false;
181 });
182 }
183}
Note: See TracBrowser for help on using the repository browser.