1jQuery(document).ready(function() { 2 initFavourites(); 3 refreshFavouritesMap(); 4}); 5 6jQuery(document).ajaxSuccess(function(){ 7 initFavourites(); 8 initializeFavouritesCount(); 9}); 10 11function initFavourites() { 12 alertify.set('notifier', 'position', 'bottom-center'); 13 14 jQuery('.favourites-add-button').unbind('click').click(function(e) { 15 e.preventDefault(); 16 var $button = jQuery(this); 17 if ($button.attr('disabled')) { 18 return; 19 } 20 var nonce = jQuery(this).data('nonce'); 21 if (nonce) { 22 var post_id = $button.data('post-id'); 23 if (post_id) { 24 var type = jQuery(this).data('type'); 25 if (type == 'single') { 26 var loading = $button.data('loading'); 27 var ready = $button.data('ready'); 28 $button.html(loading); 29 $button.attr('disabled', 'disabled'); 30 jQuery.ajax({ 31 type : "POST", 32 url : favourites_settings.ajax_url, 33 xhrFields: { 34 withCredentials: true 35 }, 36 cache: false, 37 data : { 38 action: "favourites_add_post", 39 post_id : post_id, 40 nonce: nonce 41 }, 42 success: function(response) { 43 if (response == 'OK') { 44 $button.html(ready); 45 $button.parent().find('.favourites-show-all').removeClass('d-none'); 46 refreshFavouritesCount('+'); 47 } 48 } 49 }); 50 } 51 if (type == 'list') { 52 var success = $button.data('success'); 53 $button.attr('disabled', 'disabled'); 54 jQuery.ajax({ 55 type : "POST", 56 url : favourites_settings.ajax_url, 57 xhrFields: { 58 withCredentials: true 59 }, 60 cache: false, 61 data : { 62 action: "favourites_add_post", 63 post_id : post_id, 64 nonce: nonce 65 }, 66 success: function(response) { 67 if (response == 'OK') { 68 $button.addClass('added'); 69 alertify.notify(success, 'success', 5); 70 refreshFavouritesCount('+'); 71 } 72 } 73 }); 74 } 75 } 76 } 77 }); 78 79 jQuery('.favourites-remove-button').click(function(e) { 80 e.preventDefault(); 81 var $button = jQuery(this); 82 if ($button.attr('disabled')) { 83 return; 84 } 85 var nonce = jQuery(this).data('nonce'); 86 if (nonce) { 87 var post_id = $button.data('post-id'); 88 if (post_id) { 89 var loading = $button.data('loading'); 90 $button.html(loading); 91 $button.attr('disabled', 'disabled'); 92 jQuery.ajax({ 93 type : "POST", 94 url : favourites_settings.ajax_url, 95 xhrFields: { 96 withCredentials: true 97 }, 98 cache: false, 99 data : { 100 action: "favourites_remove_post", 101 post_id : post_id, 102 nonce: nonce 103 }, 104 success: function(response) { 105 if (response == 'OK') { 106 var row = jQuery('#favourites-list .favourites-table tr#favourites-row-' + post_id); 107 if (row) { 108 jQuery(row).fadeOut(function() { 109 refreshFavouritesMap(); 110 }); 111 } 112 refreshFavouritesCount('-'); 113 } 114 } 115 }); 116 } 117 } 118 }); 119 120 jQuery('#favourites-email-form').on('submit', function(e) { 121 e.preventDefault(); 122 var nonce = jQuery(this).find('input[name=nonce]').val(); 123 124 var $email_input = jQuery(this).find('input[type=email]'); 125 126 var email = $email_input.val(); 127 if (nonce.length > 0 && email.length > 0) { 128 var $button = jQuery(this).find('input[type=submit]'); 129 if ($button.attr('disabled')) { 130 return; 131 } 132 $button.attr('disabled', 'disabled'); 133 134 var loading = $button.data('loading'); 135 var ready = $button.data('ready'); 136 $button.val(loading); 137 138 $email_success = jQuery(this).find('#email-message-success'); 139 $email_failed = jQuery(this).find('#email-message-failed'); 140 141 $email_success.hide(); 142 $email_failed.hide(); 143 144 jQuery.ajax({ 145 type : "POST", 146 url : favourites_settings.ajax_url, 147 xhrFields: { 148 withCredentials: true 149 }, 150 cache: false, 151 data : { 152 action: "favourites_send_email", 153 email: email, 154 nonce: nonce 155 }, 156 success: function(response) { 157 if (response == 'OK') { 158 $email_input.val(''); 159 $email_success.show(); 160 } else { 161 $email_failed.show(); 162 } 163 $button.val(ready); 164 $button.removeAttr('disabled'); 165 } 166 }); 167 } 168 }); 169} 170 171function initializeFavouritesCount() { 172 var $countEl = jQuery('#favourites-count'); 173 if ($countEl.length) { 174 var count = $countEl.html(); 175 if (count.isEmpty()) { 176 jQuery.ajax({ 177 type : "GET", 178 url : favourites_settings.ajax_url, 179 data : { 180 action: "favourites_get_count", 181 }, 182 success: function(response) { 183 $countEl.html(response); 184 } 185 }); 186 } 187 } 188} 189 190function refreshFavouritesCount(type = '+') { 191 var $countEl = jQuery('#favourites-count'); 192 if ($countEl.length) { 193 var current = parseInt($countEl.html()); 194 if (current >= 0) { 195 var newCount = 0; 196 if (type == '+') { 197 newCount = current + 1; 198 } else { 199 newCount = current - 1; 200 } 201 if (newCount < 0) { 202 newCount = 0; 203 } 204 $countEl.html(newCount); 205 } 206 } 207} 208 209function refreshFavouritesMap() { 210 var $map = jQuery('#favourites-map'); 211 if ($map.length) { 212 jQuery.ajax({ 213 type : "GET", 214 url : favourites_settings.ajax_url, 215 data : { 216 action: "favourites_get_product_map_data", 217 }, 218 success: function(response) { 219 if (response !== 'ERROR') { 220 var json = response; 221 if (json) { 222 var products = JSON.parse(json); 223 if (products.length > 0) { 224 showProductsOnMap(products); 225 } 226 } 227 } 228 } 229 }); 230 } 231} 232 233var map; 234var geocoder; 235var infowindow; 236var markers = []; 237var markerBounds = []; 238 239function showProductsOnMap(products) { 240 if (typeof products !== 'undefined') { 241 var oulu = {lat: 65.012, lng: 25.465}; 242 var mapElement = document.getElementById("favourites-map"); 243 if (! mapElement) { 244 return false;
245 } 246 if (typeof map == 'undefined') { 247 var map = new google.maps.Map(document.getElementById("favourites-map"), { 248 zoom: 12, 249 maxZoom: 16, 250 center: oulu 251 }); 252 } 253 if (typeof geocoder == 'undefined') { 254 var geocoder = new google.maps.Geocoder(); 255 } 256 if (typeof infowindow == 'undefined') { 257 var infowindow = new google.maps.InfoWindow(); 258 } 259 260 markers = []; 261 markerBounds = []; 262 263 var address_products = []; 264 265 for (var i=0; i<products.length; i++) { 266 var product = products[i]; 267 if (product) { 268 var coordinates = product.coordinates; 269 var address = product.address; 270 var title = product.title; 271 var url = product.url; 272 if (coordinates) { 273 var latlng = new google.maps.LatLng(coordinates.lat, coordinates.lng); 274 var marker = new google.maps.Marker({ 275 position: latlng, 276 map: map, 277 content: title, 278 address: address, 279 url: url 280 }); 281 google.maps.event.addListener(marker, 'click', function() { 282 infowindow.setContent('<a href="' + this.url + '"><h6>' + this.content + '</h6></a><p>' + this.address + '</p>'); 283 infowindow.open(map, this); 284 }); 285 markers.push(marker); 286 markerBounds.push(latlng); 287 } else if (address) { 288 address_products.push(product); 289 } 290 } 291 } 292 293 showMarkers(map); 294 fitBounds(map); 295 if (address_products.length > 0) { 296 var total_addresses = 0; 297 var processed_addresses = 0; 298 for (var i=0; i < address_products.length; i++) { 299 var product = address_products[i]; 300 if (product) { 301 var address = product.address; 302 var title = product.title; 303 var url = product.url; 304 total_addresses = total_addresses + 1; 305 geocoder.geocode({'address': address}, function(results, status) { 306 if (status == google.maps.GeocoderStatus.OK) { 307 var location = results[0].geometry.location; 308 if (location) { 309 var latlng = new google.maps.LatLng(location.lat(), location.lng()); 310 var marker = new google.maps.Marker({ 311 map: map, 312 position: latlng, 313 content: title, 314 address: address, 315 url: url 316 }); 317 google.maps.event.addListener(marker, 'click', function() { 318 infowindow.setContent('<a href="' + this.url + '"><h6>' + this.content + '</h6></a><p>' + this.address + '</p>'); 319 infowindow.open(map, this); 320 }); 321 markers.push(marker); 322 processed_addresses = processed_addresses + 1; 323 markerBounds.push(latlng); 324 fitAddressesBounds(total_addresses, processed_addresses, map); 325 } 326 } 327 }); 328 } 329 } 330 } 331 } 332} 333 334function showMarkers(map) { 335 setMapOnAll(map); 336} 337 338function setMapOnAll(map) { 339 for (let i = 0; i < markers.length; i++) { 340 markers[i].setMap(map); 341 } 342} 343 344function deleteMarkers() { 345 hideMarkers(); 346 markers = []; 347 } 348 349function fitBounds(map) { 350 if (markerBounds.length) { 351 var bounds = new google.maps.LatLngBounds(); 352 for ( var i = 0; i < markerBounds.length; i++ ) { 353 bounds.extend(markerBounds[i]); 354 } 355 map.setCenter(); 356 map.fitBounds(bounds); 357 } 358} 359 360function fitAddressesBounds(total_addresses, processed_addresses, map) { 361 if (total_addresses == processed_addresses) { 362 var bounds = new google.maps.LatLngBounds(); 363 for (var i = 0; i < markerBounds.length; i++) { 364 bounds.extend(markerBounds[i]); 365 } 366 map.setCenter(); 367 map.fitBounds(bounds); 368 } 369}
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.