##// END OF EJS Templates
fixes to css, nls to support requirejs optimizer
cin -
r36:a1a1ef050ecc 1.0.0-rc17 default
parent child
Show More
@@ -1,16 +1,17
1 import inject = require("./dom-inject");
2 import { id as mid} from "module";
3 import { TraceSource } from "@implab/core-amd/log/TraceSource";
4 const log = TraceSource.get(mid);
1 import inject from "./dom-inject";
2
3 interface OnLoad {
4 (result?: any): void;
5 error(err: any): void;
6 }
5 7
6 8 const plugin = {
7 load: async (id: string, require: Require, cb: (param: any) => void) => {
9 load: (id: string, require: Require, cb: OnLoad, config: { isBuild?: boolean }) => {
10 if (config.isBuild) {
11 cb();
12 } else {
8 13 const url = require.toUrl(id);
9 try {
10 await inject.injectStylesheet(url);
11 cb({ url });
12 } catch (e) {
13 log.error("CSS plugin failed to load {0} ({1}): {2}", id, url, e);
14 inject.injectStylesheet(url).then(() => cb({ url }), e => cb.error(e));
14 15 }
15 16 }
16 17 };
@@ -18,8 +18,8 interface NodeLoadResult {
18 18 }
19 19
20 20 class DomInject {
21 injectionPoint = document.head;
22 injectBefore = document.head.firstChild;
21 injectionPoint?: HTMLElement;
22 injectBefore?: HTMLElement;
23 23
24 24 _map: MapOf<Promise<NodeLoadResult>> = {};
25 25
@@ -48,7 +48,10 class DomInject {
48 48
49 49 mixin(node, attr);
50 50
51 this.injectionPoint.insertBefore(node, this.injectBefore);
51 const _injectionPoint = this.injectionPoint || document.head;
52 const _injectBefore = this.injectBefore || _injectionPoint.firstChild;
53
54 _injectionPoint.insertBefore(node, _injectBefore);
52 55 });
53 56 }
54 57
@@ -94,4 +97,4 class DomInject {
94 97 };
95 98
96 99 const instance = new DomInject();
97 export = instance; No newline at end of file
100 export default instance;
@@ -2,6 +2,11 import { MapOf } from "@implab/core-amd/
2 2 import { NlsBundle } from "./NlsBundle";
3 3 import { isPromise } from "@implab/core-amd/safe";
4 4
5 interface OnLoad {
6 (result?: any): void;
7 error(err: any): void;
8 }
9
5 10 export function bundle<T extends object>(nls: T, locales?: MapOf<any>) {
6 11 const nlsBundle = new NlsBundle(nls, locales);
7 12
@@ -16,13 +21,17 export function bundle<T extends object>
16 21
17 22 fn.define = (pack: Partial<T>) => pack;
18 23 fn.default = nlsBundle.default;
19 fn.load = async (id: string, require: Require, cb: { (): void; error: (arg0: any) => void; }) => {
24 fn.load = async (id: string, require: Require, cb: OnLoad, config: any) => {
25 if (config.isBuild) {
26 cb();
27 } else {
20 28 try {
21 29 await nlsBundle.getLocale(id);
22 30 cb();
23 31 } catch (e) {
24 32 cb.error(e);
25 33 }
34 }
26 35 };
27 36
28 37 return fn;
General Comments 0
You need to be logged in to leave comments. Login now