1(function( $ ) { 2 'use strict'; 3 4 // Create the defaults once 5 var pluginName = "storeLocator", 6 defaults = { 7 store_locator: '#store_locator', 8 store_modal: "#store_modal", 9 store_modal_button: "#store_modal_button", 10 store_modal_close: "#store_modal_close", 11 map_container: "#store_locator_map", 12 map_min_height: 300, 13 store_locator_sidebar: '#store_locator_sidebar', 14 store_locator_search_box: '#store_locator_search_box', 15 result_list: "#store_locator_result_list", 16 store_locator_address_field: '#store_locator_address_field', 17 store_locator_find_stores_button: '#store_locator_find_stores_button', 18 store_locator_loading: '#store_locator_loading', 19 store_locator_filter_radius: '#store_locator_filter_radius', 20 store_locator_filter_categories: '#store_locator_filter_categories', 21 store_locator_filter: '#store_locator_filter', 22 store_locator_filter_active_filter: '#store_locator_filter_active_filter', 23 store_locator_filter_open_close: '#store_locator_filter_open_close', 24 store_locator_filter_content: '#store_locator_filter_content', 25 store_locator_filter_checkbox: '.store_locator_filter_checkbox', 26 store_locator_filter_select: '.store_locator_filter_select', 27 28 store_locator_form_customer_address: 'input[name="store_locator_form_customer_address"]', 29 store_locator_form_store_select: 'select[name="store_locator_form_store_select"]', 30 31 store_locator_embedded_search: '#store_locator_embedded_search', 32 33 store_locator_get_my_position: '#store_locator_get_my_position', 34 store_locator_get_all_stores: '#store_locator_get_all_stores', 35 store_locator_dragged_button: '#store_locator_dragged_button', 36 store_locator_category_icon: '', 37 earthRadi: { 38 mi: 3963.1676, 39 km: 6378.1, 40 ft: 20925524.9, 41 mt: 6378100, 42 "in": 251106299, 43 yd: 6975174.98, 44 fa: 3487587.49, 45 na: 3443.89849, 46 ch: 317053.408, 47 rd: 1268213.63, 48 fr: 31705.3408 49 }, 50 }; 51 52 // The actual plugin constructor 53 function Plugin ( element, options ) { 54 this.element = element; 55 this.settings = $.extend( {}, defaults, options ); 56 this._defaults = defaults; 57 58 this._name = pluginName; 59 this.init(); 60 } 61 62 // Avoid Plugin.prototype conflicts 63 $.extend( Plugin.prototype, { 64 init: function() { 65 var that = this; 66 this.window = $(window); 67 this.currentURL = window.location.href; 68 this.documentHeight = $( document ).height(); 69 this.windowHeight = this.window.height(); 70 this.settings.mapDefaultZoom = parseInt(that.settings.mapDefaultZoom); 71 this.templateCache = {}; 72 this.markers = []; 73 this.ownMarker = {}; 74 this.radiusCircle = {}; 75 this.categories = {}; 76 this.filter = {}; 77 this.address = ""; 78 79 this.geocoder = new google.maps.Geocoder(); 80 81 if(!this.isEmpty($(this.settings.store_locator))){ 82 this.setResultListMaxHeight(); 83 84 // Check if we have a Modal Button (Product Page) 85 if(!this.isEmpty($(this.settings.store_modal_button))){ 86 this.initModal(function(){ 87 that.initStoreLocator(); 88 that.setResultListMaxHeight(); 89 }); 90 } else { 91 $(this.settings.store_modal_close).hide(); 92 that.initStoreLocator(); 93 } 94 } 95 if(!this.isEmpty($(this.settings.store_locator_form_store_select))){ 96 that.initForm(); 97 } 98 if(!this.isEmpty($(this.settings.store_locator_embedded_search))){ 99 that.initEmbeddedSearch(); 100 } 101 102 }, 103 setResultListMaxHeight: function() { 104 var resultList = $(this.settings.result_list); 105 var store_locator_sidebar = $(this.settings.store_locator_sidebar); 106 var height = store_locator_sidebar.height() + 20000; 107 108 if(this.settings.mapFullHeight == "1") { 109 height = this.windowHeight - $(this.settings.store_locator_search_box).height(); 110 } 111 resultList.css('max-height', height); 112 }, 113 initModal: function(callback) { 114 var store_modal = $(this.settings.store_modal); 115 var store_modal_button = $(this.settings.store_modal_button); 116 var store_modal_close = $(this.settings.store_modal_close); 117 var that = this; 118 119 store_modal_button.on('click', function() 120 { 121 store_modal.show(); 122 store_modal.modal('show'); 123 callback(); 124 }); 125 126 store_modal_close.on('click', function() 127 { 128 store_modal.hide(); 129 $('.modal-backdrop').remove(); 130 store_modal.modal('hide'); 131 }); 132 }, 133 initStoreLocator: function() { 134 var that = this; 135
136 // Do not load Map again when Modal gets reopened 137 if(that.isEmpty(that.map)){ 138 that.initMap(function(){ 139 if(that.settings.searchBoxAutocomplete === "1") { 140 that.initAutocomplete(); 141 } 142 that.initStoreLocatorButton(); 143 that.initGetCurrentPositionLink(); 144 that.initGetAllStoresLink(); 145 that.autoHeightMap(); 146 that.watchMapDragged(); 147 that.watchAddressFieldEmpty(); 148 that.watchDraggedButton(); 149 150 that.initFilter(); 151 152 var predefinedAddress = that.getParameterByName('location'); 153 if(that.settings.searchBoxAutolocate === "1" && that.isEmpty(predefinedAddress)) { 154 if(that.settings.searchBoxSaveAutolocate === "1") { 155 that.getCurrentPosition(); 156 } else { 157 that.getCurrentPosition(false); 158 } 159 } else { 160 if(!that.isEmpty(predefinedAddress)) { 161 162 var addressField = $(that.settings.store_locator_address_field); 163 addressField.val(predefinedAddress); 164 that.geocodeAddress(predefinedAddress); 165 // Default Lat Lng 166 } else { 167 var currentPosition = new google.maps.LatLng(Number(that.settings.mapDefaultLat), Number(that.settings.mapDefaultLng)); 168 that.setCurrentPosition(currentPosition); 169 } 170 } 171 }); 172 } 173 }, 174 initMap: function(callback) { 175 var mapContainer = $(this.settings.map_container); 176 var mapDefaultZoom = this.settings.mapDefaultZoom; 177 var mapDefaultType = this.settings.mapDefaultType; 178 var mapDefaultLat = Number(this.settings.mapDefaultLat); 179 var mapDefaultLng = Number(this.settings.mapDefaultLng); 180 181 var mapStyling = this.settings.mapStyling; 182 if( !this.isEmpty(mapStyling) ) { 183 mapStyling = JSON.parse(mapStyling); 184 } else { 185 mapStyling = ""; 186 } 187 188 // Construct Map 189 this.map = new google.maps.Map(mapContainer[0], { 190 zoom: mapDefaultZoom, 191 center: new google.maps.LatLng(mapDefaultLat, mapDefaultLng), 192 mapTypeId: google.maps.MapTypeId[mapDefaultType], 193 scrollwheel: false, 194 styles: mapStyling 195 }); 196 197 callback(); 198 }, 199 getCurrentPosition: function(useCookie) { 200 var that = this; 201 202 var ip_geoservice = "https://ip.nf/me.json"; 203 204 var cookieLat = that.getCookie('store_locator_lat'); 205 var cookieLng = that.getCookie('store_locator_lng'); 206 var currentPosition; 207 208 that.maybeShowLoading(); 209 210 if (typeof(useCookie)==='undefined') useCookie = true; 211 212 if(cookieLat !== "" && cookieLng !== "" && useCookie === true){ 213 currentPosition = new google.maps.LatLng(cookieLat, cookieLng); 214 } 215 216 if(typeof(currentPosition) == "undefined") { 217 if (navigator.geolocation) { 218 219 var options = { 220 enableHighAccuracy: true, 221 timeout: 8000, 222 maximumAge: 0 223 }; 224 225 navigator.geolocation.getCurrentPosition(function(position) { 226 227 var currentPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 228 document.cookie="store_locator_lat="+position.coords.latitude; 229 document.cookie="store_locator_lng="+position.coords.longitude; 230 that.setCurrentPosition(currentPosition, true); 231 }, function(error) { 232 console.log(error); 233 234 if(that.settings.searchBoxAutolocateIP == "1") { 235 236 console.log('Getting position via IP!'); 237 $.getJSON(ip_geoservice) 238 .done(function( location ) { 239 var ipLat = location.ip.latitude; 240 var ipLng = location.ip.longitude; 241 if(ipLat == "" || ipLng == "") { 242 alert('Could not find your position. Please enter it manually.'); 243 that.maybeShowLoading(); 244 return; 245 } 246 var currentPosition = new google.maps.LatLng(ipLat, ipLng); 247 document.cookie="store_locator_lat="+ipLat; 248 document.cookie="store_locator_lng="+ipLng; 249 that.setCurrentPosition(currentPosition, true); 250 }); 251 } else { 252 console.log('HTML5 Position disabled'); 253 alert('Could not find your position. Please enter it manually.'); 254 that.maybeShowLoading(); 255 } 256 257 }, options); 258 259 } else { 260 261 if(that.settings.searchBoxAutolocateIP == "1") { 262 263 console.log('Browser Geolocation not supported! Getting position via IP'); 264 265 $.getJSON(ip_geoservice) 266 .done(function( location ) { 267 var ipLat = location.ip.latitude; 268 var ipLng = location.ip.longitude; 269 if(ipLat == "" || ipLng == "") {
270 alert('Could not find your position. Please enter it manually.'); 271 that.maybeShowLoading(); 272 return; 273 } 274 var currentPosition = new google.maps.LatLng(ipLat, ipLng); 275 document.cookie="store_locator_lat="+ipLat; 276 document.cookie="store_locator_lng="+ipLng; 277 that.setCurrentPosition(currentPosition, true); 278 }); 279 } else { 280 console.log('Browser Geolocation not supported!'); 281 alert('Could not find your position. Please enter it manually.'); 282 that.maybeShowLoading(); 283 } 284 } 285 286 } else { 287 that.setCurrentPosition(currentPosition, true); 288 } 289 }, 290 setCurrentPosition: function(latlng, override) { 291 var that = this; 292 var store_locator_address_field = $(this.settings.store_locator_address_field); 293 294 this.currentPosition = latlng; 295 this.lat = latlng.lat(); 296 this.lng = latlng.lng(); 297 298 if(override) { 299 that.maybeShowLoading(); 300 } 301 302 if(store_locator_address_field.val() === "" || override) { 303 304 this.geocodeLatLng(function(address){ 305 store_locator_address_field.val(address); 306 }); 307 } 308 309 // Delete old marker 310 if(!this.isEmpty(this.ownMarker)) { 311 this.ownMarker.setMap(null); 312 } 313 314 this.ownMarker = new google.maps.Marker({ 315 position: latlng, 316 map: this.map, 317 title: 'Your Position!', 318 icon: this.settings.mapDefaultUserIcon 319 }); 320 321 this.drawRadiusCircle(true); 322 this.getStores(); 323 324 }, 325 drawRadiusCircle: function(inital) { 326 var that = this; 327 var mapRadius; 328 var distanceUnit = this.settings.mapDistanceUnit; 329 var earthRadius = this.settings.earthRadi[distanceUnit]; 330 var selectedRadius = $(this.settings.store_locator_filter_radius).find(":selected").val(); 331 332 if(!this.isEmpty(selectedRadius)){ 333 this.radius = parseFloat(selectedRadius); 334 } else { 335 this.radius = parseFloat(this.settings.mapRadius); 336 } 337 338 if(!this.isEmpty(this.radiusCircle) && typeof(this.radiusCircle.setMap) !== "undefined") { 339 this.radiusCircle.setMap(null); 340 } 341 342 if(this.settings.mapDrawRadiusCircle === "0"){ 343 if(this.settings.mapRadiusToZoom === "1") { 344 this.map.setZoom(this.radiusToZoom(this.radius)); 345 } 346 return false; 347 } 348 349 mapRadius = (this.radius / earthRadius) * this.settings.earthRadi.mt; 350 this.radiusCircle = new google.maps.Circle({ 351 center: this.currentPosition, 352 clickable: true, 353 draggable: false, 354 editable: false, 355 fillColor: '#004de8', 356 fillOpacity: 0.27, 357 map: this.map, 358 radius: mapRadius, 359 strokeColor: '#004de8', 360 strokeOpacity: 0.62, 361 strokeWeight: 1 362 }); 363 364 if(inital !== true) { 365 this.map.fitBounds(this.radiusCircle.getBounds()); 366 } 367 }, 368 initAutocomplete: function() { 369 var that = this; 370 var addressField = $(this.settings.store_locator_address_field); 371 var countryRestrict = this.settings.autocompleteCountryRestrict; 372 var type = this.settings.autocompleteType; 373 var map = this.map; 374 375 if ( !addressField) { return; } 376 377 var autocompleteOptions = {}; 378 if(!that.isEmpty(countryRestrict)) { 379 autocompleteOptions.componentRestrictions = {'country' : countryRestrict }; 380 } 381 382 if(!that.isEmpty(type)) { 383 autocompleteOptions.types = [type]; 384 } else { 385 autocompleteOptions.types = ['geocode']; 386 } 387 388 var autocomplete = new google.maps.places.Autocomplete(addressField[0], autocompleteOptions); 389 autocomplete.bindTo('bounds', map); 390 391 autocomplete.addListener('place_changed', function(e){ 392 var place = autocomplete.getPlace(); 393 if(!that.isEmpty(place.formatted_address)) { 394 that.geocodeAddress(place.formatted_address); 395 } else { 396 that.geocodeAddress(place.name); 397 } 398 }); 399 400 var predefinedAddress = that.getParameterByName('location'); 401 if(!that.isEmpty(predefinedAddress)) { 402 addressField.val(predefinedAddress); 403 that.geocodeAddress(predefinedAddress); 404 } 405 }, 406 initStoreLocatorButton: function() { 407 var that = this; 408 var button = $(this.settings.store_locator_find_stores_button); 409 var addressField = $(this.settings.store_locator_address_field); 410 var currentAddress; 411 412 button.on('click', function(e) { 413 e.preventDefault(); 414 currentAddress = addressField.val(); 415 that.geocodeAddress(currentAddress); 416 }); 417 }, 418 watchAddressFieldEmpty : function() { 419 var that = this; 420 var address_field = $(that.settings.store_locator_address_field); 421 422 address_field.on('keyup', function(e) { 423 var $this = $(this); 424 var val = $this.val() 425 if(val == "") { 426 $this.css('border', '2px solid red'); 427 } else { 428 $this.css('border', 'none'); 429 } 430 }); 431 }, 432 initGetCurrentPositionLink: function() { 433 var that = this; 434 var store_locator_get_my_position = $(this.settings.store_locator_get_my_position); 435 436 store_locator_get_my_position.on('click', function(e){ 437 e.preventDefault(); 438 that.getCurrentPosition(false); 439 }); 440 }, 441 initGetAllStoresLink: function() { 442 var that = this; 443 var store_locator_get_all_stores = $(this.settings.store_locator_get_all_stores); 444 445 store_locator_get_all_stores.on('click', function(e){ 446 e.preventDefault(); 447 that.maybeShowLoading(); 448 that.getAllStores('', '', function(response) { 449 450 if(!that.isEmpty(that.radiusCircle) && typeof(that.radiusCircle.setMap) !== "undefined") { 451 that.radiusCircle.setMap(null); 452 } 453 that.map.setZoom(parseInt(that.settings.searchBoxShowShowAllStoresZoom)); 454 var allStoresPosition = new google.maps.LatLng(Number(that.settings.searchBoxShowShowAllStoresLat), Number(that.settings.searchBoxShowShowAllStoresLng)); 455 that.map.setCenter(allStoresPosition); 456 457 that.createMarker(response); 458 that.createResultList(response); 459 that.maybeShowLoading(); 460 }); 461 }); 462 }, 463 maybeShowLoading: function() { 464 var store_locator_loading = $(this.settings.store_locator_loading); 465 466 if(store_locator_loading.hasClass('store-locator-hidden')) 467 { 468 store_locator_loading.removeClass('store-locator-hidden'); 469 } else { 470 store_locator_loading.addClass('store-locator-hidden'); 471 } 472 }, 473 geocodeAddress: function (address) { 474 var that = this; 475 var countryRestrict = that.settings.autocompleteCountryRestrict; 476 477 if ( address ) { 478 if(!that.isEmpty(countryRestrict)) { 479 var address2 = { 480 address: address, 481 componentRestrictions : {'country' : countryRestrict } 482 }; 483 } else { 484 var address2 = { 485 address: address, 486 }; 487 } 488 this.geocoder.geocode( address2, function ( results, status ) { 489 if ( status === google.maps.GeocoderStatus.OK ) { 490 that.setCurrentPosition(results[0].geometry.location); 491 } 492 } ); 493 } else { 494 $(that.settings.store_locator_address_field).css('border', '2px solid red'); 495 } 496 },
497 geocodeLatLng: function (callback) { 498 var that = this; 499 var latlng = {lat: this.lat, lng: this.lng}; 500 501 this.geocoder.geocode({'location': latlng}, function(results, status) { 502 if (status === google.maps.GeocoderStatus.OK) { 503 if (results[1]) { 504 callback(results[1].formatted_address); 505 } else { 506 window.alert('No results found'); 507 } 508 } else { 509 window.alert('Geocoder failed due to: ' + status); 510 } 511 }); 512 }, 513 autoHeightMap: function() { 514 515 var mapContainer = $(this.settings.map_container); 516 var store_locator_sidebar = $(this.settings.store_locator_sidebar); 517 var mapHeight = $(store_locator_sidebar).height(); 518 519 if(mapHeight < this.settings.map_min_height) { 520 mapHeight = this.settings.map_min_height; 521 } 522 523 if(this.settings.mapFullHeight == "1") { 524 mapHeight = this.windowHeight; 525 } 526 527 mapContainer.css('height', mapHeight); 528 google.maps.event.trigger(this.map, "resize"); 529 530 }, 531 getStores: function() { 532 var that = this; 533 that.maybeShowLoading(); 534 535 jQuery.ajax({ 536 url: that.settings.ajax_url, 537 type: 'post', 538 dataType: 'JSON', 539 data: { 540 action: 'get_stores', 541 lat: that.lat, 542 lng: that.lng, 543 radius: that.radius, 544 categories: that.categories, 545 filter: that.filter, 546 }, 547 success : function( response ) { 548 that.createMarker(response); 549 that.createResultList(response); 550 that.maybeShowLoading(); 551 if (window.history.replaceState) { 552 that.buildReplaceState(); 553 } 554 that.drawRadiusCircle(); 555 }, 556 error: function(jqXHR, textStatus, errorThrown) { 557 that.maybeShowLoading(); 558 alert('An Error Occured: ' + jqXHR.status + ' ' + errorThrown + '! Please contact System Administrator!'); 559 } 560 }); 561 }, 562 createMarker: function(stores) { 563 var that = this; 564 var storesLength = Object.keys(stores).length; 565 var store; 566 var i = 0; 567 var marker; 568 var map = this.map; 569 var infowindow = new google.maps.InfoWindow({ 570 content: "" 571 }); 572 573 // Clean markers 574 while(this.markers.length){ 575 this.markers.pop().setMap(null); 576 } 577 // Create Markers 578 if(storesLength > 0) { 579 for (i; i < storesLength; i++) { 580 581 store = stores[i]; 582 store.map = this.map; 583 this.store = store; 584 store.position = new google.maps.LatLng(store.lat, store.lng); 585 586 if(!that.isEmpty(store.ic)) { 587 store.icon = store.ic; 588 } else if(!that.isEmpty(that.settings.store_locator_category_icon)) { 589 store.icon = that.settings.store_locator_category_icon; 590 } else { 591 store.icon = that.settings.mapDefaultIcon; 592 } 593 594 // Label? 595 // store.label = i.toString(); 596 marker = new google.maps.Marker(store); 597 this.markers.push(marker); 598 if(this.settings.infowindowEnabled === "1") { 599 this.createInfowindow(marker, map, infowindow, store); 600 } 601 } 602 } 603 }, 604 createInfowindow: function(marker, map, infowindow, store) { 605 var that = this; 606 607 var infowindowLinkAction = this.settings.infowindowLinkAction; 608 store.infowindowAction = store.gu; 609 if(infowindowLinkAction == "web") { 610 store.infowindowAction = store.we; 611 } 612 if(infowindowLinkAction == "tel") { 613 store.infowindowAction = 'tel:' + store.te; 614 } 615 if(infowindowLinkAction == "email") { 616 store.infowindowAction = 'mailto:' + store.em; 617 } 618 619 var infowindowLinkActionNewTab = ''; 620 if(this.settings.infowindowLinkActionNewTab == "1") { 621 infowindowLinkActionNewTab = ' target="_blank" '; 622 } 623 624 if(!that.isEmpty(that.settings.showContactStorePage)) { 625 var arr = that.settings.showContactStorePage.split('?'); 626 if (arr.length > 1 && arr[1] !== '') { 627 var showContactStorePage = that.settings.showContactStorePage + '&'; 628 } else { 629 var showContactStorePage = that.settings.showContactStorePage + '?'; 630 } 631 } 632 633 var content = '<div id="store_locator_infowindow_' + store.ID + '" class="store_locator_infowindow">' + 634 '<div class="store-locator-col-sm-' + that.settings.infowindowDetailsColumns + ' store_locator_details">'; 635 if(this.settings.infowindowLinkAction !== "none") { 636 content += '<a href="' + store.infowindowAction + '" ' + infowindowLinkActionNewTab + '>' + 637 '<h3 class="store_locator_name">' + store.na + ' <i class="fa fa-chevron-right"></i></h3>' + 638 '</a>'; 639 640 } else { 641 content += '<h3 class="store_locator_name">' + store.na + '</h3>'; 642 } 643 content += !that.isEmpty(store.dc) ? '<span class="store_locator_distance">
643' + that.settings.showDistanceText + ': ' + store.dc + '<br/></span>' : ''; 644 content += '<p class="store_locator_address">'; 645 646 if(that.settings.showAddressStyle == "american") { 647 content += !that.isEmpty(store.st) ? '<span class="store_locator_street">' + store.st + '<br/></span>' : ''; 648 content += !that.isEmpty(store.ct) ? '<span class="store_locator_city">' + store.ct + ', </span>' : ''; 649 content += !that.isEmpty(store.rg) ? '<span class="store_locator_region">' + store.rg + ' </span>' : ''; 650 content += !that.isEmpty(store.zp) ? '<span class="store_locator_zip">' + store.zp + '<br/></span>' : ''; 651 content += !that.isEmpty(store.co) ? '<span class="store_locator_country">' + store.co + '</span>' : ''; 652 } else { 653 content += !that.isEmpty(store.st) ? '<span class="store_locator_street">' + store.st + '<br/></span>' : ''; 654 content += !that.isEmpty(store.zp) ? '<span class="store_locator_zip">' + store.zp + '</span>' : ''; 655 content += !that.isEmpty(store.ct) ? '<span class="store_locator_city">' + store.ct + '<br/></span>' : ''; 656 content += !that.isEmpty(store.rg) ? '<span class="store_locator_region">' + store.rg + '</span>' : ''; 657 content += !that.isEmpty(store.co) ? '<span class="store_locator_country">' + store.co + '</span>' : ''; 658 } 659 660 content += '</p>' + 661 '<p class="store_locator_contact">'; 662 content += !that.isEmpty(store.te) ? '<span class="store_locator_tel">' + that.settings.showTelephoneText + ': <a href="tel:' + store.te + '">' + store.te + '</a><br/></span>' : ''; 663 content += !that.isEmpty(store.em) ? '<span class="store_locator_email">' + that.settings.showEmailText + ': <a href="mailto:' + store.em + '">' + store.em + '</a><br/></span>' : ''; 664 content += !that.isEmpty(store.mo) ? '<span class="store_locator_mobile">' + that.settings.showMobileText + ': <a href="tel:' + store.mo + '">' + store.mo + '</a><br/></span>' : ''; 665 content += !that.isEmpty(store.fa) ? '<span class="store_locator_fax">' + that.settings.showFaxText + ': ' + store.fa + '<br/></span>' : ''; 666 content += !that.isEmpty(store.we) ? '<span class="store_locator_website">' + that.settings.showWebsiteText + ': <a href="' + store.we + '" target="_blank">' + store.we + '</a><br/></span>' : ''; 667 content += '</p>' + 668 '<p class="store_locator_actions">'; 669 670 content += !that.isEmpty(store.lat) ? '<a href="http://maps.google.com/maps?saddr=' + this.lat + ',' + this.lng + '&daddr=' + store.lat + ',' + store.lng + '" class="btn button btn-primary btn-lg store_locator_get_direction" target="_blank"><i class="fa fa-compass"></i> '+that.settings.showGetDirectionText+'</a>' : ''; 671 672 content += !that.isEmpty(that.settings.showContactStorePage) ? '<a href="' + showContactStorePage + 'store_id=' + store.ID + '&address=' + encodeURIComponent($(that.settings.store_locator_address_field).val()) + '&lat=' + that.lat + '&lng=' + that.lng + '" class="btn button btn-primary btn-lg store_locator_contact_store"><i class="fa fa-mail-forward"></i> '+that.settings.showContactStoreText+'</a>' : ''; 673 674 content += !that.isEmpty(store.te) ? '<a href="tel:' + store.te + '" class="btn button btn-primary btn-lg store_locator_call_now"><i class="fa fa-phone"></i> '+that.settings.showCallNowText+'</a>' : ''; 675 676 content += !that.isEmpty(store.we) ? '<a href="' + store.we + '" class="btn button btn-primary btn-lg store_locator_visit_website" target="_blank"><i class="fa fa-globe"></i> '+that.settings.showVisitWebsiteText+'</a>' : ''; 677 678 content += !that.isEmpty(store.em) ? '<a href="mailto:' + store.em + '" class="btn button btn-primary btn-lg store_locator_write_email"><i class="fa fa-envelope-o"></i> '+that.settings.showWriteEmailText+'</a>' : ''; 679 680 content += '</p>' + 681 '</div>'; 682 683 content += !that.isEmpty(store.im) ? '<div class="store-locator-col-sm-' + that.settings.infowindowImageColumns + ' store_locator_image"> <img src="' + store.im + '" class="img-responsive" width="'+that.settings.imageDimensions.width+'" height="'+that.settings.imageDimensions.height+'" /></div>' : ''; 684 685 if(!that.isEmpty(store.op)) { 686 content += '<div class="store-locator-col-sm-' + that.settings.infowindowOpeningHoursColumns + ' store_locator_opening_hours">' + 687 that.createOpeningHoursTable(store.op)+ 688 '</div>'; 689 } 690 content += !that.isEmpty(store.de) ? '<div class="store-locator-col-sm-12 store_locator_description">' + 691 '' + store.de + '' + 692 '</div>' : '';
693 content += '</div>'; 694 695 marker.addListener('click', function() { 696 697 if(!that.isEmpty(store.ic)) { 698 this.setIcon(store.ic); 699 } else if(!that.isEmpty(that.settings.store_locator_category_icon)) { 700 this.setIcon(that.settings.store_locator_category_icon); 701 } else { 702 this.setIcon(that.settings.mapDefaultIconHover); 703 } 704 705 infowindow.setContent(content); 706 infowindow.open(map, this); 707 708 if(that.settings.mapPanToOnHover == "1") { 709 that.map.panTo(this.getPosition()); 710 } 711 712 google.maps.event.addListener(map, 'click', function() { 713 infowindow.close(); 714 }); 715 google.maps.event.addListener(that.radiusCircle, 'click', function() { 716 infowindow.close(); 717 }); 718 }); 719 720 marker.addListener('mouseover', function() { 721 if(that.settings.infowindowCheckClosed == "1") { 722 if(!that.isInfoWindowOpen(infowindow)) { 723 google.maps.event.trigger(this, 'click'); 724 } 725 } else { 726 google.maps.event.trigger(this, 'click'); 727 } 728 }); 729 marker.addListener('mouseout', function() { 730 if(!that.isEmpty(store.ic)) { 731 this.setIcon(store.ic); 732 } else if(!that.isEmpty(that.settings.store_locator_category_icon)) { 733 this.setIcon(that.settings.store_locator_category_icon); 734 } else { 735 this.setIcon(that.settings.mapDefaultIcon); 736 } 737 }); 738 }, 739 createResultList: function(stores) 740 { 741 var that = this; 742 var storesLength = Object.keys(stores).length; 743 var resultList = $(this.settings.result_list); 744 var resultListIconEnabled = this.settings.resultListIconEnabled; 745 var resultListIcon = this.settings.resultListIcon; 746 var resultListIconSize = this.settings.resultListIconSize; 747 var resultListIconColor = this.settings.resultListIconColor; 748 749 var resultListPremiumIconEnabled = this.settings.resultListPremiumIconEnabled; 750 var resultListPremiumIcon = this.settings.resultListPremiumIcon; 751 var resultListPremiumIconSize = this.settings.resultListPremiumIconSize; 752 var resultListPremiumIconColor = this.settings.resultListPremiumIconColor; 753 754 var resultListLinkAction = this.settings.resultListLinkAction; 755 756 var store; 757 var premiumClass; 758 var i = 0; 759 var content; 760 var filterBadges; 761 762 if(!that.isEmpty(that.settings.showContactStorePage)) { 763 var arr = that.settings.showContactStorePage.split('?'); 764 if (arr.length > 1 && arr[1] !== '') { 765 var showContactStorePage = that.settings.showContactStorePage + '&'; 766 } else { 767 var showContactStorePage = that.settings.showContactStorePage + '?'; 768 } 769 } 770 771 resultList.html(''); 772 if(storesLength > 0) { 773 for (i; i < storesLength; i++) { 774 store = stores[i]; 775 776 content = ''; 777 premiumClass = ''; 778 if(store.pr === "1") { 779 premiumClass = ' store-locator-is-premium'; 780 } 781 782 if(resultListIconEnabled === "1") { 783 content += '<div class="store-locator-col-sm-2 store_locator_icon store-locator-hidden-sm store-locator-hidden-xs">' + 784 '<i style="color: '+ resultListIconColor +';" class="fa '+ resultListIcon +' ' + resultListIconSize +'"></i>' + 785 '</div>' + 786 '<div class="store-locator-col-sm-10 store_locator_details">'; 787 } else if(that.settings.showImage == "1" && store.im) { 788 789 content += '<div class="store-locator-col-sm-4 store_locator_image_container ' + that.settings.imagePosition + '">'; 790 content += !that.isEmpty(store.im) ? '<img src="' + store.im + '" class="store-locator-img-responsive" width="'+that.settings.imageDimensions.width+'" height="'+that.settings.imageDimensions.height+'" />' : ''; 791 content += '</div>'; 792 content += '<div class="store-locator-col-sm-8 store_locator_details">'; 793 } else { 794 content += '<div class="store-locator-col-sm-12 store_locator_details ' + premiumClass + '">'; 795 } 796 797 var resultListLinkAction = this.settings.resultListLinkAction; 798 799 store.resultListLinkAction = store.gu; 800 if(resultListLinkAction == "web") { 801 store.resultListLinkAction = store.we; 802 } 803 if(resultListLinkAction == "tel") { 804 store.resultListLinkAction = 'tel:' + store.te; 805 } 806 if(resultListLinkAction == "email") { 807 store.resultListLinkAction = 'mailto:' + store.em; 808 } 809 810 var resultListLinkActionNewTab = ''; 811 if(this.settings.resultListLinkActionNewTab == "1") { 812 resultListLinkActionNewTab = ' target="_blank" '; 813 } 814 815 if(this.settings.resultListLinkAction !== "none") { 816 content += '<a href="' + store.resultListLinkAction + '" ' + resultListLinkActionNewTab + '>' + 817 '<h3 class="store_locator_name">' + store.na + ' <i class="fa fa-chevron-right"></i></h3>' + 818 '</a>'; 819 820 } else { 821 content += '<h3 class="store_locator_name">' + store.na + '</h3>'; 822 } 823 824 content += !that.isEmpty(store.dc) ? '<span class="store_locator_distance">
824' + that.settings.showDistanceText + ': ' + store.dc + '<br/></span>' : ''; 825 826 filterBadges = ""; 827 if(!that.isEmpty(store.fi)) { 828 $.each(store.fi, function(i, item){ 829 filterBadges += that.createBadge(item); 830 }); 831 } 832 833 if(!that.isEmpty(store.ca)) { 834 $.each(store.ca, function(i, item){ 835 filterBadges += that.createBadge(item); 836 }); 837 } 838 839 content += !that.isEmpty(filterBadges) ? '<span className="store_locator_badges">' + 840 filterBadges + 841 '<br/></span>' : ''; 842 843 '<p class="store_locator_address">'; 844 845 if(that.settings.showAddressStyle == "american") { 846 content += !that.isEmpty(store.st) ? '<span class="store_locator_street">' + store.st + '<br/></span>' : ''; 847 content += !that.isEmpty(store.ct) ? '<span class="store_locator_city">' + store.ct + ', </span>' : ''; 848 content += !that.isEmpty(store.rg) ? '<span class="store_locator_region">' + store.rg + ' </span>' : ''; 849 content += !that.isEmpty(store.zp) ? '<span class="store_locator_zip">' + store.zp + '<br/></span>' : ''; 850 content += !that.isEmpty(store.co) ? '<span class="store_locator_country">' + store.co + '</span>' : ''; 851 } else { 852 content += !that.isEmpty(store.st) ? '<span class="store_locator_street">' + store.st + '<br/></span>' : ''; 853 content += !that.isEmpty(store.zp) ? '<span class="store_locator_zip">' + store.zp + '</span>' : ''; 854 content += !that.isEmpty(store.ct) ? '<span class="store_locator_city">' + store.ct + '<br/></span>' : ''; 855 content += !that.isEmpty(store.rg) ? '<span class="store_locator_region">' + store.rg + '</span>' : ''; 856 content += !that.isEmpty(store.co) ? '<span class="store_locator_country">' + store.co + '</span>' : ''; 857 } 858 859 content += '</p>' + 860 '<p class="store_locator_contact">'; 861 content += !that.isEmpty(store.te) ? '<span class="store_locator_tel">' + that.settings.showTelephoneText + ': <a href="tel:' + store.te + '">' + store.te + '</a><br/></span>' : ''; 862 content += !that.isEmpty(store.em) ? '<span class="store_locator_email">' + that.settings.showEmailText + ': <a href="mailto:' + store.em + '">' + store.em + '</a><br/></span>' : ''; 863 content += !that.isEmpty(store.mo) ? '<span class="store_locator_mobile">' + that.settings.showMobileText + ': <a href="tel:' + store.mo + '">' + store.mo + '</a><br/></span>' : ''; 864 content += !that.isEmpty(store.fa) ? '<span class="store_locator_fax">' + that.settings.showFaxText + ': ' + store.fa + '</span>' : ''; 865 866 content += !that.isEmpty(store.we) ? '<span class="store_locator_website">' + that.settings.showWebsiteText + ': <a href="' + store.we + '" target="_blank">' + store.we + '</a><br/></span>' : ''; 867 content += '</p>'; 868 content += !that.isEmpty(store.de) ? '<div class="store-locator-col-sm-12 store_locator_result_list_description">' + 869 '<p>' + store.de + '</p>' + 870 '</div>' : ''; 871 content += '<p class="store_locator_actions">'; 872 873 content += !that.isEmpty(store.lat) ? '<a href="http://maps.google.com/maps?saddr=' + this.lat + ',' + this.lng + '&daddr=' + store.lat + ',' + store.lng + '" class="btn button btn-primary btn-lg store_locator_get_direction" target="_blank"><i class="fa fa-compass"></i> '+that.settings.showGetDirectionText+'</a>' : ''; 874 875 content += !that.isEmpty(that.settings.showContactStorePage) ? '<a href="' + showContactStorePage + 'store_id=' + store.ID + '&address=' + encodeURIComponent($(that.settings.store_locator_address_field).val()) + '&lat=' + that.lat + '&lng=' + that.lng + '" class="btn button btn-primary btn-lg store_locator_contact_store"><i class="fa fa-mail-forward"></i> '+that.settings.showContactStoreText+'</a>' : ''; 876 877 content += !that.isEmpty(store.te) ? '<a href="tel:' + store.te + '" class="btn button btn-primary btn-lg store_locator_call_now"><i class="fa fa-phone"></i> '+that.settings.showCallNowText+'</a>' : ''; 878 879 content += !that.isEmpty(store.we) ? '<a href="' + store.we + '" class="btn button btn-primary btn-lg store_locator_visit_website" target="_blank"><i class="fa fa-globe"></i> '+that.settings.showVisitWebsiteText+'</a>' : ''; 880 881 content += !that.isEmpty(store.em) ? '<a href="mailto:' + store.em + '" class="btn button btn-primary btn-lg store_locator_write_email"><i class="fa fa-envelope-o"></i> '+that.settings.showWriteEmailText+'</a>' : ''; 882 883 content += '<a class="btn button btn-primary btn-lg store_locator_show_on_map"><i class="fa fa-map-marker"></i> '+ that.settings.showShowOnMapText + '</a>'; 884 885 content += '</div>'; 886 887 var render = ''; 888 render = '<div id="store_locator_result_list_item_' + store.ID + '" class="store_locator_result_list_item">' + 889 '<div class="store-locator-row">'; 890 render += content; 891 892 if(resultListPremiumIconEnabled === "1" && store.pr === "1") { 893 render += '<i style="color: '+ resultListPremiumIconColor +'; position: absolute; top: 5px; z-index: 999999; right: 10px;" class="fa '+ resultListPremiumIcon +' ' + resultListPremiumIconSize +'"></i>'; 894 } 895 896 render += '</div>' + 897 '</div>'; 898 899 resultList.append(render); 900 } 901 } else { 902 if(this.settings.mapExtendRadius === "1") { 903 if(!$(this.settings.store_locator_filter_radius + " option:last").is(":selected")) { 904 $(this.settings.store_locator_filter_radius + ' option:selected').prop('selected', false).next().prop('selected', 'selected').trigger('change'); 905 } else { 906 this.noResults(); 907 } 908 } else { 909 this.noResults(); 910 } 911 } 912 this.autoHeightMap(); 913 this.map.setCenter(this.currentPosition); 914 this.window.trigger('resize'); 915 916 if(this.settings.resultListHover == "1") { 917 this.resultItemHover(); 918 } 919 920 if(this.settings.showShowOnMap == "1") { 921 this.showOnMap(); 922 } 923 }, 924 createOpeningHoursTable: function(openingHours) { 925 var that = this; 926 927 var table = ''; 928 $.each(openingHours, function(i, item) { 929 if(that.isEmpty(item)) { 930 return true; 931 } 932 933 if(i % 2 === 0) { 934 table += '<div class="store-locator-row">'; 935 table += '<div class="store-locator-col-sm-12">'; 936 } 937 938 if(i % 2 === 0) { 939 if(i === "0") { table += that.settings.showOpeningHoursMonday; } 940 if(i === "2") { table += that.settings.showOpeningHoursTuesday; } 941 if(i === "4") { table += that.settings.showOpeningHoursWednesday; } 942 if(i === "6") { table += that.settings.showOpeningHoursThursday; } 943 if(i === "8") { table += that.settings.showOpeningHoursFriday; } 944 if(i === "10") { table += that.settings.showOpeningHoursSaturday; } 945 if(i === "12") { table += that.settings.showOpeningHoursSunday; } 946 947 table += ': ' + item; 948 } else { 949 table += " - " + item + ' ' + that.settings.showOpeningHoursClock; 950 } 951 952 if(i % 2 !== 0) { 953 table += '</div>'; 954 table += '</div>'; 955 } 956 957 }); 958 if(!that.isEmpty(table)) { 959 var title = '<h3 class="store_locator_opening_hours_title">' + that.settings.showOpeningHoursText + '</h3>'; 960 table = '<div class="store-locator-opening-hours" id="store-locator-opening-hours">' + table + '</div>'; 961 table = title + table; 962 } 963 964 return table; 965 }, 966 createBadge: function(value) { 967 var that = this; 968 969 var badgeCSS = that.slugify(value); 970 var template = '<span class="store-locator-label store-locator-label-success ' + badgeCSS + '">%s</span> '; 971 972 return that.sprintf(template, value); 973 }, 974 noResults: function() { 975 var resultList = $(this.settings.result_list); 976 977 resultList.html(''); 978 resultList.append('<h4 class="store_locator_no_stores">' + this.settings.resultListNoResultsText + '</h4>'); 979 this.autoHeightMap(); 980 }, 981 resultItemHover: function() { 982 var that = this; 983 var resultList = $(this.settings.result_list); 984 985 $('.store_locator_result_list_item').each(function(i, item){ 986 $(item).on('mouseenter', function(){ 987 google.maps.event.trigger(that.markers[i], 'click'); 988 }); 989 }); 990 }, 991 showOnMap: function() { 992 var that = this; 993 var resultList = $(this.settings.result_list); 994 995 $('.store_locator_show_on_map').each(function(i, item){ 996 $(item).on('click', function(){ 997 google.maps.event.trigger(that.markers[i], 'click'); 998 }); 999 }); 1000 }, 1001 initFilter: function() { 1002 var that = this; 1003 var store_locator_filter_open_close = $(this.settings.store_locator_filter_open_close); 1004 var store_locator_filter_icon = store_locator_filter_open_close.find('i'); 1005 1006 store_locator_filter_open_close.on('click', function(){ 1007 that.maybeShowFilter(); 1008 }); 1009
1010 that.watchRadiusSelection(); 1011 that.watchCategoriesSelection(); 1012 that.watchCheckboxFilter(); 1013 that.watchSelectFilter(); 1014 that.updateActiveFilter(); 1015 }, 1016 maybeShowFilter: function() { 1017 var store_locator_filter_content = $(this.settings.store_locator_filter_content); 1018 var store_locator_filter_open_close = $(this.settings.store_locator_filter_open_close); 1019 var store_locator_filter_icon = store_locator_filter_open_close.find('i'); 1020 1021 if(store_locator_filter_content.is(":hidden")) 1022 { 1023 store_locator_filter_icon.removeClass('fa-chevron-down'); 1024 store_locator_filter_icon.addClass('fa-chevron-up'); 1025 store_locator_filter_content.fadeIn(); 1026 } else { 1027 store_locator_filter_icon.addClass('fa-chevron-down'); 1028 store_locator_filter_icon.removeClass('fa-chevron-up'); 1029 store_locator_filter_content.fadeOut(); 1030 } 1031 }, 1032 watchRadiusSelection: function() { 1033 var that = this; 1034 var selectedRadius = $(this.settings.store_locator_filter_radius); 1035 1036 selectedRadius.on('change', function(){ 1037 that.drawRadiusCircle(); 1038 1039 that.updateActiveFilter(); 1040 that.getStores(); 1041 }); 1042 1043 var predefinedRadius = that.getParameterByName('radius'); 1044 if(!that.isEmpty(predefinedRadius)) { 1045 var options = selectedRadius.find('option'); 1046 $.each(options, function(i, index) { 1047 var option = $(this); 1048 option.prop('selected', false); 1049 if(option.val() == predefinedRadius) { 1050 option.prop('selected', true); 1051 } 1052 }); 1053 } 1054 }, 1055 watchCategoriesSelection: function() { 1056 var that = this; 1057 var selectedCategories = $(this.settings.store_locator_filter_categories); 1058 1059 if(selectedCategories.length == 0) { 1060 var selectedCategories = $('.store_locator_category_filter_image'); 1061 var selectedCategoryID = $('.store_locator_category_filter_image[data-selected="selected"]').data('category'); 1062 1063 if(selectedCategoryID > 0) { 1064 that.categories = {0: selectedCategoryID }; 1065 } 1066 1067 selectedCategories.on('click', function(){ 1068 var selected = $(this); 1069 selectedCategoryID = selected.data('category'); 1070 1071 var categoryIcon = $(selected).data('icon'); 1072 if(!that.isEmpty(categoryIcon)) { 1073 that.settings.store_locator_category_icon = categoryIcon; 1074 } else { 1075 that.settings.store_locator_category_icon = ''; 1076 } 1077 that.categories = {0: selectedCategoryID }; 1078 that.updateActiveFilter(); 1079 that.getStores(); 1080 }); 1081 } else { 1082 1083 var selectedCategoryID = selectedCategories.find(':selected').val(); 1084 var predefinedCategory = that.getParameterByName('category'); 1085 1086 if(!that.isEmpty(predefinedCategory) ) { 1087 var tst = selectedCategories.val(predefinedCategory); 1088 selectedCategoryID = predefinedCategory; 1089 } 1090 1091 that.categories = {0: selectedCategoryID }; 1092 selectedCategories.on('change', function(){ 1093 var selected = selectedCategories.find(':selected'); 1094 selectedCategoryID = selected.val(); 1095 1096 var categoryIcon = $(selected).data('icon'); 1097 if(!that.isEmpty(categoryIcon)) { 1098 that.settings.store_locator_category_icon = categoryIcon; 1099 } else { 1100 that.settings.store_locator_category_icon = ''; 1101 } 1102 that.categories = {0: selectedCategoryID }; 1103 that.updateActiveFilter(); 1104 that.getStores(); 1105 }); 1106 } 1107 }, 1108 watchCheckboxFilter: function() { 1109 var that = this; 1110 var filterCheckboxes = $(this.settings.store_locator_filter_checkbox); 1111 var filterSelects = $(this.settings.store_locator_filter_select); 1112 1113 var predefinedFilter = that.getQuerystringData('filter[]'); 1114 1115 if(typeof predefinedFilter == 'string' ) { 1116 predefinedFilter = {0 : predefinedFilter}; 1117 } 1118 1119 if(typeof predefinedFilter == 'undefined' ) { 1120 predefinedFilter = {}; 1121 } 1122 1123 filterCheckboxes.each(function(i, item) { 1124 var checkbox = $(item); 1125 1126 if(!that.isEmpty(predefinedFilter)) { 1127 $.each(predefinedFilter, function(i, index) { 1128 if(checkbox.prop('name') == index) { 1129 checkbox.prop('checked', 'checked'); 1130 } 1131 }); 1132 } 1133 1134 var isChecked = checkbox.is(":checked"); 1135 1136 if(isChecked) { 1137 var filter = checkbox.prop("name"); 1138 that.filter[filter] = filter; 1139 } 1140 }); 1141 1142 $(filterCheckboxes).on('change', function () { 1143 that.filter = {}; 1144 filterCheckboxes.each(function(i, item) { 1145 var checkbox = $(item); 1146 var isChecked = checkbox.is(":checked"); 1147 1148 if(isChecked) { 1149 var filter = checkbox.prop("name"); 1150 that.filter[filter] = filter; 1151 } 1152 }); 1153 filterSelects.each(function(i, item) { 1154 var select = $(item); 1155 var isSelected = select.find(":selected"); 1156 1157 if(isSelected) { 1158 var filter = isSelected.val(); 1159 if(!that.isEmpty(filter)) { 1160 that.filter[filter] = filter; 1161 } 1162 } 1163 }); 1164 that.updateActiveFilter(); 1165 that.getStores(); 1166 }); 1167 }, 1168 watchSelectFilter: function() { 1169 var that = this; 1170 var filterSelects = $(this.settings.store_locator_filter_select); 1171 var filterCheckboxes = $(this.settings.store_locator_filter_checkbox); 1172 1173 var predefinedFilter = that.getQuerystringData('filter[]'); 1174 1175 if(typeof predefinedFilter == 'string' ) { 1176 predefinedFilter = {0 : predefinedFilter}; 1177 } 1178 1179 if(typeof predefinedFilter == 'undefined' ) { 1180 predefinedFilter = {}; 1181 } 1182 1183 filterSelects.each(function(i, item) { 1184 var select = $(item); 1185 var options = select.find('option'); 1186 options.each(function(i, item) { 1187 1188 var option = $(this); 1189 if(!that.isEmpty(predefinedFilter)) { 1190 $.each(predefinedFilter, function(i, index) { 1191 if(option.val() == index) { 1192 select.val(index); 1193 } 1194 }); 1195 } 1196 1197 var isSelected = select.find(":selected"); 1198 if(isSelected) { 1199 var filter = isSelected.val(); 1200 if(!that.isEmpty(filter)) { 1201 that.filter[filter] = filter; 1202 } 1203 } 1204 }); 1205 }); 1206 1207 $(filterSelects).on('change', function () { 1208 that.filter = {}; 1209 filterSelects.each(function(i, item) { 1210 var select = $(item); 1211 var isSelected = select.find(":selected"); 1212 1213 if(isSelected) { 1214 var filter = isSelected.val(); 1215 if(!that.isEmpty(filter)) { 1216 that.filter[filter] = filter; 1217 } 1218 } 1219 }); 1220 filterCheckboxes.each(function(i, item) { 1221 var checkbox = $(item); 1222 var isChecked = checkbox.is(":checked"); 1223 1224 if(isChecked) { 1225 var filter = checkbox.prop("name"); 1226 that.filter[filter] = filter; 1227 } 1228 }); 1229 that.updateActiveFilter(); 1230 that.getStores(); 1231 }); 1232 }, 1233 updateActiveFilter: function() 1234 { 1235 var that = this; 1236 var store_locator_filter = $(this.settings.store_locator_filter); 1237 var store_locator_filter_active_filter = $(this.settings.store_locator_filter_active_filter); 1238 var selectedCategories = store_locator_filter.find('select'); 1239 var selectedCheckboxFilters = store_locator_filter.find('input
1239:checked'); 1240 var selectedSelectFilters = store_locator_filter.find('.single_filter_filter select :selected'); 1241 var template = '<span class="store_locator_filter_active store-locator-label store-locator-label-success %s">%s</span> '; 1242 var append = ""; 1243 1244 store_locator_filter_active_filter.html(''); 1245 selectedCategories.each(function(i, item){ 1246 var val = $(item).find(':selected').val(); 1247 if(val !== "") { 1248 var text = $(item).find(':selected').text(); 1249 var slug = that.slugify(text); 1250 append = append + that.sprintf(template, slug, text); 1251 } 1252 }); 1253 1254 selectedCheckboxFilters.each(function(i, item) { 1255 var text = $(item).val(); 1256 var slug = that.slugify(text); 1257 append = append + that.sprintf(template, slug, text); 1258 }); 1259 1260 selectedSelectFilters.each(function(i, item) { 1261 var text = $(item).val(); 1262 if(!that.isEmpty(text)) { 1263 var slug = that.slugify(text); 1264 append = append + that.sprintf(template, slug, text); 1265 } 1266 }); 1267 1268 1269 store_locator_filter_active_filter.html(append); 1270 1271 }, 1272 watchResize: function() { 1273 var store_locator_sidebar = $(this.settings.store_locator_sidebar); 1274 var store_modal_close = $(this.settings.store_modal_close); 1275 var windowWidth = this.window.width(); 1276 1277 var top; 1278 // if(windowWidth < 769) { 1279 // top = store_locator_sidebar.height() * -1; 1280 // store_modal_close.css('top', top); 1281 // } else { 1282 // top = 20; 1283 // store_modal_close.css('top', top); 1284 // } 1285 }, 1286 watchMapDragged : function() { 1287 1288 var that = this; 1289 var map = that.map; 1290 1291 var store_locator_dragged_button = $(that.settings.store_locator_dragged_button); 1292 store_locator_dragged_button.fadeOut(); 1293 1294 google.maps.event.addListener(map, 'dragend', function(e) { 1295 store_locator_dragged_button.fadeIn(); 1296 } ); 1297 1298 }, 1299 watchDraggedButton : function () { 1300 1301 var that = this; 1302 var store_locator_dragged_button = $(that.settings.store_locator_dragged_button); 1303 1304 store_locator_dragged_button.on('click', function(e) { 1305 store_locator_dragged_button.fadeOut(); 1306 1307 var coords = that.map.getCenter(); 1308 1309 var currentPosition = new google.maps.LatLng(coords.lat(), coords.lng()); 1310 that.setCurrentPosition(currentPosition); 1311 }); 1312 }, 1313 radiusToZoom: function(radius){ 1314 return Math.round(14-Math.log(radius)/Math.LN2); 1315 }, 1316 initForm : function() { 1317 var that = this; 1318 1319 var predefinedAddress = that.getParameterByName('address'); 1320 var predefinedLat = that.getParameterByName('lat'); 1321 var predefinedLng = that.getParameterByName('lng'); 1322 var addressField = $(this.settings.store_locator_form_customer_address); 1323 var address = addressField.val(); 1324 var lat, lng; 1325 1326 if(!that.isEmpty(predefinedAddress) && that.isEmpty(address)) { 1327 addressField.val(predefinedAddress); 1328 } 1329 1330 if(!that.isEmpty(predefinedLat) && !that.isEmpty(predefinedLng)) { 1331 lat = predefinedLat; 1332 lng = predefinedLng; 1333 } 1334 1335 that.watchFormSelectField(); 1336 that.watchFormAddressField(); 1337 that.initFormAutocomplete(); 1338 that.loadFormStores(lat, lng); 1339 1340 }, 1341 loadFormStores : function(lat, lng) { 1342 var that = this; 1343 1344 var storeSelectField = $(this.settings.store_locator_form_store_select); 1345 var addressField = $(this.settings.store_locator_form_customer_address); 1346 var address = addressField.val(); 1347 var predefinedStoreId = that.getParameterByName('store_id'); 1348 1349 if( (that.isEmpty(lat) || that.isEmpty(lng)) && !that.isEmpty(address)) { 1350 that.geocoder.geocode( { 'address': address }, function ( results, status ) { 1351 if ( status === google.maps.GeocoderStatus.OK ) { 1352 var location = results[0].geometry.location; 1353 lat = location.lat(); 1354 lng = location.lng(); 1355 that.getAllStores(lat, lng, that.storesToSelectField, { store_id : predefinedStoreId, that: that}); 1356 } else { 1357 that.getAllStores(lat, lng, that.storesToSelectField, { store_id : predefinedStoreId, that: that}); 1358 } 1359 } ); 1360 } else { 1361 that.getAllStores(lat, lng, that.storesToSelectField, { store_id : predefinedStoreId, that: that}); 1362 } 1363 1364 }, 1365 watchFormAddressField : function() { 1366 var that = this; 1367 var addressField = $(this.settings.store_locator_form_customer_address); 1368 1369 addressField.on('focusout', function(e) { 1370 var $this = $(this); 1371 var val = $this.val() 1372 1373 that.loadFormStores(); 1374 }); 1375 }, 1376 watchFormSelectField : function () { 1377 var that = this; 1378 var storeSelectField = $(this.settings.store_locator_form_store_select); 1379 var dataName, dataValue; 1380 storeSelectField.on('change', function(e) { 1381 var $this = $(this); 1382 var selected = storeSelectField.find(':selected'); 1383 var val = $this.val() 1384 1385 var possibleData = [ 1386 'name', 1387 'address', 1388 'zip', 1389 'city', 1390 'country', 1391 'region', 1392 'telephone', 1393 'mobile', 1394 'fax', 1395 'email', 1396 'website', 1397 ] 1398 1399 $(possibleData).each(function(i, index) { 1400 var dataName = index; 1401 var dataValue = selected.data(dataName); 1402 1403 if(typeof dataValue !== 'undefined') { 1404 dataValue = dataValue.toString(); 1405 } 1406 1407 if(that.isEmpty(dataValue)) { 1408 dataValue = ""; 1409 } 1410 var inputField = $('input[name="store_locator_form_store_' + dataName + '"]'); 1411 if(inputField.length > 0) { 1412 inputField.val(dataValue); 1413 } 1414 1415 var infoField = $('.store_locator_store_info_' + dataName); 1416 if(infoField.length > 0) { 1417 infoField.html(dataValue); 1418 } 1419 }); 1420 }); 1421 }, 1422 getAllStores: function(lat, lng, callback, options) { 1423 var that = this; 1424 1425 jQuery.ajax({ 1426 url: that.settings.ajax_url, 1427 type: 'post', 1428 dataType: 'JSON', 1429 data: { 1430 action: 'get_all_stores', 1431 lat: lat, 1432 lng: lng, 1433 }, 1434 success : function( response ) { 1435 callback(response, options); 1436 }, 1437 error: function(jqXHR, textStatus, errorThrown) { 1438 alert('An Error Occured: ' + jqXHR.status + ' ' + errorThrown + '! Please contact System Administrator!'); 1439 } 1440 }); 1441 }, 1442 // Form 1443 initFormAutocomplete: function() { 1444 var that = this; 1445 var addressField = $(this.settings.store_locator_form_customer_address); 1446 var countryRestrict = this.settings.autocompleteCountryRestrict; 1447 var type = this.settings.autocompleteType; 1448 var map = this.map; 1449
1450 if ( !addressField) { return; } 1451 1452 var autocompleteOptions = {}; 1453 if(!that.isEmpty(countryRestrict)) { 1454 autocompleteOptions.componentRestrictions = {'country' : countryRestrict }; 1455 } 1456 1457 if(!that.isEmpty(type)) { 1458 autocompleteOptions.types = [type]; 1459 } else { 1460 autocompleteOptions.types = ['geocode']; 1461 } 1462 1463 var autocomplete = new google.maps.places.Autocomplete(addressField[0], autocompleteOptions); 1464 1465 autocomplete.addListener('place_changed', function(e){ 1466 var place = autocomplete.getPlace(); 1467 if(!that.isEmpty(place.formatted_address)) { 1468 addressField.val(place.formatted_address).trigger('focusout'); 1469 } else { 1470 addressField.val(place.name).trigger('focusout'); 1471 } 1472 }); 1473 }, 1474 storesToSelectField: function(stores, options) { 1475 1476 var that = options.that; 1477 var store_id = options.store_id 1478 var storeSelectField = $(that.settings.store_locator_form_store_select); 1479 1480 var html = '<option value="">' + that.settings.trans_select_store + '</option>'; 1481 1482 var storesLength = Object.keys(stores).length; 1483 var i = 0; 1484 var store; 1485 1486 var selected; 1487 var data; 1488 var disabled; 1489 if(storesLength > 0) { 1490 for (i; i < storesLength; i++) { 1491 1492 store = stores[i]; 1493 1494 selected = ""; 1495 if(store.ID == store_id) { 1496 selected = 'selected="selected"'; 1497 } 1498 1499 data = ""; 1500 if(!that.isEmpty(store.na)) { 1501 data += ' data-name="' + store.na + '"'; 1502 if(!that.isEmpty(store.distance)) { 1503 store.distance = parseFloat(store.distance).toFixed(2); 1504 store.na = store.na + ' (' + store.distance + ' ' + that.settings.mapDistanceUnit + ')'; 1505 } 1506 } 1507 if(!that.isEmpty(store.st)) { 1508 data += ' data-address="' + store.st + '"'; 1509 } 1510 if(!that.isEmpty(store.zp)) { 1511 data += ' data-zip="' + store.zp + '"'; 1512 } 1513 if(!that.isEmpty(store.ct)) { 1514 data += ' data-city="' + store.ct + '"'; 1515 } 1516 if(!that.isEmpty(store.co)) { 1517 data += ' data-country="' + store.co + '"'; 1518 } 1519 if(!that.isEmpty(store.rg)) { 1520 data += ' data-region="' + store.rg + '"'; 1521 } 1522 if(!that.isEmpty(store.te)) { 1523 data += ' data-telephone="' + store.te + '"'; 1524 } 1525 if(!that.isEmpty(store.mo)) { 1526 data += ' data-mobile="' + store.mo + '"'; 1527 } 1528 if(!that.isEmpty(store.fa)) { 1529 data += ' data-fax="' + store.fa + '"'; 1530 } 1531 if(!that.isEmpty(store.em)) { 1532 data += ' data-email="' + store.em + '"'; 1533 } 1534 if(!that.isEmpty(store.we)) { 1535 data += ' data-website="' + store.we + '"'; 1536 } 1537 1538 1539 html += '<option value="' + store.ID + '" ' + selected + ' ' + data + '>
1539' + store.na + '</option>'; 1540 } 1541 } 1542 1543 storeSelectField.html(html).trigger('change'); 1544 }, 1545 initEmbeddedSearch : function() { 1546 var that = this; 1547 var addressField = $(this.settings.store_locator_address_field); 1548 var countryRestrict = this.settings.autocompleteCountryRestrict; 1549 var type = this.settings.autocompleteType; 1550 var map = this.map; 1551 1552 if ( !addressField) { return; } 1553 1554 var autocompleteOptions = {}; 1555 if(!that.isEmpty(countryRestrict)) { 1556 autocompleteOptions.componentRestrictions = {'country' : countryRestrict }; 1557 } 1558 1559 if(!that.isEmpty(type)) { 1560 autocompleteOptions.types = [type]; 1561 } else { 1562 autocompleteOptions.types = ['geocode']; 1563 } 1564 1565 var autocomplete = new google.maps.places.Autocomplete(addressField[0], autocompleteOptions); 1566 1567 autocomplete.addListener('place_changed', function(e){ 1568 var place = autocomplete.getPlace(); 1569 if(!that.isEmpty(place.formatted_address)) { 1570 addressField.val(place.formatted_address).trigger('focusout'); 1571 } else { 1572 addressField.val(place.name).trigger('focusout'); 1573 } 1574 }); 1575 1576 var store_locator_get_my_position = $(this.settings.store_locator_get_my_position); 1577 store_locator_get_my_position.on('click', function(e){ 1578 1579 e.preventDefault(); 1580 1581 if (navigator.geolocation) { 1582 1583 var options = { 1584 enableHighAccuracy: true, 1585 timeout: 5000, 1586 maximumAge: 0 1587 }; 1588 1589 navigator.geolocation.getCurrentPosition(function(position) { 1590 1591 if(addressField.val() === "") { 1592 var currentPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 1593 1594 that.currentPosition = currentPosition; 1595 that.lat = currentPosition.lat(); 1596 that.lng = currentPosition.lng(); 1597 1598 that.geocodeLatLng(function(address){ 1599 addressField.val(address); 1600 }); 1601 } 1602 }, function(error) { 1603 console.log(error); 1604 }, options); 1605 } 1606 }); 1607 1608 if(that.settings.searchBoxAutolocate === "1") { 1609 store_locator_get_my_position.trigger('click'); 1610 } 1611 }, 1612 isInfoWindowOpen : function(infoWindow){ 1613 var map = infoWindow.getMap(); 1614 return (map !== null && typeof map !== "undefined"); 1615 }, 1616 buildReplaceState : function() { 1617 var that = this; 1618 var address = $(that.settings.store_locator_address_field).val(); 1619 var categories = that.categories; 1620 var filter = that.filter; 1621 var radius = that.radius; 1622 1623 var queryCheck = that.currentURL.split('?'); 1624 if (queryCheck.length > 1 && queryCheck[1] !== '') { 1625 var url = that.currentURL + '&'; 1626 } else { 1627 var url = that.currentURL + '?'; 1628 } 1629 var url = queryCheck[0] + '?'; 1630 1631 var tmp = ""; 1632 if(!that.isEmpty(address)) { 1633 tmp += 'location=' + address; 1634 } 1635 1636 if(categories[0]) { 1637 if(tmp == "") { 1638 tmp += 'category=' + categories[0]; 1639 } else { 1640 tmp += '&category=' + categories[0]; 1641 } 1642 } 1643 1644 if(radius) { 1645 if(tmp == "") { 1646 tmp += 'radius=' + radius; 1647 } else { 1648 tmp += '&radius=' + radius; 1649 } 1650 } 1651 1652 if(filter) { 1653 var filterLoop = 0; 1654 $.each(filter, function(i, index) { 1655 if(filterLoop == 0 && tmp == "") { 1656 tmp += 'filter[]=' + index; 1657 } else { 1658 tmp += '&filter[]=' + index; 1659 } 1660 filterLoop++; 1661 }); 1662 } 1663 1664 1665 window.history.replaceState('test', 'Store Locator', url + tmp); 1666 }, 1667 ////////////////////// 1668 ///Helper Functions/// 1669 ////////////////////// 1670 isEmpty: function(obj) { 1671 1672 if (obj == null) return true; 1673 if (obj.length > 0) return false; 1674 if (obj.length === 0) return true; 1675 1676 for (var key in obj) { 1677 if (hasOwnProperty.call(obj, key)) return false; 1678 } 1679 1680 return true; 1681 }, 1682 sprintf: function parse(str) { 1683 var args = [].slice.call(arguments, 1), 1684 i = 0; 1685 1686 return str.replace(/%s/g, function() { 1687 return args[i++]; 1688 }); 1689 }, 1690 getCookie: function(cname) { 1691 var name = cname + "="; 1692 var ca = document.cookie.split(';'); 1693 for(var i=0; i<ca.length; i++) { 1694 var c = ca[i]; 1695 while (c.charAt(0)==' ') c = c.substring(1); 1696 if (c.indexOf(name) === 0) return c.substring(name.length, c.length); 1697 } 1698 return ""; 1699 }, 1700 slugify : function (text) { 1701 return text.toString().toLowerCase() 1702 .replace(/\s+/g, '-') // Replace spaces with - 1703 .replace(/[^\w\-]+/g, '') // Remove all non-word chars 1704 .replace(/\-\-+/g, '-') // Replace multiple - with single - 1705 .replace(/^-+/, '') // Trim - from start of text 1706 .replace(/-+$/, ''); // Trim - from end of text 1707 }, 1708 getParameterByName : function (name, url) { 1709 if (!url) url = window.location.href; 1710 name = name.replace(/[\[\]]/g, "\\$&"); 1711 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), 1712 results = regex.exec(url); 1713 if (!results) return null; 1714 if (!results[2]) return ''; 1715 return decodeURIComponent(results[2].replace(/\+/g, " ")); 1716 }, 1717 getQuerystringData : function (name) { 1718 var data = { }; 1719 var parameters = window.location.search.substring(1).split("&"); 1720 for (var i = 0, j = parameters.length; i < j; i++) { 1721 var parameter = parameters[i].split("="); 1722 var parameterName = decodeURIComponent(parameter[0]); 1723 var parameterValue = typeof parameter[1] === "undefined" ? parameter[1] : decodeURIComponent(parameter[1]); 1724 var dataType = typeof data[parameterName]; 1725 if (dataType === "undefined") { 1726 data[parameterName] = parameterValue; 1727 } else if (dataType === "array") { 1728 data[parameterName].push(parameterValue); 1729 } else { 1730 data[parameterName] = [data[parameterName]]; 1731 data[parameterName].push(parameterValue); 1732 } 1733 } 1734 return typeof name === "string" ? data[name] : data; 1735 } 1736 } ); 1737 1738 // Constructor wrapper 1739 $.fn[ pluginName ] = function( options ) { 1740 return this.each( function() { 1741 if ( !$.data( this, "plugin_" + pluginName ) ) { 1742 $.data( this, "plugin_" + 1743 pluginName, new Plugin( this, options ) ); 1744 } 1745 } ); 1746 }; 1747 1748 $.fn.emulateTransitionEnd = function (duration) { 1749 var called = false 1750 var $el = this 1751 $(this).one('bsTransitionEnd', function () { called = true }) 1752 var callback = function () { if (!called) $($el).trigger($.support.transition.end) } 1753 setTimeout(callback, duration) 1754 return this 1755 } 1756
1757 $(document).ready(function() { 1758 1759 $( "body" ).storeLocator( 1760 store_locator_options 1761 ); 1762 1763 } ); 1764 1765})( 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.