PageSourceSearch

https://visitvukovar.hr/wp-content/plugins/another-events-calendar/public/js/aec-public.js?ver=1.7.0

js visitvukovar.hr collected 2026-10-03 01:02:23 UTC 9,674 bytes, 355 lines download raw bytes

1(function( $ ) {
2	'use strict';
3
4	/*
5	 *  This function will render a Google Map onto the selected jQuery element
6	 *
7	 *  @since	1.0.0
8	 */
9	function aec_map( $el ) {
10		
11		// var
12		var $markers = $el.find('.marker');
13
14		// vars
15		var args = {
16			zoom		: parseInt( aec.zoom ),
17			center		: new google.maps.LatLng( 0, 0 ),
18			mapTypeId	: google.maps.MapTypeId.ROADMAP
19		};
20		
21		// create map	        	
22		var map = new google.maps.Map( $el[0], args );
23		
24		// add a marker reference
25		map.markers = [];
26			
27		if( $el.data('type') == 'normal' ) {
28			
29			// add markers
30			$markers.each(function(){
31				
32				aec_add_marker( $(this), map );
33				aec_center_map( map );
34				
35			});	
36		
37		} else {
38		
39			// Add marker
40			var latitude  = $('#aec-latitude').val();
41			var longitude = $('#aec-longitude').val();
42			var geocoder  = new google.maps.Geocoder();
43	
44			if( '' != latitude && '' != longitude ) {
45					
46				$markers.data( 'latitude', latitude );
47				$markers.data( 'longitude', longitude );
48				aec_add_marker( $markers, map );		
49				aec_center_map( map );
50	
51			} else {
52				
53				var default_location = $el.data('default_location');
54				geocoder.geocode( { 'address': default_location }, function( results, status ) {
55					if( status == google.maps.GeocoderStatus.OK ) {
56						aec_update_latlng( results[0].geometry.location.lat(), results[0].geometry.location.lng() );
57						$markers.data( 'latitude', results[0].geometry.location.lat() );
58						$markers.data( 'longitude', results[0].geometry.location.lng() );
59						aec_add_marker( $markers, map );		
60						aec_center_map( map );			
61					}
62				});
63				
64			};
65		} 
66		
67		// Update marker position on address change
68		$('.aec-map-field').on('blur', function() {
69			var address = [];
70			
71			if( $('#aec-venue-address').val() ) address.push( $('#aec-venue-address').val() );
72			if( $('#aec-venue-city').val() ) address.push( $('#aec-venue-city').val() );
73			if( $('#aec-venue-country').val() ) address.push( $("#aec-venue-country option:selected").text() );
74			if( $('#aec-venue-state').val() ) address.push( $('#aec-venue-state').val() );
75			if( $('#aec-venue-pincode').val() ) address.push( $('#aec-venue-pincode').val() );
76			
77			address = address.join();
78
79			geocoder.geocode( { 'address': address}, function( results, status ) {
80      			if( status == google.maps.GeocoderStatus.OK) {
81					map.markers[0].setPosition( results[0].geometry.location );
82					aec_update_latlng( results[0].geometry.location.lat(), results[0].geometry.location.lng() );
83					aec_center_map( map );					
84      			}
85    		});
86			
87		});
88		
89		// An ugly fix to display the hidden map element by resizing itself
90		$( 'select#aec-venues' ).on( "click", function() {
91														
92			if( -1 == $( this ).val() ) {
93				google.maps.event.trigger( map, "resize" );
94				aec_center_map( map );
95			}
96			
97		});
98		
99		// When modal window is open, this script resizes the map and resets the map center
100		$( '#aec-map-modal' ).on( "shown.bs.modal", function() {
101															 
102			google.maps.event.trigger( map, "resize" );
103      		aec_center_map( map );
104			
105		});
106		
107					
108	}
109	
110	/*
111	*  This function will add a marker to the selected Google Map
112	*
113	*  @since	1.0.0
114	*/	
115	function aec_add_marker( $markers, map ) {
116	
117		 // var
118		var latlng = new google.maps.LatLng( $markers.data( 'latitude' ), $markers.data( 'longitude' ) );
119		
120		// check to see if any of the existing markers match the latlng of the new marker
121		if( map.markers.length ) {
122			for( var i = 0; i < map.markers.length; i++ ) {
123				var existing_marker = map.markers[i];
124				var pos = existing_marker.getPosition();
125	
126				// if a marker already exists in the same position as this marker
127				if( latlng.equals( pos ) ) {
128					// update the position of the coincident marker by applying a small multipler to its coordinates
129					var latitude  = latlng.lat() + ( Math.random() - .5 ) / 1500; // * (Math.random() * (max - min) + min);
130					var longitude = latlng.lng() + ( Math.random() - .5 ) / 1500; // * (Math.random() * (max - min) + min);
131					latlng = new google.maps.LatLng( latitude, longitude );
132				}
133			}
134		}
135		
136		// create marker
137		var marker = new google.maps.Marker({
138			position  : latlng,
139			map		  : map,
140			draggable : ( map.type == 'form' ) ? true : false
141		});
142	
143		// add to array
144		map.markers.push( marker );
145	
146		// if marker contains HTML, add it to an infoWindow
147		if( $markers.html() ) {
148			// create info window
149			var infowindow = new google.maps.InfoWindow({
150				content	: $markers.html()
151			});
152	
153			// show info window when marker is clicked
154			google.maps.event.addListener(marker, 'click', function() {
155	
156				infowindow.open( map, marker );
157	
158			});
159		};
160		
161		// update latitude and longitude values in the form when marker is moved
162		if( map.type == 'form' ) {
163			google.maps.event.addListener(marker, "dragend", function() {
164																  
165				var point = marker.getPosition();
166				map.panTo(point);
167				update_latlng(point);
168			
169			});	
170		};
171	
172	}		  
173	
174	/*
175	 *  This function will center the map, showing all markers attached to this map
176	 *	
177	 *  @since	1.0.0
178	 */	
179	function aec_center_map( map ) {
180		
181		var bounds = new google.maps.LatLngBounds();
182	
183		if( map.markers.length > 1 ) {
184			
185			// fit to bounds
186			 var listener = google.maps.event.addListener(map, 'idle', function() {
187				
188				// loop through all markers and create bounds
189				$.each( map.markers, function( i, marker ){
190					var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
191					bounds.extend( latlng );
192				});
193		
194				map.setZoom( parseInt( aec.zoom ) );
195    			map.fitBounds( bounds );
196				
197				// Marker Cluster
198				var markerCluster = new MarkerClusterer( map, map.markers, { imagePath : aec.plugin_url+'public/images/m' } );
199				
200				google.maps.event.removeListener(listener); 
201				
202			});
203
204		} else {			
205		
206			// loop through all markers and create bounds
207				$.each( map.markers, function( i, marker ){
208					var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
209					bounds.extend( latlng );
210				});
211			
212			map.setCenter( bounds.getCenter() );		
213			map.setZoom( parseInt( aec.zoom ) );
214
215		}			
216	
217	}
218	
219	/*
220	*  Update latlng values in the event or venue forms.
221	*
222	*  @since	1.5.4
223	*/	
224	function aec_update_latlng( lat, lng ) {
225		
226		$( '#aec-latitude' ).val( lat );
227		$( '#aec-longitude' ).val( lng );
228		
229	}
230	
231	/*
232	 *  On Document Ready
233	 *
234	 *  @since	1.0.0
235	 */	
236	$(function() {
237	
238		// Add date picker in the search widget(s)
239		$( ".aec-date-picker" ).datepicker({
240			dateFormat: 'yy-mm-dd'
241		});	
242		
243		// Add map in custom post type 'aec_venues'
244		$( '.aec-map' ).each(function() {
245			var data = {
246				'type' : $(this).data('type'),	
247			};
248			aec_map( $(this), data['type'] );
249		});
250		
251		// Add Mini-calendar
252		$( 'body' ).on( 'click', '.aec-mini-calendar-nav', function( e ) {
253			e.preventDefault();
254
255			var data = {
256				'action'	: 'aec_mini_calendar',
257				'mo'        : $(this).data('month'),
258				'yr'    	: $(this).data('year'),
259				'widget_id' : $(this).data('id'),
260			};	
261			
262			$( '.aec-spinner-container', '#' + data['widget_id'] ).html( '<div class="aec-spinner"></div>' );
263			
264			jQuery.post( aec.ajaxurl, data, function( response ) {
265				$( '#' + data['widget_id'] ).replaceWith( response );
266			});
267		
268		});
269		
270		// Show / Hide time selectors in the event submission form
271		$( '#aec-all-day-event' ).on( 'change', function() {
272											  
273			if( $( "#aec-all-day-event" ).is( ":checked" ) ) { 
274				$( '.aec-event-time-fields' ).hide(); 
275			} else {
276				$( '.aec-event-time-fields' ).show();
277			}
278			
279		}).trigger( 'change' );	
280		
281		// Show / Hide recurring events in the event submission form
282		$( '#aec-recurring-event' ).on( 'change', function () {
283											  
284			if ( $( "#aec-recurring-event" ).is( ":checked" ) ) { 
285				$( '.aec-recurring-event-fields' ).show(); 
286			} else {
287				$( '.aec-recurring-event-fields' ).hide();
288			}
289			
290		});
291		
292		// Show / Hide recurring settings based on the recurring type in the event submission form
293		$( '#aec-recurring-frequency' ).on( 'change', function() {
294
295			$( '.aec-recurring-settings' ).hide();
296			
297			var value = $( this ).val();
298			switch( value ) {
299				case 'daily' :
300					$( '.aec-daily-recurrence' ).show();
301					break;
302				case 'weekly' :
303					$( '.aec-weekly-recurrence' ).show();
304					break;
305				case 'monthly' :
306					$( '.aec-monthly-recurrence' ).show();
307					break;
308			};
309			
310		}).trigger( 'change' );
311		
312		// Show / Hide Venue fields in the event submission form
313		$( '#aec-venues' ).on( 'change', function() {											 
314			
315        	var value = $( this ).val();
316			
317        	 if( -1 == value ) {
318            	$( '#aec-venue-fields' ).show();
319			} else {
320				$( '#aec-venue-fields' ).hide();
321			}
322			
323    	}).trigger( 'change' );	
324		
325		// Show / Hide Organizer fields in the event submission form
326		$( '#aec-add-new-organizer' ).on( 'click', function() {
327
328			$( '#aec-organizer-fields' ).find( '.aec-organizer-fields .aec-organizer-group-id' ).html( aec.i18n_organizer + ' #' + $( '.aec-organizer-fields' ).length );
329			var $clone = $( '#aec-organizer-fields' ).find( '.aec-organizer-fields' ).clone( false ); 
330			$( '#aec-organizer-fields-container' ).append( $clone );
331			
332		});
333		
334		// Delete image attachment
335		$( '#aec-img-delete' ).on( 'click', function( e ) {
336
337			e.preventDefault();
338			
339			var $this = $( this );
340			
341			var data = {
342				'action'        : 'aec_public_delete_attachment',
343				'post_id'       : $this.data( 'post_id' ),
344				'attachment_id' : $this.data( 'attachment_id' )
345			};
346			
347			$.post( aec.ajaxurl, data, function( response ) {
348				$( '#aec-img-preview' ).remove();
349			});
350			
351		});
352					
353	});
354
355})( 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.