PageSourceSearch

https://www.endangeredalphabets.net/wp-content/plugins/wp-google-m…?ver=10.1.08%2Bpro-10.1.05

js endangeredalphabets.net collected 2026-09-24 19:53:13 UTC 3,807 bytes, 107 lines download raw bytes

1/**
2 * @namespace WPGMZA
3 * @module LocationIQAutocomplete
4 * @requires WPGMZA.Autocomplete
5 */
6jQuery(function($) {
7	
8	var Parent = WPGMZA.Autocomplete;
9
10	WPGMZA.LocationIQAutocomplete = function(element, options) {
11		Parent.call(this, element, options);
12	}
13
14	WPGMZA.LocationIQAutocomplete.prototype = Object.create(Parent.prototype);
15	WPGMZA.LocationIQAutocomplete.prototype.constructor = WPGMZA.LocationIQAutocomplete;
16
17	WPGMZA.LocationIQAutocomplete.API_URL = "https://api.locationiq.com/v1/autocomplete"; 
18	
19	WPGMZA.LocationIQAutocomplete.prototype.autoload = function() {
20		WPGMZA.Autocomplete.prototype.autoload.apply(this, arguments);
21
22		let apikey = this.getApiKey();
23        if(apikey){
24            this.prepare();
25            this.setReady(true);
26        }
27	}
28
29	WPGMZA.LocationIQAutocomplete.prototype.getApiKey = function(){
30		let apikey = false;
31		if(WPGMZA.settings){
32			if(WPGMZA.settings.address_provider_api_key){
33				apikey = WPGMZA.settings.address_provider_api_key;
34			} else if(WPGMZA.settings.wpgmza_leaflet_locationiq_key){
35				apikey = WPGMZA.settings.wpgmza_leaflet_locationiq_key;
36			}
37		}
38		return apikey;
39	}
40
41	WPGMZA.LocationIQAutocomplete.prototype.getProvider = function(){
42		return WPGMZA.Autocomplete.Providers.LOCATION_IQ;
43	}
44
45	WPGMZA.LocationIQAutocomplete.prototype.find = function(){
46		WPGMZA.Autocomplete.prototype.find.apply(this, arguments);
47
48        let term = this.getTerm();
49        if(term){
50            let apikey = this.getApiKey();
51
52            if(apikey){
53                this.setBusy(true);
54
55                let params = new URLSearchParams({
56                    'dedupe' : '1',
57                    'q' : term.trim(),
58                    'limit' : 8, 
59                    'key' : apikey
60                });
61
62                if(this.options && this.options.country){
63                    params.append('countrycodes', this.options.country.toLowerCase());
64                }
65
66                fetch(`${WPGMZA.LocationIQAutocomplete.API_URL}?${params.toString()}`)
67                    .then((response) => {
68                        if(!response.ok){
69                            return response.json().then((error) => {
70                                /* Do nothing */	
71                                this.setBusy(false);
72                            });
73                        }
74                        return response.json();
75                    }).then((data) => {
76                        suggestions = data ? data : [];
77                        suggestions = suggestions.map((place) => {
78                            return {
79                                name : place.display_place,
80                                address : place.display_name,
81                                id : place.place_id,
82                                coordinates : {lat : place.lat, lon : place.lon},
83                                country : place.address.country ? place.address.country : false,
84                                type : place.address && place.address.country ? place.address.country : false
85                            }
86                        });
87
88                        this.setItems(suggestions);
89                        this.setBusy(false);
90                        this.present();
91                    }).catch((error) => {
92                        this.setBusy(false);
93                    });
94            }
95        }
96	}
97
98	WPGMZA.LocationIQAutocomplete.prototype.remapItem = function(item){
99		return {
100			display : item.name ? item.name : false,
101			address : item.address ? item.address : false,
102            country : item.country ? item.country : false,
103			type : item.type ? WPGMZA.capitalizeWords(item.type.replaceAll("_", " ")) : "Location",
104            coordinates : item.coordinates ? `${item.coordinates.lat}, ${item.coordinates.lon}` : false
105		};
106	}
107});

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.