PageSourceSearch

https://www.royaldoulton.com.au/skin/wwrd_custom_skin/modules/CSI_Store_Locator/store_locator.js

js royaldoulton.com.au collected 2026-10-04 21:23:17 UTC 9,729 bytes, 336 lines download raw bytes

1/**
2 * Store Locator Module
3 *
4 * @category  X-Cart Classic Module
5 * @author    CFL Systems, Inc. <[email protected]>
6 * @copyright Copyright (c) 2015 CFL Systems, Inc. All rights reserved.
7 * @license   CFL Systems Software License Agreement - https://www.cflsystems.com/software-license-agreement.html
8 * @link      https://www.cflsystems.com/store-locator-for-x-cart-classic.html
9 * Updated: 2016-11-21
10 */
11
12var maps_loaded = false; // flag if Google Maps API is already loaded
13var first_time = true; // added for initial map load
14var geocoder;
15var map;
16var directionsDisplay;
17var directionsService;
18var start_location;
19var bounds;
20var infoWindow;
21var address = 'AU';
22var searchCountry = 'AU';
23var radius = 500;
24
25var api_key = '';
26if (store_locator_api_key !== undefined && store_locator_api_key != '')
27  api_key = 'key=' + store_locator_api_key + '&';
28
29$(document).ready(function(){
30  $("#sl-submit").click(function(e){
31		e.preventDefault();
32    stepOne();
33  });
34  $("#sl-address").keyup(function(){
35    if (event.keyCode == 13) {
36      stepOne();
37    }
38  });
39});
40
41$(document).ready(first_time_page_load);
42
43function first_time_page_load() {
44	// load Google Maps API
45	if(!maps_loaded) {
46		var script = document.createElement('script');
47		script.src = 'https://maps.google.com/maps/api/js?' + encodeURI(api_key) + 'callback=initalize';
48		document.body.appendChild(script);
49	}
50}
51
52function first_time_page_load_map() {
53  geocoder.geocode({'address': 'AU'}, function (results, status) {
54    var latitude = results[0].geometry.location.lat();
55    var longitude = results[0].geometry.location.lng();
56    var myOptions = {
57      center: new google.maps.LatLng(latitude, longitude),
58      mapTypeId: google.maps.MapTypeId.ROADMAP,
59      zoom: 13
60    };
61  	var sl_map = document.getElementById('sl-map');
62
63    sl_map.className = 'map-box';
64    map = new google.maps.Map(sl_map, myOptions);
65
66		map.fitBounds(results[0].geometry.viewport);
67
68  });
69}
70
71function doNothing() {}
72
73function start(e){
74	if(!e) var e = window.event;
75	var target = e.target || e.srcElement;
76
77	switch(target.id){
78		case "sl-submit":
79			e.preventDefault ? e.preventDefault() : e.returnValue = false;
80			stepOne();
81			break;
82	}
83}
84
85function initalize(){
86	geocoder = new google.maps.Geocoder();
87	maps_loaded = true;
88
89  if (!first_time) {
90    stepTwo();
91  } else {
92    first_time = false;
93    first_time_page_load_map();
94  }
95}
96
97function stepOne(){
98	// radius = document.getElementById('sl-radius').value;
99	radius = 500;
100	address = document.getElementById('sl-address').value;
101
102	if(!address) {
103		// alert('Please enter an address');
104		// return false;
105  	address = 'Australia';
106	}
107
108	if(!radius) {
109		radius = 50;
110	}
111
112	// load Google Maps API
113	if(!maps_loaded) {
114		var script = document.createElement('script');
115		script.src = 'https://maps.google.com.au/maps/api/js?' + encodeURI(api_key) + 'callback=initalize';
116		document.body.appendChild(script);
117	}
118	else {
119		stepTwo();
120	}
121}
122
123function stepTwo(){
124  var test = new RegExp('(nz|new zealand)','i');
125  if (test.test(address)) {
126    searchCountry = 'NZ';
127  }
128
129	geocoder.geocode({
130		address: address,
131    componentRestrictions: {country: searchCountry}
132		},
133		function(results, status){
134			if(status == google.maps.GeocoderStatus.OK) {
135				bounds = new google.maps.LatLngBounds();
136				var latitude = results[0].geometry.location.lat();
137				var longitude = results[0].geometry.location.lng();
138
139				start_location = results[0].geometry.location;
140
141				directionsService = new google.maps.DirectionsService();
142				directionsDisplay = new google.maps.DirectionsRenderer();
143
144				var sl_map = document.getElementById('sl-map');
145				sl_map.className = 'map-box';
146
147				map = new google.maps.Map(sl_map, {
148					center: new google.maps.LatLng(latitude, longitude),
149					zoom: 13,
150					mapTypeId: 'roadmap'
151				});
152
153				infoWindow = new google.maps.InfoWindow;
154
155				stepThree('store_locator.php?lat=' + latitude + '&lng=' + longitude + '&radius=' + radius + '&address=' + address, function(data){
156
157					var xml = data.responseXML;
158					var markers = xml.documentElement.getElementsByTagName('store');
159
160					var sl_locations = document.getElementById('sl-locations');
161					sl_locations.innerHTML = '';
162					sl_locations.className = 'loc-box row';
163
164					document.getElementById("sl-wrapper").style.backgroundImage = "none";
165
166					if (markers.length == 0) {
167						sl_locations.innerHTML = 'No results found.';
168						return;
169					}
170
171					if (markers.length == 1) {
172						var win = new google.maps.LatLng(
173							parseFloat(markers[0].getAttribute('latitude')),
174							parseFloat(markers[0].getAttribute('longitude'))
175						);
176
177						map.setCenter(win);
178					}
179
180					for (var i = 0; i < markers.length; i++) {
181						var name = markers[i].getAttribute('name');
182						var city = markers[i].getAttribute('city');
183						var state = markers[i].getAttribute('state');
184						var zipcode = markers[i].getAttribute('zipcode');
185						var country = markers[i].getAttribute('country');
186						var phone = markers[i].getAttribute('phone');
187						var fax = markers[i].getAttribute('fax');
188						var weburl = markers[i].getAttribute('url');
189						var descr = markers[i].getAttribute('descr');
190						var address = markers[i].getAttribute('address') + ', ' + city + ', ' + state 
190+ ' ' + zipcode;
191						var address_2 = markers[i].getAttribute('address_2');
192						var point = new google.maps.LatLng(
193							parseFloat(markers[i].getAttribute('latitude')),
194							parseFloat(markers[i].getAttribute('longitude'))
195						);
196						var distance = parseFloat(markers[i].getAttribute('distance'));
197						var units = markers[i].getAttribute('units');
198
199						if (descr != '')
200							descr = '<br /><br />' + descr;
201
202						if (address_2 != '')
203							address_2 = '<br />' + address_2;
204
205						if (weburl != '')
206							weburl = '<br />Website: <a href="http://' + weburl + '" target="_blank">' + weburl + '</a>';
207
208						var html = '';
209						html = '<b>' + name + '</b><br />' + markers[i].getAttribute('address') + address_2 + '<br />' + city + ', ' + state + ' ' + zipcode + '<br /><a href="tel:' + phone + '"><i class="fa fa-phone-square">&nbsp;</i>' + phone + '</a>' + weburl + descr;
210						html = html + '<hr class="infowin-hr" />';
211            html = html + '<em>Please call the store to check stock availability.</em><br />';
212						html = html + '<a class="infowin-a" href="javascript: calcRoute(\'' + parseFloat(markers[i].getAttribute('latitude')) + ',' + parseFloat(markers[i].getAttribute('longitude')) + '\');">Directions to this location</a>';
213
214						var icon = customIcons || {};
215
216						bounds.extend(point);
217
218						if (markers.length > 1) {
219							map.fitBounds(bounds);
220						}
221
222						var marker = new google.maps.Marker({
223							map: map,
224							position: point,
225							icon: icon.icon,
226							shadow: icon.shadow,
227							id: i
228						});
229
230						bindInfoWindow(marker, map, infoWindow, html, true);
231
232						var address1 = markers[i].getAttribute('address') + address_2 + '<br />' + city + ', ' + state + ' ' + zipcode + '<br /><a href="tel:' + phone + '"><i class="fa fa-phone-square">&nbsp;</i>' + phone + '</a>' + weburl;
233
234						var sl_location = createLocation(marker, name, address1, distance, units);
235						sl_locations.appendChild(sl_location);
236
237					}
238				});
239
240				clearRoute();
241
242			}
243			else {
244				alert('geocoding error');
245				return false;
246			}
247		}
248	);
249}
250
251function stepThree(url, callback) {
252	var request = window.ActiveXObject ?
253
254	new ActiveXObject('Microsoft.XMLHTTP') :
255	new XMLHttpRequest;
256
257	request.onreadystatechange = function() {
258		if (request.readyState == 4) {
259			request.onreadystatechange = doNothing;
260			callback(request, request.status);
261		}
262	};
263
264	request.open('GET', url, true);
265	request.send(null);
266}
267
268var customIcons = {
269	icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
270	shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
271};
272
273function bindInfoWindow(marker, map, infoWindow, html, flag) {
274	google.maps.event.addListener(marker, 'click', function() {
275		if (flag)
276      clearRoute();
277
278		infoWindow.setContent(html);
279    infoWindow.open(map, marker);
280	});
281}
282
283function createLocation(marker, name, address, distance, units) {
284	var div = document.createElement('div');
285	var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ' ' + units +')<br/>' + address;
286
287	div.innerHTML = html;
288	div.style.cursor = 'pointer';
289	div.style.marginBottom = '5px';
290	div.style.paddingLeft = '7px';
291	div.style.paddingRight = '7px';
292	div.style.paddingTop = '7px';
293	div.style.paddingBottom = '7px';
294	div.className = 'col-xs-12 col-sm-6 col-md-12';
295	google.maps.event.addDomListener(div, 'click', function() {
296		google.maps.event.trigger(marker, 'click');
297	});
298	google.maps.event.addDomListener(div, 'mouseover', function() {
299		div.style.backgroundColor = '#eee';
300	});
301	google.maps.event.addDomListener(div, 'mouseout', function() {
302		div.style.backgroundColor = '#fff';
303	});
304
305	return div;
306}
307
308function calcRoute(end_location) {
309	document.getElementById("sl-directions").innerHTML = '';
310	document.getElementById("sl-clear-directions").style.display = '';
311
312	infoWindow.close();
313
314	directionsDisplay.setMap(map);
315	directionsDisplay.setPanel(document.getElementById("sl-directions"));
316
317	var request = {
318		origin: start_location,
319		destination: end_location,
320		travelMode: google.maps.TravelMode.DRIVING,
321    region: searchCountry
322	};
323
324	directionsService.route(request, function(response, status) {
325		if (status == google.maps.DirectionsStatus.OK) {
326			directionsDisplay.setDirections(response);
327		}
328	});
329}
330
331function clearRoute() {
332	document.getElementById("sl-directions").innerHTML = '';
333	document.getElementById("sl-clear-directions").style.display = 'none';
334	directionsDisplay.setMap();
335	directionsDisplay.setPanel();
336}

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.