PageSourceSearch

https://museuminsider.co.uk/wp-content/plugins/codepeople-post-map_old/js/cpm.js

js museuminsider.co.uk collected 2026-10-02 13:04:15 UTC 13,686 bytes, 544 lines download raw bytes

1/**
2 * CodePeople Post Map
3 * Version: 1.0.1
4 * Author: CodePeople
5 * Plugin URI: http://wordpress.dwbooster.com
6*/
7
8var CodePeoplePostMapPublicCounter = 0;
9function CodePeoplePostMapPublic()
10{
11	CodePeoplePostMapPublicCounter++;
12	if( typeof jQuery == 'undefined' )
13	{
14		if( CodePeoplePostMapPublicCounter <= 6 ) setTimeout( function(){ CodePeoplePostMapPublic() }, 1000 );
15		return;
16	}
17	jQuery(function( $ ){
18		// Create a class with CodePeople Post Map functionalities and attributes
19		$.CPM = function(id, config){
20			this.data = $.extend(true, {}, this.defaults, config);
21			this.id = id;
22			this.markers = [];
23			this.uniqueMarkers = [];
24			if( typeof this.data[ 'center' ] == 'object' && typeof this.data.center.length != 'undefined' && this.data.center.length == 2 )
25			{
26				this.data.center = new google.maps.LatLng( this.data.center[ 0 ], this.data.center[ 1 ] );
27			}
28			else
29			{
30				this.data.center = null;
31			}
32		};
33
34		$.CPM.prototype = {
35			defaults : {
36				markers 		: [],
37				marker_title	: 'title',
38				zoom			: 10,
39				dynamic_zoom    : false,
40				drag_map        : true,
41				type			: 'ROADMAP',
42				mousewheel 		: true,
43				scalecontrol 	: true,
44				zoompancontrol 	: true,
45				fullscreencontrol: true,
46				typecontrol 	: true,
47				streetviewcontrol : true,
48				trafficlayer 	: false,
49				show_window     : true,
50				show_default    : true,
51				display			: 'map',
52				highlight		: true,
53				highlight_class : 'cpm_highlight'
54			},
55
56			// private methods to complete every steps in map generation
57			_correct : function( v ){
58				v = (new String(v)).replace(/[^\d\+\-\.]/g, '');
59				return v*1;
60			},
61
62			_empty : function (v){
63				return (!v || /^\s*$/.test(v));
64			},
65
66			_get_latlng : function(i){
67				var me = this,
68					g  = new google.maps.Geocoder(),
69					m  = me.data.markers,
70					a  = m[i]['address'];
71
72				g.geocode({address:a}, function(result, status){
73					me.counter--;
74					if(status && status == "OK"){
75						m[i]['latlng'] = new google.maps.LatLng(me._correct(result[0]['geometry']['location'].lat()), me._correct(result[0]['geometry']['location'].lng()));
76					}else{
77						m[i]['invalid'] = true;
78					}
79
80					// All points have been checked now is possible to load the map
81					if(me.counter == 0){
82						me._load_map();
83					}
84				});
85			},
86			_str_transform : function( t ){
87				return t.replace( /&lt;/g, '<')
88						.replace( /&gt;/g, '>')
89						.replace( /&amp;/g, '&')
90						.replace( /&quot;/g, '"')
91						.replace(/\\'/g, "'")
92						.replace(/\\"/g, '"' );
93			},
94			_unique : function( l ){
95				var rtn = [];
96				this.uniqueMarkers = [];
97				for( var i = 0, h = l.length; i < h; i++ )
98				{
99					if( typeof this.uniqueMarkers[ l[ i ].position.toString() ] == 'undefined' )
100					{
101						this.uniqueMarkers[ l[ i ].position.toString() ] = [];
102						rtn.push( l[ i ] );
103					}
104					else
105					{
106						l[ i ].visible = false;
107					}
108					this.uniqueMarkers[ l[ i ].position.toString() ].push( l[ i ] );
109				}
110
111				return rtn;
112			},
113			_load_map : function(){
114
115				var me = this,
116					m  = me.data.markers,
117					h  = m.length,
118					c  = 0,
119					v  = 0; // Number of valid points
120
121				while(c < h && m[c]['invalid']) c++;
122
123				if(c < h){
124					me.map = new google.maps.Map($('#'+me.id)[0], {
125							zoom: me.data.zoom,
126							center: ( typeof me.data.center != 'undefined' && me.data.center != null ) ? me.data.center : m[c].latlng,
127							mapTypeId: google.maps.MapTypeId[me.data.type],
128							draggable: me.data.drag_map,
129
130							// Show / Hide controls
131							scaleControl: me.data.scalecontrol,
132							zoomControl: me.data.zoompancontrol,
133							mapTypeControl: me.data.typecontrol,
134							streetViewControl: me.data.streetviewcontrol,
135							scrollwheel: me.data.mousewheel,
136							fullscreenControl: me.data.fullscreencontrol,
137							styles: [
138				  {
139					"elementType": "geometry",
140					"stylers": [
141					  {
142						"color": "#f5f5f5"
143					  }
144					]
145				  },
146				  {
147					"elementType": "labels.icon",
148					"stylers": [
149					  {
150						"visibility": "off"
151					  }
152					]
153				  },
154				  {
155					"elementType": "labels.text.fill",
156					"stylers": [
157					  {
158						"color": "#616161"
159					  }
160					]
161				  },
162				  {
163					"elementType": "labels.text.stroke",
164					"stylers": [
165					  {
166						"color": "#f5f5f5"
167					  }
168					]
169				  },
170				  {
171					"featureType": "administrative.land_parcel",
172					"elementType": "labels.text.fill",
173					"stylers": [
174					  {
175						"color": "#bdbdbd"
176					  }
177					]
178				  },
179				  {
180					"featureType": "poi",
181					"elementType": "geometry",
182					"stylers": [
183					  {
184						"color": "#eeeeee"
185					  }
186					]
187				  },
188				  {
189					"featureType": "poi",
190					"elementType": "labels.text.fill",
191					"stylers": [
192					  {
193						"color": "#757575"
194					  }
195					]
196				  },
197				  {
198					"featureType": "poi.park",
199					"elementType": "geometry",
200					"stylers": [
201					  {
202						"color": "#e5e5e5"
203					  }
204					]
205				  },
206				  {
207					"featureType": "poi.park",
208					"elementType": "labels.text.fill",
209					"stylers": [
210					  {
211						"color": "#9e9e9e"
212					  }
213					]
214				  },
215				  {
216					"featureType": "road",
217					"elementType": "geometry",
218					"stylers": [
219					  {
220						"color": "#ffffff"
221					  }
222					]
223				  },
224				  {
225					"featureType": "road.arterial",
226					"elementType": "labels.text.fill",
227					"stylers": [
228					  {
229						"color": "#757575"
230					  }
231					]
232				  },
233				  {
234					"featureType": "road.highway",
235					"elementType": "geometry",
236					"stylers": [
237					  {
238						"color": "#dadada"
239					  }
240					]
241				  },
242				  {
243					"featureType": "road.highway",
244					"elementType": "labels.text.fill",
245					"stylers": [
246					  {
247						"color": "#616161"
248					  }
249					]
250				  },
251				  {
252					"featureType": "road.local",
253					"elementType": "labels.text.fill",
254					"stylers": [
255					  {
256						"color": "#9e9e9e"
257					  }
258					]
259				  },
260				  {
261					"featureType": "transit.line",
262					"elementType": "geometry",
263					"stylers": [
264					  {
265						"color": "#e5e5e5"
266					  }
267					]
268				  },
269				  {
270					"featureType": "transit.station",
271					"elementType": "geometry",
272					"stylers": [
273					  {
274						"color": "#eeeeee"
275					  }
276					]
277				  },
278				  {
279					"featureType": "water",
280					"elementType": "geometry",
281					"stylers": [
282					  {
283						"color": "#c9c9c9"
284					  }
285					]
286				  },
287				  {
288					"featureType": "water",
289					"elementType": "labels.text.fill",
290					"stylers": [
291					  {
292						"color": "#9e9e9e"
293					  }
294					]
295				  }
296				]
297					});
298
299					var map = me.map,
300						bounds = new google.maps.LatLngBounds(),
301						default_point = -1;
302
303					if(me.data.trafficlayer)
304					{
305						var trafficLayer = new google.maps.TrafficLayer();
306						trafficLayer.setMap(me.map);
307					}
308
309					if( me.data.show_default ){
310						google.maps.event.addListenerOnce(map, 'idle', function(){
311							setTimeout(function(){
312								if( me.markers.length ) google.maps.event.trigger( ( ( default_point < 0 ) ? me.markers[ 0 ] : me.markers[ default_point ] ), 'click' );
313							}, 1000);
314						});
315					}
316					me.infowindow = new google.maps.InfoWindow();
317					var title = null;
318					for (var i = c; i < h; i++){
319						if(!m[i]['invalid']){
320							if( typeof m[ i ][ 'default' ] != 'undefined' && m[ i ][ 'default' ] )
321							{
322								default_point = me.markers.length;
323							}
324
325							bounds.extend(m[i].latlng);
326
327							if(/title/i.test(me['data']['marker_title']))
328								title = me._str_transform($( m[i].info ).find('.title').text());
329							else if(/address/i.test(me['data']['marker_title']))
330								title = (m[i].address) ? me._str_transform(m[i].address) : '';
331
332							var marker = new google.maps.Marker({
333														  position: m[i].latlng,
334														  map: map,
335														  icon: new google.maps.MarkerImage(m[i].icon.replace(/^http:/i, '')),
336														  title:title
337														 });
338
339							marker.id = i;
340							me.markers.push(marker);
341							google.maps.event.addListener(marker, 'click', function(){ me.o
341pen_infowindow(this); });
342							google.maps.event.addListener(marker, 'mouseover', function(){ me.set_highlight(this); });
343							google.maps.event.addListener(marker, 'mouseout', function(){ me.unset_highlight(this); });
344						}
345					}
346					me._unique( me.markers );
347					if (h > 1 && me.data.dynamic_zoom) {
348						setTimeout( ( function( m, b ){ return function(){ m.fitBounds( b ); }; } )( map, bounds ), 500 );
349					}
350					else if (h == 1 || !me.data.dynamic_zoom) {
351						if( typeof me.data.center != 'undefined' && me.data.center != null )
352						{
353							map.setCenter( me.data.center );
354						}
355						else
356						{
357							if( default_point != -1 )
358							{
359								map.setCenter( me.markers[ default_point ].getPosition() );
360							}
361							else
362							{
363								map.setCenter(bounds.getCenter());
364							}
365						}
366						map.setZoom(me.data.zoom);
367					}
368				}
369				else
370				{
371					$('#'+me.id).hide();
372				}
373			},
374
375			// public methods
376			set_map: function(){
377				if(this.data.markers.length){
378
379					var m = this.data.markers,
380						h = m.length;
381
382					this.counter = h; // Counter is used to know the momment where all latitudes or longitudes were calculated
383
384					for(var i=0; i < h; i++){
385						if(typeof m[i] == 'undefined')
386						{
387							m[i] = {'invalid':true};
388							this.counter--;
389							continue;
390						}else if( (this._empty(m[i].lat) || this._empty(m[i].lng)) && !this._empty(m[i].address)){
391							this._get_latlng(i);
392						}else if(this._empty(m[i].lat) && this._empty(m[i].lng)){
393							// The address is not present so the point may be removed from the list
394							m[i]['invalid'] = true;
395							this.counter--;
396						}else{
397							m[i]['latlng'] = new google.maps.LatLng(this._correct(m[i].lat), this._correct(m[i].lng));
398							this.counter--;
399						}
400
401					}
402
403					// All points have been checked now is possible to load the map
404					if(this.counter == 0){
405						this._load_map();
406					}
407				}
408			},
409
410			// Open the marker bubble
411			open_infowindow : function(m){
412				var me = this,
413					info   = '',
414					unique = me.uniqueMarkers[ m.position.toString() ];
415
416				if ( !me.data.show_window ) return;
417
418				// Get the information of all concident points
419				for( var i = 0, h = unique.length; i < h; i++ )
420				{
421					info += ( i < h-1 ) ? $( '<div></div>').html( me.data.markers[ unique[ i ].id ].info ).find( '.cpm-infowindow-additional' ).remove().end().html() : me.data.markers[ unique[ i ].id ].info;
422				}
423
424				var c  = me._str_transform( info ),
425					img = $( c.replace( '%additional%', '' ) ).find( 'img' );
426
427				if( img.length )
428				{
429					var count = img.length;
430					img.each( function(){
431							$( '<img src="'+$(this).attr( 'src' ) +'">' ).on('load', (function( c, m ){
432							return function(){
433								count--;
434								if( count == 0 )
435								{
436									me.infowindow.setContent( c );
437									me.infowindow.open( me.map, m );
438								}
439							};
440						} )( c, m ) );
441					} );
442				}
443				else
444				{
445					c += '<style>.cpm-infowindow{ min-height:auto !important; } </style>';
446					me.infowindow.setContent( c );
447					me.infowindow.open( me.map, m );
448				}
449				},
450
451			// Set the highlight class to the post with ID m['post']
452			set_highlight : function(m){
453				if(this.data.highlight){
454					var id = this.data.markers[m.id]['post'];
455					$('.post-'+id).addClass(this.data.highlight_class);
456				}
457			},
458
459			// Remove the highlight class from the post with ID m['post_id']
460			unset_highlight : function(m){
461				if(this.data.highlight){
462					var id = this.data.markers[m.id]['post'];
463					$('.post-'+id).removeClass(this.data.highlight_class);
464				}
465			}
466		};
467		// End CPM class definition
468
469		// Callback function to be called after loading the maps api
470		function initialize( e )
471		{
472			var map_container = $( e ),
473				map_id = map_container.attr('id');
474
475			if( map_container.parent().is( ':hidden' ) )
476			{
477				setTimeout( function(){ initialize( e ); }, 500 );
478				return;
479			}
480
481			if(cpm_global && cpm_global[map_id] && cpm_global[map_id]['markers'].length){
482				// The maps data are defined
483				var cpm = new $.CPM(map_id, cpm_global[map_id]);
484
485				// Display map
486				if(cpm_global[map_id]['display'] == 'map'){
487					map_container.show();
488					cpm.set_map();
489				}else{
490					// Insert a icon to display map
491					var map_icon = $('<div class="cpm-mapicon"></div>');
492					map_icon.click(function(){
493						if(map_container.is( ':visible' ))
494						{
495							map_container.hide();
496						}
497						else
498						{
499							map_container.show();
500							cpm.set_map();
501						}
502					});
503					map_icon.insertBefore(map_container);
504				}
505			}
506		};
507
508		window['cpm_init'] = function(){
509			$('.cpm-map').each(function(){
510				if( $( this ).parent().is( ':hidden' ) )
511				{
512					setTimeout(
513						( function ( e )
514							{
515								return function(){ initialize( e ); };
516							} )( this ),
517						500
518					);
519				}
520				else
521				{
522					initialize( this );
523				}
524			});
525		};
526
527		var map = $('.cpm-map');
528		if(map.length){
529			if(typeof google == 'undefined' || google['maps'] == null){
530				// Create the script tag and load the maps api
531				cpm_api_key = "AIzaSyB_Wtk_Hs6YZ3L69PZdihCD8-pa6E_yqAc";
532				var script=document.createElement('script');
533				script.type  = "text/javascript";
534				script.src=(( typeof window.location.protocol != 'undefined' ) ? window.location.protocol : 'http:' )+'//maps.google.com/maps/api/js?'+((typeof cpm_api_key != 'undefined' && cpm_api_key != '')? 'ke
534y='+cpm_api_key+'&' :'')+'callback=cpm_init'+((typeof cpm_language != 'undefined' && cpm_language.lng) ? '&language='+cpm_language.lng: '');
535				document.body.appendChild(script);
536			}else{
537				cpm_init();
538			}
539		}
540	});
541}
542
543if( typeof jQuery == 'undefined' ) setTimeout( function(){ CodePeoplePostMapPublic() }, 1000 );
544else CodePeoplePostMapPublic();

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.