source: main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js@ 32832

Last change on this file since 32832 was 32832, checked in by ak19, 5 years ago

Zeddy map work. 1. Now supports saving when map editor is selected and key s is pressed.. The saved shapes are now reloaded on page (re)load. 2. If you make a change and didn't save it and try to leave the page, there's now a default warning (can't yet control the warning message, but it's helpful enough at this stage). 3. Some more fixes. 4. Some cleaning up of unused code. 5. Still some debugging statements left in, check for console.log() for instance. 6. Gone back to using javascript instead of jQuery for keyboard shortcuts so it will work for PDF docs too, but kept some additional changes made earlier so that things still work on Firefox besides Chrome.

  • Property svn:executable set to *
File size: 22.8 KB
Line 
1//var newLat, newLng = 0;
2var _docList = new Array();
3_docList.ids = new Array();
4_docList.getDocByIndex = function(index)
5{
6 return _docList[_docList.ids[index]];
7};
8
9var _map;
10var _intervalHandle;
11var _baseURL = document.URL.substring(0, document.URL.indexOf("?") + 1);
12var _retrievedClassifiers = new Array();
13var _preventLoopingSingleMarker = false;
14var _searchRunning = false;
15var _nearbyDocs = new Array();
16var _scrollThroughDefault = true;
17
18function initializeMapScripts()
19{
20 modifyFunctions();
21 setUpMap();
22
23 var jsonNodeDiv = $("#jsonNodes");
24 if(jsonNodeDiv.length)
25 {
26 var jsonNodes = eval(jsonNodeDiv.html());
27 if(jsonNodes && jsonNodes.length > 0)
28 {
29 for(var i = 0; i < jsonNodes.length; i++)
30 {
31 _docList[jsonNodes[i].nodeID] = jsonNodes[i];
32 _docList.ids.push(jsonNodes[i].nodeID);
33 createMarker(jsonNodes[i], true);
34 }
35 updateMap();
36 }
37 else
38 {
39 //$("#map_canvas").css({visibility:"hidden", height:"0px"});
40 $("#map_canvas").css({visibility:"hidden"});
41 }
42 }
43
44 _docList.loopIndex = 0;
45
46 if(_docList.ids.length > 1)
47 {
48 var startStopCheckbox = $("<input>", {"type": "checkbox", "checked": _scrollThroughDefault, "id": "scrollCheckbox"});
49 startStopCheckbox.click(function()
50 {
51 // http://stackoverflow.com/questions/901712/how-to-check-if-a-checkbox-is-checked-in-jquery
52 // http://stackoverflow.com/questions/5270689/attrchecked-checked-does-not-work
53
54 if($('#scrollCheckbox').is(':checked')) // OR: if(document.getElementById('scrollCheckbox').checked)
55 {
56 if(_intervalHandle == null)
57 {
58 _intervalHandle = setInterval(loopThroughMarkers, 2000);
59 }
60 }
61 else
62 {
63 clearInterval(_intervalHandle);
64 _intervalHandle = null;
65 }
66 });
67
68 var label = $("<span>Scroll through places</span>");
69 var container = $("<div>", {"class": "ui-widget-header ui-corner-all", "style": "clear:right; float:right; padding:0px 5px 3px 0px;"});
70 container.append(startStopCheckbox);
71 container.append(label);
72
73 $(container).insertAfter("#map_canvas");
74
75 if (_scrollThroughDefault) {
76 _intervalHandle = setInterval(loopThroughMarkers, 2000);
77 }
78
79 }
80}
81
82function setUpMap()
83{
84
85
86 var myOptions =
87 {
88 zoom: 2,
89 center: new google.maps.LatLng(0, 0),
90 mapTypeId: google.maps.MapTypeId.HYBRID
91 };
92 var $map_canvas = $("#map_canvas");
93
94 if ($map_canvas.length > 0) {
95 _map = new google.maps.Map($map_canvas[0], myOptions);
96 google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers);
97 }
98}
99
100function performSearchForMarkers()
101{
102 if(_searchRunning)
103 {
104 return;
105 }
106
107 _searchRunning = true;
108
109 var bounds = _map.getBounds();
110
111 var neLat = bounds.getNorthEast().lat();
112 var neLng = bounds.getNorthEast().lng();
113 var swLat = bounds.getSouthWest().lat();
114 var swLng = bounds.getSouthWest().lng();
115
116 var latDistance = neLat - swLat;
117 var lngDistance = neLng - swLng;
118
119 //Check which increment to use for latitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
120 var latDelta;
121 var latPrecision;
122 for(var i = 3; i >= 0; i--)
123 {
124 latDelta = (1 / Math.pow(10, i));
125 if((latDistance / latDelta) <= 5 || latDelta == 1)
126 {
127 latPrecision = i;
128 break;
129 }
130 }
131
132 //Check which increment to use for longitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
133 var lngDelta;
134 for(var i = 3; i >= 0; i--)
135 {
136 lngDelta = (1 / Math.pow(10, i));
137 if((lngDistance / lngDelta) <= 5 || lngDelta == 1)
138 {
139 lngPrecision = i;
140 break;
141 }
142 }
143
144 if(latDelta == 0.1){latDelta = 1; latPrecision = 0; }
145 if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; }
146
147 var query = "";
148 for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
149 {
150 for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++)
151 {
152 //Some necessary variables
153 var newLat = neLat - (latDelta * i);
154 var newLatString = "" + newLat;
155 var newLatTrunc;
156 if(newLat < 0){newLatTrunc = Math.ceil(newLat);}
157 else{newLatTrunc = Math.floor(newLat);}
158
159 var newLng = neLng - (lngDelta * j);
160 var newLngString = "" + newLng;
161 var newLngTrunc;
162 if(newLng < 0){newLngTrunc = Math.ceil(newLng);}
163 else{newLngTrunc = Math.floor(newLng);}
164
165 //Construct query
166 query += "(";
167 query += "LA:" + coordToAbsDirected(newLatTrunc, "lat");
168 if(latDelta != 1)
169 {
170 query += "+AND+";
171 query += "LA:" + newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1);
172 }
173 query += "+AND+";
174 query += "LN:" + coordToAbsDirected(newLngTrunc, "lng");
175 if(lngDelta != 1)
176 {
177 query += "+AND+";
178 query += "LN:" + newLngString.substring(newLngString.indexOf(".") + 1, newLngString.indexOf(".") + lngPrecision + 1);
179 }
180 query += ")";
181
182 if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; }
183 }
184 }
185
186 //var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
187 var url = gs.xsltParams.library_name;
188 var data = "a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
189 $.ajax({type:"POST", url:url, data:data})
190 .success(function(responseText)
191 {
192 //console.log("*** responseText (first 250) = " + responseText.substring(0,256));
193
194 if(responseText.search("id=\"jsonNodes") != -1)
195 {
196 var startIndex = responseText.indexOf(">");
197 var endIndex = responseText.indexOf("</");
198
199 var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
200 if(jsonNodes && jsonNodes.length > 0)
201 {
202 for(var i = 0; i < jsonNodes.length; i++)
203 {
204 var doc = jsonNodes[i];
205
206 var found = false;
207 for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
208
209 if(!found)
210 {
211 _docList[doc.nodeID] = doc;
212 _docList.ids.push(doc.nodeID);
213
214 createMarker(doc, false);
215 }
216 }
217 }
218 }
219 else
220 {
221 console.log("No JSON information received");
222 }
223
224 _searchRunning = false;
225 }).fail(function(responseText, textStatus, errorThrown) // fail() has replaced error(), http://api.jquery.com/jquery.ajax/
226 {
227 console.log("In map-scripts.performSearchForMarkers(): Got an error in ajax call");
228 _searchRunning = false;
229 });
230}
231
232function coordToAbsDirected(coord, type)
233{
234 var value = "" + coord;
235 if(coord < 0)
236 {
237 value = value.substring(1);
238 if(type == "lat")
239 {
240 value += "S";
241 }
242 else
243 {
244 value += "W";
245 }
246 }
247 else
248 {
249 if(type == "lat")
250 {
251 value += "N";
252 }
253 else
254 {
255 value += "E";
256 }
257 }
258
259 return value;
260}
261
262function updateMap()
263{
264 var markersOnMap = 0;
265 var bounds = new google.maps.LatLngBounds();
266 for(var i = 0; i < _docList.ids.length; i++)
267 {
268 var doc = _docList.getDocByIndex(i);
269 if(doc.parentCL && doc.parentCL.style.display == "none")
270 {
271 doc.marker.setVisible(false);
272 continue;
273 }
274 else
275 {
276 doc.marker.setVisible(true);
277 markersOnMap++;
278 }
279
280 bounds.extend(new google.maps.LatLng(doc.lat, doc.lng));
281 }
282
283 if(markersOnMap > 1)
284 {
285 _map.fitBounds(bounds);
286 } else if (markersOnMap == 1) {
287 // sometimes a single point bounds are too small for the map to display, so use center and zoom instead of fitbounds.
288 _map.setCenter(bounds.getCenter());
289 _map.setZoom(18); // arbitrary value that looked nice for my example
290 }
291}
292
293function loopThroughMarkers()
294{
295 if(_docList.ids.length == 0)
296 {
297 return;
298 }
299
300 var visibleMarkers = new Array();
301 for(var i = 0; i < _docList.ids.length; i++)
302 {
303 var doc = _docList.getDocByIndex(i);
304 if(doc.marker.getVisible())
305 {
306 visibleMarkers.push(doc);
307 }
308 }
309
310 if(visibleMarkers.length < 2)
311 {
312 clearAllInfoBoxes();
313 return;
314 }
315
316 clearAllInfoBoxes();
317
318 var elem = null;
319 while(!elem)
320 {
321 if(_docList.loopIndex >= visibleMarkers.length)
322 {
323 _docList.loopIndex = 0;
324 }
325
326 var doc = visibleMarkers[_docList.loopIndex];
327 var elem = gs.jqGet("div" + doc.nodeID);
328 if(elem.length)
329 {
330 elem.css("background", "#BBFFBB");
331 setTimeout(function(){elem.css("background", "");}, 2000);
332 }
333 _docList.loopIndex++;
334 }
335 doc.marker.markerInfo.open(_map, doc.marker);
336}
337
338function attachClickHandler(marker, nodeID)
339{
340 google.maps.event.addListener(marker, 'click', function()
341 {
342 document.location.href = gs.xsltParams.library_name + "?a=d&ed=1&c=" + gs.cgiParams.c + "&d=" + nodeID + "&dt=hierarchy&p.a=b&p.sa=&p.s=ClassifierBrowse";
343
344 });
345
346 if (("docEdit" in gs.cgiParams) && (gs.cgiParams['docEdit'])) {
347 google.maps.event.addListener(marker, 'mouseup', function()
348 {
349 var lat = marker.getPosition().lat();
350 var lng = marker.getPosition().lng();
351 var collection = gs.cgiParams.c;
352 var site_name = gs.xsltParams.site_name;
353
354 if (nodeID == "") {
355 nodeID = gs.cgiParams.d;
356 }
357 console.log("GPS Click handler in collection:" + collection + " in site: " + site_name + " for Doc: " + nodeID + "(" + lat + "," + lng + ")");
358
359 var callbackFunction = function(){console.log("Completed saving metadata changes. You must rebuild the collection for the changes to take effect.");};
360
361 // set 5th parameter, metapos (metadata position) or 7th param prevMetaValue (previous metadata value) to non-null if you want metamode=override to work
362 // if neither of these 2 are set, then metamode is changed to 'accumulate' instead.
363 gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Latitude", null, lat, null, "override", function(){callbackFunction();});
364 gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Longitude", null, lng, null, "override", function(){callbackFunction();});
365 console.log(nodeID);
366 console.log("GPS Click handler in collection:" + collection + " in site: " + site_name + " for Doc: " + nodeID + "(" + lat + "," + lng + ")");
367 });
368 }
369}
370
371function focusDocument(id)
372{
373 var doc = _docList[id];
374 if(doc)
375 {
376 clearInterval(_intervalHandle);
377 _intervalHandle = null;
378 _map.panTo(new google.maps.LatLng(doc.lat, doc.lng));
379 clearAllInfoBoxes();
380 doc.marker.markerInfo.open(_map, doc.marker);
381 var scrollCheckbox = $("#scrollCheckbox");
382 if(scrollCheckbox.checked)
383 {
384 scrollCheckbox.checked = false;
385 }
386 }
387}
388
389function clearAllInfoBoxes()
390{
391 for(var i = 0; i < _docList.ids.length; i++)
392 {
393 var doc = _docList.getDocByIndex(i);
394 doc.marker.markerInfo.close();
395 }
396}
397
398function createMarker(doc, mainMarker)
399{
400 var pos = new google.maps.LatLng(doc.lat,doc.lng);
401
402 var docEdit = (("docEdit" in gs.cgiParams) && (gs.cgiParams['docEdit']));
403 //var draggable_val = (docEdit) ? true : false;
404
405 // When user logs out, the very first page they're returned to has logout set
406 // If the user logged out when leaving docEdit on, then the very first page has docEdit=1 AND logout.
407 // In that case, don't allow editing. Subsequent pages in logged out mode have neither logout nor docEdit=1 set.
408 var loggedOutVar = ("logout" in gs.cgiParams);
409
410 // Don't allow dragging if either 1. docEdit not on OR 2. logout is in the cgiParams
411 var draggable_val = (!docEdit || loggedOutVar) ? false : true;
412
413 var marker
414 if(mainMarker)
415 {
416 marker = new google.maps.Marker
417 ({
418 position: pos,
419 title:doc.title,
420 map:_map,
421 draggable: draggable_val
422 });
423 }
424 else
425 {
426 marker = new google.maps.Marker
427 ({
428 position: pos,
429 title:doc.title,
430 map:_map,
431 icon:"interfaces/" + gs.xsltParams.interface_name + "/images/bluemarker.png",
432 draggable: draggable_val
433 });
434 }
435
436 var docElement = gs.jqGet("div" + doc.nodeID);
437 var parent;
438 if(docElement)
439 {
440 parent = docElement.parentNode;
441 }
442
443 while(parent && parent.nodeName != "BODY")
444 {
445 if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1)
446 {
447 doc.parentCL = parent;
448 break;
449 }
450
451 parent = parent.parentNode;
452 }
453
454 var info = new google.maps.InfoWindow({content:doc.title});
455 marker.markerInfo = info;
456 doc.marker = marker;
457 attachClickHandler(marker, doc.nodeID);
458
459 ////////////////////////////////////////////////////// TEST
460
461 newLat = marker.getPosition().lat();
462 newLng = marker.getPosition().lng();
463 //console.log("Latitude " + newLat);
464 //console.log("Longitude " + newLng);
465 //NewLatLng(newLat, newLng);
466
467// // Define the LatLng coordinates for the polygon's path.
468// var triangleCoords = [
469// {lat: 18.774, lng: -80.190},
470// {lat: 18.466, lng: -64.600},
471// {lat: 32.321, lng: -64.757},
472// {lat: 32.300, lng: -80.190},
473// {lat: 28.300, lng: -90.190}
474// ];
475//
476// // Construct the polygon.
477// var bermudaTriangle = new google.maps.Polygon({
478// paths: triangleCoords,
479// strokeColor: '#FF0000',
480// strokeOpacity: 0.8,
481// strokeWeight: 2,
482// fillColor: '#FF0000',
483// fillOpacity: 0.35
484// });
485// bermudaTriangle.setMap(map);
486}
487
488function NewLatLng(lat, lng)
489{
490 console.log("Latitude " + lat);
491 console.log("Longitude " + lng);
492}
493
494function getSubClassifier(sectionID)
495{
496 var url = gs.xsltParams.library_name + "?a=b&rt=s&s=ClassifierBrowse&c=" + gs.cgiParams.c + "&cl=" + sectionID + "&excerptid=jsonNodes";
497 $.ajax(url)
498 .success(function(responseText)
499 {
500 var startIndex = responseText.indexOf(">");
501 var endIndex = responseText.indexOf("</");
502
503 var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
504 if(jsonNodes && jsonNodes.length > 0)
505 {
506 for(var i = 0; i < jsonNodes.length; i++)
507 {
508 var doc = jsonNodes[i];
509 _docList[doc.nodeID] = doc;
510 _docList.ids.push(doc.nodeID);
511
512 createMarker(doc, false);
513 }
514
515 $("#map_canvas").css({"visibility": "visible", "height": ""});
516 }
517
518 updateMap();
519 })
520 .error(function()
521 {
522 console.log("Error getting subclassifiers");
523 return;
524 });
525}
526
527function performDistanceSearch(id, lat, lng, degrees)
528{
529 if(parseFloat(lat) > 180 || parseFloat(lat) < -180 || parseFloat(lng) > 180 || parseFloat(lat) < -180)
530 {
531 console.log("Latitude or longitude incorrectly formatted");
532 return;
533 }
534
535 if(lat.indexOf(".") == -1 || lng.indexOf(".") == -1 || (lat.indexOf(".") + 3) >= lat.length || (lng.indexOf(".") + 3) >= lng.length)
536 {
537 console.log("Latitude or longitude does not have the required precision for a distance search");
538 return;
539 }
540
541 var query = "";
542 for(var i = 0; i < degrees * 2; i++)
543 {
544 for (var j = 0; j < degrees * 2; j++)
545 {
546 var latDelta = (i - degrees) * 0.01;
547 var lngDelta = (j - degrees) * 0.01;
548
549 query += "(" + getDistanceQueryString(lat, latDelta, 2, "LA", ["N","S"]);
550 query += "+AND+";
551 query += getDistanceQueryString(lng, lngDelta, 2, "LN", ["E","W"]) + ")";
552
553 if(i != ((degrees * 2) - 1) || j != ((degrees * 2) - 1)){ query += "+OR+"; }
554 }
555 }
556
557 var inlineTemplate = '\
558 <xsl:template match="/" priority="5">\
559 <table id="nearbyDocs">\
560 <tr>\
561 <th><a href="javascript:sortByDistance();">Distance</a></th><th><a href="javascript:sortAlphabetically();">Document</a></th>\
562 </tr>\
563 <xsl:apply-templates select="//documentNode"/>\
564 </table>\
565 </xsl:template>\
566 \
567 <xsl:template match="documentNode" priority="5">\
568 <xsl:if test="@nodeID !=\''+id+'\'">\
569 <tr>\
570 <td>___<gsf:metadata name="Latitude"/>______<gsf:metadata name="Longitude"/>___</td>\
571 <td><gsf:link title="'+gs.text.doc.nearby_doc_tooltip+'" type="document"><gsf:metadata name="Title"/></gsf:link></td>\
572 </tr>\
573 </xsl:if>\
574 </xsl:template>';
575
576 var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20");
577 $.ajax(url)
578 .success(function(response)
579 {
580 response = response.replace(/<img src="[^"]*map_marker.png"[^>]*>/g, "");
581
582 var nearbyDocsArray = new Array();
583
584 var lats = new Array();
585 var lngs = new Array();
586 var matches = response.match(/___(-?[0-9\.]*)___/g);
587 for(var i = 0; i < matches.length; i += 2)
588 {
589 var matchLatFloat = parseFloat(matches[i].replace("___", ""));
590 var matchLngFloat = parseFloat(matches[i+1].replace("___", ""));
591
592 lats.push(matchLatFloat);
593 lngs.push(matchLngFloat);
594 var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0);
595 var distanceString = "" + distance;
596 distanceString = distanceString.substring(0, 6);
597 response = response.replace(matches[i] + matches[i+1], distanceString);
598 }
599
600 var index = 0;
601 var i = 0;
602 while(true)
603 {
604 var distanceStart = response.indexOf("<td>", index);
605 if(distanceStart == -1)
606 {
607 break;
608 }
609 var distanceEnd = response.indexOf("</td>", distanceStart);
610
611 var docLinkStart = response.indexOf("<td>", distanceEnd);
612 var docLinkEnd = response.indexOf("</td>", docLinkStart);
613
614 var dist = response.substring(distanceStart + 4, distanceEnd);
615 var docLink = response.substring(docLinkStart + 4, docLinkEnd);
616
617 _nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});
618
619 index = docLinkEnd;
620 }
621
622 sortByDistance(lat,lng);
623
624 var toggle = $("#nearbyDocumentsToggle");
625 toggle.attr("src", gs.imageURLs.collapse);
626 gs.functions.makeToggle(toggle, $("#nearbyDocuments"));
627 });
628}
629
630var map_centering_timeout = null;
631function recenterMapF(lat, lng)
632{
633 return function() {
634 _map.setCenter(new google.maps.LatLng(lat, lng));
635 }
636}
637function recenterMap(lat, lng)
638{
639
640 _map.setCenter(new google.maps.LatLng(lat, lng));
641
642}
643function sortByDistance(base_lat,base_lng)
644{
645 var sortedTable = '<table id="nearbyDocs" onmouseleave="clearTimeout(map_centering_timeout); recenterMap('+base_lat+','+base_lng+');"><tr><th><a href="javascript:;">Distance</a></th><th><a href="javascript:sortAlphabetically('+base_lat+', '+base_lng+');">Document</a></th></tr>';
646 _nearbyDocs.sort(function(a, b){return (a.distance - b.distance);});
647 for(var i = 0; i < _nearbyDocs.length; i++)
648 {
649
650 sortedTable += "<tr><td>" + prettifyDistance(_nearbyDocs[i].distance) + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '), 900)" >' + _nearbyDocs[i].title + "</td></tr>";
651 }
652 sortedTable += "</table>";
653
654 $("#nearbyDocuments").html(sortedTable);
655}
656function prettifyDistance(distance) {
657
658 var new_distance;
659 if (distance < 1) {
660 new_distance = (distance * 1000);
661 // Round to nearest whole number - don't need to show points of metres..
662 new_distance = Math.round(new_distance);
663 new_distance += " m";
664 }
665 else {
666 new_distance = distance +" km";
667
668 }
669 return new_distance;
670}
671
672
673
674function sortAlphabetically(base_lat, base_lng)
675{
676 var sortedTable = '<table id="nearbyDocs" onmouseleave="clearTimeout(map_centering_timeout); recenterMap('+base_lat+','+base_lng+');"><tr><th><a href="javascript:sortByDistance('+base_lat+', '+base_lng+');">Distance</a></th><th><a href="javascript:;">Document</a></th></tr>';
677 _nearbyDocs.sort(function(a, b)
678 {
679 var firstTitleStartIndex = a.title.indexOf(">");
680 var firstTitleEndIndex = a.title.indexOf("<", firstTitleStartIndex);
681 var firstTitle = a.title.substring(firstTitleStartIndex + 1, firstTitleEndIndex);
682 var secondTitleStartIndex = b.title.indexOf(">");
683 var secondTitleEndIndex = b.title.indexOf("<", secondTitleStartIndex);
684 var secondTitle = b.title.substring(secondTitleStartIndex + 1, secondTitleEndIndex);
685 return ((firstTitle.toLowerCase() == secondTitle.toLowerCase()) ? 0 : ((firstTitle.toLowerCase() > secondTitle.toLowerCase()) ? 1 : -1));
686 });
687 for(var i = 0; i < _nearbyDocs.length; i++)
688 {
689 sortedTable += "<tr><td>" + _nearbyDocs[i].distance + '</td><td onmouseover="clearTimeout(map_centering_timeout); map_centering_timeout = setTimeout(recenterMapF(' + _nearbyDocs[i].lat + ',' + _nearbyDocs[i].lng + '), 900)">' + _nearbyDocs[i].title + "</td></tr>";
690 }
691 sortedTable += "</table>";
692
693 $("#nearbyDocuments").html(sortedTable);
694}
695
696function getDistanceQueryString(currentCoord, delta, precision, indexName, dirs)
697{
698 var query = "";
699 var coordFloat = parseFloat(currentCoord);
700
701 var newCoord = "" + (coordFloat + delta);
702 var beforeDec = newCoord.substring(0, newCoord.indexOf("."));
703
704 var dir = dirs[0];
705 if(coordFloat < 0)
706 {
707 dir = dirs[1];
708 beforeDec = beforeDec.substring(1);
709 }
710 beforeDec += dir;
711
712 var afterDec = newCoord.substring(newCoord.indexOf(".") + 1, newCoord.indexOf(".") + (precision) + 1);
713
714 return indexName + ":" + beforeDec + "+AND+" + indexName + ":" + afterDec;
715}
716
717function modifyFunctions()
718{
719 toggleSection = function(sectionID)
720 {
721 var section = gs.jqGet("div" + sectionID);
722 var sectionToggle = gs.jqGet("toggle" + sectionID);
723
724 if(sectionToggle == undefined)
725 {
726 return;
727 }
728
729 // Test if 'section' exists.
730 // ==> Because we're using jQuery to do this we need to test the length of the object returned
731 // http://stackoverflow.com/questions/920236/how-can-i-detect-if-a-selector-returns-null
732 if(section.length !== 0)
733 {
734 if(isExpanded(sectionID))
735 {
736 section.css("display", "none");
737 sectionToggle.attr("src", gs.imageURLs.expand);
738
739 if(openClassifiers[sectionID].length !== 0) //if(openClassifiers[sectionID] != undefined)
740 {
741 delete openClassifiers[sectionID];
742 }
743 }
744 else
745 {
746 section.css("display", "block");
747 sectionToggle.attr("src", gs.imageURLs.collapse);
748 openClassifiers[sectionID] = true;
749 }
750 updateOpenClassifiers();
751 updateMap();
752 }
753 else
754 {
755 httpRequest(sectionID);
756 }
757 }
758
759 httpRequest = function(sectionID)
760 {
761 if(!inProgress[sectionID])
762 {
763 inProgress[sectionID] = true;
764
765 var sectionToggle = gs.jqGet("toggle" + sectionID);
766 sectionToggle.attr("src", gs.imageURLs.loading);
767
768 var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
769
770 if(gs.cgiParams.berrybasket == "on")
771 {
772 url = url + "&berrybasket=on";
773 }
774
775 if(url.indexOf("#") != -1)
776 {
777 url = url.substring(0, url.indexOf("#"));
778 }
779
780 $.ajax(url)
781 .success(function(responseText)
782 {
783 var newDiv = $("<div>");
784 var sibling = gs.jqGet("title" + sectionID);
785 sibling.after(newDiv);
786
787 newDiv.html(responseText);
788 sectionToggle.attr("src", gs.imageURLs.collapse);
789 openClassifiers[sectionID] = true;
790
791 if(gs.cgiParams.berrybasket == "on")
792 {
793 checkout();
794 }
795 updateOpenClassifiers();
796 getSubClassifier(sectionID);
797 })
798 .error(function()
799 {
800 sectionToggle.attr("src", gs.imageURLs.expand);
801 })
802 .complete(function()
803 {
804 inProgress[sectionID] = false;
805 busy = false;
806 });
807 }
808 }
809}
Note: See TracBrowser for help on using the repository browser.