1/** 2 * @namespace WPGMZA 3 * @module ProInfoWindow 4 * @requires WPGMZA.InfoWindow 5 */ 6jQuery(function($) { 7 8 WPGMZA.ProInfoWindow = function(feature) 9 { 10 var self = this; 11 12 WPGMZA.InfoWindow.call(this, feature); 13 14 this.on("infowindowopen", function(event) { 15 self.updateDistanceFromLocation(); 16 self.showDistanceAwayFromStoreLocatorCenter(); 17 18 self.updateGalleries(); 19 self.prepareSharing(); 20 }); 21 22 } 23 24 WPGMZA.ProInfoWindow.prototype = Object.create(WPGMZA.InfoWindow.prototype); 25 WPGMZA.ProInfoWindow.prototype.constructor = WPGMZA.ProInfoWindow; 26 27 WPGMZA.ProInfoWindow.STYLE_INHERIT = "-1"; 28 29 /* Base styles */ 30 WPGMZA.ProInfoWindow.STYLE_NATIVE_GOOGLE = "0"; 31 WPGMZA.ProInfoWindow.STYLE_PANEL = "4"; 32 33 WPGMZA.ProInfoWindow.STYLE_NATIVE_CLASSIC = "0"; // Alias 34 35 /* Native/Classic extensions */ 36 WPGMZA.ProInfoWindow.STYLE_NATIVE_THIN = "5"; 37 WPGMZA.ProInfoWindow.STYLE_NATIVE_FOCUS = "6"; 38 39 /* Panel Extenders */ 40 WPGMZA.ProInfoWindow.STYLE_PANEL_CARD = "7"; 41 WPGMZA.ProInfoWindow.STYLE_PANEL_DRAWER = "8"; 42 43 /* Deprecated - Legacy or unused */ 44 WPGMZA.ProInfoWindow.STYLE_MODERN = "1"; 45 WPGMZA.ProInfoWindow.STYLE_MODERN_PLUS = "2"; 46 WPGMZA.ProInfoWindow.STYLE_MODERN_CIRCULAR = "3"; 47 WPGMZA.ProInfoWindow.STYLE_TEMPLATE = "template"; // Unused 48 49 WPGMZA.ProInfoWindow.OPEN_BY_CLICK = 1; 50 WPGMZA.ProInfoWindow.OPEN_BY_HOVER = 2; 51 52 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "maxWidth", { 53 54 get: function() { 55 var width = WPGMZA.settings.wpgmza_settings_infowindow_width; 56 57 if(!width || !(/^\d+$/.test(width))) 58 return false; 59 60 return width; 61 } 62 63 }); 64 65 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "imageWidth", { 66 67 get: function() { 68 var width = WPGMZA.settings.wpgmza_settings_image_width; 69 70 if(!width || !(/^\d+$/.test(width))) 71 return false; 72 73 return width; 74 } 75 76 }); 77 78 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "imageHeight", { 79 80 get: function() { 81 var height = WPGMZA.settings.wpgmza_settings_image_height; 82 83 if(!height || !(/^\d+$/.test(height))) 84 return false; 85 86 return height; 87 } 88 89 }); 90 91 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "enableImageResizing", { 92 93 get: function() { 94 return WPGMZA.settings.wpgmza_settings_image_resizing == true; 95 } 96 97 }); 98 99 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "linkTarget", { 100 101 get: function() { 102 return WPGMZA.settings.infoWindowLinks == true ? "_BLANK" : ""; 103 } 104 105 }); 106 107 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "linkRel", { 108 109 get: function() { 110 let compiledRel = ""; 111 if(WPGMZA.settings.infoWindowLinksNofollow == true){ 112 compiledRel += "nofollow "; 113 } 114 115 if(WPGMZA.settings.infoWindowLinksNoopener == true){ 116 compiledRel += "noopener "; 117 } 118 119 if(WPGMZA.settings.infoWindowLinksNoreferrer == true){ 120 compiledRel += "noreferrer "; 121 } 122 return compiledRel && compiledRel.length > 0 ? compiledRel.trim() : ""; 123 } 124 125 }); 126 127 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "linkText", { 128 129 get: function() { 130 return WPGMZA.localized_strings.more_info; 131 } 132 133 }); 134 135 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "directionsText", { 136 137 get: function() { 138 return WPGMZA.localized_strings.get_directions; 139 } 140 141 }); 142 143 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "findNearbyText", { 144 get: function() { 145 return WPGMZA.localized_strings.find_nearby; 146 } 147 }); 148 149 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "shareLocationText", { 150 get: function() { 151 return WPGMZA.localized_strings.share_location; 152 } 153 }); 154 155 156 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "distanceUnits", { 157 158 get: function() { 159 return this.feature.map.settings.store_locator_distance == 1 ? WPGMZA.Distance.MILES : WPGMZA.Distance.KILOMETERS; 160 } 161 162 }); 163 164 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "showAddress", { 165 166 get: function() { 167 return (WPGMZA.settings.infoWindowAddress != true || WPGMZA.currentPage == 'map-edit' ? true : false); 168 } 169 170 }); 171 172 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "showTitle", { 173 get: function() { 174 return (WPGMZA.settings.infoWindowHideTitle != true || WPGMZA.currentPage == 'map-edit' ? true : false); 175 } 176 }); 177 178 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "showCategory", { 179 get: function() { 180 return (WPGMZA.settings.infoWindowHideCategory != true || WPGMZA.currentPage == 'map-edit' ? true : false); 181 } 182 }); 183 184 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "showGallery", { 185 get: function() { 186 return (WPGMZA.settings.infoWindowHideGallery != true || WPGMZA.currentPage == 'map-edit' ? true : false); 187 } 188 }); 189 190 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "showDescription", { 191 get: function() { 192 return (WPGMZA.settings.infoWindowHideDescription != true || WPGMZA.currentPage == 'map-edit' ? true : false); 193 } 194 }); 195 196 197 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "showMarkerFields", { 198 get: function() { 199 return (WPGMZA.settings.infoWindowHideMarkerFields != true || WPGMZA.currentPage == 'map-edit' ? true : false); 200 } 201 }); 202 203 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "style", { 204 205 get: function() { 206 207 if(this.map && this.map.userLocationMarker == this) 208 return WPGMZA.ProInfoWindow.STYLE_NATIVE_GOOGLE; 209
210 return this.getSelectedStyle(); 211 212 } 213 214 }); 215 216 Object.defineProperty(WPGMZA.ProInfoWindow.prototype, "isPanIntoViewAllowed", { 217 218 "get": function() 219 { 220 return (this.isStyleNativeType()); 221 } 222 223 }); 224 225 WPGMZA.ProInfoWindow.prototype.getSelectedStyle = function() 226 { 227 var globalTypeSetting = WPGMZA.settings.wpgmza_iw_type; 228 var localTypeSetting = this.feature.map.settings.wpgmza_iw_type; 229 var type = localTypeSetting; 230 231 if(localTypeSetting == WPGMZA.ProInfoWindow.STYLE_INHERIT || 232 typeof localTypeSetting == "undefined") 233 { 234 type = globalTypeSetting; 235 236 if(type == WPGMZA.ProInfoWindow.STYLE_INHERIT) 237 return WPGMZA.ProInfoWindow.STYLE_NATIVE_GOOGLE; 238 } 239 240 if(!type) 241 return WPGMZA.ProInfoWindow.STYLE_NATIVE_GOOGLE; 242 243 return String(type); 244 } 245 246 WPGMZA.ProInfoWindow.prototype.getImageElementFromURL = function(url) 247 { 248 var img = $("<img/>"); 249 250 img.addClass("wpgmza_infowindow_image"); 251 img.attr("src", url); 252 img.css({"float": "right"}); 253 254 if(this.maxWidth) 255 img.css({"max-width": this.maxWidth}); 256 257 if(this.enableImageResizing && this.imageWidth) 258 { 259 img.css({"width": this.imageWidth}); 260 img.css({"height": this.imageHeight}); 261 } 262 263 if(!this.enableImageResizing) 264 img.css({"margin": "5px"}); 265 266 return img; 267 } 268 269 WPGMZA.ProInfoWindow.prototype.showDistanceAwayFromStoreLocatorCenter = function() { 270 if (this.feature instanceof WPGMZA.Marker) { 271 // Store locator distance away 272 // added by Nick 2020-01-12 273 if (this.feature.map.settings.store_locator_show_distance && this.feature.map.storeLocator && (this.feature.map.storeLocator.state == WPGMZA.StoreLocator.STATE_APPLIED)) { 274 if(this.feature.map.settings.show_distance_from_location){ 275 // Allow the updateDistanceFromLocation method handle everything 276 return; 277 } 278 var currentLatLng = this.feature.getPosition(); 279 var distance = this.workOutDistanceBetweenTwoMarkers(this.feature.map.storeLocator.center, currentLatLng); 280 281 $(this.element).find('.sl-distance').remove(); 282 283 if(distance){ 284 $(this.element).append("<p class='sl-distance'>"+(this.feature.map.settings.store_locator_distance == WPGMZA.Distance.KILOMETERS ? distance + WPGMZA.localized_strings.kilometers_away : distance + " " +WPGMZA.localized_strings.miles_away)+"</p>"); 285 } 286 } 287 288 } 289 } 290 291 WPGMZA.ProInfoWindow.prototype.updateDistanceFromLocation = function() { 292 var marker = this.feature; 293 294 if(!(marker instanceof WPGMZA.Marker)) { 295 // We don't need to report this, shapes support info-windows, they wont do anything with distance, this warning is not needed 296 // console.warn("This function is only intended for use with markers and should not have been called in this manner"); 297 return; 298 } 299 300 var location = marker.map.showDistanceFromLocation; 301 302 if(!location) 303 return; // No location (no search performed, user location unavailable) 304 305 var distanceInKM = WPGMZA.Distance.between(location, marker.getPosition()); 306 var distanceToDisplay = distanceInKM; 307 308 if(this.distanceUnits == WPGMZA.Distance.MILES) 309 distanceToDisplay /= WPGMZA.Distance.KILOMETERS_PER_MILE; 310 311 var text = Math.round(distanceToDisplay, 2); 312 var source = location.source == WPGMZA.ProMap.SHOW_DISTANCE_FROM_USER_LOCATION ? WPGMZA.localized_strings.from_your_location : WPGMZA.localized_strings.from_searched_location; 313 var units = this.distanceUnits == WPGMZA.Distance.MILES ? WPGMZA.localized_strings.miles_away : WPGMZA.localized_strings.kilometers_away; 314 315 if($(this.element).find('.wpgmza-distance-from-location .wpgmza-amount').length <= 0){ 316 /* The inner is missing at the moment */ 317 $(this.element).find('.wpgmza-distance-from-location').html("<span class='wpgmza-amount'></span> <span class='wpgmza-units'></span> <span class='wpgmza-source'></span>"); 318 } 319 320 $(this.element).find(".wpgmza-distance-from-location .wpgmza-amount").text(text); 321 $(this.element).find(".wpgmza-distance-from-location .wpgmza-units").text(units); 322 $(this.element).find(".wpgmza-distance-from-location .wpgmza-source").text(source); 323 } 324 325 WPGMZA.ProInfoWindow.prototype.updateGalleries = function(){ 326 if(this.element){ 327 const placeholder = $(this.element).find('.wpgmza_gallery_placeholder'); 328 if(placeholder.length){ 329 if(this.feature.gallery){ 330 /* Must be initialized after opening the info-window as dom is not attached until this stage */ 331 const gallery = new WPGMZA.Gallery(this.feature.gallery, this.feature); 332 gallery.place(placeholder); 333 334 this.trigger("infowindowcontentshift"); 335 } else { 336 placeholder.remove(); 337 } 338 } 339 } 340 } 341 342 WPGMZA.ProInfoWindow.prototype.legacyCreateDefaultInfoWindow = function(map) { 343 var marker = this.feature; 344 var map = marker.map; 345 346 function empty(field) { 347 return !(field && field.length && field.length > 0); 348 } 349 350 var container = $("<div class='wpgmza_markerbox scrollFix'></div>"); 351 352 if(this.maxWidth) 353 container.css({"max-width": this.maxWidth}); 354 355 356 if(this.showGallery){ 357 if(!empty(marker.gallery)) { 358 if(WPGMZA.InternalEngine.isLegacy()){ 359 var gallery = new WPGMZA.MarkerGallery(marker, this); 360 container.append(gallery.element); 361 } else { 362 /* Uses new gallery */ 363 var galleryWrap = $("<div class='wpgmza_gallery_placeholder'></div>"); 364 if(WPGMZA.settings && WPGMZA.settings.infoWindowImageResizing){ 365 if(WPGMZA.settings.infoWindowImageHeight){ 366 /* This allows initial info-window to be set up correctly */ 367 galleryWrap.css('min-height', parseInt(WPGMZA.settings.infoWindowImageHeight) + 'px'); 368 } 369 370 if(WPGMZA.settings.infoWindowImageWidth){ 371 /* This allows initial info-window to be set up correctly */ 372 galleryWrap.css('min-width', parseInt(WPGMZA.settings.infoWindowImageWidth) + 'px'); 373 } 374 } 375 container.append(galleryWrap); 376 } 377 378 } else if(!empty(marker.pic)) { 379 // Fallback for legacy picture, which was before the marker gallery was implemented in v8. This SHOULD have been taken care of on the server by ProMarker, but this fallback is provided just in case. This can be deprecated
379in the future 380 var img = this.getImageElementFromURL(marker.pic); 381 container.append(img); 382 } 383 } 384 385 if(!empty(marker.title) && this.showTitle) { 386 var p = $("<p class='wpgmza_infowindow_title'></p>"); 387 388 p.html(marker.title); 389 390 container.append(p); 391 } 392 393 if(marker.categories && this.showCategory){ 394 if(marker.categories.length > 0){ 395 var markerCategories = []; 396 for(var i in marker.categories){ 397 var category = WPGMZA.categories.getCategoryByID(parseInt(marker.categories[i])); 398 if(category && category.name.trim() !== ""){ 399 markerCategories.push(category.name); 400 } 401 } 402 403 if(markerCategories.length){ 404 markerCategories = markerCategories.join(", "); 405 var p = $("<p class='wpgmza_infowindow_categories'></p>"); 406 p.html(markerCategories); 407 container.append(p); 408 } 409 } 410 } 411 412 if(!empty(marker.address) && this.showAddress) { 413 414 var p = $("<p class='wpgmza_infowindow_address'></p>"); 415 p.html(marker.address); 416 container.append(p); 417 418 } 419 420 if((!empty(marker.desc) || !empty(marker.description)) && this.showDescription ) { 421 var description = empty(marker.desc) ? marker.description : marker.desc; 422 var div = $("<div class='wpgmza_infowindow_description'></div>"); 423 424 div.html(description); 425 426 container.append(div); 427 } 428 429 if(map.settings.show_distance_from_location == 1) { 430 var p = $("<p class='wpgmza-distance-from-location'><span class='wpgmza-amount'></span> <span class='wpgmza-units'></span> <span class='wpgmza-source'></span></p>"); 431 432 var units = this.distanceUnits == WPGMZA.Distance.MILES ? WPGMZA.localized_strings.miles_away : WPGMZA.localized_strings.kilometers_away; 433 434 /* We don't need to do this twice -> We do this in the 'update distance from location' */ 435 //p.find(".wpgmza-units").text(units); 436 437 container.append(p); 438 } 439 440 if(!empty(marker.linkd) || !empty(marker.link)) { 441 var link = empty(marker.link) ? marker.linkd : marker.link; 442 var p = $("<p class='wpgmza_infowindow_link'></p>"); 443 var a = $("<a class='wpgmza_infowindow_link'></a>"); 444 445 a.attr("href", WPGMZA.decodeEntities(link)); 446 a.attr("target", this.linkTarget); 447 a.text(this.linkText); 448 449 if(this.linkRel){ 450 a.attr('rel', this.linkRel); 451 } 452 453 p.append(a); 454 container.append(p); 455 } 456 457 if(map.directionsEnabled && !(parseInt(WPGMZA.is_admin) === 1) && marker.getPosition && marker instanceof WPGMZA.Marker) { 458 var p = $("<p></p>"); 459 var a = $("<a class='wpgmza_gd'></a>"); 460 461 a.attr("href", "javascript: ;"); 462 a.attr("id", map.id); 463 464 a.attr("data-address", marker.address); 465 a.attr("data-latlng", marker.getPosition().toString()); 466 a.attr("data-marker-id", marker.id); 467 468 // Legacy fields 469 a.attr("wpgm_addr_field", marker.address); 470 a.attr("gps", marker.lat+","+marker.lng); 471 472 a.text(this.directionsText); 473 474 p.append(a); 475 container.append(p); 476 } 477 478 if(marker.custom_fields_html && this.showMarkerFields){
479 container.append(marker.custom_fields_html); 480 } 481 482 let additionalControls = []; 483 if(map.settings.store_locator_nearby_searches && this.feature instanceof WPGMZA.Marker){ 484 additionalControls.push(`<a class='wpgmza-nearby' href='javascript: ;'>${this.findNearbyText}</a>`); 485 } 486 487 if(map.settings.marker_share_links && navigator.canShare && this.feature instanceof WPGMZA.Marker){ 488 additionalControls.push(`<a class='wpgmza-share' href='javascript: ;'>${this.shareLocationText}</a>`); 489 } 490 491 if(additionalControls && additionalControls.length > 0){ 492 let additionalControlsWrapper = $('<div class="wpgmza-info-window-additional-controls-wrapper"/>'); 493 494 additionalControlsWrapper.attr('data-marker-id', this.feature.id); 495 for(let additionalControl of additionalControls){ 496 additionalControlsWrapper.append(additionalControl); 497 } 498 499 container.append(additionalControlsWrapper); 500 501 } 502 503 504 container.append(this.addEditButton()); 505 506 if(this.style == WPGMZA.ProInfoWindow.STYLE_NATIVE_THIN){ 507 /* Thin Restructure */ 508 let innerRow = $('<div class="wpgmza-infowindow-style-thin-inner-row" />'); 509 let leftColumn = $('<div class="wpgmza-infowindow-style-thin-column-left" />'); 510 let rightColumn = $('<div class="wpgmza-infowindow-style-thin-column-right" />'); 511 container.find('.wpgmza_gallery_placeholder,.wpgmza_infowindow_image').appendTo(leftColumn); 512 container.find('*').appendTo(rightColumn); 513 514 innerRow.append(leftColumn); 515 innerRow.append(rightColumn); 516 517 container.append(innerRow); 518 } else if(this.style == WPGMZA.ProInfoWindow.STYLE_NATIVE_FOCUS){ 519 let focusHeading = $('<div class="wpgmza-infowindow-style-focus-heading" />'); 520 521 container.find('.wpgmza_infowindow_title,.wpgmza_infowindow_address,.wpgmza_infowindow_categories').appendTo(focusHeading); 522 if(focusHeading.html().length > 0){ 523 if(container.find('.wpgmza_gallery_placeholder').length > 0){ 524 focusHeading.insertAfter(container.find('.wpgmza_gallery_placeholder')); 525 } else if(container.find('.wpgmza_infowindow_image').length > 0){ 526 focusHeading.insertAfter(container.find('.wpgmza_infowindow_image')); 527 } else if(container.find('.wpgmza_infowindow_description').length > 0){ 528 focusHeading.insertBefore(container.find('.wpgmza_infowindow_description')); 529 } else { 530 container.prepend(focusHeading); 531 } 532 } 533 } 534 535 this.setContent(container.html()); 536 } 537 538 WPGMZA.ProInfoWindow.prototype.legacyCreateModernInfoWindow = function(map) 539 { 540 // Legacy code 541 var mapid = map.id; 542 var self = this; 543 544 if($("#wpgmza_iw_holder_" + map.id).length == 0) 545 $(document.body).append("<div id='wpgmza_iw_holder_" + map.id + "'></div>"); 546 else 547 return; 548 549 var legend = document.getElementById('wpgmza_iw_holder_' + mapid); 550 if (legend !== null) 551 $(legend).remove(); 552 553 if(!window.wpgmza_iw_Div) 554 window.wpgmza_iw_Div = []; 555 556 wpgmza_iw_Div[mapid] = document.createElement('div'); 557 wpgmza_iw_Div[mapid].id = 'wpgmza_iw_holder_' + mapid; 558 wpgmza_iw_Div[mapid].style = 'display:block;'; 559 document.getElementsByTagName('body')[0].appendChild(wpgmza_iw_Div[mapid]); 560 561 wpgmza_iw_Div_inner = document.createElement('div'); 562 wpgmza_iw_Div_inner.className = 'wpgmza_modern_infowindow_inner wpgmza_modern_infowindow_inner_' + mapid; 563 wpgmza_iw_Div[mapid].appendChild(wpgmza_iw_Div_inner); 564 565 wpgmza_iw_Div_close = document.createElement('div'); 566 wpgmza_iw_Div_close.className = 'wpgmza_modern_infowindow_close'; 567 wpgmza_iw_Div_close.setAttribute('mid', mapid); 568 569 $(wpgmza_iw_Div_close).on("click", function(event) { 570 $(wpgmza_iw_Div[mapid]).remove(); 571 }); 572 573 var t = document.createTextNode("x"); 574 wpgmza_iw_Div_close.appendChild(t); 575 wpgmza_iw_Div_inner.appendChild(wpgmza_iw_Div_close); 576 577 wpgmza_iw_Div_img = document.createElement('div'); 578 wpgmza_iw_Div_img.className = 'wpgmza_iw_image'; 579 wpgmza_iw_Div_inner.appendChild(wpgmza_iw_Div_img); 580 581 wpgmza_iw_img = document.createElement('img'); 582 wpgmza_iw_img.className = 'wpgmza_iw_marker_image'; 583 wpgmza_iw_img.src = ''; 584 wpgmza_iw_img.style = 'max-width:100%;'; 585 wpgmza_iw_Div_img.appendChild(wpgmza_iw_img); 586 587 wpgmza_iw_img_div = document.createElement('div'); 588 wpgmza_iw_img_div.className = 'wpgmza_iw_title'; 589 wpgmza_iw_Div_inner.appendChild(wpgmza_iw_img_div); 590 591 wpgmza_iw_img_div_p = document.createElement('p'); 592 wpgmza_iw_img_div_p.className = 'wpgmza_iw_title_p'; 593 wpgmza_iw_img_div.appendChild(wpgmza_iw_img_div_p); 594 595 596 if(!WPGMZA.settings.wpgmza_settings_infowindow_address){ 597 wpgmza_iw_address_div = document.createElement('div'); 598 wpgmza_iw_address_div.className = 'wpgmza_iw_address'; 599 wpgmza_iw_Div_inner.appendChild(wpgmza_iw_address_div); 600 601 wpgmza_iw_address_p = document.createElement('p'); 602 wpgmza_iw_address_p.className = 'wpgmza_iw_address_p'; 603 wpgmza_iw_address_div.appendChild(wpgmza_iw_address_p); 604 } 605 606 607 wpgmza_iw_description = document.createElement('div'); 608 wpgmza_iw_description.className = 'wpgmza_iw_description'; 609 wpgmza_iw_Div_inner.appendChild(wpgmza_iw_description); 610 611 wpgmza_iw_description_p = document.createElement('p'); 612 wpgmza_iw_description_p.className = 'wpgmza_iw_description_p'; 613 wpgmza_iw_description.appendChild(wpgmza_iw_description_p); 614 615 if(map.settings.show_distance_from_location == 1) { 616 var p = $("<p class='wpgmza-distance-from-location'><span class='wpgmza-amount'></span> <span class='wpgmza-units'></span> <span class='wpgmza-source'></span></p>"); 617 618 var units = this.distanceUnits == WPGMZA.Distance.MILES ? WPGMZA.localized_strings.miles_away : WPGMZA.localized_strings.kilometers_away; 619 620 p.find(".wpgmza-units").text(units); 621 622 $(wpgmza_iw_Div_inner).append(p); 623 } 624 625 var ratingContainer = $("<div class='wpgmza-rating-container'></div>")[0]; 626 wpgmza_iw_Div_inner.appendChild(ratingContainer); 627 628 // Custom fields 629 $(wpgmza_iw_Div_inner).append("<div class='wpgmza_iw_custom_fields'/>"); 630 631 wpgmza_iw_buttons = document.createElement('div'); 632 wpgmza_iw_buttons.className = 'wpgmza_iw_buttons'; 633 wpgmza_iw_Div_inner.appendChild(wpgmza_iw_buttons); 634 635 wpgmza_directions_button = document.createElement('a'); 636 wpgmza_directions_button.className = 'wpgmza_button wpgmza_left wpgmza_directions_button'; 637 wpgmza_directions_button.src = '#'; 638 639 var t = document.createTextNode(WPGMZA.localized_strings.directions); 640 wpgmza_directions_button.appendChild(t); 641 wpgmza_iw_buttons.appendChild(wpgmza_directions_button); 642 643 wpgmza_more_info_button = document.createElement('a'); 644 wpgmza_more_info_button.className = 'wpgmza_button wpgmza_right wpgmza_more_info_button'; 645 wpgmza_more_info_button.src = '#'; 646 647 var t = document.createTextNode(WPGMZA.localized_strings.more_info); 648 wpgmza_more_info_button.appendChild(t); 649 wpgmza_iw_buttons.appendChild(wpgmza_more_info_button); 650 651 var legend = document.getElementById('wpgmza_iw_holder_' + mapid); 652 $(legend).css('display', 'block'); 653 $(legend).addClass('wpgmza_modern_infowindow'); 654 $(legend).addClass('wpgmza-shadow'); 655 656 657 658 if (WPGMZA.settings.engine == "google-maps") 659 { 660 var map = this.feature.map; 661 map.googleMap.controls[google.maps.ControlPosition.RIGHT_TOP].push(legend); 662 } 663 else { 664 var container = $(".wpgmza-ol-modern-infowindow-container[data-map-id='" + mapid + "']"); 665 if (!container.length) { 666 container = $("<div class='wpgmza-ol-modern-infowindow-container' data-map-id='" + mapid + "'></div>"); 667 $(".wpgmza_map[data-map-id='" + mapid + "']").append(container); 668 } 669 670 container.append(legend); 671 } 672 673 } 674 675 WPGMZA.ProInfoWindow.prototype.open = function(map, feature) 676 { 677 var self = this; 678 679 // Legacy support 680 if(window.infoWindow) 681 infoWindow[feature.map.id] = this; 682 683 if(!WPGMZA.InfoWindow.prototype.open.call(this, map, feature)) 684 return false; // Parent class has detected that the window shouldn't open 685 686 if(this.feature == map.userLocationMarker) 687 return true; // Allow the default style window to open for user location markers 688 689 if(map.settings.wpgmza_list_markers_by == WPGMZA.MarkerListing.STYLE_MODERN) 690 return false; // Don't show if modern style marker listing is selected 691 692 if(WPGMZA.settings.wpgmza_settings_disable_infowindows) 693 return false; // Global setting "disable infowindows" is set 694 695 if($('.wpgmza-standalone-component .wpgmza-panel-info-window[data-map="' + feature.map.id + '"]').length > 0){ 696 $('.wpgmza-standalone-component .wpgmza-panel-info-window[data-map="' + feature.map.id + '"]').removeClass('wpgmza-hidden'); 697 this.populatePanel(); 698 return false; 699 } 700 701 // Legacy support 702 if(this.isStyleNativeType() || WPGMZA.currentPage == "map-edit"){ 703 this.legacyCreateDefaultInfoWindow(); 704 return true; // Always show default style when on map edit page 705 } else if(this.isStylePanelType()){ 706 this.populatePanel(); 707 return false; //Disable the default 708 } 709 710 /** 711 * As of 9.0.0 (Atlas Novus) 712 * 713 * All code below this point should be considered legacy, it will never be called by the Atlas novus maps which only allow two styles 714 */ 715 var marker_data; 716 var data = wpgmaps_localize_marker_data[map.id]; 717 var marker = feature; 718 719 if(typeof data == "array") 720 for(var i = 0; i < data.length; i++) 721 { 722 if(data[i].marker_id == feature.id) 723 { 724 marker_data = data[i]; 725 726 break; 727 } 728 } 729 else if(typeof data == "object") 730 for(var key in data) 731 { 732 if(data[key].marker_id == feature.id) 733 { 734 marker_data = data[key]; 735 736 break; 737 } 738 } 739 740 /** Deprecated this failure block as we reference features directly now */ 741 /*if(!marker_data){
742 console.warn("Failed to find marker data for marker " + feature.id); 743 return false; 744 }*/ 745 746 this.legacyCreateModernInfoWindow(map); 747 748 if(window.modern_iw_open) 749 modern_iw_open[map.id] = true; 750 751 var element = this.element = jQuery("#wpgmza_iw_holder_" + map.id); 752 753 // Reset the contents first 754 element.find(".wpgmza_iw_marker_image").attr("src",""); 755 element.find(".wpgmza_iw_title").html(""); 756 element.find(".wpgmza_iw_description").html(""); 757 element.find(".wpgmza_iw_address_p").html(""); 758 759 760 element.find(".wpgmza_more_info_button").attr("href","#"); 761 element.find(".wpgmza_more_info_button").attr("target",""); 762 element.find(".wpgmza_directions_button").attr("gps",""); 763 element.find(".wpgmza_directions_button").attr("href","#"); 764 element.find(".wpgmza_directions_button").attr("id",""); 765 element.find(".wpgmza_directions_button").attr("data-marker-id",""); 766 element.find(".wpgmza_directions_button").attr("wpgm_addr_field",""); 767 768 769 770 if (marker.image === "" && marker.title === "") { 771 element.find(".wpgmza_iw_image").css("display","none"); 772 } else { 773 element.find(".wpgmza_iw_image").css("display","block"); 774 } 775 776 var container = $("#wpgmza_iw_holder_" + map.id + " .wpgmza_iw_image"); 777 container.html(""); 778 779 if(marker.gallery) 780 { 781 var gallery = new WPGMZA.MarkerGallery(marker, this); 782 gallery.element.css({ 783 "float": "none" 784 }); 785 container.append(gallery.element); 786 } 787 else if(marker.pic.length) 788 { 789 var image = $("<img class='wpgmza_infowindow_image'/>"); 790 image.attr("src", marker.pic); 791 image.css({"display": "block"}); 792 container.append(image); 793 } 794 else 795 { 796 element.find(".wpgmza_iw_marker_image").css("display","none"); 797 element.find(".wpgmza_iw_title").attr("style","position: relative !important"); 798 element.find(".wpgmza_iw_title").addClass('wpgmze_iw_title_no_image'); 799 } 800 801 if (marker.title !== "") { element.find(".wpgmza_iw_title").html(marker.title); } 802 803 var description = ""; 804 805 if(marker.desc) 806 description = marker.desc; 807 else if(marker.description) 808 description = marker.description; 809 810 if (description && description.length) 811 { 812 element.find(".wpgmza_iw_description").css("display","block"); 813 element.find(".wpgmza_iw_description").html(description); 814 } 815 else 816 element.find(".wpgmza_iw_description").css("display","none"); 817 818 // Custom fields 819 var container = element.find(".wpgmza_iw_description"); 820 if(marker.custom_fields_html) 821 { 822 container.append(marker.custom_fields_html); 823 container.css("display","block"); 824 } 825 826 /*if (typeof wpgmaps_localize_global_settings['wpgmza_settings_infowindow_address'] !== 'undefined' && wpgmaps_localize_global_settings['wpgmza_settings_infowindow_address'] === "yes") { 827 } else {*/ 828 if (typeof marker.address !== "undefined" && marker.address !== "") { element.find(".wpgmza_iw_address_p").html(marker.address); } 829 /*}*/ 830 831 832 if (typeof marker.link !== "undefined" && marker.link !== "") { 833 element.find(".wpgmza_more_info_button").show(); 834 element.find(".wpgmza_more_info_button").attr("href",marker.link); 835 836 element.find(".wpgmza_more_info_button").attr("target",this.linkTarget); 837 838 if(this.linkRel){ 839 element.find(".wpgmza_more_info_button").attr('rel', this.linkRel); 840 } 841 } else { 842 element.find(".wpgmza_more_info_button").hide(); 843 } 844 if (map.directionsEnabled) { 845 element.find(".wpgmza_directions_button").show(); 846 element.find(".wpgmza_directions_button").attr("href","javascript:void(0);"); 847 element.find(".wpgmza_directions_button").attr("gps",marker.lat + "," + marker.lng); 848 element.find(".wpgmza_directions_button").attr("wpgm_addr_field",marker.address); 849 element.find(".wpgmza_directions_button").attr("id",map.id); 850 element.find(".wpgmza_directions_button").attr("data-marker-id",marker.id); 851 element.find(".wpgmza_directions_button").addClass("wpgmza_gd"); 852 853 } else { 854 element.find(".wpgmza_directions_button").hide(); 855 } 856 857 element.show(); 858 859 this.trigger("domready"); 860 this.trigger("infowindowopen"); 861 862 return true; 863 } 864 865 // TODO: This doesn't appear to do anything, nor does it call the parent method 866 WPGMZA.ProInfoWindow.prototype.close = function() 867 { 868 $(this.feature.map.element).find(".wpgmza-pro-info-window-container").html(); 869 } 870 871 WPGMZA.ProInfoWindow.prototype.setPosition = function(position){ 872 873 } 874 875 WPGMZA.ProInfoWindow.prototype.prepareSharing = function(){ 876 $(document.body).off("click", ".wpgmza-share").on("click", ".wpgmza-share", (event) => { 877 this.onShare(); 878 }); 879 } 880 881 WPGMZA.ProInfoWindow.prototype.onShare = function(){ 882 if(this.feature instanceof WPGMZA.Marker){ 883 const id = this.feature.id; 884 if(window.location && window.location.href){ 885 let url = new URL(window.location.href); 886 let link = ""; 887 if(url.origin){ 888 link += url.origin; 889 } 890 891 if(url.pathname){ 892 link += url.pathname; 893 } 894 895 if(id){ 896 link += "?markerid=" + id; 897 } 898 899 if(link.trim().length){ 900 let title = document.title || ""; 901 if(this.feature.title){ 902 title = this.feature.title; 903 } 904 905 const shareData = { 906 title: title, 907 text: title, 908 url: link 909 }; 910 911 if(navigator.canShare && navigator.canShare(shareData)) { 912 navigator.share(shareData) 913 .then(() => { 914 // Success 915 }) 916 .catch((error) => { 917 918 });
919 } 920 } 921 } 922 } 923 } 924 925 /** 926 * Dynamically populates the info-window content into the dom 927 * 928 * Used by viewpoer groupings and standalone info-windows 929 * 930 * This should not be called for embedded info-windows 931 */ 932 WPGMZA.ProInfoWindow.prototype.populatePanel = function(){ 933 var self = this; 934 $('.wpgmza-panel-info-window[data-map="' + this.feature.map.id + '"]').each(function(){ 935 var feature = self.feature; 936 var map = feature.map; 937 938 if(feature instanceof WPGMZA.Marker){ 939 $(this).attr('data-marker-id', feature.id); 940 941 if(feature._lazyloadContentState && feature._lazyloadContentState.busy){ 942 $(this).addClass('wpgmza-info-window-panel-lazyload-busy'); 943 } else { 944 $(this).removeClass('wpgmza-info-window-panel-lazyload-busy'); 945 } 946 } else { 947 $(this).removeAttr('data-marker-id'); 948 } 949 950 if(map.directionsEnabled){ 951 $(this).find('.wpgmza-directions').removeClass('wpgmza-hidden'); 952 } 953 954 if(map.settings.store_locator_nearby_searches){ 955 $(this).find('.wpgmza-nearby').removeClass('wpgmza-hidden'); 956 } 957 958 $(this).find('.wpgmza-share').addClass('wpgmza-hidden'); 959 if(map.settings.marker_share_links && navigator.canShare && feature instanceof WPGMZA.Marker){ 960 $(this).find('.wpgmza-share').removeClass('wpgmza-hidden'); 961 } 962 963 let dataProps = self.compileWrapperAttributes(); 964 if(dataProps){ 965 dataProps = dataProps.split(" "); 966 for(let prop of dataProps){ 967 let [propKey, propValue] = prop.split("="); 968 if(propKey && propValue){ 969 $(this).attr(propKey, propValue.replaceAll('"', '')); 970 } 971 } 972 } 973 974 self.element = $(this); 975 976 977 $(this).find('[data-name]').each(function(){ 978 var key = $(this).data('name'); 979 var value = ""; 980 if(feature[key]){ 981 value = feature[key]; 982 } 983 984 if(key === "categories" && feature.categories){ 985 if(feature.categories.length > 0){ 986 var markerCategories = []; 987 for(var i in feature.categories){ 988 var category = WPGMZA.categories.getCategoryByID(parseInt(feature.categories[i])); 989 if(category && category.name.trim() !== ""){ 990 markerCategories.push(category.name); 991 } 992 } 993 994 value = markerCategories.join(", "); 995 } 996 } 997 998 /* Check visible states */ 999 switch(key){ 1000 case 'title': 1001 case 'description': 1002 const prop = 'show' + (key.charAt(0).toUpperCase()) + key.substr(1); 1003 if(!self[prop]){ 1004 $(this).addClass('wpgmza-hidden'); 1005 return; 1006 } 1007 break; 1008 case 'address': 1009 if(!self.showAddress){ 1010 $(this).closest('.wpgmza-address').addClass('wpgmza-hidden'); 1011 return; 1012 } 1013 break; 1014 case 'categories': 1015 if(!self.showCategory){ 1016 $(this).addClass('wpgmza-hidden'); 1017 return; 1018 } 1019 break; 1020 case 'pic': 1021 if(!self.showGallery){ 1022 $(this).parent().remove(); 1023 $(this).addClass('wpgmza-hidden'); 1024 return; 1025 } 1026 break; 1027 case 'custom_fields_html': 1028 if(!self.showMarkerFields){ 1029 $(this).addClass('wpgmza-hidden'); 1030 return; 1031 } 1032 break; 1033 1034 1035 } 1036 1037 /* Populate the DOM */ 1038 switch(key){ 1039 case 'pic': 1040 $(this).parent().find('.wpgmza-gallery').remove(); 1041 if(feature.gallery){ 1042 var gallery = new WPGMZA.Gallery(feature.gallery, feature); 1043 gallery.place($(this).parent()); 1044 1045 $(this).hide(); 1046 } else { 1047 if(value){ 1048 $(this).attr('src', value); 1049 $(this).show(); 1050 } else { 1051 $(this).hide(); 1052 } 1053 } 1054 break; 1055 case 'link': 1056 $(this).hide(); 1057 if(value){ 1058 $(this).find('a').attr('href', value); 1059 $(this).find('a').attr("target", self.linkTarget); 1060 $(this).find('a').html(self.linkText); 1061 1062 if(self.linkRel){ 1063 $(this).find('a').attr('rel', self.linkRel); 1064 } 1065 $(this).show(); 1066 } else { 1067 $(this).find('a').attr('href', '#'); 1068 } 1069 break; 1070 case 'title': 1071 if(feature instanceof WPGMZA.Marker && ((feature.map.userLocationMarker === feature) || (typeof feature.user_location !== 'undefined' && feature.user_location))){ 1072 value = WPGMZA.localized_strings.my_location; 1073 } 1074 $(this).html(value); 1075 break; 1076 case 'address': 1077 if(feature instanceof WPGMZA.Marker && ((feature.map.userLocationMarker === feature) || (typeof feature.user_location !== 'undefined' && feature.user_location))){ 1078 value = feature.getPosition().toString(); 1079 } 1080 1081 if(value){ 1082 $(this).html(value); 1083 $(this).closest('.wpgmza-address').removeClass('wpgmza-hidden'); 1084 } else { 1085 $(this).closest('.wpgmza-address').addClass('wpgmza-hidden'); 1086 } 1087 break; 1088 default: 1089 $(this).html(value); 1090 break; 1091 } 1092 1093 }); 1094 1095 /* Reset ratings container */ 1096 $(this).find('.wpgmza-rating-container').html(''); 1097 $(this).find('.wpgmza-rating').remove(); 1098 1099 $(this).addClass('wpgmza-panel-info-window-populated'); 1100 1101 self.updateDistanceFromLocation(); 1102 self.showDistanceAwayFromStoreLocatorCenter(); 1103 1104 self.feature.map.viewportGroupings.update('infowindow'); 1105 1106 self.trigger("infowindowopen"); 1107 1108 $(this).find('.wpgmza-clear').off('click').on('click', () => { 1109 if($(this).hasClass('wpgmza-panel-info-window-style-panel-group')){ 1110 /* For grouping style */ 1111 $(this).closest('.viewport-grouping').find('.grouping-handle').trigger('click'); 1112 } else { 1113 /* Only for panels which are not bound in the panel grouping */ 1114 $(this).removeClass('wpgmza-panel-info-window-populated'); 1115 } 1116 1117 self.trigger("infowindowclosed"); 1118 }); 1119 1120 }); 1121 } 1122 1123 WPGMZA.ProInfoWindow.prototype.isStyleNativeType = function(){ 1124 const nativeTypes = [ 1125 WPGMZA.ProInfoWindow.STYLE_NATIVE_GOOGLE, 1126 WPGMZA.ProInfoWindow.STYLE_NATIVE_CLASSIC, 1127 WPGMZA.ProInfoWindow.STYLE_NATIVE_THIN, 1128 WPGMZA.ProInfoWindow.STYLE_NATIVE_FOCUS 1129 ]; 1130 1131 for(let compare of nativeTypes){ 1132 if(this.style == compare){ 1133 return true; 1134 } 1135 } 1136 return false; 1137 } 1138 1139 WPGMZA.ProInfoWindow.prototype.isStylePanelType = function(){ 1140 const panelTypes = [ 1141 WPGMZA.ProInfoWindow.STYLE_PANEL, 1142 WPGMZA.ProInfoWindow.STYLE_PANEL_CARD, 1143 WPGMZA.ProInfoWindow.STYLE_PANEL_DRAWER 1144 ]; 1145 1146 for(let compare of panelTypes){ 1147 if(this.style == compare){ 1148 return true; 1149 } 1150 } 1151 return false; 1152 } 1153 1154 WPGMZA.ProInfoWindow.prototype.getStyleTypeClass = function(){ 1155 /* We only need to do this for native types - Panels get their class from a template file */ 1156 if(this.isStyleNativeType()){ 1157 let type = 'classic'; 1158 switch(this.style){ 1159 case WPGMZA.ProInfoWindow.STYLE_NATIVE_THIN: 1160 type = 'thin'; 1161 break; 1162 case WPGMZA.ProInfoWindow.STYLE_NATIVE_FOCUS: 1163 type = 'focus'; 1164 break; 1165 case WPGMZA.ProInfoWindow.STYLE_NATIVE_CLASSIC: 1166 case WPGMZA.ProInfoWindow.STYLE_NATIVE_GOOGLE: 1167 default: 1168 break; 1169 } 1170 return `wpgmza-infowindow-style-${type}`; 1171 } 1172 return false; 1173 } 1174 1175 // TODO: This should be taken care of already in core.js 1176 $(document).ready(function(event) { 1177 $(document.body).on("click", ".wpgmza-close-info-window", function(event) { 1178 $(event.target).closest(".wpgmza-info-window").remove(); 1179 }); 1180 }); 1181 1182});
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.