4 | | File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| VuetifyGoogleAutocomplete.js | 63 |0% | 65 |0/125 | 66 |0% | 67 |0/67 | 68 |0% | 69 |0/54 | 70 |0% | 71 |0/125 | 72 ||
| helper.js | 76 |0% | 78 |0/32 | 79 |0% | 80 |0/22 | 81 |0% | 82 |0/3 | 83 |0% | 84 |0/31 | 85 ||
| index.js | 89 |0% | 91 |0/15 | 92 |0% | 93 |0/8 | 94 |0% | 95 |0/3 | 96 |0% | 97 |0/15 | 98 |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | | import loadGoogleMaps from './helper'; 175 | import VuetifyGoogleAutocomplete from './VuetifyGoogleAutocomplete'; 176 | 177 | // Prevent window from being accessed within non-browser context. 178 | if (typeof window !== 'undefined') { 179 | window.vgaMapState = { 180 | initMap: false, 181 | }; 182 | 183 | window.initVGAMaps = () => { 184 | window.vgaMapState.initMap = true; 185 | }; 186 | } 187 | 188 | VuetifyGoogleAutocomplete.install = (Vue, options) => { 189 | // Set defaults 190 | options = { 191 | /* 192 | * If you want to manually install components, e.g. 193 | * import VuetifyGoogleAutoComplete from 'vuetify-google-autocomplete'; 194 | * 195 | * Vue.component('VuetifyGoogleAutoComplete', VuetifyGoogleAutoComplete) 196 | * 197 | * or locally: 198 | * then set installComponents to 'false'. 199 | * 200 | * If you want to automatically install all the components this property must be set to 'true': 201 | * 202 | * Note: Typescript will require a declaration 203 | * 204 | * index.d.ts 205 | * declare module 'vuetify-google-autocomplete'; 206 | * 207 | */ 208 | installComponents: true, 209 | /* 210 | * Allow this component to be used in conjunction with vue2-google-maps and loads maps API 211 | * via the other component. 212 | * 213 | * @see https://github.com/MadimetjaShika/vuetify-google-autocomplete/issues/60 214 | */ 215 | vueGoogleMapsCompatibility: false, 216 | ...options, 217 | }; 218 | 219 | // add Vue.$vueGoogleMapsCompatibility flag to be used for deferred loading via vue2-google-maps lazy loader 220 | Vue.mixin({ 221 | created() { 222 | this.$vueGoogleMapsCompatibility = options.vueGoogleMapsCompatibility; 223 | }, 224 | }); 225 | 226 | if (options.apiKey) { 227 | if (!options.vueGoogleMapsCompatibility) { 228 | loadGoogleMaps(options.apiKey, options.version, options.language); 229 | } // else use vue2-google-maps to load maps via loading mechanism on Vue.$gmapApiPromiseLazy 230 | } 231 | 232 | if (options.installComponents) { 233 | Vue.component(VuetifyGoogleAutocomplete.name, VuetifyGoogleAutocomplete); 234 | } 235 | }; 236 | 237 | export default VuetifyGoogleAutocomplete; 238 | |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | | /**
195 | * Loads the Google Map API. Code adopted from {@link https://github.com/xkjyeah/vue-google-maps}
196 | *
197 | * @param {string|object} apiKey API Key, or object with the URL parameters. For example to use
198 | * the Google Maps Premium API, pass { client: <YOUR-CLIENT-ID> }. You may pass the
199 | * ersion (as 'v) as a property on this parameter.
200 | * @param {string} version Google Maps SDK Version.
201 | *
202 | * Adapted from {@link https://github.com/xkjyeah/vue-google-maps}
203 | * @see {@link https://github.com/xkjyeah/vue-google-maps}
204 | * @access private
205 | */
206 | const loadGoogleMaps = (apiKey, version, language) => {
207 | try {
208 | // If not within browser context, do not continue processing.
209 | if (typeof window === 'undefined' || typeof document === 'undefined') {
210 | return;
211 | }
212 |
213 | if (typeof window.google === 'object' && typeof window.google.maps === 'object') {
214 | if (typeof window.google.maps.places === 'object') {
215 | return; // google is already loaded, don't try to load it again to prevent errors
216 | }
217 |
218 | throw new Error('Google is already loaded, but does not contain the places API.');
219 | }
220 |
221 | if (!window.vgaMapState.initMap) {
222 | const googleMapScript = document.createElement('SCRIPT');
223 |
224 | // Allow apiKey to be an object.
225 | // This is to support more esoteric means of loading Google Maps,
226 | // such as Google for business
227 | // https://developers.google.com/maps/documentation/javascript/get-api-key#premium-auth
228 | const options = {};
229 | if (typeof apiKey === 'string') {
230 | options.key = apiKey;
231 | } else if (typeof apiKey === 'object') {
232 | Object.keys(apiKey).forEach((key) => {
233 | options[key] = apiKey[key];
234 | });
235 | } else {
236 | throw new Error('apiKey should either be a string or an object');
237 | }
238 |
239 | options.libraries = 'places';
240 | options.callback = 'initVGAMaps';
241 |
242 | const parameters = Object.keys(options).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options[key])}`)
243 | .join('&');
244 |
245 | let url = `https://maps.googleapis.com/maps/api/js?${parameters}`;
246 |
247 | if (version) {
248 | url = `${url}&v=${version}`;
249 | }
250 |
251 | if (language) {
252 | url = `${url}&language=${language}`;
253 | }
254 |
255 | googleMapScript.setAttribute('src', url);
256 | googleMapScript.setAttribute('async', '');
257 | googleMapScript.setAttribute('defer', '');
258 | document.body.appendChild(googleMapScript);
259 | } else {
260 | throw new Error('Vuetify google autocomplete loaded multiple times.');
261 | }
262 | } catch (exception) {
263 | throw new Error('Vuetify google autocomplete load error: ', exception);
264 | }
265 | };
266 |
267 | export default loadGoogleMaps;
268 | |
{{ outputHtml }}
154 | {{ outputJsData }}
179 | {{ outputJsCallback }}
181 | {{ outputHtml }}
154 | {{ outputJsData }}
179 | {{ outputJsCallback }}
181 | {{ outputHtml }}
154 | {{ outputJsData }}
179 | {{ outputJsCallback }}
181 |