-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathindex.js
98 lines (81 loc) · 2.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* jshint node: true */
'use strict';
const path = require('path');
const fastbootTransform = require('fastboot-transform');
module.exports = {
name: 'ember-cli-g-maps',
options: {
nodeAssets: {
'gmaps-for-apps': {
vendor: {
srcDir: '',
include: ['gmaps.js'],
processTree(input) {
return fastbootTransform(input);
}
}
}
}
},
included() {
this._super.included.apply(this, arguments);
this._ensureThisImport();
this.import('vendor/gmaps-for-apps/gmaps.js');
},
_ensureThisImport() {
if (!this.import) {
this._findHost = function findHostShim() {
let current = this;
let app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
};
this.import = function importShim(asset, options) {
let app = this._findHost();
app.import(asset, options);
};
}
},
// Request Google Maps script in consuming app
contentFor(type, config) {
var googleMapConfig = config.googleMap || {};
var params = [];
var content = '';
var googleMapSrc, isClient;
if (type === 'head') {
googleMapSrc = 'maps.googleapis.com/maps/api/js';
// let googleMapsScript = 'http://maps.google.com/maps/api/js?sensor=true'
//Protocol setup
googleMapConfig.protocol = googleMapConfig.protocol || '//';
// default to Google Maps V3
googleMapConfig.version = googleMapConfig.version || '3';
params.push('v='+ encodeURIComponent(googleMapConfig.version));
// grab either API key or client ID
if (googleMapConfig.apiKey) {
isClient = googleMapConfig.apiKey.substr(0, 4) === 'gme-';
params.push((isClient ? 'client' : 'key') +'='+ encodeURIComponent( googleMapConfig.apiKey ));
}
// add any optional libraries
if (googleMapConfig.libraries && googleMapConfig.libraries.length) {
params.push('libraries='+ encodeURIComponent( googleMapConfig.libraries.join(',') ));
}
// add optional localization
if (googleMapConfig.language) {
params.push('language='+ encodeURIComponent( googleMapConfig.language ));
}
if (googleMapConfig.region) {
params.push('region='+ encodeURIComponent( googleMapConfig.region ));
}
googleMapSrc = googleMapConfig.protocol + googleMapSrc;
googleMapSrc += '?'+ params.join('&');
if(googleMapConfig.lazyLoad) {
content = '<meta name="ember-cli-g-maps-url" content="'+ googleMapSrc +'">';
} else {
content = '<script src="'+ googleMapSrc +'"></script>';
}
}
return content;
}
};