forked from amorimjj/redoc-try-it-out
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.ts
53 lines (45 loc) · 2.1 KB
/
module.ts
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
import { loadScript } from './utils/loaders/scripts';
import { Styler } from './styler'
import { RedocTryItOutOptions } from './interfaces/redoc-try-it-out-options.interface';
import { SwaggerWrapper } from './wrappers/swagger.wrapper';
import { RedocWrapper } from './wrappers/redoc.wrapper';
import { AuthBtn } from './elements/auth.btn';
import { TryBtn } from './elements/try.btn';
import { SwaggerConfig } from './config/swagger-config';
import { RedocTryItOutConfig } from './config/redoc-try-it-out-config';
import { AuthBtnConfig } from './config/auth-btn-config'
import { TryBtnConfigConfig } from './config/try-btn-config';
import { StyleMatcherConfig } from './config/style-matcher.config';
export class RedocTryItOut {
private static async loadDependencies():Promise<void> {
await loadScript(RedocWrapper.cfg.tryItDependencies.jqueryUrl);
return loadScript(RedocWrapper.cfg.tryItDependencies.jqueryScrollToUrl);
}
private static async loadAll(): Promise<void[]> {
await RedocTryItOut.loadDependencies();
return Promise.all([
RedocWrapper.init(),
SwaggerWrapper.init()
]);
}
private static config(url:string, cfg:RedocTryItOutOptions, element?: HTMLElement): void {
RedocWrapper.cfg = new RedocTryItOutConfig(url, cfg, element);
if ( RedocWrapper.cfg.tryItOutEnabled ){
SwaggerWrapper.cfg = new SwaggerConfig(cfg.swaggerOptions || {}, url, true);
AuthBtn.cfg = new AuthBtnConfig(cfg.authBtn || {})
TryBtn.cfg = new TryBtnConfigConfig(cfg.tryBtn || {});
Styler.cfg = new StyleMatcherConfig(cfg.stylerMatcher || {}, SwaggerWrapper.cfg, RedocWrapper.cfg);
}
}
public static async init(docUrl: string, cfg: RedocTryItOutOptions, element?: HTMLElement):Promise<void> {
RedocTryItOut.config(docUrl, cfg, element);
if ( RedocWrapper.cfg.tryItOutEnabled ) {
await RedocTryItOut.loadAll();
AuthBtn.init();
TryBtn.init();
Styler.init();
} else {
await RedocWrapper.init()
}
}
}