-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
asset-map.js
60 lines (51 loc) · 1.41 KB
/
asset-map.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
/* global window, __assetMapPlaceholder__ */
import RSVP from 'rsvp';
import $ from 'jquery';
import AssetMap from '../services/asset-map';
export function initialize(app) {
const container = app.__container__;
let config;
if(container.factoryFor) {
config = container.factoryFor('config:environment').class;
} else {
config = container.lookupFactory('config:environment');
}
let assetMapFile = window && window.__assetMapPlaceholder__;
if (!assetMapFile) {
let ifaPlaceholder = document.querySelector('[property="ifa:placeholder"]');
if (ifaPlaceholder) {
assetMapFile = decodeURIComponent(ifaPlaceholder.getAttribute('content'));
}
}
if (!assetMapFile) {
app.register('service:asset-map', AssetMap);
return;
}
if (config.ifa.inline) {
AssetMap.reopen({
map: assetMapFile.assets,
prepend: assetMapFile.prepend,
enabled: true
});
app.register('service:asset-map', AssetMap);
} else {
app.deferReadiness();
const promise = new RSVP.Promise((resolve, reject) => {
$.getJSON(assetMapFile, resolve).fail(reject);
});
promise.then((map = {}) => {
AssetMap.reopen({
map: map.assets,
prepend: map.prepend,
enabled: true
});
}).then(() => {
app.register('service:asset-map', AssetMap);
app.advanceReadiness();
});
}
}
export default {
name: 'asset-map',
initialize
};