RSS Git Download  Clone
Raw Blame History 2kB 113 lines
import {
    Injectable,
    Inject,

} from '@angular/core';

import {PlatformLocation} from '@angular/common'

import {log as defaultLog} from './util/log';
const IsBot = require("./util/is-bot.js");

const log = defaultLog.factory('boot');

declare global {
    interface Window {
        corifeusLoader: number,
        corifeus: {
            booted: boolean,
            app: {
                web: any,
                server: any
            }
            core: {
                http: {
                    counter: number,
                    status: number,
                    counterUrlMap: any,
                    error: Array<any>
                }
            }
        };
    }
}


if (typeof window !== 'undefined') {
    window.corifeusLoader = 0
    window.corifeus = {
        booted: false,
        core: {
            http: {
                status: 200,
                counter: 0,
                counterUrlMap: {},
                error: [],
            }
        },
        app: {
            web: {},
            server: {}
        }
    }

    let httpCounter = 0;
    Object.defineProperty(window.corifeus.core.http, 'counter', {
        get: () => {
            return httpCounter;
        },
        set: (value) => {
            httpCounter = value;
        }
    })
}

import {SettingsService, LocaleService} from "./";
import {RouterService} from "./services/router";


@Injectable()
export class Boot {

    constructor(
        private settings: SettingsService,
        private locale: LocaleService,
        private routerService: RouterService,
        private location: PlatformLocation
    ) {
    }

    boot() {
        log('booted web');
        this.settings.boot();

        const module = 'core';

        if (typeof document !== 'undefined') {
            const body = document.getElementsByTagName("body")[0];
            if (body) {
                const corySeo = document.createElement('div');
                body.appendChild(corySeo);
                corySeo.id = 'cory-seo';
                if (!IsBot()) {
                    corySeo.style.display = 'none';
                }
            }
        }

        this.settings.register(module, require('./json/settings.json'));

        // after settings
        this.locale.boot();

        if (typeof window !== 'undefined' && window.corifeus) {
            window.corifeus.booted = true;
        }

        this.location.onPopState(() => {
            this.routerService.scrollToTop();
        });

    }
}