PageSourceSearch

https://thekilroys.org/wp-content/plugins/custom-page-templates/assets/js/acf-google-maps.js?ver=3.0.17

js thekilroys.org collected 2026-10-03 21:45:19 UTC 2,870 bytes, 170 lines download raw bytes

1(function($) {
2
3/*
4*  new_map
5*
6*  This function will render a Google Map onto the selected jQuery element
7*
8*  @type  function
9*  @date  8/11/2013
10*  @since 4.3.0
11*
12*  @param $el (jQuery element)
13*  @return  n/a
14*/
15
16function new_map( $el ) {
17  
18  // var
19  var $markers = $el.find('.marker');
20  var zoom;
21
22  zoom = Number( $el.attr( 'data-zoom' ) );
23  zoom = zoom && ! isNaN( zoom ) ? zoom : 16;
24
25  
26  // vars
27  var args = {
28    zoom    : zoom,
29    center    : new google.maps.LatLng(0, 0),
30    mapTypeId : google.maps.MapTypeId.ROADMAP
31  };
32  
33  
34  // create map           
35  var map = new google.maps.Map( $el[0], args);
36  
37  
38  // add a markers reference
39  map.markers = [];
40  
41  
42  // add markers
43  $markers.each(function(){
44    
45      add_marker( $(this), map );
46    
47  });
48  
49  
50  // center map
51  center_map( map, zoom );
52  
53  
54  // return
55  return map;
56  
57}
58
59/*
60*  add_marker
61*
62*  This function will add a marker to the selected Google Map
63*
64*  @type  function
65*  @date  8/11/2013
66*  @since 4.3.0
67*
68*  @param $marker (jQuery element)
69*  @param map (Google Map object)
70*  @return  n/a
71*/
72
73function add_marker( $marker, map ) {
74
75  // var
76  var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
77
78  // create marker
79  var marker = new google.maps.Marker({
80    position  : latlng,
81    map     : map
82  });
83
84  // add to array
85  map.markers.push( marker );
86
87  // if marker contains HTML, add it to an infoWindow
88  if( $marker.html() )
89  {
90    // create info window
91    var infowindow = new google.maps.InfoWindow({
92      content   : $marker.html()
93    });
94
95    // show info window when marker is clicked
96    google.maps.event.addListener(marker, 'click', function() {
97
98      infowindow.open( map, marker );
99
100    });
101  }
102
103}
104
105/*
106*  center_map
107*
108*  This function will center the map, showing all markers attached to this map
109*
110*  @type  function
111*  @date  8/11/2013
112*  @since 4.3.0
113*
114*  @param map (Google Map object)
115*  @return  n/a
116*/
117
118function center_map( map, zoom ) {
119
120  // vars
121  var bounds = new google.maps.LatLngBounds();
122
123  // loop through all markers and create bounds
124  $.each( map.markers, function( i, marker ){
125
126    var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
127
128    bounds.extend( latlng );
129
130  });
131
132  // only 1 marker?
133  if( map.markers.length == 1 )
134  {
135    // set center of map
136      map.setCenter( bounds.getCenter() );
137      map.setZoom( zoom );
138  }
139  else
140  {
141    // fit to bounds
142    map.fitBounds( bounds );
143  }
144
145}
146
147/*
148*  document ready
149*
150*  This function will render each map when the document is ready (page has loaded)
151*
152*  @type  function
153*  @date  8/11/2013
154*  @since 5.0.0
155*
156*  @param n/a
157*  @return  n/a
158*/
159// global var
160var map = null;
161
162$(document).ready(function(){
163
164  $( '.dsv-acf-google-map' ).each(function(){
165    map = new_map( $(this) );
166  });
167
168});
169
170})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.