2015-10-07 12:47:57 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
import { ElementRef, ComponentRef, AfterViewInit, Component } from '@angular/core';
|
|
|
|
|
2016-08-28 21:46:10 +03:00
|
|
|
import { BrowserDomAdapter as DOM } from '../../utils/browser-adapter';
|
2016-08-22 12:12:13 +03:00
|
|
|
import { BaseComponent } from '../base';
|
2016-05-09 22:55:16 +03:00
|
|
|
|
2016-08-28 21:46:10 +03:00
|
|
|
import * as detectScollParent from 'scrollparent';
|
2016-05-20 20:36:10 +03:00
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
import { SpecManager } from '../../utils/SpecManager';
|
|
|
|
import { OptionsService, RedocEventsService } from '../../services/index';
|
2016-05-20 20:36:10 +03:00
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
@Component({
|
2015-10-07 12:47:57 +03:00
|
|
|
selector: 'redoc',
|
2016-05-25 18:34:31 +03:00
|
|
|
templateUrl: './redoc.html',
|
|
|
|
styleUrls: ['./redoc.css'],
|
2015-10-07 12:47:57 +03:00
|
|
|
})
|
2016-06-15 21:48:04 +03:00
|
|
|
export class Redoc extends BaseComponent implements AfterViewInit {
|
2016-05-25 18:34:31 +03:00
|
|
|
static appRef: ComponentRef<any>;
|
2016-08-29 07:30:49 +03:00
|
|
|
static _preOptions: any;
|
2016-06-06 19:32:20 +03:00
|
|
|
|
2016-08-29 07:30:49 +03:00
|
|
|
public options: any;
|
2016-05-06 00:48:41 +03:00
|
|
|
|
2016-06-13 20:54:24 +03:00
|
|
|
private element: any;
|
2015-12-30 11:16:36 +03:00
|
|
|
|
2016-01-24 20:01:17 +03:00
|
|
|
static showLoadingAnimation() {
|
2016-08-28 21:46:10 +03:00
|
|
|
let elem = DOM.query('redoc');
|
|
|
|
DOM.addClass(elem, 'loading');
|
2016-01-24 20:01:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static hideLoadingAnimation() {
|
2016-08-28 21:46:10 +03:00
|
|
|
let redocEl = DOM.query('redoc');
|
2016-06-23 17:36:38 +03:00
|
|
|
if (!redocEl) return;
|
2016-08-28 21:46:10 +03:00
|
|
|
DOM.addClass(redocEl, 'loading-remove');
|
2016-01-24 20:01:17 +03:00
|
|
|
setTimeout(() => {
|
2016-08-28 21:46:10 +03:00
|
|
|
DOM.removeClass(redocEl, 'loading-remove');
|
|
|
|
DOM.removeClass(redocEl, 'loading');
|
2016-01-24 20:01:17 +03:00
|
|
|
}, 400);
|
|
|
|
}
|
|
|
|
|
2016-05-20 19:31:30 +03:00
|
|
|
static displayError(err) {
|
2016-08-28 21:46:10 +03:00
|
|
|
let redocEl = DOM.query('redoc');
|
2016-06-23 17:36:38 +03:00
|
|
|
if (!redocEl) return;
|
2016-05-20 19:31:30 +03:00
|
|
|
let heading = 'Oops... ReDoc failed to render this spec';
|
|
|
|
let details = err.message;
|
|
|
|
let erroHtml = `<div class="redoc-error">
|
|
|
|
<h1>${heading}</h1>
|
|
|
|
<div class='redoc-error-details'>${details}</div>`;
|
|
|
|
redocEl.innerHTML = erroHtml;
|
|
|
|
}
|
|
|
|
|
2016-06-23 17:36:38 +03:00
|
|
|
constructor(specMgr: SpecManager, optionsMgr:OptionsService, elementRef:ElementRef,
|
2016-06-13 20:54:24 +03:00
|
|
|
public events:RedocEventsService) {
|
2016-06-23 17:36:38 +03:00
|
|
|
super(specMgr);
|
2016-08-29 07:30:49 +03:00
|
|
|
// merge options passed before init
|
|
|
|
optionsMgr.options = Redoc._preOptions;
|
2016-06-13 20:54:24 +03:00
|
|
|
this.element = elementRef.nativeElement;
|
|
|
|
//parse options (top level component doesn't support inputs)
|
|
|
|
optionsMgr.parseOptions( this.element );
|
2016-08-28 21:46:10 +03:00
|
|
|
let scrollParent = detectScollParent( this.element );
|
|
|
|
if (scrollParent === DOM.defaultDoc().body) scrollParent = window;
|
|
|
|
optionsMgr.options.$scrollParent = scrollParent;
|
2016-06-13 20:54:24 +03:00
|
|
|
this.options = optionsMgr.options;
|
|
|
|
this.events = events;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
setTimeout( () => {
|
|
|
|
this.events.bootstrapped.next({});
|
|
|
|
});
|
|
|
|
}
|
2015-10-07 12:47:57 +03:00
|
|
|
}
|