Advertisement
azekyo

Eye test js with new iframe

Sep 20th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.95 KB | None | 0 0
  1. //Setup Variables for the functions.
  2. var placeSearch, autocomplete, stores, currentURL;
  3. var componentForm = {
  4. street_number: 'short_name',
  5. route: 'long_name',
  6. locality: 'long_name',
  7. administrative_area_level_1: 'short_name',
  8. country: 'long_name',
  9. postal_code: 'short_name'
  10. };
  11.  
  12. $(window).on('load resize', function() {
  13. equalheight('.equal-height');
  14. });
  15.  
  16. //PW edits: Changed ' to " for store-finder part
  17. /*
  18. $(document).ready(function () {
  19. //STORE LIST FROM JSON FILE
  20. bootstrapMapsComponent();
  21. });
  22. */
  23.  
  24. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. // GOOGLE LOCATION FUNCTIONALITY - GETTING STORE LIST FROM JSON FILE AND DISPLAYING ON PAGE
  26. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27.  
  28. window.gMaps = [];
  29.  
  30. function bootstrapMapsComponent() {
  31. $.getJSON('{{ "store-finder.json" | asset_url }}', function (data) {
  32. stores = data;
  33. setupMaps();
  34. searchFromURL();
  35. newSearch();
  36. submitForm();
  37. getAllStores();
  38. showNearbyStores();
  39. loadBookingIframeFromURL();
  40. initAutocomplete();
  41. });
  42. }
  43.  
  44. //PW edits: changed equals operator to === from ==
  45. function setupMaps() {
  46. //store locators
  47. $('.map.storeLocator').each(function (i, elem) {
  48. if (typeof $(elem).attr('data-initialised') === 'undefined') {
  49. var mapOptions = {
  50. center: new google.maps.LatLng(-33.895516, 151.18117),
  51. zoom: 8,
  52. mapTypeId: google.maps.MapTypeId.ROADMAP,
  53. scrollwheel: false,
  54. streetViewControl: false,
  55. panControl: false,
  56. overviewMapControl: false,
  57. mapTypeControl: false,
  58. //styles: mapStyling
  59. };
  60. window.gMaps[window.gMaps.length] = new google.maps.Map(elem, mapOptions);
  61. addPointsToMap(window.gMaps[window.gMaps.length - 1]);
  62. $(elem).attr('data-initialised', '1');
  63. }
  64. });
  65. }
  66.  
  67. function addPointsToMap(map, selectedStores, storeobject) {
  68. if(!selectedStores){
  69. selectedStores = stores;
  70. }
  71. map.bnMarkers = [];
  72. var offset = 0;
  73. for (var i = 0; i < selectedStores.length; i++) {
  74. //setup
  75. if(storeobject){
  76. var store = selectedStores[i].storeInfo;
  77. }else{
  78. var store = selectedStores[i];
  79. }
  80. var store_spec = store.also || null;
  81. var pos = new google.maps.LatLng(store.lat, store.lon);
  82.  
  83. //add marker
  84. var marker = new google.maps.Marker({
  85. position: pos,
  86. map: map,
  87. title: store.name,
  88. clickable: true
  89. });
  90. //create onClick infoWindow
  91. var mapAddr = store.map_addr || store.address;
  92. var addr2 = mapAddr;
  93. mapAddr = mapAddr.parseGoogleMapsAddr();
  94. addr2 = addr2.parseGoogleMapsAddr();
  95. addrPre = '';
  96.  
  97. //build markers
  98. if (store.url != null && store.url != "" && store.url != "undefined") {
  99. marker.info = new google.maps.InfoWindow({
  100. maxWidth: 300,
  101. content: "<div class=\"gMapPopup\"><div class=\"subhead\">" + store.name + "</div><p>" + store.address + "</p><p>" + store.phone + "</p><p><a href=\"" + store.url + "\" target=\"_blank\" >" + store.url.replace('http://', '').replace('https://', '') + "</p><!--<p><a href=\"http://maps.google.com/maps?q=" + addr2 + "&daddr=" + addr2 + "\" target=\"_blank\">Get Directions &raquo;</a></p>--></div>"
  102. });
  103. }
  104. else {
  105. marker.info = new google.maps.InfoWindow({
  106. maxWidth: 300,
  107. content: "<div class=\"gMapPopup\"><div class=\"subhead\">" + store.name + "</div><p>" + store.address + "</p><p>" + store.phone + "</p><!--<p><a href=\"http://maps.google.com/maps?q=" + addr2 + "&daddr=" + addr2 + "\" target=\"_blank\">Get Directions &raquo;</a></p>--></div>"
  108. });
  109. }
  110. //add necessary info
  111. marker.storeName = store.name;
  112. //add to global for later reference
  113. var markerIndex = i + offset;
  114. map.bnMarkers[markerIndex] = marker;
  115.  
  116. //bind infoWindow to marker
  117. google.maps.event.addListener(marker, 'click', function () {
  118. for (var i = 0; i < map.bnMarkers.length; i++) {
  119. map.bnMarkers[i].info.close();
  120. }
  121. //this.info.open(map, this); Triggered Below!
  122. updateMapsForStore(getStoreInfo(this.storeName));
  123. });
  124. }
  125. }
  126.  
  127. function getMarkerForStore(markers, storeName) {
  128. for (var i = 0; i < markers.length; i++) {
  129. //console.log(markers[i].storeName + ' :: ' + storeName);
  130. if (markers[i].storeName == storeName)
  131. return markers[i];
  132. }
  133. }
  134.  
  135.  
  136. function updateMapsForStore(info, data, val) {
  137. //globals
  138. var selStore;
  139. var info;
  140. var addrPre = "";
  141. var addrPost = "";
  142. var telPre = "";
  143. var telPost = "";
  144. //used to get info or provide null for no store
  145. if (!info) {
  146. info = {};
  147. } else {
  148. var mapAddr = info.map_addr || info.address;
  149. var addr2 = mapAddr;
  150. mapAddr = mapAddr.parseGoogleMapsAddr();
  151. addr2 = addr2.parseGoogleMapsAddr();
  152. addrPre = '<a href="http://maps.google.com/maps?q=' + addr2 + '&daddr=' + addr2 + '" target="_blank">';
  153. addrPost = '</a>';
  154. telPre = '<a href="tel:' + info.phone + '">';
  155. telPost = '</a>';
  156. }
  157.  
  158. //declare info
  159. var name = info.name;
  160. var addr = info.address;
  161. var tel = info.phone;
  162.  
  163. //update map
  164. var zoomLevel = 11;
  165.  
  166. if(val && val.toLowerCase() == 'new zealand'){
  167. zoomLevel = 4;
  168. }
  169.  
  170. if (data != undefined && data.lat != undefined) {
  171. updateMap(data, zoomLevel, name, false);
  172. } else if (info.lat && info.lon) {
  173. updateMap(info, zoomLevel, name, true);
  174. }
  175. }
  176.  
  177. function updateMap(data, zoomLevel, name, isMarker){
  178. $.each(window.gMaps, function (i, map) {
  179. map.setCenter(new google.maps.LatLng(data.lat, data.lon));
  180. map.setZoom(zoomLevel);
  181. if(isMarker){
  182. var marker = getMarkerForStore(map.bnMarkers, name);
  183. marker.info.open(map, marker);
  184. }
  185. });
  186. }
  187.  
  188. function getStoreInfo(name) {
  189. for (var i = 0; i < stores.length; i++) {
  190. if (stores[i].name == name)
  191. return stores[i];
  192. }
  193. }
  194.  
  195.  
  196. function updateStoreList(stores) {
  197. var storeListLimit = stores.length;
  198. $('.map-results').find('.store-limit').text(storeListLimit);
  199. var html = '';
  200. for (i = 0; i < storeListLimit; i++) {
  201. var store = stores[i].storeInfo;
  202. var distance = Math.round( stores[i].dist * 10 ) / 10;
  203. html += '<div class="full-width store">' +
  204. '<div class="store-details col-two-third float-left">'+
  205. '<a href="'+ store.url +'"><b>' + store.name + ' ('+distance+'km)</b></a><br/>' +
  206. '<p class="address">' + store.address + '</p>' +
  207. '<p class=phone">' + store.phone + '</p>' +
  208. '<p class="email"><a href="mailto:' + store.email + '">' + store.email + '</a></p>' +
  209. store.hours +
  210. '</div>' +
  211. '<div class="col-one-third">'+
  212. '<a href="#" class="btn btn--large btn--square uppercase book-appointment" data-appointment_id=\''+store.appointment_url+'\'>Book Now</a>'+
  213. '</div></div>';
  214. }
  215. $('.map-results').find('.store-results').html(html);
  216. storeMarker(stores);
  217. bookAppointment();
  218. }
  219.  
  220. function clearMarkers(markers) {
  221. for(var i = 0; i < markers.length; i++) {
  222. markers[i].setMap(null);
  223. }
  224. }
  225.  
  226. //GET THE CLOSEST STORES (50KM RADIUS)
  227. function getClosestStores(latlong, val) {
  228. var result = new Array(0);
  229. for (var i = 0; i < stores.length; i++) {
  230. var dist = calcDist(latlong, stores[i], val);
  231. if(dist){
  232. result.push({ "dist": dist, "storeInfo": stores[i] });
  233. }
  234. }
  235. // result = _.sortBy(result, function (i) { return i.dist; });
  236. result.sort(function(a, b){return a.dist - b.dist});
  237. return result;
  238. }
  239.  
  240. //CALCULATE THE DISTANCE BETWEEN USERS LOCATION AND STORE
  241. function calcDist(pos1, pos2, val) {
  242. //setup
  243. var R = 6371; // radius of earth in km
  244. var lat1 = parseFloat(pos1.lat);
  245. var lat2 = parseFloat(pos2.lat);
  246. var lon1 = parseFloat(pos1.lon);
  247. var lon2 = parseFloat(pos2.lon);
  248. //fixes
  249. var dLat = (lat2 - lat1).toRad();
  250. var dLon = (lon2 - lon1).toRad();
  251. var lat1 = lat1.toRad();
  252. var lat2 = lat2.toRad();
  253. //calculation
  254. var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
  255. var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  256. var d = R * c;
  257. //result
  258. if(val != 'new zealand'){
  259. if(d < {{ settings.store-finder-radius }}){
  260. return d;
  261. }else{
  262. return null;
  263. }
  264. }else{
  265. return d;
  266. }
  267. }
  268.  
  269. //Generic Functions
  270. if (typeof (Number.prototype.toRad) === "undefined") {
  271. Number.prototype.toRad = function () {
  272. return this * Math.PI / 180;
  273. }
  274. }
  275. String.prototype.parseGoogleMapsAddr = function () {
  276. return this.replace(/ /g, "+").replace(/&/g, "%26").replace(/\?/g, "%3F").replace(/=/g, "%3D");
  277. }
  278.  
  279. //Styling
  280. var mapStyling = [{ "featureType": "administrative", "elementType": "labels.text.fill", "stylers": [{ "color": "#444444" }] }, { "featureType": "administrative.country", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "administrative.country", "elementType": "geometry.fill", "stylers": [{ "visibility": "off" }] }, { "featureType": "administrative.province", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.province", "elementType": "geometry.fill", "stylers": [{ "visibility": "off" }] }, { "featureType": "administrative.locality", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.locality", "elementType": "geometry.stroke", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.locality", "elementType": "labels.text", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.neighborhood", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.land_parcel", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "landscape", "elementType": "all", "stylers": [{ "color": "#f2f2f2" }, { "visibility": "simplified" }] }, { "featureType": "landscape.man_made", "elementType": "all", "stylers": [{ "visibility": "on" }] }, { "featureType": "landscape.natural.landcover", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "landscape.natural.terrain", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.attraction", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.business", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.government", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "road", "elementType": "all", "stylers": [{ "saturation": -100 }, { "lightness": 45 }, { "visibility": "off" }] }, { "featureType": "road.highway", "elementType": "all", "stylers": [{ "visibility": "simplified" }, { "hue": "#ff00c9" }] }, { "featureType": "road.highway", "elementType": "labels", "stylers": [{ "visibility": "off" }] }, { "featureType": "road.highway", "elementType": "labels.text", "stylers": [{ "visibility": "off" }] }, { "featureType": "road.highway", "elementType": "labels.text.fill", "stylers": [{ "visibility": "off" }] }, { "featureType": "road.highway.controlled_access", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "road.arterial", "elementType": "labels.icon", "stylers": [{ "visibility": "off" }] }, { "featureType": "transit", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "transit.station", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "water", "elementType": "all", "stylers": [{ "color": "#e5e8e9" }, { "visibility": "on" }] }];
  281.  
  282. function truncateString(str, length) {
  283. return str.length > length ? str.substring(0, length - 3) + '...' : str
  284. }
  285.  
  286. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  287. // GET THE LOCATION LIST BASED ON USERS POSITION
  288. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  289. function getLocationList(pos, val){
  290. var stores = getClosestStores({ "lat": pos.lat, "lon": pos.lng }, val);
  291. if(stores[0]){
  292. $('.map-results').slideDown(function(){
  293. clearMarkers(window.gMaps[window.gMaps.length - 1].bnMarkers);
  294. addPointsToMap(window.gMaps[window.gMaps.length - 1], stores, true);
  295. $('.no-results').hide();
  296. if(val){
  297. updateMapsForStore(stores[0].storeInfo, { "lat": pos.lat, "lon": pos.lng }, val); //show the closest stores
  298. }else{
  299. $(stores).each(function(key, store){
  300. updateMapsForStore(store.storeInfo, { "lat": pos.lat, "lon": pos.lng }); //show the closest stores
  301. });
  302. }
  303. updateStoreList(stores);
  304. $('html,body').animate({ scrollTop: $('.map-results').position().top - 150 }); //so you can see a little map...
  305. });
  306. }else{
  307. $('.map-results').slideUp();
  308. $('.no-results').show();
  309. }
  310. google.maps.event.trigger(window.gMaps[window.gMaps.length - 1], 'resize'); //Reinit the map because of the map been hidden and displayed
  311. $('.ajax-loader').hide();
  312. var url = window.location.href.split('?')[0] + '?lat=' + pos.lat + '&lng=' + pos.lng;
  313. if(val){
  314. url +='&allStore=true';
  315. }
  316. $('#iframeContainer').slideUp();
  317. history.pushState(null, null, url);
  318. }
  319.  
  320. function searchFromURL(){
  321. var lat = getParameterByName('lat');
  322. var lng = getParameterByName('lng');
  323. var all_stores = getParameterByName('allStore');
  324.  
  325. if(lat && lng){
  326. var pos = {
  327. lat: lat,
  328. lng: lng
  329. };
  330. if(all_stores){
  331. $('.search-location').text('New Zealand');
  332. getLocationList(pos, 'new zealand');
  333. }else{
  334. geocodeLatLng(lat, lng);
  335. getLocationList(pos);
  336. }
  337. }
  338. }
  339.  
  340. function loadBookingIframeFromURL(){
  341. var appointment_id = getParameterByName('appointment_id');
  342. if(appointment_id && appointment_id.length > 3){
  343. $('#iframeContainer').find('#iframe').html('<iframe id="wd_ediary_iframe" height="1000px" width="100%" allowfullscreen="" seamless="seamless" frameborder="0" style="overflow:hidden;clear:both;width:100%!important;" src="https://baileynelsoneyewear.gettimely.com/book/embed?location='+appointment_id+'"></iframe>');
  344. $('#iframeContainer').slideDown();
  345. } else {
  346. if(appointment_id){
  347. $('#iframeContainer').find('#iframe').html('<iframe src="https://baileynelsonnz.healthsite.io/#clinic/'+appointment_id+'" scrolling="yes" id="healthsite" style="width:480px;height:650px;border:1px solid #4f606b" gesture="media" allow="encrypted-media"></iframe>');
  348. $('#iframeContainer').slideDown();
  349. }
  350. }
  351. }
  352.  
  353. function getParameterByName(name, url) {
  354. if (!url) url = window.location.href;
  355. name = name.replace(/[\[\]]/g, "\\$&");
  356. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  357. results = regex.exec(url);
  358. if (!results) return null;
  359. if (!results[2]) return '';
  360. return decodeURIComponent(results[2].replace(/\+/g, " "));
  361. }
  362.  
  363. // GOOGLE ADDRESS AUTOCOMPLETE AND GETTING CURRENT LOCATION
  364. function initAutocomplete() {
  365. // Create the autocomplete object, restricting the search to geographical
  366. // location types.
  367. autocomplete = new google.maps.places.Autocomplete(
  368. /** @type {!HTMLInputElement} */
  369. (document.getElementById('autocomplete')),
  370. {
  371. types: ['geocode'],
  372. componentRestrictions: {country: 'nz'}
  373. }
  374. );
  375.  
  376. // When the user selects an address from the dropdown, populate the address
  377. // fields in the form.
  378. autocomplete.addListener('place_changed', updateLocation);
  379.  
  380.  
  381. // PW edits: Check for iOS device and stop propagation to ensure autocomplete works
  382. if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) {
  383. setTimeout(function() {
  384. var container = document.getElementsByClassName('pac-container')[0];
  385. container.addEventListener('touchend', function(e) {
  386. e.stopImmediatePropagation();
  387. });
  388. }, 500);
  389. }
  390. }
  391.  
  392. function submitForm(){
  393. $('.location-search-btn').on('click', function(e){
  394. e.preventDefault();
  395. if($('#autocomplete').val()){
  396. var place = $('#autocomplete').val();
  397. updateLocation(place);
  398. }else{
  399. alert('Please make sure you have typed in your location');
  400. return false;
  401. }
  402. });
  403. }
  404.  
  405. function updateLocation(input) {
  406. // Get the place details from the autocomplete object.
  407. var val = '';
  408. if(!input){
  409. var place = autocomplete.getPlace();
  410. }else{
  411. var place = {name: input};
  412. if(input.toLowerCase() == 'new zealand'){
  413. val = input.toLowerCase();
  414. }
  415. }
  416.  
  417. var pos;
  418. $('.ajax-loader').show();
  419. // Get each component of the address from the place details
  420. // and fill the corresponding field on the form.
  421. if(place.address_components && place.address_components.length){
  422. pos = {
  423. lat: place.geometry.location.lat(),
  424. lng: place.geometry.location.lng()
  425. };
  426. $('.search-location').text(place.vicinity);
  427. getLocationList(pos);
  428. }else{
  429. var geocoder = new google.maps.Geocoder();
  430. geocoder.geocode(
  431. {
  432. 'address': place.name,
  433. componentRestrictions: {
  434. country: 'NZ'
  435. }
  436. }
  437. , function(results, status) {
  438. if (status == google.maps.GeocoderStatus.OK) {
  439. pos = {
  440. lat: results[0].geometry.location.lat(),
  441. lng: results[0].geometry.location.lng()
  442. };
  443. $('.search-location').text(place.name);
  444. getLocationList(pos, val);
  445. } else {
  446. $('.ajax-loader').hide();
  447. $('.map-results').slideUp();
  448. $('.no-results').show();
  449. }
  450. }
  451. );
  452. }
  453. }
  454.  
  455. // Bias the autocomplete object to the user's geographical location,
  456. // as supplied by the browser's 'navigator.geolocation' object.
  457. function geolocate() {
  458. if (navigator.geolocation) {
  459. navigator.geolocation.getCurrentPosition(function(position) {
  460. var geolocation = {
  461. lat: position.coords.latitude,
  462. lng: position.coords.longitude
  463. };
  464. var circle = new google.maps.Circle({
  465. center: geolocation,
  466. radius: position.coords.accuracy
  467. });
  468. autocomplete.setBounds(circle.getBounds());
  469. });
  470. }
  471. }
  472. //Get the current location of the user
  473. function getCurrentLocation(){
  474. //Loading Icon here.
  475. $('.ajax-loader').show();
  476.  
  477. // Try HTML5 geolocation.
  478. if (navigator.geolocation) {
  479. navigator.geolocation.getCurrentPosition(function(position) {
  480. var pos = {
  481. lat: position.coords.latitude,
  482. lng: position.coords.longitude
  483. };
  484. geocodeLatLng(position.coords.latitude, position.coords.longitude);
  485. getLocationList(pos);
  486. }, function(error){
  487. $('.ajax-loader').hide();
  488. $('.location-container .current-location, .location-container span').css("display","none");
  489. console.log(error);
  490. });
  491. }
  492. }
  493.  
  494. function getAllStores(){
  495. $('.all-stores').on('click', function(e){
  496. e.preventDefault();
  497. $('#autocomplete').val('New Zealand');
  498. $('.location-search-btn').click();
  499. })
  500. }
  501.  
  502. //Get the suburb from the lat lon
  503. function geocodeLatLng(lat, lon) {
  504. var geocoder = new google.maps.Geocoder();
  505. var latlng = {lat: parseFloat(lat), lng: parseFloat(lon)};
  506. geocoder.geocode({'location': latlng}, function(results, status) {
  507. if (status === 'OK') {
  508. if (results[0]) {
  509. $('.search-location').text(results[0].formatted_address);
  510. } else {
  511. window.alert('No results found');
  512. }
  513. } else {
  514. }
  515. });
  516. }
  517.  
  518. function bookAppointment(){
  519. $('.book-appointment').on('click', function(e){
  520. e.preventDefault();
  521. var appointment_id = $(this).data('appointment_id');
  522. openLocationIframe(appointment_id);
  523. });
  524. }
  525.  
  526. function openLocationIframe(appointment_id){
  527. $('.ajax-loader').show();
  528. currentURL = window.location.href;
  529. var url = window.location.href.split('?')[0] + '?appointment_id=' + appointment_id;
  530. history.pushState(null, null, url);
  531. var gobj = window[window.GoogleAnalyticsObject];
  532. var tracker = gobj.getAll()[0];
  533. var appointmentUrl = 'https://baileynelsoneyewear.gettimely.com/book/embed?location=' + appointment_id;
  534. if (tracker === undefined) {
  535. var decoratedUrl = appointmentUrl;
  536. } else {
  537. var linker = new window.gaplugins.Linker(tracker);
  538. var decoratedUrl = linker.decorate(appointmentUrl);
  539. }
  540. if (screen.width <= 800) {
  541. window.location = decoratedUrl;
  542. } else {
  543. $('.map-results').slideUp(function(){
  544. $('#iframeContainer').find('#iframe').html('<iframe src="'+decoratedUrl+'" width="100%" height="800" name="open-appointments-widget-'+appointment_id+'" frameborder="0" style="border: 2px solid #045475"></iframe>');
  545. $('#iframeContainer').slideDown();
  546. $('html,body').animate({ scrollTop: $('#iframeContainer').position().top - 150 });
  547. });
  548. $('.ajax-loader').hide();
  549. }
  550. }
  551.  
  552. function showNearbyStores(){
  553. $('.nearby-stores').on('click', function(e){
  554. e.preventDefault();
  555. $('.ajax-loader').show();
  556. $('#iframeContainer').slideUp(function(){
  557. if(currentURL){
  558. history.pushState(null, null, currentURL);
  559. $('#iframeContainer').find('#iframe').html('');
  560. $('.map-results').slideDown();
  561. $('html,body').animate({ scrollTop: $('.map-results').position().top - 150 });
  562. }else{
  563. $('#autocomplete').focus();
  564. }
  565. $('.ajax-loader').hide();
  566. });
  567. });
  568. }
  569.  
  570. function newSearch(){
  571. $('.new-search').on('click', function(e){
  572. e.preventDefault();
  573. $('.map-results').slideUp();
  574. $('#autocomplete').val('').focus();
  575. var url = window.location.href.split('?')[0];
  576. history.pushState(null, null, url);
  577. });
  578. }
  579.  
  580. ///// STORE LISTING MAP MARKER ICON
  581. function storeMarker(stores){
  582. if ($('.store-results').find('.store').length) {
  583. var markers = window.gMaps[0].bnMarkers;
  584. var navigationListItems = $('.store-results .store');
  585. var storeIndexX = 0;
  586. var storeIndexY = 0;
  587. var ind = 0;
  588. while (ind < markers.length) {
  589. var marker = markers[ind];
  590. var spriteOffsetX = (storeIndexX * 39);
  591. var spriteOffsetY = (storeIndexY * 48);
  592. if (storeIndexX === 9) {
  593. storeIndexX = 0;
  594. storeIndexY++;
  595. } else {
  596. storeIndexX++;
  597. }
  598. var markerSpriteImageUrl = '{{ 'pins1-100.png' | asset_url }}';
  599. var markerImage = new google.maps.MarkerImage(markerSpriteImageUrl, new google.maps.Size(39, 42), new google.maps.Point(spriteOffsetX, spriteOffsetY), new google.maps.Point(18, 32));
  600. marker.setOptions({
  601. icon: markerImage
  602. });
  603. var img = $('<div class="navigation-map-marker" />');
  604. img.css('width', 32);
  605. img.css('height', 34);
  606. img.css('background-image', 'url("' + markerSpriteImageUrl + '")');
  607. img.css('background-position', '-' + spriteOffsetX + 'px -' + spriteOffsetY + 'px');
  608. $(navigationListItems[ind]).prepend(img);
  609. /*$(navigationListItems[ind]).mouseenter(function() {
  610. var obj = $('.navigation-map-marker', this);
  611. updatePosition(obj, 390);
  612. });
  613. $(navigationListItems[ind]).mouseleave(function() {
  614. var obj = $('.navigation-map-marker', this);
  615. updatePosition(obj, -390);
  616. });*/
  617. ind++;
  618. }
  619. }
  620. }
  621.  
  622. function updatePosition(obj, change) {
  623. var pos = obj.css("background-position");
  624. if (pos === 'undefined' || pos === null) {
  625. pos = [obj.css("background-position-x"), obj.css("background-position-y")];
  626. } else {
  627. pos = pos.split(" ");
  628. }
  629. var x = parseFloat(pos[0]);
  630. pos[0] = pos[0].replace(x, x + change);
  631. obj.css("background-position", pos.join(' '));
  632. }
  633.  
  634. /* Thanks to CSS Tricks for pointing out this bit of jQuery
  635. https://css-tricks.com/equal-height-blocks-in-rows/
  636. It's been modified into a function called at page load and then each time the page is resized. One large modification was to remove the set height before each new calculation. */
  637.  
  638. equalheight = function(container){
  639.  
  640. var currentTallest = 0,
  641. currentRowStart = 0,
  642. rowDivs = new Array(),
  643. $el,
  644. topPosition = 0;
  645. $(container).each(function() {
  646.  
  647. $el = $(this);
  648. $($el).height('auto')
  649. topPostion = $el.position().top;
  650.  
  651. if (currentRowStart != topPostion) {
  652. for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
  653. rowDivs[currentDiv].height(currentTallest);
  654. }
  655. rowDivs.length = 0; // empty the array
  656. currentRowStart = topPostion;
  657. currentTallest = $el.height();
  658. rowDivs.push($el);
  659. } else {
  660. rowDivs.push($el);
  661. currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
  662. }
  663. for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
  664. rowDivs[currentDiv].height(currentTallest);
  665. }
  666. });
  667. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement