1/** 2 * Handle user checkins 3 * 4 * 5 */ 6 7// Locations list is provided by wp_localize_script function 8var userPosition; 9 10var loadTimeout; 11 12// Google maps api is loaded only on demand 13// so just to sleep well it is better to check 14if ( typeof wpbchknShortcodeLocations !== 'undefined' && typeof google === 'object' && typeof google.maps === 'object') { 15 loadTimeout = setTimeout(function(){ loadShortcodeMap( {} ); }, 80000); 16 navigator.geolocation.getCurrentPosition( loadShortcodeMap, loadShortcodeMap ); 17} 18 19function loadShortcodeMap( userPosition ) { 20 "use strict"; 21 22 clearTimeout(loadTimeout); 23 24 var mapContainer = document.getElementById( 'wpbchkn-locations-map' ), 25 mapOptions = { 26 zoom: parseInt(wpbchknShortcodeLocationsAtts.zoom), 27 mapTypeId: google.maps.MapTypeId.ROADMAP 28 }, 29 map = new google.maps.Map( mapContainer, mapOptions ); 30 31 // Loop variables 32 var locationID, 33 checkinLink = ''; 34 35 // Store opened infoWindow globally 36 var openedInfoWindow = {}; 37 38 // Fill map with appropriate marker for each location 39 for ( locationID in wpbchknShortcodeLocations ) { 40 if ( !wpbchknShortcodeLocations.hasOwnProperty( locationID ) ) 41 continue; 42 43 // Location marker 44 wpbchknShortcodeLocations[ locationID ].marker = new google.maps.Marker({ 45 position: new google.maps.LatLng( wpbchknShortcodeLocations[ locationID ].coords.lat, wpbchknShortcodeLocations[ locationID ].coords.lng ), 46 map: map, 47 title: wpbchknShortcodeLocations[ locationID ].title, 48 draggable: false 49 }); 50 51 if ( wpbchknShortcodeLocationsAtts.hasOwnProperty('checkin') && wpbchknShortcodeLocationsAtts.checkin == '1' ) 52 checkinLink = '<a href="javascript:;" data-location="'+ locationID +'">Check In Here</a>'; 53 54 // Location Marker InfoWindow 55 wpbchknShortcodeLocations[ locationID ].infowindow = new google.maps.InfoWindow({ 56 content: '<div id="content">'+ 57 '<div id="siteNotice">'+'</div>'+ 58 '<h4 id="firstHeading" class="firstHeading">'+ wpbchknShortcodeLocations[ locationID ].title +'</h4>'+ 59 '<div id="bodyContent">'+ 60 '<p><strong>Address:</strong> '+ wpbchknShortcodeLocations[ locationID ].addr +'</p>'+ 61 '<p>'+ checkinLink +'</p>'+ 62 '</div>'+ 63 '</div>' 64 }); 65 66 // Connect marker with infoWindow 67 google.maps.event.addListener(wpbchknShortcodeLocations[ locationID ].marker, 'click', function(innerLocationID) { 68 return function() { 69 if ( typeof openedInfoWindow.close == 'function' ) 70 openedInfoWindow.close(); 71 72 openedInfoWindow = wpbchknShortcodeLocations[ innerLocationID ].infowindow; 73 wpbchknShortcodeLocations[ innerLocationID ].infowindow.open(map,wpbchknShortcodeLocations[ innerLocationID ].marker); 74 } 75 }(locationID)); 76 } 77 78 // Style map container 79 mapContainer.style.height = '300px'; 80 81 // Cneter map and add user current position 82 if ( userPosition.hasOwnProperty('coords') ) { 83 userPosition.LatLng = new google.maps.LatLng( userPosition.coords.latitude, userPosition.coords.longitude ); 84 userPosition.marker = new google.maps.Marker({ 85 position: userPosition.LatLng, 86 map: map, 87 title: 'You Are Here', 88 draggable: false 89 }); 90 map.setCenter( userPosition.LatLng ); 91 92 // Add infor window for user position too 93 userPosition.infowindow = new google.maps.InfoWindow({ 94 content: '<div id="content">'+ 95 '<p>You Are Here.</p>'+ 96 '</div>' 97 }); 98 99 google.maps.event.addListener(userPosition.marker, 'click', function(innerLocationID) { 100 return function() { 101 if ( typeof openedInfoWindow.close == 'function' ) 102 openedInfoWindow.close(); 103 104 openedInfoWindow = userPosition.infowindow; 105 106 userPosition.infowindow.open(map, userPosition.marker); 107 } 108 }(locationID)); 109 } else { 110 111 // Last added marker 112 map.setCenter( new google.maps.LatLng( wpbchknShortcodeLocations[ locationID ].coords.lat, wpbchknShortcodeLocations[ locationID ].coords.lng ) ); 113 } 114 115 // Add checkin listner 116 if ( wpbchknShortcodeLocationsAtts.hasOwnProperty('checkin') && wpbchknShortcodeLocationsAtts.checkin == '1' ) 117 jQuery(mapContainer).on('click', '[data-location]', function (e) { 118 var button = this; 119 120 jQuery.ajax({ 121 url: ajaxurl, 122 data: { 123 action: 'wpbchkn', 124 coords: { 125 lat: ( userPosition.hasOwnProperty('coords') ) ? userPosition.coords.latitude : 0, 126 lng: ( userPosition.hasOwnProperty('coords') ) ? userPosition.coords.longitude : 0 127 }, 128 email: wpbchknShortcodeLocationsAtts.email, 129 location: button.dataset.location 130 }, 131 dataType: 'json' 132 }).success(function(response){ 133 if ( response.hasOwnProperty('redirect_to') ) 134 window.location.href = response.redirect_to; 135 // else 136 // smth wrong message 137 }).error(function() { 138 // smth wrong message here 139 }); 140 }); 141};
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.