PageSourceSearch

https://toursgratis.com/assets/js/utils.js?v=5.6

js toursgratis.com collected 2026-10-03 20:30:58 UTC 16,290 bytes, 444 lines download raw bytes

1minCharactersToBeginSearching = 3;
2howManyActivitiesShows = 6;
3howManySitesShows = 6;
4
5function searchInputTrigger(input) {
6    input.click(function() {
7        $('#results-list').show(0);
8        if ($(this).val().length < minCharactersToBeginSearching) {
9            $('.search-list#first-result-list').show(0);
10            $('.search-list#second-result-list').hide(0)
11        } else {
12            $('.search-list#first-result-list').hide(0);
13            $('.search-list#second-result-list').show(0)
14        }
15    });
16    $('body').click(function(e) {
17        if (!$(e.target).hasClass(input.attr('class'))) {
18            $('.search-list#first-result-list').hide(0);
19            $('.search-list#second-result-list').hide(0)
20        }
21    })
22}
23
24function searchInInput(input, countries, locations, properties, fixedOutput, dinamicOutput, translates) {
25    input.keyup(function() {
26        searchDestinationsFounds = 0;
27        searchActivitiesFounds = 0;
28        searchWord = removeAccents(input.val().toLowerCase());
29        results = "";
30        if (searchWord.length >= minCharactersToBeginSearching) {
31            activitiesShows = howManyActivitiesShows;
32            sitesShows = howManySitesShows;
33            fixedOutput.hide(0);
34            dinamicOutput.show(0);
35            arrayKeywords = searchWord.split(' ');
36            locations.each(function() {
37                locationWord = removeAccents($(this).text().toLowerCase());
38                wordFound = findArrayInString(arrayKeywords, locationWord);
39                if (wordFound) {
40                    searchDestinationsFounds += 1;
41                    if (sitesShows > 0) {
42                        sitesShows -= 1;
43                        $(this).show(0)
44                    } else {
45                        $(this).hide(0)
46                    }
47                } else {
48                    $(this).hide(0)
49                }
50            });
51            properties.each(function() {
52                propertyWord = removeAccents($(this).text().toLowerCase());
53                wordFound = findArrayInString(arrayKeywords, propertyWord);
54                if (wordFound) {
55                    searchActivitiesFounds += 1;
56                    if (activitiesShows > 0) {
57                        activitiesShows -= 1;
58                        $(this).show(0)
59                    } else {
60                        $(this).hide(0)
61                    }
62                } else {
63                    $(this).hide(0)
64                }
65            });
66            destinationText = searchDestinationsFounds + ((searchDestinationsFounds > 1 || searchDestinationsFounds == 0) ? translates[1] : translates[0]);
67            activityText = searchActivitiesFounds + ((searchActivitiesFounds > 1 || searchActivitiesFounds == 0) ? translates[3] : translates[2]);
68            $('.slider-box .search-list#second-result-list .search-results-title').css("display", "block").children('a').html(destinationText + ', ' + activityText);
69            (searchDestinationsFounds == 0) ? $('.search-results .destinations').hide(0): $('.search-results .destinations').show(0);
70            (searchActivitiesFounds == 0) ? $('.search-results .properties').hide(0): $('.search-results .properties').show(0);
71            (searchActivitiesFounds == 0) ? $('.show-all-properties').hide(0): $('.show-all-properties').show(0)
72        } else {
73            fixedOutput.css("display", "block");
74            dinamicOutput.css("display", "none")
75        }
76    })
77}
78
79function showProperties(form, div) {
80    div.children('input[type=hidden]').val(1);
81    form.submit()
82}
83
84function showDestinations(form, div) {
85    div.children('input[type=hidden]').val(2);
86    form.submit()
87}
88
89function findArrayInString(array, string) {
90    returnValue = !0;
91    $.each(array, function(index, val) {
92        found = string.indexOf(val);
93        if (found == -1) {
94            returnValue = !1
95        }
96    });
97    return returnValue
98}
99accentMap = {
100    'á': 'a',
101    'à': 'a',
102    'ä': 'a',
103    'â': 'a',
104    'é': 'e',
105    'è': 'e',
106    'ë': 'e',
107    'ê': 'e',
108    'í': 'i',
109    'ì': 'i',
110    'ï': 'i',
111    'î': 'i',
112    'ó': 'o',
113    'ò': 'o',
114    'ö': 'o',
115    'ô': 'o',
116    'ú': 'u',
117    'ù': 'u',
118    'ü': 'u',
119    'û': 'u'
120};
121
122function removeAccents(word) {
123    if (!word) {
124        return ''
125    }
126    var newWord = '';
127    for (var i = 0; i < word.length; i++) {
128        newWord += accentMap[word.charAt(i)] || word.charAt(i)
129    }
130    return newWord
131}
132
133function moveSidebar(columnElement, filterboxTopInitial, footerTop, lastScroll) {
134    windowTop = $(window).scrollTop();
135    windowBottom = windowTop + $(window).height();
136    filterboxHeight = columnElement.outerHeight();
137    filterboxTop = columnElement.offset().top;
138    filterboxBottom = columnElement.offset().top + filterboxHeight;
139    if (lastScroll < windowTop) {
140        if (filterboxHeight > $(window).height()) {
141            if (filterboxBottom < windowBottom) {
142                if (windowBottom < footerTop) {
143                    filterboxMargin = windowBottom - filterboxHeight - filterboxTopInitial - 40;
144                    columnElement.css('margin-top', filterboxMargin)
145                } else {
146                    filterboxMargin = footerTop - filterboxHeight - filterboxTopInitial;
147                    columnElement.css('margin-top', filterboxMargin)
148                }
149            }
150        } else {
151            if (filterboxTop < windowTop) {
152                if (windowBottom < footerTop) {
153                    filterboxMargin = windowTop - filterboxTopInitial;
154                    if (filterboxMargin > 0) {
155                        columnElement.css('margin-top', filterboxMargin)
156                    } else {
157                        columnElement.css('margin-top', '0')
158                    }
159                } else {
160                    filterboxMargin = footerTop - filterboxHeight - filterboxTopInitial;
161                    columnElement.css('margin-top', filterboxMargin)
162                }
163            }
164        }
165    } else {
166        if (filterboxTop > filterboxTopInitial && filterboxTop > windowTop && windowBottom < footerTop) {
167            filterboxMargin = windowTop - filterboxTopInitial;
168            if (filterboxMargin > 0) {
169                columnElement.css('margin-top', filterboxMargin + $('#header').outerHeight())
170            } else {
171                columnElement.css('margin-top', '0')
172            }
173        }
174    }
175    lastScroll = windowTop;
176    return lastScroll
177}
178
179function fixSidebarScrollDown(sidebar, sidebarTop, footerTop, lastScroll) {
180    windowHeight = $(window).height();
181    windowScroll = $(window).scrollTop();
182    windowBottom = windowScroll + $(window).height();
183    sidebarHeight = sidebar.outerHeight();
184    actualizedSidebarTop = sidebar.offset().top;
185    sidebarBottom = actualizedSidebarTop + sidebarHeight;
186    headerHeight = $('#header').height();
187    myRight = ($(window).width() - ($('.row.marginalized').offset().left + $('.row.marginalized').outerWidth() + 15));
188    if (sidebarHeight < windowHeight) {
189        if (windowScroll > sidebarTop) {
190            if (footerTop > sidebarBottom) {
191                sidebar.css({
192                    'position': 'fixed',
193                    'right': myRight,
194                    'top': 39
195                })
196            } else {
197                newTop = footerTop - sidebarTop - sidebarHeight;
198                sidebar.css({
199                    'position': 'absolute',
200                    'right': 0,
201                    'top': newTop
202                })
203            }
204        } else {
205            sidebar.css({
206                'position': 'absolute',
207                'right': 0,
208                'top': 39
209            })
210        }
211    } else {
212        if (windowBottom > sidebarTop + sidebarHeight + 40) {
213            if (footerTop > sidebarBottom) {
214                sidebar.css({
215                    'position': 'fixed',
216                    'right': myRight,
217                    'top': windowHeight - sidebarHeight - 5
218                })
219            } else {
220                newTop = footerTop - sidebarTop - sidebarHeight;
221                sidebar.css({
222                    'position': 'absolute',
223                    'right': 0,
224                    'top': newTop
225                })
226            }
227        } else {
228            sidebar.css({
229                'position': 'absolute',
230                'right': 0,
231                'top': 39
232            })
233        }
234    }
235}
236
237function fixSidebarScrollUp(sidebar, sidebarTop, footerTop, lastScroll) {
238    windowHeight = $(window).height();
239    windowScroll = $(window).scrollTop();
240    windowBottom = windowScroll + $(window).height();
241    sidebarHeight = sidebar.outerHeight();
242    actualizedSidebarTop = sidebar.offset().top;
243    sidebarBottom = actualizedSidebarTop + sidebarHeight;
244    headerHeight = $('#header').height();
245    myRight = ($(window).width() - ($('.row.marginalized').offset().left + $('.row.marginalized').outerWidth() + 15));
246    if (windowScroll > sidebarTop - headerHeight) {
247        if (footerTop - sidebarHeight - headerHeight - 40 > windowScroll) {
248            sidebar.css({
249                'position': 'fixed',
250                'right': myRight,
251                'top': 130
252            })
253        } else {
254            newTop = footerTop - sidebarTop - sidebarHeight;
255            sidebar.css({
256                'position': 'absolute',
257                'right': 0,
258                'top': newTop
259            })
260        }
261    } else {
262        sidebar.css({
263            'position': 'absolute',
264            'right': 0,
265            'top': 39
266        })
267    }
268}
269
270function exchangeLatLon(id) {
271    newLat = $('#lon-' + id).val();
272    newLon = $('#lat-' + id).val();
273    $('#lat-' + id).val(newLat);
274    $('#lon-' + id).val(newLon);
275    updateMarkerAndMap(id);
276}
277
278function updateMarkerAndMap(id) {
279    newLat = $('#lat-' + id).val();
280    newLon = $('#lon-' + id).val();
281    markers[id].setLatLng([newLat, newLon]);
282    maps[id].panTo([newLat, newLon]);
283}
284var maps = [],
285    markers = [];
286
287function loadLeafletMap(id, lat, lon, description = null, hasSearcher = false, markerDraggable = true) {
288    maps[id] = new L.map('leaflet-map-' + id).setView([lat, lon], 15);
289
290    L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmFmYWRvbmljdXMiLCJhIjoiY2xnYW56NHc1MGVkZzNua3Bxd2t5aGJuYSJ9.CPMFq36hj4pwzS2VBqWRvA', {
291        maxZoom: 18,
292        id: 'mapbox/streets-v11',
293        tileSize: 512,
294        zoomOffset: -1
295    }).addTo(maps[id]);
296
297    var iconPath = '';
298    if (window.location.port) {
299        iconPath = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/assets/images/home/';
300    } else {
301        iconPath = window.location.protocol + '//' + window.location.hostname + '/assets/images/home/';
302    }
303    var tgIcon = L.icon({
304        iconUrl: iconPath + 'map_icon.png',
305        shadowUrl: iconPath + 'map_icon_shadow.png',
306        iconSize: [50, 60],
307        shadowSize: [60, 50],
308        iconAnchor: [25, 60],
309        shadowAnchor: [10, 51],
310        popupAnchor: [-0, -65]
311    });
312    if (description) {
313        markers[id] = new L.marker([lat, lon], {
314            icon: tgIcon,
315            draggable: markerDraggable
316        }).addTo(maps[id]).bindPopup('<b>' + description + '</b>').on('dragend', function(event) {
317            var position = this.getLatLng();
318            $('#lat-' + id).val(position.lat);
319            $('#lon-' + id).val(position.lng);
320        }).openPopup();
321    } else {
322        markers[id] = new L.marker([lat, lon], {
323            icon: tgIcon,
324            draggable: markerDraggable
325        }).addTo(maps[id]).on('dragend', function(event) {
326            var position = this.getLatLng();
327            $('#lat-' + id).val(position.lat);
328            $('#lon-' + id).val(position.lng);
329        });
330    }
331    if (hasSearcher) {
332        L.Control.geocoder({
333            defaultMarkGeocode: false
334        }).on('markgeocode', function(e) {
335            //console.log(e.geocode.center);
336            $('#lat-' + id).val(e.geocode.center.lat);
337            $('#lon-' + id).val(e.geocode.center.lng);
338            updateMarkerAndMap(id);
339        }).addTo(maps[id]);
340    }
341}
342
343function loadLeafletMapMultimarker(id, centerCoordinates, zoom, markersCoordinates, description = null, hasSearcher = false, markerDraggable = true) {
344    maps[id] = new L.map('leaflet-map-' + id).setView(centerCoordinates, zoom);
345
346    L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoicmFmYWRvbmljdXMiLCJhIjoiY2xnYW56NHc1MGVkZzNua3Bxd2t5aGJuYSJ9.CPMFq36hj4pwzS2VBqWRvA', {
347        maxZoom: 18,
348        id: 'mapbox/streets-v11',
349        tileSize: 512,
350        zoomOffset: -1
351    }).addTo(maps[id]);
352
353    var iconPath = '';
354    if (window.location.port) {
355        iconPath = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/assets/images/home/';
356    } else {
357        iconPath = window.location.protocol + '//' + window.location.hostname + '/assets/images/home/';
358    }
359
360    var tgIcon = L.icon({
361        iconUrl: iconPath + 'map_icon.png',
362        shadowUrl: iconPath + 'map_icon_shadow.png',
363        iconSize: [50, 60],
364        shadowSize: [60, 50],
365        iconAnchor: [25, 60],
366        shadowAnchor: [10, 51],
367        popupAnchor: [-0, -65]
368    });
369
370    markersCoordinates.forEach((coordinate, index) => {
371        if (description[index]) {
372            markers[id] = new L.marker(coordinate, {
373                icon: tgIcon,
374                draggable: markerDraggable
375            }).addTo(maps[id]).bindPopup('<b>' + description[index] + '</b>').on('dragend', function(event) {
376                var position = this.getLatLng();
377                $('#lat-' + id).val(position.lat);
378                $('#lon-' + id).val(position.lng);
379            });
380        } else {
381            markers[id] = new L.marker(coordinate, {
382                icon: tgIcon,
383                draggable: markerDraggable
384            }).addTo(maps[id]).on('dragend', function(event) {
385                var position = this.getLatLng();
386                $('#lat-' + id).val(position.lat);
387                $('#lon-' + id).val(position.lng);
388            });
389        }
390    })
391
392    if (hasSearcher) {
393        L.Control.geocoder({
394            defaultMarkGeocode: false
395        }).on('markgeocode', function(e) {
396            //console.log(e.geocode.center);
397            $('#lat-' + id).val(e.geocode.center.lat);
398            $('#lon-' + id).val(e.geocode.center.lng);
399            updateMarkerAndMap(id);
400        }).addTo(maps[id]);
401    }
402}
403
404function googleInfoWindow(id) {
405    var infowindow = new google.maps.InfoWindow();
406    var searchBox = $('#address-map-' + id)[0];
407    var autocomplete = new google.maps.places.Autocomplete(searchBox
407);
408}
409
410function storeLocalStorage(name, val) {
411    if (typeof(Storage) !== "undefined") {
412        localStorage.setItem(name, val);
413    } else {
414        window.alert('Please use a modern browser to properly view this template!');
415    }
416}
417
418function getLocalStorage(name) {
419    if (typeof(Storage) !== "undefined") {
420        return localStorage.getItem(name);
421    } else {
422        window.alert('Please use a modern browser to properly view this template!');
423    }
424}
425
426function updateDonicusInfoParameters() {
427    $('donicusinfo').each(function() {
428        $(this).attr('doncurrency', getLocalStorage('currencyCode') || 'EUR');
429        $(this).attr('donlocale', getLocalStorage('localeCode') || 'ES');
430    });
431}
432
433function scrollToElement(element, top = 0) {
434    if(!element) {
435        console.warn('[scrollToElement] Element to scroll not found')
436        return false
437    }
438
439    var distance = window.pageYOffset + element.getBoundingClientRect().top - 80 + top
440
441    $('html, body').stop().animate({
442        'scrollTop': distance
443    }, 800, 'swing');
444}

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.