PageSourceSearch

https://simple-life.com/wp-content/plugins/facetwp-map-facet/assets/js/front.js?ver=1.2

js simple-life.com collected 2026-10-07 05:48:25 UTC 7,307 bytes, 217 lines download raw bytes

1var FWP_MAP = FWP_MAP || {};
2
3(function($) {
4
5    FWP_MAP.markersArray = [];
6    FWP_MAP.markerLookup = {};
7    FWP_MAP.is_filtering = false;
8    FWP_MAP.is_zooming = false;
9    FWP_MAP.map_loaded = false;
10
11    // Get markers for a given post ID
12    FWP_MAP.get_post_markers = function(post_id) {
13        var output = [];
14        if ('undefined' !== typeof FWP_MAP.markerLookup[post_id]) {
15            var arrayOfIndexes = FWP_MAP.markerLookup[post_id];
16            for (var i = 0; i < arrayOfIndexes.length; i++) {
17                var index = FWP_MAP.markerLookup[post_id][i];
18                output.push(FWP_MAP.markersArray[index]);
19            }
20        }
21        return output;
22    }
23
24    FWP.hooks.addAction('facetwp/refresh/map', function($this, facet_name) {
25        var selected_values = [];
26
27        if (FWP_MAP.is_filtering) {
28            selected_values = FWP_MAP.map.getBounds().toUrlValue().split(',');
29        }
30
31        FWP.facets[facet_name] = selected_values;
32        FWP.frozen_facets[facet_name] = 'hard';
33    });
34
35    FWP.hooks.addAction('facetwp/reset', function() {
36        $.each(FWP.facet_type, function(type, name) {
37            if ('map' === type) {
38                FWP.frozen_facets[name] = 'hard';
39            }
40        });
41    });
42
43    FWP.hooks.addFilter('facetwp/selections/map', function(label, params) {
44        return FWP_JSON['map']['resetText'];
45    });
46
47    function do_refresh() {
48        if (FWP_MAP.is_filtering && ! FWP_MAP.is_zooming) {
49            FWP.autoload();
50        }
51
52        FWP_MAP.is_zooming = false;
53    }
54
55    $().on('click', '.facetwp-map-filtering', function() {
56        var $this = $(this);
57
58        if ($this.hasClass('enabled')) {
59            $this.text(FWP_JSON['map']['filterText']);
60            FWP_MAP.is_filtering = false;
61            FWP.autoload();
62        }
63        else {
64            $this.text(FWP_JSON['map']['resetText']);
65            FWP_MAP.is_filtering = true;
66            FWP.autoload();
67        }
68
69        $this.toggleClass('enabled');
70    });
71
72    FWP_MAP.init = function() {
73        if ('undefined' === typeof FWP.settings.map || '' === FWP.settings.map) {
74            return;
75        }
76
77        if ('object' !== typeof google || 'object' !== typeof google.maps) {
78            return;
79        }
80
81        var config = FWP.settings.map.config;
82
83        if (! FWP_MAP.map_loaded) {
84
85            FWP_MAP.map = new google.maps.Map(document.getElementById('facetwp-map'), FWP.settings.map.init);
86            FWP_MAP.infoWindow = new google.maps.InfoWindow();
87
88            FWP_MAP.map.addListener('dragend', function() {
89                do_refresh();
90            });
91
92            FWP_MAP.map.addListener('zoom_changed', function() {
93                do_refresh();
94            });
95
96            window.addEventListener('resize', FWP.helper.debounce(function() {
97                var center = FWP_MAP.map.getCenter();
98                google.maps.event.trigger(FWP_MAP.map, 'resize');
99                FWP_MAP.map.setCenter(center);
100            }, 500));
101
102            google.maps.event.addListener(FWP_MAP.map, 'click', function() {
103                FWP_MAP.infoWindow.close();
104            });
105
106            FWP_MAP.oms = new OverlappingMarkerSpiderfier(FWP_MAP.map, config.spiderfy);
107            FWP_MAP.map_loaded = true;
108        }
109        else {
110            clearOverlays();
111        }
112
113        // this needs to re-init on each refresh
114        FWP_MAP.bounds = new google.maps.LatLngBounds();
115        FWP_MAP.contentCache = {};
116
117        $.each(FWP.settings.map.locations, function(obj, idx) {
118            var args = Object.assign({}, obj);
119            args.map = FWP_MAP.map;
120
121            var marker = new google.maps.Marker(args);
122
123            google.maps.event.addListener(marker, 'spider_click', function() {
124                if ('undefined' !== typeof marker.content) {
125                    FWP_MAP.infoWindow.setContent(marker.content);
126                }
127                else if ('undefined' === typeof FWP_MAP.contentCache[args.post_id]) {
128                    FWP_MAP.infoWindow.setContent('Loading...');
129                    FWP_MAP.infoWindow.open(FWP_MAP.map, marker);
130
131                    return $.post(FWP_JSON.map.ajaxurl, {
132                        action: 'facetwp_map_marker_content',
133                        facet_name: FWP_JSON.map.facet_name,
134                        post_id: args.post_id
135                    }, {
136                        dataType: 'text',
137                        contentType: 'application/x-www-form-urlencoded',
138                        done: (resp) => {
139                            FWP_MAP.contentCache[args.post_id] = resp;
140                            FWP_MAP.infoWindow.setContent(resp);
141                            FWP.hooks.doAction('facetwp_map/marker/click', marker);
142                        }
143                    });
144                }
145                else {
146                    var data = FWP_MAP.contentCache[args.post_id];
147                    FWP_MAP.infoWindow.setContent(data);
148                }
149
150                FWP_MAP.infoWindow.open(FWP_MAP.map, marker);
151
152                // Custom click handler
153                FWP.hooks.doAction('facetwp_map/marker/click', marker);
154            });
155
156            // Custom mouseover handler
157            google.maps.event.addListener(marker, 'mouseover', function() {
158                FWP.hooks.doAction('facetwp_map/marker/mouseover', marker);
159            });
160
161            // Custom mouseout handler
162            google.maps.event.addListener(marker, 'mouseout', function() {
163                FWP.hooks.doAction('facetwp_map/marker/mouseout', marker);
164            });
165
166            FWP_MAP.oms.addMarker(marker);
167            FWP_MAP.markersArray.push(marker);
168            FWP_MAP.bounds.extend(marker.getPosition());
169
170            // Create an object to lookup markers based on post ID
171            if ( 'undefined' !== typeof FWP_MAP.markerLookup[obj.post_id]) {
172                FWP_MAP.markerLookup[obj.post_id].push(idx);
173            }
174            else {
175                FWP_MAP.markerLookup[obj.post_id] = [idx];
176            }
177        });
178
179        var has_results = FWP.settings.map.locations.length > 0;
180        var fit_bounds = FWP.hooks.applyFilters('facetwp_map/fit_bounds', ! FWP_MAP.is_filtering);
181
182        if (fit_bounds && has_results) {
183            FWP_MAP.map.fitBounds(FWP_MAP.bounds);
184        }
185        else if (! FWP_MAP.is_filtering && (0 !== config.default_lat || 0 !== config.default_lng)) {
186            FWP_MAP.map.setCenter({
187                lat: parseFloat(config.default_lat),
188                lng: parseFloat(config.default_lng)
189            });
190            FWP_MAP.is_zooming = true;
191            FWP_MAP.map.setZoom(config.default_zoom);
192        }
193
194        if ('undefined' !== typeof config.cluster) {
195            FWP_MAP.mc = new MarkerClusterer(FWP_MAP.map, FWP_MAP.markersArray, config.cluster);
196        }
197
198        $().trigger('facetwp-maps-loaded');
199    };
200
201    $().on('facetwp-loaded', function() {
202        FWP_MAP.init();
203    });
204
205    // Clear markers
206    function clearOverlays() {
207        FWP_MAP.oms.removeAllMarkers();
208        FWP_MAP.markersArray = [];
209        FWP_MAP.markerLookup = {};
210
211        // clear clusters
212        if ('undefined' !== typeof FWP_MAP.mc) {
213            FWP_MAP.mc.clearMarkers();
214        }
215    }
216
217})(fUtil);

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.