PageSourceSearch

https://portman.pl/wp-content/themes/asaritemplate2023/assets/js/map-contact.js?ver=1.0.0'%20defer='defer

js portman.pl collected 2026-10-08 23:42:00 UTC 13,606 bytes, 423 lines download raw bytes

1(function ($) {
2    var $window = $(window), $body, mapEngine, debug;
3
4    $(document).ready(function () {
5// =====================================================================================================================
6
7        $body = $('body:first');
8        //mapEngine = 0 | $body.hasClass('map-openstreet');
9        debug = $body.hasClass('debug');
10
11        var gmaps_wait, gmaps_wait_count = 0;
12        gmaps_check_init();
13
14
15
16// ----------------------------------------------------------------------------------
17// Mapy - sprawdzenie
18
19function gmaps_check_init() {
20
21    if (isGmapsLoaded()) {
22
23        gmapsSubpages_init();
24        gmaps_noFont();
25
26    } else if (gmaps_wait_count < 10) { // failover retries
27        gmaps_wait = setTimeout(function() { gmaps_check_init(); }, 250 + (gmaps_wait_count * 250));
28        gmaps_wait_count++;
29
30        if (debug)
31            console.log('[Theme: Google Maps - Subpages/Addons] Google Maps API not loaded yet. Initialization retry #' + gmaps_wait_count + "\n");
32    }
33}
34
35// -------------------------------------------
36// Mapy - start
37
38function gmapsSubpages_init() {
39
40
41
42    // -------------------------------------------
43    // Oferta
44
45    if (debug)
46        console.log('[Theme: Google Maps - Subpages] Started...' + "\n");
47
48    // -------------------------------------------
49    // Kontakt
50
51    var $contactRowMap = $('.theme_map_contact');
52    if (isThere($contactRowMap)) {
53
54        $contactRowMap.each(function() {
55            var $this = $(this),
56                $mapContainer = $this.closest('.theme_map_contact_container'),
57                officeId = $this.data('officeId'),
58                officeIds = $this.data('officeIds'),
59                officeAddress = $this.data('officeAddress'),
60                dataZoom = $this.data('mapZoom'),
61                dataSingleOffice = $this.data('mapSingleoffice');
62            if (!isThere($mapContainer))
63                $mapContainer = $this.parent();
64            /*if (!officeAddress) {
65                $mapContainer.css('display', 'none');
66                return false;
67            }*/
68
69            var elementId = (officeId ? ('theme_map_contact_' + officeId) : $this.attr('id'));
70
71            var objectData = (officeIds ? ('i' + officeIds) : ('a' + officeAddress));
72
73            var zoom = dataZoom || null,
74                singleOffice = dataSingleOffice || null;
75
76            //markerIcon = '/wp-content/themes/asaritemplate6/assets/img/marker.png';
77            google.maps.event.addDomListener(window, 'load', theme_map_contact(elementId, objectData, zoom, singleOffice));
78        });
79
80    }
81
82//}
83
84// ----------------------------------------------------------------------------------
85
86function theme_map_contact(elid, data, zoom, singleOffice) {
87
88    var mapElement = document.getElementById(elid),
89
90        ids = ((data.charAt(0) == 'i') ? data.substr(1) : null),//.split(','),
91        address = ((data.charAt(0) == 'a') ? data.substr(1) : null);
92
93    // Warszawa 52.229836 21.011756
94    // Północ-Centrum (Lipno k. Włocławka) 51.9189046 19.1343786
95    /*var mapLatitude = 52.229836,
96        mapLongitude = 21.011756,*/
97    var mapLatitude = 52.87,
98        mapLongitude = 19.1343786,
99        mapZoom = zoom || 6, // 13
100        mapSingleOffice = singleOffice || false;
101
102    var mapCenter = new google.maps.LatLng(mapLatitude, mapLongitude);
103
104    var mapOptions = {
105        zoom: mapZoom,
106        center: mapCenter,
107        mapTypeId: google.maps.MapTypeId.ROADMAP
108        /*disableDefaultUI: false,
109        scrollwheel: false*/
110    };
111
112    /*if (debug) {
113        console.log('typeof mapStyles = '+(typeof mapStyles)+"\n");
114        console.log('typeof markerIcon = '+(typeof markerIcon)+"\n");
115        console.log("\n");
116    }*/
117
118    if (typeof mapStyles != 'undefined')
119        mapOptions.styles = mapStyles;
120
121    var map = new google.maps.Map(mapElement, mapOptions);
122
123    // ------------
124
125    // interface state
126
127    var inter_showOffers = true,
128        inter_showSelect = false,
129
130        maploaded = false,
131        markersfitted = false;
132
133    // ------------
134
135    var newMarkers = [];
136
137    // ------------
138
139    if (debug)
140        console.log("\n" + '================' + "\n" + 'theme_map_contact(id, str):' + "\n" + '--------' + "\n" + 'id = ' + elid + "\n" + 'str = ' + "\n" + '----------------' + "\n\n");
141
142    if (address != '') {
143
144        var geocoder = new google.maps.Geocoder();
145
146        geocoder.geocode({'address': address}, function(results, status) {
147
148            if (status == google.maps.GeocoderStatus.OK)
149                map.setCenter(results[0].geometry.location);
150
151            if (mapSingleOffice) {
152
153                newMarkers[0] = new google.maps.Marker({
154                    //return new MarkerWithLabel({
155                    map: map,
156                    //position: new google.maps.LatLng(results[0].geometry.location),
157                    position: results[0].geometry.location,
158                    //label: labels[i % labels.length],
159                    title: 'Centrala',
160                    icon: '/wp-content/themes/asaritemplate2023/assets/img/maps/marker-1c.png',
161                    labelAnchor: new google.maps.Point(50, 0),
162                    labelClass: 'marker-style'
163                });
164
165                /*google.maps.event.addListener(newMarker, 'click', () => {
166                    window.location.href = location[3];
167                });*/
168            }
169
170        });
171
172    }
173
174    if (mapSingleOffice)
175        return;
176
177
178            // -----------------------------------
179
180            google.maps.event.addListener(map, 'dragend', function() {
181
182                //if (self.data('ignorebounds') != '1')
183                    loadnewmarkers(map, ids);
184
185                //map_storeCenter();
186            });
187
188            google.maps.event.addListener(map, 'resize', function() {
189
190                //if (self.data('ignorebounds') != '1')
191                    loadnewmarkers(map, ids);
192
193                //map_storeCenter();
194            });
195
196            google.maps.event.addListener(map, 'zoom_changed', function() {
197
198                //if (self.data('ignorebounds') != '1')
199                    loadnewmarkers(map, ids);
200
201                //map_storeCenter();
202            });
203
204
205            google.maps.event.addListener(map, 'idle', function() {
206
207                if (!maploaded) {
208                    loadnewmarkers(map, ids);
209                    maploaded = true;
210                }
211            });
212
213            // =========================================================================================================
214
215        /*} else
216            //alert('Nie można pokazać wybranej lokalizacji na mapie.');
217        if (debug)
218            console.log('\'theme_map_contact()\' -> GeoCoder - błąd: ' + status);
219    });*/
220
221// =====================================================================================================================
222    // Markers - functions
223
224    function loadnewmarkers(map, ids) {
225
226        if (debug)
227            console.log('[Theme] loadnewmarkers() executed...' + "\n");
228
229        //if (!isGmapsLoaded() || (typeof map.getBounds() !== 'object') || !inter_showOffers)
230        if ((typeof map.getBounds() !== 'object') || !inter_showOffers) {
231            newMarkers = [];
232            //markerCluster.clearMarkers();
233            return false;
234        }
235
236        if (maploaded)
237            return true;
238
239        var search = false;
240
241        q = '/?themeajax=offices';
242        if (ids != null)
243            q += ('&ids=' + ids);
244
245        jQuery.getJSON(q, function(locations) {
246
247            search = (locations.length < 15);
248
249            var bounds = new google.maps.LatLngBounds();
250
251            newMarkers = locations.map((location, i) => {
252                var newMarker = new google.maps.Marker({
253                    map: map,
254                    position: new google.maps.LatLng(location[1], location[2]),
255                    //title: 'Biuro',
256                    title: location[4],
257                    icon: '/wp-content/themes/asaritemplate2023/assets/img/maps/marker-2c.png',
258                    labelAnchor: new google.maps.Point(50, 0),
259                    labelClass: 'marker-style'
260                });
261
262                /*if (!i) { // only for the first result
263
264                    map.panTo(new google.maps.LatLng(location[1], location[2]));
265
266                    if (debug)
267                        console.log('map zoom = ' + map.zoom + "\n"
268                            + 'map zoom * 1.8333 = ' + (map.zoom * 1.8333) + "\n"
269                            + 'rounded map zoom * 1.8333 = ' + Math.round(map.zoom * 1.8333) + "\n");
270
271                    //map.setZoom(11);
272                    map.setZoom(Math.round(map.zoom * 1.8333));
273                }*/
274
275                google.maps.event.addListener(newMarker, 'click', () => {
276                    window.location.href = location[3];
277                });
278
279                //bounds.extend(newMarker.getPosition());
280                bounds.extend(newMarker.position);
281
282                return newMarker;
283            });
284
285            map.fitBounds(bounds, (search ? 0 : -48));
286            if (map.getZoom() > 13)
287                map.setZoom(13);
288            map.panBy(0, (search ? -25 : -55));
289
290            //map_fitmarkers();
291        });
292
293    }
294
295    // -----------------------------------
296
297    function markers_fix() {
298
299        map.setZoom(mapZoom);
300    }
301
302    // -----------------------------------
303
304    function map_fitmarkers() {
305
306        if (inter_showOffers) {
307            if ((newMarkers.length > 0) && self.data('markerfit')) {
308                var bounds = new google.maps.LatLngBounds();
309                for (var i = 0; i < newMarkers.length; i++)
310                    bounds.extend(newMarkers[i].getPosition());
311
312                map.fitBounds(bounds);
313            }
314            markersfitted = true;
315        }
316    }
317
318    // -----------------------------------
319
320    function map_storeCenter() {
321
322        var tlat = map.getCenter().lat(),
323            slat = tlat.toString(),
324
325            tlng = map.getCenter().lng(),
326            slng = tlng.toString();
327
328        jQuery('input[name="mapaCX"]').val(slat.substr(0, 8));
329        jQuery('input[name="mapaCY"]').val(slng.substr(0, 8));
330        jQuery('input[name="mapaCZ"]').val(map.getZoom());
331    }
332
333    function map_restoreCenter() {
334
335        if (self.data('markerfit') != '1') {
336
337            if (jQuery('input[name="mapaCX"]').val() != '') {
338                latitude = jQuery('input[name="mapaCX"]').val();
339                longitude = jQuery('input[name="mapaCY"]').val();
340                zoom = parseInt(jQuery('input[name="mapaCZ"]').val());
341
342                map.panTo(new google.maps.LatLng(latitude, longitude));
343
344                /*if (zoom <= 0)
345                    zoom = 12;*/
346                map.setZoom(zoom);
347            }
348        }
349    }
350
351
352
353// =====================================================================================================================
354}
355
356}
357
358// ----------------------------------------------------------------------------------
359// Zopobiegamy dołączaniu czcionki Roboto przez GMaps do nagłówka strony
360
361        function gmaps_noFont() {
362
363            var head = jQuery('head')[0],
364                insertBefore = head.insertBefore;
365            head.insertBefore = function(newElement, referenceElement) {
366                if (newElement.href && newElement.href.indexOf('https://fonts.googleapis.com/css?family=Roboto') === 0)
367                    return;
368                insertBefore.call(head, newElement, referenceElement);
369            };
370
371        }
372
373// ----------------------------------------------------------------------------------
374
375        function isGmapsLoaded() {
376            /*if (debug) {
377                console.log('typeof window.MarkerClusterer = ' + typeof window.MarkerClusterer + "\n");
378                console.log('typeof window.MarkerWithLabel = ' + typeof window.MarkerWithLabel + "\n");
379                console.log('typeof window.InfoBox = ' + typeof window.InfoBox + "\n");
380            }*/
381
382            return (
383                (typeof window.google == 'object')
384                && (typeof window.google.maps == 'object')
385                && (typeof window.google.maps.LatLng == 'function')
386
387                /*&& (typeof window.MarkerClusterer == 'function')
388                && (typeof window.MarkerWithLabel == 'function')
389                && (typeof window.InfoBox == 'function')*/
390            )
391        }
392
393
394
395// =====================================================================================================================
396    });
397
398
399// =================================================================================================
400// Tools
401
402    function isThere(el) {
403
404        return ((typeof el != 'undefined') && (el.length > 0));
405    }
406
407// --------------------------------------------------------
408
409    function isMobile() {
410
411        return (Math.round($window.outerWidth()) < 768);
412    }
413
414// --------------------------------------------------------
415
416    function isDesktop() {
417
418        return !isMobile();
419    }
420
421// =================================================================================================
422
423})(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.