]> projects.mako.cc - selectricity/blob - vendor/plugins/ym4r_gm/javascript/ym4r-gm.js
Added the forgot password functionality to the voters of Full Elections. Also, modifi...
[selectricity] / vendor / plugins / ym4r_gm / javascript / ym4r-gm.js
1 // JS helper functions for YM4R\r
2 \r
3 function addInfoWindowToMarker(marker,info,options){\r
4         GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(info,options);});\r
5         return marker;\r
6 }\r
7 \r
8 function addInfoWindowTabsToMarker(marker,info,options){\r
9      GEvent.addListener(marker, "click", function() {marker.openInfoWindowTabsHtml(info,options);});\r
10      return marker;\r
11 }\r
12 \r
13 function addPropertiesToLayer(layer,getTile,copyright,opacity,isPng){\r
14     layer.getTileUrl = getTile;\r
15     layer.getCopyright = copyright;\r
16     layer.getOpacity = opacity;\r
17     layer.isPng = isPng;\r
18     return layer;\r
19 }\r
20 \r
21 function addOptionsToIcon(icon,options){\r
22     for(var k in options){\r
23         icon[k] = options[k];\r
24     }\r
25     return icon;\r
26 }\r
27 \r
28 function addCodeToFunction(func,code){\r
29     if(func == undefined)\r
30         return code;\r
31     else{\r
32         return function(){\r
33             func();\r
34             code();\r
35         }\r
36     }\r
37 }\r
38 \r
39 function addGeocodingToMarker(marker,address){\r
40     marker.orig_initialize = marker.initialize;\r
41     orig_redraw = marker.redraw;\r
42     marker.redraw = function(force){}; //empty the redraw method so no error when called by addOverlay.\r
43     marker.initialize = function(map){\r
44         new GClientGeocoder().getLatLng(address,\r
45                                         function(latlng){\r
46             if(latlng){\r
47                 marker.redraw = orig_redraw;\r
48                 marker.orig_initialize(map); //init before setting point\r
49                 marker.setPoint(latlng);\r
50             }//do nothing\r
51         });\r
52     };\r
53     return marker;\r
54 }\r
55 \r
56 \r
57 \r
58 GMap2.prototype.centerAndZoomOnMarkers = function(markers) {\r
59      var bounds = new GLatLngBounds(markers[0].getPoint(),\r
60                                     markers[0].getPoint());\r
61      for (var i=1, len = markers.length ; i<len; i++) {\r
62          bounds.extend(markers[i].getPoint());\r
63      }\r
64      \r
65      this.centerAndZoomOnBounds(bounds);\r
66  } \r
67 \r
68 GMap2.prototype.centerAndZoomOnPoints = function(points) {\r
69      var bounds = new GLatLngBounds(points[0],\r
70                                     points[0]);\r
71      for (var i=1, len = points.length ; i<len; i++) {\r
72          bounds.extend(points[i]);\r
73      }\r
74      \r
75      this.centerAndZoomOnBounds(bounds);\r
76  } \r
77 \r
78 GMap2.prototype.centerAndZoomOnBounds = function(bounds) {\r
79     var center = bounds.getCenter();\r
80     this.setCenter(center, this.getBoundsZoomLevel(bounds));\r
81\r
82 \r
83 //For full screen mode\r
84 function setWindowDims(elem) {\r
85     if (window.innerWidth){\r
86         elem.style.height = (window.innerHeight) + 'px;';\r
87         elem.style.width = (window.innerWidth) + 'px;';\r
88     }else if (document.body.clientWidth){\r
89         elem.style.width = (document.body.clientWidth) + 'px';\r
90         elem.style.height = (document.body.clientHeight) + 'px';\r
91     }\r
92 }\r
93 \r
94 ManagedMarker = function(markers,minZoom,maxZoom) {\r
95     this.markers = markers;\r
96     this.minZoom = minZoom;\r
97     this.maxZoom = maxZoom;\r
98 }\r
99 \r
100 //Add the markers and refresh\r
101 function addMarkersToManager(manager,managedMarkers){\r
102     for(var i = 0, length = managedMarkers.length; i < length;i++) {\r
103         mm = managedMarkers[i];\r
104         manager.addMarkers(mm.markers,mm.minZoom,mm.maxZoom);\r
105     }\r
106     manager.refresh();\r
107     return manager;\r
108 }\r
109 \r
110 \r
111 var INVISIBLE = new GLatLng(0,0); //almost always invisible\r
112 \r
113 if(self.Event && Event.observe){\r
114     Event.observe(window, 'unload', GUnload);\r
115 }else{\r
116     window.onunload = GUnload;\r
117 }\r

Benjamin Mako Hill || Want to submit a patch?