PageSourceSearch

https://www.gerritys.com/wp-content/plugins/shoptocook-weeklyad/js/locator.js?ver=1786964661

js gerritys.com collected 2026-10-07 23:22:55 UTC 13,053 bytes, 278 lines download raw bytes

1var S = {
2    mapManager: {
3        icon: null,
4        defaultLat: null,
5        defaultLon: null,
6        defaultZoom: 8,
7        searchZoom: 13,
8        localSearchDistance: 50,
9        geocoder: null,
10        infoWindow: null,
11        locations: {},
12        map: null,
13        markers: {},
14        selected: null,
15        initialize: function (id, locations) {
16            S.mapManager.locations = locations;
17            S.mapManager.map = new google.maps.Map(document.getElementById(id), {
18                gridSize: 25,
19                zoom: S.mapManager.defaultZoom,
20                maxZoom: 18,
21                streetViewControl: false,
22                center: new google.maps.LatLng(S.mapManager.defaultLat, S.mapManager.defaultLon)
23            });
24            S.mapManager.geocoder = new google.maps.Geocoder();
25            S.mapManager.infoWindow = new google.maps.InfoWindow();
26            S.mapManager.infoWindow.setOptions({pixelOffset: new google.maps.Size(0, -40)});
27            google.maps.event.addListener(S.mapManager.infoWindow, 'closeclick', S.mapManager.resetMap);
28            S.mapManager.addMarkers();
29            S.mapManager.showMarkers();
30            jQuery('.locator-store-item').click(function (e) {
31                if (e.originalEvent !== null && e.originalEvent.originalTarget !== null) {
32                    if (!jQuery(e.originalEvent.originalTarget).is('a')) {
33                        S.mapManager.selectItem(jQuery(this).data('store'));
34                    }
35                }
36            });
37
38            jQuery('#store-locator-search').on('submit', S.mapManager.searchFormSumbit);
39            jQuery('.select-store').click(S.mapManager.changeStore);
40            if (S.mapManager.selected !== null) {
41                S.mapManager.searchMap(S.mapManager.selected);
42            }
43            google.maps.event.addListener(S.mapManager.map, 'tilesloaded', function (evt) {
44                jQuery(".gm-style").find("img").each(function (i, img) {
45                    var $img = jQuery(img);
46                    var attr = $img.attr('alt');
47
48                    if (typeof attr !== typeof undefined && attr !== false) {
49                        return;
50                    }
51                    $img.attr("alt", "");
52                });
53            });
54        },
55        addMarkers: function () {
56            jQuery.each(S.mapManager.locations, function (index, location) {
57                S.mapManager.markers[location['storeID']] = new google.maps.Marker({
58                    position: new google.maps.LatLng(location['latitude'], location['longitude'])
59                });
60            });
61        },
62        calculateDistance(lat1, lng1, lat2, lng2) {
63            var dLat = S.mapManager.rad(lat2 - lat1);
64            var gLng = S.mapManager.rad(lng2 - lng1);
65            var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(S.mapManager.rad(lat1)) * Math.cos(S.mapManager.rad(lat2)) *
66                    Math.sin(gLng / 2) * Math.sin(gLng / 2);
67            return (3958.8 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
68        },
69        calculateStoreDistances: function (lat, lng) {
70            jQuery.each(S.mapManager.markers, function (index, marker) {
71                var mlat = marker.position.lat();
72                var mlng = marker.position.lng();
73                var distance = S.mapManager.calculateDistance(lat, lng, mlat, mlng);
74                var $storeItem = jQuery('#store-item-' + index);
75                $storeItem.data('distance', distance);
76                $storeItem.find('.store-distance').text(distance.toFixed(2) + ' mi');
77            });
78
79            jQuery("#locator-store-list > li").sort(S.mapManager.sortStore).appendTo('#locator-store-list');
80        },
81        centerOnLocation: function (latLang) {
82            S.mapManager.map.setZoom(S.mapManager.searchZoom);
83            S.mapManager.map.setCenter(latLang);
84            S.mapManager.calculateStoreDistances(latLang.lat(), latLang.lng());
85        },
86        sortStore: function (a, b) {
87            return (jQuery(b).data('distance')) < (jQuery(a).data('distance')) ? 1 : -1;
88        },
89        changeStore: function () {
90            var store = S.mapManager.lookupStore('storeID', jQuery(this).closest('li').data('store'));
91            jQuery.ajax({
92                url: MyAjax.ajaxurl,
93                type: 'post',
94                dataType: 'json',
95                data: {
96                    action: 'stc_change_store',
97                    circularstoreidentifier: store.storeIdentifier,
98                    zipCode: store.zipCode
99                },
100                success: function (response) {
101                    if (response.status === "OK") {
102                        var $info = jQuery('.selected-store-info');
103                        var $directions = jQuery('.selected-store-directions');
104                        if ($info.length === 0) {
105                            $info = jQuery('<span class="selected-store-info"></span>');
106                            $directions = jQuery('<a class="selected-store-directions" target="_blank">Directions</a>');
107                            var $links = jQuery('<span class="selected-store-link"></span>');
108                            $links.append(' - <a href="/weekly-ad/">Specials</a> | ', $directions, ' | <a href="/locations/">Not your location?</a></span>');
109                            jQuery('.selected-store').empty().append("My Store:&nbsp;&nbsp;", $info, $links);
110                        }
111                        $info.html(store.address1);
112                        var url = "https://maps.google.com/maps?f=d&daddr=" + encodeURIComponent(store.name + ", " + store.address1 + " " + store.city + ", " + store.state + " " + store.zipCode);
113                        $directions.attr("href", url);
114                    }
115                },
116                error: function (jqXHR, textStatus, errorThrown) {
117                    alert('Error: Could not select store. Please try again later.');
118                }
119            });
120        },
121        findMarkerId: function (marker) {
122            for (var key in S.mapManager.markers) {
123                if (marker === S.mapManager.markers[key]) {
124                    return key;
125                }
126            }
127            return null;
128        },
129        formatPhone: function (str) {
130            return str.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
131        },
132        geocodeRequest: function (search) {
133            S.mapManager.geocoder.geocode({'address': search}, function (results, status) {
134                if (status === 'OK') {
135                    var latLang = results[0].geometry.location;
136                    S.mapManager.centerOnLocation(latLang);
137                } else {
138                    //alert('Geocode was not successful for the following reason: ' + status);
139                }
140            });
141        },
142        localGeoRequest: function (search) {
143            if (search === "") {
144                return;
145            }
146
147            for (var key in S.mapManager.locations) {
148                if (search.toUpperCase() === S.mapManager.locations[key]['city'].toUpperCase()) {
149                    latLng = new google.maps.LatLng(S.mapManager.locations[key].latitude, S.mapManager.locations[key].longitude);
150                    S.mapManager.centerOnLocation(latLng);
151                    //S.mapManager.selectItem(S.mapManager.locations[key].storeID);
152                    return;
153                }
154            }
155
156            jQuery.ajax({
157                url: MyAjax.ajaxurl,
158                type: 'post',
159                dataType: 'json',
160                data: {
161                    action: 'stc_georequest',
162                    q: search
163                },
164                success: function (rsp) {
165                    if (rsp.response.status === 200) {
166                        var latLng = new google.maps.LatLng(rsp.data[0].lat, rsp.data[0].lng);
167
168                        if (rsp.data.length > 1) {
169                            var closestLatLng = rsp.data[0];
170                            var closestDistance = S.mapManager.calculateDistance(closestLatLng.lat, closestLatLng.lng, S.mapManager.defaultLat, S.mapManager.defaultLon);
171
172                            for (var i = 0; i < rsp.data.length; ++i) {
173                                var distance = S.mapManager.calculateDistance(rsp.data[i].lat, rsp.data[i].lng, S.mapManager.defaultLat, S.mapManager.defaultLon);
174                                if (distance < closestDistance) {
175                                    closestDistance = distance;
176                                    closestLatLng = rsp.data[i];
177                                }
178                            }
179                            latLng = new google.maps.LatLng(closestLatLng.lat, closestLatLng.lng);
180
181                            if (closestDistance > S.mapManager.localSearchDistance) {
182                                S.mapManager.geocodeRequest(search);
183                                return;
184                            }
185                        }
186                        S.mapManager.centerOnLocation(latLng);
187                    } else {
188                        S.mapManager.geocodeRequest(search);
189                    }
190                },
191                error: function (jqXHR, textStatus, errorThrown) {
192
193                }
194            });
195        },
196        isMapVisible: function () {
197            if (jQuery(window).width() > 1070) {
198                return true;
199            } else {
200                return false;
201            }
202        },
203        lookupStore: function (property, value) {
204            for (var key in S.mapManager.locations) {
205                if (value == S.mapManager.locations[key][property]) {
206                    return S.mapManager.locations[key];
207                }
208            }
209            return null;
210        },
211        markerClick: function () {
212            S.mapManager.selectItem(S.mapManager.findMarkerId(this));
213        },
214        rad: function (x) {
215            return x * Math.PI / 180;
216        },
217        resetMap: function () {
218            jQuery('.locator-store-selected').removeClass('locator-store-selected');
219            S.mapManager.map.setZoom(S.mapManager.defaultZoom);
220            S.mapManager.map.setCenter(new google.maps.LatLng(S.mapManager.defaultLat, S.mapManager.defaultLon));
221        },
222        selectMarker: function (id) {
223            var position = S.mapManager.markers[id].getPosition();
224            var store = S.mapManager.lookupStore('storeID', id);
225            S.mapManager.map.setCenter(position);
226            S.mapManager.map.setZoom(S.mapManager.searchZoom);
227            var content = '<strong>' + store.name + '</strong><br/><br/>';
228            content += store.address1 + '<br/>' + store.city + ', ' + store.state + ' ' + store.zipCode;
229            content += (store.phone === undefined) ? '' : '<br/>Phone: ' + S.mapManager.formatPhone(store.phone);
230            content += (store.hourInfo === undefined) ? '' : '<br/>Hours: ' + store.hourInfo;
231            S.mapManager.infoWindow.setContent(content);
232            S.mapManager.infoWindow.setPosition(position);
233            S.mapManager.infoWindow.open(S.mapManager.map);
234        },
235        selectItem: function (id) {
236            jQuery('.locator-store-selected').removeClass('locator-store-selected');
237            $selected = jQuery('#store-item-' + id);
238            $selected.addClass('locator-store-selected');
239            if (S.mapManager.isMapVisible() === true) {
240                jQuery('#locator-store-list').scrollTop(jQuery('#locator-store-list').scrollTop() + $selected.position().top);
241            } else {
242                //jQuery(window).scrollTop($selected.position().top);
243            }
244            S.mapManager.selectMarker(id);
245        },
246        searchFormSumbit: function (e) {
247            e.preventDefault();
248            jQuery('.locator-store-selected').removeClass('locator-store-selected');
249            S.mapManager.searchMap(jQuery('#locator_search').val());
250        },
251        searchMap: function (search) {
252            if (search === '') {
253                return;
254            }
255            /*else if (/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(search)) {
256             var store = S.mapManager.lookupStore('zipCode', jQuery('#locator_search').val());
257             if (store !== null) {
258             S.mapManager.selectItem(store['storeID']);
259             return;
260             }
261             }*/
262            S.mapManager.infoWindow.close();
263            S.mapManager.localGeoRequest(jQuery('#locator_search').val());
264            jQuery('#locator-store-list').scrollTop(0);
265        },
266        showMarkers: function ()
267        {
268            jQuery.each(S.mapManager.markers, function (index, marker) {
269                if (S.mapManager.icon !== null) {
270                    marker.setIcon(S.mapManager.icon);
271                }
272                marker.setMap(S.mapManager.map);
273                marker.setClickable(true);
274                google.maps.event.addListener(marker, "click", S.mapManager.markerClick);
275            });
276        }
277    }
278};

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.