2016-06-06 19:32:20 +03:00
|
|
|
'use strict';
|
2016-08-28 21:46:10 +03:00
|
|
|
import './components/Redoc/redoc-initial-styles.css';
|
2016-06-06 19:32:20 +03:00
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
import { enableProdMode } from '@angular/core';
|
2016-06-06 19:32:20 +03:00
|
|
|
import { Redoc } from './components/index';
|
2016-08-28 21:46:10 +03:00
|
|
|
import { BrowserDomAdapter as DOM } from './utils/browser-adapter';
|
|
|
|
import { disableDebugTools } from '@angular/platform-browser';
|
2017-03-09 21:58:10 +03:00
|
|
|
import { isString } from './utils/helpers';
|
2016-09-28 00:30:33 +03:00
|
|
|
|
|
|
|
var bootstrapRedoc;
|
|
|
|
if (AOT) {
|
|
|
|
bootstrapRedoc = require('./bootstrap').bootstrapRedoc;
|
|
|
|
} else {
|
|
|
|
bootstrapRedoc = require('./bootstrap.dev').bootstrapRedoc;
|
|
|
|
}
|
2016-06-06 19:32:20 +03:00
|
|
|
|
2016-08-29 18:24:50 +03:00
|
|
|
if (IS_PRODUCTION) {
|
|
|
|
enableProdMode();
|
|
|
|
}
|
|
|
|
|
2016-08-28 21:46:10 +03:00
|
|
|
export const version = LIB_VERSION;
|
2016-06-23 17:36:38 +03:00
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
var moduleRef;
|
2017-03-09 21:58:10 +03:00
|
|
|
export function init(specUrlOrSpec:string|any, options:any = {}) {
|
2016-08-28 21:46:10 +03:00
|
|
|
if (moduleRef) {
|
|
|
|
destroy();
|
|
|
|
}
|
2016-08-29 07:30:49 +03:00
|
|
|
|
|
|
|
Redoc._preOptions = options;
|
2017-03-09 21:58:10 +03:00
|
|
|
options.specUrl = options.specUrl || (isString(specUrlOrSpec) ? specUrlOrSpec : '');
|
|
|
|
if (!isString(specUrlOrSpec)) {
|
|
|
|
options.spec = specUrlOrSpec;
|
|
|
|
}
|
2016-10-14 11:44:18 +03:00
|
|
|
return bootstrapRedoc()
|
2016-08-22 12:12:13 +03:00
|
|
|
.then(appRef => {
|
|
|
|
moduleRef = appRef;
|
2017-03-15 18:50:10 +03:00
|
|
|
if (IS_PRODUCTION) disableDebugTools();
|
2016-08-22 12:12:13 +03:00
|
|
|
console.log('ReDoc initialized!');
|
|
|
|
}).catch(err => {
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export function destroy() {
|
|
|
|
moduleRef.destroy();
|
2016-10-12 23:05:30 +03:00
|
|
|
moduleRef = null;
|
2016-08-22 12:12:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function autoInit() {
|
|
|
|
const specUrlAttributeName = 'spec-url';
|
2016-08-28 21:46:10 +03:00
|
|
|
let redocEl = DOM.query('redoc');
|
2016-08-22 12:12:13 +03:00
|
|
|
if (!redocEl) return;
|
2016-08-28 21:46:10 +03:00
|
|
|
if (DOM.hasAttribute(redocEl, specUrlAttributeName)) {
|
|
|
|
let url = DOM.getAttribute(redocEl, specUrlAttributeName);
|
2016-08-22 12:12:13 +03:00
|
|
|
init(url);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
autoInit();
|