Project

General

Profile

1
/**
2
 * @license Angular v4.4.6
3
 * (c) 2010-2017 Google, Inc. https://angular.io/
4
 * License: MIT
5
 */
6
import { ResourceLoader, platformCoreDynamic } from '@angular/compiler';
7
import { COMPILER_OPTIONS, Injectable, PLATFORM_ID, Version, createPlatformFactory, ɵglobal } from '@angular/core';
8
import { ɵPLATFORM_BROWSER_ID } from '@angular/common';
9
import { ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS } from '@angular/platform-browser';
10

    
11
/**
12
 * @license
13
 * Copyright Google Inc. All Rights Reserved.
14
 *
15
 * Use of this source code is governed by an MIT-style license that can be
16
 * found in the LICENSE file at https://angular.io/license
17
 */
18
class ResourceLoaderImpl extends ResourceLoader {
19
    get(url) {
20
        let resolve;
21
        let reject;
22
        const promise = new Promise((res, rej) => {
23
            resolve = res;
24
            reject = rej;
25
        });
26
        const xhr = new XMLHttpRequest();
27
        xhr.open('GET', url, true);
28
        xhr.responseType = 'text';
29
        xhr.onload = function () {
30
            // responseText is the old-school way of retrieving response (supported by IE8 & 9)
31
            // response/responseType properties were introduced in ResourceLoader Level2 spec (supported
32
            // by IE10)
33
            const response = xhr.response || xhr.responseText;
34
            // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
35
            let status = xhr.status === 1223 ? 204 : xhr.status;
36
            // fix status code when it is 0 (0 status is undocumented).
37
            // Occurs when accessing file resources or on Android 4.1 stock browser
38
            // while retrieving files from application cache.
39
            if (status === 0) {
40
                status = response ? 200 : 0;
41
            }
42
            if (200 <= status && status <= 300) {
43
                resolve(response);
44
            }
45
            else {
46
                reject(`Failed to load ${url}`);
47
            }
48
        };
49
        xhr.onerror = function () { reject(`Failed to load ${url}`); };
50
        xhr.send();
51
        return promise;
52
    }
53
}
54
ResourceLoaderImpl.decorators = [
55
    { type: Injectable },
56
];
57
/** @nocollapse */
58
ResourceLoaderImpl.ctorParameters = () => [];
59

    
60
/**
61
 * @license
62
 * Copyright Google Inc. All Rights Reserved.
63
 *
64
 * Use of this source code is governed by an MIT-style license that can be
65
 * found in the LICENSE file at https://angular.io/license
66
 */
67
const INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS = [
68
    ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS,
69
    {
70
        provide: COMPILER_OPTIONS,
71
        useValue: { providers: [{ provide: ResourceLoader, useClass: ResourceLoaderImpl }] },
72
        multi: true
73
    },
74
    { provide: PLATFORM_ID, useValue: ɵPLATFORM_BROWSER_ID },
75
];
76

    
77
/**
78
 * @license
79
 * Copyright Google Inc. All Rights Reserved.
80
 *
81
 * Use of this source code is governed by an MIT-style license that can be
82
 * found in the LICENSE file at https://angular.io/license
83
 */
84
/**
85
 * An implementation of ResourceLoader that uses a template cache to avoid doing an actual
86
 * ResourceLoader.
87
 *
88
 * The template cache needs to be built and loaded into window.$templateCache
89
 * via a separate mechanism.
90
 */
91
class CachedResourceLoader extends ResourceLoader {
92
    constructor() {
93
        super();
94
        this._cache = ɵglobal.$templateCache;
95
        if (this._cache == null) {
96
            throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
97
        }
98
    }
99
    get(url) {
100
        if (this._cache.hasOwnProperty(url)) {
101
            return Promise.resolve(this._cache[url]);
102
        }
103
        else {
104
            return Promise.reject('CachedResourceLoader: Did not find cached template for ' + url);
105
        }
106
    }
107
}
108

    
109
/**
110
 * @license
111
 * Copyright Google Inc. All Rights Reserved.
112
 *
113
 * Use of this source code is governed by an MIT-style license that can be
114
 * found in the LICENSE file at https://angular.io/license
115
 */
116

    
117
/**
118
 * @license
119
 * Copyright Google Inc. All Rights Reserved.
120
 *
121
 * Use of this source code is governed by an MIT-style license that can be
122
 * found in the LICENSE file at https://angular.io/license
123
 */
124
/**
125
 * @module
126
 * @description
127
 * Entry point for all public APIs of the common package.
128
 */
129
/**
130
 * @stable
131
 */
132
const VERSION = new Version('4.4.6');
133

    
134
/**
135
 * @license
136
 * Copyright Google Inc. All Rights Reserved.
137
 *
138
 * Use of this source code is governed by an MIT-style license that can be
139
 * found in the LICENSE file at https://angular.io/license
140
 */
141
/**
142
 * @experimental
143
 */
144
const RESOURCE_CACHE_PROVIDER = [{ provide: ResourceLoader, useClass: CachedResourceLoader }];
145
/**
146
 * @stable
147
 */
148
const platformBrowserDynamic = createPlatformFactory(platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
149

    
150
/**
151
 * @license
152
 * Copyright Google Inc. All Rights Reserved.
153
 *
154
 * Use of this source code is governed by an MIT-style license that can be
155
 * found in the LICENSE file at https://angular.io/license
156
 */
157
/**
158
 * @module
159
 * @description
160
 * Entry point for all public APIs of the platform-browser-dynamic package.
161
 */
162

    
163
// This file only reexports content of the `src` folder. Keep it that way.
164

    
165
export { RESOURCE_CACHE_PROVIDER, platformBrowserDynamic, VERSION, INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, ResourceLoaderImpl as ɵResourceLoaderImpl };
166
//# sourceMappingURL=platform-browser-dynamic.js.map
(3-3/4)