Skip to content

Commit 000335e

Browse files
committed
Load discojuice in browser, not in the server (DSpace#614)
1 parent 4b5b7dc commit 000335e

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/app/clarin-navbar-top/clarin-navbar-top.component.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { AfterViewInit, Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
22
import { AuthService } from '../core/auth/auth.service';
33
import { take } from 'rxjs/operators';
44
import { EPerson } from '../core/eperson/models/eperson.model';
55
import { ScriptLoaderService } from './script-loader-service';
66
import { HALEndpointService } from '../core/shared/hal-endpoint.service';
77
import { LocaleService } from '../core/locale/locale.service';
8+
import { isPlatformBrowser } from '@angular/common';
89

910
/**
1011
* The component which wraps `language` and `login`/`logout + profile` operations in the top navbar.
@@ -14,12 +15,13 @@ import { LocaleService } from '../core/locale/locale.service';
1415
templateUrl: './clarin-navbar-top.component.html',
1516
styleUrls: ['./clarin-navbar-top.component.scss']
1617
})
17-
export class ClarinNavbarTopComponent implements OnInit {
18+
export class ClarinNavbarTopComponent implements OnInit, AfterViewInit {
1819

1920
constructor(private authService: AuthService,
2021
private halService: HALEndpointService,
2122
private scriptLoader: ScriptLoaderService,
22-
private localeService: LocaleService) { }
23+
private localeService: LocaleService,
24+
@Inject(PLATFORM_ID) private platformId: Object) { }
2325

2426
/**
2527
* The current authenticated user. It is null if the user is not authenticated.
@@ -47,7 +49,16 @@ export class ClarinNavbarTopComponent implements OnInit {
4749
} else {
4850
this.authenticatedUser = null;
4951
}
52+
}
53+
54+
ngAfterViewInit(): void {
55+
// Load scripts only in the browser and not SSR
56+
if (isPlatformBrowser(this.platformId)) {
57+
this.loadScripts();
58+
}
59+
}
5060

61+
loadScripts() {
5162
// At first load DiscoJuice, second AAI and at last AAIConfig
5263
this.loadDiscoJuice().then(() => {
5364
this.loadAAI().then(() => {

0 commit comments

Comments
 (0)